/* ===== 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 / large phone landscape (≤ 900) ---------- *
   On ≤ 900: HUD becomes a stable top-stack + bottom-stack. JS sets
   --hud-* heights so every fixed element knows where its neighbors
   end — no overlap at any viewport.                                  */
@media (max-width: 900px) {
    .graph-labels { display: none; }                          /* HTML labels overlap on small screens */

    /* Mission menu → horizontal bar slotted directly under top hud
       NOTE: must reset `bottom` — base hud-menu is bottom-anchored (bottom:56px).
       Without `bottom:auto` the element stretches top→bottom (706px on phones),
       which inflates --hud-menu-h and pushes the panel calc off-screen. */
    .hud-menu {
        position: fixed;
        left: 12px; right: 12px;
        top: calc(var(--hud-top-h) + 6px);
        bottom: auto;
        transform: none;
        width: auto; padding: 8px;
    }
    .menu-head, .menu-foot { display: none; }
    .menu-list { flex-direction: row; flex-wrap: wrap; gap: 6px; }
    .menu-btn  { font-size: 11px; padding: 6px 10px; }

    /* Layers panel → bottom drawer parked above hud-bottom */
    .hud-layers {
        top: auto;
        bottom: calc(var(--hud-bottom-h) + 6px);
        left: 12px; right: 12px;
        width: auto;
        flex-direction: row;
        flex-wrap: wrap;
        padding: 8px;
        gap: 4px;
    }
    .hud-layers header { display: none; }
    .layer-btn { width: auto; padding: 5px 9px; }

    /* Operator card — above layers drawer */
    .hud-hero {
        bottom: calc(var(--hud-bottom-h) + var(--hud-layers-h) + 12px);
        max-width: min(94vw, 640px);
        white-space: normal;                                  /* let rows wrap */
        padding: 8px 12px;
        gap: 10px;
    }
    .op-bar { height: 18px; }
    .op-row1, .op-row2 { flex-wrap: wrap; gap: 6px; }

    /* Panel as bottom sheet — fits in middle band between top-stack and bottom-stack */
    .panel {
        top: calc(var(--hud-top-h) + var(--hud-menu-h) + 12px);
        left: 12px; right: 12px;
        bottom: calc(var(--hud-bottom-h) + var(--hud-layers-h) + 12px);
        width: auto;
        max-height: none;
    }
    .p-skillgrid   { grid-template-columns: 1fr; }
    .p-timeline li { grid-template-columns: 1fr; gap: 2px; }
}

/* ---------- Phone (≤ 640) — compact gaming HUD ---------- */
@media (max-width: 640px) {
    :root { --pad: 12px; }

    /* Top bar — drop separators, smaller clock */
    .hud-top { padding: 9px 12px; font-size: 11px; }
    .brand-sep, .hud-sep { display: none; }
    .brand-name { font-size: 12px; }
    .brand-node { font-size: 11px; }
    .hud-status { font-size: 10px; }

    /* Menu — chip row, smaller */
    .hud-menu  { padding: 6px; }
    .menu-btn  { font-size: 10.5px; padding: 5px 8px; gap: 8px; }
    .menu-btn span { font-size: 10px; }

    /* 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; }

    /* Operator card — only name + role */
    .hud-hero {
        padding: 7px 11px;
        gap: 8px;
    }
    .op-row2,
    .op-hint,
    .op-tag,
    .op-eyebrow { display: none; }
    .op-name { font-size: 12.5px; }
    .op-role { font-size: 10.5px; }

    /* Layers — compress dot only */
    .hud-layers { padding: 6px; gap: 3px; }
    .layer-btn  { padding: 4px 7px; font-size: 10.5px; }
    .layer-btn .lb { font-size: 10px; }

    /* 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; }   /* hide keyboard-only hints (4th+) */
    .hud-tag { display: none; }

    /* Panel typography compact */
    .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; }
}

/* ---------- 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; }
}

/* ---------- 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; }
}

/* ---------- 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 */
}
