/* ============================================================
   Cờ Tướng (Xiangqi) — 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: 64px;              /* distance between two adjacent lines */
  --margin: 36px;            /* padding from board edge to outer line */
  --board-w: calc(8 * var(--cell) + 2 * var(--margin)); /* 9 files -> 8 gaps */
  --board-h: calc(9 * var(--cell) + 2 * var(--margin)); /* 10 ranks -> 9 gaps */

  --wood: #e9c081;
  --wood-edge: #b07c3f;
  --line: #5b3a1a;
  --river: #cf9b54;

  --red: #b3322c;
  --black: #1c1c1c;
  --red-soft: #f3d9d2;
  --black-soft: #d8d8d8;

  --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: 56px;
  letter-spacing: 1px;
  margin: 0;
  color: #f4c150;
  text-shadow: 0 2px 0 #0b1220, 0 0 26px rgba(244, 193, 80, 0.22);
}
.tagline {
  font-family: "Poppins", sans-serif;
  font-weight: 300;
  color: var(--muted);
  margin: 6px 0 0;
  letter-spacing: 2px;
  text-transform: uppercase;
  font-size: 12px;
}

/* ---------- 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, #f0c98c, #e2b16a);
  padding: 14px;
  border-radius: 14px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45), inset 0 0 0 2px var(--wood-edge);
}
.board-wrap {
  position: relative;
  width: var(--board-w);
  height: var(--board-h);
  background:
    repeating-linear-gradient(0deg, transparent 0 22px, rgba(176,124,63,0.05) 22px 23px),
    var(--wood);
  border-radius: 8px;
  box-shadow: inset 0 0 0 2px var(--wood-edge);
}
.board-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.piece-layer {
  position: absolute;
  inset: 0;
}

/* ---------- Pieces ---------- */
.piece {
  position: absolute;
  width: calc(var(--cell) * 0.86);
  height: calc(var(--cell) * 0.86);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Averia Serif Libre", "Noto Serif SC", serif;
  font-weight: 700;
  font-size: calc(var(--cell) * 0.46);
  cursor: pointer;
  user-select: none;
  box-sizing: border-box;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  background-color: #7a5a2e;
  background-image: radial-gradient(circle at 35% 28%,
    rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0) 42%, rgba(0, 0, 0, 0.22));
  border: 3px solid transparent;
  box-shadow: 0 3px 5px rgba(0, 0, 0, 0.4);
  transition: transform 0.08s ease, box-shadow 0.12s ease;
}
.piece:hover { transform: translate(-50%, -50%) scale(1.05); }
/* Side ring: red = your side (gold), black = opponent (dark) */
.piece.red   { border-color: #ffd87a; }
.piece.black { border-color: #0c1320; }
/* Piece type → disc colour (your side: bright) */
.piece.pt-K { background-color: #c0392b; } /* General  */
.piece.pt-A { background-color: #8e44ad; } /* Advisor  */
.piece.pt-E { background-color: #117a65; } /* Elephant */
.piece.pt-H { background-color: #c87f0a; } /* Horse    */
.piece.pt-R { background-color: #2563eb; } /* Chariot  */
.piece.pt-C { background-color: #d6336c; } /* Cannon   */
.piece.pt-S { background-color: #2f9e44; } /* Soldier  */
/* Opponent side: darker, slightly greyed version of the same hue */
.piece.black.pt-K { background-color: #5e2a24; } /* General  */
.piece.black.pt-A { background-color: #482a57; } /* Advisor  */
.piece.black.pt-E { background-color: #103e35; } /* Elephant */
.piece.black.pt-H { background-color: #6a4413; } /* Horse    */
.piece.black.pt-R { background-color: #1d3a6b; } /* Chariot  */
.piece.black.pt-C { background-color: #6b2841; } /* Cannon   */
.piece.black.pt-S { background-color: #235230; } /* Soldier  */
.piece.selected {
  box-shadow: 0 0 0 3px #f5d98a, 0 4px 9px rgba(0, 0, 0, 0.5);
}
.piece.in-check {
  animation: check-pulse 0.9s ease-in-out infinite;
}
@keyframes check-pulse {
  0%, 100% { box-shadow: 0 0 0 2px #e0463f, 0 3px 5px rgba(0,0,0,0.4); }
  50%      { box-shadow: 0 0 0 6px rgba(224,70,63,0.6), 0 3px 5px rgba(0,0,0,0.4); }
}

/* ---------- 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(40, 90, 50, 0.55);
  box-shadow: 0 0 6px rgba(40, 90, 50, 0.5);
}
.move-marker.capture {
  width: calc(var(--cell) * 0.78);
  height: calc(var(--cell) * 0.78);
  border-radius: 50%;
  border: 3px solid rgba(179, 50, 44, 0.85);
  box-sizing: border-box;
}
.move-marker:hover { filter: brightness(1.25); }

/* ---------- Last move highlight (e.g. the AI's reply) ---------- */
.last-move {
  position: absolute;
  width: calc(var(--cell) * 0.92);
  height: calc(var(--cell) * 0.92);
  transform: translate(-50%, -50%);
  border-radius: 8px;
  pointer-events: none;
  box-sizing: border-box;
  z-index: 0;
}
.last-move.from {
  background: rgba(245, 217, 138, 0.16);
  border: 2px dashed rgba(245, 217, 138, 0.6);
}
.last-move.to {
  background: rgba(245, 217, 138, 0.28);
  border: 2px solid #f5d98a;
  animation: lastmove-pulse 1.1s ease-in-out 3;
}
@keyframes lastmove-pulse {
  0%, 100% { box-shadow: 0 0 6px rgba(245, 217, 138, 0.35); }
  50%      { box-shadow: 0 0 20px rgba(245, 217, 138, 0.9); }
}

/* ---------- Side panel ---------- */
.side-panel {
  width: 260px;
  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%;
  background: var(--red);
  box-shadow: 0 0 10px var(--red);
}

/* ---------- Controls ---------- */
.controls {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.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); }
.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;
}

/* ---------- Tournament ---------- */
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.45; cursor: default; filter: none; }
.tn-entry { display: flex; gap: 6px; margin-bottom: 8px; }
.tn-entry input {
  flex: 1;
  min-width: 0;
  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;
}
.tn-actions { display: flex; gap: 6px; margin-bottom: 10px; }
.tn-actions .btn { flex: 1; }
.tn-body { font-size: 13px; color: var(--text); }
.tn-match, .tn-next {
  background: rgba(245, 217, 138, 0.08);
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 8px;
}
.tn-body .red   { color: #e89a92; }
.tn-body .black { color: #d8d8d8; }
.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; }
.tn-body #tn-go { width: 100%; margin-bottom: 8px; }

/* ---------- Capture trays (flank the board) ---------- */
.cap-tray {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  min-height: 34px;
  max-width: 600px;
  margin: 0 auto;
  padding: 5px 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-family: "Poppins", sans-serif;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-right: 4px;
}
.cap-top::before    { content: "Black captured"; }
.cap-bottom::before { content: "Red captured"; }
.cap-pc {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: "Averia Serif Libre", "Noto Serif SC", serif;
  font-weight: 700;
  font-size: 15px;
  color: #fff;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.5);
  border: 2px solid transparent;
  background-color: #7a5a2e;
  background-image: radial-gradient(circle at 35% 28%,
    rgba(255, 255, 255, 0.45), rgba(255, 255, 255, 0) 45%, rgba(0, 0, 0, 0.2));
}
.cap-pc.red   { border-color: #ffd87a; }
.cap-pc.black { border-color: #0c1320; }
.cap-pc.pt-K { background-color: #c0392b; }
.cap-pc.pt-A { background-color: #8e44ad; }
.cap-pc.pt-E { background-color: #117a65; }
.cap-pc.pt-H { background-color: #c87f0a; }
.cap-pc.pt-R { background-color: #2563eb; }
.cap-pc.pt-C { background-color: #d6336c; }
.cap-pc.pt-S { background-color: #2f9e44; }
.cap-pc.black.pt-K { background-color: #5e2a24; }
.cap-pc.black.pt-A { background-color: #482a57; }
.cap-pc.black.pt-E { background-color: #103e35; }
.cap-pc.black.pt-H { background-color: #6a4413; }
.cap-pc.black.pt-R { background-color: #1d3a6b; }
.cap-pc.black.pt-C { background-color: #6b2841; }
.cap-pc.black.pt-S { background-color: #235230; }

.move-log {
  margin: 0;
  padding-left: 22px;
  max-height: 260px;
  overflow-y: auto;
  font-family: "Poppins", monospace;
  font-size: 13px;
  color: var(--muted);
}
.move-log li { margin: 2px 0; }
.move-log li.log-red   { color: #e89a92; }
.move-log li.log-black { color: #d8d8d8; }

/* ---------- Help button + 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: 640px;
  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 { color: var(--text); font-size: 14px; line-height: 1.55; margin: 6px 0; }
.help-pieces { margin: 6px 0; padding-left: 0; list-style: none; }
.help-pieces li { color: var(--text); font-size: 14px; line-height: 1.5; margin: 6px 0; }
.help-piece {
  font-family: "Averia Serif Libre", "Noto Serif SC", serif;
  font-weight: 700;
  color: var(--black);
}
.help-piece.red { color: var(--red); }
.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; }

/* ---------- How-each-piece-moves guide (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; }
.mg-other { display: inline-block; width: 12px; height: 12px; border-radius: 50%; background: #cfd6e2; border: 1px solid #9aa6bb; vertical-align: -2px; }
.mg-block { display: inline-block; width: 9px; height: 9px; border-radius: 50%; border: 1px solid #8a6a3a; vertical-align: -1px; }
.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-disc { width: 26px; height: 26px; border-radius: 50%; background: #f0dcb4; border: 2px solid #b9914f; display: flex; align-items: center; justify-content: center; font-weight: 700; color: #b3322c; font-family: "Averia Serif Libre", serif; }
.mg-name { font-size: 14px; font-weight: 600; color: var(--text); }
.mg-cap { font-size: 12px; color: var(--muted); margin: 8px 0 0; line-height: 1.5; }

@media (max-width: 720px) {
  :root { --cell: 38px; --margin: 22px; }
  .logo { font-size: 40px; }
  .help-card { padding: 20px 18px; }
}
