:root {
  --bg: #14161b;
  --panel: #1c1f26;
  --card: #232731;
  --line: #333845;
  --text: #e9e6df;
  --muted: #9aa0ab;
  --accent: #e0b25c;
  --accent-ink: #1c1606;
  --danger: #e0685c;
  --radius: 10px;
  --panel-w: 320px;
  color-scheme: dark;
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.app {
  display: grid;
  grid-template-columns: 1fr var(--panel-w);
  height: 100dvh;
}

.stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.loader {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.loader.error { color: var(--danger); padding: 2rem; text-align: center; }

.status-pill {
  position: absolute;
  top: 14px;
  left: 50%;
  translate: -50% 0;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgb(20 22 27 / 0.78);
  border: 1px solid var(--line);
  backdrop-filter: blur(6px);
  font-size: 0.9rem;
  white-space: nowrap;
  pointer-events: none;
}

.status-pill:empty { display: none; }

.status-pill.thinking::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: 1px;
  animation: pulse 1s ease-in-out infinite;
}

.status-pill.check { border-color: var(--danger); color: #ffb3aa; }

@keyframes pulse { 50% { opacity: 0.25; } }

/* --- panel --- */

.panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  min-height: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 4px 4px;
}

.brand h1 { margin: 0; font-size: 1.15rem; letter-spacing: 0.02em; }

.brand-logo { width: 28px; height: 28px; }
.brand-logo img { width: 100%; height: 100%; display: block; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}

.card h2 { margin: 0 0 8px; font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }

.field {
  display: grid;
  grid-template-columns: 90px 1fr;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.field label { color: var(--muted); font-size: 0.9rem; }

.mode-human .cpu-only { display: none; }

select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 9px;
  width: 100%;
}

textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; }

select:focus-visible, textarea:focus-visible, .btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-weight: 500;
  color: var(--text);
  background: #2d323e;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
}

.btn:hover:not(:disabled) { background: #363c4a; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { background: #ebc277; }
.btn.danger { color: #ffb3aa; }
.btn.small { padding: 6px 8px; font-size: 0.85rem; }

.card > .btn { width: 100%; }

.btn-row { display: flex; gap: 8px; }
.btn-row > .btn { flex: 1; }
.btn-row.end { justify-content: flex-end; }
.btn-row.end > .btn { flex: 0 0 auto; }

/* Icons are SVG masks (assets/icons/*.svg), active only when main.js adds .has-icons. */
.icon { display: none; }

.has-icons .icon {
  display: inline-block;
  width: 1.1em;
  height: 1.1em;
  flex: none;
  background: currentColor;
  mask: var(--icon) center / contain no-repeat;
}

.has-icons [data-icon="new-game"] { --icon: url("assets/icons/new-game.svg"); }
.has-icons [data-icon="undo"] { --icon: url("assets/icons/undo.svg"); }
.has-icons [data-icon="flip"] { --icon: url("assets/icons/flip.svg"); }
.has-icons [data-icon="resign"] { --icon: url("assets/icons/resign.svg"); }
.has-icons [data-icon="copy"] { --icon: url("assets/icons/copy.svg"); }
.has-icons [data-icon="load"] { --icon: url("assets/icons/load.svg"); }

/* --- players / captured --- */

.players { display: grid; gap: 6px; }

.player {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  padding: 2px 6px;
  border-radius: 6px;
}

.player.to-move { background: rgb(224 178 92 / 0.12); }
.player.to-move .player-name::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: 1px;
}

.player-name { font-weight: 600; font-size: 0.9rem; }

.captured { display: flex; flex-wrap: wrap; align-items: center; min-height: 22px; }

.piece-glyph { font-size: 1.15rem; line-height: 1; margin-right: -2px; }
.piece-glyph.w { color: #f1e4cb; }
.piece-glyph.b { color: #9d8f86; }
.piece-img { width: 20px; height: 20px; margin-right: -4px; }

.advantage { color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }

/* --- moves --- */

.moves-card { flex: 1 1 140px; display: flex; flex-direction: column; min-height: 140px; }

.moves {
  flex: 1;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.88rem;
  min-height: 0;
}

.moves li {
  display: grid;
  grid-template-columns: 2.6em 1fr 1fr;
  padding: 2px 4px;
  border-radius: 4px;
}

.moves li:nth-child(odd) { background: rgb(255 255 255 / 0.03); }
.moves .num { color: var(--muted); }
.moves .last { color: var(--accent); font-weight: 600; }

.moves-empty { margin: 0; color: var(--muted); font-size: 0.9rem; }
.moves:not(:empty) + .moves-empty { display: none; }

/* --- dialogs --- */

.dialog {
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
  width: min(92vw, 380px);
  box-shadow: 0 20px 60px rgb(0 0 0 / 0.5);
}

.dialog::backdrop { background: rgb(0 0 0 / 0.55); backdrop-filter: blur(2px); }
.dialog h2 { margin: 0 0 10px; font-size: 1.2rem; }
.dialog p { color: var(--muted); margin: 0 0 16px; }
.dialog .error { color: var(--danger); min-height: 1.2em; margin: 6px 0 12px; font-size: 0.9rem; }

.dialog[open] { animation: pop 0.16s ease-out; }
@keyframes pop { from { opacity: 0; scale: 0.96; } }

.promo-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }

.promo-grid .btn {
  flex-direction: column;
  gap: 4px;
  padding: 10px 4px;
  font-size: 0.8rem;
}

.promo-grid .piece-glyph { font-size: 2.2rem; margin: 0; }
.promo-grid .piece-img { width: 44px; height: 44px; margin: 0; }

.result-badge { display: block; width: 56px; height: 56px; margin-bottom: 8px; }
.result-badge:empty { display: none; }
.result-badge img { width: 100%; height: 100%; }

/* --- toast --- */

.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  translate: -50% 12px;
  padding: 8px 14px;
  border-radius: 8px;
  background: #2d323e;
  border: 1px solid var(--line);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, translate 0.2s;
}

.toast.show { opacity: 1; translate: -50% 0; }

/* --- small screens: board on top, panel below --- */

@media (max-width: 820px) {
  html, body { height: auto; overflow: visible; }

  .app {
    grid-template-columns: 1fr;
    grid-template-rows: min(100vw, 62dvh) auto;
    height: auto;
    min-height: 100dvh;
  }

  .panel { border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
  .brand { display: none; }
  .moves-card { max-height: 220px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
