/* styles.css — clean, modern, mobile-first theme. */

:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #2563eb;
  --x: #2563eb;
  --o: #e11d48;
  --win: #16a34a;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --radius: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --surface: #1e293b;
    --text: #f1f5f9;
    --muted: #94a3b8;
    --border: #334155;
    --accent: #60a5fa;
    --x: #60a5fa;
    --o: #fb7185;
    --win: #4ade80;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

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

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  justify-content: center;
  padding:
    calc(env(safe-area-inset-top) + 1.25rem)
    calc(env(safe-area-inset-right) + 1rem)
    calc(env(safe-area-inset-bottom) + 1.25rem)
    calc(env(safe-area-inset-left) + 1rem);
}

.app {
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.app-header { text-align: center; }

.app-header h1 {
  margin: 0;
  font-size: clamp(1.5rem, 6vw, 2rem);
  letter-spacing: -0.02em;
}

.app-header h1 .twist {
  color: var(--accent);
  white-space: nowrap;
}

.tagline {
  margin: 0.4rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.4;
}

/* Controls -------------------------------------------------------------- */
.controls {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  align-items: center;
}

.mode-toggle {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
  box-shadow: var(--shadow);
}

.seg {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  padding: 0.55rem 1.1rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.seg.active {
  background: var(--accent);
  color: #fff;
}

.difficulty {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.difficulty[hidden] { display: none; }

.difficulty select {
  font: inherit;
  padding: 0.45rem 0.65rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

/* Scoreboard ------------------------------------------------------------ */
.scoreboard {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 0.75rem;
}

.score-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 0.6rem 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
}

.score-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}

.score-value {
  font-size: 1.8rem;
  font-weight: 800;
  line-height: 1;
}

.score-card.x .score-value { color: var(--x); }
.score-card.o .score-value { color: var(--o); }

/* The side whose turn it is gets a colored ring. */
.score-card.x.active {
  border-color: var(--x);
  box-shadow: 0 0 0 2px var(--x) inset, var(--shadow);
}

.score-card.o.active {
  border-color: var(--o);
  box-shadow: 0 0 0 2px var(--o) inset, var(--shadow);
}

/* The winner's card lifts and glows green at game end. */
.score-card.winner {
  border-color: var(--win);
  box-shadow: 0 0 0 2px var(--win) inset, var(--shadow);
  transform: translateY(-2px);
}

.score-moves-mini {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
}

.score-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

@media (prefers-reduced-motion: reduce) {
  .score-card { transition: none; }
}

/* Status ---------------------------------------------------------------- */
.status {
  margin: 0;
  text-align: center;
  font-size: 1.1rem;
  font-weight: 600;
  min-height: 1.5rem;
}

.status.won { color: var(--win); }

/* Board ----------------------------------------------------------------- */
.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 10px;
  width: min(90vw, 420px);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: clamp(2.5rem, 14vw, 4rem);
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.12s ease, opacity 0.25s ease, background 0.2s;
}

.cell:not(:disabled):hover { transform: translateY(-2px); }
.cell:not(:disabled):active { transform: scale(0.97); }
.cell:disabled { cursor: default; }

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

/* Newly placed / present marks pop in. */
.cell.x, .cell.o { animation: pop 0.2s ease; }

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

/* The piece about to vanish on this player's next move gently pulses. */
.cell.vanishing {
  animation: warn 1.1s ease-in-out infinite;
}

@keyframes warn {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.3; }
}

.cell.win {
  background: var(--win);
  color: #fff;
  border-color: var(--win);
}

/* Actions --------------------------------------------------------------- */
.actions {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.btn {
  font: inherit;
  font-weight: 600;
  padding: 0.7rem 1.4rem;
  border-radius: 12px;
  border: 1px solid transparent;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, opacity 0.2s;
}

.btn:active { transform: scale(0.97); }

.btn.ghost {
  background: transparent;
  color: var(--accent);
  border-color: var(--accent);
  box-shadow: none;
}

.btn[hidden] { display: none; }

/* Respect reduced-motion preferences. */
@media (prefers-reduced-motion: reduce) {
  .cell, .btn { transition: none; }
  .cell.x, .cell.o, .cell.vanishing { animation: none; }
  .cell.vanishing { opacity: 0.45; }
}
