:root {
  --bg: #1b1f23;
  --panel: #23282e;
  --line: #363d45;
  --text: #ebe6da;
  --muted: #9aa1a8;
  --brass: #c8a35a;
  --danger: #c8604f;
  --light: #eeeed2;
  --dark: #769656;
  --sq: min(calc((100vh - 64px) / 8), calc((100vw - 360px - 64px) / 8));
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: 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); font-family: var(--sans); }
body { display: flex; }

.panel {
  width: 360px; flex: none; height: 100vh; overflow-y: auto;
  background: var(--panel); border-right: 1px solid var(--line);
  padding: 20px; display: flex; flex-direction: column; gap: 16px;
}
.view { display: flex; flex-direction: column; gap: 16px; flex: 1; min-height: 0; }
.view[hidden] { display: none; }
h1 { font-family: var(--serif); font-weight: 600; font-size: 28px; margin: 0; letter-spacing: .01em; }
.group { display: flex; flex-direction: column; gap: 10px; }
.group.two { flex-direction: row; gap: 12px; }
.group.two > div { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
label, .label { font-size: 13px; color: var(--muted); }
output { color: var(--brass); font-weight: 600; }
.elo-out { font-family: var(--serif); font-size: 18px; }

select, button {
  font: inherit; color: var(--text); background: #2d343b; border: 1px solid var(--line);
  border-radius: 6px; padding: 8px 10px; cursor: pointer;
}
select { min-width: 0; }
button:hover:not(:disabled), select:hover { border-color: var(--brass); }
button:disabled { opacity: .4; cursor: not-allowed; }
button.primary { background: var(--brass); color: #1b1f23; border-color: var(--brass); font-weight: 600; }
button.danger { color: var(--danger); }
:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
input[type=range] { width: 100%; accent-color: var(--brass); }

.moves-wrap { flex: 1; min-height: 140px; display: flex; flex-direction: column; gap: 6px; }
.moves {
  flex: 1; overflow-y: auto; background: #1d2126; border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 0; font-variant-numeric: tabular-nums;
}
.mv-row { display: grid; grid-template-columns: 44px 1fr 1fr; padding: 3px 10px; font-size: 15px; }
.mv-row:nth-child(even) { background: #21262b; }
.mv-row .n { color: var(--muted); }
.mv-row .cur { color: var(--brass); font-weight: 600; }

.status { min-height: 40px; font-family: var(--serif); font-size: 17px; line-height: 1.3; }
.actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }

.stage { flex: 1; display: flex; align-items: center; justify-content: center; min-width: 0; }
.board-frame { padding: 10px; background: #14171a; border-radius: 4px; box-shadow: 0 10px 40px rgba(0,0,0,.45); }
.board {
  width: calc(var(--sq) * 8); height: calc(var(--sq) * 8);
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
  user-select: none; touch-action: none;
}
.sq { position: relative; background: var(--light); }
.sq.dark { background: var(--dark); }
.sq.last::before { content: ""; position: absolute; inset: 0; background: rgba(255, 214, 10, .38); }
.sq.sel::before { content: ""; position: absolute; inset: 0; background: rgba(60, 150, 255, .45); }
.sq.check::before { content: ""; position: absolute; inset: 0; background: radial-gradient(circle, rgba(220,40,30,.9) 0%, rgba(220,40,30,0) 70%); }
.sq.hint::after { content: ""; position: absolute; left: 35%; top: 35%; width: 30%; height: 30%; border-radius: 50%; background: rgba(20, 20, 20, .28); z-index: 3; }
.sq.hint.cap::after { left: 4%; top: 4%; width: 92%; height: 92%; background: none; border: calc(var(--sq) * .08) solid rgba(20,20,20,.28); }
.coord { position: absolute; font-size: calc(var(--sq) * .17); font-weight: 600; opacity: .75; pointer-events: none; z-index: 1; color: var(--dark); }
.sq.dark .coord { color: var(--light); }
.coord.f { right: 4%; bottom: 2%; }
.coord.r { left: 4%; top: 2%; }

.piece { position: absolute; inset: 0; z-index: 2; background-size: 100% 100%; cursor: grab; }
.piece.glyph { display: flex; align-items: center; justify-content: center; font-size: calc(var(--sq) * .8); line-height: 1; background: none; }
.piece.glyph.w { color: #fff; -webkit-text-stroke: calc(var(--sq) * .02) #222; }
.piece.glyph.b { color: #222; -webkit-text-stroke: calc(var(--sq) * .015) #000; }
.piece.dragging { opacity: .25; }
.piece.ghost { position: fixed; inset: auto; z-index: 100; pointer-events: none; cursor: grabbing; }
.board.locked .piece { cursor: default; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; z-index: 200; }
.modal[hidden] { display: none; }
.modal-box { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 18px; text-align: center; }
.modal-box p { margin: 0 0 12px; font-family: var(--serif); font-size: 18px; }
.promo-choices { display: flex; gap: 10px; }
.promo-choices button { position: relative; width: 76px; height: 76px; padding: 0; background: var(--light); }
.promo-choices .piece { cursor: pointer; }

@media (max-width: 860px) {
  :root { --sq: calc((100vw - 44px) / 8); }
  body { flex-direction: column-reverse; height: auto; }
  html, body { height: auto; }
  .panel { width: 100%; height: auto; border-right: 0; border-top: 1px solid var(--line); }
  .stage { padding: 12px 0; }
  .moves-wrap { min-height: 180px; }
}
@media (prefers-reduced-motion: no-preference) { button, select { transition: border-color .15s; } }

/* ---- analysis ---- */
.status.small { font-size: 15px; min-height: 44px; }
.nav { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.actions.two-col { grid-template-columns: 1fr 1fr; }
.an-table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.an-table th { font-weight: 400; color: var(--muted); text-align: right; padding: 2px 0 6px; }
.an-table th:first-child { text-align: left; }
.an-table td { text-align: right; padding: 3px 0; }
.an-table td:first-child { text-align: left; }
.an-table .acc td { font-family: var(--serif); font-size: 26px; padding-bottom: 8px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 8px; }
.c-best { --c: #7fae4f; } .c-good { --c: #8a9199; } .c-inaccuracy { --c: #d9b73f; }
.c-mistake { --c: #e08a3c; } .c-blunder { --c: #d0523f; }
.dot { background: var(--c); }
#anGraph svg { width: 100%; height: auto; display: block; cursor: pointer; border-radius: 6px; }
.mv-row .mvb { cursor: pointer; border-radius: 4px; padding: 0 4px; margin-left: -4px; }
.mv-row .mvb:hover { background: #2d343b; }
.mv-row .mvb.sel { background: #3a4148; color: var(--brass); font-weight: 600; }
.mv-row .mvb.bad { color: var(--c); }
.sq.bestsq { box-shadow: inset 0 0 0 calc(var(--sq) * .06) #7fae4f; }
.evalbar { position: relative; width: 24px; height: calc(var(--sq) * 8 + 20px); margin-right: 12px; background: #2b3036;
  border-radius: 3px; overflow: hidden; display: flex; flex-direction: column; justify-content: flex-end; }
.evalbar[hidden] { display: none; }
.evalbar.flip { justify-content: flex-start; }
#evalFill { background: #ece8dc; width: 100%; height: 50%; transition: height .2s; }
#evalNum { position: absolute; left: 0; right: 0; font-size: 10px; text-align: center; color: #888; bottom: 3px; }
.evalbar.flip #evalNum { bottom: auto; top: 3px; }
:root.an { --sq: min(calc((100vh - 64px) / 8), calc((100vw - 360px - 110px) / 8)); }
@media (max-width: 860px) { :root.an { --sq: calc((100vw - 80px) / 8); } .stage { padding-left: 8px; } }
