:root {
  color-scheme: dark;
  --ink: #edf7f4;
  --ink-soft: #a9bfba;
  --paper: #112a2b;
  --card: #173536;
  --cell: #1d4041;
  --mint: #7bdcc2;
  --coral: #ff6b4a;
  --gold: #f3bd4f;
  --line: rgba(188, 221, 212, 0.14);
  --shadow: 0 28px 80px rgba(0, 10, 10, 0.4);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background: radial-gradient(circle at 12% 8%, rgba(255, 107, 74, 0.18), transparent 25rem), radial-gradient(circle at 90% 86%, rgba(123, 220, 194, 0.15), transparent 27rem), var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.35;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 140 140' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.07'/%3E%3C/svg%3E");
}

button { font: inherit; }
.game-shell { width: min(92%, 620px); margin: 0 auto; padding: 30px 0 24px; }
.brand { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 18px; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; }
.brand-name { font-size: 0.875rem; }
.brand-mark { display: grid; width: 30px; height: 30px; place-items: center; border-radius: 9px; color: var(--paper); background: var(--coral); font-weight: 900; transform: rotate(-5deg); }
.brand-mark--o { background: var(--mint); transform: rotate(5deg); }

.game-card { position: relative; overflow: hidden; padding: clamp(25px, 6vw, 44px); border: 1px solid var(--line); border-radius: 30px; background: rgba(23, 53, 54, 0.91); box-shadow: var(--shadow); backdrop-filter: blur(9px); }
.game-card::after { content: ""; position: absolute; top: -100px; right: -96px; width: 190px; height: 190px; border: 26px solid rgba(123, 220, 194, 0.07); border-radius: 50%; z-index: -1; }
.intro { text-align: center; }
.eyebrow { margin: 0 0 8px; color: var(--coral); font-size: 0.875rem; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; }
h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(2.4rem, 9vw, 4.3rem); line-height: 1; letter-spacing: -0.055em; }
.intro > p:last-child { margin: 12px 0 24px; color: var(--ink-soft); font-size: 1rem; }

.scoreboard { display: grid; grid-template-columns: 1fr 0.76fr 1fr; overflow: hidden; margin-bottom: 18px; border: 1px solid var(--line); border-radius: 16px; }
.score { display: flex; min-width: 0; padding: 12px 14px; align-items: center; justify-content: space-between; gap: 8px; background: rgba(12, 37, 38, 0.48); }
.score + .score { border-left: 1px solid var(--line); }
.score strong { font-family: Georgia, serif; font-size: 1.55rem; }
.player { overflow: hidden; color: var(--ink-soft); font-size: 0.875rem; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.player b { margin: 0 3px; color: var(--coral); font-size: 1rem; }
.score--o .player b { color: var(--mint); }
.score--draws { justify-content: center; text-align: center; }
.score--draws .player { display: none; }

.turn-panel { display: flex; margin: 0 auto 16px; align-items: center; justify-content: center; gap: 9px; color: var(--ink-soft); font-size: 0.9rem; font-weight: 700; }
.turn-icon { display: grid; width: 27px; height: 27px; place-items: center; border-radius: 8px; color: var(--paper); background: var(--coral); font-size: 0.82rem; font-weight: 900; transition: background 180ms ease, transform 180ms ease; }
.turn-icon.is-o { background: var(--mint); transform: rotate(8deg); }
.turn-icon.is-draw { background: var(--gold); }

.board { display: grid; aspect-ratio: 1; width: min(100%, 390px); margin: 0 auto; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.cell { display: grid; border: 0; border-radius: 18px; place-items: center; color: var(--coral); background: var(--cell); box-shadow: inset 0 0 0 1px var(--line); font-family: Georgia, serif; font-size: clamp(2.7rem, 12vw, 5.1rem); font-weight: 700; line-height: 1; cursor: pointer; transition: transform 160ms ease, background 160ms ease, box-shadow 160ms ease; }
.cell:not(:disabled):hover { transform: translateY(-3px); background: #254a4b; box-shadow: inset 0 0 0 2px rgba(255, 107, 74, 0.6), 0 10px 20px rgba(0, 0, 0, 0.18); }
.cell:focus-visible, .button:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.cell.o { color: var(--mint); }
.cell.filled { animation: place-mark 240ms cubic-bezier(0.2, 0.9, 0.3, 1.3); }
.cell.winner { color: var(--paper); background: var(--gold); box-shadow: none; animation: winner-pulse 650ms ease both; }
.cell:disabled { cursor: default; }

.actions { display: flex; margin-top: 23px; justify-content: center; gap: 11px; }
.button { min-height: 46px; padding: 0 20px; border: 0; border-radius: 999px; font-weight: 800; cursor: pointer; transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease; }
.button:hover { transform: translateY(-2px); }
.button--primary { color: var(--paper); background: var(--mint); box-shadow: 0 9px 20px rgba(0, 0, 0, 0.22); }
.button--primary:hover { background: #93e6cf; box-shadow: 0 11px 24px rgba(0, 0, 0, 0.3); }
.button--quiet { color: var(--ink-soft); background: transparent; }
.button--quiet:hover { color: var(--ink); background: rgba(123, 220, 194, 0.09); }
.footer-note { margin: 17px 0 0; color: var(--ink-soft); font-family: Georgia, serif; font-size: 0.9rem; font-style: italic; text-align: center; }

@keyframes place-mark {
  from { transform: scale(0.55) rotate(-8deg); opacity: 0; }
  to { transform: scale(1) rotate(0); opacity: 1; }
}

@keyframes winner-pulse {
  50% { transform: translateY(-4px) scale(1.02); }
}

@media (max-width: 520px) {
  .game-shell { width: min(94%, 440px); padding-top: 18px; }
  .game-card { padding: 24px 18px 26px; border-radius: 24px; }
  .score { padding: 10px 8px; }
  .score--x .player, .score--o .player { font-size: 0; }
  .score--x .player b, .score--o .player b { font-size: 1rem; }
  .score--draws .player { display: inline; }
  .score--draws { flex-direction: column; gap: 0; }
  .board { gap: 7px; }
  .cell { border-radius: 14px; }
}

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