/* =====================================================================
   CoreCraftia - windows.css (Phase 2)
   Layout layer for every window / modal / full-screen scene that sits on
   top of the game: auth, lobby, profile+inventory, adventure journal,
   skills, shop, friends, menu, settings and the small dialogs.

   Rules of this file (same architecture as hud.css):
   - one shell contract for every window: a fixed overlay that pads by the
     safe area, and a panel that never exceeds it and scrolls INSIDE
   - sizes come from tokens + fluid clamps, never from the resolution
   - two width breakpoints (compact <1024, phone <640) plus one height
     modifier (short <480px landscape); no zoom/scale, no JS coordinates
   - cosmetics (colors, borders, fonts) stay in corecraftia-ui.css - this
     file only owns geometry and flow.
   ===================================================================== */

:root{
  --win-pad-t: max(10px, env(safe-area-inset-top));
  --win-pad-r: max(12px, env(safe-area-inset-right));
  --win-pad-b: max(10px, env(safe-area-inset-bottom));
  --win-pad-l: max(12px, env(safe-area-inset-left));
  --win-gap: clamp(8px, 1.2vmin, 14px);
  --win-gap-sm: clamp(6px, 0.9vmin, 10px);
  --win-inner-pad: clamp(10px, 1.6vmin, 18px);
  --win-close: clamp(34px, 4.5vmin, 40px);      /* close buttons */
  --win-touch: 44px;                             /* minimum hit size */
  --win-avail-w: calc(100vw - var(--win-pad-l) - var(--win-pad-r));
  --win-avail-h: calc(100dvh - var(--win-pad-t) - var(--win-pad-b));
}

/* ===================================================================== */
/* 0. Shared shell                                                        */
/* ===================================================================== */
/* overlays: fill the viewport, pad by the safe area, centre the panel.
   Visibility (display:none/flex) stays with the JS that opens them. */
#player-info-modal, #quests-overlay, #skills-overlay, #shop-modal,
#friends-modal, #settings-modal, #menu-overlay,
#news-modal, #gift-overlay, #wheel-overlay, #trade-modal, #trade-qty-overlay,
#trade-final-overlay, #craft-modal, #grant-modal, #drop-modal, #info-modal,
#blast-modal, #worldchanger-modal, #namechanger-modal, #megaphone-modal,
#door-modal, #door2-modal, #lock-modal, #world-key-modal, #world-key-info-modal,
#region-lock-modal, #sign-modal, #mine-modal, #world-ready-overlay,
#npc-interact-overlay, #blast-success,
#blast-overlay, #worldchanger-overlay, #namechanger-overlay{
  position: fixed;
  inset: 0;
  width: auto;
  height: auto;
  min-height: 0;
  max-width: none;
  max-height: none;
  margin: 0;
  box-sizing: border-box;
  padding: var(--win-pad-t) var(--win-pad-r) var(--win-pad-b) var(--win-pad-l);
  align-items: center;
  justify-content: center;
  overflow: hidden;
  transform: none;
  zoom: 1;
}
/* panels: never larger than the padded viewport; simple cards scroll as a
   whole, boards (profile / journal / skills / shop) scroll inside */
#player-info-modal .player-info-card, #quests-modal, #skills-modal, .shop-shell,
.friends-card, .settings-card, #exit-menu, .news-card, .mini-reward-modal,
.trade-modal-box, .trade-qty-box, .trade-final-box, .craft-panel, .grant-box,
.legacy-inventory-modal, #info-content, .blast-box, .door-modal-box, .lock-box,
.world-key-box, #region-lock-modal .modal-content, #sign-modal .modal-content,
.mine-card, .world-ready-card, .npc-interact-card, .megaphone-card{
  box-sizing: border-box;
  position: relative;
  inset: auto;
  max-width: 100%;
  max-height: 100%;
  min-height: 0;
  margin: 0;
  flex: 0 1 auto;
  overflow: auto;
  overscroll-behavior: contain;
  zoom: 1;
}

/* every shell box the legacy sheet used to size with box-sizing */
#player-info-content, .pi-shell, .pi-board, .pi-column, .pi-card, .pi-inventory-tabs, .pi-inventory-grid,
.quests-head, .quests-body, #quests-story-books, .quest-left-shell, .quest-left-list, .quests-board,
.quests-board-top, .quests-main-grid, .quests-list-column, .quests-tabs, .quests-list-panel, .quests-detail,
.skills-head, .skills-body, .skills-panel, .skills-footer, .skills-active-bar,
.shop-shell-header, .shop-layout, .shop-sidebar, .shop-main, #shop-grid,
.friends-search-row, #friends-list, .settings-skin-palette, .exit-menu-actions,
.auth-shell, .auth-hero-wrap, .auth-hero, .auth-card, .auth-rail, .auth-panel, .auth-rail-card,
.lobby-topbar, .lobby-top-left, .lobby-utility-row, .lobby-stage, .lobby-stage-left, .lobby-stage-center,
.lobby-join, .lobby-field, .lobby-grid, .lobby-worlds-panel, .lobby-actions-stack{
  box-sizing: border-box;
}

/* ===================================================================== */
/* 1. Profile / Inventory (#player-info-modal)                            */
/* ===================================================================== */
#player-info-modal{
  align-items: flex-start;              /* card hangs from the top edge */
  padding-top: 0;
  padding-bottom: var(--win-pad-b);
}
#player-info-modal .player-info-card{
  width: min(1320px, 100%);
  margin-top: -6px;                     /* design: card starts 6px above the edge */
  max-height: calc(100% + 6px);
  padding: var(--win-inner-pad);
  display: flex;
  flex-direction: column;
  overflow: hidden;                     /* the board manages its own scroll */
}
#player-info-modal .pinfobutton{ position: absolute; top: 12px; right: 12px; z-index: 5; width: var(--win-close); height: var(--win-close); }
#player-info-content{ display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto; width: 100%; gap: 0; }
#player-info-content .pi-shell{ display: flex; flex-direction: column; gap: var(--win-gap); width: 100%; min-height: 0; flex: 1 1 auto; }
#player-info-content .pi-board{
  display: grid;
  grid-template-columns: minmax(240px, 0.42fr) minmax(0, 1.45fr) minmax(280px, 0.98fr);
  gap: var(--win-gap);
  align-items: stretch;
  width: 100%;
  min-height: 0;
  flex: 1 1 auto;
  overflow: auto;                       /* fallback scroll when the columns are taller than the card */
}
#player-info-content .pi-column{ display: flex; flex-direction: column; gap: var(--win-gap); min-width: 0; min-height: 0 !important; align-self: stretch; }
#player-info-content .pi-inventory-card{ display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto; }
#player-info-content .pi-inventory-tabs{
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  margin: var(--win-gap) 0;
  padding-bottom: 2px;
  -webkit-overflow-scrolling: touch;
}
#player-info-content .pi-inventory-tabs::-webkit-scrollbar{ display: none; }
#player-info-content .pi-inventory-tabs .pi-tab{ flex: 0 0 auto; }
/* hotbar editor inside the profile: wraps instead of overflowing */
#player-info-content .pi-hotbar-editor .pi-hotbar-wrap{ display: flex; flex-wrap: wrap; gap: 8px; }
#player-info-content .pi-hotbar-editor .pi-hotbar-section{ min-width: 0; }
#player-info-content .pi-inventory-grid{
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(clamp(52px, 9vmin, 72px), 1fr));
  gap: 8px;
  align-content: start;
  padding: 8px;
  min-height: 0;
  flex: 1 1 auto;
  max-height: none;
  overflow: auto;
}

/* ===================================================================== */
/* 2. Adventure journal (#quests-overlay)                                  */
/* ===================================================================== */
#quests-overlay{ align-items: flex-start; padding-top: 0; }
#quests-modal{
  width: min(1180px, 100%);
  margin-top: -6px;
  height: min(760px, calc(100% + 6px));  /* desktop: fixed board height (as before) */
  max-height: calc(100% + 6px);
  display: flex;
  flex-direction: column;
  gap: var(--win-gap);
  padding: var(--win-inner-pad);
  overflow: hidden;
}
#quests-modal .quests-head{ position: relative; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex: 0 0 auto; }
#quests-modal .quests-close{ width: var(--win-close); height: var(--win-close); flex: 0 0 auto; }
#quests-modal .quests-body{
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(220px, 0.82fr) minmax(0, 2.18fr);
  gap: var(--win-gap);
  overflow: hidden;
}
#quests-modal #quests-story-books{ min-height: 0; display: flex; flex-direction: column; gap: 12px; overflow: auto; }
#quests-modal .quest-left-shell{ min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: 12px; }
#quests-modal .quest-left-list{ min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: 12px; overflow: auto; }
#quests-modal #quests-list-wrap{ min-width: 0; min-height: 0; display: flex; overflow: hidden; }
#quests-modal .quests-board{ min-width: 0; min-height: 0; flex: 1 1 auto; display: flex; flex-direction: column; gap: var(--win-gap); overflow: hidden; }
#quests-modal .quests-board-top{ flex: 0 0 auto; display: grid; grid-template-columns: minmax(0, 1fr) minmax(260px, 0.52fr); overflow: hidden; }
#quests-modal .quests-main-grid{
  min-width: 0;
  min-height: 0;
  flex: 1 1 0;
  display: grid;
  grid-template-columns: minmax(0, 1.18fr) minmax(0, 0.82fr);
  grid-template-rows: minmax(0, 1fr);
  gap: var(--win-gap-sm);
  align-items: stretch;
}
#quests-modal .quests-list-column{ min-width: 0; min-height: 0; display: flex; flex-direction: column; }
#quests-modal .quests-tabs{ display: flex; flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; flex: 0 0 auto; }
#quests-modal .quests-tabs::-webkit-scrollbar{ display: none; }
#quests-modal .quests-tabs > *{ flex: 0 0 auto; white-space: nowrap; }
#quests-modal .quests-list-panel{ min-width: 0; min-height: 0; flex: 1 1 0; display: flex; flex-direction: column; overflow: hidden; }
#quests-modal .quests-list-panel-scroller{ min-height: 0; flex: 1 1 0; overflow-y: auto; overflow-x: hidden; }
#quests-modal .quests-detail{ min-width: 0; min-height: 0; display: flex; flex-direction: column; overflow: auto; }
#quests-modal .quests-detail-grid{ display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--win-gap-sm); }

/* ===================================================================== */
/* 3. Skills (#skills-overlay) - anchored bottom-right by design          */
/* ===================================================================== */
#skills-overlay{ align-items: flex-end; justify-content: flex-end; }
#skills-modal{
  width: min(1000px, 100%);
  max-height: min(100%, 760px);
  display: flex;
  flex-direction: column;
  padding: var(--win-inner-pad);
  overflow: hidden;
}
#skills-modal .skills-head{ position: relative; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex: 0 0 auto; }
#skills-modal .skills-close{ width: var(--win-close); height: var(--win-close); flex: 0 0 auto; }
#skills-modal .skills-body{
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(180px, 0.72fr) minmax(0, 1.56fr) minmax(200px, 0.68fr);
  gap: var(--win-gap-sm);
  overflow: hidden;
}
#skills-modal .skills-panel{ min-width: 0; min-height: 0; overflow: hidden; }
#skills-modal .skills-categories{ display: flex; flex-direction: column; overflow: auto; }
#skills-modal .skills-main{ display: flex; flex-direction: column; overflow: hidden; }
#skills-modal #skills-grid{
  min-height: 0;
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  grid-auto-rows: max-content;
  align-content: start;
  gap: 8px;
  overflow: auto;
}
#skills-modal .skills-detail{ display: flex; flex-direction: column; overflow: auto; }
#skills-modal .skills-footer{ position: relative; display: flex; flex-direction: column; gap: 6px; flex: 0 0 auto; }
#skills-modal .skills-active-bar{ display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 7px; }

/* ===================================================================== */
/* 4. Shop (#shop-modal)                                                  */
/* ===================================================================== */
#shop-modal .shop-shell{
  width: min(1240px, 100%);
  height: min(750px, 100%);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0 12px;
}
#shop-modal .shop-shell-header{ position: relative; display: flex; align-items: center; justify-content: space-between; gap: 14px; flex: 0 0 auto; min-height: 66px; padding: 15px 230px 0 70px; }
#shop-modal #shop-player-strip{ position: absolute; top: 14px; right: 16px; display: flex; align-items: center; z-index: 4; }
#shop-modal .shop-layout{
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 8px;
  padding: 10px 0 0;
  overflow: hidden;
}
#shop-modal .shop-sidebar{ min-width: 0; min-height: 0; overflow: auto; }
#shop-modal .shop-main{ min-width: 0; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
#shop-modal #shop-grid{
  min-height: 0;
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-auto-rows: 245px;
  gap: 16px;
  align-content: start;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 16px 16px;
}


/* desktop skin of the shop (was a min-width:781px block in the legacy sheet;
   it is the baseline look, the phone rules below adjust it) */
#shop-modal .shop-shell{ border-radius: 20px !important; }
#shop-modal .shop-header-avatar{ left: 14px; top: 11px; width: 48px; height: 58px; }
#shop-modal .shop-header-avatar > *{ transform: scale(.72); }
#shop-modal .shop-shell-kicker{ font-size: 25px !important; }
#shop-modal .shop-shell-tagline{ margin-top: 7px; font-size: 13px; }
#shop-modal .shop-shell-tagline strong{ font-size: 15px; }
#shop-modal .shop-player-wallet{ height: 52px; padding: 5px 14px 5px 52px; border-radius: 10px; }
#shop-modal .shop-player-wallet-value{ font-size: 18px !important; column-gap: 7px; }
#shop-modal .shop-player-wallet-value img,
#shop-modal .shop-player-wallet-value .shop-wallet-coin{ left: 14px; top: 12px; width: 25px; height: 25px; }
#shop-close{ width: 50px !important; height: 50px !important; margin-left: 8px !important; border-radius: 10px !important; font-size: 30px !important; }
#shop-modal .shop-sidebar-card{ padding: 14px 10px 10px !important; border-radius: 17px !important; gap: 8px !important; }
#shop-modal .shop-sidebar-label{ font-size: 12px !important; padding: 0 10px; }
#shop-tabs{ gap: 5px !important; }
.shop-tab{ grid-template-columns: 32px 1fr 31px; min-height: 43px; padding: 5px 8px !important; border-radius: 8px !important; font-size: 13px; }
.shop-tab .shop-tab-icon{ font-size: 18px; }
.shop-tab b{ min-width: 27px; padding: 5px 4px; border-radius: 6px; }
.shop-tab small{ font-size: 9px; }
.shop-coming-soon{ flex-basis: 112px; min-height: 0; margin-top: 5px; padding: 11px 10px; }
.shop-coming-soon strong{ font-size: 11px; }
.shop-coming-soon p{ font-size: 11px; line-height: 1.35; margin: 8px 0; }
.shop-coming-soon span{ font-size: 34px; }
#shop-modal .shop-main{ border-radius: 17px 17px 0 0; }
.shop-grid-toolbar{ height: 44px; padding: 0 13px; }
.shop-grid-toolbar > div{ gap: 9px; font-size: 14px; }
.shop-grid-toolbar button{ width: 37px; height: 34px; border-radius: 7px; font-size: 18px; }
#shop-grid .shop-item{ min-width: 0 !important; max-width: 100% !important; width: auto !important; padding: 8px 14px 10px !important; border-radius: 14px !important; box-sizing: border-box !important; overflow: hidden !important; }
#shop-grid .thumb{ inset: 21px 18px auto !important; width: calc(100% - 36px) !important; height: 94px !important; }
#shop-grid .thumb > *{ transform: scale(.43) !important; }
#shop-grid .name{ font-size: 16px !important; }
#shop-grid .price{ margin-top: 5px !important; font-size: 14px !important; }
#shop-grid .shop-price-value{ font-size: 14px !important; }
#shop-grid .shop-item .price .coin-inline{ width: 15px !important; height: 15px !important; vertical-align: -3px !important; }
#shop-grid .shop-card-footer{ margin-top: 6px !important; }
#shop-grid .shop-buy{ min-height: 31px !important; border-radius: 6px !important; font-size: 14px !important; }

/* ===================================================================== */
/* 5. Friends / Settings / Menu                                           */
/* ===================================================================== */
.friends-card{ width: min(760px, 100%); display: flex; flex-direction: column; gap: var(--win-gap); padding: var(--win-inner-pad); overflow: hidden; }
.friends-card .friends-search-row{ display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; }
.friends-card #friends-list{ min-height: 0; flex: 1 1 auto; max-height: none; overflow: auto; }

.settings-card{ width: min(560px, 100%); padding: clamp(14px, 2vmin, 22px); overflow: auto; }
.settings-card .settings-skin-palette{ display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 10px; }

#menu-overlay{ padding: 0; }
#exit-menu{
  position: fixed;
  inset: 0;
  margin: auto;                         /* centred without transforms */
  width: min(420px, var(--win-avail-w));
  height: fit-content;
  max-height: var(--win-avail-h);
  transform: none;
  overflow: auto;
  padding: var(--win-inner-pad);
}
#exit-menu .exit-menu-actions{ display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
#exit-menu .exit-menu-actions > #cancel-exit{ grid-column: 1 / -1; }

/* ===================================================================== */
/* 6. Auth (#auth) - login / register share one scene                     */
/* ===================================================================== */
#auth{
  position: fixed;
  inset: 0;
  width: auto;
  height: auto;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(12px, 2.5vmin, 40px);
  overflow: hidden;
}
#auth .auth-shell{
  position: relative;
  z-index: 1;
  width: min(1480px, 100%);
  max-height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 0.98fr) minmax(0, 0.82fr) minmax(0, 0.74fr);
  gap: clamp(12px, 1.5vw, 18px);
  align-items: start;
  min-height: 0;
}
#auth .auth-hero-wrap{ position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
#auth .auth-hero{ position: relative; display: flex; flex-direction: column; justify-content: flex-start; min-width: 0; min-height: 0; overflow: hidden; }
#auth .auth-card{ position: relative; display: flex; flex-direction: column; width: 100%; max-width: clamp(290px, 26vw, 350px); min-width: 0; min-height: 0; justify-self: center; overflow: hidden; }
#auth .auth-rail{ position: relative; display: grid; gap: clamp(10px, 1.2vw, 14px); align-content: start; min-width: 0; }

/* ===================================================================== */
/* 7. Lobby (#lobby) - full-screen scene                                  */
/* ===================================================================== */
#lobby{ position: fixed; inset: 0; width: auto; height: auto; box-sizing: border-box; overflow: hidden; }
#lobby .lobby-card{
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  max-height: none;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: var(--win-gap);
  padding: clamp(12px, 2.4vmin, 24px);
  overflow: hidden;
}
#lobby .lobby-topbar{ position: relative; display: flex; align-items: flex-start; justify-content: space-between; gap: var(--win-gap); flex: 0 0 auto; margin: 0; }
#lobby .lobby-top-left{ flex: 1 1 auto; min-width: 0; display: grid; grid-template-columns: minmax(200px, 330px) minmax(0, 1fr); gap: var(--win-gap); align-items: center; }
#lobby .lobby-utility-row{ display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex: 0 0 auto; }
#lobby .lobby-stage{
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(220px, 276px) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  gap: var(--win-gap);
  align-items: stretch;
  overflow: hidden;
}
#lobby .lobby-stage-left{ display: grid; grid-template-rows: auto auto; align-content: start; gap: 12px; min-width: 0; min-height: 0; overflow: auto; }
#lobby .lobby-stage-center{ display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 12px; min-width: 0; min-height: 0; }
#lobby .lobby-join{ display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: center; justify-self: center; width: min(704px, 100%); box-sizing: border-box; }
#lobby .lobby-join .lobby-join-title, #lobby .lobby-join .lobby-hint{ grid-column: 1 / -1; }
#lobby .lobby-field{ min-width: 0; }
#lobby .lobby-grid{ display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; min-height: 0; overflow: hidden; }
#lobby .lobby-worlds-panel{ min-width: 0; min-height: 0; display: flex; flex-direction: column; overflow: auto; }
#lobby .lobby-actions-stack{ display: grid; gap: 10px; }
#lobby .lobby-player-strip{ box-sizing: border-box; max-width: 100%; min-width: 0; }

/* ===================================================================== */
/* 8. Small dialogs (create world / world changer / name changer / etc.)  */
/* ===================================================================== */
.blast-box, .door-modal-box, .lock-box, .world-key-box, .grant-box,
#info-content, .legacy-inventory-modal, .trade-qty-box, .mine-card,
.world-ready-card, .megaphone-card{
  width: min(520px, 100%);
}
.trade-modal-box, .craft-panel, .news-card, .npc-interact-card{ width: min(960px, 100%); }
.mini-reward-modal{ width: min(720px, 100%); }
.mega-card{ width: min(720px, 100%); }
#megaphone-modal .mega-text, .blast-input, #auth input, #lobby input, .settings-card input[type="range"]{ box-sizing: border-box; max-width: 100%; }
#trade-requests-panel{ position: fixed; right: var(--win-pad-r); top: 30%; max-width: min(260px, 60vw); display: flex; flex-direction: column; gap: 10px; z-index: 5000; }

/* ===================================================================== */
/* 9. Breakpoints                                                          */
/* ===================================================================== */
/* ---- compact: < 1024px. Three-column boards become two columns, the
        journal's floor list becomes a horizontal strip, the shop sidebar
        collapses under the header. ---- */
@media (max-width: 1023px){
  :root{ --win-inner-pad: clamp(8px, 1.4vmin, 14px); }
  /* profile: stats | inventory, equipment below */
  #player-info-content .pi-board{ grid-template-columns: minmax(220px, 0.9fr) minmax(0, 1.6fr); }
  #player-info-content .pi-column.pi-right{ grid-column: 1 / -1; }
  #player-info-content .pi-column.pi-right .pi-equipment-card{ min-height: 0; }
  /* journal: floor books as a horizontal strip above the board */
  #quests-modal{ height: calc(100% + 6px); }
  #quests-modal .quests-body{ grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  /* on short screens the whole board scrolls; the quest list keeps a usable height */
  #quests-modal .quests-board{ overflow: auto; }
  #quests-modal .quests-main-grid{ min-height: 260px; }
  #quests-modal #quests-story-books{ flex: 0 0 auto; flex-direction: row; overflow-x: auto; overflow-y: hidden; padding: var(--win-gap-sm); scrollbar-width: thin; }
  #quests-modal .quest-left-shell, #quests-modal .quest-left-list{ flex-direction: row !important; overflow: visible !important; width: max-content; }
  #quests-modal .quest-floor-book{ flex: 0 0 clamp(150px, 26vw, 220px) !important; width: clamp(150px, 26vw, 220px) !important; }
  #quests-modal .quests-main-grid{ grid-template-columns: minmax(0, 1.18fr) minmax(0, 0.82fr); }
  /* skills: categories + grid, detail below */
  #skills-overlay{ align-items: center; justify-content: center; }
  #skills-modal{ width: 100%; max-height: 100%; }
  #skills-modal .skills-body{ grid-template-columns: minmax(150px, 0.6fr) minmax(0, 1.4fr); grid-template-rows: minmax(0, 1fr) minmax(0, 34%); }
  #skills-modal .skills-detail{ grid-column: 1 / -1; max-height: none; }
  /* shop: the category list becomes a horizontal strip above the grid */
  #shop-modal .shop-shell{ height: 100%; padding: 0 8px; }
  #shop-modal .shop-shell-header{ padding: 12px 210px 0 64px; }
  #shop-modal .shop-layout{ grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  #shop-modal #shop-grid{ grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
  #shop-modal .shop-sidebar{ max-height: none; overflow: visible; }
  #shop-modal .shop-sidebar-card{ display: block !important; height: auto !important; }
  #shop-modal #shop-tabs{ display: flex !important; flex-direction: row !important; flex-wrap: nowrap !important; gap: 8px !important; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; padding-bottom: 4px; }
  #shop-modal #shop-tabs::-webkit-scrollbar{ display: none; }
  #shop-modal #shop-tabs .shop-tab{ flex: 0 0 auto !important; width: auto !important; min-width: 0 !important; white-space: nowrap; }
  #shop-modal .shop-coming-soon{ display: none !important; }
  /* auth: hero + card, rail underneath as two cards */
  #auth .auth-shell{ grid-template-columns: minmax(0, 1.08fr) minmax(0, 0.92fr); align-items: start; overflow: auto; }
  #auth .auth-card{ max-width: none; }
  #auth .auth-rail{ grid-column: 1 / -1; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* lobby: left column stacks above the centre; the world panels scroll */
  #lobby .lobby-top-left{ grid-template-columns: minmax(0, 1fr); }
  #lobby .lobby-stage{ grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); overflow: auto; }
  #lobby .lobby-stage-left{ grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-rows: auto; }
  #lobby .lobby-grid{ grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ---- phone: < 640px. Everything is one column and scrolls inside the
        panel; tab rows scroll sideways; grids get fewer columns. ---- */
@media (max-width: 639px){
  :root{ --win-inner-pad: 10px; --win-close: 36px; }
  /* one column: the whole card scrolls, cards keep their natural height */
  #player-info-modal .player-info-card{ margin-top: 0; max-height: 100%; overflow: auto; }
  #player-info-content, #player-info-content .pi-shell{ flex: 0 0 auto; }
  #player-info-content .pi-board{ grid-template-columns: minmax(0, 1fr); grid-auto-rows: auto; align-content: start; flex: 0 0 auto; height: auto; overflow: visible; }
  #player-info-content .pi-column.pi-right{ grid-column: auto; }
  #player-info-content .pi-column > .pi-card{ flex: 0 0 auto !important; }
  #player-info-content .pi-column.pi-center .pi-inventory-card{ flex: 0 0 auto !important; }
  /* hotbar editor inside the profile: wraps instead of overflowing */
#player-info-content .pi-hotbar-editor .pi-hotbar-wrap{ display: flex; flex-wrap: wrap; gap: 8px; }
#player-info-content .pi-hotbar-editor .pi-hotbar-section{ min-width: 0; }
#player-info-content .pi-inventory-grid{ max-height: 46vh; }
  #player-info-content .pi-quick-actions{ grid-template-columns: repeat(4, minmax(0, 1fr)) !important; }

  #quests-modal{ margin-top: 0; max-height: 100%; }
  #quests-modal .quests-board{ overflow: auto; }
  #quests-modal .quests-board-top{ grid-template-columns: minmax(0, 1fr); }
  #quests-modal .quests-main-grid{ grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(320px, 1fr) auto; }
  #quests-modal .quests-list-panel-scroller{ min-height: 240px; }
  #quests-modal .quests-detail{ max-height: none; overflow: visible; }
  #quests-modal .quests-detail-grid{ grid-template-columns: repeat(2, minmax(0, 1fr)); }

  #skills-modal .skills-body{ grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) minmax(0, 34%); }
  /* categories: one horizontal strip; detail card under the grid */
  #skills-modal .skills-categories{ max-height: none; overflow: visible; }
  #skills-modal .skills-category-list{ flex-direction: row !important; flex-wrap: nowrap !important; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
  #skills-modal .skills-category-list::-webkit-scrollbar{ display: none; }
  #skills-modal .skills-category-list > *{ flex: 0 0 auto !important; }
  #skills-modal .skills-detail{ max-height: none; }
  #skills-modal .skills-active-bar{ grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }

  #shop-modal .shop-shell{ padding: 0 6px; }
  /* header: title row, then wallet + close as a second row (no overlap) */
  #shop-modal .shop-shell-header{ padding: 10px 8px 0 96px; min-height: 56px; }
  #shop-modal .shop-shell-kicker, #shop-modal .shop-shell-title{ font-size: clamp(15px, 4.6vw, 22px) !important; line-height: 1.15 !important; }
  #shop-modal #shop-player-strip{ position: static !important; inset: auto !important; width: 100% !important; justify-content: space-between; padding: 4px 0 0; }
  #shop-modal #shop-grid{ grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); grid-auto-rows: 220px; gap: 10px; padding: 0 8px 12px; }

  #exit-menu .exit-menu-actions{ grid-template-columns: minmax(0, 1fr); }
  #news-modal .news-body{ grid-template-columns: minmax(0, 1fr) !important; grid-template-rows: auto !important; overflow: auto !important; }
  #news-modal .news-section{ min-width: 0; }

  #auth{ padding: 8px; align-items: flex-start; }
  #auth .auth-shell{ grid-template-columns: minmax(0, 1fr); gap: 10px; max-height: 100%; overflow: auto; }
  #auth .auth-hero-wrap{ order: 1; }
  #auth .auth-card{ order: 0; max-width: none; }
  #auth .auth-rail{ order: 2; grid-template-columns: minmax(0, 1fr); }

  #lobby .lobby-card{ overflow: auto; }
  #lobby .lobby-topbar{ flex-direction: column; align-items: stretch; }
  #lobby .lobby-utility-row{ justify-content: flex-start; flex-wrap: wrap; }
  #lobby .lobby-stage-left{ grid-template-columns: minmax(0, 1fr); }
  #lobby .lobby-join{ grid-template-columns: minmax(0, 1fr); }
  #lobby .lobby-grid{ grid-template-columns: minmax(0, 1fr); grid-auto-rows: minmax(160px, auto); overflow: visible; }
  #lobby .lobby-worlds-panel{ max-height: 40vh; }
}

/* ---- short: landscape phones (height < 480px). Full-height windows,
        boards scroll as a whole, hanging cards sit flush with the top. ---- */
@media (max-height: 479px) and (min-width: 640px){
  :root{ --win-inner-pad: 8px; --win-pad-t: max(6px, env(safe-area-inset-top)); --win-pad-b: max(6px, env(safe-area-inset-bottom)); }
  #player-info-modal .player-info-card, #quests-modal{ margin-top: 0; max-height: 100%; }
  #player-info-content .pi-board{ overflow: auto; }
  #skills-modal{ max-height: 100%; }
  #skills-modal .skills-detail{ max-height: none; }
  #auth{ padding: 6px; }
  #auth .auth-shell{ max-height: 100%; overflow: auto; }
  #lobby .lobby-card{ overflow: auto; }
  #lobby .lobby-stage{ overflow: visible; }
}
