/* ===== Openle — chess.com-inspired theme ===== */
:root {
  --bg: #2b2d33;          /* cool dark gray (gradient applied on body) */
  --panel: #262931;       /* raised cards/panels (cool, blue-tinted) */
  --panel-2: #383c46;     /* hover / secondary surface */
  --surface: #1e2025;     /* inset surfaces (dropdown, board frame) */
  --border: #00000000;
  --border-solid: #40434d;
  --text: #f3f3f6;
  --muted: #aaaeb9;
  --muted-2: #7a7e89;
  --good: #6198ca;        /* lightly softened blue — on the target path / shared */
  --good-dim: #3b5778;
  --miss: #9ba1aa;        /* diverged tree paths */
  --accent: #6198ca;      /* lightly softened blue accent everywhere */
  --accent-dark: #4476a7; /* raised-button bottom edge */
  --accent-hover: #7daedc;
  --board-light: #b9c3ce;
  --board-dark: #596f85;
  --shadow: 0 8px 28px rgba(0,0,0,.45);
  --mono: "SFMono-Regular", ui-monospace, "Cascadia Code", Consolas, "Liberation Mono", Menlo, monospace;
  --sans: "Montserrat", system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background:
    radial-gradient(1100px 540px at 50% -8%, rgba(70,92,116,.26), transparent 60%) fixed,
    linear-gradient(170deg, #2e3d4f 0%, #2d323b 45%, #2b2b30 100%) fixed, var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* ---- Scrollbar (themed) ---- */
/* WebKit / Blink. NOTE: setting the standard scrollbar-width/scrollbar-color
   properties makes Chromium 121+ ignore these ::-webkit-scrollbar rules
   entirely, so the Firefox fallback is gated behind @supports below. */
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-solid); border-radius: 999px;
  border: 3px solid transparent; background-clip: padding-box;  /* inset pill */
}
::-webkit-scrollbar-corner { background: transparent; }
/* End-cap arrow buttons (custom scrollbars hide these by default). Chevrons are
   inline SVGs tinted with --muted-2; the hash in the color is %23-encoded. */
::-webkit-scrollbar-button:single-button {
  display: block; height: 14px; width: 14px;
  background-repeat: no-repeat; background-position: center; background-size: 14px 14px;
}
/* Chevrons hardcode --border-solid (%2340434d) to match the thumb; SVG data
   URIs can't read CSS vars. Slightly wider (~7px) than the pill. */
::-webkit-scrollbar-button:single-button:vertical:decrement {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 7 6 4 9 7' fill='none' stroke='%2340434d' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
::-webkit-scrollbar-button:single-button:vertical:increment {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 5 6 8 9 5' fill='none' stroke='%2340434d' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
::-webkit-scrollbar-button:single-button:horizontal:decrement {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M7 3 4 6 7 9' fill='none' stroke='%2340434d' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
::-webkit-scrollbar-button:single-button:horizontal:increment {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M5 3 8 6 5 9' fill='none' stroke='%2340434d' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
::-webkit-scrollbar-button:single-button:hover { background-color: var(--panel-2); }
/* Firefox only — browsers with no ::-webkit-scrollbar support. */
@supports not selector(::-webkit-scrollbar) {
  html { scrollbar-width: thin; scrollbar-color: var(--border-solid) transparent; }
}

.wrap { max-width: 1220px; margin: 0 auto; padding: 0 18px 80px; }

/* ---- App bar ---- */
.appbar {
  display: flex; align-items: center; gap: 16px;
  padding: 18px 2px 14px;
  border-bottom: 1px solid var(--border-solid);
  margin-bottom: 17px;
}
.brand { display: flex; align-items: center; gap: 12px; font-weight: 800; font-size: 24px; letter-spacing: 0; color: #fff; }
.brand .leaf { font-size: 29px; }
.brand-logo { display: block; width: auto; height: 36px; }
.brand small { color: var(--muted); font-weight: 600; font-size: 12px; letter-spacing: .05em; text-transform: uppercase; }

.modes { display: flex; gap: 3px; margin-left: 8px; background: var(--surface); border-radius: 8px; padding: 3px; }
.modes button {
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  padding: 7px 15px; border-radius: 6px; font-size: 13.5px; font-weight: 700; font-family: inherit;
  transition: background .12s, color .12s;
}
.modes button.active { background: var(--panel-2); color: #fff; }
.modes button:hover:not(.active) { color: var(--text); background: rgba(255,255,255,.04); }

.spacer { flex: 1; }
.iconbtn {
  border: 0; background: var(--panel-2); color: var(--muted);
  width: 36px; height: 36px; border-radius: 8px; cursor: pointer; font-size: 15px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; font-family: inherit;
  transition: color .12s, background .12s;
}
.iconbtn svg { display: block; width: 17px; height: 17px; }
.iconbtn:hover { color: #fff; background: var(--border-solid); }
.appbar > .iconbtn { background: var(--panel); }
.move-toggle {
  display: inline-flex; align-items: center; gap: 7px;
  height: 36px; padding: 0 12px; flex-shrink: 0;
  background: var(--panel); border-radius: 8px;
  color: var(--muted); font-size: 12.5px; font-weight: 700;
  cursor: pointer; user-select: none; white-space: nowrap;
  transition: color .12s, background .12s;
}
.move-toggle:hover { color: var(--text); }
.move-toggle input { width: 14px; height: 14px; margin: 0; accent-color: var(--good); cursor: pointer; }
.move-toggle:has(input:checked) { color: var(--text); background: rgba(97,152,202,.16); }

/* ---- Puzzle meta ---- */
.meta { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; font-size: 16px; }
.meta .title { font-size: 18px; font-weight: 700; }
.meta .sub { color: var(--muted); font-size: 15px; }
.meta .diff { padding: 2px; }
.meta .diff button { padding: 5px 12px; font-size: 14px; }
.meta .gcount { margin-left: auto; color: var(--muted); font-size: 15px; }
.meta .gcount b { color: var(--text); }

/* ---- Search / autocomplete ---- */
.search { position: relative; margin-bottom: 8px; }
.search input {
  width: 100%; padding: 13px 15px; font-size: 15px; font-family: inherit;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-solid); border-radius: 10px; outline: none;
  box-shadow: inset 0 1px 3px rgba(0,0,0,.22);
  transition: border-color .15s, box-shadow .15s;
}
.search input::placeholder { color: var(--muted-2); }
.search input:focus { border-color: var(--accent); box-shadow: inset 0 1px 3px rgba(0,0,0,.22), 0 0 0 3px rgba(97,152,202,.22); }
.search input:disabled { opacity: .55; cursor: not-allowed; }
.suggest {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 40;
  background: var(--panel); border: 1px solid var(--border-solid); border-radius: 10px;
  box-shadow: var(--shadow); max-height: 340px; overflow-y: auto; padding: 5px;
  display: none;
}
.suggest.open { display: block; }
.suggest li { list-style: none; padding: 9px 11px; border-radius: 8px; cursor: pointer; display: flex; align-items: baseline; gap: 10px; }
.suggest li.active, .suggest li:hover { background: var(--panel-2); }
.suggest .nm { font-weight: 600; flex: 1; min-width: 0; }
.suggest .nm em { color: var(--accent); font-style: normal; }
.suggest .mv { color: var(--muted-2); font-size: 12px; font-family: var(--mono); flex-shrink: 0; max-width: 230px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggest .mv em { color: var(--good); font-style: normal; font-weight: 600; }
.suggest .empty { padding: 14px; color: var(--muted); text-align: center; }

/* ---- Toast ---- */
.toast {
  position: fixed; left: 50%; top: 22px; transform: translateX(-50%) translateY(-12px);
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border-solid);
  padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- Panels ---- */
.panel {
  background: linear-gradient(180deg, rgba(255,255,255,.022), rgba(255,255,255,0) 130px), var(--panel);
  border: 1px solid var(--border-solid); border-radius: 10px; padding: 16px 18px; margin-bottom: 16px;
  box-shadow: 0 2px 14px rgba(0,0,0,.20);
}
.panel > h2 { margin: 0 0 12px; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.panel .hint { color: var(--muted-2); font-size: 13px; }
.tree-panel { padding: 10px 12px 12px; }
.tree-panel > .tree {
  height: clamp(300px, 44vh, 470px); min-height: 0;
  -webkit-mask-image:
    linear-gradient(to right, transparent, #000 9px, #000 calc(100% - 9px), transparent),
    linear-gradient(to bottom, transparent, #000 9px, #000 calc(100% - 9px), transparent);
  -webkit-mask-composite: source-in;
  mask-image:
    linear-gradient(to right, transparent, #000 9px, #000 calc(100% - 9px), transparent),
    linear-gradient(to bottom, transparent, #000 9px, #000 calc(100% - 9px), transparent);
  mask-composite: intersect;
}
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 4px; }
.panel-heading h2 { margin: 0; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.tree-controls, .tree-modal-controls { display: flex; align-items: center; gap: 2px; }
.tree-tool { width: 28px; height: 28px; border-radius: 5px; background: transparent; }
.tree-tool svg { width: 15px; height: 15px; }

/* ---- Tree ---- */
.tree {
  position: relative;
  min-height: 112px;
  width: 100%;
  overflow: hidden;
  padding: 0 0 4px;
  cursor: grab;
  touch-action: none;
  user-select: none;
  overscroll-behavior: auto;
  scrollbar-width: none;
}
.tree::-webkit-scrollbar { display: none; }
.tree.is-panning, .tree.is-panning * { cursor: grabbing !important; }
.tree-pan { position: relative; }
.tree-map { display: block; position: absolute; max-width: none; overflow: visible; }
.tree-edge { fill: none; stroke: var(--muted-2); stroke-width: 1.25; opacity: .78; }
.tree-edge--target { stroke: var(--good); stroke-width: 3; opacity: .9; }
.tree-edge--off { stroke: var(--miss); stroke-width: 1.25; opacity: .62; }
.tree-edge--hidden { stroke: var(--good); stroke-width: 1.6; stroke-dasharray: 4 4; opacity: .55; }
.tree-edge.is-latest { animation: tree-edge-arrive .42s ease-out both; }

.tree-node {
  width: 100%; height: 100%; margin: 0; padding: 2px 4px;
  position: relative;
  display: flex; align-items: center; justify-content: center; gap: 3px;
  border: 1px solid var(--border-solid); border-radius: 999px;
  background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.28);
  font-family: var(--sans); font-size: 11px; line-height: 1.15; text-align: center;
  overflow: hidden;
}
button.tree-node { cursor: pointer; }
button.tree-node:hover { filter: brightness(1.13); }
button.tree-node:focus-visible { outline: 2px solid var(--accent-hover); outline-offset: 2px; }
.tree-node--root { color: var(--text); font-size: 10.5px; font-weight: 700; border-radius: 4px; }
.tree-node--root.tree-node--target {
  background: linear-gradient(rgba(97,152,202,.14), rgba(97,152,202,.14)), var(--surface);
  border-color: var(--good-dim); color: var(--good);
}
.tree-node--sequence {
  background: linear-gradient(rgba(155,161,170,.09), rgba(155,161,170,.09)), var(--surface); border-color: rgba(155,161,170,.34);
  color: var(--miss); font-family: var(--mono); font-size: 10px; padding: 2px 4px;
}
.tree-node__sequence { display: block; width: 100%; text-align: center; white-space: normal; line-height: 1.3; }
.tree-node__sequence span { display: inline-block; margin-right: 2px; white-space: nowrap; }
.tree-node__sequence i { color: var(--muted-2); font-size: 8px; font-style: normal; margin-right: 1px; }
/* Confirmed target trunk: a sequence node, but tinted like the target path. */
.tree-node--sequence.tree-node--target { background: linear-gradient(rgba(97,152,202,.14), rgba(97,152,202,.14)), var(--surface); border-color: var(--good-dim); color: var(--good); }
.tree-seq__move { cursor: pointer; border-radius: 3px; }
.tree-seq__move:hover { background: rgba(97,152,202,.26); box-shadow: 0 0 0 2px rgba(97,152,202,.26); }
.tree-seq__move:focus-visible { outline: 1px solid var(--accent-hover); outline-offset: 2px; }
.tree-node--guess,
.tree-node--answer { flex-direction: column; gap: 1px; padding: 3px 5px; border-radius: 4px; }
.tree-node--guess.tree-node--off { color: var(--miss); border-color: rgba(155,161,170,.4); }
/* Custom-tree remove handle: a corner × revealed when hovering the opening box. */
.tree-node__remove {
  position: absolute; top: 1px; right: 2px; width: 15px; height: 15px;
  display: none; align-items: center; justify-content: center;
  border-radius: 50%; background: var(--panel-2); border: 1px solid var(--border-solid);
  color: var(--muted); font: 700 13px/1 var(--sans); cursor: pointer;
}
.tree-node--removable:hover .tree-node__remove { display: inline-flex; }
.tree-node__remove:hover { background: var(--border-solid); border-color: var(--border-solid); color: var(--text); }
/* Moves line inside a merged guess leaf: small, mono, dimmer than the name. */
.tree-node--guess .tree-node__sequence { font-family: var(--mono); font-size: 9px; opacity: .82; margin-top: 1px; }
.tree-node--guess .tree-node__sequence i { font-size: 7.5px; }
.tree-node__name {
  display: -webkit-box; max-width: 100%; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
  font-weight: 700; font-size: 10.5px; line-height: 1.12;
}
/* A guess/answer box plays that opening's whole line on the board when clicked
   (the inner move tokens keep their own per-ply navigation). */
.tree-node--clickable { cursor: pointer; }
.tree-node--clickable:hover { filter: brightness(1.15); }
.tree-node--clickable:focus-visible { outline: 2px solid var(--accent-hover); outline-offset: 2px; }
.tree-node.is-board-position {
  border-color: rgba(155,161,170,.7);
}
.tree-node.is-board-position::after {
  content: ""; position: absolute; left: 50%; bottom: 1px;
  width: 18px; height: 2px; border-radius: 2px;
  background: var(--miss); transform: translateX(-50%);
}
.tree-node--target.is-board-position {
  border-color: rgba(125,174,220,.7);
}
.tree-node--target.is-board-position::after {
  background: var(--accent);
}
.tree-node--tip {
  flex-direction: column; gap: 0; background: linear-gradient(rgba(97,152,202,.08), rgba(97,152,202,.08)), var(--surface);
  border-color: var(--good-dim); border-style: dashed; color: var(--good);
}
.tree-node__question { font-family: var(--mono); font-size: 14px; font-weight: 700; line-height: 1; }
.tree-node--answer.tree-node--target {
  background: linear-gradient(rgba(97,152,202,.14), rgba(97,152,202,.14)), var(--surface); border-color: var(--good-dim); color: var(--good);
}
/* When selected, the answer leaf takes the brighter selected-blue border like
   the main tree's selected target nodes (the base rule above would dim it). */
.tree-node--answer.tree-node--target.is-board-position { border-color: rgba(125,174,220,.7); }
.tree-node__answer-mark { font-size: 8.5px; font-weight: 800; text-transform: uppercase; }
.tree-node.is-latest { animation: tree-node-arrive .42s ease-out both; }
@keyframes tree-node-arrive {
  from { opacity: .35; transform: translateY(-5px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes tree-edge-arrive {
  from { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .tree-node.is-latest,
  .tree-edge.is-latest { animation: none; }
}

/* ---- Guess log ---- */
.ghist-item { padding: 10px 12px; border-radius: 6px; border: 1px solid transparent; margin-bottom: 6px; background: var(--surface); }
.ghist-item[data-history-guess] { cursor: pointer; }
.ghist-item[data-history-guess]:hover { filter: brightness(1.1); }
.ghist-item[data-history-guess]:focus-visible { outline: 2px solid var(--accent-hover); outline-offset: 2px; }
.ghist-item:last-child { margin-bottom: 0; }
.ghist-item.best { background: rgba(97,152,202,.12); border-color: var(--good-dim); }
.ghist-item.win  { background: rgba(97,152,202,.12); border-color: var(--good-dim); }
.ghist-item .gn { font-weight: 700; }
.ghist-item .gn .eco { color: var(--muted); font-family: var(--mono); font-size: 11.5px; margin-left: 6px; }
.ghist-item .line { font-family: var(--mono); font-size: 13px; margin-top: 4px; }
.ghist-item .line .num { color: var(--muted-2); }
.ghist-item .line .sh { color: var(--good); }
.ghist-item .line .dv { color: var(--muted-2); font-weight: 600; }
.ghist-item .line .rest { color: var(--muted-2); }
.ghist-item .ghist-move { cursor: pointer; border-radius: 3px; }
.ghist-item .ghist-move:hover { background: rgba(97,152,202,.26); box-shadow: 0 0 0 2px rgba(97,152,202,.26); }
.ghist-item .ghist-move:focus-visible { outline: 1px solid var(--accent-hover); outline-offset: 2px; }
.ghist-item.win .gn,
.ghist-item.win .gn .eco,
.ghist-item.win .line .num,
.ghist-item.win .line .sh { color: var(--good); }

/* ---- Two-column layout: tree on the left, board on the right ---- */
.layout { display: grid; grid-template-columns: minmax(0, 1.18fr) minmax(320px, .82fr); gap: 18px; align-items: start; }
.col-left { min-width: 0; }
.col-right { position: sticky; top: 16px; }
.col-left .panel:last-of-type { margin-bottom: 16px; }

/* ---- Chess board ---- */
.board-panel { padding-bottom: 18px; }
.board-wrap { width: 100%; }
.board {
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
  aspect-ratio: 1 / 1; width: 100%; container-type: inline-size;
  position: relative;
  border-radius: 8px; overflow: hidden; box-shadow: 0 6px 20px rgba(0,0,0,.4);
}
.sq { position: relative; display: flex; align-items: center; justify-content: center; min-width: 0; min-height: 0; }
.sq.l { background: var(--board-light); }
.sq.d { background: var(--board-dark); }
.sq.hl::after { content: ""; position: absolute; inset: 0; background: rgba(83, 151, 208, .45); }
.pc {
  position: relative; z-index: 1;
  width: 100%; height: 100%; object-fit: contain;
  pointer-events: none; user-select: none; -webkit-user-drag: none;
  filter: drop-shadow(0 1.5px 1px rgba(0,0,0,.3));
}
.pc.hide { visibility: hidden; }
.pc.captured-exit { animation: captured-piece-exit .22s ease-in forwards; }
@keyframes captured-piece-exit {
  0%, 68% { opacity: 1; }
  100% { opacity: 0; }
}
.move-ghost {
  position: absolute;
  left: calc(var(--from-f) * 12.5%);
  top: calc((7 - var(--from-r)) * 12.5%);
  width: 12.5%;
  height: 12.5%;
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  animation: piece-slide .22s ease-in-out forwards;
}
@keyframes piece-slide {
  to {
    left: calc(var(--to-f) * 12.5%);
    top: calc((7 - var(--to-r)) * 12.5%);
  }
}
.sq .rk, .sq .fl { position: absolute; font-size: 9px; font-weight: 700; font-family: var(--sans); z-index: 1; }
.sq .rk { top: 1px; left: 3px; }
.sq .fl { bottom: 0px; right: 3px; }
.sq.l .rk, .sq.l .fl { color: rgba(39,49,61,.72); }
.sq.d .rk, .sq.d .fl { color: rgba(243,243,246,.82); }
.board-line-label { margin: -4px 0 10px; color: var(--muted); font-size: 14px; font-weight: 700; line-height: 1.2; letter-spacing: .05em; }
.board-footer { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.board-cap { flex: 1; min-width: 0; font-family: var(--mono); font-size: 14px; line-height: 1.6; }
.board-cap .ln { color: var(--good); }
.board-cap .num { color: var(--muted-2); }
.board-cap .sh { color: var(--good); }
.board-cap .branch { color: var(--miss); }
.board-cap .muted { color: var(--muted); font-family: var(--sans); }
.board-nav { display: flex; gap: 4px; margin-left: auto; }
.board-nav .iconbtn {
  width: 24px;
  height: 24px;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  padding: 0;
}
.board-nav .iconbtn:hover { color: var(--text); background: transparent; }
.board-nav .iconbtn:disabled { opacity: .32; cursor: not-allowed; }
.board-nav .iconbtn:disabled:hover { color: var(--muted); background: transparent; }

@media (max-width: 840px) {
  .layout { grid-template-columns: 1fr; }
  .col-right { position: static; order: -1; }      /* board on top when stacked */
  .col-right .board-wrap { max-width: 420px; margin: 0 auto; }
  .tree-panel > .tree { height: clamp(280px, 52vh, 440px); }
}

/* ---- Footer actions (chess.com raised buttons) ---- */
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 4px; }
.btn {
  border: 0; background: var(--panel-2); color: var(--text);
  padding: 11px 20px; border-radius: 6px; font-size: 14px; font-weight: 700; cursor: pointer; font-family: inherit;
  border-bottom: 3px solid rgba(0,0,0,.3); transition: filter .12s, transform .04s, border-bottom-width .04s;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(2px); border-bottom-width: 1px; }
.btn.primary { background: var(--good); color: #fff; border-bottom-color: var(--accent-dark); text-transform: uppercase; letter-spacing: .03em; }
.btn.ghost { background: transparent; color: var(--muted); border-bottom-color: transparent; font-weight: 600; }
.btn.ghost:hover { background: var(--panel-2); filter: none; }

/* ---- Modal ---- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(8,7,5,.62); backdrop-filter: blur(2px);
  display: none; align-items: flex-start; justify-content: center; z-index: 200; padding: 40px 16px; overflow-y: auto;
  opacity: 0; transition: opacity .18s ease;
}
.modal-bg.open { display: flex; opacity: 1; }
.modal {
  background: var(--panel); border: 1px solid var(--border-solid); border-radius: 16px;
  max-width: 540px; width: 100%; padding: 24px 26px; box-shadow: var(--shadow); position: relative;
  transform: translateY(8px); transition: transform .18s ease;
}
.modal-bg.open .modal { transform: translateY(0); }
.modal h2 { margin: 0 0 4px; font-size: 20px; }
.modal h3 { font-size: 14px; color: var(--accent); margin: 20px 0 8px; }
.modal p, .modal li { color: var(--cbd, var(--text)); font-size: 14px; }
.modal p { margin: 8px 0; }
.modal .close { position: absolute; top: 16px; right: 16px; }
.modal ul { padding-left: 18px; margin: 8px 0; }
.modal li { margin: 5px 0; }
.modal .ex { font-family: var(--mono); font-size: 13px; background: var(--panel-2); border: 1px solid var(--border-solid); border-radius: 10px; padding: 12px 14px; white-space: pre; overflow-x: auto; line-height: 1.6; }
.how-modal { max-width: 680px; padding: 0; border-radius: 8px; overflow: hidden; }
.how-modal .close { top: 14px; right: 14px; z-index: 1; }
.how-header { padding: 20px 58px 18px 24px; border-bottom: 1px solid var(--border-solid); background: rgba(30,32,37,.5); }
.how-header h2 { margin: 0 0 6px; font-size: 22px; }
.how-header p { max-width: 570px; margin: 0; color: var(--muted); line-height: 1.45; }
.how-grid { display: grid; grid-template-columns: 1.08fr .92fr; gap: 0; padding: 20px 24px; }
.how-section { min-width: 0; padding-right: 24px; }
.how-section + .how-section { padding: 0 0 0 24px; border-left: 1px solid var(--border-solid); }
.how-modal .how-section h3 { margin: 0 0 12px; color: var(--text); font-size: 13px; font-weight: 800; text-transform: uppercase; }
.how-list { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.how-modal .how-list li { display: grid; grid-template-columns: 14px minmax(0, 1fr); gap: 9px; align-items: start; margin: 0; color: var(--muted); font-size: 13px; line-height: 1.4; }
.how-list b { color: var(--text); }
.how-list .dot { margin-top: 4px; }
.how-star, .how-branch, .how-board { color: var(--good); font-size: 14px; font-style: normal; font-weight: 700; line-height: 1.25; text-align: center; }
.how-branch, .how-board { color: var(--muted); }
.how-rules { margin: 0; }
.how-rules > div { padding: 10px 0; border-bottom: 1px solid var(--border-solid); }
.how-rules > div:first-child { padding-top: 0; }
.how-rules > div:last-child { padding-bottom: 0; border-bottom: 0; }
.how-rules dt { color: var(--text); font-size: 13px; font-weight: 800; }
.how-rules dd { margin: 2px 0 0; color: var(--muted); font-size: 13px; line-height: 1.4; }
.how-footer { padding: 13px 24px 15px; border-top: 1px solid var(--border-solid); background: rgba(30,32,37,.5); }
.how-footer p { margin: 0; color: var(--muted); font-size: 12.5px; }
.how-footer b { color: var(--text); }
.how-footer .how-credit { margin-top: 5px; color: var(--muted-2); font-size: 11px; }
.how-footer a { color: var(--accent-hover); }
.tree-modal-bg { align-items: center; padding: 24px; overflow: hidden; }
/* Lock the page behind the fullscreen tree so the wheel can't scroll it. */
html:has(.tree-modal-bg.open) { overflow: hidden; }
.tree-modal {
  display: flex; flex-direction: column;
  width: calc(100vw - 48px); height: calc(100vh - 48px); height: calc(100dvh - 48px);
  max-width: none; padding: 0; border-radius: 14px; overflow: hidden;
  background: #20242c; border-color: #444b57;
}
.tree-modal-bg.open .tree-modal { animation: tree-modal-enter .42s cubic-bezier(.2,.75,.3,1) both; }
@keyframes tree-modal-enter {
  from { opacity: 0; transform: translateY(22px); }
  to { opacity: 1; transform: translateY(0); }
}
.tree-modal-header {
  display: flex; align-items: center; gap: 16px; flex: 0 0 54px;
  padding: 0 14px 0 20px; border-bottom: 1px solid var(--border-solid);
  background: linear-gradient(180deg, rgba(36,42,52,.96), rgba(28,32,40,.96));
}
.tree-modal-brand { display: flex; align-items: center; gap: 10px; transform: translateY(2px); }
.tree-modal-brand img { display: block; width: auto; height: 28px; }
.tree-modal-brand span { color: var(--text); font-size: 27px; line-height: 1; font-weight: 800; letter-spacing: -.02em; transform: translateY(-2px); }
.tree-modal-context { display: flex; gap: 3px; padding: 3px; border-radius: 7px; background: var(--surface); }
.tree-mode-tab {
  padding: 5px 10px; border: 0; border-radius: 5px; background: transparent;
  color: var(--muted); font: 700 13px var(--sans); cursor: pointer;
  transition: background .12s, color .12s;
}
.tree-mode-tab:hover:not(.active) { color: var(--text); }
.tree-mode-tab.active { color: var(--text); background: var(--panel-2); }
.tree-modal-close {
  display: inline-flex; align-items: center; gap: 7px; margin-left: auto;
  height: 32px; padding: 0 11px; border: 1px solid var(--border-solid); border-radius: 7px;
  background: transparent; color: var(--muted); cursor: pointer; font: 700 12px var(--sans);
}
.tree-modal-close:hover { color: var(--text); background: var(--panel-2); }
.tree-modal-close svg { width: 15px; height: 15px; }
.tree-modal-body {
  /* Inspector dark palette — defined here so both the inspector panel and its
     sibling collapse tab can read them. */
  --ins-card: #23262c;
  --ins-raise: #2a2d34;
  --ins-raise-hover: #32353d;
  --ins-border: #363a44;
  position: relative; display: grid; grid-template-columns: minmax(0, 1fr) 0px;
  flex: 1 1 auto; min-height: 0; overflow: hidden;
  transition: grid-template-columns .42s cubic-bezier(.4, 0, .2, 1);
}
.tree-modal.inspector-open .tree-modal-body { grid-template-columns: minmax(0, 1fr) 470px; }
.tree-stage {
  position: relative; min-width: 0; min-height: 0; overflow: hidden;
  background:
    radial-gradient(circle at 50% 40%, rgba(54,70,89,.22), transparent 48%),
    linear-gradient(145deg, #202630, #1c2129 65%, #20262e);
}
.tree-stage-intro {
  position: absolute; top: 24px; left: 28px; z-index: 3;
  display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 13.5px;
}
.tree-stage-intro svg { width: 22.5px; height: 22.5px; color: var(--text); }
/* Custom-tree add-opening search: sits where the intro is, shown only in custom mode. */
.tree-custom-search {
  position: absolute; top: 16px; left: 24px; z-index: 5;
  width: min(380px, 62%); margin: 0; display: none;
}
.tree-modal.is-custom .tree-custom-search { display: block; }
.tree-modal.is-custom .tree-stage-intro { display: none; }
.tree-custom-search input {
  width: 100%; padding: 11px 13px; font-size: 14px; font-family: inherit;
  background: rgba(30,32,37,.95); color: var(--text);
  border: 1px solid var(--border-solid); border-radius: 8px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.tree-custom-search input::placeholder { color: var(--muted-2); }
.tree-custom-search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(97,152,202,.22); }
.tree-modal-controls {
  position: absolute; top: 18px; right: 20px; z-index: 4;
  display: flex; align-items: center; gap: 2px; padding: 3px 6px;
  border: 1px solid var(--border-solid); border-radius: 9px;
  background: rgba(30,32,37,.92);
}
.tree-modal-controls .tree-tool {
  width: 28px; height: 26px; border-radius: 6px;
  color: var(--muted); background: transparent;
  transition: color .12s, background .12s;
}
.tree-modal-controls .tree-tool:hover { color: var(--text); background: var(--panel-2); }
.tree-modal-controls .tree-tool svg { width: 14px; height: 14px; }
.tree-zoom-slider {
  --zoom-progress: 21.05%;
  width: 112px; height: 4px; margin: 0 6px;
  appearance: none; border: 0; border-radius: 999px; outline: 0;
  background: linear-gradient(to right, var(--accent) 0 var(--zoom-progress), var(--border-solid) var(--zoom-progress) 100%);
  cursor: pointer;
}
.tree-zoom-slider::-webkit-slider-thumb {
  appearance: none; width: 10px; height: 10px; border: 0;
  border-radius: 50%; background: var(--accent);
}
.tree-zoom-slider::-moz-range-thumb {
  width: 10px; height: 10px; border: 0;
  border-radius: 50%; background: var(--accent);
}
.tree-zoom-slider:focus-visible { box-shadow: 0 0 0 2px rgba(97,152,202,.3); }
.tree--fullscreen {
  position: absolute; inset: 0; min-height: 0; padding: 0;
  background: transparent; border: 0; overscroll-behavior: contain;
}
.tree--fullscreen .tree-map { margin: 0 auto; }
.tree-stage-legend {
  position: absolute; left: 24px; bottom: 18px; z-index: 3;
  display: flex; align-items: center; gap: 22px; padding: 9px 12px;
  border: 1px solid var(--border-solid); border-radius: 7px;
  background: rgba(30,32,37,.88); color: var(--muted); font-size: 12.5px;
}
.tree-stage-legend span { display: inline-flex; align-items: center; gap: 7px; }
.legend-line { display: inline-block; width: 26px; height: 2px; background: var(--miss); }
.legend-line--target { height: 3px; background: var(--good); }
.tree-inspector {
  position: relative; min-width: 0; overflow: hidden;
  border-left: 1px solid transparent;
  background: #1b1e23;
  transition: border-color .18s ease;
}
.tree-modal.inspector-open .tree-inspector { border-left-color: var(--border-solid); }
.tree-inspector-scroll {
  width: 470px; height: 100%; overflow-y: auto; padding: 22px 18px 24px;
  opacity: 0; pointer-events: none;
  transition: opacity .42s linear;
  scrollbar-width: none;  /* content fits — hide the bar (still scrolls if a short window forces it) */
}
.tree-inspector-scroll::-webkit-scrollbar { display: none; }
.tree-modal.inspector-open .tree-inspector-scroll { opacity: 1; pointer-events: auto; }
.tree-inspector-collapse {
  position: absolute; right: 0; top: 14%; z-index: 5; width: 30px; height: 54px;
  display: flex; align-items: center; justify-content: center;
  transform: translateY(-50%); border: 1px solid var(--ins-border); border-right: 0;
  border-radius: 8px 0 0 8px; background: #1b1e23; color: var(--text);
  cursor: pointer; font: 700 26px/1 var(--sans);
  transition: right .42s cubic-bezier(.4, 0, .2, 1), background .12s ease;
}
/* Collapsed: chevron points left ("open"). Expanded: points right ("collapse"). */
.tree-inspector-collapse::before { content: "\2039"; }
.tree-inspector-collapse:hover { background: var(--ins-raise); }
.tree-modal.inspector-open .tree-inspector-collapse { right: 470px; }
.tree-modal.inspector-open .tree-inspector-collapse::before { content: "\203A"; }

/* ---- Current line (top row) ---- */
.tree-inspector-line { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 13px; }
.tree-inspector-line > div { min-width: 0; }
.tree-inspector-kicker { color: var(--muted); font-size: 11px; font-weight: 600; }
.tree-inspector-moves { min-height: 18px; margin: 3px 0 0; color: var(--accent); font: 700 13.5px/1.3 var(--mono); }
.tree-inspector-moves .num { color: var(--muted-2); }
.tree-inspector-moves .sh { color: var(--accent); }
.tree-inspector-moves .branch { color: var(--miss); }
.tree-inspector-moves .muted { color: var(--muted); font-family: var(--sans); }
.tree-inspector-nav { display: flex; gap: 6px; flex: 0 0 auto; margin-left: auto; }
.tree-inspector-nav .iconbtn {
  width: 30px; height: 30px; padding: 0; border-radius: 8px;
  border: 1px solid var(--ins-border); background: var(--ins-raise); color: var(--text);
  font-size: 18px; line-height: 1; transition: background .12s;
}
.tree-inspector-nav .iconbtn:hover { color: var(--text); background: var(--ins-raise-hover); }

/* ---- Board ---- */
/* Coordinates sit OUTSIDE the frame: a left gutter holds the ranks, a bottom
   gutter holds the files. The board overflows visibly so the labels (anchored
   to the edge squares) can escape its box. */
.tree-inspector-board {
  width: calc(100% - 48px); margin: 0 auto 32px;
  border-radius: 0; overflow: visible;
  box-shadow: 0 8px 24px rgba(0,0,0,.42);
}
.tree-inspector-board .sq .rk,
.tree-inspector-board .sq .fl {
  color: var(--muted); font-size: 11px;
}
.tree-inspector-board .sq .rk {
  top: 50%; left: auto; right: 100%; bottom: auto;
  margin-right: 9px; transform: translateY(-50%);
}
.tree-inspector-board .sq .fl {
  left: 50%; right: auto; top: 100%; bottom: auto;
  margin-top: 8px; transform: translateX(-50%);
}

/* ---- Opening info card ---- */
.tree-inspector-card {
  margin: 0 0 4px; padding: 16px; border: 1px solid var(--ins-border);
  border-radius: 12px; background: var(--ins-card);
}
.tree-inspector-title-row { display: flex; align-items: center; gap: 9px; }
.tree-inspector-mark { display: none; color: var(--accent-hover); font-size: 15px; }
.tree-inspector-card h3 { margin: 0; color: var(--text); font-size: 17px; line-height: 1.2; font-weight: 800; }
.tree-inspector-card .eco {
  margin-left: 2px; padding: 3px 9px; border-radius: 6px;
  background: rgba(255,255,255,.06); color: var(--muted); font: 700 10.5px var(--mono);
}
.tree-inspector-card .eco:empty { display: none; }
.tree-inspector-card-moves { margin-top: 9px; font: 700 13px/1.4 var(--mono); }
.tree-inspector-card-moves .num { color: var(--muted-2); }
.tree-inspector-card-moves .sh { color: var(--accent); }    /* correct: on the target path */
.tree-inspector-card-moves .branch { color: var(--miss); }  /* incorrect: diverged */
/* Only the puzzle's target opening shows the star and an accent name. */
.tree-inspector-card.is-target .tree-inspector-mark { display: inline; }
.tree-inspector-card.is-target h3 { color: var(--accent-hover); }
.tree-inspector-description {
  margin: 11px 0 0 !important; color: var(--muted) !important; font-size: 13px !important; line-height: 1.5;
}
.tree-inspector-description p { margin: 0; }
.tree-inspector-description p + p { margin-top: 8px; }
.tree-inspector-desc-toggle {
  display: block; margin: 5px 0 0; padding: 0; border: none; background: none;
  color: var(--accent-hover); font-size: 11px; font-weight: 600; cursor: pointer;
}
/* Inline variant: sits right after the truncated text as "… Click for more". */
.tree-inspector-desc-toggle.is-inline { display: inline; margin: 0; font-size: inherit; }
.tree-inspector-desc-toggle:hover { text-decoration: underline; }
.tree-inspector-source {
  display: inline-block; margin-top: 7px; color: var(--muted-2);
  font-size: 11px; font-weight: 600; text-decoration: none;
}
.tree-inspector-source:hover { color: var(--accent-hover); }
.tree-inspector-meta { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin-top: 15px; }
.tree-inspector-meta div {
  min-width: 0; padding: 11px 6px; text-align: center;
  border: 1px solid var(--ins-border); border-radius: 9px; background: rgba(255,255,255,.02);
}
.tree-inspector-meta span { display: block; color: var(--muted); font-size: 10.5px; }
.tree-inspector-meta b { display: block; overflow: hidden; margin-top: 4px; color: var(--text); font-size: 18px; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Action button stack ---- */
.tree-inspector-action {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; min-height: 46px; margin-top: 12px; border: 1px solid var(--ins-border);
  border-radius: 11px; background: var(--ins-raise);
  color: var(--text); cursor: pointer;
  font: 700 13px var(--sans);
  transition: background .12s, border-color .12s, filter .12s;
}
.tree-inspector-action:hover { background: var(--ins-raise-hover); }
.tree-inspector-action svg { width: 16px; height: 16px; color: var(--muted); }
.tree-inspector-card + .tree-inspector-action { margin-top: 16px; }
.tree-inspector-action-split {
  display: grid; grid-template-columns: 1fr 1fr; margin-top: 12px;
  overflow: hidden; border: 1px solid var(--ins-border); border-radius: 11px;
}
.tree-inspector-action-split .tree-inspector-action { margin: 0; border: 0; border-radius: 0; }
.tree-inspector-action-split .tree-inspector-action + .tree-inspector-action { border-left: 1px solid var(--ins-border); }
@media (max-width: 760px) {
  .tree-modal-bg { padding: 0; }
  .tree-modal { width: 100vw; height: 100vh; height: 100dvh; border-radius: 0; }
  .tree-modal-header { padding-left: 14px; }
  .tree-modal-brand span, .tree-stage-intro { display: none; }
  .tree-modal-context { margin-left: -8px; }
  .tree-modal-close span { display: none; }
  .tree-modal.inspector-open .tree-modal-body { grid-template-columns: minmax(0, 1fr) min(88vw, 360px); }
  .tree-modal.inspector-open .tree-inspector-collapse { right: min(88vw, 360px); }
  .tree-inspector-scroll { width: min(88vw, 360px); }
  .tree-modal-controls { top: 12px; right: 12px; }
  .tree-zoom-slider { width: 84px; }
}
@media (prefers-reduced-motion: reduce) {
  .tree-modal-bg.open .tree-modal { animation: none; }
  .tree-modal-body { transition: none; }
}
.dot { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.dot.good { background: var(--good); }
.dot.bad { background: var(--miss); }

/* ---- Stats ---- */
.stats-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.stats-controls .modes { margin-left: 0; }
.stats-controls .diff button { padding: 6px 10px; font-size: 13px; }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 16px 0 6px; }
.stat { text-align: center; }
.stat .n { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 11px; letter-spacing: .04em; text-transform: uppercase; margin-top: 2px; }
.dist { margin-top: 14px; }
.dist-row { display: flex; align-items: center; gap: 8px; margin: 4px 0; font-size: 13px; }
.dist-row .k { width: 22px; color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.dist-row .bar { background: var(--good-dim); color: var(--text); border-radius: 4px; padding: 1px 8px; min-width: 22px; text-align: right; font-variant-numeric: tabular-nums; font-size: 12px; }
.dist-row .bar.cur { background: var(--good); color: #14120e; font-weight: 700; }

/* ---- Win modal ---- */
.win-modal {
  max-width: 460px;
  text-align: center;
  background:
    radial-gradient(circle at 50% 100%, rgba(97,152,202,.16), transparent 58%),
    var(--panel);
}
.win-modal h2 {
  margin: 2px 42px 10px;
  color: var(--good);
  font-size: 32px;
  font-weight: 800;
}
.win-answer { margin: 0 auto 20px; color: var(--text); font-weight: 700; }
.win-answer .eco { color: var(--muted); font-family: var(--mono); font-size: 12px; margin-left: 6px; }
.win-answer .moves { display: block; margin-top: 5px; color: var(--muted); font-family: var(--mono); font-size: 12.5px; font-weight: 500; }
.win-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin: 18px 0 22px;
}
.win-stat .n { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.win-stat .l { color: var(--muted); font-size: 11px; letter-spacing: .04em; text-transform: uppercase; }
.win-modal p { margin: 0 0 14px; font-size: 16px; }
.win-actions { display: flex; justify-content: center; gap: 16px; flex-wrap: wrap; }
.win-actions .btn { min-width: 126px; }

/* ---- Site footer ---- */
.site-footer { margin-top: 44px; padding-top: 18px; border-top: 1px solid var(--border-solid); }
.foot-row {
  display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between;
  gap: 10px 28px;
}
.foot-legal { flex: 1 1 420px; min-width: 0; font-size: 11.5px; color: var(--muted-2); }
.foot-credits { margin: 0; line-height: 1.5; }
.foot-copy { font-weight: 600; margin-right: 8px; }
.foot-disclaimer { margin: 4px 0 0; opacity: .85; }
.foot-credits a { color: var(--muted-2); text-decoration: underline; text-underline-offset: 2px; }
.foot-credits a:hover { color: var(--accent-hover); }
.foot-links { display: flex; gap: 20px; flex-shrink: 0; }
.foot-links a { color: var(--muted); font-size: 13px; text-decoration: none; cursor: pointer; transition: color .12s; }
.foot-links a:hover { color: var(--text); }

@media (max-width: 620px) {
  .appbar { flex-wrap: wrap; gap: 10px; }
  .brand small { display: none; }
  .how-grid { grid-template-columns: 1fr; padding: 18px 20px; }
  .how-section { padding: 0; }
  .how-section + .how-section { margin-top: 18px; padding: 18px 0 0; border-top: 1px solid var(--border-solid); border-left: 0; }
  .how-header { padding-left: 20px; }
  .how-footer { padding-right: 20px; padding-left: 20px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .win-stats { grid-template-columns: repeat(2, 1fr); }
  .foot-row { flex-direction: column; align-items: flex-start; gap: 10px; }
}
