:root {
  --bg: #12120f;
  --panel: #1d1d19;
  --text: #f1ece0;
  --muted: #9b968a;
  --accent: #d9b45a;
  --sq-light: #e6dcc3;
  --sq-dark: #7f9068;
  --last: rgba(217, 180, 90, 0.45);
  --tentative: rgba(80, 150, 230, 0.55);
  --selected: rgba(217, 180, 90, 0.7);
  --danger: #e0705a;
  --warn: #e7b450;
  --ok: #8fc27a;
  --gap: 16px;
  --radius: 8px;
  --board: min(calc(100vw - 64px), 560px);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, sans-serif; }
a { color: var(--accent); }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; }
button, select { font: inherit; color: var(--text); background: #2a2a24; border: 1px solid #3c3c34; border-radius: 6px; padding: 7px 12px; }
button { cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: #1a160c; border-color: var(--accent); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.page { max-width: 1040px; margin: 0 auto; padding: var(--gap); }
.top { margin-bottom: var(--gap); }
.layout { display: flex; gap: calc(var(--gap) * 1.5); align-items: flex-start; flex-wrap: wrap; }
.play { flex: 0 0 auto; }
.side { flex: 1 1 280px; display: flex; flex-direction: column; gap: var(--gap); min-width: 260px; }
.side section { background: var(--panel); border-radius: var(--radius); padding: 12px 14px; }
footer { margin-top: calc(var(--gap) * 2); }

.board-row { display: flex; gap: 8px; }
.board {
  position: relative; width: var(--board); height: var(--board);
  display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr);
  border-radius: 4px; overflow: hidden; touch-action: none; user-select: none;
}
.sq { position: relative; }
.sq.light { background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }
.sq img { position: absolute; inset: 0; width: 100%; height: 100%; cursor: grab; }
.sq img.lifted { opacity: .3; }
.sq.last::before, .sq.tentative::before, .sq.selected::before { content: ''; position: absolute; inset: 0; }
.sq.last::before { background: var(--last); }
.sq.tentative::before { background: var(--tentative); }
.sq.selected::before { background: var(--selected); }
.sq.target::after {
  content: ''; position: absolute; left: 36%; top: 36%; width: 28%; height: 28%;
  border-radius: 50%; background: rgba(20, 20, 16, .35); pointer-events: none;
}
.sq.check { background: radial-gradient(circle, #f05a3c 0%, #c8402a 40%, transparent 75%), var(--sq-dark); }
.coord { position: absolute; font-size: 11px; font-weight: 600; pointer-events: none; }
.coord.rank { left: 3px; top: 2px; }
.coord.file { right: 4px; bottom: 1px; }
.sq.light .coord { color: var(--sq-dark); }
.sq.dark .coord { color: var(--sq-light); }
.ghost { position: fixed; pointer-events: none; z-index: 10; }
.promotion {
  position: absolute; inset: 0; z-index: 5; background: rgba(10, 10, 8, .8);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
}
.promotion button { width: 72px; height: 72px; padding: 4px; background: var(--sq-light); }
.promotion img { width: 100%; height: 100%; }

.evalbar { position: relative; width: 22px; height: var(--board); background: #26261f; border-radius: 4px; overflow: hidden; }
.evalbar-white { position: absolute; left: 0; right: 0; background: #f4f1e8; transition: height .4s ease; }
.evalbar-base { position: absolute; left: 0; right: 0; height: 2px; background: var(--danger); margin-bottom: -1px; }
.evalbar-label { position: absolute; left: 0; right: 0; text-align: center; font-size: 10px; font-weight: 700; }
.evalbar-label.for-white { color: #26261f; }
.evalbar-label.for-black { color: #f4f1e8; }

.controls { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; max-width: calc(var(--board) + 30px); }
.status { font-size: 17px; font-weight: 600; }
.status.over { color: var(--accent); }
.verdict { padding: 8px 12px; border-radius: 6px; font-weight: 600; }
.verdict.stronger { background: rgba(224, 112, 90, .18); color: var(--danger); }
.verdict.risky-sacrifice { background: rgba(231, 180, 80, .16); color: var(--warn); }
.eval-change { color: var(--muted); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.settings { display: flex; flex-direction: column; gap: 10px; }
.settings label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.settings label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 15px; }
.settings p { margin: 0; }
.opening p { margin: 0 0 6px; }
.hints ol { margin: 0; padding-left: 22px; }
.hints li { margin: 2px 0; }
.hints .grade-лучший b, .hints .grade-отличный b { color: var(--ok); }
.hints .grade-неточность b { color: var(--warn); }
.hints .grade-ошибка b { color: var(--danger); }
.candidates { margin: 0; padding-left: 18px; max-height: 260px; overflow: auto; }
.candidates li { margin: 2px 0; }
.moves ol { margin: 0; padding-left: 28px; columns: 2; }
.moves li span { margin-left: 10px; }

@media (max-width: 640px) {
  :root { --gap: 10px; --board: calc(100vw - 50px); }
  h1 { font-size: 19px; }
}
