:root {
  --bg: #14110e;
  --bg-2: #1c1814;
  --ink: #f4efe6;
  --muted: #b7ab9c;
  --line: rgba(244, 239, 230, 0.14);
  --gold: #c6a15b;
  --gold-2: #e4c98a;
  --btn: #2a241e;
  --btn-ink: #f4efe6;
  --danger: #c45b4a;
  --frame: #5c3d28;
  --light: #efd3a4;
  --dark: #b06a38;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  --sans: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --serif: Palatino, "Palatino Linotype", "Iowan Old Style", Georgia, serif;
}
* { box-sizing: border-box; }
html { color-scheme: dark; }
html, body { margin: 0; padding: 0; }
body {
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(198, 161, 91, 0.08), transparent 60%),
    var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
  overflow-x: hidden;
  word-break: keep-all;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}
button, select, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }
button { cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
a { color: var(--gold-2); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); border: 0;
}
.top {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
}
.brand { color: var(--ink); text-decoration: none; font-weight: 700; letter-spacing: 0.01em; }
.brand span { color: var(--gold); }
.product {
  margin: 0; font-family: var(--serif); font-size: 1.05rem; color: var(--muted);
}
.top select {
  margin-left: auto;
  background: var(--btn); border: 1px solid var(--line); border-radius: 4px;
  padding: 8px 10px; min-height: 40px;
}
.wrap { width: min(1520px, calc(100% - 32px)); margin: 0 auto; padding-bottom: 32px; }
h1 { font-family: var(--serif); font-weight: 500; font-size: clamp(1.8rem, 3vw, 2.6rem); margin: 18px 0 6px; letter-spacing: -0.02em; }
.lead { margin: 0 0 14px; max-width: 68ch; color: var(--muted); }
.arena {
  display: grid;
  grid-template-columns: 200px minmax(280px, 1fr) 300px;
  gap: 22px;
  align-items: start;
}
.rail, .side, .stage { min-width: 0; }
.rail { display: flex; flex-direction: column; gap: 4px; position: sticky; top: 12px; }
.rail button, .tool-row button, .lesson-nav button, .btn {
  background: transparent; border: 1px solid transparent; border-radius: 4px;
  text-align: start; padding: 10px 12px; min-height: 44px; color: var(--ink);
}
.rail button:hover, .tool-row button:hover { background: rgba(255, 255, 255, 0.04); }
.rail button.is-on { border-color: var(--line); background: var(--bg-2); box-shadow: inset 2px 0 0 var(--gold); }
.record { margin-top: 14px; padding: 10px 12px 0; border-top: 1px solid var(--line); }
.record p { display: flex; justify-content: space-between; gap: 10px; margin: 0; padding: 4px 0; color: var(--muted); font-size: 0.84rem; }
.record b { color: var(--ink); font-weight: 650; font-variant-numeric: tabular-nums; }
.stage { display: flex; flex-direction: column; gap: 8px; }
.seat {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px; align-items: center;
  min-height: 52px; padding: 4px 2px;
}
.who { display: flex; gap: 10px; align-items: center; min-width: 0; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center;
  background: #2a241e; color: var(--gold-2); font-weight: 700; flex: none;
}
.who-text { display: flex; flex-direction: column; min-width: 0; }
.who-text strong { font-size: 0.98rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who-text span, .status, .lesson { color: var(--muted); font-size: 0.92rem; }
.caps { display: flex; flex-wrap: wrap; gap: 1px; justify-content: flex-end; min-height: 22px; }
.caps img { width: 16px; height: 16px; }
.clock {
  min-width: 76px; text-align: center; font-variant-numeric: tabular-nums;
  font-weight: 700; letter-spacing: 0.04em;
  background: #221c17; border-radius: 4px; padding: 8px 10px;
  border: 1px solid transparent;
}
.clock.is-running { border-color: var(--gold); color: var(--gold-2); }
.clock.is-low { color: #ffb4a8; border-color: var(--danger); }
.table { width: min(100%, 720px); margin: 0 auto; }
.frame {
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) 16px;
  background: linear-gradient(180deg, #8d6844, #3f2a1b);
  padding: 10px 12px 4px 2px;
  border-radius: 3px;
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255,255,255,0.28), inset 0 0 0 1px rgba(0,0,0,0.35);
}
.ranks, .files { display: grid; color: rgba(255, 236, 210, 0.78); font-size: 11px; font-weight: 700; }
.ranks { grid-column: 1; grid-row: 1; grid-template-rows: repeat(8, 1fr); align-items: center; justify-items: center; }
.files { grid-column: 2; grid-row: 2; grid-template-columns: repeat(8, 1fr); align-items: center; justify-items: center; }
.board { grid-column: 2; grid-row: 1; }
.table, .frame, .board, #squares, #pieces, .files, .ranks { direction: ltr; }
.board { position: relative; width: 100%; aspect-ratio: 1; touch-action: none; user-select: none; background: #111; }
#squares { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); }
.sq { position: relative; }
.sq.light { background: linear-gradient(180deg, rgba(255,255,255,0.16), rgba(255,255,255,0) 46%), var(--light); }
.sq.dark { background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(0,0,0,0.12)), var(--dark); }
.sq.last { box-shadow: inset 0 0 0 999px rgba(255, 214, 120, 0.34); }
.sq.selected { box-shadow: inset 0 0 0 3px var(--gold-2); }
.sq.check { box-shadow: inset 0 0 0 999px rgba(196, 71, 58, 0.55); }
.dot, .ring {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  pointer-events: none;
}
.dot { width: 18%; height: 18%; border-radius: 50%; background: rgba(28, 20, 12, 0.38); }
.ring { width: 86%; height: 86%; border-radius: 50%; border: 3px solid rgba(28, 20, 12, 0.4); }
.sq.hint-from, .sq.hint-to { box-shadow: inset 0 0 0 3px #7dcea0; }
#pieces { position: absolute; inset: 0; pointer-events: none; }
.piece {
  position: absolute; width: 12.5%; height: 12.5%;
  display: grid; place-items: center;
  transition: left 0.16s ease, top 0.16s ease;
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.55)) drop-shadow(0 5px 4px rgba(0, 0, 0, 0.28));
}
.piece img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.piece.lift { z-index: 3; filter: drop-shadow(0 8px 4px rgba(0, 0, 0, 0.45)); transform: translateY(-3px); }
.piece.captured { animation: take 0.18s ease forwards; }
@keyframes take { to { opacity: 0; transform: scale(0.6); } }
body.calm .piece { transition: none; animation: none; }
.promo {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  display: flex; gap: 6px; z-index: 4;
  background: rgba(20, 17, 14, 0.92); padding: 8px; border: 1px solid var(--line);
}
.promo button { width: 52px; height: 52px; background: var(--btn); border: 1px solid var(--line); padding: 4px; }
.promo img { width: 100%; height: 100%; object-fit: contain; }
.status, .lesson { margin: 0; min-height: 1.3em; }
.lesson-nav { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.lesson-nav button, .btn, .tool-row button {
  border: 1px solid var(--line); background: var(--btn); border-radius: 4px; min-height: 44px; padding: 8px 12px;
}
.btn.primary, .lesson-nav button.is-ready { background: var(--gold-2); color: #1a140e; border-color: transparent; font-weight: 700; }
.side { display: flex; flex-direction: column; gap: 16px; }
.panel h2, .settings h2 { font-family: var(--serif); font-weight: 500; font-size: 1.15rem; margin: 0 0 8px; }
fieldset { border: 0; margin: 0 0 12px; padding: 0; }
legend { color: var(--muted); font-size: 0.82rem; letter-spacing: 0.04em; text-transform: uppercase; margin-bottom: 6px; }
.choices { display: flex; flex-wrap: wrap; gap: 6px; }
.choices label {
  display: inline-flex; align-items: center; min-height: 36px;
  border: 1px solid var(--line); border-radius: 4px; padding: 0 8px; background: var(--bg-2);
}
.choices input { margin: 0 6px 0 0; }
.start-row, .sheet-row, .tool-row { display: flex; flex-wrap: wrap; gap: 8px; }
.start-row { margin-top: 4px; }
.tool-row { margin-bottom: 12px; }
.moves {
  list-style: none; margin: 0 0 16px; padding: 8px;
  max-height: 220px; overflow: auto;
  background: #100e0c; border: 1px solid var(--line); border-radius: 4px;
  font-variant-numeric: tabular-nums; min-height: 72px;
}
.moves li { display: grid; grid-template-columns: 2.2em 1fr 1fr; gap: 8px; padding: 3px 0; }
.moves .num { color: var(--muted); }
.settings { display: flex; flex-direction: column; gap: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.check { display: flex; gap: 8px; align-items: center; min-height: 36px; }
.field { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 0.92rem; }
.field select, .settings select { background: var(--btn); border: 1px solid var(--line); border-radius: 4px; padding: 8px; min-height: 40px; }
.sc-ad-slot,
#sc-ad-top,
#sc-ad-after-result,
#sc-footer-ad-anchor,
#sc-seo-ad-anchor {
  width: 100%;
  max-width: 100%;
  margin-left: auto;
  margin-right: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.sc-ad-slot .sc-ad-label,
.sc-ad-slot ins.adsbygoogle {
  margin-left: auto;
  margin-right: auto;
  text-align: center;
}
.side .sc-ad-slot { margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--line); background: #14110e; max-height: 300px; overflow: hidden; }
.side .sc-ad-slot ins.adsbygoogle { background: #14110e !important; max-height: 250px !important; }
.seo-content { margin: 36px auto 0; max-width: 78ch; }
.seo-content h2 { font-family: var(--serif); font-weight: 500; font-size: 1.55rem; margin: 28px 0 8px; }
.seo-content h3 { font-family: var(--serif); font-weight: 500; font-size: 1.15rem; margin: 18px 0 6px; }
.seo-content p { color: var(--muted); margin: 0 0 10px; }
.foot { width: min(1520px, calc(100% - 32px)); margin: 0 auto; padding: 8px 0 calc(28px + env(safe-area-inset-bottom)); color: var(--muted); font-size: 0.88rem; }
.toast {
  position: fixed; top: 72px; left: 50%; transform: translateX(-50%);
  background: #2a241e; border: 1px solid var(--line); color: var(--ink);
  padding: 10px 14px; border-radius: 4px; z-index: 20; max-width: min(92vw, 420px);
}
.modal {
  position: fixed; inset: 0; background: rgba(10, 8, 6, 0.62);
  display: grid; place-items: center; z-index: 30; padding: 16px;
}
.sheet {
  width: min(420px, 100%); background: #1c1814; border: 1px solid var(--line);
  padding: 20px; box-shadow: var(--shadow);
}
.sheet h2 { font-family: var(--serif); font-weight: 500; margin: 0 0 8px; }
.sheet p { margin: 0 0 14px; color: var(--muted); }
body.board-walnut { --light: #efd3a4; --dark: #b06a38; }
body.board-maple { --light: #f0d9b5; --dark: #b58863; }
body.board-emerald { --light: #eeeed2; --dark: #769656; }
body.board-slate { --light: #dfe5ea; --dark: #7f96a3; }
.board.mate { outline: 2px solid var(--gold); outline-offset: 4px; }
@media (max-width: 1100px) {
  .arena { grid-template-columns: 1fr; gap: 14px; }
  .rail { position: static; flex-direction: row; overflow-x: auto; padding-bottom: 4px; }
  .rail button { flex: none; }
  .rail button.is-on { box-shadow: inset 0 -2px 0 var(--gold); }
  .record { display: none; }
  .table { width: 100%; }
}
@media (max-width: 720px) {
  .wrap { width: min(100% - 16px, 1520px); }
  .top { padding: 10px 12px; }
  .product { display: none; }
  .seat { grid-template-columns: minmax(0, 1fr) auto; }
  .caps { display: none; }
  .tool-row button { flex: 1 1 30%; }
  .frame { padding: 8px 8px 2px 2px; }
}
@media (min-width: 1600px) {
  .wrap { width: min(1680px, calc(100% - 48px)); }
  .arena { grid-template-columns: 220px minmax(640px, 1fr) 320px; gap: 28px; }
}
