/* ============================================================
   Cờ Vua (International Chess) — Visual layout
   Fonts: Grenze (logo), Averia Serif Libre (headings), Poppins (body)
   Board geometry is driven by --cell; board.js reads the same value.
   ============================================================ */

:root {
  --cell: 66px;              /* one square */
  --margin: 22px;            /* coordinate gutter around the squares */
  --board-w: calc(8 * var(--cell) + 2 * var(--margin));

  --sq-light: #ecd9b6;
  --sq-dark: #b58863;
  --wood-edge: #7a5a2e;
  --coord: #8b7355;

  --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, #3a2a17, #241a0f);
  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;
  width: var(--board-w);
  height: var(--board-w);
  border-radius: 6px;
}
.board-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.piece-layer { position: absolute; inset: 0; }

/* ---------- Pieces ---------- */
/* Both sides use the SOLID glyph set — the outline set renders inconsistently
   across platforms. Fill and stroke separate the colours instead. */
.piece {
  position: absolute;
  width: calc(var(--cell) * 0.92);
  height: calc(var(--cell) * 0.92);
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell) * 0.74);
  line-height: 1;
  cursor: pointer;
  user-select: none;
  transition: transform 0.08s ease;
  z-index: 2;
}
.piece:hover { transform: translate(-50%, -50%) scale(1.06); }
.piece.white {
  color: #fdfaf3;
  text-shadow:
    0 0 1px #2b2118, 1px 0 1px #2b2118, -1px 0 1px #2b2118,
    0 1px 1px #2b2118, 0 -1px 1px #2b2118, 0 3px 4px rgba(0,0,0,0.45);
}
.piece.black {
  color: #22252c;
  text-shadow:
    0 0 1px rgba(255,255,255,0.75), 1px 0 1px rgba(255,255,255,0.4),
    -1px 0 1px rgba(255,255,255,0.4), 0 3px 4px rgba(0,0,0,0.45);
}
.piece.selected {
  filter: drop-shadow(0 0 7px #f5d98a) drop-shadow(0 0 3px #f5d98a);
}
.piece.in-check { animation: check-pulse 0.9s ease-in-out infinite; }
@keyframes check-pulse {
  0%, 100% { filter: drop-shadow(0 0 3px #e0463f); }
  50%      { filter: drop-shadow(0 0 12px #e0463f) drop-shadow(0 0 6px #e0463f); }
}

/* ---------- Move markers ---------- */
.move-marker { position: absolute; transform: translate(-50%, -50%); cursor: pointer; z-index: 5; }
.move-marker.quiet {
  width: calc(var(--cell) * 0.30);
  height: calc(var(--cell) * 0.30);
  border-radius: 50%;
  background: rgba(30, 90, 45, 0.55);
  box-shadow: 0 0 6px rgba(30, 90, 45, 0.5);
}
.move-marker.capture {
  width: calc(var(--cell) * 0.88);
  height: calc(var(--cell) * 0.88);
  border-radius: 50%;
  border: 4px solid rgba(179, 50, 44, 0.8);
}
.move-marker.castle {
  width: calc(var(--cell) * 0.46);
  height: calc(var(--cell) * 0.46);
  border-radius: 6px;
  background: rgba(244, 193, 80, 0.35);
  border: 2px solid rgba(244, 193, 80, 0.85);
}
.move-marker:hover { filter: brightness(1.3); }

/* ---------- Last move ---------- */
.last-move {
  position: absolute;
  width: var(--cell);
  height: var(--cell);
  transform: translate(-50%, -50%);
  pointer-events: none;
  z-index: 1;
}
.last-move.from { background: rgba(245, 217, 138, 0.22); }
.last-move.to   { background: rgba(245, 217, 138, 0.38); }

/* ---------- Side panel ---------- */
.side-panel {
  width: 268px;
  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%; border: 1px solid #0b1220; }
.turn-dot.w { background: #fdfaf3; box-shadow: 0 0 10px rgba(255,255,255,0.5); }
.turn-dot.b { background: #22252c; box-shadow: 0 0 10px rgba(0,0,0,0.6); }

/* ---------- 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; color: var(--text); }
.ctl select {
  margin-left: auto;
  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; }

/* ---------- Online / ladder ---------- */
.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; }

/* ---------- Capture trays ---------- */
.cap-tray {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  min-height: 32px;
  padding: 4px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--panel-line);
}
.cap-top { margin-bottom: 8px; }
.cap-bottom { margin-top: 8px; }
.cap-tray::before {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-right: 6px;
  content: "Captured";
}
.cap-pc { font-size: 20px; line-height: 1; }
.cap-pc.white { color: #fdfaf3; text-shadow: 0 0 1px #2b2118, 0 1px 1px #2b2118; }
.cap-pc.black { color: #22252c; text-shadow: 0 0 1px rgba(255,255,255,0.7); }

/* ---------- Move log ---------- */
.move-log {
  margin: 0;
  padding-left: 0;
  list-style: none;
  max-height: 240px;
  overflow-y: auto;
  font-size: 13px;
}
.move-log li {
  margin: 1px 0;
  padding: 2px 4px;
  border-radius: 4px;
  display: flex;
  gap: 8px;
}
.move-log li:nth-child(odd) { background: rgba(255,255,255,0.03); }
.mv-no { color: var(--muted); min-width: 26px; }
.mv-w { color: #f0f4ff; min-width: 62px; }
.mv-b { color: #b9c6dd; }

/* ---------- Promotion picker ---------- */
.promo-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 6, 3, 0.72);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 24px;
}
.promo-overlay.open { display: flex; }
.promo-card {
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 14px;
  padding: 22px 26px;
  text-align: center;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
}
.promo-card h3 { font-family: "Averia Serif Libre", serif; color: #f5d98a; margin: 0 0 14px; }
.promo-choices { display: flex; gap: 10px; }
.promo-pick {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--panel-line);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  font-family: "Poppins", sans-serif;
}
.promo-pick:hover { border-color: #f5d98a; background: rgba(245,217,138,0.12); }
.promo-glyph { font-size: 34px; line-height: 1; }
.promo-pick.white .promo-glyph { color: #fdfaf3; text-shadow: 0 0 1px #2b2118, 0 1px 2px #2b2118; }
.promo-pick.black .promo-glyph { color: #22252c; text-shadow: 0 0 1px rgba(255,255,255,0.7); }
.promo-name { font-size: 11px; color: var(--muted); }

/* ---------- 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: 660px;
  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-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; }

/* ---------- Move guide tiles (help modal) ---------- */
.mg-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin: 6px 0 12px; }
.mg-dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; background: #2f9e44; vertical-align: -1px; }
.mg-ring { display: inline-block; width: 13px; height: 13px; border-radius: 50%; border: 2px solid #b3322c; vertical-align: -2px; }
.move-guide { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 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-glyph { font-size: 24px; line-height: 1; color: #fdfaf3; text-shadow: 0 0 1px #2b2118, 0 1px 2px #2b2118; }
.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) {
  :root { --cell: 40px; --margin: 16px; }
  .logo { font-size: 36px; }
  .help-card { padding: 20px 18px; }
  .btn { padding: 11px 14px; }        /* comfortable tap targets */
  .btn-sm { padding: 9px 12px; }
}
