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

:root {
  --bg: #f6f4ef;
  --card: #ffffff;
  --ink: #1d2333;
  --muted: #5d6475;
  --line: #e3dfd6;
  --off: #b4533a;
  --on: #2f8a57;
  --accent: #3a6fd8;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181f;
    --card: #1e222c;
    --ink: #e9ebf0;
    --muted: #a3a9b7;
    --line: #2e3442;
    --off: #e0866d;
    --on: #6fcf97;
    --accent: #7ea6ff;
  }
}

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

.intro h1 {
  font-family: 'KenneyMiniSquare', system-ui, sans-serif;
  font-weight: normal;
  font-size: 26px;
  line-height: 1.2;
  margin: 0 0 10px;
}
.intro p { margin: 0 0 8px; color: var(--muted); }
.intro b { color: var(--ink); }
.t-off { color: var(--off) !important; }
.t-on { color: var(--on) !important; }
.hint { font-size: 14px; }

/* ---------- one trick ---------- */
.trick {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 14px 12px;
  margin: 18px 0;
  scroll-margin-top: 12px;
}
.trick-head { display: flex; gap: 10px; align-items: baseline; }
.trick-num {
  flex: none;
  font-family: 'KenneyMiniSquare', monospace;
  font-size: 13px;
  width: 24px; height: 24px; line-height: 24px;
  text-align: center;
  border-radius: 6px;
  background: var(--ink); color: var(--card);
  transform: translateY(-2px);
}
.trick h2 {
  font-family: 'KenneyMiniSquare', system-ui, sans-serif;
  font-weight: normal;
  font-size: 19px;
  margin: 0;
}
.trick h2 a { color: inherit; text-decoration: none; }
.trick h2 code { font: 12px ui-monospace, Menlo, monospace; color: var(--muted); margin-left: 6px; }
.lede { margin: 4px 0 12px; color: var(--muted); font-size: 15px; }

.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.panel { margin: 0; min-width: 0; display: flex; flex-direction: column; }
.tag {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; letter-spacing: .02em; text-transform: uppercase;
  margin: 0 0 5px;
}
.tag::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.panel.off .tag { color: var(--off); }
.panel.on .tag { color: var(--on); }

.screen {
  position: relative;
  border-radius: 6px;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  background: #dff6f5;
  cursor: pointer;
  outline: 2px solid transparent;
  outline-offset: 2px;
  touch-action: manipulation;
}
.screen canvas { display: block; width: 100%; height: 100%; }
.screen:focus-visible { outline-color: var(--accent); }
.panel.playing .screen { outline-color: var(--accent); cursor: default; }

.chip {
  position: absolute; right: 6px; bottom: 6px;
  font: 600 11px/1 system-ui, sans-serif;
  padding: 5px 7px;
  border-radius: 999px;
  background: rgba(29,35,51,.82); color: #fff;
  pointer-events: none;
  opacity: 0; transition: opacity .15s;
}
.screen:hover .chip, .panel.playing .chip, .screen:focus-visible .chip { opacity: 1; }
@media (hover: none) { .chip { opacity: .9; } }
.panel.playing .chip { background: var(--accent); }

.bigplay {
  position: absolute; inset: 0; margin: auto;
  width: 54px; height: 54px; border-radius: 50%;
  border: 0; background: rgba(29,35,51,.82); color: #fff;
  font-size: 22px; cursor: pointer; display: none;
}
.trick.idle .bigplay { display: block; }

.cap {
  margin: 7px 0 2px;
  font-size: 14px; line-height: 1.4;
  min-height: 4.2em;
  transition: opacity .2s;
}
.cap.swap { opacity: 0; }
.stats { margin: 0; font: 12px ui-monospace, Menlo, monospace; color: var(--muted); }
.stats b { color: var(--ink); font-weight: 600; }

.bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px;
  margin-top: 10px; padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 13px; color: var(--muted);
}
button.btn {
  font: 600 13px system-ui, sans-serif;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--bg); color: var(--ink);
  cursor: pointer;
}
button.btn:hover { border-color: var(--muted); }
button.btn.stop { display: none; }
.trick.has-player button.btn.stop { display: inline-block; }
.keys { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.key { display: inline-flex; align-items: center; gap: 4px; }
.kc {
  display: inline-block; width: 28px; height: 28px; overflow: hidden;
  background: #1d2333; border-radius: 5px;
}
.kc img { display: block; width: 32px; height: 32px; margin: -2px; }

/* touch controls, only while playing on a touch screen */
.pad { display: none; margin-top: 10px; gap: 8px; justify-content: space-between; user-select: none; -webkit-user-select: none; }
.trick.has-player.touch .pad { display: flex; }
.pad .grp { display: flex; gap: 8px; }
.pad button {
  min-width: 58px; height: 52px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  font: 600 14px system-ui, sans-serif;
  touch-action: none;
}
.pad button.down { background: var(--accent); color: #fff; }

.foot { margin-top: 26px; font-size: 13px; color: var(--muted); text-align: center; }
.noscript { padding: 20px; text-align: center; }

/* phones: stack the two sides */
@media (max-width: 560px) {
  main { padding: 16px 10px 32px; }
  .intro h1 { font-size: 22px; }
  .trick { padding: 12px 10px 10px; }
  .pair { grid-template-columns: 1fr; gap: 14px; }
  .cap { min-height: 0; }
}

/* ?trick=<id>&solo : just the one demo, no page chrome */
body.solo { background: transparent; }
body.solo main { padding: 0; }
body.solo .intro, body.solo .foot { display: none; }
body.solo .trick { margin: 0; }
