:root {
  --bg0: #0b3d3a;
  --bg1: #145c56;
  --bg2: #1f7a70;
  --sand: #f3e6c8;
  --cream: #fff8eb;
  --x: #ff6b4a;
  --o: #5ad1ff;
  --line: rgba(255, 248, 235, 0.28);
  --glow: rgba(255, 107, 74, 0.35);
  --radius: 1.25rem;
  --font-display: "Fredoka", "Heebo", system-ui, sans-serif;
  --font-body: "Heebo", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: var(--font-body);
  color: var(--cream);
  background: var(--bg0);
  overflow-x: hidden;
}

.bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(ellipse 80% 55% at 15% 10%, rgba(90, 209, 255, 0.18), transparent 55%),
    radial-gradient(ellipse 70% 50% at 90% 85%, rgba(255, 107, 74, 0.22), transparent 50%),
    linear-gradient(160deg, #083532 0%, #0f4f4a 42%, #163f4d 100%);
}

.bg::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.12;
  background-image:
    repeating-linear-gradient(
      -18deg,
      transparent 0 14px,
      rgba(255, 248, 235, 0.35) 14px 15px
    );
  pointer-events: none;
}

.stage {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  max-width: 28rem;
  margin: 0 auto;
  padding: clamp(1.25rem, 4vw, 2rem) 1.25rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.35rem;
  justify-content: center;
}

.brand {
  text-align: center;
  animation: rise 0.7s ease both;
}

.brand-kicker {
  margin: 0 0 0.35rem;
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--sand);
  opacity: 0.85;
}

.brand-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2.6rem, 11vw, 3.6rem);
  line-height: 0.95;
  letter-spacing: -0.02em;
  background: linear-gradient(120deg, #fff8eb 20%, #ffb199 55%, #5ad1ff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 40px var(--glow);
}

.brand-sub {
  margin: 0.55rem 0 0;
  font-size: 0.98rem;
  color: rgba(255, 248, 235, 0.78);
}

.board-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.9rem;
  animation: rise 0.85s 0.08s ease both;
}

.board {
  --gap: 0.65rem;
  width: min(88vw, 20.5rem);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: var(--gap);
  padding: var(--gap);
  border-radius: calc(var(--radius) + 0.35rem);
  background: #062e2b;
  border: 1px solid var(--line);
  box-shadow:
    0 18px 50px rgba(0, 0, 0, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.cell {
  position: relative;
  border: 2px solid rgba(255, 248, 235, 0.45);
  border-radius: var(--radius);
  background: #2a9b8f;
  color: inherit;
  font-family: var(--font-display);
  font-size: clamp(2.4rem, 12vw, 3.4rem);
  font-weight: 700;
  cursor: pointer;
  min-width: 0;
  min-height: 0;
  width: 100%;
  height: 100%;
  transition: transform 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.cell:not(:disabled):hover {
  background: #227a70;
  transform: translateY(-2px);
}

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

.cell:disabled {
  cursor: default;
}

.cell.x {
  color: var(--x);
  text-shadow: 0 0 18px rgba(255, 107, 74, 0.45);
  animation: pop 0.28s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

.cell.o {
  color: var(--o);
  text-shadow: 0 0 18px rgba(90, 209, 255, 0.45);
  animation: pop 0.28s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

.cell.win {
  background: rgba(255, 248, 235, 0.16);
  box-shadow: inset 0 0 0 2px rgba(255, 248, 235, 0.55);
  animation: winpulse 0.9s ease infinite alternate;
}

.cell.selected {
  box-shadow: inset 0 0 0 3px var(--cream), 0 0 18px rgba(255, 248, 235, 0.35);
  transform: translateY(-3px) scale(1.04);
}

.cell.movable:not(.selected) {
  box-shadow: inset 0 0 0 1px rgba(255, 248, 235, 0.35);
}

.cell.target {
  background: rgba(90, 209, 255, 0.22);
  box-shadow: inset 0 0 0 2px rgba(90, 209, 255, 0.7);
  animation: targetpulse 0.8s ease infinite alternate;
}

@keyframes targetpulse {
  from { filter: brightness(1); }
  to { filter: brightness(1.2); }
}

.status {
  margin: 0;
  min-height: 1.5em;
  text-align: center;
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--sand);
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  animation: rise 1s 0.14s ease both;
}

.mode {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.chip {
  border: 1px solid var(--line);
  background: rgba(8, 40, 38, 0.4);
  color: var(--cream);
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 500;
  padding: 0.7rem 0.6rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}

.chip.is-active {
  background: rgba(255, 248, 235, 0.16);
  border-color: rgba(255, 248, 235, 0.45);
}

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

.scores {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.score {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem;
  border-radius: 0.9rem;
  background: rgba(8, 40, 38, 0.35);
  border: 1px solid rgba(255, 248, 235, 0.12);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.score-mark {
  font-family: var(--font-display);
  font-size: 1.1rem;
}

.score-mark.x { color: var(--x); }
.score-mark.o { color: var(--o); }
.score-mark.draw { color: var(--sand); opacity: 0.8; }

.cta {
  border: 0;
  border-radius: 999px;
  padding: 0.95rem 1.2rem;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
  color: #123;
  cursor: pointer;
  background: linear-gradient(120deg, #fff8eb, #ffc9b5 55%, #9fe4ff);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.25);
  transition: transform 0.15s ease, filter 0.15s ease;
}

.cta:hover {
  filter: brightness(1.04);
}

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

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pop {
  from { transform: scale(0.4); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes winpulse {
  from { filter: brightness(1); }
  to { filter: brightness(1.18); }
}

@media (min-width: 720px) {
  .stage {
    max-width: 32rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .brand, .board-wrap, .controls, .cell.x, .cell.o, .cell.win {
    animation: none;
  }
}
