/* Tic-Tac-Toe — mobile-first
 * Touch-Targets >= 56x56px (Apple HIG 44pt + extra margin),
 * safe-area-inset für Notch-Phones, System-Font-Stack,
 * automatischer Dark-Mode über prefers-color-scheme. */

:root {
  --bg: #f8fafc;
  --fg: #0f172a;
  --muted: #475569;
  --accent-x: #2563eb;
  --accent-o: #dc2626;
  --border: #cbd5e1;
  --cell-bg: #ffffff;
  --cell-bg-pressed: #e2e8f0;
  --win-bg: #fef9c3;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.08);
  --radius: 12px;
  --tap: 56px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --fg: #f1f5f9;
    --muted: #94a3b8;
    --accent-x: #60a5fa;
    --accent-o: #f87171;
    --border: #334155;
    --cell-bg: #1e293b;
    --cell-bg-pressed: #334155;
    --win-bg: #422006;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
  }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family:
    -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue',
    Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  overscroll-behavior: contain;
}

body {
  /* Respektiere iOS Notch + Android Statusbar. */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.app {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  max-width: 480px;
  margin: 0 auto;
  padding: 1rem 1rem 2rem;
  min-height: 100dvh;
}

/* ----- Header ----- */

.header {
  text-align: center;
  width: 100%;
}

.title {
  margin: 0 0 0.25rem;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.status {
  margin: 0;
  font-size: 1rem;
  color: var(--muted);
  min-height: 1.5em;
}

.status.win {
  color: var(--accent-x);
  font-weight: 600;
}

.status.win.player-o {
  color: var(--accent-o);
}

.status.draw {
  color: var(--muted);
  font-weight: 600;
}

/* ----- Board ----- */

.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  width: 100%;
  aspect-ratio: 1;
  max-width: 360px;
}

.cell {
  background: var(--cell-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: clamp(2.5rem, 12vw, 4rem);
  font-weight: 700;
  color: var(--fg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  min-width: var(--tap);
  transition:
    background-color 0.12s ease,
    transform 0.08s ease;
  /* No text selection on rapid taps. */
  user-select: none;
  -webkit-user-select: none;
}

.cell:hover:not(:disabled) {
  background: var(--cell-bg-pressed);
}

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

.cell:disabled {
  cursor: default;
}

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

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

/* Pop-in-Animation wenn ein Zeichen gesetzt wird. */
@keyframes pop {
  0% {
    transform: scale(0.4);
    opacity: 0;
  }
  70% {
    transform: scale(1.1);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.cell.marked {
  animation: pop 0.18s ease-out;
}

/* Sieg-Zellen werden gelb hinterlegt. */
.cell.winning {
  background: var(--win-bg);
  animation: win-pulse 0.6s ease-out;
}

@keyframes win-pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

/* ----- Scoreboard ----- */

.scoreboard {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.5rem;
  width: 100%;
  max-width: 360px;
}

.score {
  background: var(--cell-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.score-label {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--muted);
}

.score-label.x {
  color: var(--accent-x);
}

.score-label.o {
  color: var(--accent-o);
}

.score-value {
  font-size: 2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ----- Controls ----- */

.controls {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
  max-width: 360px;
}

.mode-toggle {
  display: flex;
  gap: 0.5rem;
  background: var(--cell-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 0.25rem;
}

.mode-btn {
  flex: 1;
  background: transparent;
  border: none;
  padding: 0.75rem 0.5rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
  border-radius: calc(var(--radius) - 4px);
  cursor: pointer;
  min-height: var(--tap);
  transition:
    background-color 0.12s ease,
    color 0.12s ease;
}

.mode-btn.active {
  background: var(--fg);
  color: var(--bg);
}

.reset-btn {
  background: transparent;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  min-height: var(--tap);
}

.reset-btn:active {
  background: var(--cell-bg-pressed);
  color: var(--fg);
}

/* ----- Kleine Screens ----- */

@media (max-width: 360px) {
  .title {
    font-size: 1.5rem;
  }
  .status {
    font-size: 0.9rem;
  }
  .cell {
    font-size: 2.25rem;
  }
}
