/* Xiangqi analysis — dark theme with gold accents (Road of Knowledge) */
:root {
  --bg: #161512;
  --panel: #262421;
  --panel-2: #302e2c;
  --text: #bababa;
  --bright: #f0f0f0;
  --muted: #7a776f;
  --accent: #d4a537;
  --accent-2: #b8891f;
  --accent-rgb: 212, 165, 55;
  --red: #e05a4f;
  --topbar-bg: #21201d;
  --topbar-border: #3c3935;
  --border: #3c3935;
  --input-bg: #1b1a18;
  --board-w: min(calc((100vh - 150px) * 0.8875), calc(100vw - 420px), 600px);
  --radius: 8px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { font-family: "Noto Sans", "Segoe UI", Roboto, Arial, sans-serif; font-size: 14px; }
button, input, select, textarea { font: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

/* topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 18px; background: var(--topbar-bg); border-bottom: 1px solid var(--topbar-border);
  position: relative; z-index: 50;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; overflow: hidden; }
.logo-piece {
  display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: 50%;
  background: #f3e3c3; color: #b3261e; border: 2px solid var(--accent); font-size: 19px; font-weight: 700; flex-shrink: 0;
  font-family: KaiTi, STKaiti, "Kaiti SC", "Noto Serif CJK SC", "Source Han Serif SC", "Microsoft YaHei", serif;
}
.brand h1 { margin: 0; font-size: 18px; color: var(--bright); font-weight: 700; letter-spacing: .02em; white-space: nowrap; }
.tag { margin: 0; font-size: 11px; color: var(--muted); }
.top-actions { display: flex; align-items: center; gap: 10px; }
.inline { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.inline.tight { gap: 4px; }
select {
  background: var(--panel-2); color: var(--bright); border: 1px solid #4a4742; border-radius: 4px; padding: 2px 6px;
}

.btn {
  background: var(--panel-2); border: 1px solid #4a4742; color: var(--bright);
  padding: 6px 10px; border-radius: 5px; cursor: pointer; font-size: 13px; line-height: 1.2;
  touch-action: manipulation; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent-2); border-color: var(--accent); color: #1a1408; font-weight: 700; }
.btn.primary:hover { background: var(--accent); }
.btn-icon { padding: 4px 9px; font-size: 16px; }

.settings-wrap { position: relative; }
.settings-panel {
  position: absolute; right: 0; top: calc(100% + 6px); width: 300px; z-index: 60;
  background: var(--panel); border: 1px solid #4a4742; border-radius: var(--radius); padding: 10px 12px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, .5);
}
.settings-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 5px 0; font-size: 13px; color: var(--bright); cursor: default; }
.settings-row input { accent-color: var(--accent); margin: 0; }
.settings-label { color: var(--muted); min-width: 70px; }
.settings-panel .inline { color: var(--bright); }
.settings-hint { margin: 8px 0 0; font-size: 11px; color: var(--muted); line-height: 1.4; }

/* layout */
.layout {
  display: grid; grid-template-columns: var(--board-w) minmax(280px, 1fr);
  gap: 16px; padding: 16px 18px 24px; align-items: start; max-width: 1180px; margin: 0 auto;
}
.board-col { width: var(--board-w); }
.board-wrap { width: 100%; user-select: none; -webkit-user-select: none; }
.board-tools { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.status { margin-top: 8px; font-size: 13px; color: var(--muted); min-height: 1.3em; }
.status.in-check { color: var(--red); font-weight: 700; }

.side-col { display: flex; flex-direction: column; gap: 12px; min-width: 0; max-height: calc(var(--board-w) * 1.127 + 60px); }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; min-width: 0; }
.panel.grow { flex: 1 1 auto; min-height: 140px; display: flex; flex-direction: column; }
.panel-h {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 8px;
}
#engine-meta { text-transform: none; letter-spacing: 0; }
.eval-badge { font-size: 15px; font-weight: 700; color: var(--bright); text-transform: none; letter-spacing: 0; font-variant-numeric: tabular-nums; }
.eval-badge.pos, .score.pos { color: #f08a7e; }
.eval-badge.neg, .score.neg { color: #d8d8d8; }

.lines { display: flex; flex-direction: column; gap: 2px; min-height: 64px; }
.line { display: flex; gap: 8px; padding: 4px 6px; border-radius: 4px; cursor: pointer; font-size: 13px; align-items: baseline; }
.line:hover { background: var(--panel-2); }
.line .score { font-weight: 700; color: var(--bright); min-width: 50px; font-variant-numeric: tabular-nums; flex-shrink: 0; }
.line .score.pos { color: #f08a7e; }
.line .pv { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.line .num { color: var(--muted); }
.pvmv:hover { color: var(--accent); }

.moves { flex: 1 1 auto; overflow-y: auto; line-height: 1.9; font-size: 13.5px; min-height: 80px; max-height: 340px; }
.moves .num { color: var(--muted); margin-right: 2px; }
.moves .san { display: inline-block; padding: 0 5px; border-radius: 3px; cursor: pointer; color: var(--bright); line-height: 1.5; }
.moves .san:hover { background: var(--panel-2); }
.moves .san.active { background: var(--accent); color: #1a1408; font-weight: 700; }
.moves .var { color: var(--muted); }
.moves .var .san { color: var(--text); }
.moves .var .san.active { color: #1a1408; }
.notation-help { margin-top: 8px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); padding-top: 6px; }
.notation-help summary { cursor: pointer; color: var(--accent); }
.notation-help p { margin: 6px 0; line-height: 1.45; }
.notation-help code { color: var(--bright); background: var(--input-bg); padding: 0 3px; border-radius: 3px; }

textarea, .fen {
  width: 100%; background: var(--input-bg); border: 1px solid var(--border); border-radius: 4px;
  padding: 7px 8px; color: var(--text); font-family: ui-monospace, Consolas, monospace; font-size: 12px;
}
textarea { resize: vertical; }
.row { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; align-items: center; }
.fen { margin-top: 2px; }

/* board SVG */
.xq-board { display: block; width: 100%; height: auto; touch-action: none; }
.board-bg { fill: #dcb57a; }
.board-frame { fill: none; stroke: #6b4423; stroke-width: 3; }
.board-lines { fill: none; stroke: #5a3a1c; stroke-width: 1.6; stroke-linecap: square; }
.river { fill: #6b4423; font-size: 26px; text-anchor: middle; dominant-baseline: central; opacity: .8;
  font-family: KaiTi, STKaiti, "Kaiti SC", "Noto Serif CJK SC", "Source Han Serif SC", SimSun, "Microsoft YaHei", serif; letter-spacing: 8px; }
.coord { fill: #6b4423; font-size: 14px; text-anchor: middle; font-family: Arial, sans-serif; font-weight: 700; }
[data-board="dark"] .board-bg { fill: #2b2823; }
[data-board="dark"] .board-frame { stroke: var(--accent-2); }
[data-board="dark"] .board-lines { stroke: #a8865a; }
[data-board="dark"] .river, [data-board="dark"] .coord { fill: #b89a6a; }

.pc { cursor: grab; }
.pc.dragging { cursor: grabbing; filter: drop-shadow(0 6px 6px rgba(0, 0, 0, .45)); }
.pc-bg { fill: #f6e7c8; stroke: #8a6a3e; stroke-width: 2; filter: drop-shadow(0 2px 1.5px rgba(0, 0, 0, .45)); }
.pc-ring { fill: none; stroke-width: 1.6; }
.pc-red .pc-ring { stroke: #b3261e; }
.pc-black .pc-ring { stroke: #222; }
.pc-txt { font-size: 30px; font-weight: 700; text-anchor: middle; pointer-events: none;
  font-family: KaiTi, STKaiti, "Kaiti SC", "Noto Serif CJK SC", "Source Han Serif SC", "Noto Sans CJK SC", SimSun, "Microsoft YaHei", "PingFang SC", serif; }
.pc-letter { font-family: Arial, Helvetica, sans-serif; font-size: 27px; }
.pc-red .pc-txt { fill: #b3261e; }
.pc-black .pc-txt { fill: #1d1d1d; }
.marks, .hints, .arrows { pointer-events: none; }
.mark-last { fill: rgba(var(--accent-rgb), .28); stroke: rgba(var(--accent-rgb), .9); stroke-width: 2; }
.mark-from { fill: rgba(var(--accent-rgb), .14); stroke-dasharray: 5 4; }
.mark-sel { fill: none; stroke: #2f9e44; stroke-width: 4; }
.hint-dot { fill: rgba(47, 158, 68, .75); }
.hint-cap { fill: none; stroke: rgba(47, 158, 68, .85); stroke-width: 5; }
.arrow { stroke: #2f80c9; stroke-linecap: round; }
.arrow.best { stroke: #2f80c9; }
.arrow.alt { stroke: #5aa0d8; }
.arrow-head { fill: #2f80c9; }

/* modal / setup */
.modal { position: fixed; inset: 0; z-index: 300; background: rgba(0, 0, 0, .6); display: flex; align-items: center; justify-content: center; padding: 12px; }
.modal-card { background: var(--panel); border: 1px solid #4a4742; border-radius: 10px; padding: 16px 18px; max-height: 96vh; overflow: auto; color: var(--bright); }
.setup-card { width: min(980px, 100%); }
.setup-header h2 { margin: 0 0 2px; font-size: 18px; color: var(--accent); }
.setup-header p { margin: 0 0 10px; font-size: 12px; }
.setup-body { display: grid; grid-template-columns: minmax(0, 440px) minmax(260px, 1fr); gap: 16px; align-items: start; }
.setup-controls { min-width: 0; }
.palette { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-bottom: 8px; }
.pal { aspect-ratio: 1; padding: 3px; border-radius: 8px; background: var(--panel-2); border: 2px solid transparent; cursor: pointer; }
.pal svg { width: 100%; height: 100%; display: block; }
.pal.on { border-color: var(--accent); background: rgba(var(--accent-rgb), .18); }
.pal-erase { color: var(--bright); font-size: 20px; grid-column: span 1; }
.setup-side input, .setup-actions input { accent-color: var(--accent); }
.setup-fen-label { display: block; margin-top: 6px; }
.setup-error { color: var(--red); font-size: 13px; margin: 6px 0; }
.setup-actions { justify-content: flex-end; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 400;
  background: var(--panel-2); color: var(--bright); border: 1px solid var(--accent); border-radius: 6px; padding: 8px 14px; font-size: 13px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .5); max-width: 90vw;
}

/* site hamburger navigation (same pattern as the chess apps, gold accent) */
.site-menu-btn {
  appearance: none; display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 32px; padding: 0; border-radius: 6px; cursor: pointer; flex-shrink: 0;
  border: 1px solid var(--topbar-border); background: rgba(128, 128, 128, .08);
  color: var(--bright); touch-action: manipulation;
}
.site-menu-btn:hover { border-color: var(--accent); background: rgba(var(--accent-rgb), .14); }
.site-menu-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.site-menu-btn[aria-expanded="true"] { border-color: var(--accent); color: var(--accent); }
.site-menu { position: fixed; inset: 0; z-index: 200; pointer-events: none; }
.site-menu.is-open { pointer-events: auto; }
.site-menu[hidden] { display: none !important; }
.site-menu-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.5); opacity: 0; transition: opacity 0.18s ease; }
.site-menu.is-open .site-menu-backdrop { opacity: 1; }
.site-menu-panel {
  position: absolute; top: 0; right: 0; width: min(300px, 88vw); height: 100%; max-height: 100dvh;
  overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 0.15rem;
  padding: 0.9rem 0.7rem 1.4rem; background: var(--topbar-bg); border-left: 1px solid var(--topbar-border);
  box-shadow: -12px 0 32px rgba(0, 0, 0, 0.45); transform: translateX(100%); transition: transform 0.2s ease; color: var(--bright);
}
.site-menu.is-open .site-menu-panel { transform: none; }
.site-menu-section {
  margin: 0.75rem 0.5rem 0.3rem; padding-top: 0.5rem; border-top: 1px solid var(--topbar-border);
  color: var(--muted); font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
}
.site-menu-link { display: block; padding: 0.65rem 0.8rem; border-radius: 8px; color: var(--bright); font-weight: 600; font-size: 0.95rem; text-decoration: none; line-height: 1.25; }
.site-menu-link:hover { background: rgba(128, 128, 128, .12); text-decoration: none; }
.site-menu-link.is-current, .site-menu-link[aria-current="page"] { background: rgba(var(--accent-rgb), .18); color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
html.site-menu-open { overflow: hidden; }

/* responsive */
@media (max-width: 860px) {
  :root { --board-w: min(100vw, calc((100vh - 110px) * 0.8875), 600px); }
  .layout { grid-template-columns: 1fr; padding: 0 0 20px; gap: 8px; justify-items: center; }
  .board-col { width: var(--board-w); }
  .board-tools, .status { padding: 0 8px; }
  .board-tools .btn { flex: 1 0 auto; padding: 8px 8px; }
  .side-col { width: 100%; max-width: 640px; max-height: none; padding: 0 8px; }
  .moves { max-height: 220px; }
  .setup-body { grid-template-columns: 1fr; }
  .setup-board { max-width: 420px; margin: 0 auto; }
}
@media (max-width: 520px) {
  :root { --board-w: 100vw; }
  .topbar { padding: 6px 8px; gap: 6px; }
  .brand h1 { font-size: 15px; }
  .brand h1 .hide-sm { display: none; }
  .tag { display: none; }
  .logo-piece { width: 28px; height: 28px; font-size: 16px; }
  .top-actions { gap: 6px; }
  .top-actions .inline { font-size: 12px; }
  .btn { padding: 5px 8px; }
  .site-menu-btn { width: 32px; height: 30px; }
  .site-menu-btn svg { width: 18px; height: 18px; }
  .settings-panel { position: fixed; right: 8px; left: 8px; width: auto; top: 50px; }
  .modal-card { padding: 12px; }
  .palette { gap: 4px; }
}
