/* Fairy-Stockfish analysis — dark Road of Knowledge theme */
: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)), calc(100vw - 420px), 560px);
  --radius: 8px;
  /* Board square scheme (default: slightly brightened dark for mobile clarity) */
  --sq-light: #3a3530;
  --sq-dark: #2a2621;
  --sq-shogi-light: #4a4234;
  --sq-shogi-dark: #3a3328;
  --sq-river: #2e3a32;
  --board-fill: #22201c;
  --coord-fill: #c4a87a;
}
[data-board="dark"] {
  --sq-light: #3a3530;
  --sq-dark: #2a2621;
  --sq-shogi-light: #4a4234;
  --sq-shogi-dark: #3a3328;
  --sq-river: #2e3a32;
  --board-fill: #22201c;
  --coord-fill: #c4a87a;
}
[data-board="green"] {
  --sq-light: #eeeed2;
  --sq-dark: #769656;
  --sq-shogi-light: #f2efd0;
  --sq-shogi-dark: #6b8f4e;
  --sq-river: #c5d6a8;
  --board-fill: #5a7a42;
  --coord-fill: #e8e4c0;
}
[data-board="blue"] {
  --sq-light: #eceff1;
  --sq-dark: #6d8a96;
  --sq-shogi-light: #e8eef2;
  --sq-shogi-dark: #5f7d8a;
  --sq-river: #b7c9d2;
  --board-fill: #4e6874;
  --coord-fill: #dce4e8;
}
[data-board="classic"] {
  --sq-light: #f0d9b5;
  --sq-dark: #b58863;
  --sq-shogi-light: #f3dfc0;
  --sq-shogi-dark: #a67a52;
  --sq-river: #d4c49a;
  --board-fill: #8b6644;
  --coord-fill: #f5e6c8;
}
[data-board="brown"] {
  --sq-light: #e3c29f;
  --sq-dark: #8b5a2b;
  --sq-shogi-light: #e8c9a6;
  --sq-shogi-dark: #7a4e24;
  --sq-river: #c9a878;
  --board-fill: #6b4420;
  --coord-fill: #edd4b0;
}
[data-board="gray"] {
  --sq-light: #d8d8d8;
  --sq-dark: #8a8a8a;
  --sq-shogi-light: #e0e0e0;
  --sq-shogi-dark: #7a7a7a;
  --sq-river: #b8c0b8;
  --board-fill: #5a5a5a;
  --coord-fill: #e8e8e8;
}
* { 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); }
code { font-family: ui-monospace, Consolas, monospace; font-size: 0.92em; color: var(--bright); }

.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: #302e2c; color: var(--accent); border: 2px solid var(--accent); font-size: 18px; flex-shrink: 0;
}
.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; flex-wrap: wrap; justify-content: flex-end; }
.inline { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.inline.tight { gap: 4px; color: var(--bright); }
select {
  background: var(--panel-2); color: var(--bright); border: 1px solid #4a4742; border-radius: 4px; padding: 2px 6px;
  max-width: 140px;
}
.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: 320px; 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); }
.settings-row input { accent-color: var(--accent); margin: 0; }
.settings-label { color: var(--muted); min-width: 70px; }
.settings-hint { margin: 8px 0 0; font-size: 11px; color: var(--muted); line-height: 1.4; }

.engine-banner {
  margin: 0; padding: 10px 18px; background: #3a2218; border-bottom: 1px solid #6b3a2a;
  color: #f0c0a8; font-size: 13px; line-height: 1.45;
}
.engine-banner strong { color: #ffb89a; margin-right: 6px; }

.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; }
/* Hands / pockets (crazyhouse, shogi, placement, …) */
.layout.has-hands { --board-w: min(calc(100vh - 250px), calc(100vw - 420px), 560px); }
.hand {
  display: flex; align-items: center; flex-wrap: wrap; gap: 4px; min-height: 46px; padding: 3px 8px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); user-select: none; -webkit-user-select: none;
}
.hand-top { margin-bottom: 6px; }
.hand-bottom { margin-top: 6px; }
.hand-label { font-size: 12px; color: var(--muted); min-width: 52px; margin-right: 4px; }
.hand-label.to-move { color: var(--accent); font-weight: 700; }
.hand-empty { color: var(--muted); font-size: 13px; }
.hand-pc {
  position: relative; width: 40px; height: 40px; padding: 0; border: 2px solid transparent; border-radius: 8px;
  background: transparent; cursor: default; touch-action: none; opacity: .75;
}
.hand-pc.can-drop { cursor: grab; opacity: 1; }
.hand-pc.can-drop:hover { border-color: rgba(var(--accent-rgb), .6); }
.hand-pc.selected { border-color: #2f9e44; background: rgba(47, 158, 68, .18); }
.hand-svg { width: 100%; height: 100%; display: block; pointer-events: none; }
.hand-svg .pc-txt { font-size: 22px; }
.hand-cnt {
  position: absolute; right: -4px; bottom: -4px; min-width: 17px; height: 17px; padding: 0 3px; border-radius: 9px;
  background: var(--accent); color: #1a1408; font-size: 11px; font-weight: 700; line-height: 17px; text-align: center; pointer-events: none;
}
.hand-ghost { position: fixed; z-index: 500; width: 48px; height: 48px; margin: -24px 0 0 -24px; pointer-events: none; opacity: .9; }
.hand-ghost .hand-svg .pc-txt { font-size: 22px; }
.drop-ring { stroke: #2f80c9; }
.drop-ghost { font-size: 24px; font-weight: 700; fill: #2f80c9; font-family: "Segoe UI Symbol", "Noto Sans CJK SC", serif; }

.side-col { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.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; user-select: none; -webkit-user-select: none; }
.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 .pv { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.line .num { color: var(--muted); }

.moves { flex: 1 1 auto; overflow-y: auto; line-height: 1.9; font-size: 13.5px; min-height: 80px; max-height: 340px; font-family: ui-monospace, Consolas, monospace; }
.moves .num { color: var(--muted); margin-right: 2px; font-family: inherit; }
.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 .san.future { color: var(--muted, #8a8a8a); opacity: .75; }

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; }

/* SVG board — colors from data-board scheme */
.fairy-board { display: block; width: 100%; height: auto; touch-action: none; }
.board-bg { fill: var(--board-fill); }
.board-frame { fill: none; stroke: var(--accent-2); stroke-width: 2; }
.sq.light { fill: var(--sq-light); }
.sq.dark { fill: var(--sq-dark); }
.sq.shogi-sq.light { fill: var(--sq-shogi-light); }
.sq.shogi-sq.dark { fill: var(--sq-shogi-dark); }
.sq.river-row { fill: var(--sq-river); }
.sq.river-bank { fill: var(--sq-river); }
.river-band { fill: var(--board-fill); }
.river-line { stroke: var(--accent-2); stroke-width: 2.25; fill: none; }
.river-label {
  fill: var(--coord-fill); font-size: 12px; font-weight: 700;
  font-family: "Noto Sans CJK SC", "Microsoft YaHei", KaiTi, "Segoe UI Symbol", serif;
  opacity: .9; pointer-events: none;
}
.palace-line { stroke: var(--accent-2); stroke-width: 1.75; fill: none; opacity: .85; }
.coord { fill: var(--coord-fill); font-size: 12px; font-family: Arial, sans-serif; font-weight: 700; }

.pc { cursor: pointer; }
.pc-bg { fill: #f6e7c8; stroke: #8a6a3e; stroke-width: 2; filter: drop-shadow(0 2px 1.5px rgba(0, 0, 0, .45)); }
.pc-black .pc-bg { fill: #d8d0c0; }
.pc-txt {
  font-size: 26px; font-weight: 700; pointer-events: none;
  font-family: "Segoe UI Symbol", "Noto Sans CJK SC", "Noto Serif CJK JP", KaiTi, "Microsoft YaHei", serif;
}
.pc-white .pc-txt { fill: #1d1d1d; }
.pc-black .pc-txt { fill: #1d1d1d; }
.pc-black .pc-bg { stroke: #444; }
.pc.promoted .pc-bg { stroke: var(--accent); stroke-width: 2.5; }

.marks, .hints, .arrows { pointer-events: none; }
.mark-last { fill: rgba(var(--accent-rgb), .28); }
.mark-from { fill: rgba(var(--accent-rgb), .14); }
.mark-sel { fill: none; stroke: #2f9e44; stroke-width: 4; }
.mark-check { fill: rgba(224, 90, 79, .35); }
.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; }

.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-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; }

@media (max-width: 860px) {
  :root { --board-w: min(100vw, calc(100vh - 110px), 560px); }
  .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; }
  .layout.has-hands { --board-w: min(100vw, calc(100vh - 210px), 560px); }
  .hand { border-radius: 0; border-left: 0; border-right: 0; min-height: 40px; }
  .hand-pc { width: 36px; height: 36px; }
  .board-tools .btn { flex: 1 0 auto; padding: 8px 8px; }
  .side-col { width: 100%; max-width: 640px; padding: 0 8px; }
  .moves { max-height: 220px; }
}
@media (max-width: 520px) {
  :root { --board-w: 100vw; }
  .topbar { padding: 6px 8px; gap: 6px; align-items: flex-start; }
  .brand {
    flex-direction: column; align-items: center; gap: 2px;
    flex: 0 0 auto; max-width: 72px;
  }
  .logo-piece { width: 28px; height: 28px; font-size: 15px; }
  .brand-text { text-align: center; min-width: 0; width: 100%; }
  .brand h1 {
    font-size: 9px; line-height: 1.15; font-weight: 700;
    white-space: normal; letter-spacing: 0;
  }
  .brand h1 .hide-sm { display: none; }
  .tag { display: none; }
  .top-actions { gap: 6px; flex: 1; min-width: 0; }
  .top-actions .inline { font-size: 12px; }
  .btn { padding: 5px 8px; }
  .site-menu-btn { width: 32px; height: 30px; }
  .settings-panel { position: fixed; right: 8px; left: 8px; width: auto; top: 50px; }
  select { max-width: 110px; }
}

/* Variant about / SEO footer (also mirrored inline in index.html for first paint) */
.seo-about {
  max-width: 1180px;
  width: 100%;
  box-sizing: border-box;
  margin: 0 auto;
  padding: 14px 18px 22px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.6;
}
.seo-about h2 {
  margin: 0 0 6px;
  font-size: 14px;
  font-weight: 700;
  color: var(--bright);
  letter-spacing: 0.01em;
}
.seo-about p { margin: 0 0 6px; max-width: 920px; }
.seo-about .seo-extra { margin-top: 8px; opacity: 0.95; }
.seo-about a { color: var(--accent); }


/* Set up position editor */
.setup-panel {
  padding: 10px 12px; background: var(--panel); border: 1px solid var(--accent-2);
  border-radius: var(--radius); display: flex; flex-direction: column; gap: 8px;
}
.setup-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; color: var(--bright); font-size: 14px; }
.setup-head .muted { font-size: 12px; }
.setup-pal { display: flex; flex-wrap: wrap; align-items: center; gap: 3px; user-select: none; -webkit-user-select: none; }
.setup-pal .hand-label { min-width: 52px; }
.setup-pc {
  width: 40px; height: 40px; padding: 0; border: 2px solid transparent; border-radius: 8px;
  background: var(--panel-2); cursor: grab; touch-action: none;
}
.setup-pc:hover { border-color: rgba(var(--accent-rgb), .6); }
.setup-pc.selected { border-color: #2f9e44; background: rgba(47, 158, 68, .22); }
.setup-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.setup-row .inline.tight { font-size: 13px; }
.setup-row .inline.disabled { opacity: .45; }
.setup-row input[type="radio"], .setup-row input[type="checkbox"] { accent-color: var(--accent); margin: 0; }
.setup-label { color: var(--muted); font-size: 12px; min-width: 58px; }
.setup-tool.selected { border-color: #2f9e44; background: rgba(47, 158, 68, .22); }
.setup-ep {
  width: 46px; background: var(--input-bg); color: var(--bright); border: 1px solid var(--border);
  border-radius: 4px; padding: 2px 5px; font-family: ui-monospace, Consolas, monospace; font-size: 12px;
}
.setup-error {
  background: #3a2218; border: 1px solid #6b3a2a; color: #ffb89a; border-radius: 5px; padding: 6px 9px; font-size: 13px;
}
.setup-hint { margin: 0; font-size: 11.5px; color: var(--muted); line-height: 1.45; }
.setup-hand-item {
  display: inline-flex; align-items: center; gap: 2px; padding: 1px 4px 1px 1px; border-radius: 6px; background: var(--panel-2);
}
.setup-hand-item.zero .setup-hand-glyph { opacity: .45; }
.setup-hand-glyph { width: 32px; height: 32px; display: inline-block; }
.setup-hand-btn {
  width: 22px; height: 22px; padding: 0; border-radius: 4px; border: 1px solid #4a4742; background: var(--bg);
  color: var(--bright); font-size: 14px; line-height: 1; cursor: pointer; touch-action: manipulation;
}
.setup-hand-btn:hover { border-color: var(--accent); }
.setup-hand-cnt { min-width: 16px; text-align: center; font-weight: 700; color: var(--bright); font-variant-numeric: tabular-nums; font-size: 13px; }
.layout.setup-mode .board-tools .btn:not(#btn-flip) { display: none; }
.layout.setup-mode .fairy-board .pc { cursor: grab; }
.layout.setup-mode .side-col > .panel { display: none; }
@media (max-width: 860px) {
  .setup-pc { width: 36px; height: 36px; }
  .layout.setup-mode .board-tools .btn { flex: 0 0 auto; }
}
