:root {
  color-scheme: dark;
  --bg: #050608;
  --panel: #11151c;
  --panel-strong: #18202b;
  --line: #415166;
  --line-bright: #8ea6c4;
  --text: #f7fbff;
  --muted: #b8c4d2;
  --x: #74f0d2;
  --o: #ffcf5a;
  --focus: #ffffff;
  --danger: #ff6b6b;
  --win: #83ff73;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 600px;
  height: 600px;
  margin: 0;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

button {
  font: inherit;
}

.app-shell {
  width: 600px;
  height: 600px;
  margin: 0 auto;
  display: grid;
  place-items: center;
  padding: 8px;
  background:
    radial-gradient(circle at 50% 0%, rgba(116, 240, 210, 0.16), transparent 34%),
    linear-gradient(180deg, #080a0d 0%, #050608 100%);
}

.game-surface {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-rows: auto auto auto 1fr auto;
  gap: 8px;
  padding: 14px;
  border: 2px solid var(--line);
  background: var(--panel);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06), 0 24px 70px rgba(0, 0, 0, 0.55);
}

.top-bar,
.controls,
.score-strip {
  display: flex;
  align-items: center;
}

.top-bar {
  justify-content: space-between;
  gap: 16px;
}

.eyebrow,
.status,
.selection-status {
  margin: 0;
  color: var(--muted);
}

.eyebrow {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

h1 {
  margin: 2px 0 0;
  font-size: 30px;
  line-height: 1;
  letter-spacing: 0;
}

.score-strip {
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--line);
  background: var(--panel-strong);
}

.score-strip span {
  min-width: 54px;
  color: var(--text);
  font-size: 18px;
  text-align: center;
}

.score-strip strong {
  color: var(--line-bright);
}

.status {
  min-height: 28px;
  padding: 5px 10px;
  border-left: 4px solid var(--x);
  background: #0b1016;
  font-size: 18px;
  font-weight: 700;
}

.selection-status {
  min-height: 22px;
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  text-align: center;
}

.board {
  width: min(100%, 336px);
  aspect-ratio: 1;
  align-self: center;
  justify-self: center;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 8px;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  border: 2px solid var(--line-bright);
  border-radius: 8px;
  background: #0a0f15;
  color: var(--text);
  font-size: 56px;
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

.cell:hover {
  background: #14202b;
}

.focusable:focus-visible {
  outline: 4px solid var(--focus);
  outline-offset: 4px;
}

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

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

.is-selected {
  border-color: var(--focus);
  box-shadow: 0 0 0 5px rgba(255, 255, 255, 0.2), inset 0 0 0 3px rgba(116, 240, 210, 0.45);
  transform: scale(0.96);
}

.ai-move-pulse {
  animation: aiPulse 900ms ease-out 1;
}

.is-win {
  border-color: var(--win);
  background: #102411;
  box-shadow: 0 0 0 3px rgba(131, 255, 115, 0.28), 0 0 22px rgba(131, 255, 115, 0.25);
}

.controls {
  justify-content: center;
  gap: 12px;
}

.action {
  min-width: 132px;
  min-height: 44px;
  border: 2px solid var(--line-bright);
  border-radius: 8px;
  background: var(--text);
  color: #050608;
  font-weight: 800;
  cursor: pointer;
}

.action.secondary {
  background: var(--panel-strong);
  color: var(--text);
}

@keyframes aiPulse {
  0% {
    transform: scale(0.92);
    box-shadow: 0 0 0 0 rgba(255, 207, 90, 0.7);
  }

  65% {
    transform: scale(1.03);
    box-shadow: 0 0 0 14px rgba(255, 207, 90, 0);
  }

  100% {
    transform: scale(1);
    box-shadow: none;
  }
}

@media (max-width: 420px), (max-height: 540px) {
  .app-shell {
    padding: 10px;
  }

  .game-surface {
    min-height: calc(100vh - 20px);
    padding: 12px;
    gap: 10px;
  }

  h1 {
    font-size: 28px;
  }

  .board {
    width: min(100%, 320px);
    gap: 8px;
  }

  .cell {
    font-size: 48px;
  }

  .controls {
    flex-wrap: wrap;
  }
}
