*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --light: #ececee;
  --light-vein: #d8d8dc;
  --dark: #2a2a32;
  --dark-vein: #3a3a44;
  --frame: #141418;
  --bg: #0e0e12;
  --surface: rgba(255, 255, 255, 0.04);
  --surface-border: rgba(255, 255, 255, 0.1);
  --text: #ececf0;
  --muted: #9494a0;
  --accent: #b8bcc8;
  --accent-strong: #d4d8e4;
  --select: rgba(180, 186, 200, 0.55);
  --drop: rgba(140, 180, 210, 0.35);
  --layout-gap: 1.25rem;
  --app-inline-padding: 3rem;
  --layout-chrome-height: 13rem;
  --side-rail-width: 16rem;
  --board-min: 20rem;
  --board-max: 700px;
  --cri-panel-width: 20rem;
  --board-limit: min(var(--board-max), 80vh, calc(100vh - var(--layout-chrome-height)));
  --palette-toggle-block: 2.75rem;
  --piece-white: #f5f1e6;
  --piece-black: #16161c;
}

html {
  scrollbar-gutter: stable;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(circle at top, #1a1a22 0%, var(--bg) 58%);
  color: var(--text);
}

.app {
  width: 100%;
  max-width: min(
    calc(
      var(--board-max) + var(--side-rail-width) + var(--cri-panel-width) + 2 * var(--layout-gap) +
        var(--app-inline-padding)
    ),
    100%
  );
  min-width: 0;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 3rem;
}

.header {
  margin-bottom: 1.75rem;
}

.header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.header-copy {
  min-width: 0;
}

.header h1 {
  margin: 0 0 0.35rem;
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.45rem;
  min-width: 2rem;
  min-height: 2rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex: 0 0 auto;
  margin-top: 0.15rem;
}

.btn-report-issue {
  padding: 0.35rem 0.65rem;
  font-size: 0.78rem;
  line-height: 1.2;
  border-radius: 8px;
  white-space: nowrap;
}

.btn-settings {
  flex: 0 0 auto;
  border-radius: 8px;
}

.btn-settings[aria-expanded="true"] {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--accent);
}

.btn-settings-icon {
  display: block;
}

.settings-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1.25rem;
  padding: 1rem;
  border: 1px solid var(--surface-border);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.18);
}

.settings-panel[hidden] {
  display: none;
}

.settings-group-title {
  margin: 0 0 0.65rem;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.settings-group-body {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.settings-group-body.controls {
  margin-bottom: 0;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0;
}

.control {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  background: var(--surface);
}

.control-label {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.control[title],
.settings-panel .btn[title],
.settings-group-title[title] {
  cursor: help;
}

.control input {
  width: 4.25rem;
  padding: 0.3rem 0.4rem;
  border: 1px solid var(--surface-border);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  text-align: center;
}

.control input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.control input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.control-readout {
  min-width: 4.25rem;
  padding: 0.3rem 0.4rem;
  font: inherit;
  font-size: 0.9rem;
  text-align: center;
  color: var(--text);
  opacity: 0.85;
}

.control select {
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--surface-border);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  cursor: pointer;
}

.control select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.control select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.game-mode-control select {
  min-width: 11rem;
}

.dimension-hint {
  flex-basis: 100%;
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.btn {
  padding: 0.45rem 0.85rem;
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.11);
}

.btn:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: rgba(110, 231, 160, 0.14);
  border-color: rgba(110, 231, 160, 0.35);
}

.btn-primary:hover:not(:disabled) {
  background: rgba(110, 231, 160, 0.22);
}

.game-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.engine-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0;
}

#settings-engine-group[hidden] {
  display: none;
}

.control-checkbox {
  cursor: pointer;
}

.control-checkbox input {
  width: auto;
  margin: 0;
  accent-color: var(--accent-strong);
  cursor: pointer;
}

.control-suffix {
  font-size: 0.78rem;
  color: var(--muted);
}

.engine-hint {
  flex-basis: 100%;
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.game-status {
  margin: 0;
  flex: 1 1 12rem;
  font-size: 0.88rem;
  color: var(--muted);
}

.game-status.is-waiting {
  color: var(--accent-strong);
}

.app.engine-thinking .board {
  opacity: 0.72;
}

.app.play-mode .settings-panel,
.app.play-mode .btn-settings,
.app.play-mode .game-mode-control {
  opacity: 0.45;
  pointer-events: none;
}

.app.play-mode .btn-report-issue {
  opacity: 1;
  pointer-events: auto;
}

.app.play-mode .palette {
  display: none;
}

.app:not(.play-mode) .move-history {
  display: none;
}

/* ---------- Editor layout ---------- */

.editor-layout {
  container-type: inline-size;
  container-name: editor;
  position: relative;
  display: grid;
  grid-template-columns: var(--side-rail-width) var(--board-limit) minmax(0, var(--cri-panel-width));
  align-items: start;
  gap: var(--layout-gap);
  margin-bottom: 1.5rem;
  min-width: 0;
  overflow: visible;
  --cri-panel-width: clamp(14rem, 28cqi, 20rem);
  /* min(700px, largest that fits): height caps + width after side rail and CRI. */
  --board-limit: min(
    var(--board-max),
    80vh,
    calc(100vh - var(--layout-chrome-height)),
    calc(100cqi - var(--cri-panel-width) - var(--side-rail-width) - 2 * var(--layout-gap))
  );
}

/* ---------- Piece library dropdown ---------- */

.palette {
  position: relative;
  flex: 0 0 auto;
  width: 100%;
  z-index: 2;
  grid-column: 1;
  grid-row: 1;
}

.palette-toggle {
  display: inline-flex;
  align-items: center;
  width: auto;
  max-width: 100%;
  box-sizing: border-box;
  min-height: var(--palette-toggle-block);
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.palette-toggle::-webkit-details-marker {
  display: none;
}

.palette-toggle::after {
  content: "";
  width: 0.45rem;
  height: 0.45rem;
  margin-left: 0.55rem;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.15s ease;
}

.palette:not([open]) .palette-toggle::after {
  transform: rotate(-45deg);
}

.palette-toggle:hover {
  background: rgba(255, 255, 255, 0.08);
}

.palette-toggle:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.palette[open] .palette-toggle {
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
}

/* ---------- Move history (play mode, same slot as piece library) ---------- */

.move-history {
  position: relative;
  flex: 0 0 auto;
  width: 100%;
  z-index: 2;
  grid-column: 1;
  grid-row: 1;
}

.move-history-toggle {
  display: inline-flex;
  align-items: center;
  width: auto;
  max-width: 100%;
  box-sizing: border-box;
  min-height: var(--palette-toggle-block);
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.move-history-toggle::-webkit-details-marker {
  display: none;
}

.move-history-toggle::after {
  content: "";
  width: 0.45rem;
  height: 0.45rem;
  margin-left: 0.55rem;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.15s ease;
}

.move-history:not([open]) .move-history-toggle::after {
  transform: rotate(-45deg);
}

.move-history-toggle:hover {
  background: rgba(255, 255, 255, 0.08);
}

.move-history-toggle:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.move-history[open] .move-history-toggle {
  border-color: rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
}

.move-history-panel {
  position: absolute;
  top: calc(100% + 0.6rem);
  left: 0;
  right: 0;
  margin-top: 0;
  padding: 0.75rem 0.85rem;
  width: 100%;
  max-width: none;
  box-sizing: border-box;
  max-height: calc(var(--board-limit) - var(--palette-toggle-block) - 0.6rem);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--surface-border);
  border-radius: 10px;
  background: rgba(14, 14, 18, 0.96);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.45);
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
  scrollbar-width: thin;
}

.move-history-panel::-webkit-scrollbar {
  width: 0.45rem;
}

.move-history-panel::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
}

.move-history-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.move-history-empty {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.move-history-turn {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.move-history-turn-label {
  margin: 0;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.move-history-ply {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding-left: 0.15rem;
}

.move-history-move {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text);
  line-height: 1.35;
}

.move-history-flag {
  color: var(--accent-strong);
  font-weight: 600;
}

.move-history-log {
  margin: 0.15rem 0 0;
  font-size: 0.78rem;
  line-height: 1.35;
  color: var(--text-muted, #8a8a8a);
  font-style: italic;
}

.move-history-rule,
.move-history-note {
  margin: 0;
  padding-left: 0.7rem;
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.35;
}

.move-history-rule {
  color: #c4c8d4;
}

.move-history-result {
  margin: 0.15rem 0 0;
  padding-top: 0.55rem;
  border-top: 1px solid var(--surface-border);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent-strong);
}

/* Overlay below the toggle so opening the library does not shift the board. */
.palette-panel {
  position: absolute;
  top: calc(100% + 0.6rem);
  left: 0;
  right: 0;
  margin-top: 0;
  padding: 0.85rem;
  width: 100%;
  max-width: none;
  box-sizing: border-box;
  max-height: calc(var(--board-limit) - var(--palette-toggle-block) - 0.6rem);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--surface-border);
  border-radius: 10px;
  background: rgba(14, 14, 18, 0.96);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.45);
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
  scrollbar-width: thin;
}

.palette-panel::-webkit-scrollbar {
  width: 0.45rem;
}

.palette-panel::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
}

.palette-section {
  margin-inline: -0.35rem;
  padding: 0.45rem 0.35rem;
  border-radius: 8px;
  transition: background 0.15s ease;
}

.palette-section + .palette-section {
  margin-top: 0.45rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--surface-border);
}

.palette-section:hover,
.palette-section:focus-within {
  background: rgba(255, 255, 255, 0.05);
}

.palette-section-title {
  margin: 0 0 0.55rem;
  padding: 0.1rem 0;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  transition: color 0.15s ease;
}

.palette-section:hover .palette-section-title,
.palette-section:focus-within .palette-section-title {
  color: var(--accent);
}

.palette-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

.palette-pieces {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.palette-piece {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 5rem;
  height: 5rem;
  padding: 0.3rem;
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.35);
  cursor: grab;
}

.palette-piece:active {
  cursor: grabbing;
}

.palette-overlays-wall {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.6rem;
}

.palette-overlays {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.palette-overlay {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-end;
}

.palette-overlay.is-wall-overlay {
  background:
    repeating-linear-gradient(
      135deg,
      rgba(120, 120, 130, 0.28) 0,
      rgba(120, 120, 130, 0.28) 6px,
      rgba(50, 50, 58, 0.5) 6px,
      rgba(50, 50, 58, 0.5) 12px
    );
  box-shadow: inset 0 0 0 2px rgba(140, 140, 155, 0.55);
}

.palette-overlay.is-hazard-overlay {
  background:
    repeating-linear-gradient(
      135deg,
      rgba(210, 120, 60, 0.24) 0,
      rgba(210, 120, 60, 0.24) 4px,
      rgba(120, 55, 30, 0.32) 4px,
      rgba(120, 55, 30, 0.32) 8px
    );
  box-shadow: inset 0 0 0 2px rgba(220, 130, 70, 0.65);
}

.palette-overlay.is-hazard-overlay[data-owner="w"] {
  background:
    repeating-linear-gradient(
      135deg,
      rgba(90, 140, 200, 0.22) 0,
      rgba(90, 140, 200, 0.22) 4px,
      rgba(40, 70, 110, 0.3) 4px,
      rgba(40, 70, 110, 0.3) 8px
    );
  box-shadow: inset 0 0 0 2px rgba(100, 160, 220, 0.75);
}

.palette-overlay.is-hazard-overlay[data-owner="b"] {
  background:
    repeating-linear-gradient(
      135deg,
      rgba(200, 90, 70, 0.22) 0,
      rgba(200, 90, 70, 0.22) 4px,
      rgba(110, 40, 35, 0.32) 4px,
      rgba(110, 40, 35, 0.32) 8px
    );
  box-shadow: inset 0 0 0 2px rgba(220, 100, 80, 0.8);
}

.palette-wall-swatch,
.palette-hazard-swatch {
  display: block;
  flex: 1;
  min-height: 0;
  width: 100%;
  border-radius: 4px;
}

.palette-wall-swatch {
  background:
    repeating-linear-gradient(
      135deg,
      rgba(110, 110, 120, 0.35) 0,
      rgba(110, 110, 120, 0.35) 5px,
      rgba(40, 40, 48, 0.55) 5px,
      rgba(40, 40, 48, 0.55) 10px
    );
}

.palette-hazard-swatch {
  background:
    repeating-linear-gradient(
      135deg,
      rgba(220, 140, 80, 0.4) 0,
      rgba(220, 140, 80, 0.4) 5px,
      rgba(90, 40, 20, 0.55) 5px,
      rgba(90, 40, 20, 0.55) 10px
    );
}

.palette-overlay.is-hazard-overlay[data-owner="w"] .palette-hazard-swatch {
  background:
    repeating-linear-gradient(
      135deg,
      rgba(120, 170, 230, 0.4) 0,
      rgba(120, 170, 230, 0.4) 5px,
      rgba(40, 70, 110, 0.55) 5px,
      rgba(40, 70, 110, 0.55) 10px
    );
}

.palette-overlay.is-hazard-overlay[data-owner="b"] .palette-hazard-swatch {
  background:
    repeating-linear-gradient(
      135deg,
      rgba(230, 120, 100, 0.4) 0,
      rgba(230, 120, 100, 0.4) 5px,
      rgba(110, 40, 35, 0.55) 5px,
      rgba(110, 40, 35, 0.55) 10px
    );
}

.palette-overlay-label {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.1;
  text-align: center;
  color: rgba(230, 230, 235, 0.88);
}

/* ---------- Board ---------- */

.board-wrap {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: min(var(--board-limit), 100%);
  height: min(var(--board-limit), 100%);
  max-width: 100%;
  min-width: 0;
  justify-self: center;
  overflow: visible;
  grid-column: 2;
  grid-row: 1;
}

/* ---------- Custom Rules panel (right of board) ---------- */

.if-conditions-panel {
  flex: 0 0 auto;
  width: 100%;
  min-width: 0;
  max-width: var(--cri-panel-width);
  grid-column: 3;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.85rem;
  border: 1px solid var(--surface-border);
  border-radius: 10px;
  background: var(--surface);
  max-height: min(var(--board-limit), calc(100vh - var(--layout-chrome-height)));
  overflow-y: auto;
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
  scrollbar-width: thin;
}

@media (max-width: 1200px) {
  .editor-layout {
    grid-template-columns: var(--side-rail-width) var(--board-limit);
    /* CRI is below: reclaim its former column for the board. */
    --board-limit: min(
      var(--board-max),
      80vh,
      calc(100vh - var(--layout-chrome-height)),
      calc(100cqi - var(--side-rail-width) - var(--layout-gap))
    );
  }

  .palette,
  .move-history {
    grid-column: 1;
    grid-row: 1;
  }

  .board-wrap {
    grid-column: 2;
    grid-row: 1;
  }

  .if-conditions-panel {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 100%;
    max-width: none;
    max-height: none;
  }
}

@media (max-width: 720px) {
  .app {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  :root {
    --app-inline-padding: 2rem;
    --layout-chrome-height: 15rem;
  }
}

.if-conditions-header {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.if-conditions-header-row {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  width: 100%;
  padding-right: 2rem;
}

.if-conditions-title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  text-align: center;
  width: 100%;
}

.cri-player-guide-btn {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 1;
  min-width: 1.65rem;
  min-height: 1.65rem;
  padding: 0;
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1;
  border-radius: 6px;
  color: var(--muted);
}

.cri-player-guide-btn:hover {
  color: var(--text);
}

.cri-player-guide-btn[aria-expanded="true"] {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--accent);
  color: var(--text);
}

.if-conditions-hint {
  margin: 0;
  font-size: 0.72rem;
  line-height: 1.4;
  color: var(--muted);
}

.report-issue-overlay {
  position: fixed;
  inset: 0;
  z-index: 1250;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(8, 8, 12, 0.82);
  backdrop-filter: blur(4px);
}

.report-issue-overlay[hidden] {
  display: none;
}

.report-issue-panel {
  width: min(100%, 28rem);
  max-height: min(90vh, 36rem);
  overflow: auto;
  border: 1px solid var(--surface-border);
  border-radius: 10px;
  background: rgba(18, 18, 24, 0.98);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.55);
  color: var(--text);
}

.report-issue-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--surface-border);
}

.report-issue-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent-strong);
}

.report-issue-close-btn {
  font-size: 1.25rem;
  line-height: 1;
}

.report-issue-intro {
  margin: 0;
  padding: 0.85rem 1rem 0.75rem;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.5;
}

.report-issue-field {
  display: block;
  padding: 0 1rem 0.85rem;
}

.report-issue-label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text);
}

.report-issue-input {
  width: 100%;
  min-height: 4.5rem;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.42);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.45;
  resize: vertical;
}

.report-issue-input::placeholder {
  color: rgba(148, 148, 160, 0.92);
  opacity: 1;
}

.report-issue-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: rgba(180, 186, 200, 0.45);
  background: rgba(0, 0, 0, 0.55);
}

.report-issue-status {
  margin: 0;
  padding: 0 1rem 0.65rem;
  font-size: 0.82rem;
  color: var(--accent-strong);
}

.report-issue-status.is-error {
  color: #ff8a80;
}

.report-issue-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.5rem 1rem 1rem;
  border-top: 1px solid var(--surface-border);
}

.player-guide-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(8, 8, 12, 0.75);
  backdrop-filter: blur(3px);
}

.player-guide-overlay[hidden] {
  display: none;
}

.player-guide-panel {
  display: flex;
  flex-direction: column;
  width: min(42rem, 100%);
  max-height: min(85vh, 100%);
  border: 1px solid var(--surface-border);
  border-radius: 10px;
  background: rgba(18, 18, 24, 0.98);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.45);
}

.player-guide-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-shrink: 0;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--surface-border);
}

.player-guide-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.player-guide-close-btn {
  min-width: 2rem;
  min-height: 2rem;
  font-size: 1.25rem;
  line-height: 1;
}

.player-guide-content {
  overflow-y: auto;
  padding: 1rem 1.15rem 1.25rem;
  font-size: 0.88rem;
  line-height: 1.55;
  color: var(--text);
  scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
  scrollbar-width: thin;
}

.player-guide-content h1 {
  margin: 0 0 0.75rem;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--accent-strong);
}

.player-guide-content h2 {
  margin: 1.25rem 0 0.5rem;
  font-size: 1.1rem;
  font-weight: 700;
}

.player-guide-content h3 {
  margin: 1rem 0 0.4rem;
  font-size: 0.98rem;
  font-weight: 700;
}

.player-guide-content p {
  margin: 0 0 0.65rem;
}

.player-guide-content ul,
.player-guide-content ol {
  margin: 0 0 0.65rem;
  padding-left: 1.25rem;
}

.player-guide-content li {
  margin-bottom: 0.25rem;
}

.player-guide-content hr {
  margin: 1rem 0;
  border: 0;
  border-top: 1px solid var(--surface-border);
}

.player-guide-content table {
  width: 100%;
  margin: 0.5rem 0 0.75rem;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.player-guide-content th,
.player-guide-content td {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--surface-border);
  text-align: left;
  vertical-align: top;
}

.player-guide-content th {
  background: rgba(255, 255, 255, 0.04);
}

.player-guide-content code {
  padding: 0.1em 0.35em;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 0.9em;
}

.player-guide-content strong {
  font-weight: 600;
  color: var(--accent-strong);
}

.player-guide-loading,
.player-guide-error {
  margin: 0;
  color: var(--muted);
  font-style: italic;
}

.if-conditions-subtitle {
  margin: 0 0 0.4rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.match-rules-builder {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding-bottom: 0.65rem;
  border-bottom: 1px solid var(--surface-border);
}

.match-rules-complete-warn {
  margin: 0;
  font-size: 0.68rem;
  line-height: 1.4;
  color: #c9a227;
}

.match-rules-complete-warn.is-blocking {
  font-weight: 600;
}

.match-rules-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.match-rule-row {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin: 0;
  padding: 0.55rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.18);
}

.match-rule-row.is-locked .match-rule-body {
  pointer-events: none;
  opacity: 0.72;
}

.match-rule-row.is-collapsed .match-rule-body {
  display: none;
}

.match-rule-header {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
}

.match-rule-toggle {
  position: relative;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.12rem;
  min-width: 0;
  margin: 0;
  padding: 0.1rem 0 0.1rem 0.95rem;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.match-rule-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.match-rule-toggle::before {
  content: "▸";
  position: absolute;
  left: 0.05rem;
  top: 0.12rem;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.15rem;
}

.match-rule-toggle[aria-expanded="true"]::before {
  content: "▾";
}

.match-rule-title {
  margin: 0;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text);
}

.match-rule-summary {
  font-size: 0.68rem;
  line-height: 1.35;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.match-rule-row:not(.is-collapsed) .match-rule-summary {
  display: none;
}

.match-rule-remove {
  flex: 0 0 auto;
  margin: 0;
  padding: 0.2rem 0.45rem;
  border: 1px solid var(--surface-border);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font: inherit;
  font-size: 0.68rem;
  font-weight: 600;
  cursor: pointer;
}

.match-rule-remove:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

.match-rule-body {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.match-rule-add {
  align-self: flex-start;
  margin-top: 0.15rem;
}

.match-rule-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
}

.match-rule-field {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.match-rule-field.is-wide {
  grid-column: 1 / -1;
}

.match-rule-field-label {
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.match-rule-field[title],
.match-rule-field-label[title] {
  cursor: help;
}

.match-rule-field select,
.match-rule-field input[type="number"] {
  width: 100%;
  min-height: 1.75rem;
  padding: 0.25rem 0.4rem;
  border: 1px solid var(--surface-border);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  font-size: 0.75rem;
}

.match-rule-preview {
  margin: 0;
  font-size: 0.72rem;
  line-height: 1.4;
  color: var(--accent-strong);
}

.match-rule-section-label {
  margin: 0;
  grid-column: 1 / -1;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.match-rule-fields-if,
.match-rule-fields-then {
  display: contents;
}

.match-rule-counter {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.65rem;
  grid-column: 1 / -1;
}

.match-rule-counter-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
}

.match-rule-counter-limit {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
}

.match-rule-counter-limit input[type="number"] {
  width: 3.25rem;
}

.match-rule-then {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.15rem;
  padding-top: 0.4rem;
  border-top: 1px dashed rgba(255, 255, 255, 0.08);
}

.match-rule-payload-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
}

.match-rule-interval-value {
  grid-template-columns: minmax(3rem, 4rem) auto;
  align-items: center;
}

.match-rule-interval-label {
  font-size: 0.72rem;
  color: rgba(255, 255, 255, 0.55);
}

.match-rule-preview-warn {
  grid-column: 1 / -1;
  color: #c9a227;
  font-size: 0.68rem;
}

.if-conditions-live {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.if-conditions-variables-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25rem 0.65rem;
  margin: 0;
  font-size: 0.78rem;
}

.if-conditions-variables-list dt {
  margin: 0;
  color: var(--muted);
}

.if-conditions-variables-list dd {
  margin: 0;
  font-family: ui-monospace, "Cascadia Code", "Segoe UI Mono", monospace;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.if-conditions-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.if-condition-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.45rem 0.55rem;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.2);
  font-size: 0.78rem;
  line-height: 1.35;
}

.if-condition-text {
  flex: 1 1 auto;
  color: var(--text);
}

.if-condition-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.15rem;
  flex: 0 0 auto;
}

.if-condition-badge {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.if-condition-detail {
  font-size: 0.65rem;
  color: var(--muted);
  font-family: ui-monospace, "Cascadia Code", "Segoe UI Mono", monospace;
}

.if-condition-item.is-true {
  background: rgba(110, 231, 160, 0.1);
  border: 1px solid rgba(110, 231, 160, 0.25);
}

.if-condition-item.is-true .if-condition-badge {
  background: rgba(110, 231, 160, 0.2);
  color: #6ee7a0;
}

.if-condition-item.is-false .if-condition-badge {
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
}

.if-condition-item.is-pending .if-condition-badge {
  background: rgba(120, 180, 255, 0.15);
  color: var(--accent-strong);
}

.if-condition-item.is-idle {
  opacity: 0.55;
}

.if-condition-item.is-error .if-condition-badge {
  background: rgba(248, 113, 113, 0.15);
  color: #f87171;
}

.if-conditions-empty {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.45;
}

.board {
  display: grid;
  grid-template-columns: repeat(var(--files, 8), 1fr);
  grid-template-rows: repeat(var(--ranks, 8), 1fr);
  width: min(
    100%,
    calc(var(--board-limit) * var(--files, 8) / var(--ranks, 8))
  );
  max-width: 100%;
  aspect-ratio: var(--files, 8) / var(--ranks, 8);
  max-height: min(var(--board-limit), 100%);
  overflow: visible;
  border: 6px solid var(--frame);
  border-radius: 4px;
  box-shadow:
    0 18px 40px rgba(0, 0, 0, 0.55),
    inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.square {
  position: relative;
  aspect-ratio: 1;
  user-select: none;
}

.square.light {
  background:
    linear-gradient(145deg, var(--light) 0%, var(--light-vein) 48%, #f4f4f6 100%);
}

.square.dark {
  background:
    linear-gradient(145deg, var(--dark-vein) 0%, var(--dark) 52%, #222228 100%);
}

.square.selected {
  box-shadow: inset 0 0 0 3px var(--select);
}

.square.legal-target::after {
  content: "";
  position: absolute;
  inset: 32%;
  border-radius: 50%;
  background: rgba(110, 190, 120, 0.72);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.25);
  pointer-events: none;
}

.square.legal-target:has(.piece)::after {
  inset: 12%;
  border-radius: 4px;
  background: rgba(110, 190, 120, 0.28);
  box-shadow: inset 0 0 0 3px rgba(110, 190, 120, 0.85);
}

.square.drop-target {
  box-shadow: inset 0 0 0 3px var(--drop);
}

.square.drag-valid {
  box-shadow: inset 0 0 0 999px rgba(110, 190, 120, 0.2);
}

.square.drag-invalid {
  box-shadow: inset 0 0 0 999px rgba(210, 95, 95, 0.18);
}

.square.king-in-check {
  box-shadow: inset 0 0 0 3px rgba(235, 90, 90, 0.95);
}

.square.king-in-check::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(235, 90, 90, 0.22);
  pointer-events: none;
}

.square.is-trap {
  position: relative;
}

.square.is-trap::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: 2px;
  background:
    repeating-linear-gradient(
      135deg,
      rgba(120, 120, 130, 0.22) 0,
      rgba(120, 120, 130, 0.22) 4px,
      rgba(60, 60, 70, 0.28) 4px,
      rgba(60, 60, 70, 0.28) 8px
    );
  box-shadow: inset 0 0 0 2px rgba(140, 140, 155, 0.55);
}

.square.is-trap.light {
  background-color: color-mix(in srgb, var(--light) 72%, #888 28%);
}

.square.is-trap.dark {
  background-color: color-mix(in srgb, var(--dark) 72%, #666 28%);
}

.square.is-trap .piece {
  opacity: 0.35;
}

.square.is-trap.drag-invalid::after {
  box-shadow: inset 0 0 0 2px rgba(220, 80, 80, 0.75);
}

.square.is-trap-neutral::after {
  box-shadow: inset 0 0 0 2px rgba(140, 140, 155, 0.55);
}

.square.is-hazard::after {
  background:
    repeating-linear-gradient(
      135deg,
      rgba(210, 120, 60, 0.24) 0,
      rgba(210, 120, 60, 0.24) 4px,
      rgba(120, 55, 30, 0.32) 4px,
      rgba(120, 55, 30, 0.32) 8px
    );
  box-shadow: inset 0 0 0 2px rgba(220, 130, 70, 0.65);
}

.square.is-hazard.light {
  background-color: color-mix(in srgb, var(--light) 70%, #a65 30%);
}

.square.is-hazard.dark {
  background-color: color-mix(in srgb, var(--dark) 70%, #743 30%);
}

.square.is-trap-own::after {
  box-shadow: inset 0 0 0 2px rgba(100, 160, 220, 0.75);
}

.square.is-trap-enemy::after {
  box-shadow: inset 0 0 0 2px rgba(220, 100, 80, 0.8);
}

.square.is-trap-own.is-hazard::after {
  background:
    repeating-linear-gradient(
      135deg,
      rgba(90, 140, 200, 0.22) 0,
      rgba(90, 140, 200, 0.22) 4px,
      rgba(40, 70, 110, 0.3) 4px,
      rgba(40, 70, 110, 0.3) 8px
    );
}

.square.is-trap-enemy.is-hazard::after {
  background:
    repeating-linear-gradient(
      135deg,
      rgba(210, 120, 60, 0.28) 0,
      rgba(210, 120, 60, 0.28) 4px,
      rgba(120, 55, 30, 0.36) 4px,
      rgba(120, 55, 30, 0.36) 8px
    );
}

.square-trap-caption {
  position: absolute;
  left: 3px;
  right: 3px;
  bottom: 3px;
  z-index: 2;
  font-size: 0.55rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.15;
  text-align: center;
  color: rgba(255, 226, 190, 0.95);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.85);
  pointer-events: none;
  user-select: none;
}

.square-armed-promo {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  user-select: none;
  border-radius: inherit;
  background: rgba(18, 22, 32, 0.28);
  font-size: clamp(1.1rem, 3.2vw, 1.75rem);
  font-weight: 700;
  line-height: 1;
  color: rgba(255, 244, 214, 0.92);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.75);
}

.board-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  border-radius: 4px;
  background: rgba(8, 8, 12, 0.72);
  backdrop-filter: blur(2px);
  z-index: 4;
}

.board-overlay[hidden] {
  display: none;
}

.board-overlay-panel {
  width: min(18rem, 100%);
  padding: 1.1rem 1.15rem;
  border: 1px solid var(--surface-border);
  border-radius: 10px;
  background: rgba(18, 18, 24, 0.96);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.45);
  text-align: center;
}

.game-over-title {
  margin: 0 0 0.35rem;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--accent-strong);
}

.game-over-detail {
  margin: 0;
  font-size: 0.88rem;
  color: var(--muted);
}

.game-over-panel.is-win .game-over-title {
  color: #6ee7a0;
}

.game-over-panel.is-loss .game-over-title {
  color: #f87171;
}

.game-over-panel.is-draw .game-over-title {
  color: #fbbf24;
}

.promotion-menu {
  position: absolute;
  z-index: 6;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  overflow-x: hidden;
  border: 2px solid var(--frame);
  border-radius: 2px;
  background: rgba(12, 12, 16, 0.94);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55);
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
  scrollbar-width: thin;
}

.promotion-menu[hidden] {
  display: none;
}

.promotion-menu-list {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  list-style: none;
}

.promotion-menu--has-footer {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.promotion-menu--has-footer .promotion-menu-list {
  overflow-y: auto;
  overflow-x: hidden;
  flex: 0 1 auto;
  min-height: 0;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
  scrollbar-width: thin;
}

.promotion-menu--has-footer .promotion-menu-footer,
.promotion-menu--has-footer .promotion-menu-confirm-panel {
  flex: 0 0 auto;
}

.promotion-menu--grow-up .promotion-menu-list {
  flex-direction: column-reverse;
}

.promotion-menu-item {
  position: relative;
  display: block;
  width: 100%;
  height: var(--promotion-item-size, 3rem);
  flex: 0 0 var(--promotion-item-size, 3rem);
  padding: 0;
  border: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(22, 22, 28, 0.98);
  cursor: pointer;
}

.promotion-menu--setup-trap {
  overflow-y: auto;
  overflow-x: hidden;
}

.promotion-menu--setup-trap .promotion-menu-list {
  flex-direction: column;
}

.promotion-menu--setup-trap .promotion-menu-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  height: auto;
  min-height: var(--promotion-item-size, 2.1rem);
  flex: 0 0 auto;
  padding: 0.2rem 0.45rem;
  text-align: left;
}

.promotion-menu--setup-trap .promotion-menu-item .piece-icon {
  position: relative;
  inset: auto;
  width: 1.35rem;
  height: 1.35rem;
  flex: 0 0 auto;
}

.promotion-menu-item-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: rgba(236, 236, 240, 0.92);
  white-space: nowrap;
}

.promotion-menu-item:last-child {
  border-bottom: none;
}

.promotion-menu-item:hover,
.promotion-menu-item:focus-visible {
  background: rgba(180, 186, 200, 0.22);
  outline: none;
}

.promotion-menu-item .piece-icon {
  position: absolute;
  inset: 8%;
  width: auto;
  height: auto;
}

.promotion-menu-item[data-color="b"] .piece-icon {
  filter: invert(1);
}

.promotion-menu-item.is-selected {
  background: rgba(96, 165, 250, 0.28);
  box-shadow: inset 0 0 0 2px rgba(147, 197, 253, 0.85);
}

.promotion-menu-footer {
  display: flex;
  gap: 0.35rem;
  padding: 0.35rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(12, 12, 16, 0.98);
}

.promotion-menu-footer .btn {
  flex: 1 1 0;
  min-height: 1.75rem;
  padding: 0.25rem 0.4rem;
  font-size: 0.72rem;
}

.promotion-menu-confirm-panel {
  padding: 0.55rem 0.65rem;
  font-size: 0.78rem;
  line-height: 1.35;
  color: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.square.transform-target {
  box-shadow: inset 0 0 0 3px rgba(250, 204, 21, 0.85);
  cursor: pointer;
}

.square.transform-selected {
  box-shadow: inset 0 0 0 3px rgba(96, 165, 250, 0.95);
}

.square.destroy-area-carrier {
  box-shadow: inset 0 0 0 3px rgba(248, 113, 113, 0.9);
}

.square-label {
  position: absolute;
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  opacity: 0.55;
  pointer-events: none;
  user-select: none;
}

.square-label.file {
  left: 4px;
  bottom: 3px;
  color: #4a4a54;
}

.square-label.rank {
  right: 4px;
  top: 3px;
  color: #4a4a54;
}

.square.dark .square-label {
  color: #c8c8d0;
}

/* ---------- Piece rendering (filled SVG via <img>; black side CSS-inverted) ---------- */

.piece {
  position: absolute;
  inset: 8%;
  z-index: 1;
  cursor: grab;
}

.piece:active {
  cursor: grabbing;
}

.piece.dragging {
  opacity: 0.35;
}

.piece-icon {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

.piece[data-color="b"] .piece-icon,
.palette-piece[data-color="b"] .piece-icon {
  filter: invert(1);
}

.palette-piece .piece-icon {
  position: static;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
}

.palette-drag-ghost {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 10000;
  margin: 0;
  padding: 0;
  pointer-events: none;
}

.palette-drag-ghost canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.palette-drag-empty {
  position: fixed;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0.01;
  pointer-events: none;
}

/* ---------- Eval staging ---------- */

.eval-staging-section {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-bottom: 1.25rem;
  padding: 1rem;
  border: 1px solid var(--surface-border);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.18);
}

.eval-staging-section[hidden] {
  display: none;
}

.eval-staging-header {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.eval-staging-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.eval-staging-hint {
  margin: 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.eval-staging-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.eval-staging-subtitle {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 600;
}

.eval-engine-current {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.75rem;
  border: 1px solid rgba(120, 180, 255, 0.25);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.15);
}

.eval-engine-current-hint {
  margin: 0;
  font-size: 0.75rem;
  color: var(--muted);
}

.eval-engine-current-summary {
  margin: 0;
  font-size: 0.8rem;
  color: var(--accent-strong);
  font-family: ui-monospace, "Cascadia Code", "Segoe UI Mono", monospace;
}

.eval-engine-current-metrics {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  font-size: 0.8rem;
}

.eval-metric-label {
  color: var(--muted);
}

.eval-metric-value {
  font-family: ui-monospace, "Cascadia Code", "Segoe UI Mono", monospace;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.eval-engine-current-fields {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.eval-staging-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.eval-staging-empty {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.eval-slot {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.75rem;
  border: 1px solid var(--surface-border);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.22);
}

.eval-slot.is-auto {
  border-color: rgba(120, 180, 255, 0.35);
}

.eval-slot.is-preview {
  border-color: rgba(180, 140, 255, 0.35);
}

.eval-slot-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
}

.eval-slot-title {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 600;
}

.eval-slot-meta {
  font-size: 0.75rem;
  color: var(--muted);
}

.eval-slot-meta.is-material {
  color: #c9a227;
}

.eval-slot-fields {
  display: grid;
  gap: 0.55rem;
}

.eval-slot-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.eval-slot-label {
  flex: 0 0 7rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
}

.eval-slot-input,
.eval-slot-fen {
  flex: 1 1 12rem;
  min-width: 0;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--surface-border);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  font: 0.82rem/1.4 ui-monospace, "Cascadia Code", "Segoe UI Mono", monospace;
}

.eval-slot-fen {
  width: 100%;
  min-height: 3.2rem;
  resize: vertical;
}

.eval-slot-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.eval-slot-actions .btn {
  font-size: 0.78rem;
  padding: 0.35rem 0.65rem;
}
