/* style.css — Reversi smart AI */
:root {
  color-scheme: dark;
  --bg: #0e1518;
  --bg-2: #142024;
  --panel: #18262b;
  --panel-2: #1f3137;
  --line: #2a3d44;
  --line-soft: #243940;
  --text: #e8f0f2;
  --text-dim: #9fb3ba;
  --text-faint: #6c8389;
  --accent: #f0b440;
  --accent-2: #e08a3c;
  --felt: #1c7a52;
  --felt-2: #155f3f;
  --felt-line: #0d4630;
  --black-disc: #161a1d;
  --black-edge: #3a4248;
  --white-disc: #f3ece0;
  --white-edge: #c9bfae;
  --good: #5fd0a0;
  --bad: #ef6f6f;
  --shadow: 0 10px 30px rgba(0,0,0,.45);
  --radius: 14px;
  --radius-sm: 10px;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #eef2f1;
    --bg-2: #e2eae9;
    --panel: #ffffff;
    --panel-2: #f4f8f7;
    --line: #d2dee0;
    --line-soft: #e1e9e8;
    --text: #1a262a;
    --text-dim: #5a6f74;
    --text-faint: #8aa0a4;
    --accent: #c8821e;
    --accent-2: #a86a16;
    --felt: #2a8a5f;
    --felt-2: #1f7050;
    --felt-line: #155a3c;
    --black-disc: #1c2125;
    --black-edge: #454d54;
    --white-disc: #faf6ee;
    --white-edge: #d8cfbe;
    --shadow: 0 8px 24px rgba(20,40,40,.18);
  }
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #eef2f1; --bg-2: #e2eae9; --panel: #ffffff; --panel-2: #f4f8f7;
  --line: #d2dee0; --line-soft: #e1e9e8; --text: #1a262a; --text-dim: #5a6f74;
  --text-faint: #8aa0a4; --accent: #c8821e; --accent-2: #a86a16;
  --felt: #2a8a5f; --felt-2: #1f7050; --felt-line: #155a3c;
  --black-disc: #1c2125; --black-edge: #454d54; --white-disc: #faf6ee; --white-edge: #d8cfbe;
  --shadow: 0 8px 24px rgba(20,40,40,.18);
}
html[data-theme="dark"] {
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; width: 100%; min-height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(1200px 800px at 80% -10%, var(--bg-2), var(--bg) 60%);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

.app {
  max-width: 1080px;
  margin: 0 auto;
  padding: 18px 18px 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: linear-gradient(160deg, var(--felt), var(--felt-2));
  color: #fff;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.15), 0 6px 16px rgba(0,0,0,.3);
}
.brand-text h1 { margin: 0; font-size: 20px; letter-spacing: .2px; font-weight: 700; }
.brand-text .tag { margin: 2px 0 0; font-size: 12.5px; color: var(--text-dim); }

.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  height: 40px; padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 13.5px; font-weight: 600;
  cursor: pointer;
  transition: transform .12s ease, background .2s, border-color .2s, box-shadow .2s;
}
.chip:hover { transform: translateY(-1px); border-color: var(--accent); }
.chip:active { transform: translateY(0); }
.chip.primary {
  background: linear-gradient(160deg, var(--accent), var(--accent-2));
  border-color: transparent; color: #2a1c05;
  box-shadow: 0 6px 16px rgba(240,180,64,.25);
}
.chip .ico-off { display: none; }
.chip.on .ico-on { display: none; }
.chip.on .ico-off { display: block; }
.chip-label { white-space: nowrap; }

/* Stage */
.stage {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 18px;
  align-items: start;
  min-height: 0;
}
@media (max-width: 820px) {
  .stage { grid-template-columns: 1fr; }
}

/* Board */
.board-wrap {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}
.board {
  width: min(92vw, 560px);
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  gap: 3px;
  padding: 12px;
  border-radius: 18px;
  background:
    radial-gradient(120% 120% at 30% 20%, var(--felt) 0%, var(--felt-2) 70%, var(--felt-line) 100%);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,.08), inset 0 0 0 1px rgba(0,0,0,.2);
  perspective: 900px;
  touch-action: manipulation;
}
.cell {
  position: relative;
  border-radius: 6px;
  background: rgba(0,0,0,.10);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.03);
  display: grid;
  place-items: center;
  cursor: default;
  min-width: 0; min-height: 0;
}
.cell.playable { cursor: pointer; }
.cell.last::after {
  content: "";
  position: absolute; inset: 3px;
  border-radius: 6px;
  box-shadow: inset 0 0 0 2px var(--accent);
  pointer-events: none;
  opacity: .9;
}

.disc {
  width: 82%; height: 82%;
  border-radius: 50%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform .5s cubic-bezier(.4,.1,.2,1);
  opacity: 0;
  transform: rotateY(0deg) scale(.6);
}
.disc.placed { opacity: 1; transform: rotateY(0deg) scale(1); }
.face {
  position: absolute; inset: 0;
  border-radius: 50%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.face.front {
  background: radial-gradient(60% 60% at 35% 30%, #3a4248 0%, var(--black-disc) 60%, #050708 100%);
  box-shadow: 0 3px 6px rgba(0,0,0,.5), inset 0 2px 3px rgba(255,255,255,.12);
}
.face.back {
  transform: rotateY(180deg);
  background: radial-gradient(60% 60% at 35% 30%, #ffffff 0%, var(--white-disc) 55%, var(--white-edge) 100%);
  box-shadow: 0 3px 6px rgba(0,0,0,.35), inset 0 2px 3px rgba(255,255,255,.7);
}

.hint-ring {
  position: absolute;
  width: 30%; height: 30%;
  border-radius: 50%;
  border: 2px solid rgba(240,180,64,.85);
  background: rgba(240,180,64,.12);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.hint-ring.show {
  opacity: 1;
  animation: hintPulse 1.6s ease-in-out infinite;
}
@keyframes hintPulse {
  0%, 100% { transform: scale(.85); opacity: .55; }
  50% { transform: scale(1.05); opacity: .95; }
}
.cell.playable:hover .hint-ring.show { transform: scale(1.15); border-color: var(--accent); }

/* Overlay */
.board-overlay {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: radial-gradient(circle at center, rgba(8,12,14,.55), rgba(8,12,14,.85));
  backdrop-filter: blur(4px);
  border-radius: 18px;
  z-index: 5;
}
.board-overlay[hidden] { display: none; }
.overlay-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px 26px;
  text-align: center;
  box-shadow: var(--shadow);
  max-width: 320px;
  animation: pop .25s ease;
}
@keyframes pop { from { transform: scale(.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.overlay-card h2 { margin: 0 0 6px; font-size: 22px; }
.overlay-card p { margin: 0 0 14px; color: var(--text-dim); font-size: 13.5px; }
.overlay-score { display: flex; gap: 14px; justify-content: center; margin-bottom: 16px; }
.os-row { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
.btn {
  height: 42px; padding: 0 22px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-weight: 700; font-size: 14px;
  cursor: pointer;
  transition: transform .12s, box-shadow .2s, background .2s;
}
.btn.primary {
  background: linear-gradient(160deg, var(--accent), var(--accent-2));
  border-color: transparent; color: #2a1c05;
  box-shadow: 0 6px 16px rgba(240,180,64,.3);
}
.btn:hover { transform: translateY(-1px); }

/* Panel */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: var(--shadow);
}
@media (max-width: 820px) {
  .panel { padding: 14px; }
}

.scores {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
}
.score {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  border: 1px solid transparent;
  transition: border-color .2s, box-shadow .2s;
}
.score.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(240,180,64,.12);
}
.score-meta { display: flex; flex-direction: column; line-height: 1.15; }
.score-name { font-size: 12.5px; color: var(--text-dim); }
.score-val { font-size: 22px; font-weight: 800; letter-spacing: .3px; }
.vs { font-size: 12px; color: var(--text-faint); font-weight: 700; }

.dot {
  width: 22px; height: 22px; border-radius: 50%;
  flex: 0 0 auto;
  box-shadow: inset 0 1px 2px rgba(255,255,255,.2), 0 2px 4px rgba(0,0,0,.3);
}
.dot.black { background: radial-gradient(60% 60% at 35% 30%, #3a4248, var(--black-disc) 65%); }
.dot.white { background: radial-gradient(60% 60% at 35% 30%, #fff, var(--white-disc) 60%, var(--white-edge)); }
.dot.inline { width: 14px; height: 14px; display: inline-block; vertical-align: -2px; margin-right: 4px; }

.turn-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px;
  background: var(--panel-2);
  border-radius: var(--radius-sm);
}
.turn-indicator { display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: 13.5px; }
.turn-dot { width: 14px; height: 14px; border-radius: 50%; }
.turn-dot.black { background: radial-gradient(60% 60% at 35% 30%, #3a4248, var(--black-disc) 65%); }
.turn-dot.white { background: radial-gradient(60% 60% at 35% 30%, #fff, var(--white-disc) 60%, var(--white-edge)); }
.move-count { font-size: 12px; color: var(--text-faint); font-weight: 600; }

.control-group { display: flex; flex-direction: column; gap: 8px; }
.control-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .8px; color: var(--text-faint); font-weight: 700; }
.seg {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  background: var(--panel-2);
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}
.seg-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 12.5px; font-weight: 600;
  padding: 8px 6px;
  border-radius: 7px;
  cursor: pointer;
  transition: background .15s, color .15s, box-shadow .15s;
  min-height: 36px;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active {
  background: linear-gradient(160deg, var(--accent), var(--accent-2));
  color: #2a1c05;
  box-shadow: 0 3px 8px rgba(240,180,64,.25);
}
.ai-desc, .hint { margin: 0; font-size: 12px; color: var(--text-dim); line-height: 1.45; }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  width: 38px; height: 22px; border-radius: 999px;
  background: var(--line);
  position: relative;
  transition: background .2s;
}
.switch-thumb {
  position: absolute; top: 3px; left: 3px;
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff;
  transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.4);
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px rgba(240,180,64,.4); }
.switch-label { font-size: 13px; font-weight: 600; }

.log-wrap { display: flex; flex-direction: column; gap: 6px; min-height: 0; }
.log-head { font-size: 11.5px; text-transform: uppercase; letter-spacing: .8px; color: var(--text-faint); font-weight: 700; }
.log {
  margin: 0; padding: 6px 8px;
  list-style: none;
  max-height: 150px;
  overflow-y: auto;
  background: var(--panel-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-soft);
  font-size: 12px;
}
.log li { display: flex; gap: 8px; padding: 3px 0; }
.log-idx { color: var(--text-faint); width: 22px; text-align: right; font-variant-numeric: tabular-nums; }
.log-mv { color: var(--text-dim); }
.log-mv.you { color: var(--text); font-weight: 600; }
.log-mv.ai { color: var(--accent); }

.safe-area { height: calc(56px + env(safe-area-inset-bottom)); flex: 0 0 auto; }

/* Scrollbars */
.log::-webkit-scrollbar { width: 8px; }
.log::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }

/* Focus */
button:focus-visible, .seg-btn:focus-visible, .chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (max-width: 420px) {
  .app { padding: 12px 12px 0; }
  .brand-text h1 { font-size: 18px; }
  .chip { padding: 0 10px; }
  .chip-label { display: none; }
  .top-actions .chip { width: 40px; justify-content: center; }
  .top-actions .chip.primary { width: auto; }
  .top-actions .chip.primary .chip-label { display: inline; }
}
