/* ============================================================
   home.css — Mobile-only homepage styling
   ============================================================
   Load AFTER style.css. All rules for the new mobile layout are
   wrapped in @media (max-width: 999px) to protect desktop.
   ============================================================ */

.divider-h {
    display: none;
}

/* ── Desktop Hiding ──
   Keep the new mobile-only pieces hidden on desktop. */
.hero-wide,
.ao-topbar,
.ao-settings-panel,
.highlight-box,
.home-highlights,
.home-info-row,
.subject-icon,
.subject-label,
.select-heading {
    display: none;
}

/* ==========================================
   MOBILE LAYOUT (max-width: 999px)
   ========================================== */
@media (max-width: 999px) {

    /* ── Base Layout & Header ── */
    #hero-desktop {
        display: none;
    }

    /* Less side padding on phones so the cards get more room, and enough
       bottom padding that the corner Discord icon never sits on top of
       the last "Show all" button. */
    /* Strip the container card on the mobile subject-selection screen so only
       the three dark subject cards stand out against the flat page background.
       Restore full card styling once the topic dashboard is shown. */
    /* The page itself must never pan sideways on mobile; anything wider
       than the screen gets clipped instead of shifting the whole page. */
    body.index-page {
        overflow-x: hidden;
        overflow-x: clip;
    }

    body.index-page .container {
        padding: 24px 16px 72px;
        background-image: none;
        /* Transparent, NOT solid grey: the stripe texture lives on the fixed
           body::before layer behind the container, so an opaque fill here
           would blank it out. */
        background-color: transparent;
        border: none;
        border-radius: 0;
        box-shadow: none;
    }

    body.index-page:has(#topic-content-view.active-view) .container {
        background-image: url('container_background.png');
        background-color: var(--bg-container);
        border: 2px solid var(--border-main);
        border-radius: 12px;
        box-shadow: var(--shadow-soft);
    }

    .hero-wide {
        display: block;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        height: auto;
        overflow: hidden;
        line-height: 0;
        margin-bottom: 28px;
        background: #000;
        border: 1.5px solid var(--border-main);
        border-radius: 12px;
        box-shadow: var(--shadow-soft);
    }

    .discord-icon.top {
        display: none;
    }

    .sr-only-mobile {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }



    /* The four rolled hero videos share one black frame; the swap script
       reveals exactly one of them on each mobile load. 15/4 matches
       the preview cards; contain letterboxes instead of stretching if the
       mp4s turn out to be a different shape. */
    .ao-hero-video {
        display: none;
        width: 100%;
        height: auto;
        aspect-ratio: 15/4;
        object-fit: contain;
        background: #000;
        border: 0;
        border-radius: 0;
        margin-bottom: 0;
    }



    @media (prefers-reduced-motion: reduce) {

        .ao-gear-btn.ao-spin svg,
        .ao-settings-panel {
            animation: none;
        }
    }

    /* ── Settings Topbar & Panel ──
       Draft-stage header: one gear button that opens the theme and
       homepage-animation picks. Sticky, so settings stay reachable
       while scrolling; the negative margins stretch the bar over the
       container padding so it sits flush with the screen edges. */
    .ao-topbar {
        position: sticky;
        top: 0;
        z-index: 30;
        display: flex;
        align-items: center;
        min-height: 48px;
        margin: -24px -16px 12px;
        padding: 4px 10px;
        background: var(--bg-header);
        border-bottom: 1px solid var(--border-main);
    }

    .ao-gear-btn {
        width: 44px;
        height: 44px;
        display: grid;
        place-items: center;
        background: none;
        border: 0;
        border-radius: 50%;
        color: var(--text-primary);
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        transition: transform .1s ease;
    }

    .ao-gear-btn svg {
        width: 26px;
        height: 26px;
        fill: currentColor;
    }

    .ao-gear-btn:active {
        transform: scale(.92);
    }

    .ao-gear-btn.ao-spin svg {
        animation: ao-gear-spin .45s ease;
    }

    @keyframes ao-gear-spin {
        from { transform: rotate(0deg); }
        to   { transform: rotate(180deg); }
    }

    .ao-gear-btn:focus-visible {
        outline: 2px solid var(--accent-green);
        outline-offset: 2px;
    }

    .ao-discord-link {
        margin-left: auto;
        width: 44px;
        height: 44px;
        display: grid;
        place-items: center;
        color: var(--text-primary);
        -webkit-tap-highlight-color: transparent;
    }

    .ao-discord-link svg {
        width: 24px;
        height: 24px;
        fill: currentColor;
    }

    .ao-discord-link:focus-visible {
        outline: 2px solid var(--accent-green);
        outline-offset: 2px;
    }

    /* Popup, not in-flow: anchored to the sticky topbar (position: sticky
       is a containing block), so opening it never pushes the page down. */
    .ao-settings-panel {
        position: absolute;
        top: calc(100% + 6px);
        left: 10px;
        right: 10px;
        z-index: 40;
        display: block;
        background: var(--bg-container);
        border: 1.5px solid var(--border-main);
        border-radius: 12px;
        box-shadow: var(--shadow-soft);
        padding: 10px 14px 14px;
        margin: 0;
        /* Short screens (phone landscape): cap below the topbar and scroll
           inside the popup instead of getting cut off. */
        max-height: calc(100vh - 72px);
        max-height: calc(100dvh - 72px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        animation: ao-panel-pop .16s ease-out;
    }

    @keyframes ao-panel-pop {
        from { opacity: 0; transform: translateY(-6px); }
        to   { opacity: 1; transform: translateY(0); }
    }

    .ao-settings-panel.hidden {
        display: none;
    }

    .ao-settings-title {
        font-size: .95rem;
        font-weight: 700;
        color: var(--text-heading);
        margin: 8px 0 4px;
    }

    .ao-settings-row {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        padding-top: 6px;
    }

    .ao-opt {
        font: inherit;
        font-size: .95rem;
        font-weight: 600;
        color: var(--text-primary);
        background: var(--bg-card);
        border: 1.5px solid var(--border-main);
        border-radius: 10px;
        padding: 9px 14px;
        min-height: 44px;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .ao-opt.on {
        border-color: var(--accent-green);
        color: var(--accent-green);
    }

    .ao-opt:focus-visible {
        outline: 2px solid var(--accent-green);
        outline-offset: 2px;
    }

    /* ── Dividers ── */

    /* ── Dividers ── */
    .divider-h {
        width: 100%;
        height: 6px;
        display: block;
        background-image: url('icons/divider_h.svg');
        background-size: 100% 100%;
        background-repeat: no-repeat;
        margin-bottom: 20px;
    }

    /* ── Section headings (shared look) ──
       "Pick your subject" and "What's new" use the same style so the
       page reads as a calm list of labelled sections. */
    .select-heading,
    .mobile-section-heading {
        display: block;
        text-align: left;
        font-size: 1.15rem;
        color: var(--text-heading);
        margin: 0 0 12px;
        padding-left: 4px;
    }

    /* ── Band (Subjects on top, Highlights below) ── */
    .home-band {
        display: flex;
        flex-direction: column;
        gap: 28px;
        height: auto;
        position: relative;
        margin-bottom: 20px;
    }

    /* ── Subject Buttons ──
       Three equal tiles that share the row. They only scroll sideways
       if the phone is so narrow they can't fit. */
    .home-band .subject-selection-list {
        display: flex;
        flex-direction: row;
        gap: 12px;
        max-width: none;
        margin: 0;
        width: 100%;
        overflow-x: auto;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
        padding: 6px 2px 10px;
    }
    .home-band .subject-selection-list::-webkit-scrollbar {
        display: none;
    }
    

    .home-band .subject-item {
        flex: 1 1 0;
        min-width: 140px;
        height: auto;
    }

    .home-band .subject-btn {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 12px;
        padding: 20px 12px;
        width: 100%;
        height: 170px;
        background: var(--bg-container);
        border: 2px solid var(--border-main);
        border-radius: 16px;
        color: inherit;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        transition: transform .1s ease;
        box-shadow: var(--shadow-soft);
    }

    /* Dark card per subject button — only on the subject-selection screen,
       not on the topic dashboard. */
    body.index-page:not(:has(#topic-content-view.active-view)) .home-band .subject-btn {
        background: #0e1017;
        border: 1.5px solid var(--border-main);
        border-radius: 12px;
    }

    .home-band .subject-icon {
        width: 84px;
        height: 84px;
        object-fit: contain;
        display: block;
    }

    /* Labels have different shapes, so cap both dimensions and let the
       aspect ratio decide. */
    .home-band .subject-label {
        width: auto;
        height: auto;
        max-width: 70px;
        max-height: 34px;
        display: block;
        object-fit: contain;
    }

    /* "Phys" is nearly square, so it needs a much taller cap to read at the
       same size as "Chem" and "Math". */
    .home-band .subject-label[src*="phys"] {
        max-width: 62px;
        max-height: 52px;
    }

    .home-band .subject-text {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }

    .home-band .subject-btn:active {
        transform: scale(.95);
        border-color: var(--accent-green);
    }

    .home-band .subject-btn:active .subject-icon {
        filter: drop-shadow(0 0 6px rgba(61,214,140,.45));
    }

    .home-band .subject-btn:focus-visible {
        outline: 2px solid var(--accent-green);
        outline-offset: 2px;
    }

    /* ── Recent-Changes Carousel ──
       A framed card like the subject box. Arrows and dots live in a row
       underneath the card, so nothing is drawn on top of the content
       (or the video). */
    .home-highlights {
        display: block;
    }
    .home-highlights[hidden] {
        display: none;
    }

    .highlight-box {
        position: relative;
        display: flex;
        flex-direction: column;
        min-height: 0;
        touch-action: pan-y;
        overflow: hidden;
    }

    .hl-card {
        flex: 1;
        display: flex;
        flex-direction: column;
        gap: 6px;
        padding: 14px 14px 6px;
        text-decoration: none;
        color: var(--text-primary);
    }

    .hl-meta {
        display: flex;
        justify-content: space-between;
        gap: 6px;
        font-size: .72rem;
    }

    .hl-subject {
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: .03em;
    }

    .hl-card[data-subject="Chemistry"] .hl-subject {
        color: var(--accent-blue);
    }

    .hl-card[data-subject="Mathematics"] .hl-subject {
        color: var(--accent-green);
    }

    .hl-card[data-subject="Physics"] .hl-subject {
        color: var(--accent-amber);
    }

    .hl-date {
        white-space: nowrap;
        color: var(--text-secondary);
    }

    .hl-title {
        font-size: 1.05rem;
        color: var(--text-heading);
        line-height: 1.25;
        display: -webkit-box;
        -webkit-line-clamp: 3;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .hl-blurb {
        font-size: .9rem;
        line-height: 1.4;
        display: -webkit-box;
        -webkit-line-clamp: 3;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .hl-cta {
        margin-top: 4px;
        color: var(--accent-blue);
        font-weight: 600;
        font-size: .9rem;
    }

    /* Controls row: [<]  o o o  [>] */
    .hl-controls {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 6px 6px;
    }

    /* 44x44px tap target for arrows */
    .hl-arrow {
        flex: 0 0 auto;
        width: 44px;
        height: 44px;
        display: grid;
        place-items: center;
        background: none;
        border: 0;
        border-radius: 50%;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
        transition: background .2s ease;
    }

    .hl-arrow img {
        width: 20px;
        height: 20px;
        opacity: .75;
    }

    .hl-arrow:active {
        background: rgba(61,214,140,.12);
    }

    .hl-arrow:focus-visible {
        outline: 2px solid var(--accent-green);
        outline-offset: -2px;
    }

    .hl-dots {
        display: flex;
        justify-content: center;
    }

    /* Tall tap target, 8px visual dot */
    .hl-dot {
        width: 28px;
        height: 44px;
        background: none;
        border: 0;
        position: relative;
        cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }

    .hl-dot::after {
        content: "";
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 8px;
        height: 8px;
        border-radius: 50%;
        border: 1.5px solid var(--text-secondary);
    }

    .hl-dot.on::after {
        background: var(--accent-green);
        border-color: var(--accent-green);
    }

    .slide-from-right { animation: hlR .22s ease-out; }
    .slide-from-left { animation: hlL .22s ease-out; }

    @keyframes hlR { from { opacity: 0; transform: translateX(16px); } }
    @keyframes hlL { from { opacity: 0; transform: translateX(-16px); } }

    @media (prefers-reduced-motion: reduce) {
        .slide-from-right, .slide-from-left { animation: none; }
    }

    /* ── Updates and To Do Panels ──
       Default: two columns side by side (used by any page that doesn't
       opt into the tabbed variant). */
    .home-info-row {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 14px;
        margin-top: 0;
        align-items: start;
    }

    .home-panel {
        min-width: 0;
    }

    /* ── Tabbed variant (index.html) ──
       One tab bar on top, one panel visible at a time. */
    .home-info-row.hp-tabbed {
        display: flex;
        flex-direction: column;
        gap: 0;
        align-items: stretch;
        background: var(--bg-header);
        border: 1px solid var(--border-main);
        border-radius: 12px;
        padding: 8px 16px 16px;
        box-shadow: var(--shadow-soft);
    }

    .hp-tab-bar {
        display: flex;
        gap: 0;
        margin-bottom: 8px;
        border-bottom: 1px solid var(--border-main);
    }

    .hp-tab {
        flex: 1;
        background: none;
        border: none;
        padding: 10px 8px;
        font: inherit;
        font-size: 1.05rem;
        font-weight: 600;
        color: var(--text-secondary);
        cursor: pointer;
        border-bottom: 2px solid transparent;
        margin-bottom: -1px;
        -webkit-tap-highlight-color: transparent;
        transition: color 0.2s ease, border-color 0.2s ease;
    }

    .hp-tab[aria-selected="true"] {
        color: var(--accent-green);
        border-bottom-color: var(--accent-green);
    }

    .hp-tab:focus-visible {
        outline: 2px solid var(--accent-green);
        outline-offset: -2px;
    }

    .home-info-row.hp-tabbed .home-panel[hidden] {
        display: none !important;
    }

    /* The tab label already names the panel; keep the heading for
       screen readers so it doesn't duplicate the visible tab. */
    .home-info-row.hp-tabbed .home-panel .info-panel-heading {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }

    .home-panel .info-panel-heading {
        font-size: 1.15rem;
        margin-bottom: 8px;
        padding: 0 4px 8px;
        border-bottom: 1px solid var(--border-main);
    }

    .home-panel .updates-list,
    .home-panel .todo-list {
        gap: 0;
    }

    .home-info-row .home-panel .update-item,
    .home-info-row .home-panel .todo-item {
        padding: 12px 4px;
        background: none;
        border: 0;
        border-bottom: 1px solid var(--border-main);
        border-radius: 0;
        box-shadow: none;
    }

    .home-panel .update-item {
        cursor: pointer;
    }

    .home-panel .update-date {
        font-size: 0.85rem;
        margin-bottom: 4px;
    }

    .home-panel .update-title {
        font-size: 1.05rem;
        line-height: 1.3;
        color: var(--text-heading);
        margin-bottom: 6px;
    }

    .home-panel .update-text {
        font-size: 0.95rem;
        line-height: 1.5;
        color: var(--text-primary);
        display: -webkit-box;
        -webkit-line-clamp: 3;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .home-panel .update-item.open .update-text {
        display: block;
        -webkit-line-clamp: unset;
        overflow: visible;
    }

    /* Small cue that updates can be tapped open */
    .home-panel .update-item::after {
        content: "Tap to read more";
        display: block;
        margin-top: 6px;
        font-size: 0.85rem;
        font-weight: 600;
        color: var(--text-secondary);
    }

    .home-panel .update-item.open::after {
        content: "Tap to collapse";
    }

    .home-panel .todo-item {
        gap: 10px;
    }

    .home-panel .todo-box {
        width: 18px;
        height: 18px;
        font-size: .72rem;
    }

    .home-panel .todo-text {
        font-size: 1rem;
        line-height: 1.5;
        color: var(--text-primary);
    }

    /* Show only the first 3 updates and 5 todos by default */
    .home-panel:not(.expanded) .updates-list > li:nth-child(n+4),
    .home-panel:not(.expanded) .todo-list > li:nth-child(n+6) {
        display: none;
    }

    .hp-more {
        margin-top: 6px;
        background: none;
        border: 0;
        padding: 10px 4px;
        font: inherit;
        font-size: 1rem;
        font-weight: 600;
        color: var(--accent-blue);
        cursor: pointer;
    }
}

/* ── Carousel preview picture ──
   The drawings have black backgrounds, so they sit in a black frame and
   keep their full shape (nothing is cropped). Tapping the picture follows
   the card's link, since it lives inside the card. */
.hl-image-wrapper {
    margin-top: 6px;
    border-radius: 8px;
    overflow: hidden;
    background: #000;
    border: 1px solid var(--border-main);
}

.hl-image {
    display: block;
    width: 100%;
    height: auto;
    max-height: 260px;
    object-fit: contain;
}

/* ── Updates popup scroll lock ──
   While the Updates popup is open on mobile, stop the page behind it
   from scrolling, so dragging inside the popup doesn't drag the whole
   page along with it. The popup keeps its own internal scroll
   (.updates-popup's overflow-y: auto in style.css), so long updates
   still scroll inside the box.

   :has() keeps this automatic: opening the popup removes its .hidden
   class (see handleAction in index.html), which turns this rule on;
   closing it (× button, dark backdrop, or rotating to a ≥1000px
   viewport where style.css hides .updates-overlay) turns it off again.
   No JS toggling, so the lock can't desync from the popup's real
   visible state. */
@media (max-width: 999px) {
    body:has(#updates-modal:not(.hidden)) {
        overflow: hidden;
    }
}

/* ==========================================
   COLOR PRESETS (MOBILE HOMEPAGE ONLY)
   ==========================================
   The homepage body carries at most one theme class — th-yellow, th-blue
   or th-pink — added by the small roller script in index.html, which
   re-rolls on EVERY load (nothing is stored, so revisits re-roll too).
   No class = the default grey/green palette. Each preset simply remaps
   the :root palette variables, so every component recolours itself with
   no per-component rules. Variable names keep their :root spelling and
   act as role slots here: --accent-green = primary accent,
   --accent-blue = link/secondary accent, --accent-amber = highlight.
   Scoped to ≤999px so the desktop homepage always keeps the default
   palette even when the class is present. Deliberately invariant: the
   hero's blue ink, the near-black subject cards (#0e1017) and the black
   image/hero frames, which are the page's "ink" identity. */
@media (max-width: 999px) {

    /* ── Yellow / honey: warm-tinted charcoals, gold primary ── */
    body.index-page.th-yellow {
        --bg-page:        #1d1a13;
        --bg-container:   #3f392d;
        --bg-card:        #1f1600;
        --bg-header:      #1d1b16;
        --accent-green:   #ceab55;
        --accent-blue:    #cca42c;
        --accent-amber:   #dda26e;
        --border-main:    #503e08;
        --border-accent:  #ceab55;
        --h2-bg:          #221e15;
        --h4-bg:          #35301f;
        --tooltip-bg:     #1d1a13;
        --tooltip-border: #ceab55;
        --dropdown-sum:   #2b2719;
        --dropdown-ans:   #262218;
        --shadow-glow: 0 0 16px rgba(206,171,85,0.15);
    }

    /* ── Blue / frost: cool-tinted charcoals, azure primary, teal highlights ── */
    body.index-page.th-blue {
        --bg-page:        #141a22;
        --bg-container:   #2b384b;
        --bg-card:        #202836;
        --bg-header:      #182029;
        --accent-green:   #7fb3e8;
        --accent-blue:    #a8c8f0;
        --accent-amber:   #6bc4c9;
        --border-main:    #364256;
        --border-accent:  #7fb3e8;
        --h2-bg:          #182029;
        --h4-bg:          #263146;
        --tooltip-bg:     #141a22;
        --tooltip-border: #7fb3e8;
        --dropdown-sum:   #222b3a;
        --dropdown-ans:   #1d2532;
        --shadow-glow:    0 0 16px rgba(127,179,232,0.15);
    }

    /* ── Pink / rose: plum-tinted charcoals, rose primary, lilac links ── */
    body.index-page.th-pink {
        --bg-page:        #1e161c;
        --bg-container:   #261d24;
        --bg-card:        #2b2129;
        --bg-header:      #231a21;
        --accent-green:   #e593b0;
        --accent-blue:    #c0a3e2;
        --accent-amber:   #e8a87c;
        --border-main:    #4a3644;
        --border-accent:  #e593b0;
        --h2-bg:          #231a21;
        --h4-bg:          #3a2a36;
        --tooltip-bg:     #1e161c;
        --tooltip-border: #e593b0;
        --dropdown-sum:   #2c222a;
        --dropdown-ans:   #271e25;
        --shadow-glow:    0 0 16px rgba(229,147,176,0.15);
    }
}