:root {
  --paper: #F3EFE5;
  --surface: #FBF8F0;
  --panel: #F7F3E9;
  --ink: #201D18;
  --muted: #746E62;
  --line: #D8D1C2;
  --line-soft: #E6DFD1;
  --grid: rgba(32, 29, 24, 0.055);
  --grid-strong: rgba(32, 29, 24, 0.08);
  --a: #B4462E;
  --a-soft: #F4E2DC;
  --b: #2E5C7A;
  --b-soft: #E2EBF1;
  --ok: #2F6B4F;
  --ok-soft: #E4EFE7;
  --bad: #A93B2A;
  --bad-soft: #F5E1DD;
  --radius: 10px;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid-strong) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-strong) 1px, transparent 1px),
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 160px 160px, 160px 160px, 32px 32px, 32px 32px;
  color: var(--ink);
  font-family: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

::selection { background: var(--a-soft); }

button, input { font-family: inherit; }

.fx-canvas {
  position: fixed;
  inset: 0;
  z-index: 4;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.flash {
  position: fixed;
  inset: 0;
  z-index: 5;
  background: #FFFFFF;
  opacity: 0;
  pointer-events: none;
}

.shake-wrap {
  position: relative;
  z-index: 3;
  will-change: transform;
}

.screen {
  min-height: 100dvh;
  padding: clamp(24px, 4vh, 48px) clamp(24px, 4vw, 64px);
  display: flex;
  flex-direction: column;
  animation: screenIn 0.3s ease both;
}

.start-screen,
.end-screen {
  justify-content: center;
}

.start-screen { position: relative; }

.start-footnote {
  position: absolute;
  bottom: clamp(20px, 3vh, 32px);
  left: clamp(24px, 4vw, 64px);
  margin: 0;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}

/* ---------- 开始页 ---------- */

.start-layout {
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: clamp(40px, 6vw, 96px);
  align-items: center;
}

.eyebrow {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 13px;
}

.eyebrow::before {
  content: "";
  width: 8px;
  height: 8px;
  background: var(--a);
}

.intro h1 {
  display: inline-block;
  margin: 0;
  padding-bottom: 12px;
  border-bottom: 3px solid var(--a);
  font-size: clamp(52px, 6.2vw, 86px);
  font-weight: 600;
  line-height: 1.02;
  letter-spacing: -0.035em;
}

.lede {
  max-width: 34ch;
  margin: 24px 0 32px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.7;
}

.stage-list {
  max-width: 440px;
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--line);
}

.stage-list li {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.stage-num,
.stage-meta {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}

.stage-name { font-weight: 500; }

.start-note {
  margin: 24px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.setup-panel {
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.setup-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  font-weight: 600;
}

.setup-meta {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 400;
}

.channel-setup {
  display: block;
  margin: 24px 0;
  padding-left: 12px;
  border-left: 3px solid var(--a);
}

.channel-setup.b { border-left-color: var(--b); }

.channel-setup.a .channel-label { color: var(--a); }
.channel-setup.b .channel-label { color: var(--b); }

.channel-label {
  display: block;
  margin-bottom: 8px;
  font-family: var(--mono);
  font-size: 11px;
}

.channel-setup input {
  width: 100%;
  padding: 4px 0 8px;
  border: none;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.01em;
  outline: none;
  transition: border-color 0.15s;
}

.channel-setup.a input:focus { border-bottom-color: var(--a); }
.channel-setup.b input:focus { border-bottom-color: var(--b); }

.setup-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: var(--muted);
  font-size: 11px;
}

.setup-divider::before,
.setup-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}

.btn {
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.15s, transform 0.08s;
}

.btn.primary {
  background: var(--ink);
  color: var(--paper);
}

.btn.primary:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }

.setup-panel .btn.primary {
  width: 100%;
  height: 56px;
  margin-top: 24px;
  font-size: 17px;
}

.setup-note {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

/* ---------- 游戏页 ---------- */

.game-screen {
  width: 100%;
  max-width: 1500px;
  margin: 0 auto;
  padding-top: clamp(16px, 2.6vh, 28px);
  padding-bottom: clamp(16px, 2.6vh, 28px);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}

.brand::before {
  content: "";
  width: 8px;
  height: 8px;
  background: var(--a);
}

.stage-now {
  display: flex;
  align-items: baseline;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.stage-now #stageLabel { font-family: var(--mono); font-size: 11px; }
.stage-now #stageTitle { color: var(--ink); font-size: 13px; font-weight: 500; }

.round-now {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  white-space: nowrap;
}

.progress { display: flex; gap: 4px; }

.progress .dot {
  width: 10px;
  height: 3px;
  background: var(--line);
  transition: background-color 0.2s;
}

.progress .dot.done { background: var(--ink); }
.progress .dot.current { background: var(--a); }

.controls { display: flex; gap: 8px; }

.icon-btn {
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}

.timer-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 0 clamp(12px, 2vh, 20px);
}

.timer-label {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}

.timer-track {
  flex: 1;
  height: 4px;
  background: var(--line-soft);
  overflow: hidden;
}

.timer-fill {
  width: 100%;
  height: 100%;
  background: var(--a);
  transform-origin: left center;
  transition: transform 0.1s linear, background-color 0.2s;
}

.timer-fill.warn { background: #C08A2E; }
.timer-fill.danger { background: var(--bad); }

.timer-num {
  min-width: 24px;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.timer-num.danger { color: var(--bad); }

.board {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.players {
  position: relative;
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(16px, 2vw, 24px);
  min-height: 0;
}

.divider {
  position: absolute;
  top: 12px;
  bottom: 12px;
  left: 50%;
  width: 1px;
  background: var(--line);
  pointer-events: none;
}

.divider span {
  position: absolute;
  top: 50%;
  left: 50%;
  padding: 3px 7px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--paper);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 9px;
  transform: translate(-50%, -50%);
}

.divider.hit { background: var(--a); transition: background-color 0.2s; }

.player-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}

.player-panel::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--a);
}

.player-panel.b::before { background: var(--b); }

.channel-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line-soft);
}

.channel-id {
  color: var(--a);
  font-family: var(--mono);
  font-size: 11px;
}

.player-panel.b .channel-id { color: var(--b); }

.player-name {
  max-width: 42%;
  overflow: hidden;
  font-size: 14px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score {
  margin-left: auto;
  color: var(--a);
  font-family: var(--mono);
  font-size: 24px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.player-panel.b .score { color: var(--b); }

.question-block {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: clamp(108px, 14vh, 148px);
  padding: 16px;
  border-bottom: 1px solid var(--line-soft);
  background: var(--panel);
}

.type-tag {
  margin: 0 0 8px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}

.panel-question {
  margin: 0;
  font-size: clamp(18px, 1.45vw, 24px);
  font-weight: 600;
  line-height: 1.45;
  letter-spacing: 0;
  text-wrap: balance;
}

.options {
  flex: 1;
  display: grid;
  grid-auto-rows: minmax(0, 1fr);
  gap: 12px;
  min-height: 0;
  padding: 16px;
}

.option-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  height: 100%;
  min-height: 52px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: clamp(16px, 1.2vw, 20px);
  font-weight: 500;
  line-height: 1.35;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.12s, border-color 0.12s, transform 0.08s;
  -webkit-tap-highlight-color: transparent;
}

.option-letter {
  display: grid;
  flex: none;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  transition: background-color 0.12s, border-color 0.12s, color 0.12s;
}

.option-text { flex: 1; }

@media (hover: hover) and (pointer: fine) {
  .option-btn:hover {
    background: #F7F2E7;
    border-color: #CFC7B6;
  }

  .icon-btn:hover {
    background: var(--surface);
    border-color: var(--muted);
    color: var(--ink);
  }

  .btn.primary:hover { background: #000000; }
}

.option-btn:active { transform: translateY(1px); }

.option-btn.selected {
  background: var(--a-soft);
  border-color: var(--a);
}

.player-panel.b .option-btn.selected {
  background: var(--b-soft);
  border-color: var(--b);
}

.option-btn.selected .option-letter {
  background: var(--a);
  border-color: var(--a);
  color: var(--paper);
}

.player-panel.b .option-btn.selected .option-letter {
  background: var(--b);
  border-color: var(--b);
}

.player-panel.locked .option-btn { pointer-events: none; }

.option-btn.correct {
  background: var(--ok-soft);
  border-color: var(--ok);
}

.option-btn.correct .option-letter {
  background: var(--ok);
  border-color: var(--ok);
  color: var(--paper);
}

.option-btn.wrong {
  background: var(--bad-soft);
  border-color: var(--bad);
}

.option-btn.wrong .option-letter {
  background: var(--bad);
  border-color: var(--bad);
  color: var(--paper);
}

.option-btn.dim { opacity: 0.42; }

.options.judge {
  grid-auto-rows: minmax(64px, 128px);
  align-content: center;
}

.options.judge .option-btn {
  justify-content: center;
  gap: 16px;
  font-size: clamp(22px, 1.8vw, 30px);
  font-weight: 600;
  text-align: center;
}

.options.judge .option-text { flex: 0 0 auto; }

.options.judge .option-letter {
  width: 40px;
  height: 40px;
  font-size: 13px;
}

.feedback {
  min-height: 56px;
  padding: 8px 16px 12px;
  border-top: 1px solid var(--line-soft);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.feedback-answer {
  display: block;
  margin-bottom: 3px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
}

.feedback.ok .feedback-answer { color: var(--ok); }
.feedback.bad .feedback-answer { color: var(--bad); }

.feedback-explain { display: block; }

.stamp {
  position: absolute;
  top: 8px;
  right: 84px;
  z-index: 2;
  padding: 4px 8px;
  border: 2px solid var(--ok);
  border-radius: 4px;
  background: var(--surface);
  color: var(--ok);
  font-size: 12px;
  font-weight: 600;
  pointer-events: none;
  transform: rotate(-6deg);
  animation: stampIn 0.32s ease-out both;
}

.stamp.bad {
  border-color: var(--bad);
  color: var(--bad);
}

.foot {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 40px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.foot-hint {
  flex: 1;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.auto-track {
  flex: 0 0 160px;
  height: 3px;
  background: var(--line-soft);
  overflow: hidden;
}

.auto-fill {
  width: 100%;
  height: 100%;
  background: var(--ink);
  transform-origin: left center;
}

/* ---------- 结束页 ---------- */

.end-screen { align-items: center; }

.result-card {
  width: min(560px, 92vw);
  padding: clamp(28px, 5vh, 44px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.result-card .eyebrow { margin-bottom: 14px; }

.result-card h2 {
  margin: 0 0 24px;
  font-size: clamp(28px, 3.2vw, 40px);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.score-list {
  border-top: 1px solid var(--line);
  margin-bottom: 24px;
}

.score-row {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}

.score-row .dot {
  width: 7px;
  height: 7px;
  background: var(--a);
}

.score-row.b .dot { background: var(--b); }

.score-row .name {
  font-size: 14px;
  font-weight: 500;
}

.score-row .combo {
  margin-left: 8px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}

.score-row .val {
  color: var(--a);
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.score-row.b .val { color: var(--b); }

.result-note {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 12px;
}

.result-card .btn.primary {
  width: 100%;
  height: 50px;
  font-size: 15px;
}

/* ---------- 段落过场 ---------- */

.stage-intro {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid-strong) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-strong) 1px, transparent 1px),
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 160px 160px, 160px 160px, 32px 32px, 32px 32px;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.stage-intro.show { opacity: 1; }
.stage-intro.out { opacity: 0; }

.stage-inner {
  text-align: center;
  animation: stageIn 0.35s ease both;
}

.stage-kicker {
  margin: 0 0 16px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
}

.stage-title {
  margin: 0;
  font-size: clamp(44px, 6vw, 84px);
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: -0.03em;
}

.stage-sub {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.sweep {
  width: min(420px, 62vw);
  height: 2px;
  margin: 28px auto 0;
  background: var(--line);
  overflow: hidden;
}

.sweep i {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--a);
  transform-origin: left center;
  animation: sweep 1s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

/* ---------- 动画 ---------- */

@keyframes screenIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

@keyframes stampIn {
  from { opacity: 0; transform: rotate(-6deg) scale(1.45); }
  to { opacity: 1; transform: rotate(-6deg) scale(1); }
}

@keyframes stageIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@keyframes sweep {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

/* ---------- 响应式 ---------- */

@media (max-width: 960px) {
  .start-layout {
    grid-template-columns: 1fr;
    gap: 36px;
  }

  .intro h1 { font-size: clamp(44px, 10vw, 64px); }
  .setup-panel { padding: 22px; }

  .topbar {
    flex-wrap: wrap;
    gap: 10px 16px;
  }

  .round-now { margin-left: 0; order: 3; width: 100%; }
  .controls { margin-left: auto; }
  .progress { display: none; }
  .divider { display: none; }

  .players { grid-template-columns: 1fr; }

  .question-block { min-height: 92px; }
  .option-btn { min-height: 52px; font-size: 15px; }
  .options.judge .option-btn { font-size: 20px; }
  .score { font-size: 20px; }
  .feedback { min-height: 52px; }
  .foot { flex-wrap: wrap; }
  .auto-track { flex-basis: 100%; }
  .stamp { right: 66px; font-size: 11px; }
  .start-footnote {
    position: static;
    margin-top: 28px;
    text-align: center;
  }
}

@media (max-height: 760px) and (min-width: 961px) {
  .question-block { min-height: 100px; padding: 11px 14px; }
  .panel-question { font-size: clamp(17px, 1.3vw, 21px); }
  .options { gap: 7px; padding: 10px 14px; }
  .option-btn { min-height: 46px; }
  .channel-head { padding: 9px 14px; }
  .feedback { min-height: 50px; padding-top: 7px; }
  .timer-row { margin-bottom: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
