:root {
  --ink: #0e1730;
  --ink-muted: #56617a;
  --paper: #f6f5f0;
  --surface: #ffffff;
  --line: #dce2df;
  --coral: #ed6a5a;
  --coral-soft: #fff0ed;
  --teal: #0e9e94;
  --teal-soft: #e9faf6;
  --gold: #f3c667;
  --shadow: 0 18px 40px rgba(15, 23, 48, 0.1);
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(14, 23, 48, 0.028) 1px, transparent 1px) 0 0 / 26px 26px,
    linear-gradient(rgba(14, 23, 48, 0.028) 1px, transparent 1px) 0 0 / 26px 26px,
    var(--paper);
  font-family: "Microsoft YaHei UI", "Microsoft YaHei", sans-serif;
}

button { font: inherit; }

.app-shell { width: min(1440px, 100%); margin: 0 auto; padding: 30px 54px 26px; }

.masthead { display: flex; align-items: center; justify-content: space-between; padding-bottom: 29px; border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; align-items: center; gap: 12px; color: inherit; font-size: 21px; font-weight: 700; letter-spacing: 0.03em; text-decoration: none; }
.brand-orbit, .result-orbit { position: relative; display: inline-block; width: 31px; height: 27px; border: 2px solid var(--ink); border-radius: 50%; transform: rotate(-25deg); }
.brand-orbit::before, .result-orbit::before { position: absolute; top: 9px; left: -5px; width: 35px; height: 2px; background: var(--ink); content: ""; transform: rotate(51deg); }
.brand-orbit i, .brand-orbit b, .result-orbit i, .result-orbit b { position: absolute; display: block; width: 7px; height: 7px; border-radius: 50%; content: ""; }
.brand-orbit i, .result-orbit i { top: -4px; left: 4px; background: var(--coral); }
.brand-orbit b, .result-orbit b { right: 1px; bottom: -4px; background: var(--teal); }
.mode-label, .eyebrow, .move-total, .board-footer { font-family: "DM Mono", Consolas, monospace; }
.mode-label { display: flex; align-items: center; gap: 8px; color: var(--ink-muted); font-size: 11px; letter-spacing: 0.08em; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--teal); box-shadow: 0 0 0 4px rgba(14, 158, 148, 0.13); }
.header-actions { display: flex; align-items: center; gap: 16px; }
.restart-button { padding: 8px 12px; color: var(--ink); font-size: 12px; font-weight: 600; cursor: pointer; background: var(--surface); border: 1px solid var(--line); border-radius: 7px; transition: border-color 180ms ease, transform 180ms ease; }
.restart-button:hover { border-color: var(--ink-muted); transform: translateY(-1px); }
.restart-button:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }

.game-layout { display: grid; grid-template-columns: minmax(190px, 0.8fr) minmax(480px, 1.6fr) minmax(240px, 0.95fr); gap: clamp(35px, 5vw, 80px); align-items: center; padding: 66px 0 52px; }
.info-panel { min-width: 0; }
.eyebrow { margin: 0 0 10px; color: var(--ink-muted); font-size: 10px; font-weight: 500; letter-spacing: 0.15em; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 22px; font-family: "Microsoft YaHei UI", "Microsoft YaHei", sans-serif; font-size: clamp(34px, 3.4vw, 48px); font-weight: 300; line-height: 0.98; letter-spacing: -0.07em; }
h1 em { color: var(--coral); font-style: normal; }
.intro { max-width: 240px; color: var(--ink-muted); font-size: 14px; line-height: 1.8; }
.legend { display: grid; gap: 13px; margin-top: 38px; }
.legend-row { display: flex; align-items: center; gap: 11px; font-size: 13px; }
.legend-row strong, .legend-row small { display: block; }
.legend-row small { margin-top: 1px; color: var(--ink-muted); font-size: 11px; }
.mark-chip { display: grid; width: 32px; height: 32px; place-items: center; border-radius: 50%; font-family: "DM Mono", monospace; font-size: 15px; font-weight: 500; }
.x-chip { color: var(--coral); background: var(--coral-soft); border: 1px solid rgba(237, 106, 90, 0.35); }
.o-chip { color: var(--teal); background: var(--teal-soft); border: 1px solid rgba(14, 158, 148, 0.35); }
.replay-panel { max-width: 250px; margin-top: 30px; padding: 16px; background: rgba(255,255,255,0.62); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 22px rgba(15, 23, 48, 0.04); }
.replay-panel[hidden] { display: none; }
.replay-panel .eyebrow { margin-bottom: 5px; }
.replay-panel h2 { margin-bottom: 5px; font-size: 20px; }
.replay-panel > p:not(.eyebrow) { margin-bottom: 0; color: var(--ink-muted); font-size: 12px; }

.board-area { min-width: 0; }
.turn-panel { display: flex; align-items: center; justify-content: space-between; min-height: 88px; margin-bottom: 18px; padding: 16px 19px 16px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 9px 23px rgba(15, 23, 48, 0.05); }
.turn-copy { min-width: 0; }
.turn-label { display: block; margin-bottom: 2px; color: var(--ink-muted); font-family: "DM Mono", monospace; font-size: 10px; letter-spacing: 0.12em; }
.turn-copy strong { font-size: 20px; line-height: 1.15; }
.turn-copy p { margin: 4px 0 0; color: var(--ink-muted); font-size: 12px; }
.turn-token { display: grid; flex: 0 0 auto; width: 48px; height: 48px; place-items: center; border-radius: 15px; font-family: "DM Mono", monospace; font-size: 25px; font-weight: 500; }
.x-token { color: var(--coral); background: var(--coral-soft); }
.o-token { color: var(--teal); background: var(--teal-soft); }

.board-wrap { position: relative; min-width: 0; }
.board-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: repeat(3, minmax(0, 1fr)); overflow: hidden; aspect-ratio: 1; background: var(--ink); border: 8px solid var(--ink); border-radius: 18px; box-shadow: var(--shadow); gap: 4px; }
.connection-layer { position: absolute; z-index: 1; width: 100%; height: 100%; pointer-events: none; }
.entanglement-line { fill: none; stroke: #8f98aa; stroke-dasharray: 5 5; stroke-linecap: round; stroke-width: 2.5; opacity: .68; }
.entanglement-line.x { stroke: var(--coral); }
.entanglement-line.o { stroke: var(--teal); }
.entanglement-line.cycle { stroke: #d99a15; stroke-dasharray: none; stroke-width: 4; opacity: 1; animation: cycle-glow 1.2s ease-in-out infinite; }
.cell { position: relative; display: flex; flex-wrap: wrap; align-content: center; justify-content: center; min-width: 0; min-height: 0; padding: clamp(7px, 1.3vw, 13px); overflow: hidden; color: var(--ink); cursor: pointer; background: var(--surface); border: 0; transition: background 180ms ease, transform 180ms ease; gap: 5px; }
.cell:not(.classical):hover { background: #fbfbf9; }
.cell:focus-visible, .text-button:focus-visible, .primary-button:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.cell.selected { background: linear-gradient(135deg, #fff 0%, var(--coral-soft) 100%); box-shadow: inset 0 0 0 3px var(--coral); }
.cell.selected.o { background: linear-gradient(135deg, #fff 0%, var(--teal-soft) 100%); box-shadow: inset 0 0 0 3px var(--teal); }
.cell.selected::after { position: absolute; z-index: 2; right: 8px; bottom: 6px; color: var(--ink-muted); font-family: "DM Mono", monospace; font-size: 8px; letter-spacing: 0.05em; content: "SELECTED"; }
.cell.collapse-choice { cursor: pointer; background: #fff9e9; box-shadow: inset 0 0 0 4px var(--gold); animation: pulse-choice 1.3s ease-in-out infinite; }
.cell.collapse-choice::after { position: absolute; z-index: 2; right: 8px; bottom: 6px; color: #9e741b; font-family: "DM Mono", monospace; font-size: 8px; letter-spacing: 0.05em; content: "COLLAPSE"; }
.cell.nudge { animation: nudge 320ms ease; }
.quantum-mark { position: relative; z-index: 2; display: grid; width: clamp(31px, 4.1vw, 45px); height: clamp(31px, 4.1vw, 45px); place-items: center; border: 1.5px solid currentColor; border-radius: 50%; font-family: "DM Mono", monospace; font-size: clamp(10px, 1.1vw, 13px); font-weight: 500; line-height: 1; animation: materialize 280ms ease-out; }
.quantum-mark.x { color: var(--coral); background: var(--coral-soft); }
.quantum-mark.o { color: var(--teal); background: var(--teal-soft); }
.quantum-mark.collapsing { animation: quantum-collapse 260ms ease-in forwards; }
.classical { cursor: default; }
.classical.x { background: var(--coral-soft); }
.classical.o { background: var(--teal-soft); }
.classical-mark { position: relative; z-index: 2; font-family: "DM Mono", monospace; font-size: clamp(52px, 8.5vw, 100px); font-weight: 500; line-height: 1; animation: solidify 340ms cubic-bezier(.2,.85,.35,1); }
.classical.x .classical-mark { color: var(--coral); }
.classical.o .classical-mark { color: var(--teal); }
.cell.solidifying .classical-mark { animation: solidify 420ms cubic-bezier(.2,.85,.35,1); }
.collapse-card { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 10px; margin-top: 12px; padding: 13px; color: #603d00; background: #fff9e8; border: 1px solid rgba(226, 172, 57, 0.5); border-radius: 10px; }
.collapse-card[hidden] { display: none; }
.collapse-card strong, .collapse-card span { display: block; }
.collapse-card strong { font-size: 13px; }
.collapse-card span { margin-top: 3px; font-size: 11px; line-height: 1.5; }
.collapse-icon { align-self: start; color: #bd8209; font-size: 22px; }
.collapse-options { display: grid; grid-column: 1 / -1; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.collapse-option { padding: 10px 8px; color: #6e4a08; font-size: 12px; font-weight: 700; cursor: pointer; background: #fff; border: 1px solid #ddb85f; border-radius: 7px; transition: transform 160ms ease, background 160ms ease; }
.collapse-option:hover { background: #fff2c8; transform: translateY(-1px); }
.collapse-option:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.board-footer { display: flex; justify-content: space-between; margin-top: 13px; color: var(--ink-muted); font-size: 10px; letter-spacing: 0.06em; }
.text-button { padding: 0; color: var(--ink); font-size: 10px; letter-spacing: 0.04em; cursor: pointer; background: none; border: 0; text-decoration: underline; text-underline-offset: 3px; }
.text-button:disabled { color: #aeb5c3; cursor: default; text-decoration: none; }

.right-panel { align-self: stretch; display: flex; flex-direction: column; min-height: 480px; padding: 23px; background: rgba(255,255,255,0.52); border: 1px solid var(--line); border-radius: 14px; }
.history-heading { display: flex; align-items: center; justify-content: space-between; padding-bottom: 19px; border-bottom: 1px solid var(--line); }
.history-heading .eyebrow { margin-bottom: 4px; }
h2 { margin-bottom: 0; font-size: 20px; line-height: 1; }
.move-total { display: grid; width: 40px; height: 40px; place-items: center; color: var(--ink-muted); border: 1px solid var(--line); border-radius: 50%; font-size: 12px; }
.move-log { display: grid; flex: 1; min-height: 0; align-content: start; gap: 2px; max-height: 340px; margin: 14px 0; padding: 0; overflow-y: auto; list-style: none; }
.log-item { display: grid; grid-template-columns: 28px 21px 1fr; align-items: center; gap: 8px; min-height: 40px; padding: 7px 4px; color: var(--ink-muted); border-bottom: 1px solid rgba(220, 226, 223, 0.65); font-size: 11px; }
.log-number { font-family: "DM Mono", monospace; font-size: 10px; }
.log-player { display: grid; width: 20px; height: 20px; place-items: center; border-radius: 50%; font-family: "DM Mono", monospace; font-size: 10px; }
.log-item.x .log-player { color: var(--coral); background: var(--coral-soft); }
.log-item.o .log-player { color: var(--teal); background: var(--teal-soft); }
.log-item.resolved { color: var(--ink); }
.empty-log { padding: 12px 3px; color: #929aab; font-size: 11px; line-height: 1.5; }
.rule-note { display: flex; align-items: flex-start; gap: 8px; padding-top: 15px; border-top: 1px solid var(--line); }
.rule-note p { margin-bottom: 0; color: var(--ink-muted); font-size: 10px; line-height: 1.6; }
.rule-note strong { color: var(--ink); }
.rule-symbol { display: grid; flex: 0 0 auto; width: 19px; height: 19px; place-items: center; color: #927027; background: #fff4d3; border-radius: 50%; font-family: "DM Mono", monospace; font-size: 11px; }

.how-to { display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--line); }
.how-to div { display: flex; align-items: center; gap: 12px; min-height: 74px; padding: 16px 20px; border-right: 1px solid var(--line); }
.how-to div:first-child { padding-left: 0; }
.how-to div:last-child { border-right: 0; }
.how-to span { color: var(--coral); font-family: "DM Mono", monospace; font-size: 11px; }
.how-to p { margin-bottom: 0; color: var(--ink-muted); font-size: 12px; line-height: 1.55; }

.result-dialog { width: min(390px, calc(100% - 32px)); padding: 38px; color: var(--ink); text-align: center; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 30px 100px rgba(8, 17, 40, 0.26); }
.result-dialog::backdrop { background: rgba(14, 23, 48, 0.57); backdrop-filter: blur(4px); }
.result-orbit { width: 48px; height: 41px; margin-bottom: 23px; transform: rotate(-25deg) scale(1.15); }
.result-orbit::before { top: 17px; width: 54px; }
.result-orbit i { top: -4px; left: 4px; }
.result-orbit b { right: 1px; bottom: -4px; }
.result-dialog .eyebrow { margin: 0 0 10px; }
.result-dialog h2 { margin-bottom: 12px; font-family: "Microsoft YaHei UI", "Microsoft YaHei", sans-serif; font-size: 38px; font-weight: 300; letter-spacing: -0.06em; }
.result-dialog > p:not(.eyebrow) { margin-bottom: 25px; color: var(--ink-muted); font-size: 13px; line-height: 1.7; }
.primary-button { width: 100%; padding: 13px 18px; color: white; cursor: pointer; background: var(--ink); border: 0; border-radius: 9px; font-weight: 600; transition: transform 180ms ease, background 180ms ease; }
.primary-button:hover { background: #1e2b4e; transform: translateY(-2px); }
.primary-button span { margin-left: 8px; font-size: 17px; }
.secondary-button { width: 100%; margin-top: 10px; padding: 11px 14px; color: var(--ink); cursor: pointer; background: var(--surface); border: 1px solid var(--line); border-radius: 9px; font-weight: 600; }
.secondary-button:hover { background: #f4f6f7; }
.secondary-button:disabled { color: #aeb5c3; cursor: default; background: #f8f8f6; }
.replay-controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 14px 0 13px; }
.replay-controls .secondary-button, .replay-controls .primary-button { width: auto; min-height: 39px; margin: 0; padding: 7px 6px; font-size: 11px; }
#replay-back { grid-column: 1; grid-row: 1; }
#replay-next { grid-column: 2; grid-row: 1; }
#replay-play { grid-column: 1 / -1; grid-row: 2; }
.match-dialog { width: min(390px, calc(100% - 32px)); padding: 32px; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 30px 100px rgba(8, 17, 40, 0.26); }
.match-dialog::backdrop { background: rgba(14, 23, 48, 0.4); backdrop-filter: blur(3px); }
.match-dialog h2 { margin-bottom: 23px; font-size: 28px; }
.setting-field { display: grid; gap: 7px; margin: 14px 0; color: var(--ink-muted); font-size: 12px; font-weight: 600; }
.setting-field select { width: 100%; padding: 11px 12px; color: var(--ink); font: inherit; background: #fbfbf9; border: 1px solid var(--line); border-radius: 8px; }
.setting-note { margin: 20px 0 15px; color: var(--ink-muted); font-size: 11px; line-height: 1.6; }
.match-dialog .text-button { display: block; margin: 14px auto 0; }

@keyframes materialize { from { opacity: 0; transform: scale(.35); } to { opacity: 1; transform: scale(1); } }
@keyframes solidify { 0% { opacity: 0; transform: scale(.5) rotate(-15deg); } 68% { transform: scale(1.08) rotate(2deg); } 100% { opacity: 1; transform: scale(1) rotate(0); } }
@keyframes pulse-choice { 50% { box-shadow: inset 0 0 0 4px var(--gold), 0 0 0 8px rgba(243,198,103,.18); } }
@keyframes nudge { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
@keyframes cycle-glow { 50% { filter: drop-shadow(0 0 4px rgba(217, 154, 21, .8)); } }
@keyframes quantum-collapse { 45% { opacity: .35; transform: scale(1.3); filter: blur(1px); } 100% { opacity: 0; transform: scale(.18); filter: blur(4px); } }

@media (max-width: 920px) {
  .app-shell { padding: 25px 28px; }
  .game-layout { grid-template-columns: minmax(180px, .7fr) minmax(430px, 1.35fr); gap: 36px; }
  .right-panel { grid-column: 1 / -1; min-height: auto; }
  .move-log { grid-template-columns: repeat(2, 1fr); max-height: 155px; }
}

@media (max-width: 650px) {
  .app-shell { padding: 20px 16px; }
  .masthead { padding-bottom: 20px; }
  .brand { font-size: 18px; }
  .mode-label { font-size: 9px; }
  .header-actions { gap: 10px; }
  .restart-button { padding: 7px 9px; font-size: 11px; }
  .game-layout { display: flex; flex-direction: column; gap: 27px; padding: 35px 0; }
  .left-panel { align-self: stretch; }
  h1 { font-size: 39px; }
  .intro { max-width: 100%; }
  .legend { grid-template-columns: repeat(2, 1fr); margin-top: 22px; }
  .replay-panel { max-width: 360px; margin-top: 24px; }
  .board-area { width: min(100%, 500px); }
  .right-panel { width: 100%; min-height: 360px; }
  .move-log { grid-template-columns: 1fr; max-height: 160px; }
  .how-to { grid-template-columns: 1fr; }
  .how-to div, .how-to div:first-child { min-height: 52px; padding: 13px 0; border-right: 0; border-bottom: 1px solid var(--line); }
  .how-to div:last-child { border-bottom: 0; }
}

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