/* ============================================================
   THE IARI TIMES — Responsive Design
   Mobile-first breakpoints for newspaper layout
   ============================================================ */

/* ====== TABLET (max-width: 1024px) ====== */
@media (max-width: 1024px) {
    :root {
        --text-masthead-size: 56px;
        --text-h1-size: 36px;
        --text-h2-size: 26px;
        --space-outer-margin: 24px;
    }

    .newspaper-grid {
        grid-template-columns: repeat(6, 1fr);
    }

    .col-span-8,
    .col-span-7 {
        grid-column: span 6;
    }

    .col-span-4,
    .col-span-5 {
        grid-column: span 6;
    }

    .col-span-3 {
        grid-column: span 3;
    }

    .col-span-2 {
        grid-column: span 3;
    }

    .article-hero .article-image {
        height: 300px;
    }

    .navbar .nav-links {
        gap: var(--space-md);
    }

    .column-divider {
        display: none;
    }

    /* Hide desktop-only elements */
    .desktop-only {
        display: none;
    }
}

/* ====== MOBILE (max-width: 768px) ====== */
@media (max-width: 768px) {
    :root {
        --text-masthead-size: 32px;
        --text-h1-size: 24px;
        --text-h2-size: 20px;
        --text-h3-size: 16px;
        --text-body-size: 16px;
        --space-outer-margin: 0;
        --space-gutter: 0;
        --space-section-gap: 24px;
    }

    /* ---- Canvas → Normal Scroll ---- */
    #canvas-viewport {
        height: auto !important;
        overflow: visible !important;
        cursor: default !important;
        background: var(--color-surface-container-lowest) !important;
        user-select: auto !important;
        -webkit-user-select: auto !important;
    }

    #newspaper-canvas {
        position: relative !important;
        transform: none !important;
    }

    .canvas-controls,
    .canvas-hint {
        display: none !important;
    }

    /* ---- Newspaper Container ---- */
    .newspaper-container {
        width: 100%;
        max-width: 100%;
        padding: 0;
        box-shadow: none;
        background: var(--color-surface-container-lowest);
    }

    /* ---- Masthead — Compact Mobile Header ---- */
    .newspaper-masthead {
        padding: 16px 16px 12px;
        margin-bottom: 0;
        border-bottom: 2px solid var(--color-primary);
        background: #fff;
    }

    .newspaper-masthead::before {
        display: none;
    }

    .newspaper-masthead .masthead-title {
        font-size: 32px;
        line-height: 1.1;
        letter-spacing: -0.02em;
    }

    .newspaper-masthead .masthead-tagline {
        font-size: 9px;
        letter-spacing: 0.08em;
        margin-top: 6px;
        line-height: 1.4;
    }

    /* ---- Edition Bar ---- */
    .edition-bar {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 8px;
        padding: 10px 16px;
        margin-bottom: 0;
        background: #fff;
        border-bottom: 1px solid var(--color-rule-line);
        font-size: 11px;
    }

    .edition-bar .edition-cta {
        margin-left: auto;
        padding: 4px 10px;
        font-size: 10px;
    }

    /* ---- Grid → Stacked Cards ---- */
    .newspaper-grid {
        grid-template-columns: 1fr;
        gap: 0;
        padding: 0;
    }

    /* Add subtle spacing between stacked cards */
    .newspaper-grid > * + * {
        border-top: 1px solid var(--color-rule-line);
    }

    .col-span-2,
    .col-span-3,
    .col-span-4,
    .col-span-5,
    .col-span-6,
    .col-span-7,
    .col-span-8,
    .col-span-9,
    .col-span-10,
    .col-span-12 {
        grid-column: span 1;
    }

    /* ---- Hero Article — Full-width Mobile Card ---- */
    .article-hero {
        border-radius: 0;
        border-left: none;
        border-right: none;
        border-top: none;
        padding: 16px;
        margin: 0;
        background: #fff;
        border-bottom: 1px solid var(--color-rule-line);
    }

    .article-hero .article-image {
        height: 220px;
        border-radius: 10px;
        margin-bottom: 14px;
    }

    .article-hero .article-category {
        font-size: 10px;
        margin-bottom: 4px;
    }

    .article-hero .article-title {
        font-size: 24px;
        line-height: 1.2;
        margin-bottom: 8px;
        letter-spacing: -0.01em;
    }

    .article-hero .article-excerpt {
        font-size: 14px;
        line-height: 1.5;
        margin-bottom: 10px;
        display: -webkit-box;
        -webkit-line-clamp: 3;
        line-clamp: 3;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .article-hero .article-excerpt .drop-cap-letter,
    .article-hero .article-excerpt::first-letter {
        font-size: inherit;
        float: none;
        line-height: inherit;
        margin: 0;
        padding: 0;
    }

    .article-hero .article-meta {
        font-size: 11px;
        gap: 8px;
    }

    /* ---- Featured Article — Compact Mobile Card ---- */
    .article-featured {
        border-radius: 0;
        border: none;
        border-bottom: 1px solid var(--color-rule-line);
        padding: 14px 16px;
        margin: 0;
        background: #fff;
        display: flex;
        flex-direction: row;
        gap: 12px;
        align-items: flex-start;
    }

    .article-featured .article-image {
        width: 100px;
        height: 100px;
        min-width: 100px;
        border-radius: 8px;
        margin: 0;
        order: 2;
    }

    .article-featured .article-category {
        font-size: 9px;
        margin-bottom: 2px;
    }

    .article-featured .article-title {
        font-size: 15px;
        line-height: 1.3;
        margin-bottom: 4px;
    }

    .article-featured .article-excerpt {
        font-size: 13px;
        line-height: 1.4;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        margin-bottom: 4px;
    }

    .article-featured .article-meta {
        font-size: 10px;
    }

    /* ---- Compact Article — Minimal List Item ---- */
    .article-compact {
        border-radius: 0;
        border: none;
        border-bottom: 1px solid var(--color-rule-line);
        padding: 12px 16px;
        margin: 0;
        background: #fff;
    }

    .article-compact .article-category {
        font-size: 9px;
    }

    .article-compact .article-title {
        font-size: 15px;
        line-height: 1.3;
        margin-bottom: 2px;
    }

    .article-compact .article-excerpt {
        font-size: 13px;
        line-height: 1.4;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    /* ---- Section Headers ---- */
    .section-header {
        margin-top: 12px;
        margin-bottom: 0;
        padding: 14px 16px 10px;
        border-top: none;
        background: linear-gradient(to bottom, #f8f7f4, var(--color-surface-container-lowest));
        border-bottom: 1px solid var(--color-rule-line);
    }

    .section-header .section-label {
        font-size: 10px;
    }

    .section-header .section-title {
        font-size: 16px;
    }

    /* ---- Column Dividers — Hidden ---- */
    .column-divider,
    .column-divider-horizontal,
    .with-column-rule::before {
        display: none;
    }

    /* ---- Pulse Strip ---- */
    .pulse-strip {
        grid-template-columns: 1fr;
        gap: 0;
        padding: 0;
    }

    .pulse-item {
        padding: 12px 16px;
        border-left: 3px solid var(--color-accent);
        border-radius: 0;
        border-bottom: 1px solid var(--color-rule-line);
        background: #fff;
        margin-left: 0;
    }

    /* ---- Voice Cards ---- */
    .voice-card {
        padding: 16px;
        border-radius: 0;
        border-left: none;
        border-right: none;
        border-top: none;
        margin: 0;
        border-bottom: 1px solid var(--color-rule-line);
    }

    .voice-card .voice-quote-mark {
        font-size: 48px;
        opacity: 0.15;
    }

    .voice-card .voice-content {
        font-size: 15px;
        line-height: 1.55;
    }

    /* ---- Article Overlay — Full Screen on Mobile ---- */
    .article-overlay {
        padding: 0;
        align-items: stretch;
    }

    .article-overlay .overlay-content {
        max-width: 100%;
        border-radius: 0;
        padding: 52px 16px 40px 16px;
        min-height: 100vh;
        min-height: 100dvh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .article-overlay .overlay-close {
        position: fixed;
        top: 10px;
        right: 10px;
        z-index: 10001;
        background: rgba(255, 255, 255, 0.95);
        color: var(--color-on-surface);
        border-radius: 50%;
        width: 42px;
        height: 42px;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 2px 12px rgba(0,0,0,0.25);
        border: 1px solid rgba(0,0,0,0.08);
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .article-overlay .overlay-image {
        width: calc(100% + 32px);
        margin: -52px -16px 16px;
        height: 220px;
        border-radius: 0;
        object-fit: cover;
    }

    .article-overlay .overlay-title {
        font-size: 22px;
    }

    .article-overlay .overlay-body {
        font-size: 15px;
        line-height: 1.7;
    }

    /* ---- Navbar ---- */
    .navbar {
        padding: var(--space-sm) var(--space-md);
    }

    .navbar .nav-links,
    .navbar .nav-actions .btn {
        display: none;
    }

    .navbar .nav-menu-toggle {
        display: flex;
    }

    /* ---- Mobile Nav Drawer ---- */
    .mobile-nav {
        position: fixed;
        inset: 0;
        z-index: var(--z-modal);
        background: var(--color-surface-container-lowest);
        transform: translateX(-100%);
        transition: transform var(--transition-smooth);
        padding: var(--space-2xl) var(--space-lg);
    }

    .mobile-nav.open {
        transform: translateX(0);
    }

    .mobile-nav .mobile-nav-links {
        list-style: none;
        display: flex;
        flex-direction: column;
        gap: var(--space-md);
    }

    .mobile-nav .mobile-nav-links a {
        font-family: var(--font-headline);
        font-size: var(--text-h3-size);
        color: var(--color-ink-primary);
        text-decoration: none;
        padding: var(--space-sm) 0;
        border-bottom: 1px solid var(--color-rule-line);
        display: block;
    }

    /* ---- Footer ---- */
    .newspaper-footer {
        padding: 24px 16px 80px 16px;
        background: #fff;
        border-top: 2px solid var(--color-primary);
    }

    .newspaper-footer .footer-brand {
        font-size: 22px;
        margin-bottom: 8px;
    }

    .newspaper-footer .footer-links {
        flex-direction: column;
        gap: var(--space-sm);
    }

    /* ---- Subscription Widget ---- */
    /* (Widget is now centered modal, styles handled in component) */

    /* ---- Mobile Bottom Nav ---- */
    .ck-mobile-nav {
        padding-bottom: env(safe-area-inset-bottom, 8px);
    }

    /* ---- Drop cap disabled on mobile ---- */
    .drop-cap::first-letter {
        font-size: inherit !important;
        float: none !important;
        line-height: inherit !important;
        margin: 0 !important;
        padding: 0 !important;
    }
}

/* ====== SMALL MOBILE (max-width: 480px) ====== */
@media (max-width: 480px) {
    :root {
        --text-masthead-size: 32px;
        --text-h1-size: 24px;
        --text-h2-size: 20px;
    }

    .article-hero .article-image {
        height: 180px;
    }

    .voice-card {
        padding: var(--space-md);
    }

    .voice-card .voice-quote-mark {
        font-size: 48px;
    }
}

/* ====== LARGE DESKTOP (min-width: 1400px) ====== */
@media (min-width: 1400px) {
    .newspaper-container {
        max-width: 1300px;
    }
}

/* ====== PRINT STYLES ====== */
@media print {
    .navbar,
    .edition-cta,
    .article-overlay,
    .mobile-nav,
    .newspaper-footer .footer-links {
        display: none !important;
    }

    body {
        font-size: 12pt;
        color: #000;
        background: #fff;
    }

    .newspaper-grid {
        grid-template-columns: repeat(12, 1fr);
    }

    .article-hero .article-image,
    .article-featured .article-image {
        break-inside: avoid;
    }
}

/* ====== ACCESSIBILITY ====== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    :root {
        --color-rule-line: #000000;
        --color-outline: #000000;
        --color-on-surface-variant: #1c1b1b;
    }
}

/* ====== UTILITY: Hide/Show by breakpoint ====== */
.nav-menu-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--color-on-surface);
}

/* ====== BUILDER GRID (LIVE NEWSPAPER MOBILE OVERRIDES) ====== */
@media (max-width: 768px) {
    .ck-builder-grid {
        display: flex !important;
        flex-direction: column !important;
        height: auto !important;
        min-height: auto !important;
        gap: 32px !important;
        padding: 24px 16px !important;
    }
    
    .ck-builder-grid .ck-block-wrapper {
        position: static !important;
        width: 100% !important;
        transform: none !important;
        top: auto !important;
        left: auto !important;
        grid-column: auto !important;
        margin: 0 !important;
    }

    .ck-freeform-layer {
        display: none !important; /* Hide freeform elements on mobile to prevent clutter/overlapping */
    }
}
