:root {
  --paper: #f1ece2;
  --card: #fbf8f2;
  --ink: #232a36;
  --ink-2: #5a6070;
  --rule: #d6cebe;
  --accent: #3d6fb6;
  --warn: #b0442f;
  --ok: #2f7d52;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  --sans: "IBM Plex Sans", system-ui, sans-serif;
  --serif: "Instrument Serif", Georgia, serif;
  --gutter: 24px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; -webkit-appearance: none; appearance: none; }
button:focus-visible, summary:focus-visible, .panel-content:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: #ece5d6;
  padding: 0.05em 0.35em;
  border-radius: 3px;
}

#stage { position: fixed; inset: 0; overflow: hidden; }
#stage canvas { display: block; cursor: grab; }
#stage canvas:active { cursor: grabbing; }
.labels { position: absolute; inset: 0; pointer-events: none; }

/* ---------- in-scene labels ---------- */
.lbl { font-family: var(--mono); font-size: 11px; white-space: nowrap; pointer-events: none; transition: none; }
.lbl.tag {
  background: var(--card);
  border: 1px solid var(--ink);
  padding: 2px 7px;
  border-radius: 2px;
  box-shadow: 2px 2px 0 var(--ink);
}
.lbl.tag.soft { border-color: var(--rule); box-shadow: none; color: var(--ink-2); }
.lbl.tag.big { font-size: 12.5px; font-weight: 600; }
.lbl.tag.warn { border-color: var(--warn); color: var(--warn); box-shadow: 2px 2px 0 var(--warn); }
.lbl.tag.ok { border-color: var(--ok); color: var(--ok); box-shadow: 2px 2px 0 var(--ok); }
.lbl.tag.acc { border-color: var(--accent); color: var(--accent); box-shadow: 2px 2px 0 var(--accent); }
.lbl.note {
  background: var(--ink);
  color: var(--card);
  padding: 3px 8px;
  border-radius: 2px;
  font-size: 11.5px;
  animation: pop 0.35s cubic-bezier(.2,1.4,.4,1) both;
}
.lbl.note.warn { background: var(--warn); }
.lbl.note.ok { background: var(--ok); }
.lbl.plain { color: var(--ink-2); }
@keyframes pop { from { opacity: 0; translate: 0 6px; } }

/* ---------- top bar ---------- */
.top {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 16px var(--gutter);
  pointer-events: none;
  z-index: 5;
}
.top > * { pointer-events: auto; }
.brand {
  display: flex; align-items: center; gap: 10px;
  background: none; border: 0; padding: 0;
}
.brand-mark {
  width: 30px; height: 30px; display: grid; place-items: center;
  border: 1.5px solid var(--ink); background: var(--card);
  font-family: var(--mono); font-size: 17px; box-shadow: 2px 2px 0 var(--ink);
}
.brand-name { font-family: var(--serif); font-size: 24px; letter-spacing: 0.01em; }
.brand-name em { font-style: italic; }
#tabs { display: flex; gap: 4px; min-width: 0; margin-left: auto; overflow-x: auto; scrollbar-width: none; }
#tabs::-webkit-scrollbar { display: none; }
.tab {
  font-family: var(--mono); font-size: 12px;
  background: var(--card); border: 1px solid var(--rule);
  padding: 7px 11px; border-radius: 2px; white-space: nowrap;
  transition: border-color .15s, transform .15s;
}
.tab span { color: var(--ink-2); margin-right: 6px; }
.tab:hover { border-color: var(--ink); }
.tab[aria-current="true"] {
  border-color: var(--ink); background: var(--ink); color: var(--card);
}
.tab[aria-current="true"] span { color: #9aa3b5; }

.tools { display: flex; gap: 4px; }
.tool {
  font-family: var(--mono); font-size: 12px; white-space: nowrap;
  background: var(--card); border: 1px solid var(--rule); padding: 7px 11px; border-radius: 2px;
}
.tool:hover { border-color: var(--ink); }
.tool.on { border-color: var(--ink); }
.tool[aria-pressed="true"]#play { background: var(--accent); border-color: var(--accent); color: #fff; }
.tool#lbls:not(.on) { color: var(--ink-2); text-decoration: line-through; }
.labels.off { display: none; }

/* ---------- step panel ---------- */
.panel {
  position: fixed;
  left: var(--gutter); bottom: var(--gutter);
  width: 410px;
  max-height: calc(100vh - 110px);
  max-height: calc(100dvh - 110px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--card);
  border: 1.5px solid var(--ink);
  box-shadow: 6px 6px 0 var(--ink);
  padding: 20px 22px 18px;
  z-index: 4;
}
.panel-content { min-height: 0; overflow-y: auto; overscroll-behavior: contain; overflow-wrap: break-word; }
.controls, .progress { flex-shrink: 0; }
.panel-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.chip {
  font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: #fff; background: var(--accent); padding: 3px 8px; border-radius: 2px;
}
.struct { font-family: var(--mono); font-size: 11.5px; color: var(--ink-2); }
.count {
  margin-top: 16px;
  font-family: var(--mono); font-size: 11px; color: var(--ink-2); letter-spacing: .06em;
}
.verdict { font-weight: 600; letter-spacing: .08em; }
.panel[data-verdict="good"] { box-shadow: 6px 6px 0 var(--ok); border-color: var(--ok); }
.panel[data-verdict="good"] .verdict { color: var(--ok); }
.panel[data-verdict="bad"] { box-shadow: 6px 6px 0 var(--warn); border-color: var(--warn); }
.panel[data-verdict="bad"] .verdict { color: var(--warn); }
.panel h2 {
  font-family: var(--serif); font-weight: 400;
  font-size: 31px; line-height: 1.08; margin: 4px 0 10px;
}
.body { font-size: 14.5px; line-height: 1.6; color: #2f3644; min-height: 7.5em; }
.body b { font-weight: 600; color: var(--ink); }
.nums { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.nums:empty { display: none; }
.num {
  border: 1px solid var(--rule); border-radius: 2px; padding: 6px 10px 5px; min-width: 84px;
  background: var(--card);
  background: color-mix(in srgb, var(--accent) 6%, var(--card));
}
.num b { font-family: var(--serif); font-weight: 400; font-size: 24px; line-height: 1; color: var(--accent); }
.num span { font-family: var(--mono); font-size: 11px; margin-left: 4px; color: var(--ink-2); }
.num small { display: block; font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); margin-top: 3px; }
.deep { margin-top: 12px; font-size: 13.5px; line-height: 1.5; }
.deep[hidden] { display: none; }
.deep summary { font-family: var(--mono); font-size: 12px; cursor: pointer; color: var(--accent); }
.deep ul { margin: 8px 0 0; padding-left: 18px; color: #3a4150; }
.deep li + li { margin-top: 5px; }
.progress { height: 3px; background: var(--rule); margin-top: 14px; overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); }
.controls { display: flex; align-items: center; gap: 8px; margin-top: 16px; }
.btn {
  border: 1.5px solid var(--ink); background: var(--card);
  height: 36px; min-width: 36px; padding: 0 12px; border-radius: 2px;
  font-family: var(--mono); font-size: 13px;
  transition: transform .1s, box-shadow .1s;
  box-shadow: 2px 2px 0 var(--ink);
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 3px 3px 0 var(--ink); }
.btn:active { transform: translate(1px, 1px); box-shadow: 0 0 0 var(--ink); }
.btn:disabled { opacity: .35; pointer-events: none; }
.btn.primary { background: var(--ink); color: var(--card); }
.btn.ghost { box-shadow: none; border-color: var(--rule); }
.btn:focus-visible, .tab:focus-visible, .dot:focus-visible, .card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.dots { display: flex; gap: 5px; flex: 1; justify-content: center; }
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  border: 1.5px solid var(--ink); background: transparent; padding: 0;
}
.dot[aria-current="true"] { background: var(--accent); border-color: var(--accent); transform: scale(1.25); }
.dot.seen { background: var(--ink); }

.hint {
  position: fixed; right: var(--gutter); bottom: 18px;
  font-family: var(--mono); font-size: 11px; color: var(--ink-2);
  pointer-events: none;
}
.touch-hint { display: none; }

/* ---------- intro ---------- */
.intro {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(241, 236, 226, .94);
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  padding: max(40px, env(safe-area-inset-top)) max(var(--gutter), env(safe-area-inset-right)) max(40px, env(safe-area-inset-bottom)) max(var(--gutter), env(safe-area-inset-left));
  transition: opacity .45s, visibility .45s;
}
.intro.hidden { opacity: 0; visibility: hidden; }
.intro-inner { max-width: 1040px; width: 100%; min-width: 0; margin: auto; }
.eyebrow { font-family: var(--mono); font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-2); margin: 0; }
.intro h1 {
  font-family: var(--serif); font-weight: 400;
  font-size: clamp(42px, 7vw, 84px); line-height: .98; margin: 12px 0 18px;
  max-width: 14ch;
}
.intro h1 em { font-style: italic; color: var(--accent); }
.lede { font-size: 17px; line-height: 1.55; max-width: 58ch; color: #3a4150; margin: 0 0 34px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); gap: 16px; }
.card {
  text-align: left;
  background: var(--card); border: 1.5px solid var(--ink);
  padding: 18px 18px 16px; border-radius: 2px;
  box-shadow: 4px 4px 0 var(--ink);
  transition: transform .15s, box-shadow .15s;
  position: relative;
}
.card:hover { transform: translate(-2px, -2px); box-shadow: 6px 6px 0 var(--ink); }
.card .num { font-family: var(--mono); font-size: 11px; color: var(--ink-2); }
.card .name { font-family: var(--serif); font-size: 32px; line-height: 1.05; margin: 6px 0 2px; display: block; }
.card .k {
  display: inline-block; font-family: var(--mono); font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em;
  color: #fff; padding: 2px 7px; border-radius: 2px; margin: 4px 0 10px;
}
.card .t { display: block; font-family: var(--mono); font-size: 12px; color: var(--ink-2); }
.card .bar { position: absolute; top: 0; right: 0; width: 10px; height: 100%; }

.nojs { position: fixed; inset: 0; z-index: 20; margin: 0; padding: 24px; background: var(--paper); display: grid; place-items: center; font-family: var(--mono); }

/* ---------- small screens ---------- */
@media (max-width: 1000px) {
  :root { --gutter: 16px; }
  .top { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px; padding: max(8px, env(safe-area-inset-top)) max(var(--gutter), env(safe-area-inset-right)) 8px max(var(--gutter), env(safe-area-inset-left)); background: var(--paper); }
  #tabs { grid-row: 2; grid-column: 1 / -1; margin-left: 0; width: 100%; }
  .brand { min-width: 0; min-height: 44px; }
  .brand-name { font-size: 21px; }
  .brand-mark { flex-shrink: 0; }
  .tools { grid-column: 2; grid-row: 1; }
  .tool { padding: 7px 9px; }
  .tool, .tab { min-height: 44px; flex-shrink: 0; }
  .panel {
    left: max(var(--gutter), env(safe-area-inset-left)); right: max(var(--gutter), env(safe-area-inset-right)); bottom: max(var(--gutter), env(safe-area-inset-bottom));
    width: auto; max-height: 48vh; max-height: 48dvh; padding: 12px;
    box-shadow: 4px 4px 0 var(--ink);
  }
  .panel h2 { font-size: 25px; }
  .body { font-size: 14px; min-height: 0; }
  .count { margin-top: 10px; }
  .hint { display: none; }
  .controls { display: grid; grid-template-columns: 44px 44px minmax(0, 1fr); gap: 4px 8px; margin-top: 8px; }
  .dots { grid-row: 1; grid-column: 1 / -1; justify-content: flex-start; min-width: 0; overflow-x: auto; gap: 0; }
  .dot { position: relative; flex: 0 0 44px; width: 44px; height: 44px; border: 0; border-radius: 0; background: transparent; }
  .dot::after { content: ''; position: absolute; width: 9px; height: 9px; left: 17px; top: 17px; border: 1.5px solid var(--ink); border-radius: 50%; }
  .dot.seen { background: transparent; }
  .dot.seen::after { background: var(--ink); }
  .dot[aria-current="true"] { background: transparent; transform: none; }
  .dot[aria-current="true"]::after { background: var(--accent); border-color: var(--accent); transform: scale(1.25); }
  .btn { min-width: 44px; height: 44px; padding: 0 8px; white-space: nowrap; }
  .deep summary { min-height: 44px; padding-block: 12px; }
  .progress { margin-top: 8px; }
  .touch-hint { display: block; position: fixed; top: var(--scene-top, 110px); left: max(16px, env(safe-area-inset-left)); right: max(16px, env(safe-area-inset-right)); text-align: center; font: 10px var(--mono); color: var(--ink-2); pointer-events: none; }
  .lbl { font-size: 9.5px; }
}
@media (max-width: 380px) {
  .brand-mark { display: none; }
  .brand-name { font-size: 18px; }
}
@media (max-width: 1000px) and (max-height: 500px) and (orientation: landscape) {
  .top { grid-template-columns: 44px minmax(0, 1fr) auto; }
  .brand { justify-content: center; }
  .brand-name { display: none; }
  #tabs { grid-row: 1; grid-column: 2; }
  .tools { grid-column: 3; }
  .panel { top: var(--landscape-panel-top, 68px); left: auto; width: 44%; max-height: none; padding-block: 8px; }
  .panel-content { flex: 1; }
  .panel-head { display: none; }
  .count { margin-top: 0; }
  .panel h2 { font-size: 21px; }
  .touch-hint { display: none; }
  .dots { display: none; }
}
