:root {
  color-scheme: dark;
  --bg: #101315;
  --panel: #181d20;
  --panel-2: #20262a;
  --text: #f2f5f0;
  --muted: #aeb8b1;
  --line: #323b40;
  --x: #f3bf45;
  --o: #5ed0b6;
  --danger: #f26767;
  --shadow: 0 20px 70px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(94, 208, 182, 0.16), transparent 34rem),
    linear-gradient(160deg, #101315 0%, #171c1f 54%, #111416 100%);
  color: var(--text);
}

button {
  -webkit-tap-highlight-color: transparent;
  border: 0;
  color: inherit;
  font: inherit;
}

.app {
  display: grid;
  grid-template-areas:
    "topbar"
    "scoreboard"
    "board"
    "actions";
  gap: 18px;
  width: 100%;
  max-width: 520px;
  min-height: 100svh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px max(22px, env(safe-area-inset-bottom));
}

.topbar {
  grid-area: topbar;
}

.scoreboard {
  grid-area: scoreboard;
}

.board-panel {
  grid-area: board;
}

.session-actions {
  grid-area: actions;
}

.topbar,
.status-row,
.session-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2.15rem, 11vw, 4.2rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.icon-button,
.text-button,
.primary-button,
.cell {
  cursor: pointer;
  touch-action: manipulation;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  font-size: 1.35rem;
}

.scoreboard {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  min-width: 0;
}

.score {
  display: grid;
  min-width: 0;
  min-height: 92px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(24, 29, 32, 0.84);
}

.score.active {
  border-color: color-mix(in srgb, var(--active-color, var(--x)), white 8%);
  background: color-mix(in srgb, var(--active-color, var(--x)) 14%, var(--panel));
}

.score[data-score-card="X"] {
  --active-color: var(--x);
}

.score[data-score-card="O"] {
  --active-color: var(--o);
}

.score[data-score-card="draw"] {
  --active-color: var(--muted);
}

.mark {
  font-size: 1.1rem;
  font-weight: 900;
}

.label {
  align-self: end;
  min-width: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.score strong {
  font-size: 1.55rem;
  line-height: 1;
}

.board-panel {
  display: grid;
  gap: 16px;
  min-width: 0;
  align-self: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(24, 29, 32, 0.88);
  box-shadow: var(--shadow);
}

.status {
  min-width: 0;
  margin: 0;
  color: var(--text);
  font-size: 1.08rem;
  font-weight: 800;
}

.text-button {
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
  white-space: nowrap;
}

.board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  min-width: 0;
  aspect-ratio: 1;
}

.cell {
  display: grid;
  place-items: center;
  min-width: 0;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111619;
  font-size: clamp(3.2rem, 20vw, 6.8rem);
  font-weight: 950;
  line-height: 1;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.cell:active {
  transform: scale(0.96);
}

.cell.x {
  color: var(--x);
}

.cell.o {
  color: var(--o);
}

.cell.win {
  border-color: currentColor;
  background: color-mix(in srgb, currentColor 16%, #111619);
}

.cell:disabled {
  cursor: default;
}

.primary-button {
  width: 100%;
  min-height: 56px;
  border-radius: 8px;
  background: var(--text);
  color: #121619;
  font-weight: 900;
}

.primary-button:disabled {
  opacity: 0.42;
}

@media (min-width: 620px) {
  .app {
    justify-content: center;
    padding-block: 34px;
  }
}

@media (min-width: 900px) {
  body {
    background:
      radial-gradient(circle at 18% 24%, rgba(243, 191, 69, 0.1), transparent 24rem),
      radial-gradient(circle at 78% 18%, rgba(94, 208, 182, 0.13), transparent 28rem),
      linear-gradient(150deg, #101315 0%, #171c1f 52%, #101315 100%);
  }

  .app {
    grid-template-areas:
      "topbar board"
      "scoreboard board"
      "actions board";
    grid-template-columns: minmax(320px, 380px) minmax(430px, 520px);
    grid-template-rows: auto auto auto;
    align-content: center;
    align-items: start;
    justify-content: center;
    column-gap: clamp(42px, 6vw, 84px);
    row-gap: 26px;
    width: calc(100% - 72px);
    max-width: 1060px;
    padding-block: 48px;
  }

  .topbar {
    align-items: end;
  }

  .eyebrow {
    margin-bottom: 6px;
    font-size: 0.84rem;
  }

  h1 {
    font-size: clamp(4.8rem, 7vw, 7rem);
  }

  .icon-button {
    width: 56px;
    height: 56px;
    margin-bottom: 6px;
    font-size: 1.6rem;
  }

  .scoreboard {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .score {
    grid-template-columns: auto 1fr auto;
    align-items: center;
    min-height: 96px;
    padding: 18px 20px;
  }

  .mark {
    width: 46px;
    font-size: 2rem;
  }

  .label {
    align-self: center;
    font-size: 0.98rem;
  }

  .score strong {
    font-size: 2.5rem;
  }

  .board-panel {
    align-self: center;
    gap: 20px;
    width: 100%;
    padding: 22px;
  }

  .status {
    font-size: 1.45rem;
  }

  .text-button {
    min-height: 46px;
    padding-inline: 18px;
    font-size: 0.98rem;
  }

  .board {
    gap: 12px;
  }

  .cell {
    font-size: clamp(4.4rem, 7vw, 7.2rem);
  }

  .session-actions {
    width: 100%;
  }

  .primary-button {
    min-height: 64px;
    font-size: 1.08rem;
  }
}
