:root {
  color-scheme: dark;
  --accent: #c4b2f5;
  --bg: #141319;
  --panel: #1c1a23;
  --line: #ffffff10;
  --muted: #a19aaa;
  --outer: 10px;
  --header: 30px;
  --gap: 8px;
  --player: 32px;
  --game-gap: 5px;
  --panel-height: 128px;
  --side-width: clamp(180px, 27vw, 244px);
  --vh: 100vh;
  --board-size: max(0px, min(560px, calc(100vw - 2 * var(--outer)), calc(var(--vh) - 2 * var(--outer) - var(--header) - 2 * var(--gap) - 2 * var(--player) - 2 * var(--game-gap) - var(--panel-height))));
  font-family: Inter, 'Segoe UI', system-ui, sans-serif;
  font-size: 13px;
}
@supports (height: 100dvh) { :root { --vh: 100dvh; } }
* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; }
body { background: radial-gradient(ellipse at 50% -30%, #292232 0, transparent 68%), var(--bg); color: #f2eff8; }
main { height: var(--vh); width: 100%; max-width: 1080px; margin: auto; padding: var(--outer); display: grid; grid-template-rows: var(--header) minmax(0, 1fr); gap: var(--gap); }
.topbar { display: flex; align-items: center; justify-content: space-between; min-width: 0; padding: 0 3px; border-bottom: 1px solid var(--line); gap: 8px; }
.brand { display: flex; gap: 8px; align-items: center; min-width: 0; font-size: 11px; font-weight: 750; letter-spacing: .07em; white-space: nowrap; }
.brand-mark { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 7px; background: #c4b2f519; color: var(--accent); font-size: 20px; letter-spacing: 0; }
.brand-divider { color: #675e77; padding: 0 4px; }
.brand-game { font-weight: 500; letter-spacing: 0; color: var(--muted); }
.tag { display: flex; align-items: center; gap: 6px; white-space: nowrap; font-size: 9px; font-weight: 650; letter-spacing: .08em; color: var(--muted); }
.tag-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.layout { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--gap); min-height: 0; min-width: 0; }
.game { display: grid; grid-template-rows: var(--player) var(--board-size) var(--player); gap: var(--game-gap); width: var(--board-size); flex: none; min-width: 0; }
.player { display: flex; align-items: center; min-width: 0; gap: 8px; padding: 0 7px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.avatar { flex: none; display: grid; place-items: center; width: 24px; height: 24px; border-radius: 6px; font: 20px/1 'DejaVu Sans', 'Segoe UI Symbol', sans-serif; color: #252032; background: #c4b2f5; }
.avatar.black { background: #342e40; color: #e4d8fb; }
.player-info { min-width: 0; flex: 1; display: flex; align-items: baseline; gap: 7px; overflow: hidden; }
.player b { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12px; font-weight: 650; }
.player small { flex: none; color: var(--muted); font-size: 10px; }
.dot { width: 7px; height: 7px; flex: none; border-radius: 50%; background: #504a5c; }
.dot.active { background: var(--accent); box-shadow: 0 0 0 3px #c4b2f51a; }
.dot.thinking { animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: .35; } }
#board { display: grid; width: var(--board-size); height: var(--board-size); grid-template: repeat(8, minmax(0, 1fr)) / repeat(8, minmax(0, 1fr)); border-radius: 7px; overflow: hidden; touch-action: none; user-select: none; background: #d8d2e4; box-shadow: 0 0 0 1px #ffffff22, 0 8px 24px #0003; }
button { font: inherit; font-weight: 650; border: 0; border-radius: 6px; background: var(--accent); color: #241a35; cursor: pointer; transition: background .15s, opacity .15s, filter .15s; }
button:focus-visible, #history:focus-visible { outline: 2px solid #eee1ff; outline-offset: -2px; }
button:hover:not(:disabled):not(.cell) { filter: brightness(1.12); }
button:disabled { opacity: .38; cursor: not-allowed; }
.cell { border-radius: 0; padding: 0; position: relative; display: grid; place-items: center; width: 100%; height: 100%; min-width: 0; min-height: 0; background: #ded9e8; color: #696078; transition: none; }
.cell.dark { background: #817392; color: #e4dbef; }
.cell.last { background: #c9b6ee; }
.cell.dark.last { background: #9a83be; }
.cell.selected { box-shadow: inset 0 0 0 2px #fff0ff, inset 0 0 0 100px #a481d550; }
.cell.target::after { content: ''; position: absolute; width: 23%; height: 23%; border-radius: 50%; background: #2c214b65; pointer-events: none; }
.cell.target.occupied::after { width: 83%; height: 83%; border: max(2px, calc(var(--board-size) * .005)) solid #33205288; background: transparent; }
.cell.occupied { cursor: grab; }
.cell:active { cursor: grabbing; }
.piece { font-family: 'DejaVu Sans', 'Segoe UI Symbol', 'Noto Sans Symbols 2', sans-serif; line-height: 1; font-size: calc(var(--board-size) * .103); position: relative; z-index: 1; pointer-events: none; font-weight: 400; }
.piece.white { color: #fffaf4; -webkit-text-stroke: max(.4px, calc(var(--board-size) * .0017)) #38313e; text-shadow: 0 1px 2px #30263e45; }
.piece.black { color: #292334; -webkit-text-stroke: .45px #e5dcf080; text-shadow: 0 1px 2px #201a2a45; }
.coord { position: absolute; font-size: clamp(6px, calc(var(--board-size) * .019), 11px); font-weight: 750; pointer-events: none; line-height: 1; }
.rank { top: 3px; left: 3px; }.file { bottom: 3px; right: 3px; }
aside { flex: none; width: min(100%, max(280px, var(--board-size))); height: var(--panel-height); min-width: 0; min-height: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 9px; display: grid; grid-template-columns: minmax(0, .88fr) minmax(0, 1.12fr); grid-template-rows: minmax(0, 1fr) 29px; gap: 7px; }
.match-info { min-width: 0; min-height: 0; overflow: auto; scrollbar-width: thin; }
.eyebrow { font-size: 9px; letter-spacing: .08em; color: var(--muted); font-weight: 650; margin: 0 0 6px; }
#status { font-size: 13px; font-weight: 650; color: var(--accent); margin: 0; line-height: 1.3; overflow-wrap: anywhere; }
.moves { grid-column: 2; grid-row: 1 / 3; border: 1px solid var(--line); border-radius: 6px; min-height: 0; min-width: 0; display: flex; flex-direction: column; overflow: hidden; background: #17151d; }
.move-head, .move-row { display: grid; grid-template-columns: 22px minmax(0,1fr) minmax(0,1fr); gap: 5px; padding: 5px 7px; font-size: 11px; font-variant-numeric: tabular-nums; line-height: 1.3; }
.move-head { flex: none; color: var(--muted); background: #25212e; font-size: 10px; }
.move-row:nth-child(even) { background: #ffffff04; }
.move-row span:first-child { color: var(--muted); }
.move-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#history { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: #51465f transparent; }
#history:empty::after { content: 'Пока нет ходов'; display: block; color: var(--muted); padding: 9px 7px; font-size: 10px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; min-width: 0; }
.actions button { display: flex; align-items: center; justify-content: center; gap: 4px; font-size: 11px; padding: 0 4px; white-space: nowrap; min-width: 0; }
.actions svg { flex: none; width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.secondary { background: #34303e; color: #eee7fa; }
.hint { display: none; color: var(--muted); font-size: 10px; line-height: 1.4; margin: 0; }
.ghost { position: fixed; z-index: 20; display: grid; place-items: center; pointer-events: none; transform: translate(-50%, -50%); filter: drop-shadow(0 5px 4px #0005); }
dialog { border: 1px solid #ffffff22; background: var(--panel); color: #fff; border-radius: 12px; padding: 16px; max-width: calc(100vw - 16px); }
dialog::backdrop { background: #0009; }dialog h2 { font-size: 16px; margin: 0 0 12px; }#choices { display: flex; gap: 6px; margin-bottom: 10px; }#choices button { font-size: clamp(20px, 8vw, 32px); padding: 5px 8px; }#cancel { padding: 7px 12px; }
@media (min-width: 450px) and (min-aspect-ratio: 1/1), (min-width: 800px) {
  :root { --board-size: max(0px, min(560px, calc(100vw - 2 * var(--outer) - var(--side-width) - var(--gap)), calc(var(--vh) - 2 * var(--outer) - var(--header) - var(--gap) - 2 * var(--player) - 2 * var(--game-gap)))); }
  .layout { flex-direction: row; }
  aside { width: var(--side-width); height: calc(var(--board-size) + 2 * var(--player) + 2 * var(--game-gap)); display: flex; flex-direction: column; padding: 12px; gap: 10px; }
  .match-info { flex: none; max-height: 36%; }
  .moves { flex: 1; }
  .actions { flex: none; min-height: 30px; }
  .hint { display: block; flex: none; }
  #status { font-size: 15px; }
}
@media (max-height: 390px) and (min-aspect-ratio: 1/1) {
  :root { --outer: 6px; --header: 24px; --gap: 6px; --player: 26px; --game-gap: 4px; }
  .brand-mark { width: 20px; height: 20px; font-size: 17px; }.avatar { width: 20px; height: 20px; font-size: 17px; }
  aside { padding: 8px; gap: 6px; }.hint { display: none; }
}
@media (max-width: 540px) { .actions svg { display: none; }.player-info { gap: 5px; }.player small { font-size: 9px; } }
@media (max-height: 460px) and (max-aspect-ratio: 1/1) { :root { --outer: 6px; --header: 24px; --gap: 5px; --player: 25px; --game-gap: 3px; --panel-height: 104px; } .avatar { width: 19px; height: 19px; font-size: 16px; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
