/* Reversi — game-specific styles */

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.page-head h1 {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 700;
  font-size: clamp(28px, 4.4vw, 40px);
  letter-spacing: -0.02em;
  margin: 0;
  line-height: 1.05;
}
.page-head .sub {
  color: var(--ink-soft);
  margin: 6px 0 0;
  font-size: 14px;
  min-height: 1.4em;
}
.head-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.hint-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font: 600 13px 'Inter', sans-serif;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 6px 10px;
  border: 1px solid var(--line);
  background: var(--paper);
  border-radius: 999px;
}
.hint-toggle input { accent-color: var(--accent); }

.play {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}

/* ---------- Setup screen ---------- */
.setup { max-width: 520px; margin: 6px auto; }
.setup-title {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 700;
  font-size: clamp(22px, 3.2vw, 28px);
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}
.setup-sub { color: var(--ink-soft); margin: 0 0 22px; font-size: 14px; }

.setup-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 18px;
}
.setup-group[hidden] { display: none; }
.setup-label {
  font: 700 12px 'Inter', sans-serif;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.seg {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px;
  align-self: flex-start;
}
.seg-btn {
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--ink-soft);
  font: 600 13px 'Inter', sans-serif;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: background 160ms ease, color 160ms ease;
}
.seg-btn:hover { color: var(--ink); }
.seg-btn.is-active {
  background: var(--accent);
  color: var(--paper);
}
.setup-actions { margin-top: 8px; }

/* Mini chip used in setup buttons + scoreboard */
.chip {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  vertical-align: middle;
  flex-shrink: 0;
}
.chip-black { background: var(--accent); box-shadow: inset 0 -2px 0 rgba(0,0,0,0.18); }
.chip-white { background: #f4ecd4; border: 1px solid #c9bf9d; box-shadow: inset 0 -2px 0 rgba(0,0,0,0.06); }

/* ---------- Game screen ---------- */
.scoreboard {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
}
.score {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  border-radius: 12px;
  transition: border-color 200ms ease, background 200ms ease, box-shadow 200ms ease;
}
.score-white { justify-self: end; }
.score.is-turn {
  border-color: var(--line-strong);
  background: var(--paper);
  box-shadow: var(--shadow);
}
.score .chip { width: 22px; height: 22px; }
.score-info { display: flex; flex-direction: column; line-height: 1.1; }
.score-label {
  font: 700 11px 'Inter', sans-serif;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.score-val {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 700;
  font-size: 22px;
  color: var(--ink);
  margin-top: 2px;
}

.turn-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font: 600 13px 'Inter', sans-serif;
  color: var(--ink-soft);
  background: transparent;
  padding: 0 6px;
  text-align: center;
}
.turn-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  transition: background 200ms ease, border-color 200ms ease;
  border: 1px solid transparent;
}
.turn-dot.is-white {
  background: #f4ecd4;
  border-color: #c9bf9d;
}

/* ---------- Board ---------- */
.board-wrap {
  display: flex;
  justify-content: center;
}
.board {
  --cell: clamp(34px, 9.2vw, 64px);
  display: grid;
  grid-template-columns: repeat(8, var(--cell));
  grid-template-rows: repeat(8, var(--cell));
  gap: 2px;
  padding: 12px;
  background: #214a3f;
  border: 1px solid #163128;
  border-radius: 10px;
  box-shadow:
    inset 0 0 0 2px rgba(0,0,0,0.18),
    0 1px 0 rgba(31, 58, 95, 0.08),
    0 22px 44px -22px rgba(20, 50, 40, 0.55);
}

.cell {
  appearance: none;
  border: 0;
  padding: 0;
  margin: 0;
  width: var(--cell);
  height: var(--cell);
  background: #2d5a4f;
  border-radius: 4px;
  position: relative;
  cursor: default;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 180ms ease;
}
.cell.is-legal {
  cursor: pointer;
}
.cell.is-legal:hover {
  background: #357164;
}

/* Hint dot on legal moves */
.cell.show-hint::before {
  content: '';
  position: absolute;
  width: 26%;
  height: 26%;
  border-radius: 50%;
  background: rgba(244, 236, 212, 0.32);
  transform: scale(0.7);
  opacity: 0;
  transition: opacity 180ms ease, transform 180ms ease;
}
.cell.show-hint.is-legal::before { opacity: 1; transform: scale(1); }
.cell.show-hint.is-legal:hover::before {
  background: rgba(244, 236, 212, 0.55);
}

/* Last-move indicator (small ring) */
.cell.is-last-move .disc::after {
  content: '';
  position: absolute;
  inset: -6%;
  border-radius: 50%;
  border: 2px solid rgba(244, 227, 178, 0.55);
  pointer-events: none;
}

/* Discs */
.disc {
  position: relative;
  width: 78%;
  height: 78%;
  border-radius: 50%;
  transform-style: preserve-3d;
  transition: transform 220ms ease;
  /* default sits face up */
  transform: rotateY(0deg);
}
.disc-face {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.disc-face.front {
  background: radial-gradient(circle at 32% 28%, #3e5f88 0%, #1f3a5f 55%, #15294a 100%);
  box-shadow: inset 0 -3px 6px rgba(0,0,0,0.35), 0 2px 4px rgba(0,0,0,0.25);
}
.disc-face.back {
  background: radial-gradient(circle at 32% 28%, #fbf6ea 0%, #f1e6c8 60%, #d9c896 100%);
  box-shadow: inset 0 -3px 6px rgba(60, 50, 20, 0.18), 0 2px 4px rgba(0,0,0,0.18);
  transform: rotateY(180deg);
}
/* Black up = front shows navy; White up = rotate 180 to reveal back */
.disc.is-white { transform: rotateY(180deg); }

/* Spawn animation on placement */
.disc.is-new {
  animation: discIn 200ms ease-out;
}
@keyframes discIn {
  0%   { transform: scale(0.2) rotateY(0deg); opacity: 0; }
  100% { transform: scale(1) rotateY(var(--end-rot, 0deg)); opacity: 1; }
}
.disc.is-white.is-new {
  --end-rot: 180deg;
}

/* Chain-flipped disc — briefly glows */
@keyframes rv-just-flipped {
  0%   { filter: drop-shadow(0 0 0 rgba(213, 192, 125, 0)); }
  50%  { filter: drop-shadow(0 0 6px rgba(213, 192, 125, 0.7)); }
  100% { filter: drop-shadow(0 0 0 rgba(213, 192, 125, 0)); }
}
.disc.just-flipped {
  animation: rv-just-flipped 700ms ease-out;
}

@media (prefers-reduced-motion: reduce) {
  .disc, .disc.is-new, .disc.just-flipped { animation: none; transition: none; }
}

/* ---------- Win overlay ---------- */
.win-overlay {
  position: fixed; inset: 0; background: rgba(28, 42, 58, 0.55);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.win-overlay[hidden] { display: none; }
.win-card {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 28px 30px; text-align: center; box-shadow: var(--shadow-lift); max-width: 360px;
  width: 100%;
}
.win-card h2 {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 700;
  font-size: 26px;
  margin: 0 0 6px;
  letter-spacing: -0.01em;
}
.win-sub {
  color: var(--ink-soft);
  margin: 0 0 18px;
}
.win-scores {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-bottom: 22px;
}
.win-score {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.win-score .chip { width: 28px; height: 28px; }
.win-score-label {
  font: 700 11px 'Inter', sans-serif;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}
.win-score-val {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 700;
  font-size: 28px;
  color: var(--ink);
}
.win-actions { display: flex; justify-content: center; gap: 10px; }

/* ---------- Aside / help ---------- */
.aside-info { margin-top: 22px; }
.aside-info details {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 16px;
  box-shadow: var(--shadow);
}
.aside-info summary {
  cursor: pointer;
  font: 700 14px 'Inter', sans-serif;
  color: var(--ink);
}
.aside-info .help-body {
  margin-top: 10px;
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.55;
}
.aside-info .help-body p { margin: 0 0 8px; }
.aside-info .help-body ul { margin: 0 0 8px; padding-left: 18px; }
.aside-info .help-body li { margin: 4px 0; }

/* ---------- Responsive ---------- */
@media (max-width: 520px) {
  .play { padding: 14px; }
  .scoreboard { gap: 8px; }
  .score { padding: 8px 10px; gap: 8px; }
  .score .chip { width: 18px; height: 18px; }
  .score-val { font-size: 18px; }
  .turn-indicator { font-size: 12px; }
  .board { padding: 8px; gap: 2px; }
}
@media (max-width: 380px) {
  .scoreboard {
    grid-template-columns: 1fr 1fr;
  }
  .turn-indicator { grid-column: 1 / -1; order: -1; justify-content: center; }
}
