@font-face {
  font-family: "Huaxin Serif";
  src: url("/assets/fonts/serif-subset.woff2") format("woff2");
  font-weight: 200 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #fbfaf7;
  --paper-2: #f4f1ea;
  --sheet: #fffdf8;
  --ink: #171614;
  --ink-2: #57534d;
  --ink-3: #7a756b;
  --line: #e7e3da;
  --line-2: #d7d2c6;
  --accent: #a6472e;
  --accent-soft: #f3e7e1;
  --danger: #b23a2f;
  --serif: "Huaxin Serif", "Noto Serif SC", "Songti SC", "SimSun", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  --mono: "SFMono-Regular", "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  min-height: 100svh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; }
[hidden] { display: none !important; }

/* paper-cut background */
.cutout {
  position: fixed;
  pointer-events: none;
  z-index: 0;
  opacity: .55;
  filter: drop-shadow(0 10px 18px rgba(23, 22, 20, .05));
}
.cutout.c1 {
  width: 280px; height: 210px; left: -74px; top: 110px;
  background: #eee8dd;
  clip-path: polygon(0 12%, 18% 4%, 34% 14%, 51% 3%, 70% 12%, 100% 5%, 94% 42%, 100% 72%, 82% 88%, 61% 80%, 44% 96%, 26% 84%, 7% 94%, 0 66%);
  transform: rotate(-8deg);
}
.cutout.c2 {
  width: 240px; height: 180px; right: -58px; bottom: 12%;
  background: var(--accent-soft);
  clip-path: polygon(0 18%, 22% 7%, 40% 17%, 61% 5%, 85% 14%, 100% 32%, 91% 58%, 100% 84%, 72% 93%, 51% 82%, 30% 96%, 8% 82%);
  transform: rotate(7deg);
}
.cutout.c3 {
  width: 130px; height: 120px; right: 11%; top: 8%;
  background: #e7e1d4;
  clip-path: polygon(0 22%, 26% 3%, 53% 15%, 80% 4%, 100% 25%, 88% 52%, 100% 78%, 70% 95%, 38% 85%, 12% 94%, 0 65%);
  transform: rotate(14deg);
}
.grid {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image: radial-gradient(rgba(23, 22, 20, .13) 1px, transparent 1px);
  background-size: 26px 26px;
  opacity: .28;
  mask-image: radial-gradient(ellipse at 50% 45%, rgba(0,0,0,.8), transparent 72%);
  -webkit-mask-image: radial-gradient(ellipse at 50% 45%, rgba(0,0,0,.8), transparent 72%);
  transition: opacity 1.2s ease;
}
body.glow .grid { opacity: .55; }
.ink {
  position: fixed;
  width: 580px; height: 580px;
  left: -170px; bottom: -260px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(23, 22, 20, .13), rgba(23, 22, 20, .04) 45%, transparent 70%);
  filter: blur(5px);
  pointer-events: none;
  z-index: 0;
  opacity: .9;
  transition: opacity 1.6s ease, transform 1.6s ease;
}
body.ink-gone .ink { opacity: .2; transform: translateY(30px) scale(.9); }
body.ink-gone .grid { opacity: .6; }

/* header */
.topbar {
  position: relative;
  z-index: 3;
  width: min(100% - 48px, 980px);
  margin: 0 auto;
  padding: 26px 0 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand { font-family: var(--serif); font-size: 22px; font-weight: 600; letter-spacing: .02em; }
.crumb { display: flex; align-items: center; gap: 9px; font-size: 11px; color: var(--ink-3); letter-spacing: .08em; }
.crumb i { width: 18px; height: 1px; background: var(--line-2); }
.topnav { display: flex; align-items: center; gap: 18px; }
.topnav a { font-size: 12px; color: var(--ink-2); transition: color .2s ease; }
.topnav a:hover { color: var(--ink); }

main {
  position: relative;
  z-index: 2;
  width: min(100% - 48px, 980px);
  margin: 0 auto;
  padding: 42px 0 70px;
}
.stage-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}
.kicker { font-family: var(--mono); font-size: 9.5px; letter-spacing: .2em; text-transform: uppercase; color: var(--ink-3); }
.stage-head h1 {
  margin-top: 8px;
  font-family: var(--serif);
  font-size: clamp(46px, 6vw, 72px);
  line-height: .95;
  font-weight: 500;
  letter-spacing: -.04em;
}
.stage-head .sub { margin-top: 10px; font-size: 12px; color: var(--ink-3); letter-spacing: .02em; }
.stage-meta { text-align: right; }
.stage-meta .label { font-family: var(--mono); font-size: 9.5px; letter-spacing: .12em; color: var(--ink-3); }
.dots { display: flex; gap: 6px; justify-content: flex-end; margin-top: 9px; }
.dots span { width: 22px; height: 3px; border-radius: 3px; background: var(--line-2); transition: background .3s ease; }
.dots span.on { background: var(--accent); }
.dots span.done { background: var(--ink); }

/* game panel */
.panel {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 16px;
  background:
    linear-gradient(135deg, rgba(255,255,255,.55), transparent 48%),
    var(--sheet);
  box-shadow: 0 1px 0 rgba(23,22,20,.03), 0 34px 70px -54px rgba(23,22,20,.5);
  overflow: hidden;
}
.panel::before {
  content: "";
  position: absolute; inset: 0;
  pointer-events: none;
  background-image: repeating-linear-gradient(to bottom, transparent 0, transparent 43px, rgba(23,22,20,.035) 43px, rgba(23,22,20,.035) 44px);
  opacity: .55;
}
.panel-inner { position: relative; padding: clamp(24px, 4vw, 42px); }
.stage-title { font-family: var(--serif); font-size: clamp(23px, 2.4vw, 31px); font-weight: 500; letter-spacing: -.02em; }
.stage-desc { max-width: 600px; margin-top: 10px; font-size: 12.5px; line-height: 1.9; color: var(--ink-3); }
.type-line {
  margin: 38px 0 14px;
  min-height: 84px;
  display: flex;
  flex-wrap: wrap;
  gap: 1px;
  font-family: var(--mono);
  font-size: clamp(42px, 5.4vw, 62px);
  line-height: 1.25;
  letter-spacing: .12em;
  color: var(--ink-3);
  user-select: none;
}
.type-line .ch {
  position: relative;
  color: #c9c0b3;
  transition: color .14s ease, background .14s ease, transform .14s ease;
}
.type-line .ch.current {
  color: var(--ink);
  background: var(--accent-soft);
  border-radius: 5px;
  transform: translateY(-2px);
}
.type-line .ch.current::after {
  content: "";
  position: absolute;
  left: 1px; right: 1px; bottom: -7px;
  height: 2px;
  background: var(--accent);
  border-radius: 2px;
  animation: caret 1.05s step-end infinite;
}
.type-line .ch.ok { color: var(--ink-2); }
.type-line .ch.bad { color: var(--danger); text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 5px; }
.type-line .ch.space { min-width: .55em; }
@keyframes caret { 0%, 55% { opacity: 1; } 56%, 100% { opacity: 0; } }
.stage-hint { min-height: 20px; font-size: 11.5px; color: var(--ink-3); letter-spacing: .02em; }
.stage-hint b { color: var(--ink-2); font-weight: 600; }

/* mini keyboard */
.mini-kb {
  max-width: 650px;
  margin: 18px auto 0;
  padding: 14px 16px 11px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 253, 248, .7);
  box-shadow: 0 12px 30px -26px rgba(23,22,20,.35);
  user-select: none;
}
.mini-kb-row { display: flex; justify-content: center; gap: 6px; margin-bottom: 6px; }
.mk {
  display: grid;
  place-items: center;
  width: 46px; height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-3);
  transition: background .14s ease, color .14s ease, border-color .14s ease, transform .14s ease;
}
.mk.next {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
  transform: translateY(1px);
}
.mk.done {
  background: var(--accent-soft);
  border-color: rgba(166, 71, 46, .35);
  color: var(--accent);
}
.mini-kb-hint { margin-top: 5px; text-align: center; font-size: 9.5px; letter-spacing: .12em; color: var(--ink-3); }
.stats b.pop { animation: combo-pop .24s ease; }
@keyframes combo-pop {
  0% { transform: scale(1); color: var(--accent); }
  45% { transform: scale(1.22); color: var(--accent); }
  100% { transform: none; }
}

/* auto speech bubble */
.speech {
  position: fixed;
  top: 92px;
  left: 50%;
  z-index: 25;
  width: min(500px, calc(100vw - 36px));
  padding: 14px 18px 15px;
  border: 1px solid var(--line);
  border-left: 2px solid var(--accent);
  border-radius: 10px;
  background: rgba(255, 253, 248, .98);
  box-shadow: 0 24px 50px -30px rgba(23,22,20,.55);
  transform: translate(-50%, 8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
}
.speech.show { opacity: 1; transform: translate(-50%, 0); }
.speech.leaving { opacity: 0; transform: translate(-50%, -26px); }
.speech-who {
  font-family: var(--mono);
  font-size: 8.5px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--accent);
}
.speech-text {
  margin-top: 6px;
  font-size: 13.5px;
  line-height: 1.75;
  color: var(--ink-2);
}
.speech.note { border-left-color: var(--line-2); }
.speech.note .speech-who { display: none; }
.speech.note .speech-text { color: var(--ink-3); font-style: italic; }

/* paper scraps */
.confetti-layer { position: absolute; inset: 0; z-index: 8; pointer-events: none; overflow: hidden; }
.confetti {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: 6px;
  height: 9px;
  background: var(--c);
  opacity: .85;
  transform: translate(-50%, -50%) rotate(var(--r));
  animation: confetti-fly 1.15s cubic-bezier(.18,.7,.3,1) forwards;
}
@keyframes confetti-fly {
  0% { opacity: 0; transform: translate(-50%, -50%) rotate(var(--r)) scale(.7); }
  12% { opacity: .9; }
  100% { opacity: 0; transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) rotate(calc(var(--r) + 220deg)) scale(1); }
}

.stats {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 26px;
  margin-top: 30px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: .1em;
  color: var(--ink-3);
}
.stats b { margin-left: 7px; font-family: var(--serif); font-size: 19px; font-weight: 500; letter-spacing: 0; color: var(--ink); }
.stats .right { margin-left: auto; color: var(--ink-3); }

/* stage 3 */
.challenge { text-align: center; padding: 16px 0 8px; }
.challenge .round { font-family: var(--mono); font-size: 9.5px; letter-spacing: .16em; color: var(--ink-3); }
.challenge .prompt { margin-top: 18px; font-family: var(--serif); font-size: clamp(26px, 3.2vw, 38px); font-weight: 500; }
.challenge .sub { margin-top: 9px; font-size: 12px; color: var(--ink-3); }
.keycaps { display: flex; align-items: center; justify-content: center; gap: 18px; margin: 32px 0 26px; }
.keycap {
  display: grid; place-items: center;
  width: 76px; height: 76px;
  border: 1px solid var(--line-2);
  border-radius: 13px;
  background: var(--paper);
  font-family: var(--mono);
  font-size: 27px;
  color: var(--ink-2);
  box-shadow: 0 4px 0 rgba(23,22,20,.05);
  transition: background .18s ease, color .18s ease, border-color .18s ease, transform .18s ease, box-shadow .18s ease;
}
.keycap.on {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
  transform: translateY(2px);
  box-shadow: 0 1px 0 rgba(23,22,20,.12);
}
.keycap.hot { border-color: var(--accent); color: var(--accent); }
.keycap.hot.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.key-divider { width: 38px; height: 1px; background: var(--line-2); }
.timer { max-width: 360px; height: 3px; margin: 0 auto; background: var(--line); border-radius: 3px; overflow: hidden; }
.timer span { display: block; height: 100%; width: 100%; background: var(--accent); transform-origin: left; transition: transform .06s linear; }
.challenge-note { margin-top: 18px; min-height: 18px; font-size: 11.5px; color: var(--ink-3); }
.challenge-note.bad { color: var(--danger); }
.challenge-note.good { color: var(--accent); }

/* whisper */
.whisper {
  position: fixed;
  right: 26px;
  bottom: 26px;
  z-index: 20;
  width: min(320px, calc(100vw - 36px));
  padding: 14px 16px 13px;
  border: 1px solid var(--line);
  border-left: 2px solid var(--accent);
  border-radius: 10px;
  background: rgba(255, 253, 248, .97);
  box-shadow: 0 18px 40px -24px rgba(23,22,20,.5);
  transform: translateY(10px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
  cursor: pointer;
}
.whisper.show { opacity: 1; transform: none; pointer-events: auto; }
.whisper .who { font-family: var(--mono); font-size: 8.5px; letter-spacing: .16em; text-transform: uppercase; color: var(--accent); }
.whisper p { margin-top: 6px; font-size: 12.5px; line-height: 1.7; color: var(--ink-2); }
.whisper .close { position: absolute; top: 8px; right: 10px; font-size: 12px; color: var(--ink-3); }

/* overlays */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(23, 22, 20, .26);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}
.overlay.show { opacity: 1; pointer-events: auto; }
.overlay-card {
  width: min(100%, 520px);
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--sheet);
  box-shadow: 0 40px 80px -40px rgba(23,22,20,.6);
  padding: 30px;
  transform: translateY(8px);
  transition: transform .2s ease;
}
.overlay.show .overlay-card { transform: none; }
.dlg-kicker { font-family: var(--mono); font-size: 9px; letter-spacing: .18em; text-transform: uppercase; color: var(--accent); }
.dlg-who { margin-top: 12px; font-family: var(--serif); font-size: 22px; font-weight: 500; }
.dlg-text { margin-top: 12px; min-height: 74px; font-size: 15px; line-height: 1.9; color: var(--ink-2); }
.dlg-note { margin-top: 10px; font-size: 11.5px; color: var(--ink-3); font-style: italic; }
.dlg-actions { margin-top: 22px; display: flex; justify-content: flex-end; gap: 10px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 40px; padding: 0 18px;
  border-radius: 999px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  font-size: 12.5px;
  cursor: pointer;
  transition: transform .15s ease, opacity .15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn.ghost { border-color: var(--line-2); background: transparent; color: var(--ink-2); }
.btn.ghost:hover { border-color: var(--ink); color: var(--ink); }
.btn.disabled { border-color: var(--line-2); background: var(--paper-2); color: var(--ink-3); cursor: not-allowed; }
.btn.disabled:hover { transform: none; }

/* result */
.result-card { width: min(100%, 560px); }
.result-kicker { font-family: var(--mono); font-size: 9px; letter-spacing: .2em; text-transform: uppercase; color: var(--ink-3); }
.result-card h2 { margin-top: 12px; font-family: var(--serif); font-size: 34px; font-weight: 500; line-height: 1.2; letter-spacing: -.03em; }
.result-text { margin-top: 10px; font-size: 13px; line-height: 1.85; color: var(--ink-3); }
.result-stats { display: flex; gap: 28px; margin-top: 22px; padding: 14px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.result-stats div span { display: block; font-family: var(--mono); font-size: 8.5px; letter-spacing: .1em; color: var(--ink-3); }
.result-stats div b { display: block; margin-top: 4px; font-family: var(--serif); font-size: 21px; font-weight: 500; }
.item {
  display: grid;
  grid-template-columns: 82px 1fr;
  gap: 16px;
  align-items: center;
  margin-top: 22px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
}
.item-visual {
  position: relative;
  width: 82px; height: 82px;
  border: 1px solid var(--line-2);
  border-radius: 2px;
  background-color: var(--sheet);
  background-image: linear-gradient(rgba(23,22,20,.075) 1px, transparent 1px), linear-gradient(90deg, rgba(23,22,20,.075) 1px, transparent 1px);
  background-size: 10px 10px;
  clip-path: polygon(0 0, 100% 0, 100% 72%, 76% 100%, 0 100%);
}
.item-visual::after {
  content: "";
  position: absolute;
  left: 18px; top: 26px;
  width: 32px; height: 32px;
  border: 1px solid rgba(166, 71, 46, .45);
  border-radius: 50%;
  transform: rotate(-12deg);
  opacity: .7;
}
.item-visual.draft, .item-visual.gomoku { display: grid; place-items: center; }
.item-visual.draft::after, .item-visual.gomoku::after { display: none; }
.item-visual.draft svg, .item-visual.gomoku svg { width: 58px; height: 58px; overflow: visible; }
.dc-paper { fill: #fffdf8; stroke: var(--ink); stroke-width: 2; stroke-linejoin: round; }
.dc-grid { fill: none; stroke: rgba(23,22,20,.18); stroke-width: 1; }
.dc-fold { fill: none; stroke: rgba(23,22,20,.5); stroke-width: 1.4; }
.gp-grid { fill: none; stroke: rgba(23,22,20,.22); stroke-width: 1; }
.gp-black { fill: var(--ink); }
.gp-white { fill: #fffdf8; stroke: var(--ink); stroke-width: 2; }
.gp-shine { fill: rgba(255,255,255,.4); }
.item-tag { font-family: var(--mono); font-size: 8.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--accent); }
.item-name { margin-top: 5px; font-family: var(--serif); font-size: 20px; font-weight: 500; }
.item-desc { margin-top: 5px; font-size: 11.5px; line-height: 1.7; color: var(--ink-3); }
.result-actions { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 24px; }

.exit-btn {
  position: fixed;
  right: 24px;
  top: 78px;
  z-index: 5;
  padding: 7px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(251,250,247,.8);
  color: var(--ink-3);
  font-size: 11px;
  cursor: pointer;
  transition: border-color .2s ease, color .2s ease;
}
.exit-btn:hover { border-color: var(--ink-2); color: var(--ink); }

.footnote {
  margin-top: 22px;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  font-size: 10.5px;
  color: var(--ink-3);
}

@media (max-width: 760px) {
  .topbar, main { width: min(100% - 32px, 980px); }
  .stage-head { align-items: flex-start; flex-direction: column; gap: 16px; }
  .stage-meta { text-align: left; }
  .dots { justify-content: flex-start; }
  .type-line { font-size: 42px; margin-top: 28px; }
  .keycap { width: 62px; height: 62px; font-size: 23px; }
  .stats { gap: 16px; }
  .stats .right { width: 100%; margin-left: 0; }
  .whisper { right: 16px; bottom: 16px; left: 16px; width: auto; }
  .speech { top: 72px; }
  .mini-kb { padding: 10px 8px 8px; overflow-x: auto; }
  .mini-kb-row { gap: 4px; }
  .mk { width: 31px; height: 28px; font-size: 9.5px; border-radius: 5px; }
  .exit-btn { top: 70px; right: 16px; }
  .topnav a:first-child { display: none; }
  .footnote { flex-direction: column; gap: 6px; }
  .result-stats { gap: 18px; }
}

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