:root {
  --bg: #05070c;
  --bg2: #080c14;
  --panel: #0b1220cc;
  --line: #16324a;
  --cyan: #00f3ff;
  --cyan-dim: #00f3ff55;
  --mag: #ff2d6a;
  --mag-dim: #ff2d6a55;
  --ice: #d7fbff;
  --dim: #6d8aa0;
  --warn: #ffd000;
  --ok: #7cff6b;
  --sq-l: #1c4a63;
  --sq-d: #0d2433;
  --text: #e7f6ff;
  --dock: #070b12ee;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --label-textbook: #4da3ff;
  --label-brilliant: #ff2bd6;
  --label-great: #7cff6b;
  --label-best: #00f3ff;
  --label-excellent: #3dffc8;
  --label-good: #b8ff3c;
  --label-inaccuracy: #ffd400;
  --label-mistake: #ff8a00;
  --label-blunder: #ff2a2a;
  --label-miss: #ff4d8c;
  --label-forced: #8aa0b8;
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Bahnschrift, "Segoe UI Condensed", "Arial Narrow", "Helvetica Neue", sans-serif;
  letter-spacing: 0.04em;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

body {
  min-height: 100dvh;
  background:
    radial-gradient(1200px 600px at 10% -10%, #0a2a3d55, transparent 50%),
    radial-gradient(900px 500px at 110% 10%, #3a102455, transparent 45%),
    linear-gradient(180deg, #070b12 0%, #05070c 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(0, 243, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 243, 255, 0.035) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: radial-gradient(ellipse at 50% 30%, #000 20%, transparent 75%);
  z-index: 0;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.015) 0 1px,
    transparent 1px 3px
  );
  z-index: 50;
  mix-blend-mode: overlay;
}

#gate { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 20px; }
#gate[hidden] { display: none !important; }
#gate > .sheet-bg { background: #02050bce; backdrop-filter: blur(8px); }
#gate-form { position: relative; width: min(100%, 400px); max-height: calc(100dvh - 40px); overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 48px 30px 30px; background: #0b1220; border: 1px solid #25445a; border-radius: 16px; box-shadow: 0 24px 100px #0009; }
#gate-form label { font-size: 13px; color: #bdcdd9; margin-top: 6px; }
#gate-form input { font: inherit; letter-spacing: normal; color: var(--ice); background: #060d17; border: 1px solid #294153; border-radius: 7px; min-height: 46px; width: 100%; padding: 0 12px; user-select: text; }
#gate-form button { font: inherit; color: var(--ice); background: transparent; border: 1px solid var(--line); border-radius: 7px; min-height: 44px; cursor: pointer; }
#gate-form #gate-close { position: absolute; right: 10px; top: 8px; width: 36px; min-height: 36px; border: 0; color: #9bb0c0; font-size: 24px; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; background: #060d17; padding: 4px; border-radius: 9px; margin: 0 0 2px; }
#gate-form .auth-tabs button { border: 0; font-size: 13px; }
#gate-form .auth-tabs [aria-pressed="true"] { background: #1c3445; color: var(--cyan); }
.password-field { position: relative; }
#gate-form .password-field input { padding-right: 65px; }
#gate-form #gate-show-pass { position: absolute; right: 6px; top: 3px; min-height: 40px; border: 0; padding: 0 8px; color: #a6bed0; font-size: 12px; }
#gate-form #gate-login { background: var(--cyan); color: #031016; border-color: var(--cyan); font-weight: 600; }
#gate-form #gate-guest { border: 0; color: #9bb0c0; }
#gate-err { color: #ff819a; font-size: 13px; line-height: 1.4; letter-spacing: normal; }
#gate-err:empty { display: none; }
.field-help { color: #8fa9bc; font-size: 12px; line-height: 1.4; letter-spacing: normal; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }
button:disabled { opacity: .45; cursor: wait; }
.session-bar { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; gap: 10px; color: #8fa9bc; min-height: 30px; font-size: 12px; letter-spacing: .015em; }
.account-actions { display: flex; gap: 8px; flex-shrink: 0; }
.account-actions button, #btn-retry { background: #0c1d2a; border: 1px solid #234356; color: var(--cyan); font: inherit; padding: 7px 12px; border-radius: 6px; cursor: pointer; }
#status-bar { display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 26px; color: #91abba; font-size: 12px; letter-spacing: .025em; text-align: center; }
#status-bar.error { color: #ff819a; }
#btn-retry { padding: 3px 9px; }
@media (max-width: 500px) { #gate-form { padding: 42px 24px 24px; } .session-bar { font-size: 11px; } #session-note { max-width: 230px; } }

#app {
  position: relative;
  z-index: 1;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding:
    calc(28px + var(--safe-t))
    calc(12px + var(--safe-r))
    calc(12px + var(--safe-b))
    calc(12px + var(--safe-l));
  gap: 10px;
}

.top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
}

.ident {
  display: flex;
  align-items: baseline;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: inherit;
  padding: 8px 10px;
  min-height: 44px;
  cursor: pointer;
  clip-path: polygon(8px 0, 100% 0, 100% calc(100% - 8px), calc(100% - 8px) 100%, 0 100%, 0 8px);
}

.ident.you { justify-self: start; border-color: var(--cyan-dim); }
.ident.ai { justify-self: end; border-color: var(--mag-dim); }

.tag {
  font-size: 10px;
  letter-spacing: 0.22em;
  color: var(--dim);
}

.you .tag { color: var(--cyan); }
.ai .tag { color: var(--mag); }

.elo {
  font-variant-numeric: tabular-nums;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.brand {
  font-size: 13px;
  letter-spacing: 0.42em;
  color: var(--ice);
  opacity: 0.7;
  pointer-events: none;
}

.spark { color: var(--cyan); display: inline-flex; }
.spark.lg { color: var(--cyan); height: 36px; }

.spark svg { display: block; }

#busy {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 2px;
  z-index: 12;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, var(--cyan), var(--mag), transparent);
  background-size: 200% 100%;
  animation: scan 0.9s linear infinite;
  border: 0;
}

@keyframes scan {
  from { background-position: 100% 0; }
  to { background-position: -100% 0; }
}

.stage {
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.rail { display: none; }

.board-col {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.eval-track {
  position: relative;
  width: min(100%, 72vh);
  height: 8px;
  background: var(--mag);
  overflow: hidden;
  flex: 0 0 auto;
  clip-path: polygon(4px 0, 100% 0, calc(100% - 4px) 100%, 0 100%);
}

#eval-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 50%;
  background: var(--cyan);
  box-shadow: 0 0 12px var(--cyan);
  transition: width 0.22s ease;
}

#eval-txt {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 9px;
  letter-spacing: 0.12em;
  color: #041018;
  mix-blend-mode: difference;
  color: var(--ice);
}

#board-wrap {
  position: relative;
  width: min(100%, calc(100dvh - 220px), 720px);
  aspect-ratio: 1;
  flex: 0 1 auto;
  contain: layout;
}

#board-wrap::before,
#board-wrap::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border: 1.5px solid var(--cyan);
  pointer-events: none;
  z-index: 4;
}

#board-wrap::before {
  top: -5px;
  left: -5px;
  border-right: 0;
  border-bottom: 0;
}

#board-wrap::after {
  bottom: -5px;
  right: -5px;
  border-left: 0;
  border-top: 0;
  border-color: var(--mag);
}

#board {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  touch-action: none;
  background: #07141e;
  outline: 1px solid #123047;
}

.sq {
  position: relative;
  display: grid;
  place-items: center;
}

.sq.l { background: var(--sq-l); }
.sq.d { background: var(--sq-d); }

.sq.last {
  box-shadow: inset 0 0 0 999px rgba(0, 243, 255, 0.16);
}

.sq.sel {
  box-shadow: inset 0 0 0 2px var(--cyan), inset 0 0 18px rgba(0, 243, 255, 0.25);
}

.sq.check {
  box-shadow: inset 0 0 0 2px var(--mag), inset 0 0 22px rgba(255, 45, 106, 0.45);
  animation: pulse-check 1.1s ease-in-out infinite;
}

@keyframes pulse-check {
  50% { box-shadow: inset 0 0 0 2px var(--mag), inset 0 0 28px rgba(255, 45, 106, 0.7); }
}

.sq.hint-from,
.sq.hint-to {
  box-shadow: inset 0 0 0 2px var(--mag), inset 0 0 16px rgba(255, 45, 106, 0.35);
}

.sq.hint-to { animation: pulse-check 0.8s ease-in-out infinite; }

.sq.legal::after,
.sq.capture::after {
  content: "";
  position: absolute;
  z-index: 2;
  pointer-events: none;
}

.sq.legal::after {
  width: 22%;
  height: 22%;
  border-radius: 50%;
  background: rgba(0, 243, 255, 0.55);
  box-shadow: 0 0 8px var(--cyan);
}

.sq.capture::after {
  inset: 8%;
  border-radius: 50%;
  border: 3px solid rgba(255, 45, 106, 0.75);
  box-shadow: 0 0 8px var(--mag);
}

.sq .coord {
  position: absolute;
  font-size: 9px;
  letter-spacing: 0.08em;
  color: rgba(215, 251, 255, 0.45);
  pointer-events: none;
  z-index: 1;
}

.sq .coord.file { right: 3px; bottom: 2px; }
.sq .coord.rank { left: 3px; top: 2px; }

#pieces {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
}

#pieces .piece {
  position: absolute;
  left: 0;
  top: 0;
  width: 12.5%;
  height: 12.5%;
  padding: 0;
  box-sizing: border-box;
  object-fit: contain;
  pointer-events: none;
  display: block;
  will-change: transform;
  transform: translate(var(--tx, 0%), var(--ty, 0%)) scale(0.88);
  transition: transform 0.18s cubic-bezier(0.22, 0.8, 0.24, 1), opacity 0.16s ease;
}

#pieces .piece.king-fall {
  z-index: 7;
  transform-origin: 50% 88%;
  animation: king-fall 0.82s cubic-bezier(0.4, 0.02, 0.72, 0.18) forwards;
  filter: drop-shadow(0 0 12px var(--mag));
  transition: none;
}

#pieces .piece.king-gone {
  opacity: 0;
  animation: none;
}

@keyframes king-fall {
  0% {
    transform: translate(var(--tx), var(--ty)) scale(0.88) rotate(0deg);
  }
  22% {
    transform: translate(var(--tx), var(--ty)) scale(0.92) rotate(calc(var(--rot) * 0.18));
  }
  100% {
    transform: translate(var(--tx), calc(var(--ty) + 12%)) scale(0.88) rotate(var(--rot));
  }
}

#fx {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 8;
  overflow: hidden;
}

.shard {
  position: absolute;
  width: 6px;
  height: 6px;
  margin: -3px 0 0 -3px;
  border-radius: 1px;
  background: var(--shard, var(--cyan));
  box-shadow: 0 0 10px var(--shard, var(--cyan));
  animation: shard-fly 0.78s ease-out forwards;
}

.shard.long {
  width: 11px;
  height: 3px;
}

@keyframes shard-fly {
  to {
    transform: translate(var(--dx), var(--dy)) rotate(240deg) scale(0.15);
    opacity: 0;
  }
}

.piece.w { filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.45)); }
.piece.b { filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.55)); }

#ghost {
  position: fixed;
  width: 64px;
  height: 64px;
  pointer-events: none;
  z-index: 40;
  transform: translate(-50%, -50%);
}

.arrows {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 3;
}

#stamp {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  z-index: 6;
  font-size: clamp(22px, 7vw, 48px);
  font-weight: 700;
  letter-spacing: 0.2em;
  text-shadow: 0 0 18px currentColor, 0 0 42px currentColor;
  animation: stamp 1.15s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes stamp {
  0% { opacity: 0; transform: scale(1.35) skewX(-8deg); }
  18% { opacity: 1; transform: scale(1) skewX(0); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: scale(0.96); }
}

#promo {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  background: rgba(5, 7, 12, 0.55);
}

.promo-row {
  display: flex;
  gap: 8px;
  background: #0b1220;
  border: 1px solid var(--cyan);
  padding: 10px;
}

.promo-row button {
  width: 56px;
  height: 56px;
  background: #102232;
  border: 1px solid var(--line);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.promo-row img { width: 80%; height: 80%; }

#end {
  position: absolute;
  inset: 0;
  z-index: 9;
  display: grid;
  place-items: center;
  padding: 10px;
  overflow: auto;
  background: rgba(5, 7, 12, 0.78);
  backdrop-filter: blur(5px);
}

.end-card {
  width: min(92%, 340px);
  max-height: 100%;
  overflow: auto;
  padding: 20px 18px 14px;
  background: #0b1220;
  border: 1px solid var(--cyan-dim);
  text-align: center;
  clip-path: polygon(12px 0, 100% 0, 100% calc(100% - 12px), calc(100% - 12px) 100%, 0 100%, 0 12px);
}

#end-term {
  font-size: 11px;
  letter-spacing: 0.28em;
  color: var(--mag);
  margin-bottom: 4px;
}

#end-view {
  font-size: 28px;
  letter-spacing: 0.28em;
  margin-bottom: 6px;
}

#end-delta {
  font-size: 26px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.08em;
}

#end-delta.up { color: var(--cyan); }
#end-delta.down { color: var(--mag); }

#end-rating {
  font-size: 18px;
  letter-spacing: 0.12em;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}

#end-opp {
  color: var(--dim);
  font-size: 11px;
  letter-spacing: 0.16em;
  margin: 4px 0 12px;
}

.end-caps {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 8px 0 12px;
  text-align: left;
}

.end-cap {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 8px;
  align-items: center;
}

.end-cap .tag.you { color: var(--cyan); }
.end-cap .tag.ai { color: var(--mag); }

.cap-row {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  min-height: 26px;
  align-items: center;
}

.cap-row img {
  width: 22px;
  height: 22px;
  display: block;
}

#end-acc {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.14em;
  font-size: 16px;
  color: var(--cyan);
  margin-bottom: 8px;
}

#end-counts {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  color: var(--dim);
  font-size: 11px;
  letter-spacing: 0.12em;
  margin-top: 6px;
}

.end-chip {
  border: 1px solid color-mix(in srgb, currentColor 40%, transparent);
  padding: 3px 6px;
}

#end-new, .dock button, .seg button {
  font: inherit;
  letter-spacing: 0.18em;
  color: var(--ice);
  background: transparent;
  border: 1px solid var(--line);
  cursor: pointer;
}

#end-new {
  margin-top: 16px;
  width: 100%;
  height: 44px;
  border-color: var(--cyan);
}

#vsbest {
  width: min(100%, 72vh);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 6px;
  align-items: center;
  font-variant-numeric: tabular-nums;
  font-size: 13px;
}

.vb { display: flex; gap: 6px; align-items: baseline; min-width: 0; }
.vb:last-child { justify-content: flex-end; }
.vb .k { font-size: 9px; letter-spacing: 0.18em; color: var(--dim); }
.vb.acc {
  color: var(--cyan);
  font-size: 16px;
  letter-spacing: 0.08em;
}

#you-san, #best-san { color: var(--dim); overflow: hidden; text-overflow: ellipsis; }

#moves, .moves-rail {
  list-style: none;
  width: min(100%, 72vh);
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
  min-height: 28px;
}

#moves::-webkit-scrollbar { display: none; }

#moves li, .moves-rail li {
  flex: 0 0 auto;
  font-size: 12px;
  letter-spacing: 0.04em;
  padding: 4px 6px;
  border: 1px solid transparent;
  color: var(--ice);
}

#moves li .n, .moves-rail li .n { color: var(--dim); margin-right: 4px; }

#moves li[data-label], .moves-rail li[data-label] {
  border-color: color-mix(in srgb, currentColor 35%, transparent);
}

#pv, #pv-rail {
  width: min(100%, 72vh);
  min-height: 16px;
  font-size: 12px;
  color: var(--dim);
  letter-spacing: 0.08em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dock {
  display: flex;
  gap: 8px;
}

.dock button {
  flex: 1;
  min-height: 48px;
  background: var(--dock);
  border-color: var(--line);
}

.dock button:active { border-color: var(--cyan); color: var(--cyan); }
.dock button.on {
  border-color: var(--cyan);
  color: var(--cyan);
  box-shadow: inset 0 0 12px rgba(0, 243, 255, 0.12);
}
.dock button:disabled { opacity: 0.35; }
#btn-settings { letter-spacing: 0; min-width: 44px; padding: 7px 10px; }
#btn-play { min-width: 72px; }

#sheet { position: fixed; inset: 0; z-index: 30; }
.sheet-bg {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  border: 0;
  width: 100%;
  height: 100%;
}
.sheet-card {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 12px 16px calc(18px + var(--safe-b));
  background: #0b1220;
  border-top: 1px solid var(--cyan-dim);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sheet-handle {
  width: 42px;
  height: 4px;
  background: #1e3a50;
  border-radius: 2px;
  align-self: center;
  margin-bottom: 4px;
}
.sheet-elo { font-size: 32px; letter-spacing: 0.12em; }
.sheet-record { color: var(--dim); letter-spacing: 0.16em; font-size: 13px; }

.slider-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-variant-numeric: tabular-nums;
}

.bot-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  flex: 0 1 auto;
  min-height: 88px;
  max-height: min(42vh, calc(100dvh - 340px));
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.bot {
  appearance: none;
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 36px;
  padding: 5px 8px;
  background: #081018;
  border: 1px solid var(--line);
  color: var(--ice);
  font: inherit;
  font-size: 12px;
  letter-spacing: 0.04em;
  cursor: pointer;
  text-align: left;
}
.bot.on {
  border-color: var(--cyan);
  color: var(--cyan);
  background: #0b1c28;
  box-shadow: inset 0 0 10px rgba(0, 243, 255, 0.1);
}
.bot-emoji { font-size: 15px; letter-spacing: 0; line-height: 1; }
.bot-meta { display: flex; align-items: center; gap: 6px; min-width: 0; }
.bot-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bot.defeated .bot-name { text-decoration: line-through; color: var(--dim); }
.bot-status { display: flex; align-items: center; flex: 0 0 auto; }
.bot-crowns { letter-spacing: 0; font-size: 10px; line-height: 1; }
.bot-defeated { color: #ff2a2a; letter-spacing: 0.1em; font-size: 8px; }
.bot-elo { color: var(--dim); font-variant-numeric: tabular-nums; font-size: 11px; }
.bot.on .bot-elo { color: var(--cyan); }
.ident .tag.bot-emoji { letter-spacing: 0; font-size: 18px; }

#btn-reset-elo, #btn-reset-bots {
  font: inherit;
  letter-spacing: 0.18em;
  color: var(--ice);
  background: transparent;
  border: 1px solid var(--line);
  min-height: 44px;
  cursor: pointer;
}
#btn-reset-bots {
  align-self: start;
  min-height: 32px;
  padding: 0 2px;
  border: 0;
  color: var(--dim);
  letter-spacing: 0.16em;
  font-size: 11px;
}
#btn-reset-elo:active, #btn-reset-bots:active {
  border-color: var(--mag);
  color: var(--mag);
}
#btn-reset-bots:active { border-color: transparent; }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 24px;
  background: transparent;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 3px;
  background: linear-gradient(90deg, var(--mag), var(--cyan));
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -8px;
  background: var(--ice);
  border: 2px solid var(--cyan);
  box-shadow: 0 0 8px var(--cyan);
}

.seg {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.seg button { min-height: 44px; }
.seg button.on { border-color: var(--cyan); color: var(--cyan); }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.panel-elo { font-size: 28px; letter-spacing: 0.1em; }
.panel-record, .panel-peak { color: var(--dim); font-size: 12px; letter-spacing: 0.14em; }

[hidden] { display: none !important; }

@media (min-width: 960px) {
  #app { grid-template-rows: auto 1fr auto; max-width: 1400px; margin: 0 auto; padding-top: calc(36px + var(--safe-t)); }
  .ident.you { cursor: pointer; }
  .stage {
    grid-template-columns: 220px minmax(0, 1fr) 240px;
    align-items: start;
  }
  .rail {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  #board-wrap {
    width: min(100%, 72vh, 680px);
  }
  .eval-track { width: min(100%, 72vh, 680px); }
  #vsbest, #moves, #pv { width: min(100%, 72vh, 680px); }
  .moves-rail {
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    max-height: 58vh;
    width: 100%;
  }
  #moves { display: none; }
  #pv { display: none; }
}

@media (orientation: landscape) and (max-height: 560px) {
  #app {
    grid-template-columns: minmax(210px, 48vh) 1fr;
    grid-template-rows: auto 1fr auto;
  }
  .top { grid-column: 2; }
  .stage {
    grid-column: 1;
    grid-row: 1 / span 2;
  }
  .dock { grid-column: 2; }
  .brand { display: none; }
  #moves { display: none; }
  #board-wrap { width: min(100%, calc(100dvh - 24px)); }
}

.label-textbook { color: var(--label-textbook); }
.label-brilliant { color: var(--label-brilliant); }
.label-great { color: var(--label-great); }
.label-best { color: var(--label-best); }
.label-excellent { color: var(--label-excellent); }
.label-good { color: var(--label-good); }
.label-inaccuracy { color: var(--label-inaccuracy); }
.label-mistake { color: var(--label-mistake); }
.label-blunder { color: var(--label-blunder); }
.label-miss { color: var(--label-miss); }
.label-forced { color: var(--label-forced); }

html[data-board="nexus"] {
  --sq-l: #1c4a63;
  --sq-d: #0d2433;
}
html[data-board="ice"] {
  --sq-l: #d7e6f0;
  --sq-d: #5a7d94;
}
html[data-board="ice"] .sq .coord { color: rgba(8, 18, 28, 0.45); }
html[data-board="ember"] {
  --sq-l: #6a2a2a;
  --sq-d: #241014;
}
html[data-board="grove"] {
  --sq-l: #3d6b52;
  --sq-d: #14261c;
}
html[data-board="graphite"] {
  --sq-l: #6b7380;
  --sq-d: #2a3038;
}
html[data-board="sand"] {
  --sq-l: #e0c9a0;
  --sq-d: #8a6a42;
}
html[data-board="sand"] .sq .coord { color: rgba(40, 24, 8, 0.5); }

#settings { position: fixed; inset: 0; z-index: 32; }
#settings > .sheet-bg { background: #02050bce; backdrop-filter: blur(8px); }
#settings .settings-card {
  gap: 10px;
  padding: 10px 14px calc(14px + var(--safe-b));
  max-height: calc(100dvh - 10px);
  overflow: hidden;
  border-radius: 14px 14px 0 0;
}
.settings-title {
  font-size: 12px;
  letter-spacing: 0.32em;
  color: var(--ice);
}
.settings-tools {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 0 0 auto;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.settings-flags {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.settings-flags button {
  font: inherit;
  letter-spacing: 0.16em;
  color: var(--ice);
  background: transparent;
  border: 1px solid var(--line);
  min-height: 40px;
  cursor: pointer;
}
.settings-flags button.on {
  border-color: var(--cyan);
  color: var(--cyan);
  box-shadow: inset 0 0 10px rgba(0, 243, 255, 0.1);
}
#settings .seg button { min-height: 40px; }
.swatch-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}
.swatch {
  appearance: none;
  border: 1px solid var(--line);
  background: #081018;
  color: var(--dim);
  min-height: 52px;
  padding: 6px 2px 5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  font: inherit;
  letter-spacing: 0.08em;
  font-size: 9px;
}
.swatch.on {
  border-color: var(--cyan);
  color: var(--cyan);
  box-shadow: inset 0 0 10px rgba(0, 243, 255, 0.1);
}
.swatch-pieces {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1px;
  height: 22px;
}
.swatch-pieces img {
  width: 20px;
  height: 20px;
  display: block;
}
.swatch-board {
  width: 22px;
  height: 22px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  outline: 1px solid rgba(255,255,255,0.08);
}
.swatch-board i:nth-child(1),
.swatch-board i:nth-child(4) { background: var(--a); }
.swatch-board i:nth-child(2),
.swatch-board i:nth-child(3) { background: var(--b); }
@media (max-width: 380px) {
  .swatch { font-size: 7px; letter-spacing: 0.04em; min-height: 48px; padding: 5px 1px 4px; }
  .swatch-pieces { height: 18px; }
  .swatch-pieces img { width: 16px; height: 16px; }
  .swatch-board { width: 18px; height: 18px; }
}

@media (min-width: 960px) {
  #settings .settings-card {
    left: 50%;
    right: auto;
    bottom: auto;
    top: 50%;
    transform: translate(-50%, -50%);
    width: min(560px, 92vw);
    border: 1px solid var(--cyan-dim);
    border-radius: 12px;
    max-height: min(82vh, 760px);
    overflow: hidden;
    padding: 16px 18px 18px;
  }
  .bot-list {
    grid-template-columns: 1fr 1fr 1fr;
    max-height: min(46vh, 420px);
  }
}

/* Reserve room for account controls, move feedback, and the dock at every size. */
.board-col { --board-size: min(100%, max(180px, calc(100dvh - 340px)), 680px); }
#board-wrap, .eval-track, #vsbest, #moves, #pv { width: var(--board-size); }
#board-wrap { flex: none; }
#pv:empty, #pv-rail:empty { display: none; }
.sheet-card { max-height: calc(100dvh - 30px); overflow-y: auto; }
@media (orientation: landscape) and (max-height: 560px) {
  .board-col { --board-size: min(100%, max(160px, calc(100dvh - 140px))); }
  #settings .settings-card { overflow-y: auto; }
  .bot-list { max-height: 28vh; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

.top { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); }
.ident { min-width: 0; max-width: 100%; }
.ident .tag { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ident .elo { flex-shrink: 0; }
.ident.ai .tag { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 42vw; }
.brand { white-space: nowrap; }
@media (max-width: 500px) {
  .ident { gap: 5px; padding: 8px; }
  .ident .elo { font-size: 18px; }
  .brand { letter-spacing: .1em; font-size: 10px; }
  .top { gap: 6px; }
}

#resign { position: fixed; inset: 0; z-index: 36; }
.resign-card { gap: 14px; text-align: center; }
#resign-copy { font-size: 16px; line-height: 1.4; color: var(--ice); letter-spacing: 0.02em; }
#resign-elo { font-size: 32px; letter-spacing: 0.08em; font-variant-numeric: tabular-nums; color: var(--mag); min-height: 1em; }
#resign-elo:empty { display: none; }
#resign-confirm, #resign-cancel {
  font: inherit;
  letter-spacing: 0.16em;
  min-height: 48px;
  cursor: pointer;
}
#resign-confirm { background: var(--mag); color: #14040a; border: 1px solid var(--mag); }
#resign-cancel { background: #0c1d2a; color: var(--ice); border: 1px solid #234356; }

#play { position: fixed; inset: 0; z-index: 34; }
.play-card { gap: 12px; }
#btn-hotseat, #btn-queue {
  font: inherit;
  letter-spacing: 0.16em;
  color: var(--ice);
  background: #0c1d2a;
  border: 1px solid #234356;
  min-height: 48px;
  cursor: pointer;
}
#btn-queue.on {
  border-color: var(--cyan);
  color: var(--cyan);
}
.online-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 40vh;
  overflow-y: auto;
}
.online-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  color: var(--ice);
  letter-spacing: 0.08em;
  font-size: 14px;
}
.online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 8px var(--ok);
  flex-shrink: 0;
}
.online-rating { margin-left: auto; color: var(--dim); font-variant-numeric: tabular-nums; }
.sheet-name { color: var(--cyan); letter-spacing: 0.18em; font-size: 12px; }
.history-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 36vh;
  overflow-y: auto;
}
.history-row {
  display: grid;
  grid-template-columns: 22px 1fr auto auto;
  gap: 8px;
  align-items: center;
  font-size: 13px;
  letter-spacing: 0.04em;
}
.history-row .res-w { color: var(--ok); }
.history-row .res-l { color: var(--mag); }
.history-row .res-d { color: var(--dim); }
.history-opp { color: var(--ice); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-delta { font-variant-numeric: tabular-nums; }
.history-delta.up { color: var(--ok); }
.history-delta.down { color: var(--mag); }
@media (min-width: 960px) {
  .play-card, .resign-card, #sheet .sheet-card {
    left: 50%;
    right: auto;
    bottom: auto;
    top: 50%;
    transform: translate(-50%, -50%);
    width: min(420px, 90vw);
    border: 1px solid var(--cyan-dim);
    max-height: 82vh;
    overflow: auto;
  }
}
