:root {
  color-scheme: light;
  font-family: Geist, "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --paper: #f0f3ed;
  --ink: #162a24;
  --muted: #54635a;
  --line: #cbd6cc;
  --card: #fafcf8;
  --mint: #78ebc2;
  --amber: #ffc068;
  --dark: #172a24;
  font-synthesis: none;
  background: var(--paper);
  color: var(--ink);
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 290px; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .48; }
button:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 3px solid #197956;
  outline-offset: 3px;
}
[hidden] { display: none !important; }
p, h1, h2, h3 { margin: 0; }

.topbar { background: #e7ede5; border-bottom: 1px solid #ced8ce; }
.topbar-inner {
  max-width: 1152px;
  min-height: 75px;
  margin: 0 auto;
  padding: 12px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.brand, .top-actions { display: flex; align-items: center; gap: 12px; }
.brand { font-size: 24px; font-weight: 780; letter-spacing: -.06em; }
.brand-mark {
  display: grid;
  place-content: center;
  grid-template-columns: repeat(2, 5px);
  gap: 4px;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--dark);
  transform: rotate(-8deg);
}
.brand-mark i { width: 5px; height: 5px; border-radius: 50%; background: var(--mint); }
.brand-mark i:last-child { background: var(--amber); }

.button {
  appearance: none;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  min-height: 41px;
  padding: 7px 13px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--ink);
  font-weight: 650;
  font-size: .875rem;
  line-height: 1.3;
}
.button-outline { background: transparent; border-color: var(--line); }
.button-outline:hover:not(:disabled) { background: #e6eee6; border-color: #a7baab; }
.button-primary { background: #b6ecce; border-color: #a4d8ba; }
.button-primary:hover:not(:disabled) { background: #9de3be; border-color: #79ba9a; }
.full-width { width: 100%; }
.sound-meter { display: flex; align-items: center; gap: 2px; height: 15px; }
.sound-meter i { width: 2px; height: 6px; border-radius: 3px; background: currentColor; }
.sound-meter i:nth-child(2) { height: 13px; }
.sound-meter i:nth-child(3) { height: 9px; }
.sound-meter i:nth-child(4) { height: 5px; }
.sound-button[aria-pressed=false] .sound-meter { opacity: .45; }
.sound-button[aria-pressed=false] .sound-meter i { height: 2px; }

.layout {
  max-width: 1152px;
  padding: 31px 28px 42px;
  margin: 0 auto;
  display: grid;
  align-items: start;
  grid-template-columns: minmax(0, 1fr) minmax(288px, 342px);
  gap: 35px;
}
.arena { width: 100%; max-width: 668px; }
.arena-heading { display: flex; justify-content: space-between; align-items: end; gap: 12px; margin-bottom: 18px; }
.turn-label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: .875rem;
  font-weight: 650;
}
.turn-dot { height: 8px; width: 8px; border-radius: 50%; background: #278765; }
.turn-label[data-side=mint] .turn-dot { background: var(--team-mint-turn, #278765); }
.turn-label[data-side=amber] .turn-dot { background: var(--team-amber-turn, #a85f15); }
.turn-label[data-side=none] .turn-dot { background: #78877d; }
h1 { font-size: clamp(1.7rem, 3vw, 2.45rem); line-height: 1.07; letter-spacing: -.052em; font-weight: 760; }
.move-count { color: var(--muted); font-size: .875rem; font-weight: 620; font-variant-numeric: tabular-nums; white-space: nowrap; padding-bottom: 4px; }

.board-shell {
  position: relative;
  container-type: inline-size;
}
.board-case {
  --board-size: 9;
  --grid-gap: clamp(1px, .35cqi, 2.4px);
  --grid-padding: 3px;
  --frame: clamp(20px, 3.4vw, 35px);
  --grid-spaces: calc((var(--board-size) - 1) * var(--grid-gap) + 2 * var(--grid-padding) + 4px);
  --cube-size: min(calc((100cqi - 2 * var(--frame) - var(--grid-spaces)) / var(--board-size) * .71), 51px);
  position: relative;
  padding: var(--frame);
  background: linear-gradient(145deg, #324e41, #1b3028 48%, #122820);
  border: 1px solid #233d31;
  border-radius: 18px;
  box-shadow: inset 1px 1px 1px #769281b3, inset 0 -2px 2px #0c2118b3, 0 5px 0 #12271e, 0 13px 25px #10271a4d;
  transform: perspective(2200px) rotateX(23deg);
  transform-style: preserve-3d;
}
.board, .motion-layer {
  display: grid;
  grid-template: repeat(var(--board-size), minmax(0, 1fr)) / repeat(var(--board-size), minmax(0, 1fr));
  gap: var(--grid-gap);
  padding: var(--grid-padding);
  border: 1px solid transparent;
  transform-style: preserve-3d;
}
.board {
  aspect-ratio: 1;
  background: #122a21;
  border-color: #84a294;
  border-radius: 4px;
  box-shadow: inset 1px 1px 3px #071a12, 0 0 0 1px #0e241b, 0 2px 0 #56746670;
}
.square {
  --rim: #4a715e;
  --floor: #2b4d40;
  --well-inset: clamp(2px, .72cqi, 5px);
  position: relative;
  appearance: none;
  padding: 0;
  border: 1px solid #52695a;
  border-radius: 4px;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  background: linear-gradient(146deg, #b2cbb268, transparent 47%, #102b25a3), var(--rim);
  box-shadow: inset 0 1px #cce4cb77, inset 0 -1px #102b25b3, 0 1px 1px #05151080;
  transform-style: preserve-3d;
  color: #daffe8;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.square.light { --rim: #648775; --floor: #426756; }
.square::before {
  content: "";
  position: absolute;
  inset: var(--well-inset);
  pointer-events: none;
  border: 1px solid #1128208f;
  border-radius: 2px;
  background: radial-gradient(ellipse at 66% 80%, #a1c2a526, transparent 82%), var(--floor);
  box-shadow: inset 1px 2px 3px #081e16bc, inset -1px -1px 1px #dce8cb6b, 0 1px 0 #b6d2b178;
}
.square.last::after, .square.selected::after, .square.suggested::after, .square.path::after {
  content: "";
  position: absolute;
  inset: var(--well-inset);
  pointer-events: none;
  border-radius: 2px;
}
.square.last::after { border: 1px solid #b8d2ba77; background: #ade4c517; }
.square.selected::after { border: 2px solid #a2f5ca; background: #abf4ca28; }
.square.suggested::after { border: 2px dashed #ffe295; }
.square.path::after { background: radial-gradient(circle, #c0ffd594 18%, #adffd130 20%); }
.square[data-action=legal] { --floor: #4b7f65; }
.square[data-action=capture] { --floor: #735a42; }
.square:focus-visible { z-index: 4; outline: 2px solid #fff3ae; outline-offset: -3px; }
.castle {
  position: absolute;
  width: 71%;
  aspect-ratio: 1;
  border: 1px dashed var(--castle-color);
  border-radius: 8px;
  display: grid;
  place-items: center;
  pointer-events: none;
}
.square[data-castle=mint] { --castle-color: var(--team-mint-castle, #9ce8bd); }
.square[data-castle=amber] { --castle-color: var(--team-amber-castle, #f3c27b); }
.castle .crown { grid-area: auto; width: 41%; background: var(--castle-color); }
.end-marker {
  z-index: 3;
  position: absolute;
  width: 39%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 1px solid #abefc5;
  border-radius: 50%;
  background: #1b3729dc;
  color: #e1ffed;
  font-weight: 750;
  font-size: clamp(.62rem, 2.25cqi, .93rem);
  box-shadow: 0 1px 5px #0e201f60;
}
.square[data-action=capture] .end-marker {
  inset: auto 3px 3px auto;
  background: #5b3324;
  border-color: #ffe1a3;
  color: #ffe6b8;
}
.square.suggested .end-marker { border-color: #ffe295; }
.coordinates {
  position: absolute;
  display: grid;
  align-items: center;
  text-align: center;
  pointer-events: none;
  color: #b7c9bc;
  font-weight: 650;
  font-size: clamp(.65rem, 1.2vw, .8rem);
  line-height: 1;
}
.coordinates-top, .coordinates-bottom { grid-template-columns: repeat(var(--board-size), 1fr); left: var(--frame); right: var(--frame); height: var(--frame); }
.coordinates-left, .coordinates-right { grid-template-rows: repeat(var(--board-size), 1fr); top: var(--frame); bottom: var(--frame); width: var(--frame); }
.coordinates-top { top: 0; }
.coordinates-bottom { bottom: 0; }
.coordinates-left { left: 0; }
.coordinates-right { right: 0; }

.die {
  --cube-z: calc(var(--cube-size) / 2);
  position: relative;
  z-index: 2;
  width: var(--cube-size);
  aspect-ratio: 1;
  transform-style: preserve-3d;
  transform: translateZ(var(--cube-z));
  pointer-events: none;
}
.rotor { position: absolute; inset: 0; transform-style: preserve-3d; }
.die[data-side=mint] {
  --die-top: var(--team-mint-top, #b4f1d8);
  --die-edge: var(--team-mint-edge, #6da995);
  --die-bottom: var(--team-mint-front, #528e7b);
  --die-core: var(--team-mint-core, #2d6252);
  --die-line: var(--team-mint-rim, #d3ffeaa8);
  --die-symbol: var(--team-mint-crown, #183c32);
  --pip: var(--team-mint-pit, #183c32);
  --pip-base: var(--team-mint-pit-base, #38695a);
}
.die[data-side=amber] {
  --die-top: var(--team-amber-top, #ffcf86);
  --die-edge: var(--team-amber-edge, #d79851);
  --die-bottom: var(--team-amber-front, #b6793f);
  --die-core: var(--team-amber-core, #814f22);
  --die-line: var(--team-amber-rim, #fff1c4b8);
  --die-symbol: var(--team-amber-crown, #482b19);
  --pip: var(--team-amber-pit, #482b19);
  --pip-base: var(--team-amber-pit-base, #7d5030);
}
.face {
  --face-color: var(--die-edge);
  position: absolute;
  inset: 0;
  border-radius: 8%;
  border: 1px solid var(--die-core);
  background: linear-gradient(147deg, #c4fff837, transparent 33%, #14282097), var(--die-core);
  box-shadow: inset 0 1px var(--die-line);
  backface-visibility: hidden;
}
.face-panel {
  position: absolute;
  inset: 7%;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  place-items: center;
  padding: 7%;
  border-radius: 11%;
  background: linear-gradient(145deg, #fff7, transparent 45%, #18222132), var(--face-color);
  box-shadow: inset 1px 1px var(--die-line), inset -1px -1px #152b2673, 0 1px 1px #111f1bd9;
}
.face-top { --face-color: var(--die-top); transform: translateZ(var(--cube-z)); }
.face-bottom { transform: rotateY(180deg) translateZ(var(--cube-z)); }
.face-north { transform: rotateX(90deg) translateZ(var(--cube-z)); }
.face-south { --face-color: var(--die-bottom); transform: rotateX(-90deg) translateZ(var(--cube-z)); }
.face-east { transform: rotateY(90deg) translateZ(var(--cube-z)); }
.face-west { transform: rotateY(-90deg) translateZ(var(--cube-z)); }
.pip {
  width: 77%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(ellipse at 65% 72%, var(--pip-base) 20%, var(--pip) 68%);
  box-shadow: inset 1px 1px 1px #0a110ebf, 0 1px 0 var(--die-line), 0 -1px 0 #0b241c4d;
}
.die[data-role=king] .face-panel { box-shadow: inset 0 0 0 1px var(--die-line), inset 0 0 0 2px #3840335c; }
.crown {
  grid-area: 1 / 1 / 4 / 4;
  width: 84%;
  aspect-ratio: 1.28;
  background: var(--die-symbol);
  filter: drop-shadow(0 1px 0 var(--die-line, transparent));
  clip-path: polygon(0 20%, 27% 44%, 50% 1%, 73% 44%, 100% 20%, 85% 88%, 15% 88%);
}
.die-shadow {
  z-index: 1;
  position: absolute;
  width: var(--cube-size);
  aspect-ratio: 1;
  border-radius: 24%;
  box-shadow: 0 0 clamp(2px, .75cqi, 6px) 2px #071a13b8;
}
.motion-layer { position: absolute; inset: var(--frame); z-index: 5; pointer-events: none; }
.motion-slot { display: grid; place-items: center; min-width: 0; min-height: 0; transform-style: preserve-3d; }

.board-footer { margin: 19px 0 0; min-height: 42px; display: flex; align-items: start; gap: 12px; justify-content: space-between; }
.board-description { display: flex; flex: 1; align-items: start; gap: 12px; justify-content: space-between; line-height: 1.45; }
#board-caption { font-size: .9375rem; color: var(--muted); }
.castle-legend { color: var(--muted); flex: 0 0 auto; display: flex; gap: 6px; align-items: center; font-size: .825rem; margin-top: 2px; }
.castle-legend i { width: 11px; height: 11px; border: 1px dashed #718a74; border-radius: 2px; }

.sidebar { display: grid; gap: 13px; padding-top: 4px; }
.sidebar h2 { font-size: 1rem; letter-spacing: -.02em; font-weight: 720; }
.score-card, .control-card, .help-card, .history-card {
  border-radius: 12px;
  border: 1px solid #d5ded4;
  background: var(--card);
  padding: 17px;
}
.score-card { background: #172b23; border-color: #263d32; color: #f0f8ef; box-shadow: 0 4px 12px #172b2315; }
.score-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 13px; gap: 10px; }
.score-row { display: grid; grid-template-columns: 12px minmax(0, 1fr) 22px; align-items: center; gap: 9px; }
.score-row + .score-row { border-top: 1px solid #344d41; padding-top: 11px; margin-top: 11px; }
.score-mint { --player: var(--team-mint-swatch, var(--mint)); --player-ink: var(--team-mint-score, var(--mint)); }
.score-amber { --player: var(--team-amber-swatch, var(--amber)); --player-ink: var(--team-amber-score, var(--amber)); }
.color-marker { width: 10px; height: 10px; border-radius: 3px; background: var(--player); box-shadow: 0 0 0 1px #effff35c; transform: rotate(-12deg); }
.score-player { display: grid; gap: 2px; font-size: .9rem; font-weight: 650; }
.score-player small { font-size: .8rem; color: var(--player-ink); font-weight: 480; }
.score-row > strong { color: var(--player-ink); font-size: 1.5rem; font-weight: 720; text-align: right; font-variant-numeric: tabular-nums; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; margin: 13px 0 0; padding: 3px; border: 1px solid #d8e2d9; border-radius: 9px; background: #eaf0e8; }
.segmented button { min-height: 36px; border: 1px solid transparent; background: transparent; border-radius: 6px; font-size: .875rem; font-weight: 660; color: #4d6054; padding: 4px; }
.segmented button[aria-pressed=true] { background: #fff; color: var(--ink); border-color: #d3ded5; box-shadow: 0 1px 3px #29433119; }
.segmented button:hover:not([aria-pressed=true]) { color: var(--ink); background: #dce8df; }
.mode-controls { margin-top: 16px; }
.field-heading { display: flex; justify-content: space-between; gap: 8px; align-items: center; margin-bottom: 8px; font-size: .875rem; }
.field-heading span, .field-heading label { color: var(--muted); font-weight: 570; }
.field-heading strong { color: #23583f; font-weight: 730; }
.levels { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-bottom: 13px; }
.levels button { min-height: 38px; border: 1px solid #d0dbd0; background: #f2f6f1; color: var(--muted); border-radius: 6px; font-size: .9375rem; font-weight: 690; }
.levels button:hover { background: #e3efe4; }
.levels button[aria-pressed=true] { background: #25483a; border-color: #25483a; color: #fff; }
.help-heading { display: flex; align-items: center; justify-content: space-between; gap: 9px; }
.help-card p { margin: 8px 0 12px; font-size: .875rem; line-height: 1.42; color: var(--muted); }
.toggle { width: 43px; height: 24px; border: 1px solid #a6b8aa; border-radius: 99px; display: grid; align-items: center; padding: 2px; background: #d6e0d7; }
.toggle i { width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px #0a36234f; }
.toggle[aria-checked=true] { background: #307557; border-color: #307557; }
.toggle[aria-checked=true] i { justify-self: end; }
.history-card { padding: 13px 17px; }
.history-card summary { cursor: pointer; font-size: .875rem; font-weight: 670; }
.history-list { max-height: 180px; overflow-y: auto; margin: 12px 0 0; padding-left: 21px; font-size: .875rem; line-height: 1.5; color: var(--muted); }
.history-list:empty::after { content: "Здесь появятся сыгранные ходы."; }
.history-list li + li { margin-top: 3px; }

#join-form { margin-top: 13px; }
#join-form label { display: block; font-size: .875rem; margin-bottom: 6px; }
.join-row { display: flex; gap: 7px; }
input {
  min-width: 0;
  width: 100%;
  border: 1px solid #c5d3c7;
  border-radius: 7px;
  padding: 7px 8px;
  color: var(--ink);
  background: white;
  min-height: 39px;
  font-size: .875rem;
}
#room-code { text-transform: uppercase; }
#room-code::placeholder { text-transform: none; }
.invite-value { margin-top: 8px; }
.room-display { letter-spacing: .14em; font-variant-numeric: tabular-nums; }
.room-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 8px; }
.network-status { font-size: .875rem; line-height: 1.4; color: var(--muted); }
.network-status:not(:empty) { margin-top: 9px; }
.network-status[data-error=true] { color: #952f26; }

.outcome { z-index: 7; position: absolute; inset: 0; display: grid; place-items: center; padding: 17px; background: #11251fc9; border-radius: 17px; }
.outcome-card { max-width: 350px; padding: 24px; border-radius: 12px; background: var(--card); box-shadow: 0 8px 24px #06120d70; text-align: center; }
.outcome-card h2 { font-size: 1.65rem; line-height: 1.2; letter-spacing: -.045em; }
.outcome-card p { margin-top: 8px; line-height: 1.45; color: var(--muted); }
.outcome-actions { display: flex; justify-content: center; gap: 7px; margin-top: 16px; flex-wrap: wrap; }

dialog {
  width: min(640px, calc(100% - 24px));
  padding: 0;
  max-height: min(86vh, 760px);
  border: 1px solid #b8cdbf;
  border-radius: 14px;
  box-shadow: 0 16px 70px #11251f55;
  color: var(--ink);
  background: var(--card);
}
dialog::backdrop { background: #13291fcc; }
.dialog-heading { position: sticky; z-index: 2; top: 0; display: flex; align-items: center; justify-content: space-between; gap: 9px; padding: 17px 22px; border-bottom: 1px solid var(--line); background: var(--card); }
.dialog-heading h2 { font-size: clamp(1.275rem, 3vw, 1.66rem); line-height: 1.16; letter-spacing: -.043em; }
.rules-copy { padding: 17px 22px 24px; font-size: 1rem; line-height: 1.55; }
.rules-copy h3 { margin: 14px 0 4px; font-size: 1rem; }
.rules-intro { font-weight: 700; }
.rule-distances { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-top: 12px; }
.rule-distances div { display: grid; gap: 2px; background: #eaf0e8; border: 1px solid #d8e2d9; border-radius: 7px; padding: 8px; font-size: .875rem; }
.rule-distances span { color: var(--muted); }

@media (min-width: 1000px) and (max-height: 900px) {
  .topbar-inner { min-height: 64px; }
  .layout { grid-template-columns: minmax(0, clamp(380px, 100svh - 205px, 630px)) minmax(288px, 342px); justify-content: center; gap: 28px; padding-top: 18px; }
  .arena-heading { margin-bottom: 13px; }
  .board-footer { margin-top: 15px; }
  .sidebar { gap: 10px; }
  .score-card, .control-card, .help-card { padding: 14px; }
  .score-heading { margin-bottom: 9px; }
  .score-row + .score-row { padding-top: 8px; margin-top: 8px; }
  .mode-controls { margin-top: 12px; }
}
@media (max-width: 900px) {
  .topbar-inner { padding-inline: 20px; }
  .layout { padding-inline: 18px; gap: 20px; grid-template-columns: minmax(0, 1fr) 285px; }
  .score-card, .control-card, .help-card { padding: 13px; }
}
@media (max-width: 730px) {
  .layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; max-width: 620px; padding-top: 19px; }
  .topbar-inner { min-height: 62px; padding-inline: 16px; }
  .arena-heading { margin-bottom: 12px; }
  .board-case { border-radius: 12px; --frame: clamp(17px, 4vw, 28px); transform: perspective(2200px) rotateX(20deg); }
  .board-footer { margin-top: 14px; }
  .sidebar { padding-top: 0; }
}
@media (max-width: 390px) {
  .layout { padding-inline: 11px; }
  .topbar-inner { padding-inline: 11px; }
  .top-actions { gap: 5px; }
  .button { padding-inline: 9px; }
  .brand { gap: 7px; font-size: 21px; }
  .brand-mark { width: 31px; height: 31px; }
  .board-description { gap: 7px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; }
}
.square:is(.rolling-origin, .rolling-capture) > :is(.die, .die-shadow) { visibility: hidden; }
