@font-face { font-family: KenneyFuture; src: url(../assets/kenney-fonts/KenneyFuture.ttf) format('truetype'); font-display: swap; }
@font-face { font-family: KenneyMini; src: url(../assets/kenney-fonts/KenneyMini.ttf) format('truetype'); font-display: block; }

.viz-root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --surface-2: #f2f1ee;
  --border: #e2e0da;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #7a7974;
  --grid: #d9d7d0;
  --series-1: #2a78d6;
  --series-1-fill: rgba(42, 120, 214, .14);
  --mark-new: #eb6834;
  --mark-twist: #6250d6;
  --band-rest: #1baf7a;
  --band-pad: #8a8780;
  --band-phase: #b9b6ad;
  --accent: #eb6834;
  --on: #1baf7a;
  --off: #8a8780;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .viz-root {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --surface-2: #232321;
    --border: #353532;
    --text-primary: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #8f8e86;
    --grid: #3a3a37;
    --series-1: #3987e5;
    --series-1-fill: rgba(57, 135, 229, .2);
    --mark-new: #d95926;
    --mark-twist: #9085e9;
    --band-rest: #199e70;
    --band-pad: #8f8e86;
    --band-phase: #55554f;
    --accent: #d95926;
    --on: #199e70;
    --off: #8f8e86;
  }
}
:root[data-theme="dark"] .viz-root {
  color-scheme: dark;
  --surface-1: #1a1a19; --surface-2: #232321; --border: #353532;
  --text-primary: #f0efec; --text-secondary: #c3c2b7; --text-muted: #8f8e86; --grid: #3a3a37;
  --series-1: #3987e5; --series-1-fill: rgba(57, 135, 229, .2);
  --mark-new: #d95926; --mark-twist: #9085e9; --band-rest: #199e70; --band-pad: #8f8e86; --band-phase: #55554f;
  --accent: #d95926; --on: #199e70; --off: #8f8e86;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: transparent; }
.viz-root {
  max-width: 720px; margin: 0 auto; padding: 16px 12px 32px;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text-primary); background: var(--surface-1);
}
.solo .viz-root { padding: 8px; }
.solo .intro, .solo .page-foot { display: none; }

h1, h2 { font-family: KenneyFuture, system-ui, sans-serif; font-weight: normal; letter-spacing: .01em; margin: 0; }
h1 { font-size: 26px; line-height: 1.2; margin-bottom: 8px; }
.intro p { color: var(--text-secondary); margin: 0 0 8px; }
.intro .keys { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--text-secondary); }
.intro .keys a { color: inherit; }
code { font: 12px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace; }

.trick { margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--border); }
.solo .trick { margin: 0; padding: 0; border: 0; }
.trick-head { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: start; }
.num {
  font-family: KenneyFuture, system-ui, sans-serif; font-size: 18px; width: 34px; height: 34px;
  display: grid; place-items: center; border-radius: 8px; background: var(--accent); color: #fff;
}
.trick h2 { font-size: 20px; line-height: 1.2; }
.lede { margin: 4px 0 0; color: var(--text-secondary); }
.solo-link { font-size: 12px; color: var(--text-muted); text-decoration: none; white-space: nowrap; padding-top: 4px; }
.solo-link:hover { color: var(--text-primary); text-decoration: underline; }

.stage { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 14px; }
.side { margin: 0; min-width: 0; display: flex; flex-direction: column; }
.side-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.tag {
  font-family: KenneyFuture, system-ui, sans-serif; font-size: 13px; padding: 2px 8px 1px; border-radius: 4px; color: #fff;
}
.side.off .tag { background: var(--off); }
.side.on .tag { background: var(--on); }
.side-head code { color: var(--text-muted); }
.setup { margin: 0 0 6px; font-size: 13px; line-height: 1.4; color: var(--text-secondary); min-height: 3.6em; }
.screen { position: relative; border-radius: 6px; overflow: hidden; background: #0e1020; line-height: 0; outline-offset: 2px; }
.screen canvas { width: 100%; aspect-ratio: 4 / 3; display: block; image-rendering: pixelated; cursor: pointer; }
.side.playing .screen { box-shadow: 0 0 0 3px var(--accent); }
.side.playing .screen canvas { touch-action: none; cursor: crosshair; }
.screen canvas:focus-visible { outline: 2px solid var(--series-1); }

.graph { position: relative; margin-top: 6px; }
.graph canvas { width: 100%; height: 60px; display: block; touch-action: pan-y; }
.tip {
  position: absolute; bottom: calc(100% + 4px); left: 0; z-index: 3; pointer-events: none;
  padding: 5px 8px; border-radius: 6px; font-size: 12px; line-height: 1.35; white-space: nowrap;
  background: var(--text-primary); color: var(--surface-1); box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.tip .tip-new { color: var(--mark-new); }
.tip .tip-twist { color: var(--mark-twist); }
.axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-muted); margin-top: 2px; gap: 6px; }
.axis span:nth-child(2) { text-align: center; }
.caption { margin: 8px 0 0; font-size: 13px; line-height: 1.4; min-height: 4.2em; color: var(--text-primary); }
.caption b { font-variant-numeric: tabular-nums; color: var(--text-muted); font-weight: 600; margin-right: 2px; }
.stat {
  margin: 6px 0 0; font-size: 12.5px; line-height: 1.4; padding: 6px 8px; border-radius: 6px;
  background: var(--surface-2); color: var(--text-secondary); font-variant-numeric: tabular-nums; min-height: 3.4em;
}
.stat b { color: var(--text-primary); }

.controls { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; align-items: center; }
.controls .spacer { flex: 1; }
.btn {
  font: 600 13px/1 system-ui, -apple-system, "Segoe UI", sans-serif; padding: 8px 12px; min-height: 36px;
  border-radius: 6px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-primary); cursor: pointer;
}
.btn:hover { border-color: var(--text-muted); }
.btn:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; }
.btn[aria-pressed="true"].play { background: var(--accent); border-color: var(--accent); color: #fff; }
.hint { margin: 8px 0 0; font-size: 13px; padding: 6px 10px; border-left: 3px solid var(--accent); background: var(--surface-2); border-radius: 0 6px 6px 0; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 10px 0 0; font-size: 12px; color: var(--text-secondary); }
.lg { display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 16px; height: 10px; border-radius: 2px; }
.sw-rest { background: color-mix(in srgb, var(--band-rest) 25%, transparent); border-bottom: 2px solid var(--band-rest); }
.sw-pad { background: repeating-linear-gradient(-45deg, var(--band-pad) 0 1px, transparent 1px 4px); opacity: .8; }
.sw-phase { width: 2px; height: 12px; background: var(--band-phase); }
.why { margin: 10px 0 0; font-size: 14px; color: var(--text-secondary); }
.err { color: var(--text-secondary); }
.page-foot { margin-top: 32px; font-size: 12px; color: var(--text-muted); }
.page-foot a { color: inherit; }

@media (max-width: 600px) {
  .stage { grid-template-columns: minmax(0, 1fr); gap: 22px; }
  .setup, .caption, .stat { min-height: 0; }
  h1 { font-size: 22px; }
  .controls .spacer { display: none; }
  .controls .btn { flex: 1 1 auto; }
}
