*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-hover: #243044;
  --border: #2d3a4f;
  --text: #e8edf5;
  --text-muted: #8b9cb3;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --x-color: #f472b6;
  --o-color: #34d399;
  --win: #fbbf24;
  --radius: 12px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(59, 130, 246, 0.12) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(244, 114, 182, 0.08) 0%, transparent 50%);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.app {
  width: 100%;
  max-width: 520px;
  padding: 2rem 1.5rem;
}

.app.app-wide {
  max-width: min(96vw, 620px);
}

header {
  text-align: center;
  margin-bottom: 2rem;
}

h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  color: var(--text-muted);
  margin-top: 0.5rem;
  font-size: 0.95rem;
}

.hidden {
  display: none !important;
}

/* Game selection */
.game-select {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.game-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
  padding: 1.25rem 1.5rem;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
  text-align: left;
  box-shadow: var(--shadow);
}

.game-btn:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
  transform: translateY(-2px);
}

.game-icon {
  font-size: 1.75rem;
  margin-bottom: 0.25rem;
}

.game-label {
  font-size: 1.1rem;
  font-weight: 600;
}

.game-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Mode selection */
.mode-select {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.back-btn {
  margin-top: 0.5rem;
}

.mode-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
  padding: 1.25rem 1.5rem;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
  text-align: left;
  box-shadow: var(--shadow);
}

.mode-btn:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
  transform: translateY(-2px);
}

.mode-icon {
  font-size: 1.75rem;
  margin-bottom: 0.25rem;
}

.mode-label {
  font-size: 1.1rem;
  font-weight: 600;
}

.mode-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Game section */
.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.mode-badge {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  background: rgba(59, 130, 246, 0.15);
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
}

.turn-indicator {
  font-size: 1rem;
  font-weight: 500;
}

.turn-indicator .mark-x {
  color: var(--x-color);
  font-weight: 700;
}

.turn-indicator .mark-o {
  color: var(--o-color);
  font-weight: 700;
}

/* Board */
.board {
  display: grid;
  gap: 4px;
  background: #1e6b3a;
  padding: 6px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
}

.board-ttt {
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  background: var(--border);
  padding: 8px;
}

.board-reversi {
  grid-template-columns: repeat(8, 1fr);
}

.cell {
  aspect-ratio: 1;
  background: var(--surface);
  border: none;
  border-radius: 8px;
  font-size: 2.5rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cell:hover:not(:disabled):not(.taken) {
  background: var(--surface-hover);
}

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

.cell:disabled {
  cursor: default;
}

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

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

.cell.winning {
  background: rgba(251, 191, 36, 0.2);
  animation: pulse 0.6s ease-in-out;
}

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

.board.thinking .cell-reversi:not(.disc-black):not(.disc-white) {
  opacity: 0.5;
}

.cell-reversi {
  position: relative;
  font-size: 0;
  border-radius: 4px;
  background: #2d8a4e;
  padding: 0;
  min-height: 0;
}

.cell-reversi::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 84%;
  height: 84%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  pointer-events: none;
}

.cell-reversi.disc-black::after {
  background: radial-gradient(circle at 32% 28%, #6b6b6b, #1a1a1a 55%, #000 100%);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.45);
}

.cell-reversi.disc-white::after {
  background: radial-gradient(circle at 32% 28%, #ffffff, #e8e8e8 55%, #b0b0b0 100%);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
}

.cell-reversi.valid-move {
  cursor: pointer;
}

.cell-reversi.valid-move::after {
  width: 28%;
  height: 28%;
  background: rgba(251, 191, 36, 0.85);
  box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.4);
}

.cell-reversi.valid-move:hover::after {
  width: 32%;
  height: 32%;
  background: rgba(251, 191, 36, 1);
}

.cell-reversi.disc-black.valid-move::after,
.cell-reversi.disc-white.valid-move::after {
  width: 84%;
  height: 84%;
}

.mark-black {
  color: #a3a3a3;
  font-weight: 700;
}

.mark-white {
  color: #f5f5f5;
  font-weight: 700;
}

.score-bar {
  text-align: center;
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--text-muted);
}

/* Minesweeper */
.board-minesweeper {
  display: grid;
  gap: 2px;
  background: var(--border);
  padding: 4px;
  user-select: none;
}

.board-mines-8 {
  grid-template-columns: repeat(8, 1fr);
}

.board-mines-15 {
  grid-template-columns: repeat(15, 1fr);
}

.cell-mine {
  aspect-ratio: 1;
  min-width: 0;
  min-height: 0;
  padding: 0;
  font-size: 0.85rem;
  font-weight: 700;
  border: none;
  border-radius: 3px;
  background: #4a6fa5;
  color: var(--text);
  cursor: pointer;
  line-height: 1;
}

.board-mines-15 .cell-mine {
  font-size: 0.65rem;
  border-radius: 2px;
}

.cell-mine:hover:not(:disabled):not(.revealed) {
  background: #5a82b8;
}

.cell-mine.revealed {
  background: #2a3548;
  cursor: default;
}

.cell-mine.flagged {
  background: #4a6fa5;
  font-size: 0.75rem;
}

.cell-mine.mine-hit {
  background: #7f1d1d;
}

.cell-mine.mine-show {
  background: #3f3f46;
  opacity: 0.85;
}

.cell-mine.n1 { color: #60a5fa; }
.cell-mine.n2 { color: #4ade80; }
.cell-mine.n3 { color: #f87171; }
.cell-mine.n4 { color: #a78bfa; }
.cell-mine.n5 { color: #fbbf24; }
.cell-mine.n6 { color: #2dd4bf; }
.cell-mine.n7 { color: #f472b6; }
.cell-mine.n8 { color: #94a3b8; }

/* Result */
.result {
  text-align: center;
  padding: 1rem;
  margin-bottom: 1rem;
  background: rgba(251, 191, 36, 0.1);
  border: 1px solid rgba(251, 191, 36, 0.3);
  border-radius: var(--radius);
}

.result-text {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--win);
}

/* Controls */
.controls {
  display: flex;
  gap: 0.75rem;
}

.btn {
  flex: 1;
  padding: 0.85rem 1.25rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

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

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--border);
}

.btn-secondary:hover {
  background: var(--surface-hover);
  border-color: var(--text-muted);
}

/* Stats panel */
.stats-panel {
  margin-top: 1.5rem;
  padding: 1.25rem;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.stats-title {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.stats-empty {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.stats-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  max-height: 200px;
  overflow-y: auto;
}

.stats-item {
  padding: 0.65rem 0.75rem;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.stats-item:hover {
  border-color: var(--accent);
  background: var(--surface-hover);
}

.stats-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.stats-rate {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--win);
}

.stats-item-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.history-panel {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.history-title {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.history-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 140px;
  overflow-y: auto;
}

.history-item {
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 0.4rem 0.5rem;
  background: var(--bg);
  border-radius: 6px;
}

.history-win {
  color: var(--o-color);
}

.history-loss {
  color: var(--x-color);
}

/* Setup form */
.setup-title {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 1.25rem;
  text-align: center;
}

.setup-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.field span {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
}

.field input {
  padding: 0.85rem 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
}

.field input:focus {
  outline: none;
  border-color: var(--accent);
}

.players-bar {
  text-align: center;
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.players-bar .mark-x {
  color: var(--x-color);
  font-weight: 600;
}

.players-bar .mark-o {
  color: var(--o-color);
  font-weight: 600;
}

.result-stats {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
  font-weight: 400;
}
