/* App shell, layout and responsive structure. Components live in components.css. */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 var(--fs-14)/1.45 var(--font-sans);
  font-feature-settings: 'ss01', 'cv11';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
  overscroll-behavior: none;
  transition: background-color var(--t-med) var(--ease), color var(--t-med) var(--ease);
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus { outline: none; }
:focus-visible { box-shadow: var(--focus); border-radius: var(--r-sm); }
::selection { background: var(--accent-soft); }
.num { font-variant-numeric: tabular-nums; }
.mono, .field-input.num, .stepper-input, .pc-dim, .ver-num, .range-out { font-family: var(--font-mono); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.sr { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: fixed; left: 12px; top: -60px; z-index: 100; background: var(--ink); color: var(--bg); padding: 8px 12px; border-radius: var(--r-sm); text-decoration: none; transition: top var(--t-fast) var(--ease); }
.skip:focus { top: 12px; }
.noscript { padding: 40px; font-family: var(--font-serif); font-style: italic; font-size: 24px; }

/* ---------- shell grid ---------- */
.app {
  display: grid;
  height: 100dvh;
  grid-template-columns: var(--left-w) minmax(0, 1fr) var(--right-w);
  grid-template-rows: var(--topbar-h) minmax(0, 1fr);
  grid-template-areas: 'top top top' 'left stage right';
  isolation: isolate;
}
.topbar { grid-area: top; }
.panel-left { grid-area: left; }
.stage { grid-area: stage; }
.panel-right { grid-area: right; }

/* first paint: fade the shell in once modules are ready */
.app[data-ready='false'] .panel, .app[data-ready='false'] .rail-band { opacity: 0; }
.panel, .rail-band { transition: opacity var(--t-slow) var(--ease); }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px 0 16px;
  padding-top: var(--safe-t);
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  position: relative;
  z-index: 20;
  min-width: 0;
}
.brand { display: flex; align-items: center; gap: 9px; color: var(--ink); text-decoration: none; flex: none; border-radius: var(--r-sm); }
.brand .mark { display: block; }
.wordmark { font-weight: 600; font-size: 15px; letter-spacing: -0.035em; white-space: nowrap; }
.tb-sep { width: 1px; height: 20px; background: var(--line-strong); flex: none; margin: 0 4px; }
.tb-spacer { flex: 1; min-width: 4px; }
.tb-group { display: flex; align-items: center; gap: 2px; flex: none; }
.tb-collapse { display: contents; }

/* ---------- panels ---------- */
.panel {
  background: var(--surface);
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 5;
}
.panel-left { border-right: 1px solid var(--line); }
.panel-right { border-left: 1px solid var(--line); }
.panel-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
  scrollbar-gutter: stable;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 16px 18px 6px;
}
.panel-title { font-size: var(--fs-13); font-weight: 600; letter-spacing: -0.01em; margin: 0; }
.panel-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 14px 10px 18px;
  border-top: 1px solid var(--line);
  font-size: var(--fs-12);
  color: var(--muted);
}

/* ---------- stage ---------- */
.stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  position: relative;
  background: var(--bg);
}
.viewport {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: linear-gradient(180deg, var(--scene-top), var(--scene-bottom));
  touch-action: none;
  container-type: size;
  container-name: viewport;
}
.scene-host { position: absolute; inset: 0; }
.scene-host canvas { display: block; outline: none; }
.viewport:fullscreen { background: linear-gradient(180deg, var(--scene-top), var(--scene-bottom)); }

.rail-band {
  flex: none;
  height: var(--rail-h);
  border-top: 1px solid var(--line);
  background: var(--surface);
  position: relative;
  z-index: 4;
  min-width: 0;
}

/* ---------- Mid desktop: details float over the viewport ---------- */
@media (min-width: 1100px) and (max-width: 1439.98px) {
  .app { grid-template-columns: var(--left-w) minmax(0, 1fr); grid-template-areas: 'top top' 'left stage'; }
  .panel-right {
    position: fixed;
    top: calc(var(--topbar-h) + 12px);
    right: 12px;
    bottom: calc(var(--rail-h) + 12px);
    width: min(340px, 38vw);
    border: 1px solid var(--glass-line);
    border-radius: var(--r-lg);
    background: var(--glass-strong);
    backdrop-filter: blur(22px) saturate(1.4);
    -webkit-backdrop-filter: blur(22px) saturate(1.4);
    box-shadow: var(--shadow-3);
    transform: translateX(calc(100% + 24px));
    visibility: hidden;
    transition: transform var(--t-med) var(--ease), visibility 0s linear var(--t-med);
    z-index: 15;
  }
  .app[data-detail='open'] .panel-right {
    transform: none;
    visibility: visible;
    transition: transform var(--t-med) var(--spring), visibility 0s;
  }
}
@media (min-width: 1440px), (max-width: 1099.98px) { .only-mid { display: none !important; } }

/* ---------- Tablet and mobile: one stage, controls in a sheet or drawer ---------- */
@media (max-width: 1099.98px) {
  :root { --topbar-h: 52px; }
  .app { grid-template-columns: minmax(0, 1fr); grid-template-areas: 'top' 'stage'; }
  .panel-left, .panel-right, .rail-band { display: none; }
  .only-wide { display: none !important; }
}
@media (min-width: 1100px) {
  .sheet, .only-narrow { display: none !important; }
}
@media (max-width: 759.98px) {
  .tb-collapse > * { display: none !important; }
  .wordmark { display: none; }
  .topbar { padding-left: 12px; gap: 6px; }
  .tb-sep.hide-sm { display: none; }
}
@media (min-width: 760px) { .only-sm { display: none !important; } }
