:root {
  --ground: #F2E8E0;
  --ink: #23201D;
  --muted: #6E655E;
  --cobalt: #2F4BD0;
  --alert: #E2552D;
  --light: #FFFFFF;
  --shade: #D6C8BD;
  --raise: -6px -6px 14px #FFFFFF, 6px 6px 14px #D6C8BD;
  --lift: -8px -8px 16px #FFFFFF, 8px 8px 16px #D6C8BD;
  --press: inset 4px 4px 10px #D6C8BD, inset -4px -4px 10px #FFFFFF;
  --sans: "Avenir Next", "Century Gothic", "Segoe UI", "Trebuchet MS", sans-serif;
  --mono: "Cascadia Mono", "Cascadia Code", "Segoe UI Mono", ui-monospace, monospace;
  --spring: 420ms cubic-bezier(0.22, 1.4, 0.36, 1);
  color-scheme: light;
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--ground); color: var(--ink); }
body { overflow: hidden; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
p { margin: 0 0 8px; }
h1, h2 { margin: 0 0 8px; font-weight: 650; letter-spacing: -0.02em; }
h1 { font-size: 34px; }
h2 { font-size: 18px; }
p, h1, h2, td, th, li, label { text-shadow: none; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--cobalt); outline-offset: 3px; }

.screen {
  position: relative;
  width: 100%;
  max-width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) 250px;
  grid-template-areas:
    "rail stage"
    "chains chains";
  overflow: hidden;
}
.rail { grid-area: rail; }
.stage { grid-area: stage; }
.chains { grid-area: chains; }
.drawer { display: none; min-width: 0; min-height: 0; }
.screen.tool-open .drawer {
  display: block;
  position: absolute;
  z-index: 5;
  left: 96px;
  top: 0;
  bottom: 250px;
  width: min(340px, calc(100vw - 120px));
  overflow: auto;
  background: var(--ground);
  box-shadow: var(--raise);
}
.rail, .stage, .chains { min-width: 0; min-height: 0; }
.chains { box-shadow: inset 0 1px 0 var(--shade); }

.rail {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px 10px;
  overflow: hidden;
}
.brand-lock { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.brand { margin: 0; font-size: 18px; font-weight: 700; }
.kicker, .panel > p, .knob-block > p, .step-detail, label, .target-readout p, .figure-row p {
  color: var(--muted);
  font-size: 14px;
}
.rail-nav { display: flex; flex-direction: column; gap: 10px; }
.rail-nav .keycap { width: 100%; min-height: 48px; padding: 8px; }
.status {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}
.token { display: flex; flex-direction: column; gap: 8px; }
.token input { width: 100%; }

.drawer { padding: 22px 16px 28px; background: var(--ground); }
.chains {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: auto auto auto minmax(0, 1fr);
  gap: 6px 24px;
  overflow: hidden;
  padding: 12px 18px 10px;
}
.chains .figure-row { display: none; }
.chains .track,
.chains > p { grid-column: 1 / -1; margin: 0; }
.chains > section { min-height: 0; overflow: auto; }
.chains > section:nth-of-type(1) { max-height: none; }
.events-block { max-height: 108px; }
.events-block:not(:has(tbody tr)) { display: none; }
.chains h2 {
  position: sticky;
  top: 0;
  margin-bottom: 8px;
  background: var(--ground);
}
.panel { display: flex; flex-direction: column; gap: 12px; }
.lede { margin: 0; color: var(--muted); }
.drawer h3 { margin: 8px 0 0; font-size: 16px; }
.drawer .model-form {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
  margin: 0;
}
.drawer .fields label,
.drawer .model-form label { width: 100%; }
.file-list { display: flex; flex-direction: column; gap: 10px; }
.file-row { width: 100%; justify-content: flex-start; text-align: left; }
.filters {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  text-align: center;
}
.filters .keycap { min-width: 72px; padding: 8px 10px; }

.stage {
  display: flex;
  flex-direction: column;
  padding: 20px 24px 16px;
  gap: 14px;
  overflow: hidden;
}
.stage-head, .module-head, .figure-row, .detail-actions, .composer-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}
.stage-head { justify-content: space-between; align-items: flex-end; min-width: 0; }
.stage-head > div { min-width: 0; }
.stage-head h1 {
  margin: 0;
  font-size: clamp(22px, 2vw, 32px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.screen-video {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  border-radius: 24px;
  overflow: hidden;
  background: #1c1917;
  box-shadow: var(--press);
}
.screen-video video,
.screen-video img.cell-live {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #1c1917;
}
.player-grid {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  gap: 8px;
  padding: 8px;
}
.player-grid[data-layout="1"] { grid-template-columns: 1fr; }
.player-grid[data-layout="1"] .player-cell:not(:first-child) { display: none; }
.player-grid[data-layout="4"] { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.player-cell { position: relative; min-width: 0; min-height: 0; overflow: hidden; border-radius: 16px; background: #111; }
.player-cell video.cell-video,
.player-cell img.cell-live {
  position: absolute;
  inset: 0;
  z-index: 1;
}
.cell-note {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 100%;
  margin: 0;
  padding: 16px;
  border: 0;
  background: transparent;
  box-shadow: none;
  color: #f2e8e0;
  text-align: center;
  cursor: pointer;
}
.cell-source { position: absolute; top: 10px; left: 10px; z-index: 3; }
.player-tools { position: relative; z-index: 3; display: flex; justify-content: flex-end; gap: 8px; padding: 8px 8px 0; }
.source-sheet {
  position: absolute;
  z-index: 4;
  left: 16px;
  right: 16px;
  bottom: 16px;
  max-height: 78%;
  overflow: auto;
  padding: 16px;
  border-radius: 20px;
  background: var(--ground);
  box-shadow: var(--raise);
}
.choice-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.choice-row > span { color: var(--muted); font-size: 14px; }
.camera-fields { display: grid; grid-template-columns: 1fr 120px; gap: 10px; }
#screenEmpty { display: none; }
.stage-head .keycap { flex: none; }
.mono { font-family: var(--mono); color: var(--muted); }
.transcript {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 12px;
  max-height: 30%;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
#stageHint { max-width: 62ch; margin: 0; color: #f2e8e0; font-size: 16px; }
.messages {
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: auto;
  font-size: 16px;
  line-height: 1.4;
}
.messages:empty { display: none; }
.transcript .bubble { color: #f2e8e0; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45); }
.transcript .who { color: #f2e8e0; }
.bubble { white-space: pre-wrap; background: transparent; box-shadow: none; }
.who { margin: 0 0 4px; color: var(--muted); font-size: 13px; }
.bubble.user { color: var(--ink); }
.bubble.assistant { color: var(--muted); font-size: 18px; }
.transcript .bubble.user,
.transcript .bubble.assistant { color: #f2e8e0; font-size: 16px; }
.pick-mode { display: flex; gap: 8px; }
.pick-mode .keycap { min-width: 72px; }
#searchState { min-height: 1.2em; }
.model-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 320px;
  overflow: auto;
}
.model-row {
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  text-align: left;
  line-height: 1.3;
}
.model-row.is-current { background: #f3e6c8; color: #6d5420; }
.model-row small { display: block; color: var(--muted); font-size: 12px; }
.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: end;
}
.composer textarea { min-height: 64px; font-size: 16px; }
.composer-actions { display: flex; flex-direction: column; gap: 12px; padding-bottom: 2px; }

.figure-row { align-items: flex-end; flex-wrap: wrap; }
.figure-row p { margin: 6px 0 0; }
.events-block { min-height: 0; }
.chain { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.step {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  column-gap: 12px;
}
.step-rail { display: flex; flex-direction: column; align-items: center; }
.bead {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--ground);
  box-shadow: -3px -3px 6px var(--light), 3px 3px 6px var(--shade);
  flex: none;
}
.step.done .bead, .step.current .bead { background: var(--cobalt); box-shadow: var(--press); }
.step.gap .bead, .step.alert .bead { background: var(--alert); box-shadow: var(--press); }
.stem { width: 2px; flex: 1; min-height: 8px; margin: 2px 0; background: var(--shade); }
.step-title { margin: 0; font-weight: 650; }
.step.current .step-title { color: var(--cobalt); }
.step.gap .step-title, .step.alert .step-title { color: var(--alert); }
.step-detail { margin: 0 0 2px; font-size: 13px; line-height: 1.25; }

.keycap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 16px;
  border: 0;
  border-radius: 16px;
  background: var(--ground);
  color: var(--ink);
  box-shadow: var(--raise);
  text-decoration: none;
  transition: transform 280ms cubic-bezier(0.34, 1.45, 0.64, 1), color 160ms ease;
}
.keycap:hover:not(:disabled):not(.is-current):not(:active) {
  transform: translateY(-2px);
  box-shadow: var(--lift);
}
.keycap:active:not(:disabled),
.keycap.is-current:not(:disabled) {
  transform: translateY(2px);
  box-shadow: var(--press);
  color: var(--cobalt);
}
.keycap:disabled {
  color: var(--muted);
  cursor: not-allowed;
  transform: none;
  box-shadow: inset 2px 2px 6px var(--shade), inset -2px -2px 6px var(--light);
}
.lamp {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--ground);
  box-shadow: -3px -3px 6px var(--light), 3px 3px 6px var(--shade);
  flex: none;
}
.lamp.on, .lamp.alert { box-shadow: var(--press); }
.lamp.on { background: var(--cobalt); }
.lamp.alert { background: var(--alert); }

.odometer {
  display: inline-flex;
  gap: 3px;
  align-items: center;
  height: 52px;
  padding: 8px 12px;
  border-radius: 16px;
  background: var(--ground);
  box-shadow: var(--press);
  color: var(--cobalt);
  font-family: var(--mono);
  font-size: 32px;
  font-variant-numeric: tabular-nums;
  line-height: 36px;
}
.digit { width: 0.62em; height: 36px; overflow: hidden; }
.digit-strip { display: block; }
.digit-strip span { display: block; height: 36px; text-align: center; }

.fields { display: flex; flex-direction: column; gap: 14px; }
label { display: block; }
textarea, select, input[type="text"], input[type="password"], input[type="number"], input:not([type]) {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 12px 14px;
  border: 0;
  border-radius: 16px;
  appearance: none;
  background: var(--ground);
  color: var(--ink);
  box-shadow: var(--press);
  resize: vertical;
}
.mail-send { padding-top: 28px; padding-bottom: 28px; }
.sr-file {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  opacity: 0;
}
.file-key { position: relative; width: fit-content; }
.file-key input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  box-shadow: none;
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; min-height: 24px; }
.chip { color: var(--ink); font-size: 14px; }
.module-actions { padding-top: 12px; }

.track {
  height: 14px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--ground);
  box-shadow: var(--press);
}
.track > span { display: block; height: 100%; width: 0; border-radius: 999px; background: var(--cobalt); }
#progressText.alert, .alert { color: var(--alert); }

.sheet { width: 100%; border-collapse: collapse; background: transparent; box-shadow: none; }
.sheet th, .sheet td {
  padding: 8px 6px;
  border: 0;
  border-bottom: 1px solid var(--shade);
  text-align: left;
  vertical-align: top;
  font-weight: 500;
  box-shadow: none;
}
.sheet th { color: var(--muted); font-size: 13px; font-weight: 600; }
.sheet td.alert { color: var(--alert); font-weight: 650; }

.jobs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.jobs .keycap { width: 100%; min-width: 0; justify-content: space-between; align-items: center; text-align: left; }
.jobs .keycap .job-name { min-width: 0; flex: 1; overflow-wrap: anywhere; white-space: normal; }
.jobs .keycap span:not(.job-name) { flex: none; white-space: nowrap; color: var(--muted); font-family: var(--mono); font-size: 13px; }
.jobs .keycap.is-current span { color: var(--cobalt); }

.menu { position: relative; margin-top: 6px; }
.menu-trigger { width: 100%; justify-content: space-between; }
.menu-list {
  position: absolute;
  z-index: 7;
  left: 0;
  right: 0;
  top: calc(100% + 8px);
  margin: 0;
  padding: 8px;
  list-style: none;
  border-radius: 16px;
  background: var(--ground);
  box-shadow: var(--press);
}
.menu-item {
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  text-align: left;
}
.menu-item.is-current { box-shadow: var(--press); color: var(--cobalt); }

.stack { position: relative; min-height: 48px; }
.stack-card {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 156px;
  padding: 12px 14px;
  overflow: hidden;
  border-radius: 24px;
  background: var(--ground);
  box-shadow: var(--raise);
  touch-action: none;
}
.stack-card img, .stack-card video {
  display: block;
  width: 100%;
  height: 104px;
  object-fit: cover;
  border-radius: 12px;
  background: var(--shade);
  box-shadow: none;
}
.stack-card p { margin: 6px 0 0; color: var(--muted); }
.audio-face {
  display: grid;
  place-items: center;
  height: 104px;
  border-radius: 12px;
  font-family: var(--mono);
}

.knob-block { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.knob { position: relative; width: 168px; height: 168px; touch-action: none; border-radius: 50%; }
.knob-svg { width: 168px; height: 168px; display: block; }
.ring-track, .ring-value {
  fill: none;
  stroke-width: 10;
  stroke-linecap: round;
  transform-origin: 90px 90px;
  transform: rotate(135deg);
}
.ring-track { stroke: var(--shade); }
.ring-value { stroke: var(--cobalt); }
.knob-cap {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 104px;
  height: 104px;
  margin: -52px 0 0 -52px;
  border-radius: 50%;
  background: var(--ground);
  box-shadow: var(--raise);
}
.needle {
  position: absolute;
  left: 50%;
  top: 14px;
  width: 4px;
  height: 22px;
  margin-left: -2px;
  border-radius: 4px;
  background: var(--cobalt);
  transform-origin: 2px 38px;
}
.chart { width: 100%; height: auto; display: block; }
.chart .axis { stroke: var(--shade); stroke-width: 2; }
.chart .bar { fill: var(--shade); }
.chart .target-line { stroke: var(--cobalt); stroke-width: 3; }
.chart text { fill: var(--muted); font-family: var(--sans); font-size: 13px; }

.detail {
  width: min(860px, calc(100vw - 48px));
  padding: 22px;
  border: 0;
  border-radius: 24px;
  background: var(--ground);
  color: var(--ink);
  box-shadow: var(--raise);
}
.detail::backdrop { background: rgba(35, 32, 29, 0.28); }
.detail img, .detail video, .detail audio { width: 100%; max-height: 64vh; box-shadow: none; }
.detail-actions { margin-top: 16px; flex-wrap: wrap; }

@media (max-width: 980px) {
  .screen, .screen.tool-open {
    grid-template-columns: 84px minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) 220px;
  }
  .figure-row { display: none; }
  .screen.tool-open .drawer {
    left: 84px;
    bottom: 220px;
    width: min(320px, calc(100vw - 96px));
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
