@import url("https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700;800&family=Newsreader:ital,opsz,wght@1,6..72,500&display=swap");

:root {
  color-scheme: light;
  --navy-950: #0b2033;
  --navy-900: #132d46;
  --navy-800: #1d3c59;
  --blue-muted: #627b91;
  --paper: #f3f0e8;
  --paper-deep: #e9e4d8;
  --serif: "Newsreader", Georgia, serif;
  --sans: "DM Sans", system-ui, sans-serif;
  --site-rail-width: 278px;
  --site-rail-active-text: #f6edd2;
  --bg: var(--paper);
  --ink: #17283a;
  --muted: #627b91;
  --panel: rgba(255, 255, 255, 0.64);
  --panel-soft: rgba(255, 255, 255, 0.42);
  --line: rgba(19, 45, 70, 0.16);
  --accent: #1d3c59;
  --accent-strong: #132d46;
  --accent-contrast: #ffffff;
  --maize: #d2ad52;
  --maize-bright: #ffcb05;
  --maize-soft: #eee2bd;
  --soft: #e9e4d8;
  --danger: #a73535;
  --danger-soft: #fae7e7;
  --light-square: #f8f6ef;
  --dark-square: #8fc7e8;
  --selected-light-square: #d8edf8;
  --selected-dark-square: #55c4dc;
  --legal-move-marker: rgba(28, 42, 54, 0.18);
  --legal-marker-light: var(--legal-move-marker);
  --legal-marker-dark: var(--legal-move-marker);
  --coord-ink: rgba(16, 36, 52, 0.62);
  --selected: #ffcb05;
  --arrow: #c94f2d;
  --white-piece: #ffffff;
  --white-piece-outline: rgba(15, 23, 35, 0.84);
  --black-piece: #101720;
  --black-piece-outline: rgba(255, 255, 255, 0.66);
  --shadow: 0 14px 38px rgba(19, 45, 70, 0.08);
  font-family: var(--sans);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1723;
  --ink: #eef4ff;
  --muted: #aab7c8;
  --panel: #172233;
  --panel-soft: #1c293c;
  --line: #2d3a4d;
  --accent: #ffcb05;
  --accent-strong: #ffdb4d;
  --accent-contrast: #0f1723;
  --maize: #ffcb05;
  --maize-soft: #40371d;
  --soft: #23334a;
  --danger: #ff9f9f;
  --danger-soft: #3a2026;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.24);
}

:root[data-board-theme="michigan"] {
  --light-square: #e3bd38;
  --dark-square: #294965;
  --selected-light-square: #f6d55c;
  --selected-dark-square: #426b89;
  --legal-marker-light: rgba(0, 39, 76, 0.25);
  --legal-marker-dark: rgba(255, 255, 255, 0.3);
  --coord-ink: rgba(0, 30, 58, 0.82);
  --arrow: #b53f30;
}

:root[data-board-theme="tournament"] {
  --light-square: #ebe8d6;
  --dark-square: #5d914f;
  --selected-light-square: #f3edb4;
  --selected-dark-square: #7bb768;
  --legal-marker-light: rgba(32, 68, 31, 0.22);
  --legal-marker-dark: rgba(255, 255, 255, 0.29);
  --coord-ink: rgba(28, 51, 31, 0.68);
  --arrow: #c04f35;
}

:root[data-board-theme="terracotta"] {
  --light-square: #ead8bd;
  --dark-square: #b76f52;
  --selected-light-square: #f3dfae;
  --selected-dark-square: #db8e65;
  --coord-ink: rgba(72, 38, 28, 0.7);
  --arrow: #174d70;
}

:root[data-board-theme="graphite"] {
  --light-square: #dce2e6;
  --dark-square: #52616c;
  --selected-light-square: #f0f2c2;
  --selected-dark-square: #748692;
  --coord-ink: rgba(21, 31, 39, 0.68);
  --arrow: #d39815;
}

:root[data-board-theme="lions"] {
  --light-square: #c9cdd1;
  --dark-square: #0076b6;
  --selected-light-square: #e5e8eb;
  --selected-dark-square: #18a5df;
  --coord-ink: rgba(0, 34, 68, 0.78);
  --arrow: #002244;
}

:root[data-board-theme="tigers"] {
  --light-square: #e99845;
  --dark-square: #183a61;
  --selected-light-square: #ffc06a;
  --selected-dark-square: #35628c;
  --legal-marker-light: rgba(15, 42, 71, 0.27);
  --legal-marker-dark: rgba(255, 255, 255, 0.32);
  --coord-ink: rgba(12, 35, 64, 0.84);
  --arrow: #fa4616;
}

:root[data-board-theme="red-wings"] {
  --light-square: #f7f3ea;
  --dark-square: #ce1126;
  --selected-light-square: #fff0cd;
  --selected-dark-square: #f04455;
  --coord-ink: rgba(74, 6, 14, 0.78);
  --arrow: #171717;
}

:root[data-board-theme="pistons"] {
  --light-square: #c83c4d;
  --dark-square: #3157b5;
  --selected-light-square: #ed5968;
  --selected-dark-square: #557bd6;
  --legal-marker-light: rgba(255, 255, 255, 0.34);
  --legal-marker-dark: rgba(255, 255, 255, 0.34);
  --coord-ink: rgba(255, 255, 255, 0.78);
  --arrow: #f5f7fa;
}

:root[data-board-theme="walnut"] {
  --light-square: #e5d3b6;
  --dark-square: #79513a;
  --selected-light-square: #f1dfbd;
  --selected-dark-square: #a27453;
  --coord-ink: rgba(67, 40, 25, 0.72);
  --arrow: #1d5e78;
}

:root[data-board-theme="midnight"] {
  --light-square: #aebdcc;
  --dark-square: #263548;
  --selected-light-square: #cad9e6;
  --selected-dark-square: #49627d;
  --coord-ink: rgba(14, 25, 39, 0.78);
  --arrow: #f2c94c;
}

:root[data-board-theme="accessibility"] {
  --light-square: #ffffff;
  --dark-square: #171717;
  --selected-light-square: #fff36a;
  --selected-dark-square: #007f99;
  --legal-move-marker: rgba(0, 213, 255, 0.42);
  --coord-ink: #000000;
  --selected: #00d5ff;
  --arrow: #ffbf00;
}

:root[data-piece-palette="ivory-charcoal"] {
  --white-piece: #fff3d6;
  --white-piece-outline: rgba(65, 47, 24, 0.88);
  --black-piece: #202936;
  --black-piece-outline: rgba(255, 246, 224, 0.7);
}

:root[data-piece-palette="high-contrast"] {
  --white-piece: #ffffff;
  --white-piece-outline: #05070a;
  --black-piece: #05070a;
  --black-piece-outline: #ffffff;
}

:root[data-piece-palette="michigan-pieces"] {
  --white-piece: #ffcb05;
  --white-piece-outline: #00274c;
  --black-piece: #00274c;
  --black-piece-outline: #ffdf64;
}

:root[data-piece-palette="steel-charcoal"] {
  --white-piece: #aeb8c2;
  --white-piece-outline: #20262d;
  --black-piece: #242a31;
  --black-piece-outline: #dce3e9;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

a {
  color: inherit;
}

button,
textarea,
select,
input {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}

button:hover {
  border-color: var(--accent);
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--maize-soft);
  border-color: var(--maize);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 700;
  padding: 0 16px;
}

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

.icon-button {
  width: 42px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  font-size: 20px;
}

.icon-button[aria-pressed="true"] {
  border-color: var(--maize);
  background: var(--maize-soft);
  color: var(--accent-strong);
}

.site-rail {
  position: fixed;
  z-index: 10;
  inset: 0 auto 0 0;
  width: var(--site-rail-width);
  display: flex;
  flex-direction: column;
  padding: 32px 28px;
  overflow-y: auto;
  background: var(--navy-900);
  color: #fff;
}

.site-rail::after {
  position: absolute;
  right: 18px;
  bottom: 18px;
  width: 76px;
  height: 76px;
  border: 1px solid rgba(210, 173, 82, 0.22);
  border-radius: 50%;
  content: "";
  pointer-events: none;
}

.portrait {
  position: relative;
  width: 104px;
  height: 104px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 3px solid var(--maize);
  border-radius: 50%;
  background: var(--navy-800);
  box-shadow: 0 0 0 7px rgba(210, 173, 82, 0.1);
}

.portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
}

.portrait-fallback {
  display: none;
  color: var(--maize);
  font-family: var(--serif);
  font-size: 56px;
  font-style: italic;
}

.portrait.image-missing .portrait-fallback {
  display: block;
}

.identity {
  margin-top: 28px;
}

.site-rail .eyebrow,
.nav-heading {
  color: var(--maize);
}

.identity strong {
  display: block;
  margin-top: 9px;
  font-family: var(--serif);
  font-size: 28px;
  font-style: italic;
  font-weight: 500;
  line-height: 1.05;
}

.site-nav {
  margin-top: 72px;
}

.nav-heading {
  display: block;
  margin-bottom: 12px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
  opacity: 0.78;
}

.nav-link {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 10px;
  align-items: center;
  margin: 0 -12px;
  padding: 15px 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  transition: 180ms ease;
}

.nav-link:hover,
.nav-link:focus-visible,
.nav-link.is-current {
  border-color: rgba(210, 173, 82, 0.45);
  background: rgba(255, 255, 255, 0.075);
  color: var(--site-rail-active-text);
  outline: none;
}

.nav-icon {
  color: var(--maize);
  font-size: 22px;
}

.nav-arrow {
  color: var(--maize);
}

.rail-note {
  max-width: 170px;
  margin: auto 0 0;
  padding-top: 54px;
  color: rgba(255, 255, 255, 0.5);
  font-size: 12px;
  line-height: 1.6;
}

.app {
  height: 100vh;
  height: 100dvh;
  width: calc(100vw - var(--site-rail-width));
  margin-left: var(--site-rail-width);
  padding: 10px 0;
  overflow: hidden;
}

.workspace {
  display: grid;
  grid-template-columns: clamp(260px, 22vw, 300px) minmax(440px, 1fr) clamp(340px, 28vw, 380px);
  gap: 5px;
  width: 100%;
  height: 100%;
  min-height: 0;
}

.panel,
.board-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.input-panel {
  min-height: 0;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.brand-lockup {
  display: flex;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  flex: 0 0 42px;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--maize);
  color: #00274c;
  font-size: 26px;
}

.eyebrow {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.1;
}

p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.field {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

textarea {
  width: 100%;
  min-height: 120px;
  flex: 1;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  color: var(--ink);
  background: var(--panel-soft);
  line-height: 1.45;
}

textarea:focus {
  outline: 3px solid var(--maize-soft);
  border-color: var(--accent);
}

.actions,
.toolbar,
.move-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.actions button {
  flex: 1;
}

.status {
  min-height: 44px;
  border-radius: 8px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 12px;
  line-height: 1.35;
}

.status.error {
  color: var(--danger);
  border-color: #e7b6b6;
  background: var(--danger-soft);
}

.board-panel {
  min-width: 0;
  min-height: 0;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}

.appearance-bar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

@media (min-width: 1101px) {
  .appearance-bar {
    min-height: 63px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: 54px;
    align-items: end;
    column-gap: 8px;
  }

  .appearance-bar .move-controls {
    justify-self: start;
    gap: 4px;
  }

  .appearance-bar .move-controls .icon-button {
    width: 30px;
  }

  .appearance-bar .appearance-controls {
    width: 100%;
    justify-content: flex-end;
    flex-wrap: nowrap;
    gap: 4px;
  }

  .appearance-bar .position-label {
    min-width: 60px;
    max-width: 60px;
  }

  #boardThemeSelect {
    width: 164px;
    max-width: none;
  }

  #pieceStyleSelect {
    width: 68px;
  }

  #piecePaletteSelect {
    width: 88px;
  }

  .appearance-bar .select-control select {
    padding-inline: 7px 20px;
  }
}

@media (min-width: 1101px) and (max-width: 1200px) {
  .appearance-bar {
    column-gap: 4px;
  }

  .appearance-bar .move-controls .icon-button {
    width: 27px;
  }

  .appearance-bar .position-label {
    min-width: 52px;
    max-width: 52px;
  }

  #boardThemeSelect {
    width: 132px;
  }

  #pieceStyleSelect {
    width: 58px;
  }

  #piecePaletteSelect {
    width: 72px;
  }

  .appearance-bar .icon-button {
    width: 32px;
  }

  .appearance-bar .theme-toggle {
    padding-inline: 5px;
  }

  .appearance-bar #themeLabel {
    display: none;
  }
}

.appearance-title strong {
  font-size: 18px;
  color: var(--accent-strong);
}

.appearance-controls {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
}

.select-control {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.select-control select {
  min-height: 40px;
  max-width: 138px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 32px 0 10px;
  background: var(--panel-soft);
  color: var(--ink);
  text-transform: none;
  cursor: pointer;
}

.select-control input {
  width: 82px;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: var(--panel-soft);
  color: var(--ink);
}

.theme-toggle {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
}

.toggle-track {
  position: relative;
  width: 34px;
  height: 18px;
  border-radius: 999px;
  background: var(--soft);
  box-shadow: inset 0 0 0 1px var(--line);
}

.toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent-strong);
  transition: transform 160ms ease, background 160ms ease;
}

.theme-toggle[aria-checked="true"] .toggle-thumb {
  transform: translateX(16px);
  background: var(--maize);
}

.toolbar {
  justify-content: space-between;
  flex-wrap: wrap;
}

.position-label {
  min-width: 104px;
  max-width: 130px;
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.stage {
  min-height: 0;
  flex: 1;
  display: grid;
  place-items: center;
}

.board-area {
  --board-size: 390px;
  display: grid;
  grid-template-columns: 46px var(--board-size);
  gap: 10px;
  align-items: stretch;
  width: calc(var(--board-size) + 56px);
  max-width: 100%;
}

.board-stack {
  min-width: 0;
  width: var(--board-size);
  display: grid;
  grid-template-rows: auto var(--board-size) auto;
  gap: 8px;
}

.player-label {
  min-height: 30px;
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.player-label strong {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-label > span:last-child {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.turn-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--line);
  box-shadow: 0 0 0 3px transparent;
}

.player-label.active .turn-indicator {
  background: var(--maize);
  box-shadow: 0 0 0 3px var(--maize-soft);
}

.player-label.active strong {
  color: var(--accent-strong);
}

.eval-bar {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
  height: 100%;
  min-height: 0;
  padding-block: 30px;
}

.eval-side {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  text-align: center;
  text-transform: uppercase;
}

.eval-track {
  position: relative;
  min-height: 0;
  border: 2px solid var(--accent-strong);
  border-radius: 8px;
  overflow: hidden;
  background: #202936;
}

.eval-bar.flipped .eval-track {
  transform: rotate(180deg);
}

.eval-fill {
  position: absolute;
  left: 0;
  width: 100%;
  transition: height 180ms ease;
}

.black-fill {
  top: 0;
  height: 50%;
  background: #202936;
}

.white-fill {
  bottom: 0;
  height: 50%;
  background: #f5f7f8;
}

.eval-midline {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 2px;
  background: var(--maize);
  transform: translateY(-1px);
}

.board {
  position: relative;
  width: var(--board-size);
  height: var(--board-size);
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border: 2px solid var(--accent-strong);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 18px 40px rgba(0, 39, 76, 0.16);
}

.square {
  position: relative;
  display: grid;
  place-items: center;
  user-select: none;
  container-type: size;
}

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

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

.square.selected-piece-square.light {
  background: var(--selected-light-square);
}

.square.selected-piece-square.dark {
  background: var(--selected-dark-square);
}

.legal-move-marker {
  position: absolute;
  z-index: 1;
  pointer-events: none;
}

.legal-move-marker.destination {
  width: 29%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--square-legal-marker, var(--legal-move-marker));
}

.legal-move-marker.capture {
  inset: 0;
  border-radius: 2px;
  box-shadow: inset 0 0 0 1.1cqw var(--square-legal-marker, var(--legal-move-marker));
}

.square.light .legal-move-marker {
  --square-legal-marker: var(--legal-marker-light);
}

.square.dark .legal-move-marker {
  --square-legal-marker: var(--legal-marker-dark);
}

.square.from,
.square.to {
  box-shadow: inset 0 0 0 999px color-mix(in srgb, var(--selected) 46%, transparent);
}

.piece {
  position: relative;
  z-index: 2;
  font-size: clamp(28px, 7vh, 68px);
  font-size: clamp(28px, 86cqh, 72px);
  line-height: 1;
  cursor: grab;
  touch-action: none;
  user-select: none;
  filter: drop-shadow(0 2px 1px rgba(0, 0, 0, 0.18));
}

.piece[data-color="w"] {
  color: var(--white-piece);
  text-shadow: -1px -1px 0 var(--white-piece-outline), 1px -1px 0 var(--white-piece-outline), -1px 1px 0 var(--white-piece-outline), 1px 1px 0 var(--white-piece-outline), 0 2px 2px rgba(0, 0, 0, 0.22);
}

.piece[data-color="b"] {
  color: var(--black-piece);
  text-shadow: -1px -1px 0 var(--black-piece-outline), 1px -1px 0 var(--black-piece-outline), -1px 1px 0 var(--black-piece-outline), 1px 1px 0 var(--black-piece-outline), 0 2px 2px rgba(0, 0, 0, 0.28);
}

:root[data-piece-style="vector"] .piece,
:root[data-piece-style="broadcast"] .piece {
  width: 86%;
  height: 86%;
  background: var(--piece-fill);
  color: transparent;
  font-size: 0;
  filter: drop-shadow(1px 0 0 var(--piece-outline)) drop-shadow(-1px 0 0 var(--piece-outline)) drop-shadow(0 1px 0 var(--piece-outline)) drop-shadow(0 -1px 0 var(--piece-outline));
  -webkit-mask-position: center;
  mask-position: center;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-size: contain;
  mask-size: contain;
}

:root[data-piece-style="vector"] .piece[data-color="w"],
:root[data-piece-style="broadcast"] .piece[data-color="w"] {
  --piece-fill: var(--white-piece);
  --piece-outline: var(--white-piece-outline);
}

:root[data-piece-style="vector"] .piece[data-color="b"],
:root[data-piece-style="broadcast"] .piece[data-color="b"] {
  --piece-fill: var(--black-piece);
  --piece-outline: var(--black-piece-outline);
}

:root[data-piece-style="broadcast"] .piece {
  width: 91%;
  height: 91%;
  filter: drop-shadow(1.5px 0 0 var(--piece-outline)) drop-shadow(-1.5px 0 0 var(--piece-outline)) drop-shadow(0 1.5px 0 var(--piece-outline)) drop-shadow(0 -1.5px 0 var(--piece-outline)) drop-shadow(0 2px 2px rgba(0, 0, 0, 0.3));
}

:root[data-piece-style="vector"] .piece[data-piece="p"],
:root[data-piece-style="broadcast"] .piece[data-piece="p"] {
  -webkit-mask-image: url("../public/pieces/cc0-vector/pawn.svg");
  mask-image: url("../public/pieces/cc0-vector/pawn.svg");
}

:root[data-piece-style="vector"] .piece[data-piece="r"],
:root[data-piece-style="broadcast"] .piece[data-piece="r"] {
  -webkit-mask-image: url("../public/pieces/cc0-vector/rok.svg");
  mask-image: url("../public/pieces/cc0-vector/rok.svg");
}

:root[data-piece-style="vector"] .piece[data-piece="n"],
:root[data-piece-style="broadcast"] .piece[data-piece="n"] {
  -webkit-mask-image: url("../public/pieces/cc0-vector/knight_3.svg");
  mask-image: url("../public/pieces/cc0-vector/knight_3.svg");
}

:root[data-piece-style="vector"] .piece[data-piece="b"],
:root[data-piece-style="broadcast"] .piece[data-piece="b"] {
  -webkit-mask-image: url("../public/pieces/cc0-vector/bishop_0.svg");
  mask-image: url("../public/pieces/cc0-vector/bishop_0.svg");
}

:root[data-piece-style="vector"] .piece[data-piece="q"],
:root[data-piece-style="broadcast"] .piece[data-piece="q"] {
  -webkit-mask-image: url("../public/pieces/cc0-vector/queen.svg");
  mask-image: url("../public/pieces/cc0-vector/queen.svg");
}

:root[data-piece-style="vector"] .piece[data-piece="k"],
:root[data-piece-style="broadcast"] .piece[data-piece="k"] {
  -webkit-mask-image: url("../public/pieces/cc0-vector/king_1.svg");
  mask-image: url("../public/pieces/cc0-vector/king_1.svg");
}

:root[data-piece-style="modern"] .piece {
  font-family: "Arial Unicode MS", "Noto Sans Symbols 2", sans-serif;
  font-size: clamp(27px, 6.6vh, 64px);
  font-size: clamp(27px, 86cqh, 70px);
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.34));
  transform: scaleX(0.94);
}

:root[data-piece-style="minimal"] .piece {
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(26px, 6.4vh, 62px);
  font-size: clamp(26px, 83cqh, 68px);
  filter: none;
  opacity: 0.9;
}

.piece:active {
  cursor: grabbing;
}

.drag-ghost {
  position: fixed;
  z-index: 20;
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.coord {
  position: absolute;
  left: 5px;
  bottom: 4px;
  font-size: 11px;
  color: var(--coord-ink);
  font-weight: 800;
}

.arrow-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 3;
}

.analysis {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.analysis-panel {
  min-width: 0;
  min-height: 0;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}

.analysis-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.analysis-heading .eyebrow {
  margin: 0;
}

.analysis-heading strong {
  color: var(--accent-strong);
  font-size: 16px;
}

.pv-strip {
  min-width: 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 14px;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 14px;
  background: var(--panel-soft);
}

.pv-strip span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.pv-strip strong {
  min-width: 0;
  overflow: hidden;
  font-size: 13px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.candidate-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel-soft);
}

.candidate-header,
.moves-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  background: var(--panel);
}

.analysis-panel .candidate-header {
  align-items: stretch;
  flex-direction: column;
  gap: 10px;
  padding: 11px 12px;
}

.candidate-header h2,
.moves-header h2 {
  margin: 0;
  font-size: 16px;
  color: var(--accent-strong);
}

.engine-controls {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.analysis-panel .engine-controls {
  justify-content: flex-start;
}

.stop-button {
  color: var(--danger);
  font-size: 15px;
}

.analysis-progress {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 16px;
  border-block: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.depth-warning {
  color: var(--danger);
}

.candidate-list {
  display: grid;
  gap: 1px;
  background: var(--line);
}

.candidate-row {
  width: 100%;
  min-height: 52px;
  display: grid;
  grid-template-columns: 28px minmax(56px, auto) minmax(110px, auto) minmax(0, 1fr) 24px;
  align-items: center;
  gap: 12px;
  border: 0;
  border-radius: 0;
  padding: 8px 16px;
  background: var(--panel);
  text-align: left;
}

.analysis-panel .candidate-row {
  min-height: 62px;
  grid-template-columns: 24px minmax(48px, auto) minmax(0, 1fr) 20px;
  gap: 8px;
  padding: 7px 12px;
}

.analysis-panel .candidate-score {
  grid-column: 3;
  grid-row: 1;
}

.analysis-panel .candidate-pv {
  grid-column: 2 / -1;
  grid-row: 2;
}

.analysis-panel .candidate-play {
  grid-column: 4;
  grid-row: 1;
}

.candidate-row:hover {
  background: var(--maize-soft);
}

.candidate-rank {
  color: var(--muted);
  font-weight: 800;
}

.candidate-move {
  color: var(--accent-strong);
  font-size: 16px;
}

.candidate-score {
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.candidate-pv {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.candidate-play {
  color: var(--accent);
  text-align: right;
}

.candidate-empty {
  min-height: 58px;
  display: grid;
  place-items: center;
  padding: 12px 16px;
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
}

.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 0;
  padding: 10px;
  background: var(--panel-soft);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin-top: 6px;
  min-height: 20px;
  font-size: 16px;
  overflow-wrap: anywhere;
}

.eval-summary strong {
  color: var(--accent-strong);
}

.moves-wrap {
  min-height: 100px;
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
}

.moves-header {
  border-bottom: 1px solid var(--line);
}

.moves-header span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.move-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1px;
  background: var(--line);
}

.move-pair {
  display: grid;
  grid-template-columns: 38px 1fr 1fr;
  gap: 1px;
  background: var(--line);
}

.move-pair > * {
  min-height: 38px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  background: var(--panel);
}

.move-number {
  color: var(--muted);
  font-weight: 800;
}

.move-token {
  border: 0;
  border-radius: 0;
  min-height: 38px;
  justify-content: flex-start;
  background: var(--panel);
}

.move-token.active {
  background: var(--maize-soft);
  color: var(--accent-strong);
  font-weight: 800;
}

@media (max-width: 1100px) {
  .app {
    width: calc(100vw - var(--site-rail-width));
    height: auto;
    min-height: 100vh;
    padding: 10px;
    overflow: visible;
  }

  .workspace {
    grid-template-columns: 1fr;
    gap: 12px;
    width: 100%;
    max-width: 900px;
    height: auto;
    margin: 0 auto;
  }

  .input-panel,
  .board-panel,
  .analysis-panel {
    min-height: auto;
    overflow: visible;
  }

  .input-panel {
    min-height: min(620px, calc(100vh - 20px));
  }

  textarea {
    min-height: 300px;
  }

  .stage {
    min-height: auto;
    display: grid;
    place-items: center;
    container-type: normal;
  }

  .board {
    width: 100%;
    height: auto;
    aspect-ratio: 1 / 1;
  }

  .board-area {
    width: min(100%, 620px);
    grid-template-columns: 46px minmax(0, 1fr);
    margin: 0 auto;
  }

  .board-stack {
    width: 100%;
    grid-template-rows: auto auto auto;
  }

  .analysis-panel {
    display: flex;
  }

  .moves-wrap {
    max-height: 360px;
  }
}

@media (max-width: 1040px) {
  .site-rail {
    position: relative;
    width: 100%;
    min-height: auto;
    display: grid;
    grid-template-columns: auto 1fr minmax(240px, 0.8fr);
    gap: 24px;
    align-items: center;
    padding: 22px 28px;
  }

  .site-rail::after,
  .identity .eyebrow,
  .rail-note,
  .nav-heading {
    display: none;
  }

  .portrait {
    width: 72px;
    height: 72px;
  }

  .identity,
  .site-nav {
    margin: 0;
  }

  .identity strong {
    margin: 0;
    font-size: 23px;
  }

  .app {
    width: 100%;
    margin-left: 0;
  }
}

@media (max-width: 720px) {
  .site-rail {
    grid-template-columns: auto 1fr;
  }

  .site-nav {
    grid-column: 1 / -1;
  }

  .appearance-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .appearance-controls {
    justify-content: flex-start;
  }
}

@media (max-width: 560px) {
  .app {
    padding: 10px;
  }

  .toolbar,
  .move-controls {
    width: 100%;
  }

  .candidate-header {
    align-items: stretch;
    flex-direction: column;
  }

  .engine-controls {
    justify-content: flex-start;
  }

  .candidate-row {
    grid-template-columns: 24px minmax(52px, auto) minmax(0, 1fr) 20px;
    gap: 8px;
    padding-inline: 10px;
  }

  .candidate-score {
    grid-column: 3;
    grid-row: 1;
    justify-self: start;
  }

  .candidate-pv {
    grid-column: 2 / -1;
    grid-row: 2;
    width: 100%;
  }

  .candidate-play {
    grid-column: 4;
    grid-row: 1;
  }

  .appearance-controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: end;
  }

  .select-control select {
    width: 100%;
    max-width: none;
  }

  .appearance-controls > .icon-button {
    width: 100%;
  }

  .theme-toggle {
    grid-column: 1 / -1;
    justify-content: center;
  }

  .move-controls {
    justify-content: space-between;
  }

  .position-label {
    min-width: 110px;
    font-size: 13px;
  }

  .board-area {
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 8px;
  }

  .eval-track {
    min-height: 220px;
    border-radius: 6px;
  }

  .eval-bar {
    padding-block: 30px;
  }

  .eval-side {
    font-size: 9px;
  }
}
