:root {
  color-scheme: light;
  --bg: #f6f3ee;
  --panel: #ffffff;
  --ink: #1f1a16;
  --muted: #7a7068;
  --line: #e7e0d7;
  --soft: #f1ece5;
  --accent: #f0731f;
  --accent-soft: #fdeadb;
  --amber: #e9a100;
  --amber-soft: #fff4d6;
  --green: #2f9e57;
  --green-soft: #e3f5e9;
  --blue: #2f6fd6;
  --blue-soft: #e4edfb;
  --red: #d23f3f;
  --red-soft: #fbe5e5;
  --radius: 14px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 var(--font);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
button { font: inherit; color: inherit; cursor: pointer; }

/* -- top bar ------------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-tile {
  width: 34px; height: 34px; border-radius: 10px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #f0731f, #f2a51a);
  box-shadow: 0 4px 14px rgba(240, 115, 31, .35);
}
.brand-name { font-size: 18px; font-weight: 700; letter-spacing: -.02em; }
.brand-name b { color: var(--accent); }
.brand-tag {
  font-size: 12px; color: var(--muted); border: 1px solid var(--line);
  border-radius: 999px; padding: 2px 10px;
}
.controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.btn {
  border: 1px solid var(--line); background: var(--panel);
  border-radius: 10px; padding: 8px 14px; font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary.running { background: var(--ink); border-color: var(--ink); }
.btn.ghost:hover, .speed button:hover { background: var(--soft); }
#voice.on { border-color: var(--accent); color: var(--accent); }
#voice.unsupported { display: none; }
.speed { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.speed button { border: 0; background: var(--panel); padding: 8px 12px; font-size: 13px; }
.speed button.on { background: var(--ink); color: #fff; }

/* -- layout ---------------------------------------------------------------- */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 340px;
  gap: 16px;
  padding: 16px 20px;
  align-items: start;
}
.scenarios, .panels, .narration, .tracker, .scene-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.scenarios { padding: 16px; position: sticky; top: 76px; }
.scenarios h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 10px; }
.scenarios ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.scenario {
  width: 100%; text-align: left; border: 1px solid var(--line); background: var(--panel);
  border-radius: 12px; padding: 10px 12px; display: grid; grid-template-columns: 26px 1fr; gap: 2px 8px;
}
.scenario:hover { border-color: var(--accent); }
.scenario .num { grid-row: span 2; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.scenario .title { font-weight: 600; }
.scenario .sub { font-size: 12px; color: var(--muted); }
.scenario.active { border-color: var(--accent); background: var(--accent-soft); }
.scenario.active .num { color: var(--accent); }
.scenario.done .num::after { content: " ✓"; color: var(--green); }
.scenario .steps { grid-column: 2; margin: 6px 0 0; padding: 0; list-style: none; display: none; gap: 3px; }
.scenario.active .steps { display: grid; }
.scenario .steps li { font-size: 12px; color: var(--muted); padding-left: 14px; position: relative; }
.scenario .steps li::before { content: ""; position: absolute; left: 2px; top: 7px; width: 6px; height: 6px; border-radius: 50%; background: var(--line); }
.scenario .steps li.now { color: var(--ink); font-weight: 600; }
.scenario .steps li.now::before { background: var(--accent); }
.scenario .steps li.past::before { background: var(--green); }
.hint { font-size: 12px; color: var(--muted); margin: 12px 0 0; }

/* -- stage ------------------------------------------------------------------ */
.stage { display: grid; gap: 12px; min-width: 0; }
.scene-wrap {
  position: relative; overflow: hidden;
  background: radial-gradient(ellipse at 50% 35%, #fffaf3 0%, #f3ece2 70%);
}
#scene { display: block; width: 100%; height: auto; max-height: 72vh; touch-action: manipulation; }
.clock {
  position: absolute; top: 12px; left: 14px; z-index: 1;
  font-weight: 700; font-variant-numeric: tabular-nums; font-size: 15px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 4px 10px;
}
.clock::before { content: "🕒 "; }
.legend {
  position: absolute; top: 12px; right: 14px; z-index: 1;
  display: flex; gap: 10px; font-size: 12px; color: var(--muted);
  background: rgba(255, 255, 255, .85); border: 1px solid var(--line); border-radius: 10px; padding: 4px 10px;
}
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }
.dot.free { background: #cfa171; }
.dot.busy { background: var(--accent); }
.dot.bill { background: var(--amber); }

.narration { padding: 12px 16px; display: flex; gap: 12px; align-items: baseline; }
.narration .label {
  flex: none; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--accent);
}
.narration p { margin: 0; font-size: 15px; font-weight: 500; }

.tracker { padding: 14px 16px; }
.tracker .head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.tracker .head b { font-size: 14px; }
.tracker .head code { font-size: 13px; background: var(--soft); border-radius: 6px; padding: 1px 6px; }
.tracker .head span { color: var(--muted); font-size: 12px; }
.steps-row { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 0; }
.tstep { position: relative; text-align: center; font-size: 12px; color: var(--muted); padding: 0 4px; }
.tstep .ball {
  width: 26px; height: 26px; border-radius: 50%; margin: 0 auto 6px; display: grid; place-items: center;
  border: 2px solid var(--line); background: var(--panel); font-weight: 700; font-size: 12px; position: relative; z-index: 1;
}
.tstep::before {
  content: ""; position: absolute; top: 12px; left: -50%; width: 100%; height: 2px; background: var(--line);
}
.tstep:first-child::before { display: none; }
.tstep.past .ball { background: var(--green); border-color: var(--green); color: #fff; }
.tstep.past::before, .tstep.now::before { background: var(--green); }
.tstep.now .ball { border-color: var(--accent); color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.tstep.now { color: var(--ink); font-weight: 600; }

/* -- panels ---------------------------------------------------------------- */
.panels { padding: 0; overflow: hidden; position: sticky; top: 76px; }
.detail { padding: 16px; border-bottom: 1px solid var(--line); }
.detail .kicker { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.detail h3 { margin: 2px 0 10px; font-size: 18px; letter-spacing: -.01em; }
.detail .note { font-size: 13px; background: var(--soft); border-radius: 10px; padding: 10px 12px; margin-top: 10px; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
.tabs { display: flex; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button {
  flex: 1; border: 0; background: none; padding: 10px 8px; font-size: 13px; color: var(--muted);
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs button.on { color: var(--ink); font-weight: 700; border-bottom-color: var(--accent); }
.tabs button.ping { color: var(--accent); }
.tab-body { padding: 12px 14px 16px; max-height: 460px; overflow-y: auto; }
.empty { color: var(--muted); font-size: 13px; text-align: center; padding: 18px 0; }

.board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tcard { border: 1px solid var(--line); border-radius: 10px; padding: 8px; font-size: 12px; }
.tcard b { font-size: 15px; display: block; }
.tcard.busy { background: var(--accent-soft); border-color: #f6b98b; }
.tcard.bill { background: var(--amber-soft); border: 2px solid var(--amber); }
.tcard .st { color: var(--green); font-weight: 600; }
.tcard.busy .st, .tcard.bill .st { color: var(--ink); }
.tag { display: inline-block; font-size: 10px; font-weight: 700; border-radius: 999px; padding: 1px 7px; margin-top: 3px; }
.tag.amber { background: var(--amber); color: #fff; }
.tag.blue { background: var(--blue-soft); color: var(--blue); }
.tag.green { background: var(--green-soft); color: var(--green); }
.tag.gray { background: var(--soft); color: var(--muted); }
.tag.red { background: var(--red-soft); color: var(--red); }

.ticket { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 8px; font-size: 13px; }
.ticket .th { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.ticket ul { margin: 0; padding-left: 16px; color: var(--muted); }

.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.stat { background: var(--soft); border-radius: 10px; padding: 8px 10px; }
.stat span { font-size: 11px; color: var(--muted); display: block; }
.stat b { font-size: 16px; font-variant-numeric: tabular-nums; }
.subhead { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 12px 0 6px; }
.row { display: flex; justify-content: space-between; gap: 8px; padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.row:last-child { border-bottom: 0; }
.row .r { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row small { color: var(--muted); display: block; }
.row.hl { background: var(--amber-soft); border-radius: 8px; padding: 7px 8px; border-bottom: 0; margin-bottom: 4px; }

.stock-row { padding: 6px 0; font-size: 13px; }
.stock-row .top { display: flex; justify-content: space-between; }
.bar { height: 6px; border-radius: 6px; background: var(--soft); margin-top: 4px; position: relative; overflow: hidden; }
.bar i { position: absolute; inset: 0 auto 0 0; background: var(--green); border-radius: 6px; transition: width .6s ease; }
.stock-row.low .bar i { background: var(--red); }
.stock-row.low .top b { color: var(--red); }

.log-row { font-size: 13px; padding: 6px 0; border-bottom: 1px dashed var(--line); display: grid; grid-template-columns: 44px 1fr; gap: 8px; }
.log-row time { color: var(--muted); font-variant-numeric: tabular-nums; }

.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 4px 20px 18px; }

/* -- scene (SVG) ------------------------------------------------------------ */
#scene text { font-family: var(--font); }
.zone-label { font-size: 13px; font-weight: 700; fill: #8a7d70; letter-spacing: .08em; text-transform: uppercase; }
.clickable { cursor: pointer; }
.table .top { fill: #d9a46a; transition: fill .4s; }
.table .left { fill: #b98250; }
.table .right { fill: #9c6a3f; }
.table.busy .top { fill: #f5a061; }
.table.bill .top { fill: #f6c445; }
.table .code { font-size: 12px; font-weight: 800; fill: #4a3b2e; }
.table .ring { fill: none; stroke: transparent; stroke-width: 3; }
.table.bill .ring { stroke: var(--amber); animation: pulse 1.2s ease-in-out infinite; }
.table.selected .ring { stroke: var(--accent); }
.zone-hit { fill: transparent; }
.zone-hit:hover { fill: rgba(240, 115, 31, .06); }
.actor .tag-bg { fill: #fff; stroke: var(--line); }
.actor .tag-text { font-size: 10px; font-weight: 700; fill: #4a3b2e; }
.bubble rect { fill: #fff; stroke: #e2d8cc; }
.bubble text { font-size: 11px; font-weight: 600; fill: var(--ink); }
.pulse-ring { fill: none; stroke: var(--accent); stroke-width: 3; animation: grow 1.4s ease-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
@keyframes grow { 0% { opacity: .9; transform: scale(.6); } 100% { opacity: 0; transform: scale(1.6); } }
.pulse-ring { transform-box: fill-box; transform-origin: center; }

/* -- small screens ---------------------------------------------------------- */
@media (max-width: 1180px) {
  .layout { grid-template-columns: minmax(0, 1fr) 320px; }
  .scenarios { grid-column: 1 / -1; position: static; }
  .scenarios ol { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .scenario .steps { display: none !important; }
  .hint { display: none; }
}
@media (max-width: 820px) {
  .topbar { padding: 10px 16px; }
  .brand-tag { display: none; }
  .layout { grid-template-columns: minmax(0, 1fr); padding: 12px 16px; gap: 12px; }
  .scenarios { padding: 12px; }
  .scenarios h2 { display: none; }
  .scenarios ol { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: minmax(150px, 1fr); overflow-x: auto; padding-bottom: 2px; }
  .panels { position: static; }
  .legend { display: none; }
  .narration { flex-direction: column; gap: 4px; }
  .narration p { font-size: 14px; }
  .tstep { font-size: 10px; }
  .tab-body { max-height: none; }
  .controls { width: 100%; }
  .controls .btn.primary { flex: 1; }
}
