/* CSS Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* iPhone-inspired Color Palette */
    --primary-color: #007AFF;
    --secondary-color: #5856D6;
    --accent-color: #FF3B30;
    --success-color: #34C759;
    --warning-color: #FF9500;
    --gray-50: #F2F2F7;
    --gray-100: #E5E5EA;
    --gray-200: #D1D1D6;
    --gray-300: #C7C7CC;
    --gray-400: #AEAEB2;
    --gray-500: #8E8E93;
    --gray-600: #636366;
    --gray-700: #48484A;
    --gray-800: #3A3A3C;
    --gray-900: #1C1C1E;
    --white: #FFFFFF;
    --black: #000000;
    
    /* Typography */
    --font-primary: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    --font-mono: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
    
    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;
    --space-3xl: 4rem;
    
    /* Border Radius */
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

body {
    font-family: var(--font-primary);
    line-height: 1.6;
    color: var(--gray-900);
    background-color: var(--white);
    overflow-x: hidden;
}

/* Accessibility Utilities */
.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0 0 0 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--primary-color);
    color: var(--white);
    padding: var(--space-sm) var(--space-md);
    z-index: 200;
    border-radius: 0 0 var(--radius-md) 0;
    text-decoration: none;
    transition: top 0.2s ease;
}

.skip-link:focus {
    top: 0;
}

/* --------------------------------------- */
/* Reusable Layout & Component Patterns    */
/* --------------------------------------- */

/* Section rhythm */
section {
    scroll-margin-top: 5rem; /* better anchor focus offset */
}

.section-block {
    padding: var(--space-3xl) 0 var(--space-2xl);
    position: relative;
}

/* Subtle divider between large content blocks */
.section-divider, .section-block + .section-block::before {
    content: '';
    display: block;
    height: 1px;
    background: linear-gradient(to right, transparent, var(--gray-200), transparent);
    margin: var(--space-3xl) auto var(--space-2xl);
    max-width: 900px;
}

/* Card Grid System */
.grid {
    display: grid;
    gap: var(--space-xl);
}
.grid.cols-2 { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }

/* Unified Card Base */
.card {
    background: var(--white);
    border: 1px solid var(--gray-100);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
    transition: box-shadow .25s ease, transform .25s ease, border-color .25s ease;
}
.card:hover, .card:focus-within {
    box-shadow: var(--shadow-lg);
    transform: translateY(-3px);
    border-color: var(--primary-color);
}

/* Consistent Media Aspect */
.card-media, .card .card-media, .card .guide-image, .card .news-image, .card .article-image {
    aspect-ratio: 16 / 9;
    width: 100%;
    overflow: hidden;
    position: relative;
    background: var(--gray-50);
}
.card-media img, .card .guide-image img, .card .news-image img, .card .article-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform .35s ease;
}
.card:hover .card-media img, .card:hover .guide-image img, .card:hover .news-image img, .card:hover .article-image img {
    transform: scale(1.05);
}

/* Card Body */
.card-body, .card .guide-content, .card .news-content, .card .article-content {
    padding: var(--space-lg);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    flex: 1;
}

/* Meta Row */
.card-meta, .card .guide-meta, .card .news-meta, .card .article-meta {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    font-size: .75rem;
    letter-spacing: .03em;
    text-transform: uppercase;
    color: var(--gray-500);
    font-weight: 600;
}

/* Badges */
.badge, .guide-badge, .news-badge, .card .guide-badge {
    position: absolute;
    top: .75rem;
    left: .75rem;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: #fff;
    padding: .35rem .6rem;
    font-size: .7rem;
    border-radius: var(--radius-sm);
    letter-spacing: .05em;
    font-weight: 600;
    box-shadow: var(--shadow-md);
}

/* Difficulty & status pills */
.pill, .difficulty, .reading-time, .time, .popularity, .news-date {
    background: var(--gray-100);
    color: var(--gray-700);
    padding: .25rem .5rem;
    border-radius: 999px;
    font-size: .7rem;
    line-height: 1;
    font-weight: 500;
}
.difficulty.easy { background: #E7F9ED; color: #137A32; }
.difficulty.medium { background: #FFF4D6; color: #8B6100; }
.difficulty.hard { background: #FFE2E0; color: #B02014; }

/* Typography improvements inside cards */
.card h3, .guide-card h3, .news-card h3, .featured-article h3, .guide-item h3 {
    font-size: 1.05rem;
    line-height: 1.35;
    margin: 0 0 .4rem;
}
.card h3 a, .guide-card h3 a, .news-card h3 a, .featured-article h3 a, .guide-item h3 a {
    text-decoration: none;
    color: var(--gray-900);
}
.card h3 a:hover { color: var(--primary-color); }

/* Uniform card spacing override for legacy selectors */
/* NOTE: For older markup, these legacy selectors now inherit unified spacing via shared rules below. */
.featured-article, .guide-card, .news-card, .guide-item, .category-card {
    background: var(--white);
    border: 1px solid var(--gray-100);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    position: relative;
    transition: box-shadow .25s ease, transform .25s ease, border-color .25s ease;
}
.featured-article:hover, .guide-card:hover, .news-card:hover, .guide-item:hover, .category-card:hover,
.featured-article:focus-within, .guide-card:focus-within, .news-card:focus-within, .guide-item:focus-within, .category-card:focus-within {
    box-shadow: var(--shadow-lg);
    transform: translateY(-3px);
    border-color: var(--primary-color);
}

/* Category cards icon sizing alignment */
.category-card .category-icon { font-size: 2.25rem; margin-bottom: var(--space-sm); }

/* Readability: limit paragraph line length inside cards */
.card p, .guide-card p, .news-card p, .article-content p, .guide-content p, .news-content p {
    max-width: 60ch;
}

/* Section headers */
.section-header { margin: 0 0 var(--space-xl); text-align: center; }
.section-header p { color: var(--gray-600); max-width: 60ch; margin: 0.25rem auto 0; }

/* Breadcrumb */
.breadcrumb { background: var(--gray-50); border-bottom: 1px solid var(--gray-100); font-size: .8rem; }
.breadcrumb .container { padding-top: .6rem; padding-bottom: .6rem; }
.breadcrumb-list { list-style: none; display: flex; gap: .35rem; padding: 0; margin: 0; flex-wrap: wrap; }
.breadcrumb-list li a { color: var(--gray-600); text-decoration: none; }
.breadcrumb-list li a:hover { color: var(--primary-color); text-decoration: underline; }
.breadcrumb-list [aria-current="page"] span { font-weight: 600; color: var(--gray-900); }

/* Footer disclaimer uniform style */
.footer .disclaimer { font-size: .7rem; letter-spacing: .02em; }

/* Active nav indicator (aria-current support) */
.nav-menu a[aria-current="page"], .nav-menu a.active { color: var(--primary-color); position: relative; }
.nav-menu a[aria-current="page"]::after, .nav-menu a.active::after { content: ''; position: absolute; left: 0; right: 0; bottom: -4px; height: 2px; background: var(--primary-color); border-radius: 2px; }

/* Improved vertical rhythm for major content containers */
.quick-fixes, .repair-categories, .all-guides, .repair-tools,
.optimization-categories, .all-guides, .optimization-tools, .optimization-tips,
.tips-categories, .featured-guides, .news-categories, .featured-news {
    padding-top: var(--space-2xl);
    padding-bottom: var(--space-2xl);
}

/* Consistent grid gap adjustments */
.guides-grid, .news-grid, .quick-fixes-grid, .categories-grid, .tools-grid, .tips-grid {
    display: grid;
    gap: var(--space-xl);
}

/* Responsive card grid defaults */
@media (min-width: 640px) {
    .guides-grid, .news-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 960px) {
    .guides-grid, .news-grid { grid-template-columns: repeat(3, 1fr); }
}

/* Horizontal reading comfort: widen line-height for long articles */
article p { line-height: 1.55; }

/* Subtle background stripes option for large lists (opt-in) */
.striped-list > *:nth-child(odd) { background: linear-gradient(to right, var(--gray-50), transparent); }

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--space-md);
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.3;
    margin-bottom: var(--space-md);
}

h1 { font-size: 2.5rem; }
h2 { font-size: 2rem; }
h3 { font-size: 1.5rem; }
h4 { font-size: 1.25rem; }
h5 { font-size: 1.125rem; }
h6 { font-size: 1rem; }

p {
    margin-bottom: var(--space-md);
}

/* Links */
a {
    color: var(--primary-color);
    text-decoration: none;
    transition: color 0.2s ease;
}

a:hover {
    color: var(--secondary-color);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-sm) var(--space-lg);
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-primary);
    font-size: 1rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: var(--shadow-sm);
}

.btn-primary {
    background-color: var(--primary-color);
    color: var(--white);
}

.btn-primary:hover {
    background-color: var(--secondary-color);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background-color: var(--gray-100);
    color: var(--gray-900);
}

.btn-secondary:hover {
    background-color: var(--gray-200);
    transform: translateY(-1px);
}

/* Header */
.header {
    background-color: var(--white);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-wrapper {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-md) 0;
}

.logo a {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    text-decoration: none;
    color: var(--gray-900);
}

.logo-icon {
    font-size: 2rem;
}

.logo-text {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

.logo-tagline {
    font-size: 0.875rem;
    color: var(--gray-500);
    display: none;
}

.nav-menu {
    display: flex;
    list-style: none;
    gap: var(--space-lg);
    margin: 0;
    padding: 0;
}

.nav-menu a {
    color: var(--gray-700);
    font-weight: 500;
    padding: var(--space-sm);
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
}

.nav-menu a:hover {
    background-color: var(--gray-50);
    color: var(--primary-color);
}

/* Mobile Menu */
.hamburger {
    display: none;
    flex-direction: column;
    cursor: pointer;
    padding: var(--space-sm);
}

.hamburger span {
    width: 25px;
    height: 3px;
    background-color: var(--gray-700);
    margin: 2px 0;
    transition: 0.3s;
    border-radius: 2px;
}

/* Hero Section */
.hero {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: var(--white);
    padding: var(--space-3xl) 0;
    position: relative;
    overflow: hidden;
}

.hero::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="10" cy="10" r="1" fill="rgba(255,255,255,0.1)"/><circle cx="90" cy="90" r="1" fill="rgba(255,255,255,0.1)"/></svg>') repeat;
    opacity: 0.1;
}

.hero .container {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-2xl);
    align-items: center;
    position: relative;
    z-index: 1;
}

.hero-title {
    font-size: 3rem;
    font-weight: 700;
    margin-bottom: var(--space-md);
    line-height: 1.2;
}

.hero-subtitle {
    font-size: 1.25rem;
    margin-bottom: var(--space-2xl);
    opacity: 0.9;
}

.search-bar {
    display: flex;
    background-color: var(--white);
    border-radius: var(--radius-lg);
    padding: var(--space-xs);
    margin-bottom: var(--space-2xl);
    box-shadow: var(--shadow-lg);
}

.search-bar input {
    flex: 1;
    border: none;
    padding: var(--space-md);
    font-size: 1rem;
    border-radius: var(--radius-md);
    color: var(--gray-900);
}

.search-bar input::placeholder {
    color: var(--gray-500);
}

.search-bar input:focus {
    outline: none;
}

.search-btn {
    background-color: var(--primary-color);
    color: var(--white);
    border: none;
    padding: var(--space-md);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 1.2rem;
    transition: background-color 0.2s ease;
}

.search-btn:hover {
    background-color: var(--secondary-color);
}

.hero-cta {
    display: flex;
    gap: var(--space-md);
    flex-wrap: wrap;
}

.hero-image {
    display: none;
}

.hero-image img {
    width: 100%;
    height: auto;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
}

/* Ad Sections */
.ad-section {
    padding: var(--space-lg) 0;
    background-color: var(--gray-50);
}

.ad-banner {
    text-align: center;
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--white);
    border-radius: var(--radius-md);
    border: 2px dashed var(--gray-200);
}

.sidebar-ad {
    position: fixed;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    width: 160px;
    z-index: 50;
    display: none;
}

.mobile-sticky-ad {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 50;
    background-color: var(--white);
    padding: var(--space-sm);
    box-shadow: var(--shadow-lg);
    display: none;
}

/* Categories Section */
.categories {
    padding: var(--space-3xl) 0;
    background-color: var(--white);
}

.section-title {
    text-align: center;
    margin-bottom: var(--space-2xl);
    color: var(--gray-900);
}

.categories-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-lg);
}

.category-card {
    background-color: var(--white);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    text-align: center;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--gray-100);
    transition: all 0.3s ease;
}

.category-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-xl);
    border-color: var(--primary-color);
}

.category-icon {
    font-size: 3rem;
    margin-bottom: var(--space-md);
}

.category-card h3 {
    color: var(--gray-900);
    margin-bottom: var(--space-sm);
}

.category-card p {
    color: var(--gray-600);
    margin-bottom: var(--space-lg);
}

.category-link {
    color: var(--primary-color);
    font-weight: 600;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    transition: color 0.2s ease;
}

.category-link:hover {
    color: var(--secondary-color);
}

/* Featured Articles */
.featured {
    padding: var(--space-3xl) 0;
    background-color: var(--gray-50);
}

.featured-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-lg);
}

.featured-article {
    background-color: var(--white);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);
    transition: all 0.3s ease;
}

.featured-article:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.article-image {
    aspect-ratio: 16/9;
    overflow: hidden;
}

.article-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.featured-article:hover .article-image img {
    transform: scale(1.05);
}

.article-content {
    padding: var(--space-lg);
}

.article-content h3 {
    margin-bottom: var(--space-sm);
}

.article-content h3 a {
    color: var(--gray-900);
    text-decoration: none;
}

.article-content h3 a:hover {
    color: var(--primary-color);
}

.article-content p {
    color: var(--gray-600);
    margin-bottom: var(--space-md);
}

.article-meta {
    display: flex;
    gap: var(--space-md);
    font-size: 0.875rem;
    color: var(--gray-500);
}

/* Newsletter */
.newsletter {
    padding: var(--space-3xl) 0;
    background: linear-gradient(135deg, var(--secondary-color) 0%, var(--primary-color) 100%);
    color: var(--white);
    text-align: center;
}

.newsletter h2 {
    margin-bottom: var(--space-md);
}

.newsletter p {
    margin-bottom: var(--space-xl);
    opacity: 0.9;
}

.newsletter-form {
    display: flex;
    max-width: 400px;
    margin: 0 auto;
    gap: var(--space-sm);
}

.newsletter-form input {
    flex: 1;
    padding: var(--space-md);
    border: none;
    border-radius: var(--radius-md);
    font-size: 1rem;
}

.newsletter-form input:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.3);
}

/* Footer */
.footer {
    background-color: var(--gray-900);
    color: var(--gray-300);
    padding: var(--space-3xl) 0 var(--space-lg);
}

.footer-content {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--space-xl);
    margin-bottom: var(--space-2xl);
}

.footer-section h3 {
    color: var(--white);
    margin-bottom: var(--space-md);
}

.footer-section ul {
    list-style: none;
}

.footer-section ul li {
    margin-bottom: var(--space-sm);
}

.footer-section ul li a {
    color: var(--gray-400);
    text-decoration: none;
    transition: color 0.2s ease;
}

.footer-section ul li a:hover {
    color: var(--primary-color);
}

.social-links {
    display: flex;
    gap: var(--space-md);
}

.social-links a {
    font-size: 1.5rem;
    text-decoration: none;
    transition: transform 0.2s ease;
}

.social-links a:hover {
    transform: scale(1.2);
}

.footer-bottom {
    border-top: 1px solid var(--gray-700);
    padding-top: var(--space-lg);
    text-align: center;
}

.disclaimer {
    font-size: 0.875rem;
    color: var(--gray-500);
    margin-top: var(--space-sm);
}

/* Responsive Design */
@media (min-width: 640px) {
    .logo-tagline {
        display: block;
    }
    
    .categories-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .featured-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .newsletter-form {
        flex-direction: row;
    }
    
    .footer-content {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 768px) {
    .container {
        padding: 0 var(--space-lg);
    }
    
    .hero .container {
        grid-template-columns: 1fr 1fr;
    }
    
    .hero-image {
        display: block;
    }
    
    .categories-grid {
        grid-template-columns: repeat(2, 1fr);
        max-width: 800px;
        margin: 0 auto;
    }
    
    .featured-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .sidebar-ad {
        display: block;
    }
}

@media (min-width: 1024px) {
    .categories-grid {
        grid-template-columns: repeat(4, 1fr);
        max-width: 1000px;
        margin: 0 auto;
    }
    
    .footer-content {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (max-width: 767px) {
    .nav-menu {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background-color: var(--white);
        flex-direction: column;
        padding: var(--space-lg);
        box-shadow: var(--shadow-lg);
        border-radius: 0 0 var(--radius-md) var(--radius-md);
    }
    
    .nav-menu.active {
        display: flex;
    }
    
    .hamburger {
        display: flex;
    }
    
    .hamburger.active span:nth-child(1) {
        transform: rotate(-45deg) translate(-5px, 6px);
    }
    
    .hamburger.active span:nth-child(2) {
        opacity: 0;
    }
    
    .hamburger.active span:nth-child(3) {
        transform: rotate(45deg) translate(-5px, -6px);
    }
    
    .hero-title {
        font-size: 2rem;
    }
    
    .hero-cta {
        flex-direction: column;
    }
    
    .mobile-sticky-ad {
        display: block;
    }
    
    body {
        padding-bottom: 80px; /* Account for sticky mobile ad */
    }
}

/* Performance Optimizations */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Print Styles */
@media print {
    .header,
    .ad-section,
    .sidebar-ad,
    .mobile-sticky-ad,
    .newsletter,
    .footer {
        display: none;
    }
    
    .hero {
        background: none;
        color: var(--black);
    }
}

/* Focus Styles for Accessibility */
button:focus,
input:focus,
a:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}