@font-face {
  font-family: "Marcellus";
  src: url("/marcellus.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --page: #0a0a11;
  --surface: #12151d;
  --surface-2: #1a1e28;
  --surface-3: #20242f;
  --line: #2b303d;
  --ink: #eff5ff;
  --muted: #9aa3b2;
  --blue: #6da6ff;
  --red: #ff6b6b;
  --green: #4fd1a5;
  --brown: #e0a568;
  --purple: #c084fc;
  --focus: #f8fbff;
  --board-line: 2px;
  --piece-ring-line: 3px;
  --piece-ring-shadow: 2px;
  --quint-line: 3px;
  --quint-halo: 6px;
  color-scheme: dark;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  background:
    radial-gradient(1100px 700px at 50% -12%, rgba(192, 132, 252, 0.09), transparent 62%),
    radial-gradient(900px 650px at 88% 112%, rgba(109, 166, 255, 0.05), transparent 60%),
    var(--page);
  background-attachment: fixed;
  color: var(--ink);
  overflow-x: hidden;
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 390px);
  gap: 18px;
  height: 100vh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100dvh;
  max-width: 1500px;
  margin-inline: auto;
  padding: 18px;
}

.play-surface,
.side-panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--line) 85%, transparent);
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}

.play-surface {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 16px;
  min-height: 0;
  overflow: hidden;
  padding: 18px;
}

.side-panel {
  display: grid;
  grid-template-rows: auto auto auto minmax(130px, 1fr) auto;
  gap: 0;
  min-height: 0;
  overflow: hidden;
  background: #10131a;
}

.top-bar {
  display: grid;
  grid-template-columns: minmax(0, max-content) minmax(0, 1fr);
  align-items: start;
  gap: 18px;
}

.brand-block {
  min-width: 0;
}

.header-meta {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 12px;
  justify-self: end;
  width: 100%;
  min-width: 0;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-family: Marcellus, Georgia, serif;
  font-size: 30px;
  line-height: 1;
  font-weight: 400;
  letter-spacing: 0.045em;
}

h2 {
  font-size: 12px;
  line-height: 1.2;
  font-weight: 650;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}

h3 {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.09em;
  line-height: 1.2;
  text-transform: uppercase;
}

.status-line {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  justify-content: flex-end;
  margin-top: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  max-width: 100%;
  min-height: 28px;
  padding: 4px 9px;
  border: 1px solid rgba(154, 163, 178, 0.22);
  border-radius: 999px;
  background: rgba(26, 30, 40, 0.76);
  color: var(--muted);
  font-weight: 650;
}

.status-chip-primary {
  border-color: rgba(192, 132, 252, 0.38);
  background: rgba(192, 132, 252, 0.12);
}

.status-chip-muted {
  font-size: 11px;
  opacity: 0.72;
}

.status-turn {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  max-width: 100%;
  min-height: 34px;
  padding: 5px 14px;
  border: 1px solid rgba(192, 132, 252, 0.45);
  border-radius: 999px;
  background: rgba(192, 132, 252, 0.16);
  color: var(--ink);
  font-size: 15px;
  font-weight: 700;
}

.status-turn.status-over {
  border-color: rgba(192, 132, 252, 0.6);
  background: rgba(192, 132, 252, 0.22);
}

.turn-token {
  width: 16px;
  height: 16px;
  flex: none;
  border-radius: 50%;
}

.turn-token.turn-black {
  background: #0e131c;
  border: 2px solid #6b7790;
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.12);
}

.turn-token.turn-white {
  background: #eef3fb;
  border: 2px solid #9fadc6;
  box-shadow: inset 0 -1px 1px rgba(0, 0, 0, 0.18);
}

.turn-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink);
}

.status-chip-label {
  color: #838b99;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.status-chip-value {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink);
}

.status-chip.color-blue .status-chip-value {
  color: var(--blue);
}

.status-chip.color-red .status-chip-value {
  color: var(--red);
}

.status-chip.color-green .status-chip-value {
  color: var(--green);
}

.status-chip.color-brown .status-chip-value {
  color: var(--brown);
}

.status-chip.color-purple .status-chip-value {
  color: var(--purple);
}

.toolbar,
.position-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.toolbar {
  justify-content: flex-end;
}

.tool-button {
  min-height: 36px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
  font-weight: 650;
  white-space: nowrap;
}

.tool-button:hover:not(:disabled),
.tool-button:focus-visible {
  border-color: var(--focus);
  background: var(--surface-3);
  outline: none;
}

a.tool-button {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  font-size: 14px;
}

.tool-button:disabled {
  color: #667080;
  background: #14161e;
}

.tool-button.danger {
  border-color: rgba(255, 107, 107, 0.5);
  color: #ff8a8a;
}

.tool-button.bot-action {
  min-width: 86px;
  border-color: rgba(192, 132, 252, 0.42);
  background: rgba(192, 132, 252, 0.14);
  color: #efdfff;
}

.tool-button.bot-action:hover:not(:disabled),
.tool-button.bot-action:focus-visible {
  border-color: var(--purple);
  background: rgba(192, 132, 252, 0.22);
}

.terminal-banner {
  padding: 10px 12px;
  border: 1px solid rgba(192, 132, 252, 0.42);
  border-radius: 10px;
  background: rgba(192, 132, 252, 0.14);
  color: #e5d1ff;
  font-weight: 700;
}

.board-stage {
  --coord-size: clamp(20px, 2.6vmin, 26px);
  container-type: inline-size;
  grid-row: 3;
  align-self: center;
  justify-self: center;
  display: grid;
  grid-template-columns: var(--coord-size) minmax(0, 1fr);
  grid-template-rows: minmax(0, auto) var(--coord-size);
  width: min(100%, calc(100dvh - 148px), calc(100vw - 480px));
  max-width: 1000px;
}

.board {
  --board-line: clamp(1px, 0.28cqi, 3px);
  --piece-ring-line: clamp(2px, 0.42cqi, 4px);
  --piece-ring-shadow: clamp(2px, 0.5cqi, 5px);
  --quint-line: clamp(2px, 0.4cqi, 4px);
  --quint-halo: clamp(3px, 0.66cqi, 7px);
  container-type: inline-size;
  display: grid;
  grid-column: 2;
  grid-row: 1;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-template-rows: repeat(7, minmax(0, 1fr));
  width: 100%;
  aspect-ratio: 1;
  border: var(--board-line) solid #443f60;
  background: #1b1826;
  gap: var(--board-line);
  box-shadow:
    0 0 0 1px rgba(160, 175, 200, 0.1),
    0 0 44px rgba(192, 132, 252, 0.11),
    0 0 110px rgba(192, 132, 252, 0.05),
    0 20px 46px rgba(0, 0, 0, 0.34);
}

.rank-labels,
.file-labels {
  display: grid;
  color: #838b99;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  line-height: 1;
  text-transform: uppercase;
}

.rank-labels {
  grid-column: 1;
  grid-row: 1;
  grid-template-rows: repeat(7, minmax(0, 1fr));
  padding-right: 8px;
}

.rank-labels span {
  display: grid;
  align-items: center;
  justify-content: end;
}

.file-labels {
  grid-column: 2;
  grid-row: 2;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  padding-top: 8px;
}

.file-labels span {
  display: grid;
  place-items: start center;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  border: 0;
  border-radius: 0;
  padding: 0;
  background: #312f47;
  color: var(--ink);
  isolation: isolate;
}

.cell:nth-child(even) {
  background: #363452;
}

.cell:hover:not(:disabled) {
  outline: 2px solid color-mix(in srgb, currentColor 70%, white);
  outline-offset: -2px;
  z-index: 3;
}

.cell:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: -3px;
  z-index: 3;
}

.cell.legal-selected::before {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 26%;
  aspect-ratio: 1;
  content: "";
  border: var(--board-line) solid currentColor;
  border-radius: 50%;
  background: transparent;
  opacity: 0.42;
  transform: translate(-50%, -50%);
  pointer-events: none;
  transition: opacity 140ms ease;
}

.cell.legal-selected.quint-space::before {
  width: 72%;
  border-width: calc(var(--board-line) * 1.25);
  opacity: 0.5;
}

.cell.legal-selected::after {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 58%;
  aspect-ratio: 1;
  content: "";
  border: var(--board-line) solid color-mix(in srgb, currentColor 55%, white);
  border-radius: 50%;
  background: color-mix(in srgb, color-mix(in srgb, currentColor 62%, white) 40%, transparent);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(0.82);
  transition:
    opacity 140ms ease,
    transform 140ms ease;
}

.cell.legal-selected:hover:not(:disabled)::before,
.cell.legal-selected:focus-visible::before {
  opacity: 0;
}

.cell.legal-selected:hover:not(:disabled)::after,
.cell.legal-selected:focus-visible::after {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.cell.last-affected {
  background-image: linear-gradient(rgba(255, 209, 102, 0.07), rgba(255, 209, 102, 0.07));
}

.cell.last-move {
  background-image: linear-gradient(rgba(255, 209, 102, 0.13), rgba(255, 209, 102, 0.13));
  box-shadow: inset 0 0 0 2px rgba(255, 209, 102, 0.45);
}

.cell.selected-target {
  box-shadow:
    inset 0 0 0 2px color-mix(in srgb, currentColor 70%, transparent),
    inset 0 0 14px color-mix(in srgb, currentColor 24%, transparent);
}

.piece {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 66%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 0;
  background: radial-gradient(
    circle at 35% 28%,
    color-mix(in srgb, currentColor 48%, white),
    currentColor 47%,
    color-mix(in srgb, currentColor 80%, #05080d)
  );
  box-shadow:
    inset 0 2px 2px rgba(255, 255, 255, 0.42),
    inset 0 -4px 7px color-mix(in srgb, currentColor 45%, #05080d),
    0 0 0 1px color-mix(in srgb, currentColor 52%, #05080d),
    0 5px 12px rgba(0, 0, 0, 0.45);
}

.piece.has-quint::after {
  position: absolute;
  inset: -12%;
  content: "";
  border: var(--piece-ring-line) solid var(--purple);
  border-radius: 50%;
  box-shadow: 0 0 0 var(--piece-ring-shadow) #151221;
}

.quint-only {
  position: relative;
  z-index: 1;
  width: 40%;
  aspect-ratio: 1;
  border: var(--quint-line) solid color-mix(in srgb, var(--purple) 82%, white);
  border-radius: 18%;
  background:
    radial-gradient(circle at 50% 50%, color-mix(in srgb, var(--purple) 88%, white) 0 12%, transparent 13%),
    color-mix(in srgb, var(--purple) 18%, transparent);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.18),
    0 0 0 var(--quint-halo) color-mix(in srgb, var(--purple) 8%, transparent),
    0 8px 18px rgba(0, 0, 0, 0.26);
  transform: rotate(45deg);
}

.quint-only::after {
  position: absolute;
  inset: 24%;
  content: "";
  border: max(1px, calc(var(--quint-line) * 0.66)) solid color-mix(in srgb, var(--purple) 72%, white);
  border-radius: 18%;
}

.color-blue,
.piece-blue {
  color: var(--blue);
}

.color-red,
.piece-red {
  color: var(--red);
}

.color-green,
.piece-green {
  color: var(--green);
}

.color-brown,
.piece-brown {
  color: var(--brown);
}

.color-purple,
.piece-purple {
  color: var(--purple);
}

.panel-section {
  min-width: 0;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.panel-section:last-child {
  border-bottom: 0;
}

.panel-section.grow {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
  min-height: 0;
}

.color-picker {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.move-hint {
  margin-top: 10px;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.45;
}

.move-hint .hint-color {
  font-weight: 700;
}

.purple-target {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.purple-target select {
  min-width: 0;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 30px 7px 9px;
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
}

.purple-target select,
.bot-controls select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path d='M1 1.5l5 5 5-5' fill='none' stroke='%2398a7bc' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

.purple-target select:focus {
  border-color: var(--focus);
  outline: none;
}

.bot-controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 10px;
}

.bot-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.bot-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  min-width: 36px;
  padding: 8px;
  color: var(--muted);
}

.icon-button[aria-expanded="true"] {
  border-color: rgba(192, 132, 252, 0.55);
  background: rgba(192, 132, 252, 0.12);
  color: #efdfff;
}

.bot-controls[hidden] {
  display: none;
}

.bot-controls label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.bot-controls select {
  min-width: 0;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 28px 6px 8px;
  background-color: var(--surface-2);
  color: var(--ink);
  font: inherit;
}

.bot-controls select:focus {
  border-color: var(--focus);
  outline: none;
}

.bot-controls .toggle-control {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
}

.toggle-control input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--purple);
}

.color-button {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 7px;
  min-height: 40px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.color-button.color-blue {
  color: var(--blue);
}

.color-button.color-red {
  color: var(--red);
}

.color-button.color-green {
  color: var(--green);
}

.color-button.color-brown {
  color: var(--brown);
}

.color-button[aria-pressed="true"] {
  border-color: currentColor;
  background: color-mix(in srgb, currentColor 11%, var(--surface-2));
  box-shadow: inset 0 0 0 2px currentColor;
}

.color-button:disabled {
  opacity: 0.38;
}

.swatch {
  width: 16px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: currentColor;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.22),
    0 0 0 1px rgba(0, 0, 0, 0.2);
}

.scores {
  display: grid;
  margin-top: 12px;
}

.match-title {
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.match-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 10px 0 14px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.match-side {
  display: grid;
  gap: 9px;
  min-width: 0;
}

.match-name-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.match-side-white .match-name-row {
  flex-direction: row-reverse;
}

.match-name {
  color: var(--ink);
  font-size: 14px;
  font-weight: 700;
}

.match-side.active .match-name {
  color: var(--purple);
}

.match-side-black .win-track {
  justify-content: flex-start;
}

.match-score {
  display: flex;
  align-items: baseline;
  gap: 7px;
}

.match-score-num {
  color: var(--ink);
  font-family: Marcellus, Georgia, serif;
  font-size: 27px;
  font-weight: 400;
  line-height: 1;
}

.match-score-sep {
  color: #575e6c;
  font-size: 16px;
  font-weight: 650;
}

.win-track {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  min-width: 0;
}

.win-slot {
  width: 11px;
  aspect-ratio: 1;
  border: 2px solid #3b4152;
  border-radius: 3px;
  background: #12151d;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  opacity: 0.86;
  transform: rotate(45deg);
}

.win-slot.filled {
  border-color: color-mix(in srgb, currentColor 78%, white);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.22), transparent 48%),
    currentColor;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.28),
    0 0 0 3px color-mix(in srgb, currentColor 10%, transparent),
    0 5px 12px rgba(0, 0, 0, 0.28);
  opacity: 1;
}

.won-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  padding: 7px 11px;
  border: 1px solid color-mix(in srgb, currentColor 28%, transparent);
  border-radius: 8px;
  background: color-mix(in srgb, currentColor 10%, transparent);
}

.won-chip-label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.won-chip-name {
  min-width: 0;
  font-size: 13px;
  font-weight: 700;
}

.won-note {
  min-width: 0;
  color: color-mix(in srgb, currentColor 62%, transparent);
  font-size: 11px;
  font-weight: 600;
}

.won-chip-winner {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
}

.won-chip-winner svg {
  display: block;
}

.race-row {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 9px 0;
}

.race-row + .race-row {
  border-top: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
}

.won-chip + .race-row {
  margin-top: 6px;
}

.race-label {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.race-dot {
  width: 9px;
  aspect-ratio: 1;
  flex: none;
  border-radius: 50%;
  background: currentColor;
}

.race-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--ink);
  font-size: 12px;
  font-weight: 650;
}

.race-side {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
  min-width: 0;
}

.race-side-white {
  flex-direction: row-reverse;
}

.race-finish {
  width: 9px;
  aspect-ratio: 1;
  justify-self: center;
  border: 1.5px solid #4c5364;
  border-radius: 2px;
  transform: rotate(45deg);
}

.race-pip {
  width: 11px;
  aspect-ratio: 1;
  flex: none;
  border: 1.5px solid color-mix(in srgb, var(--muted) 32%, transparent);
  border-radius: 50%;
  background: transparent;
}

.race-pip.filled {
  border-color: currentColor;
  background: currentColor;
}

.race-pip.match-point {
  border: 1.5px dashed color-mix(in srgb, currentColor 70%, transparent);
}

.log {
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 6px;
  scrollbar-width: thin;
  scrollbar-color: #2d323e transparent;
}

.log::-webkit-scrollbar,
#position-json::-webkit-scrollbar {
  width: 8px;
}

.log::-webkit-scrollbar-track,
#position-json::-webkit-scrollbar-track {
  background: transparent;
}

.log::-webkit-scrollbar-thumb,
#position-json::-webkit-scrollbar-thumb {
  background: #2d323e;
  border-radius: 999px;
}

.log-entry {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #14171f;
  padding: 10px;
}

.log-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
}

.log-events {
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.log-events li + li {
  margin-top: 5px;
}

.empty-log {
  display: grid;
  place-items: center;
  min-height: 76px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

.position-panel summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  list-style: none;
}

.position-panel summary::-webkit-details-marker {
  display: none;
}

.position-panel summary::after {
  content: "+";
  display: grid;
  place-items: center;
  width: 24px;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
  font-size: 16px;
  font-weight: 900;
  line-height: 1;
}

.position-panel[open] summary::after {
  content: "-";
}

.position-content {
  margin-top: 12px;
}

#position-json {
  width: 100%;
  min-height: 96px;
  margin-top: 10px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #0d0f16;
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.4;
}

#position-json:focus {
  border-color: var(--focus);
  outline: none;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 14px;
  border: 1px solid rgba(255, 107, 107, 0.46);
  border-radius: 8px;
  background: #2d1218;
  color: #ffd0d0;
  font-weight: 650;
  box-shadow: 0 18px 38px rgba(0, 0, 0, 0.42);
}

/* Move resolution animations. Delays are set from JS via --anim-delay so the
   turn plays back in rule order: place, violence, marks, lotus, scoring. */

.ghost-holder {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.piece.ghost {
  will-change: transform, opacity;
}

.cell-flash {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: currentColor;
  opacity: 0;
  animation: cell-flash 480ms ease both;
  animation-delay: var(--anim-delay, 0ms);
}

@keyframes cell-flash {
  0% {
    opacity: 0;
  }
  30% {
    opacity: 0.38;
  }
  100% {
    opacity: 0;
  }
}

.piece.anim-place {
  animation: piece-in 230ms cubic-bezier(0.24, 0.9, 0.32, 1.3) both;
  animation-delay: var(--anim-delay, 0ms);
}

@keyframes piece-in {
  0% {
    transform: scale(0.25);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.piece.ghost-out-mark {
  animation: ghost-mark-out 260ms ease-in both;
  animation-delay: var(--anim-delay, 0ms);
}

@keyframes ghost-mark-out {
  0% {
    transform: scale(1);
    opacity: 1;
  }
  100% {
    transform: scale(0.3);
    opacity: 0;
  }
}

.piece.ghost-out-violence {
  animation: ghost-violence-out 430ms ease-in both;
  animation-delay: var(--anim-delay, 0ms);
}

@keyframes ghost-violence-out {
  0% {
    transform: translateX(0) scale(1);
    opacity: 1;
  }
  14% {
    transform: translateX(-9%) scale(1);
  }
  28% {
    transform: translateX(9%) scale(1);
  }
  42% {
    transform: translateX(-7%) scale(1);
  }
  56% {
    transform: translateX(7%) scale(1);
    opacity: 1;
  }
  100% {
    transform: translateX(0) scale(0.3);
    opacity: 0;
  }
}

.piece.ghost-out-lotus {
  animation: ghost-lotus-out 340ms ease-in both;
  animation-delay: var(--anim-delay, 0ms);
}

@keyframes ghost-lotus-out {
  0% {
    transform: translate(0, 0) scale(1);
    opacity: 1;
  }
  100% {
    transform: translate(var(--gx, 0%), var(--gy, 0%)) scale(0.3);
    opacity: 0;
  }
}

.quint-only.anim-quint-in {
  animation: quint-in 300ms ease-out both;
  animation-delay: var(--anim-delay, 0ms);
}

@keyframes quint-in {
  0% {
    transform: rotate(45deg) scale(0);
    opacity: 0;
  }
  65% {
    transform: rotate(45deg) scale(1.3);
    opacity: 1;
  }
  100% {
    transform: rotate(45deg) scale(1);
    opacity: 1;
  }
}

.quint-only.ghost-quint-out {
  animation: ghost-quint-out 320ms ease-in both;
  animation-delay: var(--anim-delay, 0ms);
}

@keyframes ghost-quint-out {
  0% {
    transform: rotate(45deg) scale(1);
    opacity: 1;
  }
  35% {
    transform: rotate(45deg) scale(1.25);
    opacity: 1;
  }
  100% {
    transform: rotate(45deg) scale(0.2);
    opacity: 0;
  }
}

.piece.anim-ring-in::after {
  animation: ring-in 300ms ease-out both;
  animation-delay: var(--ring-delay, 0ms);
}

@keyframes ring-in {
  0% {
    transform: scale(0.3);
    opacity: 0;
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.race-pip.pip-pop {
  animation: pip-pop 280ms ease-out both;
  animation-delay: var(--anim-delay, 0ms);
}

@keyframes pip-pop {
  0% {
    transform: scale(0);
  }
  65% {
    transform: scale(1.5);
  }
  100% {
    transform: scale(1);
  }
}

.won-chip.chip-in {
  animation: chip-in 380ms cubic-bezier(0.2, 0.8, 0.3, 1.1) both;
  animation-delay: var(--anim-delay, 0ms);
}

@keyframes chip-in {
  0% {
    transform: translateY(16px);
    opacity: 0;
  }
  100% {
    transform: translateY(0);
    opacity: 1;
  }
}

.win-slot.slot-pop {
  animation: slot-pop 320ms ease-out both;
  animation-delay: var(--anim-delay, 0ms);
}

@keyframes slot-pop {
  0% {
    transform: rotate(45deg) scale(0);
  }
  65% {
    transform: rotate(45deg) scale(1.4);
  }
  100% {
    transform: rotate(45deg) scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .ghost-holder,
  .cell-flash {
    display: none;
  }

  .piece.anim-place,
  .quint-only.anim-quint-in,
  .piece.anim-ring-in::after,
  .race-pip.pip-pop,
  .win-slot.slot-pop,
  .won-chip.chip-in {
    animation: none;
  }
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    min-height: 100vh;
    min-height: 100dvh;
    height: auto;
  }

  .side-panel {
    grid-template-rows: auto auto auto minmax(140px, 38vh) auto;
  }

  .board-stage {
    width: min(100%, calc(100vw - 36px), calc(100dvh - 150px));
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 10px;
    gap: 10px;
  }

  .play-surface,
  .side-panel {
    border-radius: 12px;
  }

  .play-surface {
    padding: 12px;
  }

  .side-panel {
    grid-template-rows: auto auto auto minmax(150px, 260px) auto;
  }

  .top-bar {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .header-meta {
    grid-template-columns: 1fr;
    justify-self: stretch;
    width: 100%;
  }

  h1 {
    font-size: 26px;
  }

  .toolbar {
    justify-content: stretch;
    width: 100%;
  }

  .tool-button {
    flex: 1 1 auto;
    padding-inline: 10px;
  }

  .status-line {
    gap: 6px;
    justify-content: flex-start;
  }

  .status-chip {
    min-height: 26px;
    padding: 3px 8px;
    font-size: 12px;
  }

  .board-stage {
    --coord-size: clamp(18px, 5.5vw, 22px);
    width: min(100%, calc(100vw - 28px), calc(100dvh - 170px));
  }

  .rank-labels,
  .file-labels {
    font-size: 10px;
  }

  .color-picker {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .panel-section {
    padding: 14px;
  }

  .purple-target,
  .bot-controls {
    grid-template-columns: 1fr;
  }

  .match-grid {
    gap: 8px;
  }

  .match-name-row {
    gap: 6px;
  }

  .match-name {
    font-size: 13px;
  }

  .match-score-num {
    font-size: 24px;
  }

  .won-chip {
    flex-wrap: wrap;
  }

  .won-chip-winner {
    margin-left: auto;
  }

  .race-row {
    grid-template-columns: minmax(54px, 0.9fr) minmax(0, 1fr) auto minmax(0, 1fr);
    gap: 6px;
  }

  .race-pip {
    width: 10px;
  }
}

@media (max-height: 680px) and (min-width: 981px) {
  .app-shell {
    height: auto;
  }

  .board-stage {
    width: min(100%, calc(100dvh - 130px), calc(100vw - 480px));
  }
}
