@font-face {
  font-family: "KMini";
  src: url("assets/kenney-mini.ttf") format("truetype");
  font-display: block;
}

.dt-root {
  color-scheme: light;
  --bg: #fcfcfb;
  --panel: #ffffff;
  --ink: #0b0b0b;
  --ink2: #52514e;
  --muted: #76756f;
  --line: #e2e1dc;
  --grid: #ecebe7;
  --band: #e6e5df;
  --band-ink: #6b6a64;
  --off: #eb6834;
  --on: #2a78d6;
  --good: #0ca30c;
  --crit: #d03b3b;
  --btn: #f1f0ec;
  --btn-hover: #e6e5df;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .dt-root {
    color-scheme: dark;
    --bg: #1a1a19;
    --panel: #222221;
    --ink: #f0efec;
    --ink2: #c3c2b7;
    --muted: #9a998f;
    --line: #383835;
    --grid: #2e2e2c;
    --band: #353532;
    --band-ink: #b2b1a8;
    --off: #d95926;
    --on: #3987e5;
    --btn: #2e2e2c;
    --btn-hover: #3a3a37;
  }
}
:root[data-theme="dark"] .dt-root {
  color-scheme: dark;
  --bg: #1a1a19; --panel: #222221; --ink: #f0efec; --ink2: #c3c2b7; --muted: #9a998f;
  --line: #383835; --grid: #2e2e2c; --band: #353532; --band-ink: #b2b1a8;
  --off: #d95926; --on: #3987e5; --btn: #2e2e2c; --btn-hover: #3a3a37;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body.dt-root {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
.wrap { max-width: 720px; margin: 0 auto; padding: 24px 12px 48px; }

header h1 { font-size: 1.6rem; line-height: 1.2; margin: 0 0 .5rem; }
header p { margin: .4rem 0; color: var(--ink2); }
.formula {
  font: 600 .9rem/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 12px; margin: .8rem 0; color: var(--ink);
}
nav.toc { display: flex; flex-wrap: wrap; gap: 6px; margin: 1rem 0 0; }
nav.toc a {
  font-size: .85rem; text-decoration: none; color: var(--ink);
  background: var(--btn); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px;
}
nav.toc a:hover { background: var(--btn-hover); }

section.trick { margin-top: 40px; scroll-margin-top: 12px; }
section.trick h2 { font-size: 1.25rem; margin: 0 0 .25rem; display: flex; align-items: baseline; gap: .5rem; flex-wrap: wrap; }
section.trick h2 code { font-size: .8rem; font-weight: 500; color: var(--muted); }
.lede { margin: 0 0 12px; color: var(--ink2); }

.stage { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; outline: none; border-radius: 12px; }
.stage:focus-visible { box-shadow: 0 0 0 3px color-mix(in srgb, var(--on) 45%, transparent); }
.side {
  --c: var(--off);
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px; display: flex; flex-direction: column; gap: 6px; min-width: 0;
}
.side.on { --c: var(--on); }
.side-head { display: flex; align-items: center; gap: 6px; font-size: .78rem; line-height: 1.25; color: var(--ink2); min-height: 2.5em; }
.tag {
  flex: none; font: 10px/1 "KMini", system-ui, sans-serif; letter-spacing: .04em; text-transform: uppercase;
  color: var(--ink); border: 1px solid var(--line); border-radius: 4px; padding: 4px 5px 3px 4px;
  display: inline-flex; align-items: center; gap: 4px; background: var(--bg);
}
.tag::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--c); }
.arena { position: relative; }
.arena canvas {
  display: block; width: 100%; aspect-ratio: 192 / 112; border-radius: 6px;
  image-rendering: pixelated; background: #3b2a26; touch-action: manipulation;
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent;
}
.playing .arena canvas { cursor: pointer; }
.pbtns { display: none; gap: 6px; flex-wrap: wrap; }
.playing .pbtns { display: flex; }
.pbtns button { flex: 1 1 0; min-width: 0; }

.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; font-size: .72rem; color: var(--ink2); margin-top: 2px; }
.chart-head .ct { font-weight: 600; color: var(--ink); }
.key { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.key i { display: inline-block; width: 14px; height: 8px; border-radius: 2px; background: var(--band); border: 1px dashed var(--band-ink); }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.chart .ax { fill: var(--muted); font-size: 10px; }
.chart .lbl { fill: var(--ink2); font-size: 11px; }
.chart .val { fill: var(--ink); font-size: 11px; font-weight: 600; }
.chart .bandt { fill: var(--band-ink); font-size: 9.5px; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .base { stroke: var(--line); stroke-width: 1; }
.chart .band { fill: var(--band); stroke: var(--band-ink); stroke-dasharray: 3 2; stroke-width: .75; }
.chart .mark { fill: var(--c); }
.chart .mark.ghost { fill-opacity: .3; stroke: var(--c); stroke-width: 1; stroke-dasharray: 2 1.5; }
.chart .mark.dim { fill-opacity: .55; }
.chart .line { fill: none; stroke: var(--c); stroke-width: 2; stroke-linejoin: round; }
.chart .dot { fill: var(--c); stroke: var(--panel); stroke-width: 2; }
.chart .marker { stroke: var(--ink2); stroke-width: 1; stroke-dasharray: 2 2; }
.chart .ok { fill: var(--good); font-weight: 700; font-size: 11px; }
.chart .bad { fill: var(--crit); font-weight: 700; font-size: 11px; }
.chart .hit { fill: transparent; }
.chart .hit:hover { fill: color-mix(in srgb, var(--ink) 6%, transparent); }
.chart .cur { fill: none; stroke: var(--ink); stroke-width: 1.5; }

.caption { margin: 0; font-size: .86rem; line-height: 1.4; min-height: 4.2em; color: var(--ink); }

.controls { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.controls .hint { font-size: .8rem; color: var(--ink2); flex: 1 1 180px; }
button {
  font: 500 .85rem/1 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink);
  background: var(--btn); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px;
  cursor: pointer; min-height: 36px; touch-action: manipulation;
}
button:hover:not(:disabled) { background: var(--btn-hover); }
button:disabled { opacity: .45; cursor: default; }
button[aria-pressed="true"] { border-color: var(--ink2); }
.progress { height: 3px; background: var(--line); border-radius: 2px; overflow: hidden; margin-top: 8px; }
.progress span { display: block; height: 100%; width: 0; background: var(--ink2); }
.solo-link { font-size: .78rem; color: var(--muted); }

.tip {
  position: fixed; z-index: 10; pointer-events: none; background: var(--ink); color: var(--bg);
  font-size: .75rem; line-height: 1.35; padding: 5px 8px; border-radius: 6px; max-width: 240px;
  opacity: 0; transition: opacity .1s; white-space: pre-line;
}
.tip.show { opacity: 1; }

footer { margin-top: 48px; font-size: .8rem; color: var(--muted); }
footer a { color: inherit; }

/* Solo embed: just the one trick, no page chrome */
.solo header, .solo footer, .solo nav, .solo .solo-link, .solo section.trick:not(.active) { display: none; }
.solo .wrap { padding: 8px; }
.solo section.trick { margin-top: 0; }

@media (max-width: 560px) {
  .stage { grid-template-columns: 1fr; }
  .side-head { min-height: 0; }
  .caption { min-height: 0; }
  header h1 { font-size: 1.35rem; }
}
