/* Popout shell for every in-game panel (popout-shell.js). One kit sheet:
   header (eyebrow, title, status, BACK) · rail (kit tabs) · body (scrolling
   content grid) · footer (actions). Sizes follow data-size; the panel sits in
   the band under the top HUD row (hud-layout.js: --hud-safe-* and --hud-scale)
   so it never covers the stats, toolbar or callout. Themed by the kit tokens
   (html[data-i8-theme]), so every UI theme keeps its WCAG contrast. */
.sled-stage .sled-popout, .leave-confirm-dialog.sled-popout {
  --popout-top: calc(var(--hud-safe-t, 10px) + 84px * var(--hud-scale, 1) + 12px);
  --popout-w: 1180px;
  box-sizing: border-box; position: fixed; inset: var(--popout-top) var(--hud-safe-r, 10px) var(--hud-safe-b, 10px) var(--hud-safe-l, 10px);
  width: min(calc(var(--popout-w) * var(--hud-scale, 1)), calc(100% - var(--hud-safe-l, 10px) - var(--hud-safe-r, 10px))); max-width: 100%; max-height: calc(100% - var(--popout-top) - var(--hud-safe-b, 10px));
  margin: 0 auto; padding: 0; border: 0; border-radius: var(--i8-r-panel); color: var(--i8-text); font-family: var(--i8-font);
  background: transparent; overflow: visible;
}
.sled-popout[data-size="medium"] { --popout-w: 760px; }
.sled-popout[data-size="compact"] { --popout-w: 520px; margin-block: auto; max-height: min(60%, 420px); }
.sled-popout::backdrop { background: rgba(3, 4, 10, .66); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.sled-popout > .sled-popout__frame {
  display: flex; flex-direction: column; width: 100%; max-height: 100%; height: auto; min-height: 0; padding: 0; border-radius: inherit;
  background: var(--i8-grad-glass), var(--i8-glass-bg-strong);
  box-shadow: 0 0 0 1.5px var(--i8-accent), 0 0 0 3px rgba(139, 92, 246, .28), var(--i8-shadow), 0 0 36px rgba(139, 92, 246, .3);
}
/* An open popout is a column box, so its max-height (the band) bounds the
   frame and the body scrolls. A percentage frame height alone resolved
   against the dialog's fit-content height and let a long list (Race & Map
   selector, Hub activities) run off the bottom of the screen. Wide fills the
   band; medium and compact keep their content height up to it. */
.sled-stage .sled-popout[open], .leave-confirm-dialog.sled-popout[open] { display: flex; flex-direction: column; }
.sled-popout > .sled-popout__frame { flex: 0 1 auto; }
.sled-stage .sled-popout[data-size="wide"] { height: auto; }
.sled-popout[data-size="wide"] > .sled-popout__frame { flex: 1 1 auto; height: auto; }
.sled-popout__head { flex: none; align-items: flex-start; padding: var(--i8-s3) var(--i8-s4) var(--i8-s2); background: linear-gradient(90deg, rgba(77, 232, 255, .08), rgba(230, 76, 255, .08)); border-bottom: 1px solid var(--i8-line-soft); border-radius: var(--i8-r-panel) var(--i8-r-panel) 0 0; }
.sled-popout__titles { display: grid; min-width: 0; gap: 2px; }
.sled-popout__title { margin: 0; font: 800 clamp(18px, 2.4vw, 26px)/1.15 var(--i8-font-display); letter-spacing: .04em; text-transform: uppercase; background: var(--i8-grad-chrome); -webkit-background-clip: text; background-clip: text; color: transparent; overflow-wrap: anywhere; }
.sled-popout__status { margin: 0; font-size: var(--i8-fs-sm); }
.sled-popout__status:empty { display: none; }
.sled-popout__close { flex: none; }
.sled-popout__body { flex: 1 1 auto; display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--i8-s3); align-items: start; min-height: 0; padding: var(--i8-s3) var(--i8-s4); overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; scrollbar-width: thin; scrollbar-color: var(--i8-violet) transparent; }
.sled-popout[data-size="wide"] .sled-popout__body:has(> .sled-popout__rail) { grid-template-columns: minmax(170px, 220px) minmax(0, 1fr); }
.sled-popout__rail { position: sticky; top: 0; z-index: 2; display: flex; flex-direction: column; align-items: stretch; gap: 4px; padding: 6px; }
.sled-popout__rail > button { flex: none; justify-content: flex-start; min-height: var(--i8-touch); text-align: left; }
.sled-popout__rail > button[aria-selected="true"] { box-shadow: inset 3px 0 0 var(--i8-accent), var(--i8-inset); }
.sled-popout[data-size="medium"] .sled-popout__rail, .sled-popout[data-size="compact"] .sled-popout__rail { flex-direction: row; flex-wrap: wrap; }
.sled-popout__panels { display: grid; min-width: 0; gap: var(--i8-s3); }
.sled-popout__panel { display: grid; gap: var(--i8-s2); min-width: 0; }
.sled-popout__panel[hidden] { display: none !important; }
.sled-popout__panel > p { margin: 0; color: var(--i8-text-soft); line-height: 1.5; }
.sled-popout__panel > p[role="status"]:empty { display: none; }
.sled-popout__panel > h3, .sled-popout__panel > h4 { margin: var(--i8-s2) 0 0; color: var(--i8-cyan); font: 800 var(--i8-fs-md)/1.2 var(--i8-font-display); letter-spacing: var(--i8-track); text-transform: uppercase; }
/* Content grid: option lists reflow from one column on phones to two or three on wide panels. */
.sled-popout__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); gap: var(--i8-s2); }
.sled-popout__panel > button:not(.i8-icon-btn), .sled-popout__grid > button, .sled-popout__list > button { display: flex; align-items: center; justify-content: flex-start; width: 100%; min-height: var(--i8-touch); margin: 0; text-align: left; white-space: normal; overflow-wrap: anywhere; }
.sled-popout__list { display: grid; gap: var(--i8-s2); }
.sled-popout__foot { flex: none; align-items: center; justify-content: flex-end; gap: var(--i8-s2); padding: var(--i8-s2) var(--i8-s4) var(--i8-s3); border-top: 1px solid var(--i8-line-soft); background: rgba(9, 12, 24, .5); border-radius: 0 0 var(--i8-r-panel) var(--i8-r-panel); }
.sled-popout__foot:empty { display: none; }
.sled-popout__foot > .primary { order: -1; margin-right: auto; }
.sled-popout__foot > button { min-height: var(--i8-touch); }
.sled-popout[data-size="compact"] .sled-popout__foot { justify-content: space-between; }
/* While any popout is open the bottom HUD row and the touch pads step aside; the top row stays as context. */
html[data-popout-open] .sled-stage .touch-controls, html[data-popout-open] .sled-world-hud > .i8-hud__bottom, html[data-popout-open] .sled-world-hud > #winter-dock,
html[data-popout-open] .sled-world-hud .infin8-instruments, html[data-popout-open] .sleddin-community .community-dock { display: none !important; }
/* Phones: the sheet fills the band under the top row with 16 px side gutters and the device safe area. */
@media (max-width: 600px), (max-height: 500px) and (orientation: landscape) {
  .sled-stage .sled-popout, .leave-confirm-dialog.sled-popout { inset: var(--popout-top) max(10px, env(safe-area-inset-right, 0px)) max(10px, env(safe-area-inset-bottom, 0px)) max(10px, env(safe-area-inset-left, 0px)); width: calc(100% - max(10px, env(safe-area-inset-left, 0px)) - max(10px, env(safe-area-inset-right, 0px))); margin-inline: 0; }
  .sled-stage .sled-popout:not([data-size="compact"]) { height: auto; }
  .sled-popout:not([data-size="compact"]) > .sled-popout__frame { flex: 1 1 auto; height: auto; }
  .sled-popout[data-size="compact"] { max-height: 100%; height: auto; }
  .sled-popout[data-size="compact"] > .sled-popout__frame { height: auto; }
  .sled-popout__head { flex-wrap: wrap; padding: var(--i8-s2) var(--i8-s3); }
  .sled-popout__body { padding: var(--i8-s2) var(--i8-s3); }
  .sled-popout[data-size="wide"] .sled-popout__body:has(> .sled-popout__rail) { grid-template-columns: minmax(0, 1fr); }
  .sled-popout__rail { flex-direction: row; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-inline: calc(var(--i8-s3) * -1); padding-inline: var(--i8-s3); border-radius: 0; border-left: 0; border-right: 0; background: var(--i8-panel-solid); }
  .sled-popout__rail::-webkit-scrollbar { display: none; }
  .sled-popout__rail > button { min-width: max-content; }
  .sled-popout__foot { padding: var(--i8-s2) var(--i8-s3) max(var(--i8-s2), env(safe-area-inset-bottom, 0px)); }
  .sled-popout__foot > button { flex: 1 1 140px; }
}
/* 10-foot console layout: the band is the 5% title-safe area at the TV scale (hud-layout.js). */
html[data-console-layout="true"] .sled-stage .sled-popout { font-size: 20px; }
html[data-console-layout="true"] .sled-popout__title { font-size: 32px; }
html[data-console-layout="true"] .sled-popout__rail > button, html[data-console-layout="true"] .sled-popout__foot > button, html[data-console-layout="true"] .sled-popout__panel button { min-height: var(--console-target, 56px); font-size: 20px; }
html[data-console-layout="true"] .sled-popout[data-size="wide"] .sled-popout__body:has(> .sled-popout__rail) { grid-template-columns: minmax(220px, 280px) minmax(0, 1fr); }
/* Light and non-neon themes: the frame takes the theme's solid panel, no neon glow. */
html[data-i8-theme]:not([data-i8-theme="neon"]) .sled-popout > .sled-popout__frame { background: var(--i8-panel-solid); box-shadow: 0 0 0 2px var(--i8-line), var(--i8-shadow); }
html[data-i8-theme]:not([data-i8-theme="neon"]) .sled-popout__head { background: var(--i8-panel-alt); }
html[data-i8-theme]:not([data-i8-theme="neon"]) .sled-popout__title { background: none; -webkit-background-clip: initial; background-clip: initial; color: var(--i8-cyan); }
html[data-i8-theme]:not([data-i8-theme="neon"]) .sled-popout__foot { background: var(--i8-panel-alt); }
@media (prefers-reduced-motion: reduce) { .sled-popout[open] { animation: none; } }

/* ---- Garage service bay: the same shell docked beside the 3D showroom ---- */
.garage-controls.sled-popout__dock { display: flex; flex-direction: column; gap: 0; padding: 0; overflow: hidden; text-align: left; }
.garage-controls.sled-popout__dock > .sled-popout__head { position: sticky; top: 0; z-index: 7; }
.garage-controls.sled-popout__dock > .sled-popout__rail { flex: none; position: sticky; top: 0; z-index: 6; }
/* Desktop and TV dock: the part categories never fill the panel. Tall screens
   wrap them into a compact grid; shorter ones get one scrolling row (as phones
   already do), so the parts and repairs below keep most of the panel. */
@media (min-width: 900px) and (min-height: 800px), (orientation: landscape) and (min-height: 800px) {
  #game-stage .garage-controls.sled-popout__dock > .garage-category-tabs { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 5px; max-height: 32%; overflow-y: auto; }
  #game-stage .garage-controls.sled-popout__dock > .garage-category-tabs > button { width: 100%; min-height: 34px; padding-inline: 6px; justify-content: center; text-align: center; }
  html[data-console-layout="true"] #game-stage .garage-controls.sled-popout__dock > .garage-category-tabs > button { min-height: 48px; }
}
@media (min-width: 900px) and (min-height: 560px) and (max-height: 799.98px), (orientation: landscape) and (min-height: 560px) and (max-height: 799.98px) {
  #game-stage .garage-controls.sled-popout__dock > .garage-category-tabs { display: flex; flex-direction: row; flex-wrap: nowrap; gap: 6px; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; scroll-snap-type: x proximity; }
  #game-stage .garage-controls.sled-popout__dock > .garage-category-tabs > button { flex: none; min-height: 38px; scroll-snap-align: start; }
}
.garage-controls.sled-popout__dock > .sled-popout__body { flex: 1 1 auto; display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; padding: 10px 12px; overflow-y: auto; min-height: 0; }
.garage-controls.sled-popout__dock > .sled-popout__foot.garage-actions { position: sticky; bottom: 0; z-index: 6; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; padding: 9px 12px 10px; box-shadow: 0 -12px 12px rgba(7, 25, 45, .9); border-top: 1px solid var(--i8-line-soft); border-radius: 0; }
.garage-controls.sled-popout__dock > .sled-popout__foot.garage-actions > #garage-ride { grid-column: 1 / -1; order: -1; margin: 0; }
.garage-controls .sled-popout__head .garage-selector { flex: 1 1 auto; min-width: 0; }
.garage-controls .sled-popout__head #garage-balance { flex: none; color: var(--i8-warning); font: 800 var(--i8-fs-sm)/1.2 var(--i8-font-display); letter-spacing: .04em; }
/* Repairs slot: the condition readout and the Repair action the economy owner fills in. */
#garage-repair-slot { display: grid; gap: 8px; }
#garage-condition-readout { margin: 0; color: var(--i8-text-soft); font-size: var(--i8-fs-sm); }
#garage-condition-readout:empty { display: none; }
#garage-repair-actions:empty { display: none; }
#garage-repair-actions { display: flex; flex-wrap: wrap; gap: 8px; }
/* Garage tabs are kit tabs: aria-pressed marks the open category for the gamepad navigator and the kit. */
.garage-category-tabs.i8-tabs > button[aria-pressed="true"] { color: #fff; }
