
:root {
  color-scheme: dark;
  --ink: #f8f3ff;
  --muted: #d3caef;
  --muted-2: #a99fcf;
  --panel: rgba(12, 10, 26, .94);
  --panel-2: rgba(18, 14, 38, .96);
  --board: rgba(10, 10, 22, .72);
  --purple: #8b5cf6;
  --pink: #ff58b3;
  --orange: #ff9c43;
  --gold: #ffd166;
  --aqua: #22dfd2;
  --blue: #53a7ff;
  --green: #4df09a;
  --shadow: 0 28px 80px rgba(3, 5, 18, .52);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: #0b0915; }
body {
  min-height: 100vh;
  margin: 0;
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 10%, rgba(255, 88, 179, .18), transparent 24%),
    radial-gradient(circle at 86% 12%, rgba(34, 223, 210, .15), transparent 26%),
    radial-gradient(circle at 50% 110%, rgba(255, 209, 102, .16), transparent 32%),
    radial-gradient(circle at 25% 75%, rgba(139, 92, 246, .13), transparent 28%),
    linear-gradient(160deg, #05040b 0%, #0a0714 24%, #100b22 58%, #171031 100%);
  overflow-x: hidden;
}

body::before,
body::after {
  content: "";
  position: fixed;
  border-radius: 50%;
  filter: blur(16px);
  opacity: .55;
  z-index: -1;
  animation: floaty 8s ease-in-out infinite alternate;
}
body::before {
  width: 280px;
  height: 280px;
  background: linear-gradient(135deg, rgba(139, 92, 246, .75), rgba(255, 88, 179, .65));
  left: -90px;
  top: 38%;
}
body::after {
  width: 250px;
  height: 250px;
  background: linear-gradient(135deg, rgba(34, 223, 210, .70), rgba(83, 167, 255, .55));
  right: -100px;
  top: 58%;
  animation-delay: -2.2s;
}

@keyframes floaty {
  from { transform: translateY(-14px) rotate(-5deg); }
  to { transform: translateY(18px) rotate(6deg); }
}

button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-shell {
  width: min(780px, calc(100% - 28px));
  margin: 0 auto;
  padding: max(30px, env(safe-area-inset-top)) 0 max(28px, env(safe-area-inset-bottom));
}

.hero {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: .76rem;
  font-weight: 900;
  letter-spacing: .18em;
  color: var(--aqua);
  text-shadow: 0 0 12px rgba(34, 223, 210, .22);
}

h1 {
  margin: 0;
  font-size: clamp(2.7rem, 9vw, 5.3rem);
  line-height: 1.02;
  letter-spacing: -.068em;
  text-shadow: 0 0 28px rgba(139, 92, 246, .16);
}

h1 span {
  color: var(--pink);
  text-shadow: 3px 4px 0 rgba(255, 209, 102, .36), 0 0 20px rgba(255, 88, 179, .24);
}

.subtitle {
  max-width: 560px;
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.56;
}

.install-button, .primary-button, .secondary-button {
  border: 0;
  border-radius: 999px;
  font-weight: 850;
  cursor: pointer;
  transition: transform .16s ease, box-shadow .16s ease, opacity .16s ease, filter .16s ease;
}
.install-button:hover, .primary-button:hover, .secondary-button:hover { transform: translateY(-2px); filter: brightness(1.04); }
.install-button:active, .primary-button:active, .secondary-button:active { transform: translateY(0); }

.install-button {
  white-space: nowrap;
  padding: 12px 18px;
  color: white;
  background: linear-gradient(135deg, var(--purple), var(--pink));
  box-shadow: 0 10px 24px rgba(139, 92, 246, .35);
}

.game-card {
  position: relative;
  overflow: hidden;
  padding: clamp(16px, 3vw, 28px);
  background: linear-gradient(180deg, rgba(15, 11, 33, .97), rgba(7, 7, 18, .97));
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 34px;
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,.04);
  backdrop-filter: blur(18px);
}
.game-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at top left, rgba(139, 92, 246, .10), transparent 28%),
    radial-gradient(circle at bottom right, rgba(34, 223, 210, .08), transparent 26%);
  pointer-events: none;
}

.score-row {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.score-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border-radius: 18px;
  font-weight: 800;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.08);
  backdrop-filter: blur(10px);
}
.score-pill span { color: var(--muted); }
.score-pill strong { font-size: 1.35rem; }
.player-score {
  background: linear-gradient(135deg, rgba(139, 92, 246, .20), rgba(255, 88, 179, .12));
  box-shadow: inset 0 0 0 1px rgba(139, 92, 246, .22);
}
.draws-score {
  background: linear-gradient(135deg, rgba(255, 156, 67, .14), rgba(255, 209, 102, .10));
  box-shadow: inset 0 0 0 1px rgba(255, 159, 67, .18);
}
.computer-score {
  background: linear-gradient(135deg, rgba(34, 223, 210, .16), rgba(83, 167, 255, .12));
  box-shadow: inset 0 0 0 1px rgba(83, 167, 255, .20);
}
.player-score strong { color: #e1b9ff; }
.draws-score strong { color: var(--gold); }
.computer-score strong { color: #8addff; }

.status-wrap {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: 19px 2px 14px;
}
.status {
  margin: 0;
  min-height: 1.4em;
  font-weight: 850;
  font-size: 1.05rem;
}
.controls { display: flex; gap: 12px; color: var(--muted); font-size: .9rem; }
.toggle {
  display: flex;
  align-items: center;
  gap: 5px;
  user-select: none;
  cursor: pointer;
  padding: 8px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.06);
}
.toggle input { accent-color: var(--aqua); width: 18px; height: 18px; }

.board {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(10px, 2vw, 16px);
  width: min(100%, 540px);
  margin: 0 auto;
  padding: 10px;
  border-radius: 32px;
  background: linear-gradient(180deg, rgba(255,255,255,.045), rgba(255,255,255,.02));
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.06), 0 16px 34px rgba(2, 4, 14, .24);
}

.cell {
  --tile-accent: rgba(255,255,255,.10);
  position: relative;
  isolation: isolate;
  aspect-ratio: 1;
  border: 0;
  border-radius: clamp(20px, 4vw, 30px);
  background: linear-gradient(145deg, rgba(58, 44, 105, .92), rgba(19, 18, 39, .98));
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.06), 0 12px 26px rgba(4, 4, 20, .32);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: clamp(2.9rem, 14vw, 5.9rem);
  line-height: 1;
  transition: transform .14s ease, box-shadow .14s ease, background .14s ease, filter .14s ease;
}
.cell::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(180deg, rgba(255,255,255,.12), transparent 35%, transparent 70%, rgba(0,0,0,.10));
  z-index: -1;
}
.cell::after {
  content: "";
  position: absolute;
  width: 34%;
  height: 34%;
  top: 10%;
  right: 10%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,.18), rgba(255,255,255,0) 70%);
  pointer-events: none;
}

.cell:nth-child(1) { background: linear-gradient(145deg, #7138df, #35106f); }
.cell:nth-child(2) { background: linear-gradient(145deg, #e7439f, #77184f); }
.cell:nth-child(3) { background: linear-gradient(145deg, #18b9ac, #07566c); }
.cell:nth-child(4) { background: linear-gradient(145deg, #e57d2c, #7c3514); }
.cell:nth-child(5) { background: linear-gradient(145deg, #397ee8, #17347f); }
.cell:nth-child(6) { background: linear-gradient(145deg, #a147d9, #521375); }
.cell:nth-child(7) { background: linear-gradient(145deg, #dca832, #76500d); }
.cell:nth-child(8) { background: linear-gradient(145deg, #2ecf81, #10643e); }
.cell:nth-child(9) { background: linear-gradient(145deg, #e9536d, #7e1b38); }

.cell:not(:disabled):hover {
  transform: translateY(-3px) rotate(-1deg) scale(1.012);
  box-shadow: inset 0 0 0 3px rgba(255,255,255,.18), 0 18px 28px rgba(4, 4, 20, .40);
  filter: saturate(1.08) brightness(1.08);
}
.cell:disabled { cursor: default; }
.cell.x {
  color: #fff8ff;
  background: linear-gradient(145deg, #7c46e8, #b12885);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.18), 0 0 0 2px rgba(239, 195, 255, .12), 0 16px 30px rgba(171, 97, 244, .34);
}
.cell.o {
  color: #f3ffff;
  background: linear-gradient(145deg, #14a99f, #2e6dcc);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.18), 0 0 0 2px rgba(173, 238, 255, .12), 0 16px 30px rgba(65, 189, 236, .34);
}
.cell.pop { animation: pop .28s cubic-bezier(.2,1.4,.4,1); }
.cell.win {
  animation: winnerPulse .7s ease-in-out infinite alternate;
  box-shadow: inset 0 0 0 4px rgba(255,209,102,.58), 0 0 0 6px rgba(255,209,102,.18), 0 0 28px rgba(255,209,102,.24);
}

@keyframes pop {
  0% { transform: scale(.72) rotate(-8deg); opacity: .2; }
  72% { transform: scale(1.08) rotate(3deg); }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
@keyframes winnerPulse {
  from { transform: scale(1); }
  to { transform: scale(1.045) rotate(1deg); }
}

.action-row {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 20px;
}
.primary-button, .secondary-button { padding: 12px 18px; }
.primary-button {
  color: white;
  background: linear-gradient(135deg, var(--purple), #b66bff);
  box-shadow: 0 9px 18px rgba(139, 92, 246, .28);
}
.secondary-button {
  color: var(--ink);
  background: linear-gradient(135deg, rgba(255,255,255,.14), rgba(255,255,255,.08));
  border: 1px solid rgba(255,255,255,.08);
}

.tiny-note {
  text-align: center;
  color: var(--muted-2);
  font-size: .82rem;
  margin: 15px 0 0;
}

.confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 20;
}

@media (max-width: 620px) {
  .app-shell { width: min(100% - 18px, 560px); padding-top: max(18px, env(safe-area-inset-top)); }
  .hero { align-items: flex-start; }
  .hero .subtitle { font-size: .94rem; }
  .install-button { padding: 10px 13px; font-size: .85rem; }
  .game-card { border-radius: 27px; }
  .score-pill { flex-direction: column; padding: 9px 7px; gap: 1px; }
  .score-pill span { font-size: .78rem; }
  .status-wrap { align-items: flex-start; flex-direction: column; }
  .controls { width: 100%; justify-content: flex-end; }
}

@media (display-mode: standalone) {
  .tiny-note, .install-button { display: none !important; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}

/* Playful animated logo treatment */
h1 {
  display: inline-block;
  font-family: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", "Nunito", system-ui, sans-serif;
  font-weight: 950;
  font-variation-settings: "wght" 950;
  letter-spacing: -.055em;
  padding: .04em .04em .15em;
  background: linear-gradient(
    90deg,
    #ff63c3 0%,
    #ffb24d 16%,
    #ffe66d 32%,
    #57f0b1 48%,
    #46d9ff 64%,
    #9b7cff 80%,
    #ff63c3 100%
  );
  background-size: 250% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 4px 0 rgba(27, 13, 55, .75)) drop-shadow(0 0 18px rgba(154, 124, 255, .28));
  animation: title-gradient 6s linear infinite, title-bob 3.8s ease-in-out infinite;
}

h1 span {
  color: inherit;
  -webkit-text-fill-color: transparent;
  text-shadow: none;
}

@keyframes title-gradient {
  0% { background-position: 0% 50%; }
  100% { background-position: 250% 50%; }
}

@keyframes title-bob {
  0%, 100% { transform: translateY(0) rotate(-.4deg) scale(1); }
  50% { transform: translateY(-3px) rotate(.4deg) scale(1.015); }
}

@media (prefers-reduced-motion: reduce) {
  h1 { animation: none; background-position: 50% 50%; }
}
