/* Openings — phone-first, theme-able. Themes swap the nine core colours;
 * green = the right move, red = a wrong move, in every theme. */

:root {                    /* default: Royal — royal blue & gold */
  --bg: #0d1322; --panel: #15203a; --panel2: #1d2b4e; --line: #2b3c66;
  --text: #e9ecf5; --muted: #96a2c4; --accent: #d9b45b;
  --up: #66c98a; --down: #e0716f;
}
html[data-theme="ember"] {
  --bg: #111318; --panel: #191c24; --panel2: #222633; --line: #2a2f3c;
  --text: #eae7e0; --muted: #9298a8; --accent: #e5a558;
  --up: #69c98a; --down: #e0716f;
}
html[data-theme="ice"] {
  --bg: #0d1418; --panel: #141d23; --panel2: #1c2830; --line: #263540;
  --text: #e4ebee; --muted: #8fa3ad; --accent: #56c3dc;
  --up: #69c98a; --down: #e0716f;
}
html[data-theme="nocturne"] {
  --bg: #141020; --panel: #1c1730; --panel2: #262040; --line: #322a52;
  --text: #eae6f2; --muted: #9d94b8; --accent: #a78bda;
  --up: #69c98a; --down: #e0716f;
}
html[data-theme="paper"] { /* light */
  --bg: #f5f2ec; --panel: #fdfbf7; --panel2: #ece6d8; --line: #d8d1c0;
  --text: #29261f; --muted: #7a7468; --accent: #8a6d1d;
  --up: #1a8f4a; --down: #c04543;
}
:root {
  --accent-soft: color-mix(in srgb, var(--accent) 14%, transparent);
  --up-soft: color-mix(in srgb, var(--up) 14%, transparent);
  --down-soft: color-mix(in srgb, var(--down) 14%, transparent);
  --radius: 14px;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;

  /* the board: squares take a tint of the theme accent; the pieces are plain
     ivory and near-black in every theme, as on a real set */
  --sq-light: color-mix(in srgb, var(--accent) 14%, #efe9dc);
  --sq-dark: color-mix(in srgb, var(--accent) 38%, #6b7486);
  --pw: #f8f5ec;
  --pw-line: #1d1d24;
  --pb: #24242b;
  --pb-line: #e9e5d8;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { background: var(--bg); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  max-width: 640px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 14px)
           calc(env(safe-area-inset-right) + 16px)
           calc(env(safe-area-inset-bottom) + 28px)
           calc(env(safe-area-inset-left) + 16px);
  -webkit-tap-highlight-color: transparent;
}
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
.theme-row { margin-top: 26px; display: flex; align-items: center; gap: 12px; justify-content: center; }
.theme-label { color: var(--muted); font-size: 0.75rem; }
.theme-dot { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); padding: 0; }
.theme-dot.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.foot-note { color: var(--muted); font-size: 0.72rem; text-align: center; margin-top: 8px; line-height: 1.5; }

/* ------------------------------------------------------------ shared */
.head { margin: 6px 2px 14px; }
.head h1 { font-size: 1.45rem; letter-spacing: 0.01em; }
.tagline { color: var(--muted); font-size: 0.8rem; margin-top: 4px; line-height: 1.4; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.empty {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 18px 16px;
  color: var(--muted);
  font-size: 0.88rem;
  text-align: center;
  line-height: 1.5;
}
.label { color: var(--muted); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; }
.eco {
  display: inline-block;
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 1px 5px;
  flex: none;
}
.btn {
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel2);
  font-size: 0.86rem;
}
.btn:active { transform: scale(0.98); }
.btn.primary { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.btn:disabled { opacity: 0.35; cursor: default; }
.link-btn { color: var(--accent); font-size: 0.85rem; padding: 6px 2px; }

/* ------------------------------------------------------------ picker */
.search {
  width: 100%;
  font: inherit;
  font-size: 16px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 14px;
  outline: none;
}
.search:focus { border-color: var(--accent); }
.search::placeholder { color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 0.82rem;
}
.chip:active { background: var(--panel2); }
.section-label { margin: 18px 2px 8px; }
.count-line { color: var(--muted); font-size: 0.75rem; margin: 12px 2px 8px; }
.results { display: flex; flex-direction: column; gap: 8px; }
.result {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px 13px;
}
.result:active { background: var(--panel2); }
.result-top { display: flex; align-items: baseline; gap: 8px; }
.result-name { font-weight: 600; font-size: 0.93rem; line-height: 1.3; }
.result-moves { color: var(--muted); font-size: 0.76rem; margin-top: 5px; line-height: 1.45; overflow-wrap: anywhere; }
.pick-foot { display: flex; justify-content: center; gap: 18px; margin-top: 16px; }

/* ------------------------------------------------------------ board view */
.open-card { display: flex; align-items: center; gap: 12px; }
.open-main { flex: 1; min-width: 0; }
.open-name { font-weight: 650; font-size: 1.02rem; line-height: 1.3; }
.open-sub { color: var(--muted); font-size: 0.76rem; margin-top: 4px; }
.open-top { display: flex; align-items: baseline; gap: 8px; }

.controls { display: flex; flex-wrap: wrap; gap: 10px 8px; margin: 12px 0; align-items: flex-end; justify-content: space-between; }
.ctl { display: flex; flex-direction: column; gap: 5px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--panel); }
.seg button { padding: 8px 9px; font-size: 0.8rem; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--panel); }
.stepper button { width: 32px; padding: 7px 0; font-size: 1.05rem; color: var(--accent); }
.stepper button:disabled { opacity: 0.3; }
.stepper .val { min-width: 28px; text-align: center; font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 0.95rem; }

.board-wrap { position: relative; width: 100%; aspect-ratio: 1 / 1; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.board {
  position: absolute; inset: 0;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.sq { position: relative; }
.sq.l { background: var(--sq-light); }
.sq.d { background: var(--sq-dark); }
.sq.last::before, .sq.sel::before, .sq.ok::before, .sq.bad::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
}
.sq.last::before { background: color-mix(in srgb, var(--accent) 34%, transparent); }
.sq.sel::before { background: color-mix(in srgb, var(--accent) 55%, transparent); }
.sq.ok::before { background: color-mix(in srgb, var(--up) 70%, transparent); animation: fade 0.9s ease-out forwards; }
.sq.bad::before { background: color-mix(in srgb, var(--down) 75%, transparent); animation: fade 0.9s ease-out forwards; }
@keyframes fade { from { opacity: 1; } to { opacity: 0; } }
.sq.tgt::after {
  content: ""; position: absolute; left: 50%; top: 50%;
  width: 28%; height: 28%; border-radius: 50%;
  transform: translate(-50%, -50%);
  background: color-mix(in srgb, var(--pw-line) 34%, transparent);
  pointer-events: none;
}
.sq.tgt.cap::after {
  width: 86%; height: 86%;
  background: none;
  border: 4px solid color-mix(in srgb, var(--pw-line) 34%, transparent);
}
.coord {
  position: absolute;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
  opacity: 0.85;
}
.coord.rank { left: 3px; top: 3px; }
.coord.file { right: 3px; bottom: 2px; }
.sq.l .coord { color: var(--sq-dark); }
.sq.d .coord { color: var(--sq-light); }

.pc { position: absolute; inset: 4%; pointer-events: none; }
.pc svg { width: 100%; height: 100%; display: block; stroke-width: 1.25; stroke-linejoin: round; stroke-linecap: round; overflow: visible; }
.pw svg { fill: var(--pw); stroke: var(--pw-line); }
.pb svg { fill: var(--pb); stroke: var(--pb-line); }
.pw .dt { fill: var(--pw-line); stroke: none; }
.pb .dt { fill: var(--pb-line); stroke: none; }
.pc.lift { opacity: 0.3; }
.ghost { position: fixed; z-index: 50; pointer-events: none; transform: translate(-50%, -60%) scale(1.25); inset: auto; }

.arrows { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.arrow { fill: var(--up); stroke: var(--up); opacity: 0.88; }

.posname { color: var(--muted); font-size: 0.76rem; margin: 8px 2px 0; line-height: 1.4; }

.status { margin-top: 10px; }
.status-text { font-size: 0.94rem; line-height: 1.4; }
.status-text b { font-family: var(--mono); font-weight: 700; color: var(--accent); }
.status-sub { color: var(--muted); font-size: 0.8rem; margin-top: 4px; line-height: 1.4; }
.status.good { border-color: var(--up); background: var(--up-soft); }
.status.warn { border-color: var(--down); background: var(--down-soft); }
.status-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.nav { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 10px; }
.nav .btn { padding: 11px 0; font-size: 1rem; }

.block { margin-top: 14px; }
.block-head { display: flex; align-items: baseline; justify-content: space-between; margin: 0 2px 8px; }
.moves { font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 0.9rem; line-height: 2; }
.mv-num { color: var(--muted); margin-right: 4px; }
.mv { padding: 3px 6px; border-radius: 6px; margin-right: 6px; }
button.mv:active { background: var(--panel2); }
.mv.cur { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.mv.hid { color: var(--muted); }
.moves-note { color: var(--muted); font-size: 0.76rem; margin-top: 8px; line-height: 1.45; font-family: inherit; }

.book { display: flex; flex-direction: column; gap: 6px; }
.book-row {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
}
.book-row:active { background: var(--panel2); }
.book-row.inline { border-color: var(--up); }
.book-san { font-family: var(--mono); font-weight: 700; font-size: 0.92rem; min-width: 54px; }
.book-name { flex: 1; min-width: 0; font-size: 0.84rem; line-height: 1.3; }
.book-count { color: var(--muted); font-size: 0.72rem; font-family: var(--mono); flex: none; }
