/* ============================================================
   Cờ Caro (Gomoku) — Visual layout
   Fonts: Grenze (logo), Averia Serif Libre (headings), Poppins (body)
   The square size is set on #board-wrap by board.js as --cell and
   --mark, because it depends on the board size.

   The board is a sheet of graph paper rather than a wooden goban:
   caro is a pen-and-paper game, and the arcade already has a Go
   board, so the two never get mistaken for each other at a glance.
   ============================================================ */

:root {
  --paper: #fbfaf3;
  --paper-edge: #cfd8e4;

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

  --ink-x: #1c4fd0;   /* blue biro */
  --ink-o: #d1382f;   /* red biro */
}

* { 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, #26354f, #16203a);
  padding: 12px;
  border-radius: 14px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5), inset 0 0 0 1px rgba(255,255,255,0.06);
  max-width: 100%;
}
.board-wrap {
  position: relative;
  border-radius: 4px;
  cursor: pointer;
  background: var(--paper);
  box-shadow: inset 0 0 30px rgba(150,170,195,0.22), 0 1px 0 rgba(255,255,255,0.3);
  max-width: 100%;
}
.board-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.mark-layer { position: absolute; inset: 0; pointer-events: none; }

/* ---------- Marks ---------- */
.mark {
  position: absolute;
  width: var(--mark, 22px);
  height: var(--mark, 22px);
  transform: translate(-50%, -50%);
}
/* X is two crossing pen strokes. */
.mark.x::before, .mark.x::after {
  content: "";
  position: absolute;
  left: 50%; top: 50%;
  width: 100%;
  height: 17%;
  min-height: 2px;
  border-radius: 2px;
  background: var(--ink-x);
}
.mark.x::before { transform: translate(-50%, -50%) rotate(45deg); }
.mark.x::after  { transform: translate(-50%, -50%) rotate(-45deg); }
/* O is a ring, not a disc — so the square underneath still reads as paper. */
.mark.o {
  border: max(2px, calc(var(--mark, 22px) * 0.17)) solid var(--ink-o);
  border-radius: 50%;
}
/* The most recent mark glows, so you can always find the reply you're answering. */
.mark.last { filter: drop-shadow(0 0 5px rgba(244, 160, 40, 0.95)); }
.mark.ghost { opacity: 0.34; }
.mark.win {
  filter: drop-shadow(0 0 7px rgba(255, 190, 30, 1));
  animation: mark-pop 0.45s ease-out;
}
@keyframes mark-pop {
  0%   { transform: translate(-50%, -50%) scale(1); }
  45%  { transform: translate(-50%, -50%) scale(1.28); }
  100% { transform: translate(-50%, -50%) scale(1); }
}

/* The stroke through the winning five, drawn the way you would on paper. */
.win-line {
  position: absolute;
  height: 5px;
  border-radius: 3px;
  background: rgba(232, 116, 30, 0.85);
  box-shadow: 0 0 10px rgba(255, 170, 40, 0.7);
  pointer-events: none;
  animation: line-in 0.35s ease-out;
}
@keyframes line-in { from { opacity: 0; } to { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .mark.win, .win-line { animation: none; }
}

/* ---------- 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: 15px; height: 15px; flex: none;
  position: relative;
}
.turn-dot.x::before, .turn-dot.x::after {
  content: ""; position: absolute; left: 50%; top: 50%;
  width: 100%; height: 3px; border-radius: 2px; background: #6f9dff;
}
.turn-dot.x::before { transform: translate(-50%,-50%) rotate(45deg); }
.turn-dot.x::after  { transform: translate(-50%,-50%) rotate(-45deg); }
.turn-dot.o { border: 3px solid #ff7a70; border-radius: 50%; }

.result {
  margin-top: 10px;
  font-family: "Averia Serif Libre", serif;
  font-size: 15px;
  color: #ffdf95;
  min-height: 0;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.result.show {
  opacity: 1;
  padding: 9px 11px;
  border: 1px solid rgba(244,193,80,0.4);
  background: rgba(244,193,80,0.09);
  border-radius: 9px;
}

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

/* ---------- 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 {
  margin-left: auto;
  width: 148px;
  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; }

/* ---------- 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: 12px; height: 12px; flex: none; position: relative; }
.mv-dot.x::before, .mv-dot.x::after {
  content: ""; position: absolute; left: 50%; top: 50%;
  width: 100%; height: 2.5px; border-radius: 2px; background: #6f9dff;
}
.mv-dot.x::before { transform: translate(-50%,-50%) rotate(45deg); }
.mv-dot.x::after  { transform: translate(-50%,-50%) rotate(-45deg); }
.mv-dot.o { border: 2.5px solid #ff7a70; border-radius: 50%; }

/* ---------- Help modal ---------- */
.help-btn { margin-top: 12px; }
.help-overlay {
  position: fixed; inset: 0;
  background: rgba(6, 10, 18, 0.74);
  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-card li { margin: 3px 0; }
.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(230px, 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; }
}
