/* Entry point — imports all style modules for the Taikyoku Shogi Web GUI *//* Design tokens — Taikyoku Shogi Web GUI */

:root {
  color-scheme: dark;
  --bg: #1a1a2e;
  --bg-panel: #16213e;
  --bg-deep: #0a0a1a;
  --border: #0f3460;
  --accent: #f0526c; /* 4.6:1 on --bg-panel (WCAG AA for bold headings) */
  --accent-2: #4a90d9;
  --text: #e0e0e0;
  --muted: #8a8fa8;
  --ok: #5cb85c;
  --warn: #e8b84a;
  --err: #d9534f;
  --focus: #ffd700;
  --button-bg: #13294b;
  --button-fg: var(--text);
  --accent-fg: #08131d;
}

/* Manual light theme, or automatic when the OS prefers light and the user
   has not forced a theme. Only tokens change; no root font-size override. */
/* Warm parchment scheme inspired by the ATSA play frontend. */
html[data-theme='parchment'] {
  color-scheme: light;
  --bg: #efe9d8;
  --bg-panel: #faf7ef;
  --bg-deep: #e6dfcc;
  --border: #c9c2b0;
  --accent: #2f5d50;
  --accent-2: #3578c5;
  --text: #272822;
  --muted: #6a6356;
  --focus: #c47a2c;
  --button-bg: #e6dfcc;
  --button-fg: #272822;
  --accent-fg: #ffffff;
}

html[data-theme='light'] {
  color-scheme: light;
  --bg: #f4f5f8;
  --bg-panel: #ffffff;
  --bg-deep: #e8eaf0;
  --border: #c8cedb;
  --accent: #c0223c;
  --accent-2: #1668b0;
  --text: #1b2030;
  --muted: #5a6070;
  --focus: #a86000;
  --button-bg: #e3e7ef;
  --button-fg: #1b2030;
  --accent-fg: #ffffff;
}
@media (prefers-color-scheme: light) {
  html:not([data-theme]) {
    color-scheme: light;
    --bg: #f4f5f8;
    --bg-panel: #ffffff;
    --bg-deep: #e8eaf0;
    --border: #c8cedb;
    --accent: #c0223c;
    --accent-2: #1668b0;
    --text: #1b2030;
    --muted: #5a6070;
    --focus: #a86000;
    --button-bg: #e3e7ef;
    --button-fg: #1b2030;
    --accent-fg: #ffffff;
  }
}

/* Extra built-in page schemes. A custom theme maps to one of these schemes
   through its `scheme` field, so imported themes never need to ship CSS. */
html[data-theme='midnight'] {
  color-scheme: dark;
  --bg: #0b1020;
  --bg-panel: #141c34;
  --bg-deep: #070b16;
  --border: #2b3a63;
  --accent: #ffd166;
  --accent-2: #7aa2f7;
  --text: #dce3f5;
  --muted: #8a99bd;
  --focus: #ffd166;
  --button-bg: #1a2542;
  --button-fg: #dce3f5;
  --accent-fg: #0b1020;
}

html[data-theme='forest'] {
  color-scheme: dark;
  --bg: #101c14;
  --bg-panel: #172a1d;
  --bg-deep: #0a120c;
  --border: #2f5137;
  --accent: #f2c14e;
  --accent-2: #7ee081;
  --text: #e4efdf;
  --muted: #8ba482;
  --focus: #f2c14e;
  --button-bg: #1f3525;
  --button-fg: #e4efdf;
  --accent-fg: #101c14;
}

html[data-theme='crimson'] {
  color-scheme: dark;
  --bg: #23131a;
  --bg-panel: #331b25;
  --bg-deep: #160b10;
  --border: #5c2c3a;
  --accent: #ff9f68;
  --accent-2: #e07a8f;
  --text: #f5e3e5;
  --muted: #a88b83;
  --focus: #ffd166;
  --button-bg: #3d202b;
  --button-fg: #f5e3e5;
  --accent-fg: #23131a;
}

html[data-theme='solar'] {
  color-scheme: light;
  --bg: #fdf3dc;
  --bg-panel: #fffaf0;
  --bg-deep: #f0e2c0;
  --border: #d8bd82;
  --accent: #c47a2c;
  --accent-2: #3a8fb7;
  --text: #4a3510;
  --muted: #7a6640;
  --focus: #c47a2c;
  --button-bg: #f0e2c0;
  --button-fg: #4a3510;
  --accent-fg: #ffffff;
}

/* Reset & base — Taikyoku Shogi Web GUI */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  height: 100%;
}

/* The document itself is the scroll container. Do NOT give body a fixed
   height + overflow of its own: that creates a nested scroller that swallows
   touch gestures starting on the canvas. */
body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100%;
  overflow: auto;
  touch-action: manipulation;
}

/* Desktop: fixed viewport height so the flex child (canvas) keeps its natural
   width instead of being squeezed. Mobile overrides this below. */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh; /* fallback */
  height: 100dvh;
  overflow: auto;
}

.main {
  overflow: auto;
}

/* Desktop: let the page scroll when the board is taller/wider than the
   viewport, instead of cutting off content. Mobile keeps overflow: visible
   so the whole document scrolls. */
@media (min-width: 901px) {
  .app {
    overflow: auto;
  }
}

/* Skip link */
.skip-link {
  position: absolute;
  left: -9999px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
  z-index: 1000;
}

.skip-link:focus {
  position: fixed;
  top: 8px;
  left: 8px;
  width: auto;
  height: auto;
  padding: 6px 12px;
  background: var(--accent);
  color: #000;
  font-weight: bold;
  border-radius: 4px;
  z-index: 1000;
}

/* Focus indicator — keep the visible ring on all interactive controls. */
:where(a:any-link, button, select, input, textarea, canvas[tabindex]):focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

/* Screen-reader-only text that stays in the accessibility tree. */
.visually-hidden:where(:not(:focus-within, :active)) {
  position: absolute !important;
  clip-path: inset(50%) !important;
  overflow: hidden !important;
  width: 1px !important;
  height: 1px !important;
  margin: -1px !important;
  padding: 0 !important;
  border: 0 !important;
  white-space: nowrap !important;
}

/* Comfortable pointer targets (larger on touch devices). */
:root { --target-size: 24px; }
@media (pointer: coarse) {
  :root { --target-size: 44px; }
}
:where(button, select, textarea, input:not([type='checkbox'], [type='radio'])) {
  min-block-size: var(--target-size);
}
:where(.toolbar, nav) { flex-wrap: wrap; }

@media (prefers-reduced-motion: no-preference) {
  :where(button, select, input) { transition: background-color 120ms ease, border-color 120ms ease; }
}

/* Avoid orphaned single words in short headings; harmless where unsupported. */
:where(h1, h2, h3) { text-wrap: balance; }
:where(p, li) { text-wrap: pretty; }
/* Layout — Taikyoku Shogi Web GUI */

header.header {
  background: var(--bg-panel);
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 2px solid var(--border);
  flex-wrap: wrap;
  row-gap: 6px;
}

header.header h1 {
  font-size: 16px;
  color: var(--accent);
  white-space: nowrap;
  letter-spacing: 0.4px;
}

header.header h1 small {
  color: var(--muted);
  font-size: 10px;
  font-weight: 400;
  margin-left: 6px;
}

/* Toolbar */
.toolbar {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.toolbar label {
  font-size: 11px;
  color: var(--muted);
}

.toolbar select,
.toolbar button,
.panel button {
  padding: 6px 10px;
  min-inline-size: 24px;
  min-block-size: 24px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 11px;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.toolbar button,
.panel button {
  background: var(--button-bg);
  color: var(--button-fg);
}

.toolbar button:hover,
.panel button:hover {
  background: var(--accent);
  border-color: var(--accent);
}

.toolbar button[aria-disabled='true'],
.panel button[aria-disabled='true'] {
  opacity: 0.45;
  cursor: not-allowed;
  background: var(--button-bg);
}

.toolbar button[aria-pressed='true'],
.toolbar button:hover,
.panel button:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}

/* Zoom */
.zoom {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--muted);
}

.zoom input {
  width: 90px;
  accent-color: var(--accent);
}

/* Status bar */
.status-bar {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 11px;
  color: var(--muted);
}

#busy {
  color: var(--warn);
  min-width: 0;
}

/* Main shell */
.main {
  flex: 1;
  display: flex;
  gap: 10px;
  padding: 10px;
  min-height: 0;
  justify-content: center;
}

.board-wrap {
  display: flex;
  align-items: stretch;
  flex: 0 1 auto;
  overflow: auto;
  border: 2px solid var(--border);
  background: var(--bg-deep);
  border-radius: 4px;
  min-width: 0;
}

.board-stack {
  position: relative;
  width: fit-content;
}

.board-stack canvas {
  display: block;
}

/* Keep native two-dimensional panning/scrolling available on the board at all
   times. Dragging is armed explicitly (long-press on touch) and only then do
   we preventDefault on touchmove, so swiping over the board still scrolls. */
#board-canvas {
  touch-action: pan-x pan-y;
  -webkit-user-select: none;
  user-select: none;
}

/* Annotation layer sits exactly over the base board and never eats clicks. */
#board-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

aside.sidebar {
  width: 310px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
  overflow-y: auto;
  padding-right: 2px;
}

/* Evaluation bar: a vertical balance meter beside the board (Chess.com style).
   White fills from the top, Black from the bottom; the marker sits at zero. */
.eval-bar {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 0 0 20px;
  inline-size: 20px;
  border-inline-start: 1px solid var(--border);
  background: var(--bg-panel);
  overflow: hidden;
}

.eval-bar.side-left {
  order: -1;
  border-inline-start: 0;
  border-inline-end: 1px solid var(--border);
}

.eval-bar[hidden] {
  display: none;
}

.eval-bar.flipped {
  flex-direction: column-reverse;
}

.eval-bar-black,
.eval-bar-white {
  inline-size: 100%;
  transition: block-size 180ms ease;
}

.eval-bar-black {
  background: #1b1b1f;
  border-block-start: 2px solid var(--focus);
}

.eval-bar-white {
  background: #f0f0f5;
}

.eval-bar-label {
  position: absolute;
  inset-block-start: 50%;
  inset-inline-start: 50%;
  transform: translate(-50%, -50%);
  font-size: 9px;
  font-weight: 700;
  color: var(--text);
  background: var(--bg-panel);
  padding: 1px 2px;
  border-radius: 3px;
  pointer-events: none;
}

/* Components — Taikyoku Shogi Web GUI */

/* Panels */
.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  flex-shrink: 0;
}

.panel h2 {
  font-size: 10px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 5px;
}

/* Info rows */
.info-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  padding: 2px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.info-row:last-child {
  border-bottom: 0;
}

.info-row .label {
  color: var(--muted);
}

.info-row .value {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* Status message */
.status-msg {
  font-size: 11px;
  margin-top: 5px;
  min-height: 14px;
  word-break: break-word;
}

.status-msg.info {
  color: var(--accent-2);
}

.status-msg.success {
  color: var(--ok);
}

.status-msg.error {
  color: var(--err);
}

/* Engine grid */
.engine-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 10px;
}

.engine-grid .info-row {
  font-size: 10px;
}

.engine-note {
  font-size: 9px;
  color: var(--muted);
  margin-top: 5px;
}

/* Score chart */
#score-chart {
  width: 100%;
  height: 64px;
  display: block;
  background: var(--bg-deep);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 4px;
}

/* Move log */
.move-log {
  max-height: 170px;
  overflow-y: auto;
  font-size: 10px;
  font-family: ui-monospace, monospace;
  background: var(--bg-deep);
  border-radius: 4px;
  padding: 3px 0;
}

.move-log .entry {
  padding: 1px 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.move-log .entry:nth-child(odd) {
  background: rgba(255, 255, 255, 0.02);
}

.move-log .entry:last-child {
  color: var(--warn);
}

.move-log .entry.empty {
  color: var(--muted);
  font-style: italic;
}

/* Enlarged piece preview in the inspector */
.inspect-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0;
}
.inspect-preview canvas {
  width: 72px;
  height: 72px;
  flex: 0 0 72px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.25);
}

/* Header repo link: same shape as the toolbar buttons, no extra noise. */
.repo-link {
  display: inline-flex;
  align-items: center;
  padding: 5px 9px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--button-bg);
  color: var(--button-fg);
  font-size: 11px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.repo-link:hover,
.repo-link:focus-visible {
  border-color: var(--accent-2);
  color: var(--accent-2);
}

/* About text stays in the DOM for crawlers but is collapsed by default. */
.about-panel summary {
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-2);
  padding-block: 2px;
}
.about-body {
  font-size: 10px;
  line-height: 1.45;
  color: var(--muted);
}
.about-body p { margin: 5px 0 0; }
.about-body ul { margin: 5px 0 0; padding-inline-start: 18px; }
.about-body a { color: var(--accent-2); }

/* One compact line, no extra blocks. */
.site-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-block-start: 6px;
  padding-block-start: 5px;
  border-block-start: 1px solid var(--border);
  font-size: 10px;
  color: var(--muted);
}
.site-footer a { color: var(--accent-2); text-decoration: none; }
.site-footer a:hover,
.site-footer a:focus-visible { text-decoration: underline; }

/* Game library + search tree */
.games-panel search { display: flex; align-items: center; gap: 6px; margin-block: 4px; }
.games-panel input[type='search'],
.games-panel input[type='text'] {
  font: inherit;
  font-size: max(1rem, 0.8em);
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 3px 6px;
  min-inline-size: 0;
  flex: 1;
}
.games-panel select { inline-size: 100%; font: inherit; font-size: max(1rem, 0.8em); }
.search-tree { max-block-size: 12rem; overflow: auto; font-size: 10px; }
.search-tree details { margin-inline-start: 8px; }
.search-tree summary { cursor: pointer; padding-block: 1px; }
.search-tree .tag { color: var(--ok); font-weight: 700; }
.search-tree .score { color: var(--accent-2); }

/* Analysis + review panels */
.analysis-head {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.analysis-head h2 { margin: 0; margin-inline-end: auto; font-size: 13px; }
.analysis-status, .analysis-pv {
  margin: 6px 0 0;
  font-size: 10px;
  color: var(--muted);
}
.analysis-pv {
  overflow-wrap: anywhere;
  font-family: ui-monospace, monospace;
  color: var(--text);
}
.analysis-candidates {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  font-size: 10px;
}
.analysis-candidates li {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  padding: 2px 0;
  border-block-start: 1px solid var(--border);
}
.analysis-candidates li.best { color: var(--ok); font-weight: 700; }
.analysis-settings { margin-block-start: 6px; }
.analysis-settings summary { cursor: pointer; font-size: 10px; color: var(--accent-2); }
/* Keep the native range control; only its accent follows the theme. */
input[type='range'] {
  accent-color: var(--accent-2);
  min-block-size: 24px;
}
#analysis-cpu { flex: 1; }
#review-slider { inline-size: 100%; }
#score-chart { cursor: crosshair; touch-action: none; }

/* Per-side controllers grouped as a native form group. */
.players-panel legend {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-2);
  padding: 0 4px;
}
.players-panel select,
.players-panel input {
  font: inherit;
  font-size: max(1rem, 0.8em);
  padding: 2px 4px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
}

/* Engine tools: native <details> disclosure with compact control rows. */
.engine-tools summary {
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-2);
  padding-block: 2px;
}
.engine-tool-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-block-start: 6px;
}
.engine-tool-row label {
  font-size: 10px;
  color: var(--muted);
}
.engine-tool-row input {
  inline-size: 4.5rem;
  padding: 2px 4px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
}
.engine-tool-row button {
  font-size: 10px;
  padding: 3px 7px;
}
#engine-tool-output {
  display: block;
  margin-block-start: 6px;
  font-size: 10px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

/* Piece index: browsable lexicon from the generated piece database. */
.piece-panel input[type='search'] {
  flex: 1;
  min-inline-size: 0;
  font: inherit;
  font-size: max(1rem, 0.8em);
  padding: 3px 6px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
}
#pieces-list {
  margin-block-start: 6px;
  max-block-size: 240px;
  overflow-y: auto;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding-block: 2px;
}
#pieces-list .hint {
  margin-block: 2px 4px;
  padding-inline: 8px;
}
#pieces-list .piece-rows {
  display: flex;
  flex-direction: column;
}
#pieces-list .piece-row {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
  color: var(--text);
  font-size: 10px;
  padding: 4px 8px;
  cursor: pointer;
}
#pieces-list .piece-row:last-child {
  border-bottom: 0;
}
#pieces-list .piece-row:hover,
#pieces-list .piece-row:focus-visible {
  background: var(--bg-panel);
  color: var(--accent-2);
}
#pieces-list .pieces-back {
  margin-block-end: 6px;
  background: var(--bg);
}
#pieces-list .pieces-back:hover,
#pieces-list .pieces-back:focus-visible {
  border-color: var(--accent);
}
#pieces-list .piece-detail-title {
  margin-block-end: 6px;
  font-size: 12px;
  color: var(--accent);
}

/* Links to related pieces in the detail view (promotion chain). */
.piece-link {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent-2);
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.piece-link:hover,
.piece-link:focus-visible {
  color: var(--accent);
}

/* Movement diagram: SVG board with a compact symbol legend. */
.piece-movement-title {
  margin-block: 8px 4px;
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.4px;
  text-transform: uppercase;
}
.inspect-movement {
  margin-block-start: 6px;
}
.movement-diagram-svg {
  display: block;
  inline-size: 100%;
  block-size: auto;
  max-block-size: 210px;
  margin-inline: auto;
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 4px;
}
.movement-legend {
  margin-block: 4px 0;
  font-size: 9px;
  line-height: 1.3;
  color: var(--muted);
}
.md-board { fill: var(--bg-deep); }
.md-grid {
  stroke: var(--border);
  stroke-width: 0.6;
  opacity: 0.55;
}
.md-slide {
  stroke: var(--accent-2);
  stroke-width: 1.6;
  stroke-linecap: round;
}
.md-unlimited { stroke-dasharray: 3 2; }
.md-range-end { fill: var(--accent-2); }
.md-capture {
  stroke: var(--warn);
  stroke-width: 2.8;
  stroke-linecap: round;
  opacity: 0.9;
}
.md-arrow-normal { fill: var(--accent-2); }
.md-arrow-capture { fill: var(--warn); }
.md-step {
  fill: var(--bg-deep);
  stroke: var(--text);
  stroke-width: 1.4;
}
.md-jump {
  fill: var(--ok);
  font-size: 13px;
  font-family: "Noto Sans CJK JP", "Yu Gothic", sans-serif;
}
.md-token {
  fill: var(--bg-panel);
  stroke: var(--accent);
  stroke-width: 1.2;
}
.md-glyph {
  fill: var(--text);
  font-family: "Noto Sans CJK JP", "Yu Gothic", sans-serif;
  pointer-events: none;
}

/* Isolate sidebar panels so live updates do not reflow the whole page. */
.panel {
  content-visibility: auto;
  contain-intrinsic-size: auto 220px;
}

/* Piece tags & hints */
.piece-tags {
  font-size: 10px;
  color: var(--accent-2);
  margin-top: 4px;
}

.hint {
  font-size: 9px;
  color: var(--muted);
  margin-top: 4px;
  line-height: 1.35;
}

/* TSFEN box */
.tsfen-box {
  width: 100%;
  height: 54px;
  resize: vertical;
  background: var(--bg-deep);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: ui-monospace, monospace;
  font-size: 9px;
  padding: 5px;
  margin-bottom: 5px;
}

/* Button row & shortcuts */
.button-row {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.shortcuts {
  font-size: 9px;
  color: var(--muted);
  margin-top: 6px;
  line-height: 1.5;
}

.shortcuts kbd {
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0 3px;
  font-family: inherit;
}

/* Active toggle state (Start game, Auto, Analyze). */
.toolbar button.active,
.panel button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}

/* Appearance panel: theme picker, style selects and colour editor. */
.appearance-panel select {
  font: inherit;
  font-size: max(1rem, 0.8em);
  padding: 2px 4px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
  flex: 1;
  min-inline-size: 0;
}

/* Theme picker in the main toolbar: keep it readable even with long names
   like "Midnight" or "Parchment". */
#theme-select {
  min-inline-size: 110px;
  font: inherit;
  font-size: max(1rem, 0.8em);
  padding: 2px 6px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
}
.theme-details summary {
  cursor: pointer;
  font-size: 10px;
  color: var(--accent-2);
  margin-block-start: 6px;
  min-block-size: var(--target-size);
  display: flex;
  align-items: center;
}
.theme-color-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 4px 8px;
  margin-block-start: 6px;
}
.theme-color-grid label {
  font-size: 9px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 4px;
  min-inline-size: 0;
}
.theme-color-grid input[type='color'] {
  inline-size: 28px;
  block-size: 24px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg);
  cursor: pointer;
  flex: 1;
  min-inline-size: 24px;
}
.theme-file {
  inline-size: 100%;
  font-size: 10px;
  color: var(--muted);
}
.link-button {
  background: none !important;
  border: 0 !important;
  padding: 0 !important;
  min-block-size: 0 !important;
  color: var(--accent-2) !important;
  font-size: 10px;
  text-decoration: underline;
}
.link-button:hover {
  background: none !important;
  color: var(--text) !important;
}
/* Native dialog — Taikyoku Shogi Web GUI */

dialog {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0;
  width: min(420px, 92vw);
  max-height: 85vh;
  overflow: auto;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  background: var(--bg-panel);
  color: var(--text);
}

dialog::backdrop {
  background: rgba(6, 8, 20, 0.6);
  overscroll-behavior: contain;
}

dialog:modal {
  overscroll-behavior: contain;
}

dialog h2 {
  font-size: 14px;
  color: var(--accent);
  margin: 0 0 8px 16px;
}

dialog p {
  font-size: 11px;
  color: var(--muted);
  margin: 0 16px 12px 16px;
}

dialog .options {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0 16px 12px 16px;
}

dialog button {
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
}

dialog button:hover,
dialog button:focus-visible {
  border-color: var(--accent);
  outline: none;
}

dialog button[value='cancel'] {
  color: var(--muted);
}

dialog button.cancel-row {
  margin-top: 8px;
  text-align: center;
  background: transparent;
  color: var(--muted);
}

dialog button.cancel-row:hover {
  color: var(--text);
  border-color: var(--accent);
}

/* Help → project modal. Native <dialog> gives focus trapping and Esc for free. */
.help-project {
  margin: 0 16px 12px;
  padding-block-start: 8px;
  border-block-start: 1px solid var(--border);
}
.help-project .hint { margin-block-start: 0; }
.repo-links {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0 16px 12px;
}
.repo-links a {
  color: var(--accent-2);
  font-size: 12px;
  text-decoration: none;
  padding: 2px 0;
}
.repo-links a:hover,
.repo-links a:focus-visible { text-decoration: underline; }
/* Developer tools panel — Taikyoku Shogi Web GUI */

.dev-tools {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 8px 10px;
  margin-top: 8px;
  flex-shrink: 0;
}

.dev-tools h2 {
  font-size: 10px;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--accent-2);
  margin-bottom: 5px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dev-tools .dev-toggle {
  font-size: 10px;
  padding: 2px 6px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
}

.dev-tools .dev-toggle:hover {
  border-color: var(--accent-2);
  color: var(--text);
}

.dev-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-top: 4px;
}

.dev-grid button {
  width: 100%;
  text-align: left;
  padding: 5px 8px;
  font-size: 10px;
  background: #1e293b;
  color: var(--text);
  border: 1px solid #334155;
  border-radius: 4px;
  cursor: pointer;
}

.dev-grid button:hover {
  background: #334155;
  border-color: var(--accent-2);
}

.dev-note {
  font-size: 9px;
  color: var(--muted);
  margin-top: 5px;
}

.dev-tools .dev-subhead {
  margin-top: 10px;
  border-top: 1px solid #334155;
  padding-top: 8px;
}

.dev-config {
  font-size: 9px;
  color: var(--muted);
  margin-top: 5px;
  line-height: 1.4;
}

.dev-logs {
  margin: 5px 0 0;
  padding: 6px;
  max-height: 120px;
  overflow: auto;
  background: #020617;
  border: 1px solid #334155;
  border-radius: 4px;
  color: var(--text);
  font-size: 9px;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
}

.dev-filter {
  display: flex;
  gap: 4px;
  margin-top: 5px;
}

.dev-filter button {
  flex: 1;
  font-size: 9px;
  padding: 2px;
  background: transparent;
  color: var(--muted);
  border: 1px solid #334155;
  border-radius: 3px;
  cursor: pointer;
}

.dev-filter button[aria-pressed='true'] {
  color: var(--text);
  border-color: var(--accent-2);
  background: #1e293b;
}

.dev-tools h3.dev-subhead {
  font-size: 9px;
  margin-top: 8px;
}

.dev-chart {
  display: block;
  width: 100%;
  height: 90px;
  background: #020617;
  border: 1px solid #334155;
  border-radius: 4px;
  margin-top: 4px;
}

/* Responsive — Taikyoku Shogi Web GUI */

/* The board is a wide 2D surface: allow horizontal panning inside its own
   region when zoomed in, but NEVER trap the vertical gesture — keep the default
   `overscroll-behavior: auto` so a swipe starting on the board propagates to
   the document scroll. `contain` here was swallowing the gesture on phones. */
.board-wrap {
  scrollbar-width: thin;
}

/* ── Desktop (>900px): sidebar beside the board ── */
@media (min-width: 901px) {
  .main {
    flex-direction: row;
    align-items: stretch;
    overflow: hidden;
  }
  aside.sidebar {
    width: 310px;
    flex-shrink: 0;
    overflow-y: auto;
  }
  .board-wrap {
    align-self: flex-start;
    max-inline-size: 100%;
    max-block-size: 100%;
    overflow: auto;
  }
}

/* ── Mobile (<=900px): vertical stack, the DOCUMENT scrolls ── */
@media (max-width: 900px) {
  body {
    height: auto;
    min-height: 100%;
    overflow-x: visible;
    overflow-y: visible;
  }
  .app {
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }
  .main {
    flex-direction: column;
    align-items: stretch;
    /* No overflow here: the document scrolls, so gestures on the canvas reach
       it instead of being trapped in a nested flex scroll container. */
    overflow: visible;
    min-height: 0;
    padding: 6px;
    gap: 8px;
  }

  /* Board takes full width. No nested scroll container at all: the whole
     document pans in 2D, so a swipe anywhere on the canvas (centre included)
     scrolls the page instead of being trapped. */
  .board-wrap {
    align-self: center;
    max-inline-size: 100%;
    width: 100%;
    overflow: visible;
  }

  /* Sidebar stacks below the board and scrolls independently. */
  aside.sidebar {
    width: 100%;
    max-width: 100%;
    flex-shrink: 1;
    overflow-y: auto;
    padding-inline: 0;
    padding-block-end: 8px;
  }

  header.header {
    padding: 6px max(6px, env(safe-area-inset-right)) 6px max(6px, env(safe-area-inset-left));
    padding-block-start: max(6px, env(safe-area-inset-top));
    gap: 6px;
  }

  header.header h1 {
    white-space: normal;
    font-size: clamp(1rem, 0.9rem + 1vw, 1.25rem);
  }

  header.header h1 small {
    font-size: 0.65rem;
  }

  .status-bar {
    margin-inline-start: 0;
    inline-size: 100%;
    justify-content: space-between;
    font-size: 0.75rem;
  }

  .zoom input {
    inline-size: clamp(60px, 20vw, 110px);
  }

  .site-footer {
    padding-inline-end: max(6px, env(safe-area-inset-right));
    padding-inline-start: max(6px, env(safe-area-inset-left));
    padding-block-end: max(6px, env(safe-area-inset-bottom));
  }
}

/* Touch screens need larger, well-separated targets. */
@media (pointer: coarse) {
  :where(.toolbar button, .panel button, .toolbar select, .panel select) {
    min-block-size: var(--target-size);
    min-inline-size: var(--target-size);
  }
  .theme-color-grid input[type='color'] {
    inline-size: 36px;
    block-size: 36px;
  }
  .zoom input {
    min-block-size: 36px;
  }
  .toolbar select,
  .toolbar button {
    font-size: 0.9rem;
    padding: 8px 10px;
  }
}

/* Long unbroken strings (URLs, TSFEN) must never force sideways scrolling. */
:where(.panel, .toolbar, .site-footer) {
  min-inline-size: 0;
  overflow-wrap: break-word;
}
:where(a, code) {
  overflow-wrap: anywhere;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
