/* ============================================================================
   HOLLOWCROSS — MOBILE / RESPONSIVE LAYER
   Loaded LAST so it overrides. Keeps the gothic gold-on-dark theme; makes every
   screen fit phones in BOTH portrait and landscape with no sideways scroll.
   "Mobile mode" = narrow width (<=768px) OR a short landscape viewport (phones
   held sideways, which can be wide but short).
   ============================================================================ */

/* ---- base (all sizes): controls live hidden on desktop ---- */
.nav-toggle { display: none; }
.nav-backdrop { display: none; }
#nav-switchmode { display: none; }   /* drawer-only; desktop has the topbar mode button */
img, video, svg { max-width: 100%; }

/* ============================================================================
   DESKTOP / WINDOWED (769–1499px, tall enough to not be a landscape phone).
   The full inline nav is 11 tabs + brand + gems + profile + mode + logout, which
   needs ~1500px. Below that (incl. the Steam desktop app, whose window is
   960px-and-up and freely resized) the tabs truncate. So collapse JUST the nav
   into the hamburger drawer and keep the rest of the topbar inline at full size.
   The short-landscape-phone case (max-height 560) is handled by the mobile block
   below, so exclude it here with min-height.
   ============================================================================ */
@media (min-width: 769px) and (max-width: 1499px) and (min-height: 561px) {
  #topbar { gap: 10px; padding: 8px 14px; }
  #topbar .nav-toggle {
    display: inline-flex; align-items: center; justify-content: center; order: -1;
    width: 40px; height: 40px; min-width: 40px; font-size: 19px; line-height: 1;
    background: none; border: 1px solid #3a3340; color: var(--gold);
    border-radius: 8px; padding: 0; flex: 0 0 auto;
  }
  /* nav element -> slide-in drawer from the left */
  #topbar-nav, #topbar nav {
    position: fixed; top: 0; left: 0; z-index: 60;
    width: min(320px, 42vw); height: 100vh; max-height: 100vh;
    display: flex; flex-direction: column; align-items: stretch; gap: 5px;
    background: #120f16; border-right: 1px solid var(--gold);
    padding: 60px 12px 20px; overflow-y: auto;
    transform: translateX(-105%); transition: transform .22s ease;
    box-shadow: 8px 0 40px rgba(0,0,0,.65);
  }
  body.nav-open #topbar-nav, body.nav-open #topbar nav { transform: translateX(0); }
  #topbar-nav .navbtn {
    width: 100%; text-align: left; padding: 12px 14px; font-size: 15px;
    border: 1px solid transparent; border-radius: 8px; color: var(--ink);
    white-space: nowrap; min-height: 44px;
  }
  #topbar-nav .navbtn.active { background: #1d1826; border-color: var(--gold); color: var(--gold); }
  #topbar-nav .navbtn.hidden { display: none !important; }
  .nav-backdrop {
    display: block; position: fixed; inset: 0; z-index: 55;
    background: rgba(4,3,6,.62); opacity: 0; pointer-events: none; transition: opacity .2s ease;
  }
  body.nav-open .nav-backdrop { opacity: 1; pointer-events: auto; }
  /* keep everything on one line and let long labels ellipsize instead of clipping */
  #topbar .gems, #topbar .mode-switch, #topbar #btn-logout { white-space: nowrap; flex: 0 0 auto; }
  .pf-widget { flex: 0 1 auto; min-width: 0; }
  .pf-widget-name { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* Tight desktop windows near the 960px app minimum: drop the brand wordmark and the
   XP bar so the right-side cluster never overflows. */
@media (min-width: 769px) and (max-width: 1120px) and (min-height: 561px) {
  #topbar .brand { display: none; }
  #topbar .mode-switch #cur-mode-label { max-width: 74px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; vertical-align: bottom; }
}

/* ============================================================================
   MAIN MOBILE BLOCK  — width<=768px  OR  short landscape
   ============================================================================ */
@media (max-width: 768px), (orientation: landscape) and (max-height: 560px) {

  /* --- hard stop on horizontal scroll (clip, not hidden: hidden breaks the sticky
         topbar because it turns body into a scroll container) --- */
  html, body { overflow-x: clip; max-width: 100%; }
  .screen { min-height: 100svh; }
  #game { min-height: 100svh; padding: 6px; }

  /* --- kill the fixed min-widths that force flex rows wider than the screen --- */
  .hero { min-width: 0; flex: 1 1 auto; padding: 6px 10px; }
  .hero-row { gap: 8px; flex-wrap: wrap; }
  .hub-card { min-width: 0; }
  .an-mode { min-width: 0; flex-basis: 100%; }
  .sb-costslider, .sb-totem, .guild-create input, .q-reward, .q-action { min-width: 0; }

  /* ===================== TOPBAR -> HAMBURGER DRAWER ===================== */
  .nav-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    width: 42px; height: 42px; min-width: 42px; font-size: 20px; line-height: 1;
    background: none; border: 1px solid #3a3340; color: var(--gold);
    border-radius: 8px; padding: 0; flex: 0 0 auto; letter-spacing: 0;
  }
  #topbar {
    flex-wrap: nowrap; gap: 6px; padding: 6px 8px; align-items: center;
    position: sticky; top: 0;
  }
  #topbar .brand { display: none; }
  #topbar .spacer { flex: 1 1 auto; }

  /* the nav element becomes a slide-in drawer from the left */
  #topbar-nav, #topbar nav {
    position: fixed; top: 0; left: 0; z-index: 60;
    width: min(82vw, 320px); height: 100svh; max-height: 100svh;
    display: flex; flex-direction: column; align-items: stretch; gap: 5px;
    background: #120f16; border-right: 1px solid var(--gold);
    padding: 60px 12px calc(20px + env(safe-area-inset-bottom)); overflow-y: auto;
    transform: translateX(-105%); transition: transform .22s ease;
    box-shadow: 8px 0 40px rgba(0,0,0,.65); order: 0; width: min(82vw, 320px);
  }
  body.nav-open #topbar-nav, body.nav-open #topbar nav { transform: translateX(0); }
  #topbar-nav .navbtn {
    width: 100%; text-align: left; padding: 14px 14px; font-size: 16px;
    border: 1px solid transparent; border-radius: 8px; color: var(--ink);
    white-space: normal; min-height: 48px;
  }
  #topbar-nav .navbtn.active { background: #1d1826; border-color: var(--gold); color: var(--gold); }
  #topbar-nav .navbtn.hidden { display: none !important; }

  /* backdrop behind the drawer */
  .nav-backdrop {
    display: block; position: fixed; inset: 0; z-index: 55;
    background: rgba(4,3,6,.62); opacity: 0; pointer-events: none;
    transition: opacity .2s ease;
  }
  body.nav-open .nav-backdrop { opacity: 1; pointer-events: auto; }

  /* compact right-side cluster: half-size STACKED gems/credits + avatar + mode + logout */
  #topbar { gap: 5px; padding: 6px 8px; }
  #topbar .gems {
    display: inline-flex; flex-direction: column; align-items: flex-end;
    font-size: 10px; line-height: 1.18; letter-spacing: 0; flex: 0 0 auto;
  }
  #topbar .gems .cur, #topbar .gems .cred, #topbar .gems .lvl,
  #topbar .gems .cur.cred { display: block; margin: 0; }
  #pf-widget .pf-widget-meta { display: none; }
  #pf-widget { padding: 0; gap: 0; flex: 0 0 auto; }
  #pf-widget .pf-widget-av { width: 32px; height: 32px; }
  #btn-switchmode { padding: 6px 8px; font-size: 12px; min-height: 38px; flex: 0 0 auto; }
  #btn-switchmode #cur-mode-label { display: none; }   /* keep just the ⇄ glyph */
  #btn-logout { padding: 6px 8px; font-size: 11px; min-height: 38px; flex: 0 0 auto; white-space: nowrap; }

  /* ===================== GENERIC SCREEN / PANEL FLUIDITY ===================== */
  .lobby-box, .demo-box, .launch-box { width: min(560px, 94vw); padding: 22px 16px; }
  .auth-box { width: min(460px, 94vw); padding: 26px 18px; }

  /* any card/tile grid collapses sensibly instead of overflowing */
  .modes-grid { grid-template-columns: 1fr; }
  .souls-lobby-grid, .souls-builder { grid-template-columns: 1fr; }
  .ach-grid { grid-template-columns: 1fr 1fr; }
  .reveal-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  /* wide tables scroll INSIDE their own box, never the page */
  table, .an-table { display: block; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* full-screen-ish modals/overlays */
  .demo-overlay .demo-box { width: 96vw; max-height: 92svh; }
  .hcs-overlay { padding: 8px; }
  .hcs-ov-box { width: 96vw; max-height: 94svh; }

  /* Siege/Souls lobby action row (Practice vs Bot / Find Opponent / Deck Builder):
     shrink the font ~3 sizes so all three fit the row instead of being clipped. */
  .souls-lobby-btns { gap: 5px; }
  .souls-lobby-btns button { font-size: 10px; padding: 8px 8px; letter-spacing: 0; min-height: 36px; min-width: 0; white-space: nowrap; flex: 0 1 auto; overflow: visible; }

  /* Deck builders (siege + souls) are a 2-column grid (pool + 320px deck panel) set
     via inline style — force a single stacked column on phones so they stop overlapping. */
  .siege-builder, .souls-builder { grid-template-columns: 1fr !important; }

  /* Siege deploy hand: FULL-size cards in a swipeable fan. The front card reads clearly
     (highest z), the rest tuck ~⅓ behind (still glowing when playable) and slide out as
     you scroll across; the focused/tapped card pops forward. */
  #siege-hand {
    justify-content: flex-start !important;
    overflow-x: auto; overflow-y: visible;
    gap: 0 !important; min-height: 104px !important;
    padding: 6px 30% 8px 10px !important;
    -webkit-overflow-scrolling: touch; scroll-snap-type: x proximity;
  }
  #siege-hand .souls-hcard { width: 66px !important; flex: 0 0 66px; margin-right: -20px; scroll-snap-align: start; }
  #siege-hand .souls-hcard:last-child { margin-right: 0; }
  #siege-hand .souls-hcard.picked, #siege-hand .souls-hcard:hover { z-index: 99 !important; transform: translateY(-8px); }

  /* switch-mode entry only appears inside the drawer (topbar has its own on desktop) */
  #nav-switchmode { display: block; }

  /* comfortable touch targets + readable base text */
  button, .navbtn, .buy, .big, .tab, input, select, .sb-chan {
    min-height: 40px;
  }
  input, select, textarea { font-size: 16px; }   /* >=16px stops iOS zoom-on-focus */

  /* the live battle canvas already fits width:100%; give it more of the screen */
  .battle-stage { height: 60svh; }
}

/* Siege runs a VERTICAL field in portrait (your keep bottom, enemy top), so the
   deploy lane-picker must be 3 COLUMNS (left/mid/right lanes) to match, not rows. */
@media (orientation: portrait) {
  #siege-lanepick { flex-direction: row !important; }
  #siege-lanepick > [data-lane] { margin: 8px 3px !important; }
}

/* ============================================================================
   PORTRAIT PHONES (narrow) — denser cards + single-column extras
   ============================================================================ */
@media (max-width: 480px) {
  .ach-grid { grid-template-columns: 1fr; }
  .card { width: 104px; height: 146px; }        /* proven size (matches demo cells) */
  .big-card .card.bigcard { width: min(70vw, 240px); height: auto; aspect-ratio: 12 / 17; }
  .title { font-size: 34px; letter-spacing: 4px; }
  #logo { max-width: 220px; }
  .hero-portrait { width: 46px; height: 46px; }
}

/* ============================================================================
   LANDSCAPE PHONES (wide but short) — reclaim vertical space
   ============================================================================ */
@media (orientation: landscape) and (max-height: 560px) {
  #topbar { padding: 4px 8px; }
  #topbar-nav, #topbar nav { padding-top: 52px; width: min(60vw, 300px); }
  .battle-stage { height: 78svh; }           /* board gets most of the short screen */
  .lobby-box, .auth-box { padding: 16px 18px; }
  .auth-box { width: min(520px, 92vw); }
}
