/* fastReversi - styles. Light/dark themes via CSS variables. */

/* ---- Theme tokens ------------------------------------------------------- */

:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --text: #1f2937;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --board-bg: #1f7a4d;
  --board-line: #14613b;
  --cell-hover: rgba(255, 255, 255, 0.12);
  --disc-black: #1b1b1b;
  --disc-black-edge: #000000;
  --disc-white: #fafafa;
  --disc-white-edge: #c9c9c9;
  --hint: rgba(255, 255, 255, 0.55);
  --last-move: #facc15;
  --skip: #d97706;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.08);
  --radius: 12px;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #243349;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --border: #334155;
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --board-bg: #14532d;
  --board-line: #0b3d20;
  --cell-hover: rgba(255, 255, 255, 0.08);
  --disc-black: #0a0a0a;
  --disc-black-edge: #000000;
  --disc-white: #f1f5f9;
  --disc-white-edge: #94a3b8;
  --hint: rgba(255, 255, 255, 0.4);
  --last-move: #fbbf24;
  --skip: #f59e0b;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

/* ---- Base --------------------------------------------------------------- */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.app {
  max-width: 1080px;
  margin: 0 auto;
  padding: 20px 16px 32px;
}

.app-header {
  text-align: center;
  margin-bottom: 20px;
}

.app-title {
  margin: 0;
  font-size: 2rem;
  letter-spacing: -0.02em;
}

.app-tagline {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* ---- Layout ------------------------------------------------------------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 24px;
  align-items: start;
}

.game-area {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.scoreboard {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: var(--shadow);
}

.score {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.score-white { justify-content: flex-end; }

.score-disc {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex-shrink: 0;
}

.score-disc.black {
  background: radial-gradient(circle at 35% 30%, #444, var(--disc-black));
  border: 1px solid var(--disc-black-edge);
}

.score-disc.white {
  background: radial-gradient(circle at 35% 30%, #fff, var(--disc-white));
  border: 1px solid var(--disc-white-edge);
}

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

.score-value {
  font-size: 1.35rem;
  font-variant-numeric: tabular-nums;
  min-width: 1.4em;
  text-align: center;
}

.turn-box { text-align: center; }

.turn-indicator {
  margin: 0;
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
}

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

.board-wrap {
  width: 100%;
}

.board {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  gap: 2px;
  background: var(--board-line);
  border: 4px solid var(--board-line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.cell {
  position: relative;
  background: var(--board-bg);
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s ease;
}

.cell:hover { background: color-mix(in srgb, var(--board-bg) 88%, white); }

.cell:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
  z-index: 2;
}

/* Legal-move hint dot (only when hints enabled). */
.cell.legal::after {
  content: "";
  position: absolute;
  width: 30%;
  height: 30%;
  border-radius: 50%;
  background: var(--hint);
  pointer-events: none;
}

/* Highlight the most recent move. */
.cell.last-move {
  box-shadow: inset 0 0 0 3px var(--last-move);
}

/* ---- Discs -------------------------------------------------------------- */

.disc {
  width: 78%;
  height: 78%;
  border-radius: 50%;
  transform: scale(0);
  transition: transform 0.18s ease;
}

.disc.black, .disc.white {
  transform: scale(1);
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.35);
}

.disc.black {
  background: radial-gradient(circle at 35% 30%, #4a4a4a, var(--disc-black) 70%);
  border: 1px solid var(--disc-black-edge);
}

.disc.white {
  background: radial-gradient(circle at 35% 30%, #ffffff, var(--disc-white) 70%);
  border: 1px solid var(--disc-white-edge);
}

/* Flip animation applied to captured discs. */
.disc.flipping {
  animation: flip 0.35s ease;
}

@keyframes flip {
  0% { transform: scale(1) rotateY(0deg); }
  50% { transform: scale(1) rotateY(90deg); }
  100% { transform: scale(1) rotateY(0deg); }
}

/* ---- Status + actions --------------------------------------------------- */

.status-message {
  min-height: 1.5em;
  margin: 0;
  text-align: center;
  font-weight: 500;
  color: var(--text-muted);
}

.status-message.skip { color: var(--skip); font-weight: 600; }
.status-message.thinking { color: var(--accent); }
.status-message.game-over { color: var(--text); font-weight: 700; font-size: 1.1rem; }

.actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease,
    opacity 0.15s ease;
}

.btn:hover { background: var(--surface-2); }
.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

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

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ---- Panels (sidebar) --------------------------------------------------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.panel-title {
  margin: 0 0 12px;
  font-size: 1.05rem;
}

.field {
  margin-bottom: 14px;
}

.field:last-child { margin-bottom: 0; }

.field-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.field-inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.field-inline .switch-label {
  font-size: 0.9rem;
  font-weight: 600;
}

.select {
  width: 100%;
  padding: 8px 10px;
  font-size: 0.95rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}

.select:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }

.radio-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.radio {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.92rem;
  cursor: pointer;
}

/* ---- Switch toggle ------------------------------------------------------ */

.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}

.switch-track {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 999px;
  transition: background-color 0.2s ease;
}

.switch-track::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::before { transform: translateX(20px); }
.switch input:focus-visible + .switch-track {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ---- Move history ------------------------------------------------------- */

.move-history {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 240px;
  overflow-y: auto;
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.move-history li {
  padding: 3px 6px;
  border-radius: 4px;
}

.move-history li:nth-child(even) { background: var(--surface-2); }
.move-history .history-skip { color: var(--skip); font-style: italic; }
.move-history .history-empty { color: var(--text-muted); font-style: italic; }

/* ---- Rules + footer ----------------------------------------------------- */

.rules-text {
  margin: 0;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.app-footer {
  margin-top: 28px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* ---- Responsive --------------------------------------------------------- */

@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    order: 2;
  }
  .board { max-width: 480px; }
}

@media (max-width: 520px) {
  .app { padding: 14px 10px 24px; }
  .app-title { font-size: 1.6rem; }
  .scoreboard { padding: 10px; gap: 6px; }
  .score-label { display: none; }
  .turn-indicator { font-size: 0.85rem; white-space: normal; }
  .actions { flex-direction: column; }
  .btn { width: 100%; }
}

/* Respect reduced-motion preferences. */
@media (prefers-reduced-motion: reduce) {
  .disc, .disc.flipping, .cell, .switch-track::before {
    transition: none;
    animation: none;
  }
}
