@font-face {
  font-family: "Kenney Mini";
  src: url("assets/fonts/kenney-mini.ttf") format("truetype");
  font-display: swap;
}

:root {
  color-scheme: light;
  --bg: #fcfcfb;
  --card: #ffffff;
  --line: #e4e1da;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #77756f;
  --accent: #6250d6;
  --off: #6b6a66;
  --on: #1b8a5a;
  --risky: #c2410c;
  /* Chart series: reference palette slots 1-3, fixed order. */
  --safe: #2a78d6;
  --greedy: #eb6834;
  --sensible: #1baf7a;
  --stage: #1b1420;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #1a1a19;
    --card: #222220;
    --line: #34332f;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #9a998f;
    --accent: #9085e9;
    --off: #a3a29a;
    --on: #3fbf86;
    --risky: #f08a5d;
    --safe: #3987e5;
    --greedy: #d95926;
    --sensible: #199e70;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.wrap { max-width: 720px; margin: 0 auto; padding: 20px 14px 40px; }
a { color: var(--accent); }

h1 { font-size: 1.6rem; line-height: 1.2; margin: 0 0 .5em; }
.intro p { color: var(--text-2); margin: 0 0 1em; }
#nav { display: flex; flex-wrap: wrap; gap: 6px; }
#nav a {
  text-decoration: none; color: var(--text); border: 1px solid var(--line);
  background: var(--card); border-radius: 999px; padding: 3px 11px; font-size: .88rem;
}
#nav a b { color: var(--accent); margin-right: 2px; }
#nav a:hover { border-color: var(--accent); }

.badge {
  display: inline-block; font: 11px/1 "Kenney Mini", ui-monospace, monospace;
  letter-spacing: .04em; text-transform: uppercase; padding: 4px 7px 3px; border-radius: 4px;
  color: #fff; background: var(--off); vertical-align: 1px; white-space: nowrap;
}
.badge.on { background: var(--on); }

.trick { margin: 44px 0 0; padding-top: 18px; border-top: 1px solid var(--line); scroll-margin-top: 12px; }
.trick h2 { font-size: 1.3rem; margin: 0 0 .3em; display: flex; align-items: center; gap: 10px; }
.trick h2 .num {
  font: 700 15px/1 system-ui, sans-serif; color: #fff; background: var(--accent);
  width: 26px; height: 26px; border-radius: 6px; display: inline-grid; place-items: center;
}
.what { margin: 0 0 .3em; }
.seen { margin: 0 0 14px; color: var(--muted); font-size: .9rem; }

.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.panel { min-width: 0; display: flex; flex-direction: column; }
.ph { display: flex; align-items: baseline; gap: 8px; margin-bottom: 6px; min-height: 2.6em; }
.ph .sub { font-size: .82rem; color: var(--text-2); line-height: 1.3; }
canvas {
  display: block; width: 100%; aspect-ratio: 16 / 9; background: var(--stage);
  border-radius: 8px; image-rendering: pixelated; touch-action: manipulation;
}
.panel.on canvas { box-shadow: 0 0 0 2px var(--on); }
.panel.off canvas { box-shadow: 0 0 0 2px color-mix(in srgb, var(--off) 45%, transparent); }
canvas:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.caption {
  margin: 8px 0 0; font-size: .86rem; line-height: 1.4; color: var(--text);
  min-height: 4.2em; padding: 7px 9px; background: var(--card); border: 1px solid var(--line); border-radius: 6px;
}

.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.actions[hidden] { display: none; }
button {
  font: inherit; font-size: .86rem; cursor: pointer; border-radius: 6px; padding: 7px 12px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); min-height: 36px;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
button:disabled { opacity: .45; cursor: default; }
.act { flex: 1 1 auto; }
.act.risky { border-color: color-mix(in srgb, var(--risky) 55%, var(--line)); color: var(--risky); font-weight: 600; }
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.controls .play { background: var(--accent); color: #fff; border-color: var(--accent); }
.play-note { display: none; flex-basis: 100%; margin: 2px 0 0; font-size: .85rem; color: var(--text-2); }
.playing .play-note { display: block; }

/* Simulation charts */
.sim { position: relative; margin-top: 22px; padding: 14px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
.sim h3 { font-size: 1rem; margin: 0 0 .2em; }
.sim-note { margin: 0 0 10px; font-size: .84rem; color: var(--text-2); }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.side { margin: 0; min-width: 0; }
.side figcaption { margin-bottom: 6px; }
.row { display: grid; grid-template-columns: 86px 1fr; gap: 8px; align-items: start; margin-bottom: 8px; }
.who { display: grid; grid-template-columns: 10px 1fr; column-gap: 5px; font-size: .82rem; line-height: 1.25; }
.who .sw { width: 10px; height: 10px; border-radius: 2px; margin-top: 3px; }
.who small { grid-column: 2; color: var(--muted); font-size: .72rem; }
.sw.safe { background: var(--safe); } .sw.sensible { background: var(--sensible); } .sw.greedy { background: var(--greedy); }
.plot { min-width: 0; }
.hist { display: block; width: 100%; height: 40px; overflow: visible; }
.hist .bar.safe { fill: var(--safe); } .hist .bar.sensible { fill: var(--sensible); } .hist .bar.greedy { fill: var(--greedy); }
.hist .hit { fill: transparent; }
.hist .bin:hover .bar { opacity: .75; }
.hist .base { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }
.hist .mean { stroke: var(--text); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.stats { font-size: .72rem; color: var(--text-2); margin-top: 2px; font-variant-numeric: tabular-nums; }
.axis { display: flex; justify-content: space-between; margin-left: 94px; font-size: .7rem; color: var(--muted); border-top: 1px solid var(--line); padding-top: 2px; }
.verdict { font-size: .82rem; margin: 10px 0 0; padding: 7px 9px; border-radius: 6px; background: color-mix(in srgb, var(--text) 5%, transparent); }
.verdict.real { border-left: 3px solid var(--on); }
.verdict.flat, .verdict.fake { border-left: 3px solid var(--off); }
.key { font-size: .75rem; color: var(--muted); margin: 12px 0 6px; }
details { font-size: .82rem; }
summary { cursor: pointer; color: var(--accent); }
table { border-collapse: collapse; width: 100%; margin-top: 8px; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 3px 6px; border-bottom: 1px solid var(--line); }
th:nth-child(-n+2), td:nth-child(-n+2) { text-align: left; }
.tip {
  position: absolute; transform: translateX(-50%); pointer-events: none; z-index: 2;
  background: var(--text); color: var(--bg); font-size: .76rem; padding: 4px 8px; border-radius: 5px; white-space: nowrap;
}

.foot { margin-top: 48px; font-size: .8rem; color: var(--muted); }
code { font-size: .9em; }

/* Solo mode: just the one trick, no page chrome. */
.solo .intro, .solo .foot { display: none; }
.solo .wrap { padding-top: 8px; }
.solo .trick { margin-top: 0; border-top: 0; padding-top: 0; }

@media (max-width: 600px) {
  .cols { grid-template-columns: 1fr; }
}
@media (max-width: 540px) {
  .wrap { padding: 14px 12px 32px; }
  h1 { font-size: 1.35rem; }
  .pair { grid-template-columns: 1fr; gap: 18px; }
  .ph { min-height: 0; }
  .caption { min-height: 0; }
  .sim { padding: 12px 10px; }
}
