:root {
  --bg: #14110e;
  --panel: #1c1814;
  --panel-2: #241f1a;
  --line: #3a332b;
  --ink: #f3eee6;
  --mute: #c9bfb1;
  --dim: #b3a898;
  --cyan: #e0b84a;
  --yellow: #f0c419;
  --green: #3dba5f;
  --red: #e24b4b;
  --magenta: #c46a3a;
  --blue: #8eaddf;
  --btn-bg: #e0b84a;
  --btn-ink: #14110e;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
  --sidebar: 228px;
  --top: 56px;
  --radius: 10px;
  --font: "Plus Jakarta Sans", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  color-scheme: dark;
}

html[data-theme="light"] {
  --bg: #f6f1e8;
  --panel: #fbf8f3;
  --panel-2: #f3eee6;
  --line: #e4d9c8;
  --ink: #1a1612;
  --mute: #5e564c;
  --dim: #6f675c;
  --cyan: #9a7408;
  --yellow: #b8860b;
  --green: #1f7a3f;
  --red: #c0393a;
  --magenta: #8f4a28;
  --blue: #3d5ea8;
  --btn-bg: #9a7408;
  --btn-ink: #f6f1e8;
  --shadow: 0 16px 40px rgba(70, 48, 20, 0.08);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}
img, video { max-width: 100%; display: block; }
[hidden] { display: none !important; }
a { color: var(--blue); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: var(--cyan); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.skip {
  position: absolute; left: 12px; top: -40px; background: var(--btn-bg); color: var(--btn-ink);
  padding: 8px 12px; border-radius: 8px; z-index: 20;
}
.skip:focus { top: 12px; }

.shell { min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 16px;
  height: var(--top); padding: 0 20px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 700; letter-spacing: -0.03em; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(160deg, var(--yellow), var(--magenta));
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.2);
}
.brand small { display: block; font-weight: 500; color: var(--dim); letter-spacing: 0; font-size: 11px; }
.top-spacer { flex: 1; }
.top-links { display: flex; gap: 8px; align-items: center; }
.icon-btn, .btn, .btn-ghost {
  min-height: 36px; border-radius: 8px; padding: 0 12px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; cursor: pointer; text-decoration: none; font-weight: 650;
}
.pill { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; font-weight: 700; color: var(--btn-ink); background: var(--cyan); border-radius: 999px; padding: 3px 8px; }
.btn { background: var(--btn-bg); color: var(--btn-ink); }
.btn:hover { filter: brightness(1.05); color: var(--btn-ink); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--cyan); color: var(--ink); }
.icon-btn { width: 36px; padding: 0; background: var(--panel-2); border: 1px solid var(--line); color: var(--ink); }
.menu-btn { display: none; }

.layout { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); }
.sidebar {
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 12px 12px 32px;
  position: sticky; top: var(--top); height: calc(100vh - var(--top)); overflow: auto;
}
.nav-label { margin: 14px 10px 6px; color: var(--dim); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; }
.nav-link {
  display: flex; align-items: center; gap: 8px;
  min-height: 34px; padding: 0 10px; border-radius: 8px;
  color: var(--mute); text-decoration: none; font-weight: 600; font-size: 14px;
}
.nav-link:hover { background: var(--panel-2); color: var(--ink); }
.nav-link.active { background: color-mix(in srgb, var(--cyan) 16%, var(--panel)); color: var(--ink); }
.main { padding: 28px 32px 64px; min-width: 0; }
.crumbs { display: flex; flex-wrap: wrap; gap: 6px; color: var(--dim); font-size: 13px; margin-bottom: 12px; }
.crumbs a { color: var(--mute); text-decoration: none; }
.page-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-end; margin-bottom: 22px; }
.page-head h1 { margin: 0; font-size: clamp(26px, 3vw, 34px); letter-spacing: -0.04em; line-height: 1.1; }
.kicker { margin: 0 0 6px; color: var(--magenta); font-weight: 700; font-size: 13px; letter-spacing: .08em; text-transform: uppercase; }
.lede { margin: 8px 0 0; max-width: 68ch; color: var(--mute); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.banner {
  display: flex; gap: 12px; align-items: flex-start;
  background: color-mix(in srgb, var(--cyan) 12%, var(--panel));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 18px; color: var(--ink);
}
.banner strong { color: var(--cyan); }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.metrics { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.card, .metric {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px;
}
.metric span { display: block; color: var(--dim); font-size: 13px; }
.metric strong { display: block; margin-top: 4px; font-size: 26px; letter-spacing: -0.04em; font-variant-numeric: tabular-nums; }
.metric em { font-style: normal; color: var(--mute); font-size: 13px; }
.card h2, .card h3 { margin: 0 0 8px; letter-spacing: -0.03em; }
.card p { margin: 0; color: var(--mute); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.id { font-family: var(--mono); font-size: 12px; color: var(--mute); }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table { width: 100%; border-collapse: collapse; min-width: 720px; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--dim); font-size: 11px; letter-spacing: .07em; text-transform: uppercase; font-weight: 700; cursor: pointer; white-space: nowrap; background: var(--panel-2); position: sticky; top: 0; }
th[aria-sort="ascending"]::after { content: " ↑"; color: var(--cyan); }
th[aria-sort="descending"]::after { content: " ↓"; color: var(--cyan); }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: color-mix(in srgb, var(--panel-2) 70%, transparent); }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input, .field input, .field select, .field textarea {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px; width: 100%;
}
.toolbar input { max-width: 320px; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field span { font-weight: 650; }
.hint { color: var(--dim); font-size: 13px; }
.field .error { color: var(--red); font-size: 13px; min-height: 1em; }
.form { max-width: 720px; }
.checks { display: grid; gap: 8px; }
.checks label { display: flex; gap: 10px; align-items: flex-start; min-height: 32px; }
.checks input, .confirm input { width: 18px; height: 18px; min-height: 18px; margin-top: 2px; accent-color: var(--cyan); }
.confirm { display: flex; gap: 10px; align-items: center; margin: 4px 0 14px; }

.badge { display: inline-flex; align-items: center; min-height: 24px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 700; border: 1px solid var(--line); }
.badge-good { color: var(--green); background: color-mix(in srgb, var(--green) 14%, transparent); }
.badge-bad { color: var(--red); background: color-mix(in srgb, var(--red) 12%, transparent); }
.badge-warn { color: var(--yellow); background: color-mix(in srgb, var(--yellow) 12%, transparent); }
.badge-neutral { color: var(--mute); }

.empty, .error-panel {
  padding: 28px; text-align: center; color: var(--mute);
}
.error-panel { color: var(--ink); border: 1px solid color-mix(in srgb, var(--red) 50%, var(--line)); border-radius: var(--radius); background: color-mix(in srgb, var(--red) 8%, var(--panel)); }
.chart { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 140px 1fr 48px; gap: 10px; align-items: center; }
.bar { height: 12px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--cyan); border-radius: 99px; }
.hero { display: grid; grid-template-columns: 1.15fr .85fr; gap: 28px; align-items: stretch; }
.hero h1 { font-size: clamp(36px, 5vw, 56px); line-height: 1.02; letter-spacing: -0.045em; margin: 0 0 12px; }
.gate { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr); }
.gate-copy { padding: 56px 64px; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; justify-content: center; }
.gate-copy h1 { font-size: clamp(34px, 4vw, 52px); letter-spacing: -0.045em; line-height: 1.05; margin: 28px 0 12px; }
.gate-copy p, .gate-copy li { color: var(--mute); }
.gate-copy ul { margin: 18px 0 0; padding-left: 18px; display: grid; gap: 8px; }
.gate-panel { padding: 40px 48px; display: flex; flex-direction: column; justify-content: center; }
.gate-tools { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin-bottom: 18px; }
.sample { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; overflow: hidden; box-shadow: var(--shadow); }
.sample header, .player-chrome { display: flex; justify-content: space-between; gap: 8px; align-items: center; padding: 10px 12px; background: var(--panel-2); border-bottom: 1px solid var(--line); }
.sample pre { margin: 0; padding: 16px; overflow: auto; color: var(--mute); font-size: 12px; line-height: 1.55; white-space: pre-wrap; }
.tally { font-family: var(--mono); font-size: 12px; color: var(--cyan); }
.step { padding-left: 44px; position: relative; }
.step::before {
  content: attr(data-n);
  position: absolute; left: 14px; top: 16px; width: 28px; height: 28px; border-radius: 8px;
  display: grid; place-items: center; background: var(--panel-2); border: 1px solid var(--line); color: var(--cyan); font-weight: 700;
}
.player { background: #0c0b09; border-radius: 16px; overflow: hidden; border: 1px solid var(--line); }
.stage { position: relative; aspect-ratio: 16/9; background: #100e0c; }
.stage video, .stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.log { max-height: 280px; overflow: auto; font-family: var(--mono); font-size: 12px; background: var(--panel-2); border-radius: 10px; padding: 10px; }
.log div { padding: 3px 0; border-bottom: 1px solid var(--line); }
.companion { width: 300px; max-width: 100%; border-radius: 10px; border: 1px solid var(--line); }
.colophon { margin-top: 36px; color: var(--dim); font-size: 13px; }
.prose { max-width: 74ch; }
.prose h2 { margin-top: 1.4em; letter-spacing: -0.03em; }
.prose code, .prose pre { font-family: var(--mono); font-size: 13px; }
.prose pre { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; overflow: auto; }
.login-card { max-width: 440px; margin: 8vh auto; }

@media (max-width: 1020px) {
  .metrics, .grid-3 { grid-template-columns: 1fr 1fr; }
  .hero, .gate { grid-template-columns: 1fr; }
  .gate-copy, .gate-panel { padding: 28px 20px; }
}
@media (max-width: 860px) {
  .menu-btn { display: inline-flex; }
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; z-index: 40; top: var(--top); left: 0; bottom: 0; width: min(86vw, 320px);
    transform: translateX(-105%); transition: transform .2s ease; box-shadow: var(--shadow);
  }
  .sidebar.open { transform: none; }
  .main { padding: 20px 16px 48px; }
  .page-head { flex-direction: column; align-items: stretch; }
  .grid-2, .grid-3, .bar-row { grid-template-columns: 1fr; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .table-wrap table, .table-wrap thead, .table-wrap tbody, .table-wrap tr, .table-wrap td { display: block; min-width: 0; width: 100%; }
  .table-wrap thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table-wrap tr { border-bottom: 1px solid var(--line); padding: 8px 0; }
  .table-wrap td { border: 0; padding: 4px 14px 10px; }
  .table-wrap td::before { content: attr(data-label); display: block; color: var(--dim); font-size: 11px; letter-spacing: .06em; text-transform: uppercase; font-weight: 700; margin-bottom: 2px; }
  .icon-btn, .btn, .btn-ghost { min-height: 44px; }
  .page-head { align-items: start; }
  .top-links .hide-sm { display: none; }
  table { min-width: 640px; }
}
