/* リソグラフ印刷の色味をイメージした配色（紙 + 蛍光ピンク + ブルー + グリーン） */
:root {
  --paper: #f4f0e6;
  --paper-2: #ebe5d6;
  --ink: #1d1f33;
  --ink-soft: #565a73;
  --blue: #0078bf;
  --pink: #ff48b0;
  --green: #00a95c;
  --yellow: #ffe800;
  --line: #d6cfbd;
  --radius: 14px;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
  --sans: "Zen Kaku Gothic New", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.85;
  /* 紙のざらつき */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.1 0 0 0 0 0.1 0 0 0 0 0.2 0 0 0 .06 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.wrap {
  max-width: 1040px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ---------- 表紙 ---------- */
.hero {
  padding: 88px 0 56px;
  border-bottom: 2px solid var(--ink);
}
.hero .kicker {
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: .14em;
  color: var(--blue);
  margin: 0 0 18px;
}
.hero h1 {
  font-size: clamp(38px, 7.4vw, 84px);
  line-height: 1.15;
  font-weight: 900;
  margin: 0;
  letter-spacing: -.01em;
  /* 版ずれ（ミスレジ）風 */
  text-shadow: 3px 2px 0 rgba(255, 72, 176, .55), -2px -1px 0 rgba(0, 120, 191, .45);
}
.hero h1 .sub {
  display: block;
  font-size: .42em;
  font-weight: 700;
  letter-spacing: .02em;
  margin-top: 18px;
  text-shadow: none;
  color: var(--ink-soft);
}
.hero .lead {
  max-width: 640px;
  margin: 32px 0 0;
  font-size: 18px;
}
.hero .lead strong { background: linear-gradient(transparent 60%, var(--yellow) 60%); }

/* ---------- 章 ---------- */
.chapter {
  padding: 72px 0 40px;
  border-bottom: 1px dashed var(--line);
}
.chapter-head {
  display: flex;
  align-items: baseline;
  gap: 18px;
  margin-bottom: 8px;
}
.chapter-no {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 15px;
  color: var(--paper);
  background: var(--ink);
  padding: 2px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.chapter h2 {
  font-size: clamp(26px, 4.2vw, 40px);
  line-height: 1.3;
  margin: 0;
  font-weight: 900;
}
.chapter h3 {
  font-size: 21px;
  margin: 56px 0 6px;
  font-weight: 900;
}
.prose { max-width: 680px; }
.prose p { margin: 14px 0; }

mark { background: linear-gradient(transparent 55%, var(--yellow) 55%); color: inherit; padding: 0 2px; }
.c-blue { color: var(--blue); font-weight: 700; }
.c-pink { color: var(--pink); font-weight: 700; }
.c-green { color: var(--green); font-weight: 700; }

/* ---------- 実験台（図 + 操作） ---------- */
.lab {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 20px;
  margin-top: 28px;
  align-items: start;
}
.stage {
  position: relative;
  background: #fffdf7;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 6px 6px 0 var(--ink);
}
.stage canvas {
  display: block;
  width: 100%;
  touch-action: none;
  cursor: grab;
}
.stage canvas.dragging { cursor: grabbing; }
.stage .hint {
  position: absolute;
  left: 12px;
  top: 10px;
  font-size: 13px;
  color: var(--ink-soft);
  background: rgba(255, 253, 247, .85);
  padding: 2px 8px;
  border-radius: 6px;
  pointer-events: none;
}

.panel {
  background: var(--paper-2);
  border-radius: var(--radius);
  padding: 18px 18px 20px;
  font-size: 15px;
  line-height: 1.7;
}
.panel h4 {
  margin: 0 0 10px;
  font-size: 14px;
  letter-spacing: .08em;
  color: var(--ink-soft);
  font-weight: 700;
}
.panel + .panel { margin-top: 14px; }

.steps { list-style: none; margin: 0; padding: 0; counter-reset: s; }
.steps li {
  counter-increment: s;
  position: relative;
  padding: 8px 10px 8px 42px;
  border-radius: 10px;
  transition: background .25s, opacity .25s;
}
.steps li::before {
  content: counter(s);
  position: absolute;
  left: 8px;
  top: 8px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  display: grid;
  place-items: center;
  line-height: 1;
}
.steps.playing li { opacity: .35; }
.steps.playing li.on { opacity: 1; background: #fffdf7; }
.steps li.on::before { background: var(--yellow); }

.control { margin: 12px 0 4px; }
.control label {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 700;
}
.control output { font-family: var(--mono); font-weight: 600; }
input[type="range"] {
  width: 100%;
  accent-color: var(--blue);
  height: 28px;
}

.btn {
  appearance: none;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink);
  background: #fffdf7;
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 8px 16px;
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--ink);
  transition: transform .08s, box-shadow .08s, background .15s;
  min-height: 44px;
}
.btn:hover { background: var(--yellow); }
.btn:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--ink); }
.btn.primary { background: var(--pink); color: #fff; }
.btn.primary:hover { background: #ff2aa0; }
.btn[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.btn:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button {
  appearance: none;
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 600;
  border: 2px solid var(--ink);
  background: #fffdf7;
  color: var(--ink);
  border-radius: 8px;
  padding: 4px 9px;
  cursor: pointer;
  min-height: 36px;
}
.seg button[aria-pressed="true"] { background: var(--blue); color: #fff; border-color: var(--blue); }

.readout {
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.8;
  white-space: nowrap;
  overflow-x: auto;
}
.readout .k { display: inline-block; width: 3.6em; font-weight: 600; }

.note {
  font-size: 14px;
  color: var(--ink-soft);
  margin-top: 10px;
}
.warn {
  font-size: 14px;
  background: #fff3c4;
  border-left: 4px solid var(--pink);
  padding: 6px 10px;
  border-radius: 6px;
  margin-top: 10px;
}
.warn[hidden] { display: none; }

.legend { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.legend li { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.legend i { width: 14px; height: 14px; border-radius: 50%; display: inline-block; flex: none; }

/* ---------- 時計 ---------- */
.clock-lab {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 28px;
  align-items: center;
  margin-top: 24px;
}
.clock-lab svg { width: 100%; max-width: 280px; display: block; margin: 0 auto; }
.clock-readout {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.6;
}
.clock-readout .big {
  font-family: var(--mono);
  font-size: 44px;
  font-weight: 600;
  color: var(--pink);
}
.clock-readout .turns { color: var(--blue); }

/* ---------- 大きな数 ---------- */
.bignum {
  margin-top: 28px;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  padding: 22px 22px 24px;
  background: var(--ink);
  color: var(--paper);
}
.bignum .label { font-size: 14px; letter-spacing: .06em; color: #b9bdd6; }
.bignum .digits {
  font-family: var(--mono);
  font-size: clamp(15px, 2.4vw, 22px);
  line-height: 1.5;
  word-break: break-all;
  color: var(--yellow);
  margin: 8px 0 12px;
}
.bignum p { margin: 6px 0; font-size: 16px; }
.bignum strong { color: var(--pink); }

/* ---------- 第3章 ---------- */
.jump-count {
  font-family: var(--mono);
  font-size: 56px;
  font-weight: 600;
  line-height: 1.1;
  color: var(--pink);
}
.jump-count small { font-family: var(--sans); font-size: 18px; color: var(--ink); margin-left: 6px; }

.eq {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 600;
  background: #fffdf7;
  border: 2px solid var(--ink);
  border-radius: 10px;
  display: inline-block;
  padding: 4px 14px;
}

.race { margin-top: 24px; }
.race-controls { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.k-input { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.k-input label { font-weight: 700; font-size: 15px; }
.k-input input {
  font-family: var(--mono);
  font-size: 15px;
  flex: 1 1 280px;
  min-width: 0;
  min-height: 44px;
  padding: 6px 12px;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: #fffdf7;
  color: var(--ink);
}
.k-input input:focus-visible { outline: 3px solid var(--blue); outline-offset: 1px; }
.race-stage canvas { cursor: default; }

.race-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: 14px;
  margin-top: 14px;
}
.race-grid .panel + .panel { margin-top: 0; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  max-height: 132px;
  overflow-y: auto;
  position: relative;
}
.chip {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 6px;
  border: 1.5px solid var(--ink-soft);
  color: var(--ink-soft);
  background: transparent;
  line-height: 1.6;
}
.chip.done.chip-double { background: var(--pink); border-color: var(--pink); color: #fff; }
.chip.done.chip-add { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.chip.now { outline: 3px solid var(--yellow); outline-offset: 1px; }
.path { margin-top: 10px; white-space: normal; word-break: break-all; }

.race-result {
  margin-top: 16px;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--paper);
  padding: 18px 20px;
}
.race-result[hidden] { display: none; }
.race-result .res-row { display: flex; gap: 12px; align-items: baseline; margin: 6px 0; font-size: 16px; }
.race-result b { color: var(--yellow); }
.race-result b.c-pink { color: var(--pink); }
.race-result .note { color: #b9bdd6; }
.race-result code { font-family: var(--mono); color: var(--paper); word-break: break-all; }
.pill {
  flex: none;
  font-size: 13px;
  font-weight: 700;
  padding: 1px 10px;
  border-radius: 999px;
  color: #fff;
}
.pill-pink { background: var(--pink); }
.pill-blue { background: var(--blue); }

/* ---------- 第4章 ---------- */
.game { margin-top: 28px; scroll-margin-top: 16px; }
.level-tabs button { min-width: 52px; font-size: 15px; }
.level-tabs button.cleared::after { content: " ✓"; }
.level-title { margin: 12px 0 0; font-size: 16px; }
.level-title b { font-family: var(--mono); color: var(--pink); }
.stage canvas[hidden] { display: none; }
.numbers {
  padding: 22px 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.numbers[hidden] { display: none; }
.numbers .nb-note { margin: 0; font-size: 15px; color: var(--ink-soft); }
.numbers .nb-row { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.numbers code {
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.6;
  word-break: break-all;
  background: var(--paper-2);
  padding: 6px 10px;
  border-radius: 8px;
  max-width: 100%;
}
.numbers .nb-answer { margin: 0; font-size: 15px; word-break: break-all; }
.numbers .nb-answer b { font-family: var(--mono); color: var(--pink); }
.msg { margin-top: 10px; font-size: 15px; }
.msg:empty { display: none; }
.history { list-style: none; margin: 10px 0 0; padding: 0; max-height: 120px; overflow-y: auto; font-size: 14px; }
.history:empty { display: none; }
.history li { display: flex; gap: 10px; padding: 2px 0; border-top: 1px dashed var(--line); color: var(--ink-soft); }
.history .hk { font-family: var(--mono); font-weight: 600; color: var(--ink); min-width: 6em; }
.brute-box { margin-top: 12px; }
.brute-box[hidden] { display: none; }
.bar { height: 10px; border: 2px solid var(--ink); border-radius: 999px; background: #fffdf7; margin-top: 8px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--pink); }
.table-wrap { overflow-x: auto; margin-top: 10px; }
table.score { border-collapse: collapse; width: 100%; min-width: 620px; font-size: 14px; background: #fffdf7; border: 2px solid var(--ink); border-radius: var(--radius); }
table.score th, table.score td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.score thead th { background: var(--ink); color: var(--paper); font-weight: 700; font-size: 13px; }
table.score tbody th { white-space: nowrap; }
table.score td:nth-child(2), table.score td:nth-child(4) { font-family: var(--mono); font-weight: 600; }
table.score tr.now { background: #fff7c2; }
table.score tr.estimate { background: var(--paper-2); }
table.score tr.estimate td:last-child { color: var(--pink); font-weight: 700; }

/* ---------- 第5章 ---------- */
.live {
  margin-top: 28px;
  background: var(--ink);
  color: var(--paper);
  border-radius: var(--radius);
  padding: 22px 22px 26px;
  box-shadow: 6px 6px 0 var(--pink);
}
.live .label { font-size: 13px; letter-spacing: .06em; color: #b9bdd6; font-weight: 700; }
.live .note { color: #b9bdd6; }
.live-head { display: flex; flex-wrap: wrap; align-items: center; gap: 14px 18px; }
.live-head .btn { box-shadow: 3px 3px 0 var(--paper); border-color: var(--paper); }
.live-head .btn:active { box-shadow: 0 0 0 var(--paper); }
.live-status { margin: 0; font-size: 15px; flex: 1 1 260px; }
.live-stats {
  display: grid;
  grid-template-columns: minmax(0, 2fr) repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-top: 22px;
}
.stat { border-top: 2px solid #3a3d58; padding-top: 10px; min-width: 0; }
.stat .value {
  font-family: var(--mono);
  font-weight: 600;
  font-size: clamp(26px, 4.4vw, 44px);
  color: var(--yellow);
  line-height: 1.2;
  word-break: break-all;
  font-variant-numeric: tabular-nums;
}
.stat .value.small { font-size: 20px; color: var(--paper); }
.stat .sub { font-size: 14px; color: #b9bdd6; }
.digits-compare { margin-top: 26px; }
.dc-row { margin-top: 10px; }
.dc-digits {
  font-family: var(--mono);
  font-size: clamp(14px, 2.1vw, 21px);
  font-weight: 600;
  letter-spacing: .02em;
  line-height: 1.5;
  margin-top: 2px;
}
.dc-digits .grp { white-space: nowrap; display: inline-block; }
.dc-digits .mask { color: #6c7092; }
.dc-digits .lead { color: #474a66; }
.dc-digits .on { color: var(--pink); }
.percent-box { margin-top: 22px; }
.percent {
  font-family: var(--mono);
  font-size: clamp(14px, 2.1vw, 20px);
  line-height: 1.5;
  word-break: break-all;
  margin-top: 2px;
}
.percent .lead { color: #6c7092; }
.percent b { color: var(--pink); }
.percent .note b { color: var(--yellow); }
table.eta { min-width: 560px; }
table.eta tbody th { white-space: normal; font-weight: 700; width: 46%; }
table.eta td.t { font-family: var(--mono); font-weight: 600; color: var(--pink); white-space: nowrap; }

/* ---------- まとめ ---------- */
.summary { padding-bottom: 72px; }
.summary h2 { text-shadow: 2px 2px 0 rgba(255, 72, 176, .5), -1px -1px 0 rgba(0, 120, 191, .4); }
.sum-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin: 24px 0 8px; }
.sum-card { border: 2px solid var(--ink); border-radius: var(--radius); padding: 18px 20px; background: #fffdf7; }
.sum-card p { margin: 8px 0 0; }
.sum-card .tag { display: inline-block; font-weight: 900; font-size: 15px; padding: 1px 12px; border-radius: 999px; color: #fff; }
.sum-card.go .tag { background: var(--blue); }
.sum-card.back .tag { background: var(--pink); }

/* ---------- この先 ---------- */
.next {
  padding: 56px 0 96px;
}
.next ol {
  list-style: none;
  padding: 0;
  margin: 18px 0 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.next ol.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.next li {
  border: 2px dashed var(--ink-soft);
  border-radius: var(--radius);
  padding: 16px;
  color: var(--ink-soft);
  font-size: 15px;
  line-height: 1.6;
}
.next li b { display: block; color: var(--ink); font-size: 17px; margin-bottom: 4px; }

footer {
  font-size: 13px;
  color: var(--ink-soft);
  padding: 24px 0 48px;
  border-top: 1px solid var(--line);
}

/* ---------- スマホ ---------- */
@media (max-width: 820px) {
  body { font-size: 16px; }
  .wrap { padding: 0 16px; }
  .hero { padding: 56px 0 40px; }
  .lab { grid-template-columns: minmax(0, 1fr); }
  .stage { box-shadow: 4px 4px 0 var(--ink); }
  .clock-lab { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .clock-lab svg { max-width: 220px; }
  .next ol, .next ol.two { grid-template-columns: minmax(0, 1fr); }
  .race-grid { grid-template-columns: minmax(0, 1fr); }
  .live { padding: 18px 16px 20px; box-shadow: 4px 4px 0 var(--pink); }
  .live-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stat-main { grid-column: 1 / -1; }
  .sum-grid { grid-template-columns: minmax(0, 1fr); }
  .race-result .res-row { flex-direction: column; gap: 4px; }
  .eq { font-size: 16px; }
  .chapter { padding-top: 52px; }
  .chapter-head { flex-direction: column; gap: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
