/* ============================================================
   Cờ Vây (Go / Weiqi) — Visual layout
   Fonts: Grenze (logo), Averia Serif Libre (headings), Poppins (body)
   Stone size and line spacing are set on #board-wrap by board.js
   as --stone and --gocell, since they depend on the board size.
   ============================================================ */

:root {
  --wood: #e0ab63;
  --wood-2: #d09a52;
  --wood-edge: #8a5a24;

  --bg: #0f1726;
  --panel: #18233b;
  --panel-line: rgba(255,255,255,0.08);
  --text: #e8eef9;
  --muted: #93a3c0;
  --accent: #10b981;
  --gold: #f4c150;
  --field: #0f1726;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Poppins", system-ui, sans-serif;
  font-weight: 300;
  color: var(--text);
  background: radial-gradient(1200px 600px at 50% -10%, #16213a 0%, var(--bg) 60%);
  min-height: 100vh;
}

/* ---------- Header ---------- */
.app-header { text-align: center; padding: 28px 16px 12px; }
.logo {
  font-family: "Grenze", serif;
  font-weight: 700;
  font-size: 52px;
  letter-spacing: 1px;
  margin: 0;
  color: var(--gold);
  text-shadow: 0 2px 0 #0b1220, 0 0 26px rgba(244, 193, 80, 0.22);
}
.tagline { color: var(--muted); margin: 6px 0 0; letter-spacing: 2px; text-transform: uppercase; font-size: 12px; }
.back-link { color: #f5d98a; font-size: 13px; text-decoration: none; }
.back-link:hover { text-decoration: underline; }

/* ---------- Layout ---------- */
.app-main {
  display: flex;
  gap: 28px;
  justify-content: center;
  align-items: flex-start;
  padding: 18px 16px 48px;
  flex-wrap: wrap;
}

/* ---------- Board ---------- */
.board-panel {
  background: linear-gradient(160deg, #6b4520, #4a2f14);
  padding: 12px;
  border-radius: 14px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5), inset 0 0 0 2px var(--wood-edge);
}
.board-wrap {
  position: relative;
  border-radius: 5px;
  cursor: pointer;
  background:
    repeating-linear-gradient(93deg, rgba(138,90,36,0.10) 0 3px, transparent 3px 11px),
    linear-gradient(160deg, var(--wood), var(--wood-2));
  box-shadow: inset 0 0 22px rgba(90,55,15,0.35);
}
.board-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.stone-layer { position: absolute; inset: 0; pointer-events: none; }

/* ---------- Stones ---------- */
.stone {
  position: absolute;
  width: var(--stone, 40px);
  height: var(--stone, 40px);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.45);
}
.stone.black {
  background: radial-gradient(circle at 33% 28%, #6d7480 0%, #2b2f36 38%, #101216 100%);
}
.stone.white {
  background: radial-gradient(circle at 33% 28%, #ffffff 0%, #f0ece2 45%, #c8c2b4 100%);
}
/* The most recent stone carries a small dot, as reviewers mark diagrams. */
.stone.last::after {
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  width: 30%; height: 30%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #e23b3b;
}
.stone.ghost { opacity: 0.42; box-shadow: none; }
/* Stones marked dead during scoring fade out and get a cross. */
.stone.dead { opacity: 0.32; }
.stone.dead::before {
  content: "✕";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--stone, 40px) * 0.6);
  color: #b3322c;
  font-weight: 700;
}

/* ---------- Territory overlay (scoring) ---------- */
.territory {
  position: absolute;
  width: calc(var(--stone, 40px) * 0.42);
  height: calc(var(--stone, 40px) * 0.42);
  transform: translate(-50%, -50%);
  border-radius: 2px;
}
.territory.t-black { background: rgba(20, 22, 26, 0.72); }
.territory.t-white { background: rgba(255, 255, 255, 0.82); }

/* ---------- Flash message ---------- */
.flash {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%) translateY(20px);
  background: #2a1b1b;
  border: 1px solid #b3322c;
  color: #ffd9d5;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 70;
  max-width: 92vw;
  text-align: center;
}
.flash.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Side panel ---------- */
.side-panel {
  width: 272px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 14px;
  padding: 18px 20px 24px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.4);
}
.panel-title {
  font-family: "Averia Serif Libre", serif;
  font-weight: 700;
  font-size: 16px;
  color: #f5d98a;
  margin: 18px 0 10px;
  border-bottom: 1px solid var(--panel-line);
  padding-bottom: 6px;
}
.panel-title:first-child { margin-top: 0; }

.turn-indicator { display: flex; align-items: center; gap: 10px; font-weight: 500; font-size: 15px; }
.turn-dot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.turn-dot.b { background: radial-gradient(circle at 33% 28%, #6d7480, #101216); }
.turn-dot.w { background: radial-gradient(circle at 33% 28%, #fff, #c8c2b4); }

.stat-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--muted);
  margin-top: 8px;
  gap: 8px;
}
.stat-row span { display: flex; align-items: center; gap: 5px; }
.stat-row b { color: var(--text); font-weight: 500; }
.stat-row i { flex: none; }
.muted { color: var(--muted); }

/* ---------- Controls ---------- */
.controls { margin-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.btn-row { display: flex; gap: 6px; }
.btn-row .btn { flex: 1; }
.btn {
  font-family: "Poppins", sans-serif;
  font-weight: 600;
  font-size: 14px;
  color: #06281e;
  background: var(--accent);
  border: none;
  border-radius: 11px;
  padding: 9px 14px;
  cursor: pointer;
  transition: filter 0.12s ease, transform 0.06s ease;
}
.btn:hover { filter: brightness(1.07); }
.btn:active { transform: scale(0.985); }
.btn:disabled { opacity: 0.45; cursor: default; filter: none; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--panel-line); }
.btn-ghost:hover { color: #f5d98a; border-color: #f5d98a; }
.ctl { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.ctl select, .ctl input[type="number"] {
  margin-left: auto;
  width: 92px;
  background: var(--field);
  color: var(--text);
  border: 1px solid var(--panel-line);
  border-radius: 6px;
  padding: 3px 6px;
  font-family: "Poppins", sans-serif;
}
.ai-status { font-size: 12px; color: #f5d98a; min-height: 16px; font-style: italic; }
.note { font-size: 11.5px; color: var(--muted); line-height: 1.5; font-style: italic; }

/* ---------- Scoring panel ---------- */
.scoring-panel {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid rgba(244,193,80,0.35);
  background: rgba(244,193,80,0.07);
  border-radius: 10px;
}
.score-line { font-size: 15px; margin-bottom: 8px; font-family: "Averia Serif Libre", serif; }
.score-hint { font-size: 12px; color: var(--muted); margin-bottom: 10px; line-height: 1.5; }
.legend { display: flex; gap: 14px; font-size: 11.5px; color: var(--muted); margin-bottom: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: -1px; margin-right: 4px; }
.legend i.b { background: rgba(20,22,26,0.8); }
.legend i.w { background: rgba(255,255,255,0.85); }

/* ---------- Online ---------- */
.tn-entry { display: flex; gap: 6px; margin-bottom: 8px; }
.tn-entry input, #ol-name {
  flex: 1;
  min-width: 0;
  width: 100%;
  background: var(--field);
  color: var(--text);
  border: 1px solid var(--panel-line);
  border-radius: 6px;
  padding: 6px 8px;
  font-family: "Poppins", sans-serif;
  font-size: 13px;
  margin-bottom: 8px;
}
.tn-actions { display: flex; gap: 6px; margin-bottom: 10px; }
.tn-actions .btn { flex: 1; }
.tn-body { font-size: 13px; }
.tn-result { font-family: "Averia Serif Libre", serif; font-size: 15px; color: #f5d98a; margin-bottom: 6px; }
.tn-king { color: #ffcf6b; font-weight: 500; margin-bottom: 8px; }
.tn-sub { color: var(--muted); margin: 6px 0 4px; font-size: 12px; }
.tn-hint { color: var(--muted); font-style: italic; font-size: 12px; }
.tn-queue { margin: 0 0 8px; padding-left: 22px; max-height: 140px; overflow-y: auto; }
.tn-queue li { margin: 2px 0; }

/* ---------- Move log ---------- */
.move-log {
  margin: 0; padding-left: 0; list-style: none;
  max-height: 220px; overflow-y: auto; font-size: 13px;
}
.move-log li {
  display: flex; align-items: center; gap: 7px;
  padding: 2px 4px; border-radius: 4px;
}
.move-log li:nth-child(odd) { background: rgba(255,255,255,0.03); }
.mv-no { color: var(--muted); min-width: 30px; }
.mv-dot { width: 11px; height: 11px; border-radius: 50%; flex: none; }
.mv-dot.b { background: radial-gradient(circle at 33% 28%, #6d7480, #101216); }
.mv-dot.w { background: radial-gradient(circle at 33% 28%, #fff, #c8c2b4); }
.mv-cap { color: #e89a92; font-size: 12px; margin-left: auto; }

/* ---------- Help modal ---------- */
.help-btn { margin-top: 12px; }
.help-overlay {
  position: fixed; inset: 0;
  background: rgba(10, 6, 3, 0.72);
  display: none; align-items: center; justify-content: center;
  z-index: 50; padding: 24px;
}
.help-overlay.open { display: flex; }
.help-card {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 14px;
  max-width: 680px; width: 100%;
  max-height: 86vh; overflow-y: auto;
  padding: 26px 30px 24px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
}
.help-card h2 { font-family: "Averia Serif Libre", serif; color: #f5d98a; margin: 0 36px 6px 0; font-size: 22px; }
.help-card h3 { font-family: "Averia Serif Libre", serif; color: #f5d98a; font-size: 15px; margin: 18px 0 6px; }
.help-card p { font-size: 14px; line-height: 1.55; margin: 6px 0; }
.help-card b { color: #f3e6d3; }
.help-card ol, .help-card ul { font-size: 14px; line-height: 1.6; padding-left: 20px; }
.help-close {
  position: absolute; top: 14px; right: 16px;
  background: transparent; border: none; color: var(--muted);
  font-size: 28px; line-height: 1; cursor: pointer; padding: 0 6px;
}
.help-close:hover { color: #f5d98a; }
.help-actions { text-align: right; margin-top: 20px; }

/* ---------- Diagram tiles in the help modal ---------- */
.move-guide { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin: 8px 0 14px; }
.mg-tile { background: rgba(255,255,255,0.03); border: 1px solid var(--panel-line); border-radius: 10px; padding: 10px; }
.mg-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.mg-name { font-size: 14px; font-weight: 600; }
.mg-cap { font-size: 12px; color: var(--muted); margin: 8px 0 0; line-height: 1.5; }

@media (max-width: 900px) {
  .app-main { gap: 18px; }
  .side-panel { width: min(100%, 420px); }
}
@media (max-width: 720px) {
  .logo { font-size: 36px; }
  .help-card { padding: 20px 18px; }
  .btn { padding: 11px 14px; }
  .btn-sm { padding: 9px 12px; }
  .board-panel { padding: 8px; }
}
