/* =========================================================
   Gomoku — Premium modern
   Zen (light) & Night (dark) themes
   ========================================================= */

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

:root {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow-1: 0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.06);
  --shadow-2: 0 10px 30px rgba(0,0,0,.12);
  --shadow-3: 0 20px 60px rgba(0,0,0,.25);
  --ease: cubic-bezier(.2,.8,.2,1);
  --dur: .28s;
}

/* Zen (light) */
[data-theme="zen"] {
  --bg: #f4efe6;
  --bg-soft: #ede6d6;
  --surface: #fbf8f1;
  --surface-2: #f0ead8;
  --ink: #15181e;
  --ink-soft: #555a66;
  --ink-mute: #8a8f9a;
  --line: rgba(20, 22, 28, 0.14);
  --line-strong: rgba(20, 22, 28, 0.22);
  --accent: #b8523b;
  --accent-soft: #d97a62;
  --gold: #c9a24a;
  --win: #2f8f5f;
  --danger: #c24a3a;
  --stone-black: radial-gradient(circle at 35% 30%, #4a4a54 0%, #1a1a1f 55%, #0a0a0d 100%);
  --stone-white: radial-gradient(circle at 35% 30%, #ffffff 0%, #ece8dd 60%, #c9c3b1 100%);
  --board-bg: linear-gradient(180deg, #e6c98a 0%, #d8b56e 100%);
  --board-line: rgba(40, 28, 10, .55);
}

/* Night (dark) */
[data-theme="night"] {
  --bg: #0b0d12;
  --bg-soft: #10131a;
  --surface: #151924;
  --surface-2: #1b2030;
  --ink: #f1f2f6;
  --ink-soft: #b4b8c4;
  --ink-mute: #7a7f8c;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --accent: #ff8765;
  --accent-soft: #ffa88c;
  --gold: #e5c46b;
  --win: #5ed19a;
  --danger: #ff6a58;
  --stone-black: radial-gradient(circle at 35% 30%, #3a3f4d 0%, #0e1016 55%, #05060a 100%);
  --stone-white: radial-gradient(circle at 35% 30%, #ffffff 0%, #e5e8f0 60%, #aab0c0 100%);
  --board-bg: linear-gradient(180deg, #2a2016 0%, #1c1610 100%);
  --board-line: rgba(230, 200, 140, .28);
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

#app {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
  position: relative;
}

button {
  font-family: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  font-size: inherit;
}

/* =========================================================
   SCREENS
   ========================================================= */
.screen {
  display: none;
  flex: 1;
  flex-direction: column;
  padding: 24px 20px 32px;
  animation: fadeIn var(--dur) var(--ease);
}
.screen.active { display: flex; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* =========================================================
   HOME
   ========================================================= */
.screen--home { justify-content: space-between; }

.home-header {
  padding-top: 24px;
  text-align: center;
}
.brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.brand-mark {
  position: relative;
  width: 70px;
  height: 42px;
}
.brand-mark .stone {
  position: absolute;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  box-shadow: 0 4px 10px rgba(0,0,0,.2), inset 0 -2px 4px rgba(0,0,0,.2);
}
.brand-mark .stone--black { left: 0; top: 2px; background: var(--stone-black); }
.brand-mark .stone--white { right: 0; top: 2px; background: var(--stone-white); }
.brand-title {
  font-size: 32px;
  margin: 0;
  letter-spacing: -0.02em;
  font-weight: 700;
}
.brand-tag {
  margin: 0;
  color: var(--ink-soft);
  font-size: 14px;
  letter-spacing: .2px;
}

.modes {
  display: grid;
  gap: 12px;
  padding: 28px 0;
}
.mode-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  text-align: left;
  transition: transform var(--dur) var(--ease), border-color var(--dur) var(--ease), background var(--dur) var(--ease);
  box-shadow: var(--shadow-1);
}
.mode-card:active { transform: scale(.985); }
.mode-card:hover { border-color: var(--line-strong); }
.mode-card--primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-soft) 100%);
  color: #fff;
  border-color: transparent;
}
.mode-card--primary .mode-sub { color: rgba(255,255,255,.82); }
.mode-card--ghost {
  background: transparent;
  border-style: dashed;
}
.mode-title {
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.mode-sub {
  font-size: 13px;
  color: var(--ink-soft);
}

.home-footer {
  display: flex;
  justify-content: center;
  gap: 16px;
  padding-top: 8px;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px solid var(--line);
  transition: transform var(--dur) var(--ease), color var(--dur) var(--ease);
}
.icon-btn:hover { color: var(--ink); }
.icon-btn:active { transform: scale(.92); }

/* =========================================================
   DIFFICULTY
   ========================================================= */
.back-btn {
  align-self: flex-start;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-soft);
  margin-bottom: 12px;
}
.screen-title {
  font-size: 26px;
  margin: 8px 4px 22px;
  letter-spacing: -0.01em;
}
.difficulty-list {
  display: grid;
  gap: 12px;
}
.diff-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 16px;
  align-items: center;
  text-align: left;
  transition: transform var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.diff-card:hover { border-color: var(--accent); }
.diff-card:active { transform: scale(.985); }
.diff-name {
  font-size: 18px;
  font-weight: 650;
  grid-column: 1;
}
.diff-desc {
  font-size: 13px;
  color: var(--ink-soft);
  grid-column: 1;
}
.diff-dots {
  grid-column: 2;
  grid-row: 1 / span 2;
  display: flex;
  gap: 5px;
}
.diff-dots i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--line-strong);
}
.diff-dots i.on { background: var(--accent); }

/* =========================================================
   GAME SCREEN
   ========================================================= */
.screen--game { padding: 12px 14px 20px; }

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 4px 14px;
}

.players {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 14px;
  box-shadow: var(--shadow-1);
}
.player {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border-radius: 999px;
  transition: background var(--dur) var(--ease);
}
.player.active {
  background: var(--surface-2);
}
.player-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}
.stone {
  display: inline-block;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  box-shadow: 0 2px 5px rgba(0,0,0,.25), inset 0 -1px 2px rgba(0,0,0,.25);
}
.stone--black { background: var(--stone-black); }
.stone--white { background: var(--stone-white); }
.turn-divider {
  color: var(--ink-mute);
  font-size: 14px;
}

/* Board */
.board-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  max-width: 540px;
  margin: 10px auto;
  padding: 14px;
  border-radius: var(--radius-md);
  background: var(--board-bg);
  box-shadow: var(--shadow-2), inset 0 0 0 1px rgba(0,0,0,.15);
  overflow: hidden;
}
.board {
  position: relative;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
}

/* Grid lines drawn via CSS background */
.board::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(to right, var(--board-line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--board-line) 1px, transparent 1px);
  background-size: calc(100% / 14) calc(100% / 14);
  background-position: 0 0;
  pointer-events: none;
}
.star {
  position: absolute;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--board-line);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.cell {
  position: absolute;
  width: calc(100% / 15);
  height: calc(100% / 15);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transform: translate(-50%, -50%);
}
.cell .stone-el {
  width: 110%;
  height: 110%;
  border-radius: 50%;
  opacity: 0;
  transform: scale(.4);
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
  box-shadow: 0 3px 8px rgba(0,0,0,.35), inset 0 -2px 4px rgba(0,0,0,.25);
}
.cell.placed .stone-el {
  opacity: 1;
  transform: scale(1);
}
.cell.black .stone-el { background: var(--stone-black); }
.cell.white .stone-el { background: var(--stone-white); }

.cell.last::after {
  content: "";
  position: absolute;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  border: 2px solid var(--accent);
  pointer-events: none;
  animation: pulse 1.4s var(--ease) infinite;
}
@keyframes pulse {
  0%, 100% { opacity: .8; transform: scale(1); }
  50% { opacity: .3; transform: scale(1.25); }
}

.cell.win .stone-el {
  box-shadow: 0 0 0 3px var(--win), 0 3px 12px rgba(0,0,0,.35), inset 0 -2px 4px rgba(0,0,0,.25);
}

.cell.ghost:hover .stone-el {
  opacity: .35;
  transform: scale(.9);
}

.cell.threat::before {
  content: "";
  position: absolute;
  width: 40%;
  height: 40%;
  border-radius: 50%;
  background: rgba(255, 120, 80, .35);
  border: 1.5px dashed rgba(255, 120, 80, .8);
}

/* Game bar */
.game-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 6px 2px;
}
.game-info { display: flex; flex-direction: column; gap: 2px; }
.info-label { font-size: 15px; font-weight: 650; }
.info-sub { font-size: 12px; color: var(--ink-soft); }
.game-actions { display: flex; gap: 8px; }
.chip {
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  transition: transform var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.chip:hover { color: var(--ink); border-color: var(--line-strong); }
.chip:active { transform: scale(.95); }
.chip[disabled] { opacity: .4; cursor: not-allowed; }

/* =========================================================
   OVERLAYS / SHEETS
   ========================================================= */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(6px);
  display: none;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
  animation: fadeIn var(--dur) var(--ease);
}
.overlay.active { display: flex; }

.sheet {
  width: 100%;
  max-width: 560px;
  background: var(--surface);
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  padding: 28px 24px 32px;
  box-shadow: var(--shadow-3);
  animation: slideUp .34s var(--ease);
}
@media (min-width: 560px) {
  .overlay { align-items: center; }
  .sheet { border-radius: 24px; }
}
@keyframes slideUp {
  from { transform: translateY(30px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.sheet-icon {
  font-size: 42px;
  text-align: center;
  color: var(--gold);
  margin-bottom: 4px;
}
.sheet-title {
  font-size: 22px;
  text-align: center;
  margin: 6px 0 6px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.sheet-sub {
  text-align: center;
  color: var(--ink-soft);
  margin: 0 0 22px;
  font-size: 14px;
}

.sheet-actions {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.btn {
  padding: 14px 18px;
  border-radius: 14px;
  background: var(--surface-2);
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease);
}
.btn:active { transform: scale(.98); }
.btn--primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-soft) 100%);
  color: #fff;
}
.btn--ghost {
  background: transparent;
  color: var(--ink-soft);
}

/* settings */
.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 4px;
  border-bottom: 1px solid var(--line);
}
.settings-row:last-of-type { border-bottom: none; }
.seg {
  display: flex;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}
.seg-btn {
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
}
.seg-btn.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-1);
}

.switch { position: relative; width: 44px; height: 26px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  inset: 0;
  background: var(--surface-2);
  border-radius: 999px;
  transition: background var(--dur) var(--ease);
}
.slider::before {
  content: "";
  position: absolute;
  left: 3px;
  top: 3px;
  width: 20px;
  height: 20px;
  background: var(--ink);
  border-radius: 50%;
  transition: transform var(--dur) var(--ease);
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(18px); background: #fff; }

/* stats */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}
.stat {
  background: var(--surface-2);
  border-radius: 12px;
  padding: 14px;
  text-align: center;
}
.stat-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -0.02em;
}
.stat-label {
  font-size: 12px;
  color: var(--ink-soft);
  margin-top: 4px;
}

/* Lessons list */
.screen-sub {
  margin: -14px 4px 18px;
  color: var(--ink-soft);
  font-size: 14px;
}
.progress-bar {
  height: 6px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  margin: 0 4px 18px;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-soft));
  border-radius: 999px;
  transition: width var(--dur) var(--ease);
}
.lessons-list {
  display: grid;
  gap: 10px;
}
.lesson-row {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: center;
  gap: 14px;
  text-align: left;
  transition: transform var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.lesson-row:hover { border-color: var(--accent); }
.lesson-row:active { transform: scale(.985); }
.lesson-row[disabled] { opacity: .45; cursor: not-allowed; }
.lesson-num {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  color: var(--ink-soft);
  font-weight: 700;
  font-size: 14px;
}
.lesson-row.done .lesson-num {
  background: var(--win);
  color: #fff;
}
.lesson-row.current .lesson-num {
  background: var(--accent);
  color: #fff;
}
.lesson-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.lesson-title { font-size: 15px; font-weight: 650; color: var(--ink); }
.lesson-sub { font-size: 12px; color: var(--ink-soft); }
.lesson-check {
  color: var(--ink-mute);
  font-size: 18px;
}
.lesson-row.done .lesson-check { color: var(--win); }

/* Lesson intro card inside game screen */
.lesson-intro {
  display: none;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  margin: 2px 0 4px;
}
.lesson-intro.active { display: block; }
.lesson-concept {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--accent);
}
.lesson-text {
  margin: 6px 0 0;
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
}

/* Analysis screen */
.analysis-summary {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin: 0 4px 18px;
}
.analysis-pill {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 4px;
  text-align: center;
}
.analysis-pill .pill-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
}
.analysis-pill .pill-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  margin-top: 2px;
}
.analysis-pill.c-excellent .pill-value { color: var(--win); }
.analysis-pill.c-good .pill-value { color: var(--ink); }
.analysis-pill.c-inaccurate .pill-value { color: var(--gold); }
.analysis-pill.c-mistake .pill-value { color: var(--accent); }
.analysis-pill.c-blunder .pill-value { color: var(--danger); }

.analysis-critical {
  margin: 0 4px 22px;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  border-left: 4px solid var(--accent);
}
.analysis-critical.empty {
  border-left-color: var(--win);
}
.critical-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  font-weight: 700;
}
.analysis-critical.empty .critical-label { color: var(--win); }
.critical-title {
  font-size: 16px;
  font-weight: 650;
  margin: 6px 0 4px;
  color: var(--ink);
}
.critical-text {
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.5;
  margin: 0 0 12px;
}
.critical-actions {
  display: flex;
  gap: 8px;
}

.analysis-heading {
  margin: 0 4px 10px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
}
.analysis-list {
  display: grid;
  gap: 6px;
  padding: 0 4px 24px;
}
.analysis-move {
  display: grid;
  grid-template-columns: 32px 28px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 13px;
}
.move-idx { color: var(--ink-mute); font-weight: 600; text-align: right; }
.move-stone {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.move-stone.b { background: var(--stone-black); }
.move-stone.w { background: var(--stone-white); }
.move-coord { color: var(--ink); font-family: monospace; font-size: 13px; }
.move-tag {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.move-tag.c-excellent { background: rgba(47, 143, 95, .18); color: var(--win); }
.move-tag.c-good { background: var(--surface-2); color: var(--ink-soft); }
.move-tag.c-inaccurate { background: rgba(201, 162, 74, .2); color: var(--gold); }
.move-tag.c-mistake { background: rgba(184, 82, 59, .2); color: var(--accent); }
.move-tag.c-blunder { background: rgba(194, 74, 58, .25); color: var(--danger); }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 40px;
  transform: translate(-50%, 30px);
  background: var(--ink);
  color: var(--bg);
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: transform var(--dur) var(--ease), opacity var(--dur) var(--ease);
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,.2);
}
.toast.active {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* Replay bar */
.replay-bar {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 6px 4px;
}
.replay-bar.active { display: flex; }
.replay-btn {
  width: 42px;
  height: 42px;
}
.replay-btn--primary {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-soft) 100%);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
}
.replay-close {
  margin-left: 4px;
}

/* Welcome tips */
.welcome-tips {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 6px 0 10px;
}
.tip {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface-2);
  border-radius: 12px;
  font-size: 14px;
  color: var(--ink);
}
.tip-dot {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

/* Screen display fix - non-home screens default hidden */
#screen-difficulty, #screen-game, #screen-lessons, #screen-analysis { display: none; }
#screen-difficulty.active, #screen-game.active, #screen-lessons.active, #screen-analysis.active { display: flex; }
