/* Layout and component styles. Colors come only from theme.css variables. */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

button, [data-ply], .game-item {
  touch-action: manipulation; /* no double-tap zoom delay when tapping quickly */
  -webkit-tap-highlight-color: transparent;
}

body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: 14px;
  overflow: hidden;
}

a { color: var(--color-accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Buttons ---------- */

.btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  cursor: pointer;
  transition: background-color 0.15s, transform 0.05s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: default; transform: none; }
.btn:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }

.btn-primary { background: var(--color-primary); color: var(--color-on-primary); }
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-primary:active { background: var(--color-primary-active); }

.btn-accent { background: var(--color-accent); color: var(--color-on-accent); }
.btn-accent:hover { background: var(--color-accent-hover); }

.btn-ghost { background: transparent; color: var(--color-text); border-color: var(--color-border); }
.btn-ghost:hover { background: var(--color-surface-3); }

.btn-block { width: 100%; padding: 12px; font-size: 16px; }

/* Text inputs: 16px text keeps iOS from zooming in on focus. */
.search input, .field input {
  font: inherit;
  font-size: 16px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface-2);
  color: var(--color-text);
}
.search input::placeholder, .field input::placeholder { color: var(--color-text-faint); }
.search input:focus, .field input:focus { outline: none; border-color: var(--color-primary-hover); }

.btn-big {
  width: 260px;
  padding: 18px 24px;
  font-size: 22px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- Screens ---------- */

.screen { height: 100vh; }

/* ---------- Sign in ---------- */

.login {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: radial-gradient(circle at 50% 40%, var(--color-surface-2), var(--color-bg) 70%);
}
.login-card {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 28px 24px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.login-card .brand { justify-content: center; }
.login-card .brand h1 { font-size: 48px; }
.login-lead { margin: 0; text-align: center; color: var(--color-text-muted); }
.login-error {
  margin: 0;
  padding: 10px 12px;
  border-left: 3px solid var(--color-error);
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
  color: var(--color-error);
  font-weight: 600;
}

/* ---------- Home ---------- */

.home {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr) var(--sidebar-width);
}

.home-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  background: radial-gradient(circle at 50% 40%, var(--color-surface-2), var(--color-bg) 70%);
}

.brand { display: flex; align-items: center; gap: 14px; }
/* The logo is 32x32 pixel art: show it at exact multiples of 32px, scaled without smoothing. */
.brand img {
  width: 64px;
  height: 64px;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}
.brand h1 {
  margin: 0;
  font-size: 64px;
  letter-spacing: -1px;
  color: var(--color-accent);
}
.home-main .brand { margin-bottom: 24px; }

.home-actions { display: flex; flex-direction: column; gap: 16px; }

.account {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  margin-top: 10px;
  padding: 6px 6px 6px 8px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 999px;
}
.account-avatar {
  flex: none;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 50%;
  background: var(--color-primary);
  color: var(--color-on-primary);
  font-weight: 700;
}
.account-avatar img { width: 100%; height: 100%; object-fit: cover; }
.account-text {
  min-width: 0;
  color: var(--color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account-text b { color: var(--color-text); }
.btn-small { flex: none; padding: 6px 14px; font-size: 13px; border-radius: 999px; }
.btn-settings { width: 260px; margin-top: 4px; padding: 10px 16px; font-size: 16px; }

/* ---------- Settings window ---------- */

.settings-card { max-height: calc(100dvh - 32px); overflow-y: auto; }
.volume-row { display: flex; align-items: center; gap: 12px; }
.volume-row input[type="range"] { flex: 1; accent-color: var(--color-primary-hover); }
.volume-value { min-width: 42px; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.choice-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.choice-grid.boards { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); }
.choice {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
  color: var(--color-text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.choice:hover { background: var(--color-surface-3); }
.choice.active { border-color: var(--color-accent); }
.choice-label { display: flex; align-items: center; gap: 6px; }
.piece-preview { display: flex; }
.piece-preview img { width: 36px; height: 36px; }
.board-swatch {
  width: 48px;
  height: 48px;
  border-radius: 4px;
  background: conic-gradient(var(--swatch-dark) 25%, var(--swatch-light) 0 50%, var(--swatch-dark) 0 75%, var(--swatch-light) 0);
}
.custom-colors { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.custom-colors input[type="color"] {
  width: 100%;
  height: 40px;
  padding: 2px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
  cursor: pointer;
}
.settings-preview { display: grid; grid-template-columns: repeat(6, 1fr); border-radius: var(--radius-sm); overflow: hidden; }
.preview-sq { aspect-ratio: 1; display: grid; place-items: center; }
.preview-sq.light { background: var(--board-light); }
.preview-sq.dark { background: var(--board-dark); }
.preview-sq img { width: 100%; height: 100%; }

.sidebar-left { border-left: none; border-right: 1px solid var(--color-border); }
.sidebar-heading {
  display: flex;
  align-items: center;
  min-height: 40px;
  padding: 0 4px;
  font-size: 17px;
  font-weight: 800;
  color: var(--color-accent);
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  padding: 16px;
  gap: 12px;
}

.search { position: relative; display: flex; gap: 8px; }
.search input { flex: 1; min-width: 0; }

.suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 10;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.suggestion {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.suggestion:hover, .suggestion.active { background: var(--color-surface-3); }
.suggestion-remove {
  border: none;
  background: none;
  color: var(--color-text-faint);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}
.suggestion-remove:hover { color: var(--color-error); }

.profile {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  background: var(--color-surface-2);
  border-radius: var(--radius);
}
.avatar { width: 48px; height: 48px; border-radius: var(--radius-sm); object-fit: cover; }
.avatar-placeholder {
  display: grid;
  place-items: center;
  background: var(--color-primary);
  color: var(--color-on-primary);
  font-weight: 700;
  font-size: 20px;
}
.profile-name { font-size: 17px; font-weight: 700; display: flex; align-items: center; gap: 6px; }
.profile-name a { color: var(--color-text); }
.profile-sub { color: var(--color-text-muted); font-size: 13px; }
.title-badge {
  background: var(--color-loss);
  color: var(--color-on-primary);
  font-size: 11px;
  padding: 1px 5px;
  border-radius: 3px;
}

.status { color: var(--color-text-muted); font-size: 13px; }
.status.error { color: var(--color-error); }

.games-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.game-item {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px;
  background: var(--color-surface-2);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.game-item:hover, .game-item:focus-visible {
  border-color: var(--color-primary-hover);
  background: var(--color-surface-3);
  outline: none;
}
.game-result {
  flex: none;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  font-size: 20px;
  font-weight: 800;
  line-height: 1;
  color: var(--color-bg);
}
.result-win { background: var(--color-win); }
.result-loss { background: var(--color-loss); }
.result-draw { background: var(--color-draw); }

.pager {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px;
  padding-top: 4px;
}
.pager-btn {
  min-width: 34px;
  height: 34px;
  padding: 0 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
  color: var(--color-text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.pager-btn:hover:not(:disabled) { background: var(--color-surface-3); }
.pager-btn.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--color-on-primary);
  cursor: default;
}
.pager-btn:disabled:not(.active) { opacity: 0.4; cursor: default; }
.pager-gap { padding: 0 2px; color: var(--color-text-faint); }
.game-info { min-width: 0; flex: 1; }
.game-players { display: flex; align-items: center; gap: 5px; font-weight: 600; min-width: 0; }
.game-opponent { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.game-rating { color: var(--color-text-muted); font-weight: 400; }
.vs { color: var(--color-text-faint); font-weight: 400; }
.game-meta {
  color: var(--color-text-muted);
  font-size: 12px;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.color-dot {
  flex: none;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid var(--color-border);
}
.color-dot.white { background: var(--eval-white); }
.color-dot.black { background: var(--eval-black); }

/* ---------- Analysis ---------- */

.analysis {
  display: grid;
  grid-template-columns: minmax(0, 1fr); /* long one-line titles must truncate, not widen the page */
  grid-template-rows: auto minmax(0, 1fr);
  --board-size: min(calc(100vh - 210px), calc(100vw - var(--panel-width) - 120px));
}
/* Room boards have no eval bar but may have the piece palette underneath. */
.analysis.room { --board-size: min(calc(100vh - 260px), calc(100vw - var(--panel-width) - 80px)); }
/* The host also gets a column of saved-position previews between the board and the side panel. */
.analysis.room.has-slots { --board-size: min(calc(100vh - 260px), calc(100vw - var(--panel-width) - 390px)); }
.analysis.room.has-slots .analysis-body { grid-template-columns: minmax(0, 1fr) 296px var(--panel-width); }

.room-slots { overflow-y: auto; gap: 8px; }
.slot-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 8px; }
.slot { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.slot-head { display: flex; align-items: center; gap: 3px; }
.slot-num { flex: 1; font-size: 12px; font-weight: 800; color: var(--color-text-muted); }
.slot-act {
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid var(--color-border);
  border-radius: 5px;
  background: var(--color-surface-2);
  color: var(--color-text);
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
}
.slot-act:hover:not(:disabled) { background: var(--color-surface-3); }
.slot-act:disabled { opacity: 0.3; cursor: default; }
.kick-btn {
  flex: none;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--color-border);
  border-radius: 5px;
  background: var(--color-surface-3);
  color: var(--color-text-muted);
  font: inherit;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
}
.kick-btn:hover { background: var(--color-loss); color: var(--color-on-primary); }
.slot-board {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1; /* every slot is the same size, filled or empty */
  padding: 0;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  background: none;
  cursor: pointer;
  overflow: hidden;
}
.slot-board:hover { border-color: var(--color-accent); }
.mini-board {
  position: absolute;
  inset: 0;
  background: conic-gradient(var(--board-dark) 25%, var(--board-light) 0 50%, var(--board-dark) 0 75%, var(--board-light) 0) 0 0 / 25% 25%;
}
.mini-piece { position: absolute; width: 12.5%; height: 12.5%; }
.slot.vacant .mini-board { filter: brightness(0.35); } /* an empty slot is a darkened empty board */

.analysis-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}
.analysis-header .btn { flex: none; white-space: nowrap; }
.game-title { display: flex; flex-direction: column; min-width: 0; }
.game-title-players, .game-title-meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.game-title-players { font-weight: 700; }
.game-title-meta {
  color: var(--color-text-muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.analysis-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--panel-width);
  gap: 16px;
  padding: 16px;
  min-height: 0;
}

.board-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.player-bar {
  width: calc(var(--board-size) + 34px);
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 34px;
  font-weight: 600;
}
.player-rating { color: var(--color-text-muted); font-weight: 400; }
.player-accuracy {
  margin-left: auto;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  background: var(--color-surface-3);
  font-size: 12px;
}

.board-row { display: flex; gap: 8px; }

.eval-bar {
  position: relative;
  width: 26px;
  height: var(--board-size);
  background: var(--eval-black);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.eval-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 50%;
  background: var(--eval-white);
  transition: height 0.3s ease;
}
.eval-bar.flipped .eval-fill { bottom: auto; top: 0; }
.eval-text {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 4px;
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  color: var(--eval-text-on-white);
}
.eval-bar.black-ahead .eval-text { bottom: auto; top: 4px; color: var(--eval-text-on-black); }
.eval-bar.flipped .eval-text { bottom: auto; top: 4px; }
.eval-bar.flipped.black-ahead .eval-text { top: auto; bottom: 4px; }

/* Board */
.board {
  position: relative;
  width: var(--board-size);
  height: var(--board-size);
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: var(--radius-sm);
  overflow: hidden;
  user-select: none;
  box-shadow: var(--shadow);
}
.sq { position: relative; }
.sq.light { background: var(--board-light); }
.sq.dark { background: var(--board-dark); }
.sq.hl::after { content: ''; position: absolute; inset: 0; background: var(--board-highlight); }
.piece { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 1; }
.coord {
  position: absolute;
  z-index: 2;
  font-size: calc(var(--board-size) / 8 * 0.18);
  font-weight: 700;
  line-height: 1;
}
.coord-rank { top: 3px; left: 3px; }
.coord-file { bottom: 3px; right: 4px; }
.sq.light .coord { color: var(--board-coord-on-light); }
.sq.dark .coord { color: var(--board-coord-on-dark); }
.arrows { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 3; pointer-events: none; }

/* Interactive boards (room screen): selection, legal-move targets, check, drag & drop. */
.board.interactive { touch-action: none; } /* drags shouldn't scroll the page */
.board.interactive .sq { cursor: pointer; }
.sq.sel::before, .sq.pre::before, .sq.in-check::before { content: ''; position: absolute; inset: 0; }
.sq.sel::before { background: var(--board-selected); }
.sq.pre::before { background: var(--board-premove); }
.sq.in-check::before { background: radial-gradient(circle, var(--board-check) 0%, transparent 72%); }
.target-dot, .target-ring { position: absolute; z-index: 2; border-radius: 50%; pointer-events: none; }
.target-dot { inset: 36%; background: var(--board-target); }
.target-ring { inset: 3%; border: calc(var(--board-size) / 8 * 0.08) solid var(--board-target); }
.piece.dragging { opacity: 0.25; }
.piece.captured { z-index: 0; pointer-events: none; } /* fades out underneath the capturing piece */
/* Someone else's dragged piece (positions arrive ~12x/s, so glide between them). */
.remote-drag {
  position: absolute;
  z-index: 6;
  width: 12.5%;
  height: 12.5%;
  transform: translate(-50%, -50%);
  transition: left 90ms linear, top 90ms linear;
  pointer-events: none;
}
.remote-drag img { width: 100%; height: 100%; filter: drop-shadow(0 6px 6px var(--color-overlay)); }
.remote-drag-label {
  position: absolute;
  left: 50%;
  top: 100%;
  transform: translateX(-50%);
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--color-surface-3);
  color: var(--color-text);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.drag-ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 300;
  pointer-events: none;
  will-change: transform;
}
.badge {
  position: absolute;
  z-index: 4;
  top: 2%;
  right: 2%;
  width: 36%;
  height: 36%;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--cls);
  color: var(--class-text);
  font-size: calc(var(--board-size) / 8 * 0.2);
  font-weight: 800;
  box-shadow: 0 1px 4px var(--color-overlay);
}

.controls { display: flex; gap: 8px; }
.controls .btn { min-width: 52px; font-size: 16px; }

/* Review panel */
.review-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  padding: 12px;
  background: var(--color-surface);
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
}

.progress { display: flex; flex-direction: column; gap: 6px; }
.progress-label { font-size: 12px; color: var(--color-text-muted); }
.progress.error .progress-label { color: var(--color-error); }
.progress-track { height: 6px; background: var(--color-surface-3); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--color-accent); transition: width 0.2s; }

.move-comment {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 52px;
  padding: 10px 12px;
  background: var(--color-surface-2);
  border-radius: var(--radius-sm);
}
.comment-main { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.comment-main[class*="cls-"] b { color: var(--cls); }
.comment-eval {
  margin-left: auto;
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  background: var(--color-surface-3);
  font-size: 12px;
  font-weight: 700;
}
.comment-sub { color: var(--color-text-muted); font-size: 13px; }

.eval-graph {
  position: relative;
  flex: none;
  height: 70px;
  background: var(--eval-graph-bg);
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
}
.eval-graph svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.graph-area { fill: var(--eval-white); }
.graph-mid { stroke: var(--color-text-faint); stroke-width: 1; vector-effect: non-scaling-stroke; }
.graph-dot {
  position: absolute;
  width: 8px;
  height: 8px;
  margin: -4px 0 0 -4px;
  border-radius: 50%;
  background: var(--cls);
  border: 1px solid var(--eval-black);
}
.graph-cursor {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  background: var(--eval-graph-marker);
}

.move-list {
  flex: 1;
  min-height: 120px;
  overflow-y: auto;
  padding: 4px;
  background: var(--color-surface-2);
  border-radius: var(--radius-sm);
}
.move-row {
  display: grid;
  grid-template-columns: 38px 1fr 1fr;
  align-items: center;
}
.move-row:nth-child(odd) { background: var(--color-surface); }
.move-num { color: var(--color-text-faint); padding-left: 6px; }
.move {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
}
.move:hover { background: var(--color-surface-3); }
.move.active { background: var(--color-primary); color: var(--color-on-primary); }
.empty { color: var(--color-text-muted); padding: 8px; }

.cls-icon {
  flex: none;
  width: 18px;
  height: 18px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  background: var(--cls);
  color: var(--class-text);
  font-size: 10px;
  font-weight: 800;
  line-height: 1;
}
.cls-icon.pending { background: var(--color-surface-3); }

.summary { flex: none; }
.summary-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.summary-table th { font-weight: 700; padding: 4px; overflow: hidden; text-overflow: ellipsis; max-width: 120px; }
.summary-table td { padding: 2px 4px; text-align: center; }
.summary-table .count { font-weight: 700; color: var(--cls); width: 25%; }
.summary-table .cls-name { display: flex; align-items: center; justify-content: center; gap: 6px; color: var(--color-text-muted); }
.accuracy-row td { font-size: 18px; font-weight: 800; padding-bottom: 6px; }
.accuracy-row td:nth-child(2) { font-size: 12px; font-weight: 400; color: var(--color-text-muted); }

/* Classification color hook: any .cls-<key> element exposes --cls. */
.cls-brilliant { --cls: var(--class-brilliant); }
.cls-great { --cls: var(--class-great); }
.cls-best { --cls: var(--class-best); }
.cls-excellent { --cls: var(--class-excellent); }
.cls-good { --cls: var(--class-good); }
.cls-book { --cls: var(--class-book); }
.cls-inaccuracy { --cls: var(--class-inaccuracy); }
.cls-mistake { --cls: var(--class-mistake); }
.cls-miss { --cls: var(--class-miss); }
.cls-blunder { --cls: var(--class-blunder); }

/* ---------- Lobby (Host / Join) ---------- */

.lobby-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--color-backdrop);
  overflow-y: auto;
}
.lobby-card {
  width: 100%;
  max-width: 440px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.lobby-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.lobby-header h2 {
  margin: 0;
  min-width: 0;
  font-size: 20px;
  color: var(--color-accent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.icon-btn {
  flex: none;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:hover { background: var(--color-surface-3); color: var(--color-text); }

.lobby-body { display: flex; flex-direction: column; gap: 14px; }
.lobby-form { display: flex; flex-direction: column; gap: 12px; }
.lobby-hint { margin: 0; color: var(--color-text-muted); font-size: 13px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}
.whitelist-add { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.name-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.name-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  padding: 4px 4px 4px 10px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-surface-2);
  font-weight: 600;
  overflow-wrap: anywhere;
}
.name-chip button {
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--color-text-muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.name-chip button:hover { background: var(--color-surface-3); color: var(--color-text); }

.room-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}
.live { display: inline-flex; align-items: center; gap: 6px; color: var(--color-win); text-transform: none; letter-spacing: 0; }
.live-dot, .pulse {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-win);
  animation: pulse 1.6s ease-in-out infinite;
}
.pulse { width: 10px; height: 10px; background: var(--color-accent); }
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.35; transform: scale(0.8); }
}

.room-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 50vh;
  overflow-y: auto;
}
.room-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--color-surface-2);
  border-radius: var(--radius-sm);
}
.room-info { flex: 1; min-width: 0; }
.room-name, .room-meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-name { font-weight: 700; }
.room-meta { font-size: 12px; color: var(--color-text-muted); margin-top: 2px; }
.room-empty {
  padding: 18px 12px;
  text-align: center;
  color: var(--color-text-muted);
  background: var(--color-surface-2);
  border-radius: var(--radius-sm);
}
.room-empty.error { color: var(--color-error); }

.room-code-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--color-surface-2);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
}
.room-code-box b { font-size: 24px; letter-spacing: 0.18em; color: var(--color-accent); }

.player-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.player {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--color-surface-2);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-weight: 600;
}
.player.waiting {
  background: transparent;
  border: 1px dashed var(--color-border);
  color: var(--color-text-muted);
  font-weight: 400;
  min-height: 52px;
}
/* chess.com avatar (an <img>), or the player's initial when they have none (a <span>). */
.player-avatar, .bar-avatar {
  flex: none;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm); /* rounded squares inside a match (the home screen keeps circles) */
  background: var(--color-primary);
  color: var(--color-on-primary);
  font-weight: 700;
  object-fit: cover;
}
.player-avatar { width: 30px; height: 30px; }
.bar-avatar { width: 30px; height: 30px; font-size: 13px; border: 2px solid var(--color-bg); }
.avatar-stack { display: flex; flex: none; }
.avatar-stack .bar-avatar + .bar-avatar { margin-left: -10px; } /* teammates overlap */
.player-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag {
  flex: none;
  padding: 2px 7px;
  border-radius: 4px;
  background: var(--color-surface-3);
  color: var(--color-text-muted);
  font-size: 11px;
  font-weight: 700;
}
.tag-you { background: var(--color-accent); color: var(--color-on-accent); }

.room-status { margin: 0; color: var(--color-text-muted); }
.room-status.connected { color: var(--color-win); font-weight: 600; }
.room-status.error { color: var(--color-error); }
.share-url {
  padding: 10px 12px;
  border: 1px dashed var(--color-primary-hover);
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}
.share-url b { color: var(--color-accent); }

/* ---------- Room (host vs players) ---------- */

.room .player-bar { width: var(--board-size); padding-left: 0; min-height: 34px; }
.room .player-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-board-row { position: relative; }
.room-panel { overflow-y: auto; }

.clock-wrap { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.clock-add {
  padding: 4px 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.clock-add:hover { background: var(--color-surface-3); color: var(--color-text); }
.paused-note { color: var(--clock-active-bg); font-weight: 700; }
.preview-note { margin-bottom: 4px; color: var(--color-accent); font-size: 13px; font-weight: 700; }
.saved-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.toggle-row { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.toggle-row input { width: 18px; height: 18px; flex: none; accent-color: var(--color-primary-hover); }
.slot-btn { min-height: 32px; min-width: 36px; padding: 4px 10px; }
.room-moves .move { cursor: pointer; }
.clock {
  min-width: 76px;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  background: var(--clock-bg);
  color: var(--clock-text);
  font-size: 18px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.clock.active { background: var(--clock-active-bg); color: var(--clock-active-text); }
.clock.paused { opacity: 0.6; }
.clock.low { color: var(--clock-low); }
.clock.active.low { background: var(--clock-low); color: var(--color-on-primary); }

.panel-stack { display: flex; flex-direction: column; gap: 14px; }
.panel-section { display: flex; flex-direction: column; gap: 8px; }
.panel-section p { margin: 0; }
.panel-title {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}
.hint { margin: 0; color: var(--color-text-muted); font-size: 13px; }
.hint.center { text-align: center; }

.segmented, .chips { display: flex; flex-wrap: wrap; gap: 6px; }
.segmented .seg-btn { flex: 1; }
.seg-btn {
  min-height: 38px;
  padding: 6px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
  color: var(--color-text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.seg-btn:hover { background: var(--color-surface-3); }
.seg-btn.active { background: var(--color-primary); border-color: var(--color-primary); color: var(--color-on-primary); }
.custom-time { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.button-row { display: flex; gap: 8px; }
.button-row .btn { flex: 1; }

.palette {
  width: var(--board-size);
  display: grid;
  grid-template-columns: repeat(13, 1fr);
  gap: 4px;
}
.palette-btn {
  aspect-ratio: 1;
  min-width: 0;
  padding: 2px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  font-size: 18px;
  font-weight: 800;
  cursor: pointer;
}
.palette-btn img { width: 100%; height: 100%; display: block; }
.palette-btn.active { background: var(--color-primary); border-color: var(--color-accent); color: var(--color-on-primary); }

.promotion-picker {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  background: var(--color-backdrop);
}
.promotion-choices {
  display: flex;
  gap: 6px;
  padding: 8px;
  border-radius: var(--radius);
  background: var(--color-surface);
  box-shadow: var(--shadow);
}
.promotion-choices button {
  width: calc(var(--board-size) / 8);
  aspect-ratio: 1;
  padding: 2px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--board-light);
  cursor: pointer;
}
.promotion-choices img { width: 100%; height: 100%; display: block; }

.game-status { min-height: 24px; }
.room-status .pulse, .game-status .pulse { display: inline-block; vertical-align: middle; margin-right: 4px; }
.room-status.your-move { color: var(--color-accent); font-weight: 700; }
.check-text { color: var(--color-loss); }
.result-banner {
  margin: 0;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--color-surface-3);
  font-size: 18px;
  font-weight: 800;
  text-align: center;
}
.result-banner.won { background: var(--color-primary); color: var(--color-on-primary); }
.result-banner.lost { background: var(--color-surface-2); color: var(--color-loss); }
.room-moves { flex: 1; min-height: 140px; }
.move.muted { color: var(--color-text-faint); cursor: default; }

/* ---------- Saved room games (home, left) and the game-over banner ---------- */

.game-over {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 90;
  width: min(420px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 18px 20px 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface-2);
  box-shadow: 0 0 0 100vmax var(--color-backdrop), var(--shadow); /* dims the page behind it */
  text-align: center;
  transform: translate(-50%, -50%);
  animation: pop-in 0.25s ease-out;
}
.game-over.won { background: var(--color-primary); border-color: var(--color-primary); color: var(--color-on-primary); }
.game-over .icon-btn { position: absolute; top: 4px; right: 4px; width: 32px; height: 32px; color: inherit; }
.game-over-title { font-size: 22px; font-weight: 800; }
.game-over-sub { margin-bottom: 8px; font-size: 13px; opacity: 0.8; }
@keyframes pop-in { from { transform: translate(-50%, -50%) scale(0.85); opacity: 0; } to { transform: translate(-50%, -50%) scale(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .game-over { animation: none; } }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 100;
  max-width: calc(100vw - 32px);
  padding: 10px 18px;
  background: var(--color-surface-3);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  text-align: center;
}

/* ---------- Tablets & phones: everything stacks and the page scrolls ---------- */

@media (max-width: 900px) {
  body { overflow: auto; }
  .screen {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
  }
  .login {
    padding-left: calc(16px + env(safe-area-inset-left, 0px));
    padding-right: calc(16px + env(safe-area-inset-right, 0px));
  }

  .home { grid-template-columns: minmax(0, 1fr); }
  .home-main { order: 1; }
  .sidebar-left { order: 2; border-right: none; border-top: 1px solid var(--color-border); }
  .home .sidebar:not(.sidebar-left) { order: 3; }
  .home-main {
    padding: calc(40px + env(safe-area-inset-top, 0px)) 16px 32px;
    gap: 10px;
  }
  .brand h1 { font-size: 48px; }
  .home-main .brand { margin-bottom: 16px; }
  .home-actions { flex-direction: row; width: 100%; max-width: 440px; gap: 12px; }
  .btn-big { flex: 1; width: auto; padding: 16px 12px; font-size: 20px; }
  .btn-settings { width: 100%; max-width: 440px; }
  .sidebar {
    border-left: none;
    border-top: 1px solid var(--color-border);
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }
  .games-list { flex: none; overflow: visible; }

  .analysis { --board-size: min(calc(100vw - 66px), 640px); }
  .analysis.room { --board-size: min(calc(100vw - 32px), 640px); } /* no eval bar beside this board */
  .room-moves { flex: none; max-height: 240px; }
  .analysis-header {
    position: sticky;
    top: 0;
    z-index: 5;
    padding-top: calc(10px + env(safe-area-inset-top, 0px));
  }
  .analysis-body {
    grid-template-columns: minmax(0, 1fr);
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }
  .analysis.room.has-slots { --board-size: min(calc(100vw - 32px), 640px); }
  .analysis.room.has-slots .analysis-body { grid-template-columns: minmax(0, 1fr); }
  .room-slots { order: 3; }
  .slot-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  .controls { width: calc(var(--board-size) + 34px); padding-left: 34px; }
  .controls .btn { flex: 1; min-width: 0; padding: 11px 0; }
  .review-panel { padding: 10px; }
  .move-list { flex: none; max-height: 320px; }
}

/* Phones: the lobby becomes a bottom sheet. */
@media (max-width: 600px) {
  .lobby-backdrop { align-items: flex-end; padding: 0; }
  .lobby-card {
    max-width: none;
    border-radius: var(--radius) var(--radius) 0 0;
    border-bottom: none;
    padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  }
  .brand h1 { font-size: 42px; }
}

@media (prefers-reduced-motion: reduce) {
  .live-dot, .pulse { animation: none; }
  .eval-fill, .progress-fill { transition: none; }
}

/* ---------- Analysis: the line you tried ---------- */
.variation {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px 6px;
  margin-top: 6px;
  padding: 8px;
  border-top: 1px dashed var(--color-border);
}
.variation-label { width: 100%; font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--color-accent); }
.variation .move-num { padding-left: 0; }

/* ---------- Puzzles ---------- */
.btn-puzzles { background: var(--color-surface-3); color: var(--color-text); border-color: var(--color-primary); }
.btn-puzzles:hover { background: var(--color-surface-2); }
.btn-sub { display: block; margin-top: 2px; font-size: 13px; font-weight: 500; color: var(--color-text-muted); }
.btn-sub:empty { display: none; }

.puzzle-card { display: flex; flex-direction: column; gap: 4px; padding: 12px; border-radius: var(--radius-sm); background: var(--color-surface-2); }
.puzzle-rating-row { display: flex; align-items: baseline; gap: 10px; }
.puzzle-rating-value { font-size: 38px; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.puzzle-delta { font-size: 20px; font-weight: 800; }
.puzzle-delta.gain { color: var(--color-win); }
.puzzle-delta.loss { color: var(--color-loss); }
.puzzle-status.success { border-left: 3px solid var(--color-win); }
.puzzle-status.fail { border-left: 3px solid var(--color-loss); }
.puzzle .room-panel { overflow-y: auto; }
/* ---------- Entering a room (js/transition.js) ---------- */
.logo-sprite {
  flex: none;
  width: 64px;
  height: 64px;
  background: url('../assets/chesset%20logo%20animation.png') 0 0 / 320px 64px no-repeat; /* 5 frames of 32x32 pixel art, shown at 2x */
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}
/* The room or puzzle screen waits below the screen, over the home screen, until it rises into place. */
.entering-screen { position: fixed; inset: 0; z-index: 40; height: auto; overflow: hidden; }
.entering-screen:not(.login) { background: var(--color-bg); } /* (the sign-in screen keeps its own background) */
.entering .home { pointer-events: none; }
.entering { overflow: hidden; } /* (the logo grows past the screen's sides while it goes) */

/* A new puzzle's pieces fade in (the position is swapped in place, nothing slides or jumps). */
.board.fresh .piece { animation: piece-in 280ms ease-out; }
@keyframes piece-in { from { opacity: 0; } }