/* ===== v2026 · responsive ladder — phone-portrait → 4K TV =====
   Breakpoints:
     ≤ 480   phones portrait
     ≤ 640   phones landscape / phablets
     ≤ 900   small tablets / portrait iPad
     ≤ 1200  tablets / small laptops
     ≥ 2200  4K / large displays
     ≥ 3200  8K / ultra-wide tv
   Modifier media:
     (pointer: coarse)         touch devices — hide crosshair, native cursor
     (orientation: portrait)   portrait tweaks for tablets/phones
   Component-local @media (e.g. invader-hud at ≤ 640, desktop-bar at ≤ 640,
   p-era at ≤ 640) live next to the component so the file stays focused.
   ============================================================================ */

/* ---------- Tablet (≤ 1200) — narrower panel, hide secondary stats ---------- */
@media (max-width: 1200px) {
    .hud-stats { display: none; }
    .hud-layers { top: 64px; }       /* slot under top bar since stats are gone */
    .panel { width: min(520px, 60vw); }
}

/* ---------- Small tablet / phone (≤ 900) — pill / drawer pattern ----------
   At ≤ 900 every narrow viewport (phone portrait → small iPad portrait)
   uses the same pill pattern: menu + layers collapse into small pills
   anchored under the top bar. Tap to expand a vertical drawer, tap an
   item to act + auto-collapse. The horizontal chip-row attempt was
   wrapping (9 missions + 5 layers) and sandwiching the panel into a
   sliver with no body room.
   The second media term catches large phones in LANDSCAPE: their width can
   exceed 900 (e.g. 932) but a touch device that short (≤500 tall) is a phone,
   not a laptop — so it gets the same pill UX. Big tablets in landscape
   (height > 500) stay on the desktop layout. */
@media (max-width: 900px), (pointer: coarse) and (max-height: 500px) {
    /* Node labels stay visible on touch/small screens (per request). Shrink the
       primary card + mini chips so 9 missions + 5 stacks crowd less. */
    .graph-label-primary { padding: 5px 9px; gap: 1px; }
    .graph-label-primary .gl-name  { font-size: 11px; }
    .graph-label-primary .gl-stack { font-size: 8.5px; }
    .graph-label-mini { font-size: 8.5px; padding: 2px 5px; }
    :root { --pad: 12px; }

    /* Top bar — drop separators, smaller type. Clock + status label stay
       visible (per request); a min gap keeps the brand from gluing to them. */
    .hud-top { padding: 9px 12px; font-size: 11px; }
    .brand-sep, .hud-sep { display: none; }
    .brand-name { font-size: 12px; }
    .brand-node { font-size: 11px; }
    .brand-role { display: none; }                            /* keep top bar single-line */
    .hud-clock { font-size: 11px; }                           /* base is 14.5px — shrink so it fits beside the brand */
    .hud-status { font-size: 10px; white-space: nowrap; }
    .hud-brand { flex: 0 0 auto; min-width: 0; }              /* hug content — never shrink the box under the text (was overlapping the clock) */
    .hud-meta { gap: 7px; flex: 0 1 auto; padding-left: 10px; min-width: 0; }

    /* MENU pill — anchor top-left under top bar.
       NOTE: must reset `bottom` — base hud-menu is bottom-anchored;
       without `bottom:auto` the element stretches top→bottom and
       inflates --hud-menu-h, pushing the panel calc off-screen. */
    .hud-menu {
        position: fixed;
        top: calc(var(--hud-top-h) + 8px);
        bottom: auto;
        left: 12px; right: auto;
        transform: none;
        width: auto;
        max-width: calc(100vw - 24px);
        padding: 6px 10px;
        background: rgba(7, 11, 24, 0.88);
        border: 1px solid var(--border-2);
        border-radius: 10px;
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
    }
    .hud-menu .menu-head { display: flex; font-size: 10.5px; }
    .hud-menu .menu-foot { display: none !important; }
    .hud-menu .menu-list {
        flex-direction: column !important;
        flex-wrap: nowrap !important;
        gap: 2px;
        width: 230px;
        max-width: calc(100vw - 48px);
    }
    .hud-menu .menu-btn { width: 100%; font-size: 12px; padding: 8px 10px; gap: 10px; }
    .hud-menu .menu-btn span { font-size: 11px; }
    .hud-menu.collapsed { padding: 6px 10px; min-width: 0; }
    .hud-menu.collapsed .menu-head { padding: 0; margin: 0; border-bottom: none; }
    /* Collapsed pill must size to its header only. The hidden drawer keeps its
       explicit width (230/210px) and would stretch the auto-width pill, making
       the two pills overlap on a narrow phone. Zero it while folded. */
    .hud-menu.collapsed .menu-list { width: 0; min-width: 0; }

    /* LAYERS pill — anchor top-right under top bar (mirror of menu) */
    .hud-layers {
        top: calc(var(--hud-top-h) + 8px);
        bottom: auto;
        right: 12px; left: auto;
        width: auto;
        max-width: calc(100vw - 24px);
        padding: 6px 10px;
        background: rgba(7, 11, 24, 0.88);
        border: 1px solid var(--border-2);
        border-radius: 10px;
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        flex-direction: column;
        flex-wrap: nowrap;
        gap: 2px;
    }
    .hud-layers .layers-head { display: flex; font-size: 10.5px; padding-bottom: 6px; margin-bottom: 6px; }
    .hud-layers .layer-btn {
        width: 200px;
        max-width: calc(100vw - 48px);
        font-size: 12px;
        padding: 7px 10px;
        gap: 10px;
        justify-content: flex-start;
    }
    .hud-layers .layer-btn .lb { font-size: 10.5px; opacity: 0.7; }
    .hud-layers.collapsed { padding: 6px 10px; min-width: 0; }
    .hud-layers.collapsed .layers-head { padding: 0; margin: 0; border-bottom: none; }
    /* Same as the menu pill — fold the hidden buttons' width so the STACKS
       pill shrinks to its header and clears the MISSIONS pill. */
    .hud-layers.collapsed > .layer-btn { width: 0; min-width: 0; }

    /* Operator card — compact, above bottom hud */
    .hud-hero {
        bottom: calc(var(--hud-bottom-h) + 12px);
        max-width: min(94vw, 520px);
        white-space: normal;
        padding: 7px 11px;
        gap: 8px;
    }
    .op-bar { height: 18px; }
    .op-row1, .op-row2 { flex-wrap: wrap; gap: 6px; }
    .op-row2, .op-hint, .op-tag, .op-eyebrow { display: none; }
    .op-name { font-size: 12.5px; }
    .op-role { font-size: 10.5px; }

    /* Bottom HUD — strip non-essentials, single line */
    .hud-bottom {
        padding: 8px 12px;
        font-size: 10px;
        flex-wrap: wrap;
        gap: 4px;
        overflow: hidden;
        white-space: nowrap;
    }
    .hud-controls {
        overflow: hidden;
        text-overflow: ellipsis;
        flex: 1 1 auto;
        min-width: 0;
    }
    .hud-controls kbd:nth-of-type(n+4) { display: none; }
    .hud-tag { display: none; }

    /* Panel — full middle band between top bar and bottom hud.
       At ≤900 the pills sit on top of the panel (overlay), so the
       panel can use the full vertical space without subtracting
       --hud-menu-h / --hud-layers-h. */
    .panel {
        top: calc(var(--hud-top-h) + 12px);
        left: 12px; right: 12px;
        bottom: calc(var(--hud-bottom-h) + 12px);
        width: auto;
        max-height: none;
    }
    .panel-head { padding: 10px 14px; font-size: 10px; }
    .panel-body { padding: 16px 16px 22px; }
    .p-title    { font-size: clamp(18px, 5vw, 24px); }
    .p-node-title { font-size: clamp(20px, 6vw, 28px); }
    .p-lead     { font-size: 13.5px; }
    .p-bullets li { font-size: 13px; }
    .p-skillgrid   { grid-template-columns: 1fr; }
    .p-timeline li { grid-template-columns: 1fr; gap: 2px; }
}

/* ---------- Phone (≤ 640) — extra-tight delta on top of the ≤900 pill rule ---------- */
@media (max-width: 640px) {
    /* Even narrower drawers + tighter type */
    .hud-menu .menu-list   { width: 210px; }
    .hud-layers .layer-btn { width: 184px; }

    /* Boot card compact */
    .boot-card     { padding: 20px 22px 18px; width: 92vw; }
    .boot-title    { font-size: 16px; }
    .boot-subtitle { font-size: 9.5px; }
    .boot-log      { font-size: 11.5px; }
    .boot-mark     { font-size: 24px; }
}

/* ---------- Phone portrait (≤ 480) — strip to bare essentials ---------- */
@media (max-width: 480px) {
    .hud-top .hud-meta { gap: 6px; }
    .hud-status > .dot-pulse { width: 6px; height: 6px; }

    .hud-hero   { display: none; }                             /* operator card off — too crowded */

    /* Mission menu — tight chips */
    .hud-menu  { padding: 4px; }
    .menu-btn  { font-size: 10px; padding: 5px 8px; gap: 6px; min-width: 0; }
    .menu-list { gap: 4px; }

    /* Bottom HUD — only first 3 hints */
    .hud-bottom { padding: 6px 10px; font-size: 9.5px; }
    .hud-controls kbd:nth-of-type(n+3) { display: none; }

    /* Layers compact */
    .hud-layers { padding: 5px; }
    .layer-btn  { font-size: 9.5px; padding: 3px 6px; }

    /* Boot — even more compact */
    .boot-card     { padding: 16px 18px 14px; }
    .boot-title    { font-size: 14px; letter-spacing: 0.12em; }
    .boot-subtitle { font-size: 9px; }
    .boot-log      { font-size: 10.5px; }
    .boot-mark     { font-size: 22px; }
    .boot-tag      { min-width: 26px; font-size: 9px; }

    .panel-no    { font-size: 11px; }
    .p-chips     { gap: 4px; }
    .p-chip      { font-size: 9.5px; padding: 2px 6px; }
}

/* ---------- Phone ONLY (≤ 640 + landscape phones) — hide STACKS, MISSIONS full-screen ----------
   Tablets (> 640) keep the two-pill layout. On a phone the layers/STACKS pill
   is dropped entirely and the MISSIONS menu, when opened, becomes a full-screen
   overlay (big tap rows). Collapsed it's still the small top-left pill. */
@media (max-width: 640px), (pointer: coarse) and (max-height: 500px) {
    /* Drop the STACKS pill on phones — too cramped beside MISSIONS */
    .hud-layers { display: none !important; }

    /* Expanded MISSIONS = full-screen sheet, animated open ("efeito de abrir") */
    .hud-menu:not(.collapsed) {
        position: fixed;
        inset: 0;
        top: 0; left: 0; right: 0; bottom: 0;
        width: 100vw; max-width: none;
        height: 100vh; height: 100dvh;
        transform: none;
        margin: 0; padding: 0;
        border: none;
        border-radius: 0;
        background: rgba(5, 8, 18, 0.97);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
        display: flex;
        flex-direction: column;
        z-index: 40;
        animation: phone-menu-in 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
    }
    /* Sheet fades + lifts in; rows cascade up underneath */
    @keyframes phone-menu-in {
        from { opacity: 0; transform: translateY(16px); }
        to   { opacity: 1; transform: translateY(0); }
    }
    .hud-menu:not(.collapsed) .menu-list {
        animation: phone-menu-rows-in 0.55s 0.08s cubic-bezier(0.22, 1, 0.36, 1) both;
    }
    @keyframes phone-menu-rows-in {
        from { opacity: 0; transform: translateY(10px); }
        to   { opacity: 1; transform: translateY(0); }
    }
    .hud-menu:not(.collapsed) .menu-head {
        flex: 0 0 auto;
        padding: 18px 20px;
        font-size: 13px;
        letter-spacing: 0.16em;
        border-bottom: 1px solid var(--border-2);
    }
    .hud-menu:not(.collapsed) .menu-head .hud-toggle {
        width: 40px; height: 40px;
        font-size: 24px; line-height: 1;
    }
    .hud-menu:not(.collapsed) .menu-list {
        flex: 1 1 auto;
        width: 100%; max-width: none;
        gap: 0;
        padding: 4px 0;
        overflow-y: auto;
        justify-content: flex-start;
    }
    .hud-menu:not(.collapsed) .menu-btn {
        width: 100%;
        font-size: 16px;
        padding: 18px 24px;
        gap: 14px;
        border-radius: 0;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    }
    .hud-menu:not(.collapsed) .menu-btn span { font-size: 15px; }
    .hud-menu:not(.collapsed) .menu-btn span:first-child { opacity: 0.5; min-width: 22px; }

    /* Popups open OVER the full-screen MISSIONS sheet (z 40) — phone only */
    .panel { z-index: 50; }
}

/* ---------- 4K TV / big display (≥ 2200) — scale typography + breathing room ---------- */
@media (min-width: 2200px) {
    :root {
        --pad: 40px;
    }
    html { font-size: 18px; }                                  /* root scale for relative units */
    .hud-top    { padding: 22px var(--pad); font-size: 14px; }
    .hud-bottom { padding: 16px var(--pad); font-size: 13px; }
    .hud-menu   { width: 280px; padding: 18px; font-size: 14px; }
    .menu-btn   { font-size: 14.5px; padding: 11px 14px; }
    .hud-stats  { font-size: 13px; padding: 16px 18px; gap: 8px 22px; }
    .hud-layers { width: 220px; padding: 14px 16px; top: 270px; }
    .layer-btn  { font-size: 13px; padding: 9px 10px; }
    .panel      { width: min(720px, 38vw); }
    .panel-head { padding: 18px 22px; font-size: 13px; }
    .panel-body { padding: 28px 28px 32px; }
    .hud-hero   { padding: 14px 22px; max-width: min(1000px, 60vw); }
    .op-name    { font-size: 17px; }
    .op-role    { font-size: 13px; }
    .boot-card  { width: min(720px, 42vw); }
    .boot-title { font-size: 22px; }
    .boot-log   { font-size: 14px; }
}

/* ---------- 8K-ish / ultra-wide (≥ 3200) ---------- */
@media (min-width: 3200px) {
    :root { --pad: 56px; }
    html { font-size: 20px; }
    .hud-menu   { width: 340px; }
    .panel      { width: min(900px, 32vw); }
}

/* ---------- Touch devices: no crosshair, native cursor ---------- */
@media (pointer: coarse) {
    .reticle { display: none; }
    #webgl   { cursor: default; }
    #webgl.dragging { cursor: grabbing; }
    /* Bigger tap targets */
    .menu-btn    { min-height: 36px; }
    .layer-btn   { min-height: 34px; }
    .panel-close { width: 36px; height: 36px; }

    /* Keyboard-hint footer (DRAG/WHEEL/CLICK/ESC) is meaningless on touch and
       was overflowing into an `op…` ellipsis. Drop it entirely. */
    .hud-bottom  { display: none; }
}

/* ---------- Portrait orientation on phones/tablets — extra vertical room for canvas ---------- */
@media (orientation: portrait) and (max-width: 900px) {
    .hud-menu  { top: 50px; }      /* tighter under top bar */
}
