/* =========================================================================
   BlunderEngine design system
   Dark "engine console" look: flat charcoal surfaces, one signal green, a
   monospace readout voice for anything the engine reports. No gradients.
   ====================================================================== */

:root {
  --bg: #262522;
  --bg-2: #201f1c;
  --panel: #302f2b;
  --panel-2: #3a3933;
  --line: #4b4941;
  --line-soft: #3c3a34;

  --text: #f5f2e9;
  --text-2: #c1beb3;
  --text-3: #a19e93;

  --green: #97be59;
  --green-dim: #73953e;
  --green-fade: rgba(151, 190, 89, 0.13);
  --amber: #f0a92b;
  --amber-fade: rgba(240, 169, 43, 0.15);
  --red: #e2574c;
  --red-fade: rgba(226, 87, 76, 0.14);
  --blue: #4aa3df;
  --violet: #9d7ce0;

  --light-sq: #eee9ce;
  --dark-sq: #7c9855;
  --sel: rgba(99, 193, 50, 0.55);
  --last: rgba(240, 169, 43, 0.38);
  --check: rgba(226, 87, 76, 0.62);

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 8px 26px rgba(0, 0, 0, 0.42);

  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --nav-w: 208px;
  --header-h: 64px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body { overflow-y: scroll; }

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.015em; line-height: 1.2; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.18rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 0.85em; }
::selection { background: var(--green); color: #0b0d10; }

:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; border-radius: 4px; }

/* ------------------------------------------------------------------ shell */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--nav-w);
  flex: 0 0 var(--nav-w);
  background: var(--bg-2);
  border-right: 1px solid var(--line-soft);
  padding: 14px 12px 20px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 8px 16px;
  font-weight: 750;
  font-size: 1.06rem;
  letter-spacing: -0.02em;
}
.brand small {
  display: block;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-3);
  font-family: var(--mono);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-weight: 550;
  font-size: 0.93rem;
  cursor: pointer;
  border: 1px solid transparent;
}
.nav-link:hover { background: var(--panel); color: var(--text); }
.nav-link.active { background: var(--green-fade); color: var(--text); border-color: rgba(99, 193, 50, 0.28); }
.nav-link .ic { width: 18px; height: 18px; flex: none; opacity: 0.9; }
.nav-sep { height: 1px; background: var(--line-soft); margin: 10px 6px; }
.nav-label {
  font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--text-3); padding: 6px 10px 2px; font-family: var(--mono);
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--header-h);
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 18px;
  position: sticky;
  top: 0;
  background: rgba(20, 22, 26, 0.92);
  backdrop-filter: blur(8px);
  z-index: 40;
}
.topbar .spacer { flex: 1; }

.content { padding: 22px 24px 60px; max-width: 1240px; width: 100%; margin: 0 auto; flex: 1; }
.content.wide { max-width: 1500px; }

/* mobile nav */
.mobile-nav { display: none; }
.menu-btn { display: none; }

/* ------------------------------------------------------------------ atoms */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, transform 0.06s;
  white-space: nowrap;
}
.btn:hover { background: #2b313a; border-color: #3a4250; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--green); border-color: var(--green); color: #0d1108; }
.btn-primary:hover { background: #6ed13a; border-color: #6ed13a; }
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--panel); }
.btn-danger { border-color: rgba(226, 87, 76, 0.4); color: #f0a49d; }
.btn-danger:hover { background: var(--red-fade); border-color: var(--red); }
.btn-sm { padding: 6px 11px; font-size: 0.85rem; }
.btn-lg { padding: 12px 22px; font-size: 1rem; }
.btn-block { width: 100%; }

.card {
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 16px;
}
.card-tight { padding: 12px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  border: 1px solid var(--line);
  color: var(--text-2);
  background: var(--panel-2);
  white-space: nowrap;
}
.chip-free { color: #a8e07f; border-color: rgba(99, 193, 50, 0.35); background: var(--green-fade); }
.chip-premium { color: #f3c66b; border-color: rgba(240, 169, 43, 0.35); background: var(--amber-fade); }
.chip-new { color: #8fd0f5; border-color: rgba(74, 163, 223, 0.35); background: rgba(74, 163, 223, 0.13); }
.chip-mono { font-family: var(--mono); }

.mono { font-family: var(--mono); }
.muted { color: var(--text-2); }
.dim { color: var(--text-3); }
.small { font-size: 0.85rem; }
.tiny { font-size: 0.78rem; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; }
.row-wrap { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 10px; }
.grow { flex: 1; }
.stack > * + * { margin-top: 12px; }
.hidden { display: none !important; }

.field { display: block; margin-bottom: 12px; }
.field > span, .field > label { display: block; font-size: 0.83rem; color: var(--text-2); margin-bottom: 5px; font-weight: 600; }
.input, select.input, textarea.input {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
}
.input:focus { border-color: var(--green); outline: none; }

.notice {
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--panel-2);
  font-size: 0.88rem;
}
.notice-error { border-color: rgba(226, 87, 76, 0.45); background: var(--red-fade); color: #f5b6b0; }
.notice-ok { border-color: rgba(99, 193, 50, 0.4); background: var(--green-fade); color: #bfe7a2; }
.notice-warn { border-color: rgba(240, 169, 43, 0.4); background: var(--amber-fade); color: #f2d09a; }

.page-head { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head p { margin: 4px 0 0; color: var(--text-2); font-size: 0.92rem; }

.section-title {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--text-3);
  margin: 26px 0 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.section-title::after { content: ''; flex: 1; height: 1px; background: var(--line-soft); }

/* ------------------------------------------------------------------- home */
.hero {
  border: 1px solid var(--line-soft);
  border-radius: 14px;
  background: var(--panel);
  padding: 26px;
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 26px;
  align-items: center;
}
.hero h1 { font-size: 2.05rem; letter-spacing: -0.03em; }
.hero .lede { color: var(--text-2); font-size: 1.02rem; max-width: 52ch; margin-top: 10px; }
.hero-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.hero-side { display: grid; gap: 10px; }

.stat-strip { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 18px; }
.stat-strip .s { font-family: var(--mono); }
.stat-strip .s b { display: block; font-size: 1.3rem; color: var(--green); font-weight: 700; }
.stat-strip .s span { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-3); }

/* ------------------------------------------------------------- bot cards */
.bot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(268px, 1fr));
  gap: 12px;
}

.bot-card {
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  cursor: pointer;
  position: relative;
  transition: border-color 0.14s, transform 0.1s, background 0.14s;
}
.bot-card:hover { border-color: var(--accent, var(--green)); transform: translateY(-2px); background: var(--panel-2); }
.bot-card .head { display: flex; gap: 11px; align-items: center; }
.bot-card .name { font-weight: 680; font-size: 1rem; letter-spacing: -0.01em; }
.bot-card .tagline { color: var(--text-3); font-size: 0.8rem; }
.bot-card .rule {
  font-size: 0.84rem;
  color: var(--text-2);
  background: var(--bg-2);
  border: 1px solid var(--line-soft);
  border-left: 2px solid var(--accent, var(--green));
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 8px 10px;
  min-height: 58px;
}
.bot-card .foot { display: flex; align-items: center; gap: 8px; margin-top: auto; }
.bot-card.locked { opacity: 0.82; }
.bot-card .lock-note { font-size: 0.76rem; color: var(--amber); }

.avatar {
  width: 46px; height: 46px; flex: none;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--bg-2);
  overflow: hidden;
}
.avatar svg { display: block; width: 100%; height: 100%; }
.avatar-lg { width: 68px; height: 68px; border-radius: 14px; }
.avatar-sm { width: 32px; height: 32px; border-radius: 8px; }

.cs-badge {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 5px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--text-2);
}
.cs-badge b { color: var(--text); }

/* --------------------------------------------------------------- filters */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line-soft); border-radius: 8px; padding: 3px; gap: 2px; }
.seg button {
  border: 0; background: transparent; color: var(--text-2);
  padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 0.87rem; font-weight: 600;
}
.seg button.on { background: var(--panel-2); color: var(--text); }

/* ------------------------------------------------------------ play board */
.play-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 20px;
  align-items: start;
}

.board-column { display: flex; flex-direction: column; gap: 10px; min-width: 0; }

.board-wrap {
  width: 100%;
  max-width: min(72vh, 760px);
  margin: 0 auto;
}

/* The board is a strict square grid: 8 equal columns x 8 equal rows.        */
.board {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid #0e1013;
  touch-action: manipulation;
  user-select: none;
}
.sq { position: relative; }
.sq.light { background: var(--light-sq); }
.sq.dark { background: var(--dark-sq); }
.sq .coord {
  position: absolute;
  font-size: clamp(7px, 1.4cqw, 11px);
  font-family: var(--mono);
  font-weight: 700;
  opacity: 0.55;
  pointer-events: none;
}
.sq .coord.file { right: 3px; bottom: 1px; }
.sq .coord.rank { left: 3px; top: 1px; }
.sq.light .coord { color: #6d8a4f; }
.sq.dark .coord { color: #e9e3d0; }

.sq.last::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--last);
  pointer-events: none;
}
.sq.sel::after {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--sel);
  pointer-events: none;
}
.sq.check::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, var(--check) 0%, rgba(226, 87, 76, 0) 72%);
  pointer-events: none;
}
.sq.hint::after {
  content: '';
  position: absolute;
  left: 50%; top: 50%;
  width: 30%; height: 30%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(20, 22, 26, 0.32);
  pointer-events: none;
}
.sq.hint.occupied::after {
  width: 100%; height: 100%;
  border-radius: 0;
  background: none;
  box-shadow: inset 0 0 0 max(4px, 7%) rgba(20, 22, 26, 0.3);
}
.sq.over { box-shadow: inset 0 0 0 max(3px, 4%) rgba(99, 193, 50, 0.9); }

.piece {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  display: grid;
  place-items: center;
}
.piece svg { width: 92%; height: 92%; display: block; }
.piece.dragging { opacity: 0.32; }

.drag-ghost {
  position: fixed;
  z-index: 999;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(1.08);
  filter: drop-shadow(0 6px 10px rgba(0, 0, 0, 0.5));
}

.board.flipped { transform: none; }

/* players above/below the board */
.player-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  min-height: 52px;
}
.player-bar .who { font-weight: 640; }
.player-bar .sub { font-size: 0.78rem; color: var(--text-3); }
.player-bar.turn { border-color: rgba(99, 193, 50, 0.5); background: var(--green-fade); }
.captured { display: flex; gap: 1px; flex-wrap: wrap; align-items: center; }
.captured svg { width: 17px; height: 17px; opacity: 0.9; }
.captured .adv { font-family: var(--mono); font-size: 0.78rem; color: var(--text-2); margin-left: 4px; }

/* ------------------------------------------------------- challenge panel */
.panel-col { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

.rule-box {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
}
.rule-box .rb-head {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 13px;
  border-bottom: 1px solid var(--line-soft);
}
.rule-box .rb-body { padding: 12px 13px; }
.rule-text { font-size: 0.88rem; color: var(--text-2); }

.live-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--text-3);
  text-transform: uppercase;
}
.live-indicator.on {
  color: #ffd489;
  border-color: rgba(240, 169, 43, 0.55);
  background: var(--amber-fade);
}
.live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-3);
  flex: none;
}
.live-indicator.on .live-dot { background: var(--amber); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(240, 169, 43, 0.65); }
  60% { box-shadow: 0 0 0 7px rgba(240, 169, 43, 0); }
}

.cs-meter { margin-top: 10px; }
.cs-meter .cs-row { display: flex; align-items: baseline; justify-content: space-between; font-family: var(--mono); }
.cs-meter .cs-val { font-size: 1.45rem; font-weight: 700; color: var(--text); }
.cs-meter .cs-val.up { color: var(--red); }
.cs-meter .cs-val.down { color: var(--green); }
.cs-track { height: 6px; border-radius: 3px; background: var(--bg-2); border: 1px solid var(--line-soft); overflow: hidden; margin-top: 6px; }
.cs-fill { height: 100%; background: var(--green); transition: width 0.45s ease, background 0.3s; }
.cs-fill.hot { background: var(--red); }
.cs-note { font-size: 0.74rem; color: var(--text-3); margin-top: 5px; }

.event-log {
  max-height: 168px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-family: var(--mono);
  font-size: 0.76rem;
}
.event-log .ev {
  padding: 6px 9px;
  border-radius: 5px;
  background: var(--bg-2);
  border-left: 2px solid var(--line);
  color: var(--text-2);
}
.event-log .ev.up { border-left-color: var(--red); color: #f0aca6; }
.event-log .ev.down { border-left-color: var(--green); color: #b7e598; }
.event-log .ev.rule { border-left-color: var(--amber); color: #f2cf9b; }
.event-log .ev.info { border-left-color: var(--blue); }

/* flash banner over the board when a challenge fires */
.board-flash {
  position: absolute;
  left: 50%;
  top: 14px;
  transform: translateX(-50%);
  z-index: 20;
  padding: 8px 16px;
  border-radius: 999px;
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  background: rgba(18, 20, 24, 0.94);
  border: 1px solid var(--amber);
  color: #ffd489;
  pointer-events: none;
  animation: flashIn 0.28s ease-out;
  box-shadow: var(--shadow);
  max-width: 88%;
  text-align: center;
}
.board-flash.down { border-color: var(--green); color: #bfe7a2; }
.board-flash.up { border-color: var(--red); color: #f5b6b0; }
@keyframes flashIn {
  from { opacity: 0; transform: translate(-50%, -8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* move list */
.moves {
  display: grid;
  grid-template-columns: 34px 1fr 1fr;
  font-family: var(--mono);
  font-size: 0.83rem;
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  background: var(--bg-2);
}
.moves .n { color: var(--text-3); padding: 4px 6px; text-align: right; background: var(--panel); }
.moves .m { padding: 4px 8px; cursor: pointer; }
.moves .m:hover { background: var(--panel-2); }
.moves .m.cur { background: var(--green-fade); color: #cdefb4; }
.moves .m.empty { cursor: default; }

.game-controls { display: flex; gap: 6px; flex-wrap: wrap; }
.game-controls .btn { flex: 1; min-width: 0; }

/* thinking bar */
.thinking {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 0.76rem;
  color: var(--text-3);
  min-height: 20px;
}
.thinking .bar { flex: 1; height: 3px; background: var(--line-soft); border-radius: 2px; overflow: hidden; }
.thinking .bar i { display: block; height: 100%; background: var(--green); width: 0%; transition: width 0.18s; }

/* eval bar */
.evalbar {
  width: 14px;
  border-radius: 4px;
  overflow: hidden;
  background: #23262b;
  border: 1px solid #0e1013;
  position: relative;
  flex: none;
}
.evalbar i { position: absolute; left: 0; right: 0; bottom: 0; background: #eceadf; transition: height 0.4s ease; }
.board-and-eval { display: flex; gap: 8px; align-items: stretch; }
.board-and-eval .board-wrap { flex: 1; }

/* ------------------------------------------------------------- modal */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(8, 9, 11, 0.72);
  display: grid; place-items: center;
  padding: 18px;
  animation: fadeIn 0.14s ease-out;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: min(520px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 20px;
}
.modal h2 { margin-bottom: 8px; }
.modal-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.modal-actions .btn { flex: 1; }

/* promotion picker */
.promo-choices { display: flex; gap: 8px; justify-content: center; margin-top: 12px; }
.promo-choices button {
  width: 68px; height: 68px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  display: grid; place-items: center;
}
.promo-choices button:hover { border-color: var(--green); background: var(--green-fade); }
.promo-choices svg { width: 78%; height: 78%; }

/* ------------------------------------------------------------- tables */
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th {
  text-align: left;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--text-3);
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  font-weight: 700;
}
.table td { padding: 9px 10px; border-bottom: 1px solid var(--line-soft); }
.table tr:hover td { background: var(--panel-2); }
.table .num { font-family: var(--mono); text-align: right; }
.rank-1 { color: #ffd76e; font-weight: 700; }
.rank-2 { color: #d5dbe4; font-weight: 700; }
.rank-3 { color: #d9a273; font-weight: 700; }

/* ------------------------------------------------------- achievements */
.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.ach {
  display: flex; gap: 11px; align-items: flex-start;
  padding: 12px; border-radius: var(--radius);
  border: 1px solid var(--line-soft); background: var(--panel);
}
.ach.earned { border-color: rgba(99, 193, 50, 0.42); background: var(--green-fade); }
.ach .medal {
  width: 34px; height: 34px; flex: none; border-radius: 9px;
  display: grid; place-items: center;
  background: var(--bg-2); border: 1px solid var(--line);
  font-size: 16px;
}
.ach.earned .medal { background: var(--green); border-color: var(--green); }
.ach .t { font-weight: 640; font-size: 0.92rem; }
.ach .d { font-size: 0.8rem; color: var(--text-2); }
.ach.locked { opacity: 0.62; }

/* --------------------------------------------------------------- misc */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 0.88rem; }
.kv dt { color: var(--text-3); font-family: var(--mono); font-size: 0.78rem; padding-top: 2px; }
.kv dd { margin: 0; }

.pill-row { display: flex; gap: 6px; flex-wrap: wrap; }

.ad-slot {
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.78rem;
  color: var(--text-3);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-2);
}
.ad-slot .lbl {
  font-family: var(--mono); font-size: 9px; letter-spacing: 0.1em;
  text-transform: uppercase; border: 1px solid var(--line); padding: 2px 5px; border-radius: 3px;
}

.result-banner {
  text-align: center;
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel-2);
}
.result-banner .big { font-size: 1.35rem; font-weight: 720; }
.result-banner.win { border-color: rgba(99, 193, 50, 0.5); background: var(--green-fade); }
.result-banner.loss { border-color: rgba(226, 87, 76, 0.45); background: var(--red-fade); }
.result-banner.draw { border-color: rgba(240, 169, 43, 0.4); background: var(--amber-fade); }

.spinner {
  width: 15px; height: 15px; flex: none;
  border: 2px solid var(--line);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast-host { position: fixed; right: 16px; bottom: 16px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--green);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  box-shadow: var(--shadow);
  font-size: 0.88rem;
  max-width: 330px;
  animation: toastIn 0.2s ease-out;
}
.toast.err { border-left-color: var(--red); }
.toast.warn { border-left-color: var(--amber); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.footer {
  border-top: 1px solid var(--line-soft);
  padding: 18px 24px 30px;
  color: var(--text-3);
  font-size: 0.8rem;
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  align-items: center;
}
.footer a:hover { color: var(--text-2); text-decoration: underline; }

.analysis-move { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 5px; font-family: var(--mono); font-size: 0.82rem; }
.q-best { color: #8fe06a; }
.q-good { color: #b8d99a; }
.q-inaccuracy { color: #f0cf8a; }
.q-mistake { color: #f0a94b; }
.q-blunder { color: #ef6f5f; }
.q-book { color: var(--text-3); }

.acc-big { font-family: var(--mono); font-size: 2rem; font-weight: 700; line-height: 1; }

/* ----------------------------------------------------------- responsive */
@media (max-width: 1100px) {
  .play-layout { grid-template-columns: minmax(0, 1fr) 300px; gap: 14px; }
}

@media (max-width: 940px) {
  .sidebar { display: none; }
  .menu-btn { display: inline-flex; }
  .content { padding: 16px 14px 90px; }
  .hero { grid-template-columns: 1fr; padding: 20px; }
  .hero h1 { font-size: 1.65rem; }
  .play-layout { grid-template-columns: 1fr; }
  .board-wrap { max-width: min(96vw, 620px); }
  .panel-col { order: 2; }

  .mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 60;
    background: rgba(23, 26, 31, 0.97);
    border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    backdrop-filter: blur(8px);
  }
  .mobile-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 5px 2px;
    font-size: 10px;
    color: var(--text-3);
    font-weight: 600;
  }
  .mobile-nav a.active { color: var(--green); }
  .mobile-nav .ic { width: 20px; height: 20px; }

  .drawer {
    position: fixed;
    inset: 0;
    z-index: 150;
    background: rgba(8, 9, 11, 0.6);
  }
  .drawer .sheet {
    position: absolute;
    top: 0; bottom: 0; left: 0;
    width: 264px;
    background: var(--bg-2);
    border-right: 1px solid var(--line);
    padding: 14px 12px;
    overflow-y: auto;
    animation: slideIn 0.18s ease-out;
  }
  @keyframes slideIn { from { transform: translateX(-100%); } to { transform: none; } }

  .moves { max-height: 150px; }
  .game-controls .btn { flex: 1 1 46%; }
}

@media (max-width: 560px) {
  h1 { font-size: 1.35rem; }
  .content { padding: 12px 10px 90px; }
  .bot-grid { grid-template-columns: 1fr; gap: 10px; }
  .board-wrap { max-width: 100%; }
  .board-and-eval { gap: 5px; }
  .evalbar { width: 10px; }
  .player-bar { padding: 6px 8px; min-height: 46px; }
  .card { padding: 13px; }
  .modal { padding: 16px; }
  .promo-choices button { width: 60px; height: 60px; }
  .stat-strip { gap: 12px; }
  .footer { padding: 16px 12px 100px; }
}

/* Keep the board comfortably visible next to the phone chrome. */
@media (max-width: 940px) and (orientation: landscape) {
  .board-wrap { max-width: min(82vh, 520px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* Squares holding a movable piece opt out of touch scrolling so a drag never
   scrolls the page; empty squares keep normal scrolling on phones. */
.sq.mine { touch-action: none; }

/* The wordmark lives in the sidebar on desktop, in the top bar on mobile. */
.hide-desktop { display: none; }
@media (max-width: 940px) { .hide-desktop { display: inline; } }

td.center, th.center { text-align: center; }

/* Inline icons default to a sensible size everywhere, not just in the nav. */
.ic { width: 18px; height: 18px; flex: none; }
.btn .ic { width: 16px; height: 16px; }

@media (max-width: 560px) {
  .topbar { padding: 0 10px; gap: 8px; }
  .topbar .btn { padding: 6px 10px; font-size: 0.82rem; }
  /* One clear action in the header on a phone; the rest lives in the drawer. */
  #topRight a[href="/register"] { display: none; }
  #topRight a[href="/premium"] { display: none; }
}

/* Visually hidden but still announced by screen readers (display:none is not). */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}
