/* SPDX-License-Identifier: GPL-3.0-only */

@font-face {
  font-family: "Instrument Sans";
  font-style: normal;
  font-weight: 400 600;
  font-display: swap;
  src: url("fonts/instrument-sans-latin.woff2") format("woff2");
}

@font-face {
  font-family: "Instrument Serif";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/instrument-serif-latin.woff2") format("woff2");
}

/* ---------- Theme tokens ---------- */

:root,
:root[data-theme="dark"] {
  color-scheme: dark;

  --bg: #181b20;
  --surface: #1e2228;
  --surface-raised: #242930;
  --surface-sunken: #14171b;
  --line: #2b313a;
  --line-strong: #3a414c;

  --text: #f2f4f5;
  --text-dim: #b6bdc6;
  --text-mute: #919aa4;
  --accent: #2dd4c0;
  --accent-hover: #59dfcf;
  --accent-text: #2dd4c0;
  --accent-ink: #082621;
  --accent-soft: #1d3431;
  --accent-line: #315b55;
  --danger: #e58f7d;
  --danger-soft: #352523;
  --danger-line: #5e3a33;
  --hover: #262c33;
  --hover-strong: #2d343c;
  --square-hover: rgba(255, 255, 255, 0.055);

  --board-light: #dfe3dc;
  --board-dark: #43615b;
  --board-light-coord: #23423c;
  --board-dark-coord: #dce9e5;
  --piece-light: #faf7ef;
  --piece-light-line: #1f2a28;
  --piece-dark: #1e2529;
  --piece-dark-line: #c4d1ce;
  --focus-board: #f4f0e6;

  --last-wash: rgba(45, 212, 192, 0.2);
  --last-wash-hover: rgba(45, 212, 192, 0.27);
  --selected-wash: rgba(45, 212, 192, 0.32);
  --selected-wash-hover: rgba(45, 212, 192, 0.38);
  --check-wash: rgba(229, 143, 125, 0.3);
  --check-wash-hover: rgba(229, 143, 125, 0.36);
  --target: rgba(8, 32, 26, 0.36);
  --target-on-dark: #e8f7f3;

  --backdrop: rgba(8, 10, 13, 0.64);
  --shadow-dialog: 0 34px 80px -28px rgba(0, 0, 0, 0.75);
  --shadow-menu: 0 18px 36px -18px rgba(0, 0, 0, 0.7);
  --shadow-board: 0 28px 54px -38px rgba(0, 0, 0, 0.8);
  --selection: rgba(45, 212, 192, 0.3);

  --font-sans: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-serif: "Instrument Serif", Georgia, "Times New Roman", serif;

  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);

  --board-size: clamp(300px, min(calc(100vw - 32px), calc(100dvh - 262px)), 720px);
}

:root[data-theme="light"] {
  color-scheme: light;

  --bg: #f1f0eb;
  --surface: #f8f7f2;
  --surface-raised: #fffefa;
  --surface-sunken: #e9e7e0;
  --line: #dedbd3;
  --line-strong: #c9c5bb;

  --text: #1a1e23;
  --text-dim: #4c555f;
  --text-mute: #646d77;
  --accent: #2dd4c0;
  --accent-hover: #20c4b2;
  --accent-text: #0b756b;
  --accent-ink: #072a25;
  --accent-soft: #dcf5f0;
  --accent-line: #8fd8cc;
  --danger: #a84432;
  --danger-soft: #f8e4df;
  --danger-line: #dfb7ad;
  --hover: #eeece6;
  --hover-strong: #e7e4dc;
  --square-hover: rgba(12, 24, 22, 0.055);

  --board-light: #ece8dd;
  --board-dark: #6d8a82;
  --board-light-coord: #3c5750;
  --board-dark-coord: #f2f7f4;
  --piece-light: #fffdf7;
  --piece-light-line: #2a332f;
  --piece-dark: #222b2e;
  --piece-dark-line: #e4ece9;
  --focus-board: #12171a;

  --last-wash: rgba(12, 138, 125, 0.22);
  --last-wash-hover: rgba(12, 138, 125, 0.29);
  --selected-wash: rgba(12, 138, 125, 0.32);
  --selected-wash-hover: rgba(12, 138, 125, 0.38);
  --check-wash: rgba(179, 77, 58, 0.3);
  --check-wash-hover: rgba(179, 77, 58, 0.36);
  --target: rgba(13, 45, 39, 0.38);
  --target-on-dark: #f7fffd;

  --backdrop: rgba(25, 28, 30, 0.42);
  --shadow-dialog: 0 34px 76px -32px rgba(38, 40, 38, 0.4);
  --shadow-menu: 0 18px 34px -18px rgba(38, 40, 38, 0.32);
  --shadow-board: 0 24px 44px -36px rgba(38, 40, 38, 0.5);
  --selection: rgba(20, 150, 136, 0.26);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  background: var(--bg);
  overflow-x: hidden;
}

body {
  margin: 0;
  min-width: 300px;
  min-height: 100dvh;
  color: var(--text);
  background: var(--bg);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

button,
summary {
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
}

button,
summary {
  touch-action: manipulation;
}

::selection {
  background: var(--selection);
  color: var(--text);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.svg-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.app {
  width: var(--board-size);
  max-width: calc(100% - 32px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: clamp(14px, 2.4vh, 24px) 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: clamp(11px, 1.8vh, 16px);
  container-type: inline-size;
  container-name: app;
}

/* ---------- Header ---------- */

.topbar {
  position: relative;
  z-index: 40;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  min-height: 40px;
  animation: enter 560ms var(--ease-out) both;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand__word {
  font-family: var(--font-serif);
  font-size: 28px;
  line-height: 1;
  letter-spacing: -0.025em;
  color: var(--text);
  white-space: nowrap;
}

.brand__dot {
  color: var(--accent);
}

.brand__meta {
  padding-left: 12px;
  border-left: 1px solid var(--line-strong);
  font-size: 8.5px;
  font-weight: 600;
  letter-spacing: 0.13em;
  line-height: 1.35;
  text-transform: uppercase;
  color: var(--text-mute);
  white-space: nowrap;
}

.status {
  display: flex;
  align-items: center;
  justify-self: center;
  gap: 8px;
  min-width: 0;
  white-space: nowrap;
}

.status__dot {
  width: 6px;
  height: 6px;
  flex: none;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  transition: background-color 180ms ease, box-shadow 180ms ease;
}

.status__text {
  overflow: hidden;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: -0.005em;
  text-overflow: ellipsis;
  color: var(--text);
  transition: color 180ms ease;
}

.status.is-check .status__dot {
  background: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-soft);
}

.status.is-check .status__text {
  color: var(--danger);
}

.status.is-over .status__dot {
  background: var(--text-dim);
  box-shadow: 0 0 0 3px var(--surface-raised);
}

.topbar__actions {
  display: flex;
  align-items: center;
  justify-self: end;
  gap: 7px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font-size: 12px;
  font-weight: 550;
  letter-spacing: -0.005em;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease,
    transform 120ms var(--ease-out);
}

.btn:active {
  transform: scale(0.97);
}

.btn--ghost {
  border-color: var(--line-strong);
  background: var(--surface);
  color: var(--text-dim);
}

.btn--primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.btn--danger {
  border-color: var(--danger-line);
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 600;
}

.btn--quiet {
  border-color: transparent;
  background: transparent;
  color: var(--text-mute);
}

.btn--icon {
  width: 40px;
  padding: 0;
}

.btn__icon {
  width: 14px;
  height: 14px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 220ms var(--ease-out);
}

#new-game {
  padding-left: 12px;
  padding-right: 12px;
}

@media (hover: hover) and (pointer: fine) {
  .btn--ghost:hover {
    border-color: var(--accent-line);
    background: var(--hover);
    color: var(--text);
  }

  #new-game:hover .btn__icon {
    transform: rotate(70deg);
  }

  .btn--primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
  }

  .btn--danger:hover {
    background: var(--danger-soft);
    border-color: var(--danger);
  }

  .btn--quiet:hover {
    background: var(--hover);
    color: var(--text);
  }
}

/* More menu */

.more {
  position: relative;
}

.more summary {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
  list-style: none;
  transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease;
}

.more summary::-webkit-details-marker {
  display: none;
}

.more summary svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.more[open] summary {
  border-color: var(--accent-line);
  background: var(--accent-soft);
  color: var(--accent-text);
}

.menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 30;
  width: 196px;
  padding: 5px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface-raised);
  box-shadow: var(--shadow-menu);
  transform-origin: top right;
  animation: menuIn 140ms var(--ease-out) both;
}

.menu button {
  width: 100%;
  min-height: 38px;
  padding: 0 11px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: background-color 140ms ease, color 140ms ease;
}

.menu .menu__danger {
  color: var(--danger);
}

.menu__sep {
  height: 1px;
  margin: 4px 7px;
  background: var(--line);
}

@media (hover: hover) and (pointer: fine) {
  .more summary:hover {
    border-color: var(--accent-line);
    color: var(--text);
  }

  .menu button:hover {
    background: var(--hover);
    color: var(--text);
  }

  .menu .menu__danger:hover {
    background: var(--danger-soft);
    color: var(--danger);
  }
}

/* ---------- Table ---------- */

.table {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.player {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  height: 52px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
  transition: background-color 200ms ease, border-color 200ms ease;
  animation: enter 560ms 60ms var(--ease-out) both;
}

.player--white {
  animation-delay: 150ms;
}

.player.is-active {
  border-color: var(--accent-line);
  background: var(--accent-soft);
}

.player.is-active::before {
  content: "";
  position: absolute;
  left: -1px;
  top: 12px;
  bottom: 12px;
  width: 2px;
  border-radius: 0 2px 2px 0;
  background: var(--accent);
}

.player.is-check {
  border-color: var(--danger-line);
  background: var(--danger-soft);
}

.player.is-check::before {
  background: var(--danger);
}

.player__who {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.player__king {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface-raised);
}

.player__king .piece-svg {
  width: 23px;
  height: 23px;
}

.player__id {
  min-width: 0;
}

.player__name {
  display: block;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.15;
  color: var(--text);
}

.player__state {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  color: var(--text-mute);
  font-size: 8.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  line-height: 1.15;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
  transition: color 180ms ease;
}

.player.is-active .player__state {
  color: var(--accent-text);
}

.player.is-check .player__state {
  color: var(--danger);
}

.player.is-winner .player__state {
  color: var(--accent-text);
}

.player__taken {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  margin-left: auto;
}

.player__label {
  flex: none;
  color: var(--text-mute);
  font-size: 8.5px;
  font-weight: 600;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.taken {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 2px 5px;
  min-height: 22px;
}

.taken__item {
  display: inline-flex;
  align-items: center;
  line-height: 1;
}

.taken .piece-svg {
  display: block;
  width: 21px;
  height: 21px;
  flex: none;
}

.taken__count {
  margin-left: 1px;
  padding-top: 4px;
  color: var(--text-mute);
  font-size: 9px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.taken__empty {
  color: var(--text-mute);
  font-size: 12px;
  line-height: 1;
  opacity: 0.65;
}

.player__score {
  display: flex;
  align-items: baseline;
  justify-content: flex-end;
  flex: none;
  gap: 4px;
  min-width: 82px;
}

.player__points {
  font-size: 22px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.045em;
  line-height: 1;
  color: var(--text);
}

.player__unit {
  font-size: 8.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-mute);
}

.player__edge {
  align-self: center;
  margin-left: 2px;
  padding: 3px 6px;
  border-radius: 99px;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 9px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
  line-height: 1;
}

.player.is-flash .player__points {
  animation: scoreFlash 420ms var(--ease-out);
}

/* ---------- Board ---------- */

.board-shell {
  position: relative;
  width: 100%;
  padding: 8px;
  border: 1px solid var(--line-strong);
  border-radius: 17px;
  background: var(--surface);
  box-shadow: var(--shadow-board);
  animation: boardEnter 640ms 100ms var(--ease-out) both;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  border-radius: 8px;
  background: var(--board-dark);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2);
  isolation: isolate;
  user-select: none;
}

.square {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  aspect-ratio: 1;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: var(--board-light);
  color: inherit;
  appearance: none;
  cursor: pointer;
}

.square.is-dark {
  background: var(--board-dark);
}

.square.is-light {
  background: var(--board-light);
}

.square::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  background: transparent;
  pointer-events: none;
  transition: background-color 150ms ease;
}

.square.is-last::before {
  background: var(--last-wash);
}

.square.is-selected::before {
  background: var(--selected-wash);
  box-shadow: inset 0 0 0 2px rgba(16, 60, 51, 0.16);
}

.square.is-check::before {
  background: var(--check-wash);
  box-shadow: inset 0 0 0 2.5px var(--danger);
}

.square.is-target::after {
  content: "";
  position: absolute;
  z-index: 3;
  width: 26%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--target);
  pointer-events: none;
  animation: targetIn 150ms var(--ease-out) both;
}

.square.is-dark.is-target::after {
  background: var(--target-on-dark);
}

.square.is-target.is-capture::after {
  inset: 5px;
  width: auto;
  height: auto;
  border: 2.5px solid var(--accent);
  border-radius: 5px;
  background: transparent;
}

.piece-wrap {
  position: relative;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 90%;
  height: 90%;
  pointer-events: none;
}

.piece-svg {
  display: block;
  width: 100%;
  height: 100%;
  fill: currentColor;
  stroke: var(--piece-line);
  stroke-width: 10;
  stroke-linejoin: round;
  paint-order: stroke fill;
}

.piece-svg--w {
  color: var(--piece-light);
  --piece-line: var(--piece-light-line);
}

.piece-svg--b {
  color: var(--piece-dark);
  --piece-line: var(--piece-dark-line);
}

.coord {
  position: absolute;
  z-index: 4;
  margin: 0;
  font-size: clamp(7px, 1.2vmin, 10px);
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1;
  pointer-events: none;
  opacity: 0.55;
}

.coord::before {
  content: attr(data-coord);
}

.coord--file {
  right: 5px;
  bottom: 4px;
}

.coord--rank {
  left: 5px;
  top: 4px;
}

.square.is-light .coord {
  color: var(--board-light-coord);
}

.square.is-dark .coord {
  color: var(--board-dark-coord);
}

.square.is-arrived .piece-wrap {
  animation: arrive 190ms var(--ease-out);
}

.square.is-selected .piece-wrap {
  transform: translateY(-2px) scale(1.015);
  transition: transform 150ms var(--ease-out);
}

.square:focus {
  outline: none;
}

.square:focus-visible {
  z-index: 5;
  outline: 2px solid var(--focus-board);
  outline-offset: -3px;
}

/* ---------- Preferences ---------- */

:root[data-coords="off"] .coord {
  display: none;
}

:root[data-last-move="off"] .square.is-last::before {
  background: transparent;
}

@media (hover: hover) and (pointer: fine) {
  .square:hover::before {
    background: var(--square-hover);
  }

  .square.is-last:hover::before {
    background: var(--last-wash-hover);
  }

  .square.is-selected:hover::before {
    background: var(--selected-wash-hover);
  }

  .square.is-check:hover::before {
    background: var(--check-wash-hover);
  }

  :root[data-last-move="off"] .square.is-last:hover::before {
    background: var(--square-hover);
  }
}

/* ---------- Footer ---------- */

.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: var(--text-mute);
  font-size: 10.5px;
  line-height: 1.4;
  animation: enter 560ms 210ms var(--ease-out) both;
}

.values {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px 11px;
  margin: 0;
}

.values__label {
  color: var(--text-dim);
  font-size: 8.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.values span {
  white-space: nowrap;
}

.values b {
  margin-left: 2px;
  color: var(--text-dim);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.first {
  margin: 0;
  flex: none;
  color: var(--text-mute);
  white-space: nowrap;
}

/* ---------- Dialogs ---------- */

.dialog {
  width: min(92vw, 420px);
  max-height: min(88dvh, 640px);
  margin: auto;
  padding: 26px;
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  background: var(--surface-raised);
  color: var(--text);
  box-shadow: var(--shadow-dialog);
}

.dialog[open] {
  animation: dialogIn 220ms var(--ease-out) both;
}

.dialog::backdrop {
  background: var(--backdrop);
  animation: backdropIn 220ms ease-out both;
}

.dialog__title {
  margin: 0 0 9px;
  font-family: var(--font-serif);
  font-size: clamp(30px, 5.4vw, 38px);
  font-weight: 400;
  letter-spacing: -0.022em;
  line-height: 1.02;
}

.dialog__sub {
  margin: 0;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.55;
}

.dialog__actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 24px;
}

.dialog__actions .btn {
  min-width: 118px;
}

.eyebrow {
  margin: 0 0 9px;
  color: var(--accent-text);
  font-size: 8.5px;
  font-weight: 600;
  letter-spacing: 0.15em;
  line-height: 1.2;
  text-transform: uppercase;
}

/* Promotion */

.promotion {
  width: min(92vw, 444px);
}

.promotion__options {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 7px;
  margin-top: 20px;
}

.promote {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding: 13px 4px 11px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background-color 160ms ease, border-color 160ms ease, transform 120ms var(--ease-out);
}

.promote .piece-svg {
  width: clamp(34px, 8vw, 48px);
  height: clamp(34px, 8vw, 48px);
}

.promote__name {
  max-width: 100%;
  overflow: hidden;
  font-size: 10.5px;
  font-weight: 500;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.promote__value {
  color: var(--text-mute);
  font-size: 8.5px;
  font-weight: 500;
  line-height: 1.2;
}

.promote:active {
  transform: scale(0.96);
}

@media (hover: hover) and (pointer: fine) {
  .promote:hover {
    border-color: var(--accent-line);
    background: var(--accent-soft);
  }
}

.promotion__cancel {
  width: 100%;
  margin-top: 12px;
  border-color: transparent;
  font-weight: 500;
}

/* Confirm */

.confirm .dialog__actions {
  margin-top: 26px;
}

/* Settings */

.settings {
  width: min(94vw, 480px);
  max-height: min(92dvh, 730px);
  padding: 26px;
}

.settings[open] {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.settings > :not(.settings__body) {
  flex-shrink: 0;
}

.settings__body {
  display: grid;
  flex: 1 1 auto;
  gap: 18px;
  min-height: 0;
  margin-top: 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.settings__body::-webkit-scrollbar {
  width: 8px;
}

.settings__body::-webkit-scrollbar-track {
  background: transparent;
}

.settings__body::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 99px;
  background: var(--line-strong);
  background-clip: padding-box;
}

.settings__group {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.settings__legend {
  display: block;
  margin: 0 0 8px;
  padding: 0;
  color: var(--text-mute);
  font-size: 8.5px;
  font-weight: 600;
  letter-spacing: 0.13em;
  line-height: 1.2;
  text-transform: uppercase;
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-sunken);
}

.segment {
  position: relative;
  min-width: 0;
}

.segment__input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.segment__label {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}

.segment__input:checked + .segment__label {
  border-color: var(--line-strong);
  background: var(--surface-raised);
  color: var(--text);
}

.segment__input:focus-visible + .segment__label {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (hover: hover) and (pointer: fine) {
  .segment__input:not(:checked) + .segment__label:hover {
    color: var(--text);
    background: var(--hover);
  }
}

.settings__options {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  padding: 0 13px;
}

.setting {
  position: relative;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 11px 0;
  cursor: pointer;
}

.setting + .setting {
  border-top: 1px solid var(--line);
}

.setting__copy {
  flex: 1;
  min-width: 0;
}

.setting__name {
  display: block;
  color: var(--text);
  font-size: 12px;
  font-weight: 550;
  line-height: 1.3;
}

.setting__desc {
  display: block;
  margin-top: 2px;
  color: var(--text-mute);
  font-size: 10.5px;
  line-height: 1.4;
}

.setting__input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.switch {
  position: relative;
  flex: none;
  width: 40px;
  height: 23px;
  border: 1px solid var(--line-strong);
  border-radius: 99px;
  background: var(--surface-sunken);
  transition: background-color 150ms ease, border-color 150ms ease;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--text-mute);
  transition: transform 170ms var(--ease-out), background-color 150ms ease;
}

.setting__input:checked + .switch {
  border-color: var(--accent);
  background: var(--accent);
}

.setting__input:checked + .switch::after {
  background: var(--accent-ink);
  transform: translateX(17px);
}

.setting__input:focus-visible + .switch {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (hover: hover) and (pointer: fine) {
  .setting:hover .switch {
    border-color: var(--accent-line);
  }
}

.about-link {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background-color 160ms ease, border-color 160ms ease,
    transform 120ms var(--ease-out);
}

.about-link:active {
  transform: scale(0.99);
}

.about-link__copy {
  flex: 1;
  min-width: 0;
}

.about-link__name {
  display: block;
  font-size: 12px;
  font-weight: 550;
  line-height: 1.3;
}

.about-link__desc {
  display: block;
  margin-top: 2px;
  color: var(--text-mute);
  font-size: 10.5px;
  line-height: 1.4;
}

.about-link__icon {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  color: var(--text-mute);
  transition: color 160ms ease, transform 160ms var(--ease-out);
}

@media (hover: hover) and (pointer: fine) {
  .about-link:hover {
    border-color: var(--accent-line);
    background: var(--hover);
  }

  .about-link:hover .about-link__icon {
    color: var(--accent-text);
    transform: translateX(2px);
  }
}

.settings__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 23px;
}

.settings__actions .btn {
  min-width: 0;
}

.settings__reset {
  margin-right: auto;
  padding-left: 0;
  padding-right: 0;
}

/* About */

.about {
  width: min(92vw, 460px);
  max-height: min(94dvh, 640px);
}

.credits {
  margin: 22px 0 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.credit {
  padding: 12px 14px;
}

.credit + .credit {
  border-top: 1px solid var(--line);
}

.credit dt {
  color: var(--text-mute);
  font-size: 8.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  line-height: 1.2;
  text-transform: uppercase;
}

.credit dd {
  margin: 4px 0 0;
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.55;
}

.credit a {
  color: var(--accent-text);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.about__note {
  margin: 12px 2px 0;
  color: var(--text-mute);
  font-size: 10.5px;
  line-height: 1.5;
}

.about .dialog__actions {
  margin-top: 22px;
}

@media (max-width: 620px) {
  .dialog.about {
    padding: 16px;
  }

  .about .credits {
    margin-top: 12px;
  }

  .about .credit {
    padding: 7px 12px;
  }

  .about .credit dd {
    line-height: 1.45;
  }

  .about .about__note {
    margin-top: 6px;
  }

  .about .dialog__actions {
    margin-top: 10px;
  }
}

@media (hover: hover) and (pointer: fine) {
  .credit a:hover {
    color: var(--accent-hover);
  }
}

/* Result */

.result {
  position: relative;
  width: min(92vw, 448px);
  padding: 30px;
  overflow: visible;
}

.result__close {
  position: absolute;
  top: 14px;
  right: 14px;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-mute);
  font-size: 22px;
  font-weight: 300;
  line-height: 1;
  cursor: pointer;
  transition: background-color 140ms ease, color 140ms ease;
}

.result__title {
  margin: 0 0 8px;
  font-family: var(--font-serif);
  font-size: clamp(44px, 9vw, 58px);
  font-weight: 400;
  letter-spacing: -0.035em;
  line-height: 0.95;
}

.result__scores {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 22px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.result__score {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.result__color {
  flex: none;
}

.mini-king {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface-raised);
}

.mini-king .piece-svg {
  width: 19px;
  height: 19px;
}

.result__name {
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 500;
}

.result__score strong {
  margin-left: auto;
  font-size: 18px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}

.result__divider {
  width: 1px;
  height: 24px;
  flex: none;
  background: var(--line);
}

.result__legend {
  margin: 8px 2px 0;
  color: var(--text-mute);
  font-size: 9px;
  letter-spacing: 0.04em;
  text-align: right;
}

.result .dialog__actions {
  margin-top: 22px;
}

@media (hover: hover) and (pointer: fine) {
  .result__close:hover {
    background: var(--hover);
    color: var(--text);
  }
}

/* ---------- Responsive ---------- */

@media (max-width: 620px) {
  .app {
    max-width: calc(100% - 24px);
    gap: 10px;
    padding: 12px 0;
  }

  .dialog {
    padding: 22px;
    border-radius: 17px;
  }

  .result {
    padding: 26px 22px 22px;
  }

  .dialog__actions {
    gap: 7px;
  }

  .dialog__actions .btn {
    flex: 1;
    min-width: 0;
  }

  .promotion__options {
    gap: 6px;
  }

  .promote {
    padding: 10px 3px 9px;
  }

  .settings__actions .btn {
    flex: 1;
  }

  .settings__reset {
    padding-left: 10px;
    padding-right: 10px;
  }
}

@media (max-height: 700px) and (min-width: 700px) {
  .app {
    padding: 10px 0;
    gap: 9px;
  }

  .player {
    height: 46px;
  }

  .table {
    gap: 6px;
  }

  .footer {
    font-size: 9.5px;
  }
}

@media (max-width: 360px) {
  #result-dialog {
    padding: 24px 18px 18px;
  }

  #result-dialog .dialog__actions {
    flex-direction: column;
  }

  #result-dialog .dialog__actions .btn {
    width: 100%;
    padding: 0 12px;
  }

  .settings {
    padding: 22px 18px;
  }

  .settings__actions {
    flex-direction: column-reverse;
  }

  .settings__actions .btn {
    width: 100%;
  }

  .settings__reset {
    margin-right: 0;
  }
}

/* ---------- Container-based compact layout ---------- */

@container app (max-width: 560px) {
  .brand__meta {
    display: none;
  }

  .topbar {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .status {
    justify-self: center;
  }
}

@container app (max-width: 460px) {
  .topbar {
    gap: 8px;
  }

  .brand__word {
    font-size: 25px;
  }

  .status__text {
    max-width: 128px;
    font-size: 11px;
  }

  .btn {
    min-height: 38px;
  }

  .btn--icon,
  .more summary {
    width: 38px;
    height: 38px;
  }

  #new-game {
    width: 38px;
    padding: 0;
  }

  .btn__label {
    display: none;
  }

  .btn__icon {
    width: 16px;
    height: 16px;
  }

  .table {
    gap: 7px;
  }

  .player {
    height: 48px;
    gap: 10px;
    padding: 0 11px;
  }

  .player__king {
    width: 27px;
    height: 27px;
  }

  .player__king .piece-svg {
    width: 21px;
    height: 21px;
  }

  .player__name {
    font-size: 12px;
  }

  .player__state {
    margin-top: 2px;
    font-size: 8px;
  }

  .player__taken {
    gap: 6px;
  }

  .player__label {
    display: none;
  }

  .taken {
    gap: 1px 4px;
  }

  .taken .piece-svg {
    width: 19px;
    height: 19px;
  }

  .player__score {
    min-width: 52px;
    gap: 3px;
  }

  .player__points {
    font-size: 20px;
  }

  .player__edge {
    padding: 2px 5px;
    font-size: 8.5px;
  }

  .board-shell {
    padding: 6px;
    border-radius: 15px;
  }

  .board {
    border-radius: 7px;
  }

  .coord {
    font-size: 8px;
  }

  .coord--file {
    right: 4px;
    bottom: 3px;
  }

  .coord--rank {
    left: 4px;
    top: 3px;
  }

  .footer {
    font-size: 9.5px;
  }

  .values {
    gap: 2px 8px;
  }

  .values__label {
    font-size: 8px;
  }

  .first {
    display: none;
  }
}

@container app (max-width: 380px) {
  .status__text {
    max-width: 104px;
  }

  .player__state {
    letter-spacing: 0.08em;
  }

  .player__score {
    min-width: 44px;
  }

  .player__unit {
    display: none;
  }

  .taken {
    gap: 1px 2px;
  }

  .taken .piece-svg {
    width: 17px;
    height: 17px;
  }

  .taken__count {
    margin-left: 0;
    padding-top: 2px;
    font-size: 8px;
  }

  .coord {
    opacity: 0.42;
  }

  .topbar__actions {
    gap: 5px;
  }

  .btn--icon,
  .more summary {
    width: 36px;
    height: 36px;
  }

  #new-game {
    width: 36px;
  }
}

@container app (max-width: 330px) {
  #settings-open {
    display: none;
  }
}

/* ---------- Motion ---------- */

@keyframes enter {
  from {
    opacity: 0;
    transform: translateY(7px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes boardEnter {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.992);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes menuIn {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(-3px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes targetIn {
  from {
    opacity: 0;
    transform: scale(0.58);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes arrive {
  0% {
    opacity: 0.55;
    transform: translateY(-3px) scale(0.97);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes scoreFlash {
  0% {
    color: var(--accent);
    transform: translateY(1px);
  }
  40% {
    color: var(--accent-text);
  }
  100% {
    color: var(--text);
    transform: translateY(0);
  }
}

@keyframes dialogIn {
  from {
    opacity: 0;
    transform: translateY(7px) scale(0.965);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes backdropIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

:root[data-motion="off"] *,
:root[data-motion="off"] *::before,
:root[data-motion="off"] *::after {
  animation-delay: 0s !important;
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-delay: 0s !important;
  transition-duration: 0.01ms !important;
}

@media (prefers-reduced-motion: reduce) {
  .topbar,
  .player,
  .board-shell,
  .footer {
    animation: none;
  }

  .square.is-target::after,
  .square.is-arrived .piece-wrap,
  .player.is-flash .player__points,
  .menu,
  .dialog[open],
  .dialog::backdrop {
    animation: none;
  }

  .btn,
  .btn__icon,
  .square::before,
  .piece-wrap {
    transition-duration: 0.01ms !important;
  }
}
