:root {
  --bg: #153936;
  --bg-deep: #102d2b;
  --paper: #f8f5e9;
  --paper-soft: #ebe8dc;
  --ink: #152421;
  --muted: #9eb3ac;
  --line: rgba(248, 245, 233, 0.18);
  --line-strong: rgba(248, 245, 233, 0.34);
  --gold: #f1c84b;
  --x: #e85b40;
  --o: #247aa0;
  --draw: #809189;
  --focus: #f8d770;
  --radius: 26px;
  --board-radius: 18px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html {

  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--paper);
  font-family: "Microsoft YaHei UI", "Microsoft YaHei", "PingFang SC", "Noto Sans SC", sans-serif;
  background-color: var(--bg);
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.024) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.024) 1px, transparent 1px);
  background-size: 34px 34px;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
}

button:focus-visible,
a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 4px;
}

.app {
  width: min(1180px, calc(100% - 48px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 26px 0 20px;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 32px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 18px;
}

.brand-mark {
  position: relative;
  flex: 0 0 auto;
  width: 68px;
  height: 68px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  justify-items: center;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 5px 5px 0 rgba(0, 0, 0, 0.22);
  transform: rotate(-5deg);
}

.brand-x,
.brand-o {
  position: relative;
  display: block;
}

.brand-x {
  width: 18px;
  height: 18px;
}

.brand-x::before,
.brand-x::after {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 4px;
  border-radius: 999px;
  background: var(--ink);
  content: "";
  transform: translate(-50%, -50%) rotate(45deg);
}

.brand-x::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

.brand-o {
  width: 18px;
  height: 18px;
  border: 4px solid var(--ink);
  border-radius: 50%;
}

.brand-copy h1 {
  margin: 0;
  font-size: clamp(2.4rem, 4vw, 3.5rem);
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0.08em;
}

.brand-copy p {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

.topbar-tools {
  display: flex;
  align-items: center;
  gap: 18px;
  padding-top: 8px;
}

.mode-switch {
  display: flex;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(7, 26, 24, 0.34);
}

.mode-button {
  min-height: 42px;
  padding: 0 18px;
  border: 0;
  border-radius: 999px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  transition: color 160ms ease, background-color 160ms ease, transform 160ms ease;
}

.mode-button:hover {
  color: var(--paper);
}

.mode-button.is-active {
  color: var(--ink);
  background: var(--gold);
  font-weight: 800;
}

.mode-button:active {
  transform: scale(0.97);
}

.round-counter {
  min-width: 91px;
  padding-left: 18px;
  border-left: 1px solid var(--line-strong);
  color: var(--muted);
  font-size: 0.9rem;
  white-space: nowrap;
}

.round-counter strong {
  display: inline-block;
  min-width: 1.2em;
  color: var(--paper);
  font-family: "Bahnschrift", "Arial Narrow", sans-serif;
  font-size: 1.55rem;
  font-weight: 700;
  text-align: center;
  vertical-align: -0.08em;
}

.game-grid {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(190px, 0.7fr) minmax(400px, 520px) minmax(190px, 0.7fr);
  grid-template-areas: "intro play score";
  align-items: center;
  gap: clamp(24px, 3vw, 44px);
  padding: 32px 0 28px;
}

.intro-rail {
  grid-area: intro;
  align-self: center;
  min-width: 0;
}

.turn-panel {
  padding-bottom: 24px;
}

.rail-label {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.turn-stack {
  display: flex;
  align-items: center;
  gap: 16px;
}

.turn-symbol {
  flex: 0 0 auto;
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  color: var(--paper);
  font-family: "Bahnschrift", "Arial Narrow", sans-serif;
  font-size: 2rem;
  font-weight: 800;
  transition: color 180ms ease, border-color 180ms ease, background-color 180ms ease;
}

.turn-symbol.turn-x {
  border-color: rgba(232, 91, 64, 0.72);
  color: var(--x);
  background: rgba(232, 91, 64, 0.08);
}

.turn-symbol.turn-o {
  border-color: rgba(79, 164, 202, 0.72);
  color: #7cc9e8;
  background: rgba(36, 122, 160, 0.12);
}

.turn-copy strong {
  display: block;
  font-size: 1.45rem;
  font-weight: 800;
}

.turn-copy p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.45;
}

.player-list {
  border-top: 1px solid var(--line-strong);
}

.player-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 13px;
  min-height: 72px;
  padding: 10px 8px 10px 14px;
  border-bottom: 1px solid var(--line);
  transition: background-color 180ms ease, padding-left 180ms ease;
}

.player-row.is-active {
  padding-left: 20px;
  background: rgba(241, 200, 75, 0.08);
}

.player-row.is-active::before {
  position: absolute;
  top: 15px;
  bottom: 15px;
  left: 0;
  width: 4px;
  border-radius: 999px;
  background: var(--gold);
  content: "";
}

.player-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  font-family: "Bahnschrift", "Arial Narrow", sans-serif;
  font-size: 1.4rem;
  font-weight: 800;
  line-height: 1;
}

.mark-x-mini {
  color: var(--x);
}

.mark-o-mini {
  color: #7cc9e8;
}

.player-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.player-name {
  overflow: hidden;
  font-size: 1rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-meta {
  color: var(--muted);
  font-size: 0.76rem;
}

.turn-pip {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: transparent;
  transition: background-color 180ms ease, transform 180ms ease;
}

.player-row.is-active .turn-pip {
  background: var(--gold);
  transform: scale(1.25);
}

.how-to {
  margin-top: 26px;
  padding-top: 22px;
  border-top: 1px solid var(--line-strong);
}

.how-to p:last-child {
  max-width: 26ch;
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.65;
}

.play-area {
  grid-area: play;
  width: 100%;
  max-width: 520px;
  justify-self: center;
}

.board-shell {
  position: relative;
  padding: 18px;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  color: var(--ink);
  background: var(--paper);
  box-shadow: 10px 10px 0 var(--gold);
  animation: board-arrive 620ms cubic-bezier(0.2, 0.75, 0.22, 1) both;
}

.board-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 1px 2px 14px;
  font-size: 0.84rem;
  font-weight: 700;
}

.move-count {
  color: #68746f;
  font-family: "Bahnschrift", "Arial Narrow", sans-serif;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.board-wrap {
  position: relative;
}

.board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
  aspect-ratio: 1 / 1;
  padding: 8px;
  border-radius: var(--board-radius);
  background: var(--ink);
}

.board[aria-busy="true"] {
  cursor: progress;
}

.tile {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 11px;
  color: var(--ink);
  background: #fffdf5;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 150ms ease, transform 150ms ease;
}

.tile:hover {
  background: #fff8de;
}

.tile:active {
  transform: scale(0.98);
}

.tile[aria-disabled="true"] {
  cursor: default;
}

.tile[aria-disabled="true"]:hover {
  background: #fffdf5;
}

.tile.is-win {
  background: #fff1bd;
}

.tile.is-win.tile-x {
  box-shadow: inset 0 0 0 3px var(--x);
}

.tile.is-win.tile-o {
  box-shadow: inset 0 0 0 3px var(--o);
}

.mark {
  position: relative;
  display: block;
  pointer-events: none;
  animation: mark-in 230ms cubic-bezier(0.2, 0.9, 0.25, 1.2) both;
}

.mark-x {
  width: 54%;
  height: 54%;
}

.mark-x::before,
.mark-x::after {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100%;
  height: 17%;
  min-height: 7px;
  border-radius: 999px;
  background: var(--x);
  content: "";
  transform: translate(-50%, -50%) rotate(45deg);
}

.mark-x::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

.mark-o {
  width: 47%;
  aspect-ratio: 1 / 1;
  border: clamp(7px, 0.62vw, 10px) solid var(--o);
  border-radius: 50%;
}

.tile.is-win .mark {
  animation: winner-mark 900ms cubic-bezier(0.2, 0.8, 0.2, 1) infinite alternate;
}

.preview-mark {
  opacity: 0.16;
  animation: none;
}

.preview-mark.mark-x::before,
.preview-mark.mark-x::after {
  background: var(--x);
}

.preview-mark.mark-o {
  border-color: var(--o);
}

.win-line {
  position: absolute;
  z-index: 3;
  height: 7px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-50%) rotate(var(--line-angle, 0deg)) scaleX(0);
  transform-origin: left center;
}

.win-line.is-visible {
  opacity: 1;
  animation: draw-line 460ms cubic-bezier(0.15, 0.7, 0.2, 1) 80ms forwards;
}

.win-line.line-x {
  background: var(--x);
  box-shadow: 0 2px 0 rgba(86, 24, 14, 0.18);
}

.win-line.line-o {
  background: var(--o);
  box-shadow: 0 2px 0 rgba(8, 45, 63, 0.18);
}

.board-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding-top: 15px;
}

.status {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 9px;
}

.status-dot {
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--draw);
}

.status-dot.is-x {
  background: var(--x);
}

.status-dot.is-o {
  background: var(--o);
}

.status-dot.is-win {
  background: var(--gold);
  box-shadow: 0 0 0 4px rgba(241, 200, 75, 0.22);
}

.status p {
  margin: 0;
  overflow: hidden;
  font-size: 0.9rem;
  font-weight: 700;
  line-height: 1.35;
  text-overflow: ellipsis;
}

.round-button {
  flex: 0 0 auto;
  min-height: 45px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 0 17px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  color: var(--paper);
  background: var(--ink);
  font-weight: 700;
  cursor: pointer;
  transition: color 160ms ease, background-color 160ms ease, transform 160ms ease;
}

.round-button:hover {
  color: var(--ink);
  background: var(--gold);
}

.round-button:active {
  transform: scale(0.97);
}

.round-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.keyboard-hint {
  margin: 17px 0 0;
  color: rgba(248, 245, 233, 0.55);
  font-size: 0.76rem;
  line-height: 1.5;
  text-align: center;
}

.score-rail {
  grid-area: score;
  align-self: center;
  min-width: 0;
}

.score-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 2px solid var(--gold);
}

.score-heading h2 {
  margin: 0;
  font-size: 1.45rem;
  font-weight: 900;
}

.score-heading span {
  color: var(--muted);
  font-size: 0.72rem;
}

.score-list {
  padding-top: 5px;
}

.score-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 70px;
  border-bottom: 1px solid var(--line);
}

.score-player {
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--paper-soft);
  font-size: 0.9rem;
  font-weight: 700;
}

.score-player i {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  font-family: "Bahnschrift", "Arial Narrow", sans-serif;
  font-size: 1rem;
  font-style: normal;
  font-weight: 800;
}

.score-player-x i {
  border-color: rgba(232, 91, 64, 0.55);
  color: var(--x);
}

.score-player-o i {
  border-color: rgba(79, 164, 202, 0.55);
  color: #7cc9e8;
}

.score-player-draw i {
  color: var(--muted);
  font-size: 0.9rem;
}

.score-row strong {
  color: var(--paper);
  font-family: "Bahnschrift", "Arial Narrow", sans-serif;
  font-size: 2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.clear-button {
  margin-top: 17px;
  padding: 8px 0;
  border: 0;
  border-bottom: 1px solid var(--line-strong);
  color: var(--muted);
  background: transparent;
  font-size: 0.82rem;
  cursor: pointer;
  transition: color 150ms ease, border-color 150ms ease;
}

.clear-button:hover:not(:disabled) {
  color: var(--paper);
  border-color: var(--paper);
}

.clear-button:disabled {
  opacity: 0.38;
  cursor: default;
}

.score-note {
  margin: 22px 0 0;
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.65;
}

.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  color: rgba(248, 245, 233, 0.52);
  font-size: 0.72rem;
}

@keyframes board-arrive {
  from {
    opacity: 0;
    transform: translateY(16px) rotate(-0.25deg);
  }
  to {
    opacity: 1;
    transform: translateY(0) rotate(0);
  }
}

@keyframes mark-in {
  from {
    opacity: 0;
    transform: scale(0.72);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes winner-mark {
  from {
    transform: scale(1);
  }
  to {
    transform: scale(1.08);
  }
}

@keyframes draw-line {
  from {
    transform: translateY(-50%) rotate(var(--line-angle, 0deg)) scaleX(0);
  }
  to {
    transform: translateY(-50%) rotate(var(--line-angle, 0deg)) scaleX(1);
  }
}

@media (hover: none) {
  .tile:hover {
    background: #fffdf5;
  }
}

@media (max-width: 1040px) {
  .app {
    width: min(100% - 32px, 760px);
  }

  .game-grid {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "play"
      "intro"
      "score";
    gap: 30px;
    padding-top: 28px;
  }

  .play-area {
    max-width: 540px;
  }

  .intro-rail {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 24px;
    width: 100%;
    max-width: 620px;
    justify-self: center;
  }

  .turn-panel {
    padding-bottom: 0;
  }

  .player-list {
    border-top: 0;
  }

  .how-to {
    grid-column: 1 / -1;
    margin-top: 0;
  }

  .how-to p:last-child {
    max-width: 48ch;
  }

  .score-rail {
    width: 100%;
    max-width: 620px;
    justify-self: center;
  }

  .score-note {
    max-width: 48ch;
  }
}

@media (max-width: 680px) {
  .app {
    width: calc(100% - 24px);
    padding-top: 18px;
  }

  .topbar {
    flex-direction: column;
    gap: 22px;
  }

  .brand {
    gap: 14px;
  }

  .brand-mark {
    width: 55px;
    height: 55px;
  }

  .brand-copy h1 {
    font-size: 2.45rem;
  }

  .brand-copy p {
    margin-top: 6px;
    font-size: 0.82rem;
  }

  .topbar-tools {
    width: 100%;
    justify-content: space-between;
    gap: 12px;
    padding-top: 0;
  }

  .mode-switch {
    flex: 1;
  }

  .mode-button {
    flex: 1;
    min-height: 39px;
    padding: 0 12px;
    font-size: 0.86rem;
  }

  .round-counter {
    min-width: 76px;
    padding-left: 12px;
  }

  .game-grid {
    gap: 28px;
    padding: 24px 0;
  }

  .board-shell {
    padding: 12px;
    border-radius: 20px;
    box-shadow: 7px 7px 0 var(--gold);
  }

  .board-heading {
    padding-bottom: 10px;
  }

  .board {
    gap: 6px;
    padding: 6px;
    border-radius: 14px;
  }

  .tile {
    border-radius: 9px;
  }

  .board-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .status {
    min-height: 32px;
    justify-content: center;
  }

  .status p {
    flex: 1;
  }

  .round-button {
    width: 100%;
  }

  .keyboard-hint {
    margin-top: 14px;
    font-size: 0.72rem;
  }

  .intro-rail {
    grid-template-columns: 1fr;
    gap: 22px;
  }

  .turn-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 20px;
    align-items: center;
  }

  .turn-panel .rail-label {
    grid-column: 1 / -1;
    margin-bottom: -8px;
  }

  .turn-stack {
    grid-column: 1 / -1;
  }

  .player-list {
    border-top: 1px solid var(--line-strong);
  }

  .how-to {
    grid-column: auto;
  }

  .score-heading h2 {
    font-size: 1.25rem;
  }

  .score-row {
    min-height: 61px;
  }

  .score-row strong {
    font-size: 1.75rem;
  }

  .footer {
    align-items: flex-start;
    flex-direction: column;
    gap: 7px;
    padding-bottom: 6px;
  }
}

@media (max-width: 340px) {
  .topbar-tools {
    flex-wrap: wrap;
  }

  .mode-switch {
    flex-basis: 100%;
  }

  .round-counter {
    min-width: auto;
    padding-left: 0;
    border-left: 0;
  }
}

@media (max-width: 390px) {
  .brand-copy h1 {
    font-size: 2.15rem;
  }

  .brand-copy p {
    max-width: 18ch;
  }

  .mode-button {
    padding: 0 8px;
    font-size: 0.8rem;
  }

  .round-counter {
    min-width: 65px;
    font-size: 0.78rem;
  }

  .turn-symbol {
    width: 50px;
    height: 50px;
    font-size: 1.7rem;
  }

  .turn-copy strong {
    font-size: 1.2rem;
  }
}

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