@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700;800&family=Space+Grotesk:wght@500;600;700&display=swap');

:root {
  color-scheme: dark;
  --bg: #090e1c;
  --surface: #111a2d;
  --surface-2: #17233a;
  --surface-3: #1c2a43;
  --text: #edf3ff;
  --muted: #8493ad;
  --line: rgba(157, 179, 215, .13);
  --accent: #8d7cff;
  --accent-2: #58d7df;
  --x: #62d8e3;
  --o: #a995ff;
  --success: #7be0b0;
  --danger: #ff8d9c;
  --shadow: 0 24px 70px rgba(0, 0, 0, .25);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f2f5fc;
  --surface: #ffffff;
  --surface-2: #f5f7ff;
  --surface-3: #e9edfa;
  --text: #17213a;
  --muted: #69758d;
  --line: rgba(45, 61, 95, .14);
  --accent: #6855e8;
  --accent-2: #168f9a;
  --x: #087e91;
  --o: #7057d9;
  --success: #16875a;
  --danger: #d34c64;
  --shadow: 0 20px 55px rgba(35, 49, 84, .10);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 15% 5%, rgba(141,124,255,.14), transparent 28rem),
    radial-gradient(circle at 90% 25%, rgba(88,215,223,.10), transparent 25rem),
    var(--bg);
  color: var(--text);
  font-family: "DM Sans", sans-serif;
  transition: background .25s, color .25s;
}

button, input, select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app {
  width: min(100% - 32px, 760px);
  margin: 0 auto;
  padding: 22px 0 34px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand {
  color: var(--text);
  text-decoration: none;
  font: 800 15px "Space Grotesk", sans-serif;
  letter-spacing: .12em;
}

.brand span {
  color: var(--accent-2);
}

.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 13px;
  color: var(--text);
  background: var(--surface);
  font-size: 18px;
}

.game-container {
  width: min(100%, 590px);
  margin: 26px auto 0;
}

.intro {
  text-align: center;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--accent-2);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .18em;
}

h1, h2, p {
  margin-top: 0;
}

h1 {
  margin-bottom: 7px;
  font: 700 clamp(29px, 6vw, 42px) "Space Grotesk", sans-serif;
  letter-spacing: -.04em;
}

.subtitle {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 14px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
}

.setup {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 13px;
  padding: 17px;
  margin-bottom: 15px;
}

.setting {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
}

.setting label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.setting input,
.setting select {
  width: 100%;
  min-width: 0;
  padding: 10px 11px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
}

.setting input:focus,
.setting select:focus {
  border-color: var(--accent);
}

.hidden {
  display: none !important;
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 15px;
}

.score-card {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  column-gap: 8px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 15px;
}

.score-symbol {
  grid-row: span 2;
  font: 700 24px "Space Grotesk", sans-serif;
}

.x-card .score-symbol {
  color: var(--x);
}

.o-card .score-symbol {
  color: var(--o);
}

.draw-card .score-symbol {
  color: var(--muted);
}

.score-name {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score-card strong {
  font: 700 19px "Space Grotesk", sans-serif;
}

.game-panel {
  padding: 21px;
}

.game-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 17px;
}

.meta-label {
  color: var(--muted);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .15em;
}

.game-meta h2 {
  margin: 5px 0 0;
  font: 700 16px "Space Grotesk", sans-serif;
}

.timer-wrap {
  text-align: right;
}

.timer-wrap strong {
  display: block;
  margin-top: 4px;
  font: 700 19px "Space Grotesk", sans-serif;
  font-variant-numeric: tabular-nums;
}

.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 9px;
  width: min(100%, 390px);
  margin: 0 auto;
}

.cell {
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: var(--surface-2);
  color: var(--text);
  font: 700 clamp(42px, 11vw, 66px) "Space Grotesk", sans-serif;
  display: grid;
  place-items: center;
  transition: transform .15s, background .2s, border-color .2s;
}

.cell:not(:disabled):hover {
  transform: translateY(-2px);
  background: var(--surface-3);
  border-color: var(--accent);
}

.cell:disabled {
  cursor: default;
}

.cell.x {
  color: var(--x);
  text-shadow: 0 0 24px color-mix(in srgb, var(--x), transparent 65%);
}

.cell.o {
  color: var(--o);
  text-shadow: 0 0 24px color-mix(in srgb, var(--o), transparent 65%);
}

.cell.win {
  background: color-mix(in srgb, var(--success), transparent 83%);
  border-color: var(--success);
  animation: winPulse .65s ease-in-out infinite alternate;
}

.message {
  min-height: 22px;
  margin: 16px 0 13px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.buttons {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 9px;
}

.buttons button,
.text-button {
  border: 0;
  border-radius: 11px;
  padding: 10px 15px;
  font-size: 12px;
  font-weight: 800;
  transition: transform .15s, opacity .15s;
}

.buttons button:hover,
.text-button:hover {
  transform: translateY(-1px);
}

.primary-button {
  color: #fff;
  background: linear-gradient(120deg, var(--accent), #6c9bff);
}

.secondary-button {
  color: var(--text);
  background: var(--surface-3);
  border: 1px solid var(--line) !important;
}

button:disabled {
  opacity: .4;
  cursor: not-allowed;
  transform: none !important;
}

.history-panel {
  margin-top: 15px;
  padding: 18px;
}

.history-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.history-heading h2 {
  margin: 0;
  font: 700 18px "Space Grotesk", sans-serif;
}

.text-button {
  padding: 8px 10px;
  color: var(--muted);
  background: var(--surface-2);
}

.history-list {
  list-style: none;
  padding: 0;
  margin: 14px 0 0;
}

.history-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
  font-size: 12px;
}

.history-list li span:last-child {
  color: var(--muted);
  white-space: nowrap;
}

.empty-history {
  color: var(--muted);
}

footer {
  margin-top: 20px;
  color: var(--muted);
  text-align: center;
  font-size: 10px;
}

@keyframes winPulse {
  from { transform: scale(1); }
  to { transform: scale(1.035); }
}

@media (max-width: 480px) {
  .app {
    width: min(100% - 22px, 760px);
    padding-top: 14px;
  }

  .game-container {
    margin-top: 20px;
  }

  .setup {
    padding: 13px;
    gap: 11px;
  }

  .game-panel {
    padding: 15px;
  }

  .score-card {
    padding: 10px 8px;
    column-gap: 5px;
  }

  .score-symbol {
    font-size: 20px;
  }

  .score-name {
    font-size: 9px;
  }

  .score-card strong {
    font-size: 17px;
  }

  .cell {
    border-radius: 13px;
  }

  .buttons button {
    flex: 1 1 auto;
    padding: 11px 9px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
