:root {
  color-scheme: dark;
  --bg: #101714;
  --surface: #18221d;
  --surface-2: #202d26;
  --line: rgba(231, 238, 232, 0.11);
  --text: #eef3ef;
  --muted: #9cac9f;
  --accent: #a9bc83;
  --accent-deep: #879a68;
  --accent-border: rgba(169, 188, 131, 0.4);
  --accent-soft: rgba(169, 188, 131, 0.07);
  --accent-focus: rgba(169, 188, 131, 0.55);
  --bg-glow: rgba(83, 119, 86, 0.14);
  --select-bg: #1a251f;
  --board-frame-bg: #26322b;
  --board-border: rgba(255, 255, 255, 0.12);
  --panel-bg: rgba(24, 34, 29, 0.82);
  --footer-text: #c8d3ca;
  --primary-text: #18200f;
  --primary-hover: #b8c998;
  --empty-text: #718078;
  --move-number: #66756c;
  --row-line: rgba(255, 255, 255, 0.045);
  --coordinate-light: rgba(20, 30, 23, 0.62);
  --coordinate-dark: rgba(235, 242, 228, 0.62);
  --light-square: #aeb5a4;
  --dark-square: #667368;
  --game-top-space: clamp(18px, 2.5vw, 32px);
  --board-size: max(320px, min(72vh, calc(100vh - 138px - var(--game-top-space)), 680px, 58vw));
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #edf0e9;
  --surface: #f8faf5;
  --surface-2: #e5eae1;
  --line: rgba(34, 53, 41, 0.15);
  --text: #1b2820;
  --muted: #647168;
  --accent: #68851f;
  --accent-deep: #526b16;
  --accent-border: rgba(82, 107, 22, 0.36);
  --accent-soft: rgba(82, 107, 22, 0.08);
  --accent-focus: rgba(82, 107, 22, 0.5);
  --bg-glow: rgba(100, 127, 87, 0.16);
  --select-bg: #f8faf5;
  --board-frame-bg: #c7cec4;
  --board-border: rgba(35, 50, 40, 0.18);
  --panel-bg: rgba(250, 252, 248, 0.92);
  --footer-text: #4f5d53;
  --primary-text: #ffffff;
  --primary-hover: #78962d;
  --empty-text: #7b877f;
  --move-number: #7b877f;
  --row-line: rgba(34, 53, 41, 0.08);
  --coordinate-light: rgba(27, 40, 31, 0.62);
  --coordinate-dark: rgba(247, 250, 244, 0.78);
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 16% 5%, var(--bg-glow), transparent 32rem),
    var(--bg);
  transition: color 180ms ease, background-color 180ms ease;
}

button, select { font: inherit; }
button { color: inherit; }

.page-shell {
  width: min(1360px, calc(100% - 40px));
  margin: 0 auto;
}

.topbar {
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--accent-border);
  border-radius: 12px;
  color: var(--accent);
  font: 29px/1 "Segoe UI Symbol", serif;
  background: var(--accent-soft);
}

.brand strong { display: block; letter-spacing: 0.13em; font-size: 15px; }
.brand small { display: block; margin-top: 2px; color: var(--muted); letter-spacing: 0.2em; font-size: 9px; }

.toolbar-actions { display: flex; gap: 8px; }
.evaluation-toggle {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--muted);
  background: var(--surface);
  font-size: 11px;
  font-weight: 750;
  cursor: pointer;
}
.evaluation-toggle:hover { color: var(--accent); border-color: var(--accent-border); }
.evaluation-toggle input { margin: 0; accent-color: var(--accent); }
.field-label { color: var(--muted); font-size: 12px; font-weight: 600; }
.select-row { display: flex; gap: 8px; }
.select-row .wide-select { min-width: 0; flex: 1 1 auto; }
.select-row .icon-button { flex: 0 0 40px; }

select {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px 38px 10px 12px;
  color: var(--text);
  outline: none;
  background: var(--select-bg);
}

select:focus { border-color: var(--accent-focus); }

.icon-button, .text-button {
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
}

.icon-button { width: 40px; border-radius: 9px; font-size: 20px; }
.theme-toggle { font-size: 18px; line-height: 1; }
.text-button { padding: 7px 12px; border-radius: 8px; color: var(--muted); font-size: 12px; }
.toolbar-link { display: inline-flex; align-items: center; text-decoration: none; }
.icon-button:hover, .text-button:hover { color: var(--accent); border-color: var(--accent-border); }

.game-layout {
  display: grid;
  grid-template-columns: minmax(170px, 255px) minmax(0, var(--board-size)) minmax(310px, 380px);
  justify-content: center;
  gap: clamp(16px, 1.8vw, 32px);
  padding: var(--game-top-space) 0 0;
}

.avatar-column {
  align-self: start;
  height: var(--board-size);
  display: grid;
  place-items: center;
}

.teseo-avatar {
  display: block;
  width: min(100%, 255px);
  height: auto;
  filter:
    drop-shadow(0 16px 24px rgba(0, 0, 0, 0.35))
    drop-shadow(0 0 18px rgba(169, 188, 131, 0.08));
  user-select: none;
}

.board-with-evaluation {
  position: relative;
  width: calc(100% + 31px);
  margin-left: -31px;
  display: grid;
  grid-template-columns: 23px minmax(0, 1fr);
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--board-border);
  border-radius: 16px;
  background: var(--board-frame-bg);
  box-shadow: 0 26px 70px rgba(0, 0, 0, 0.28);
}
.evaluation-bar {
  --evaluation-share: 50%;
  position: relative;
  width: 100%;
  min-width: 0;
  z-index: 3;
  overflow: hidden;
  border-radius: 6px;
  background: var(--dark-square);
}
.evaluation-white {
  position: absolute;
  inset: auto 0 0;
  height: var(--evaluation-share);
  background: var(--light-square);
  will-change: height;
}
.evaluation-divider {
  position: absolute;
  left: 0;
  right: 0;
  bottom: var(--evaluation-share);
  height: 2px;
  background: var(--accent);
  box-shadow: 0 0 7px rgba(169, 188, 131, 0.75);
  will-change: bottom;
}
.evaluation-bar[data-orientation="black"] .evaluation-white { inset: 0 0 auto; }
.evaluation-bar[data-orientation="black"] .evaluation-divider {
  top: var(--evaluation-share);
  bottom: auto;
}
.evaluation-score {
  position: absolute;
  z-index: 1;
  left: 2px;
  right: 2px;
  padding: 3px 0;
  border-radius: 4px;
  color: #202420;
  text-align: center;
  font-size: 8px;
  font-weight: 850;
  line-height: 1;
  background: rgba(255, 255, 255, 0.68);
}
.evaluation-score[data-side="black"] { color: #f3f4ef; background: rgba(0, 0, 0, 0.44); }
.evaluation-score:not([data-side="black"]) { color: #202420; background: rgba(255, 255, 255, 0.68); }
.evaluation-bar:not([data-orientation="black"]) .evaluation-score[data-side="black"],
.evaluation-bar[data-orientation="black"] .evaluation-score:not([data-side="black"]) { top: 3px; bottom: auto; }
.evaluation-bar:not([data-orientation="black"]) .evaluation-score:not([data-side="black"]),
.evaluation-bar[data-orientation="black"] .evaluation-score[data-side="black"] { top: auto; bottom: 3px; }
.evaluation-bar.is-loading .evaluation-divider { animation: evaluation-pulse 1.1s ease-in-out infinite; }
.evaluation-bar.is-forced-mate .evaluation-divider { opacity: 0; box-shadow: none; }
.evaluation-bar.is-unavailable { filter: saturate(0); opacity: 0.58; }
.evaluation-bar.is-unavailable .evaluation-divider { box-shadow: none; }
@keyframes evaluation-pulse { 50% { opacity: 0.35; } }

.board-frame {
  position: relative;
  overflow: hidden;
  min-width: 0;
  border-radius: 10px;
}

.capture-tray {
  width: calc(100% - 16px);
  min-height: 30px;
  margin-left: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
}
.capture-tray-top { margin-bottom: 4px; }
.capture-tray-bottom { margin-top: 4px; }
.captured-piece-list {
  min-width: 0;
  display: flex;
  align-items: center;
  padding-left: 5px;
}
.captured-piece-group {
  display: flex;
  align-items: center;
}
.captured-piece-group + .captured-piece-group { margin-left: -4px; }
.captured-piece {
  width: 25px;
  height: 25px;
  flex: 0 0 25px;
  object-fit: contain;
  filter: drop-shadow(0 2px 1px rgba(0, 0, 0, 0.2));
}
.captured-piece-group .captured-piece + .captured-piece { margin-left: -19px; }
.material-advantage {
  flex: 0 0 auto;
  min-width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  border: 1px solid var(--board-border);
  border-radius: 999px;
  color: var(--accent);
  background: var(--board-frame-bg);
  font-weight: 850;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.board {
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  grid-template-rows: repeat(8, minmax(0, 1fr));
  overflow: hidden;
  border-radius: 10px;
}

.square {
  position: relative;
  width: 100%;
  min-height: 0;
  min-width: 0;
  aspect-ratio: 1;
  overflow: hidden;
  border: 0;
  padding: 0;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.square:disabled { cursor: default; opacity: 1; }
.square.light { background: var(--light-square); }
.square.dark { background: var(--dark-square); }
.square.last-move { box-shadow: inset 0 0 0 999px rgba(169, 188, 131, 0.27); }
.square.selected { box-shadow: inset 0 0 0 999px rgba(184, 201, 152, 0.43); }
.square.move-target::after,
.square.drag-target::after {
  content: "";
  position: absolute;
  width: 23%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(25, 36, 29, 0.39);
}
.square.capture-target::after,
.square.drag-capture-target::after {
  content: "";
  position: absolute;
  inset: 5%;
  border: clamp(3px, 0.45vw, 6px) solid rgba(25, 36, 29, 0.38);
  border-radius: 50%;
}
.square.drag-hover { box-shadow: inset 0 0 0 4px var(--accent); }

.piece {
  position: relative;
  z-index: 1;
  display: block;
  width: 86%;
  height: 86%;
  object-fit: contain;
  pointer-events: none;
  -webkit-touch-callout: none;
  -webkit-user-drag: none;
  -webkit-user-select: none;
  user-select: none;
  filter: drop-shadow(0 3px 1px rgba(0, 0, 0, 0.25));
}
.piece.draggable { cursor: grab; pointer-events: auto; touch-action: none; }
.piece.drag-origin { opacity: 0.22; }
.dragging-piece, .dragging-piece * { cursor: grabbing !important; }
.drag-piece,
.moving-piece {
  position: fixed;
  z-index: 1000;
  margin: 0;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  filter: drop-shadow(0 8px 6px rgba(0, 0, 0, 0.35));
}
.drag-piece { transform: scale(1.08); }
.drag-piece.is-touch-drag { transform: scale(3); }
.moving-piece {
  transform: translate3d(0, 0, 0) scale(1);
  transition: transform 420ms cubic-bezier(0.22, 0.8, 0.3, 1);
}
.moving-piece.is-moving {
  transform: translate3d(var(--move-x), var(--move-y), 0) scale(1.04);
}
.cat-carried-piece {
  position: absolute;
  z-index: 1001;
  transition: none;
  will-change: transform, opacity;
}
.captured-piece-animation {
  position: absolute;
  z-index: 999;
  margin: 0;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
  filter: drop-shadow(0 3px 1px rgba(0, 0, 0, 0.25));
  will-change: transform, opacity;
}
.bot-cat-paw-stage {
  position: absolute;
  z-index: 1002;
  overflow: hidden;
  border-radius: 10px;
  pointer-events: none;
  user-select: none;
  isolation: isolate;
}
.bot-cat-paw {
  position: absolute;
  z-index: 1;
  display: block;
  margin: 0;
  pointer-events: none;
  user-select: none;
  transform-origin: 50% 0;
  filter:
    drop-shadow(0 10px 8px rgba(0, 0, 0, 0.28))
    drop-shadow(0 0 2px rgba(255, 255, 255, 0.18));
  will-change: height, transform;
}
.bot-cat-leg {
  position: absolute;
  z-index: 0;
  inset: 0 0 var(--paw-overlap);
  background-image: url("/graphics/cat-leg-repeat.png");
  background-position: center bottom;
  background-repeat: repeat-y;
  background-size: 116% auto;
}
.bot-cat-paw-tip {
  position: absolute;
  z-index: 1;
  left: 0;
  bottom: 0;
  display: block;
  width: var(--paw-tip-size);
  height: var(--paw-tip-size);
  object-fit: contain;
  -webkit-mask-image: linear-gradient(
    to bottom,
    transparent 0%,
    rgba(0, 0, 0, 0.45) 9%,
    #000 22%
  );
  mask-image: linear-gradient(
    to bottom,
    transparent 0%,
    rgba(0, 0, 0, 0.45) 9%,
    #000 22%
  );
  pointer-events: none;
  user-select: none;
}
.animation-target { visibility: hidden; }

.coordinate {
  position: absolute;
  z-index: 2;
  color: var(--coordinate-light);
  font-size: clamp(8px, 1vw, 11px);
  font-weight: 800;
}
.file-coordinate { right: 4px; bottom: 2px; }
.rank-coordinate { left: 4px; top: 2px; }
.square.dark .coordinate { color: var(--coordinate-dark); }

.thinking-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  place-content: center;
  justify-items: center;
  border-radius: 10px;
  background: rgba(12, 18, 15, 0.72);
  backdrop-filter: blur(3px);
  color: #eef3ef;
}
.thinking-overlay:not([hidden]) { display: grid; }
.thinking-overlay strong { margin-top: 15px; font-size: 15px; }
.thinking-overlay small { margin-top: 4px; color: #9cac9f; }
.game-summary-overlay {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: grid;
  place-items: center;
  padding: clamp(10px, 3.6%, 24px);
  overflow: hidden;
  border-radius: 10px;
  color: #eef3ef;
  background: rgba(10, 15, 12, 0.86);
  backdrop-filter: blur(4px);
  animation: summary-reveal 220ms ease-out;
}
.game-summary-card {
  width: 100%;
  max-height: 100%;
  display: grid;
  gap: clamp(6px, 1.8vh, 12px);
}
.game-summary-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.game-summary-heading span { display: block; color: var(--accent); font-size: clamp(7px, 1.2vw, 9px); font-weight: 850; letter-spacing: 0.18em; }
.game-summary-heading strong { display: block; margin-top: 3px; font-size: clamp(13px, 2.1vw, 18px); }
.game-summary-heading button {
  flex: 0 0 auto;
  width: clamp(28px, 5vw, 34px);
  height: clamp(28px, 5vw, 34px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 9px;
  color: #eef3ef;
  background: rgba(255, 255, 255, 0.08);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.game-summary-heading button:hover,
.game-summary-heading button:focus-visible { border-color: var(--accent); color: var(--accent); outline: none; }
.evaluation-chart {
  width: 100%;
  min-height: 0;
  aspect-ratio: 1.78;
  display: block;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  background: #121916;
}
.chart-background { fill: #121916; }
.chart-white-area { fill: var(--light-square); }
.chart-black-area { fill: var(--dark-square); }
.chart-midline { stroke: rgba(255, 255, 255, 0.4); stroke-width: 2; stroke-dasharray: 8 9; }
.chart-curve { fill: none; stroke: var(--accent); stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; filter: drop-shadow(0 0 5px rgba(169, 188, 131, 0.45)); }
.chart-side-label { font-size: 18px; font-weight: 850; letter-spacing: 0.12em; }
.chart-black-label { fill: rgba(245, 248, 245, 0.72); }
.chart-white-label { fill: rgba(20, 29, 23, 0.72); }
.chart-axis-label { fill: rgba(238, 243, 239, 0.62); font-size: 15px; font-weight: 750; letter-spacing: 0.08em; }
.chart-end-label { text-anchor: end; }
.game-summary-footer { display: flex; align-items: center; flex-wrap: wrap; gap: 5px 12px; color: #d5ddd7; font-size: clamp(8px, 1.5vw, 10px); }
.game-summary-footer span { display: inline-flex; align-items: center; gap: 5px; }
.game-summary-footer small { margin-left: auto; color: #9cac9f; font-size: inherit; }
.summary-export-button {
  padding: 5px 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 7px;
  color: #eef3ef;
  background: rgba(255, 255, 255, 0.08);
  font-size: inherit;
  font-weight: 750;
  cursor: pointer;
}
.summary-export-button:hover,
.summary-export-button:focus-visible { border-color: var(--accent); color: var(--accent); outline: none; }
.summary-swatch { width: 8px; height: 8px; border-radius: 2px; }
.summary-swatch.white { background: var(--light-square); }
.summary-swatch.black { background: var(--dark-square); }
@keyframes summary-reveal { from { opacity: 0; transform: scale(0.985); } }
.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(169, 188, 131, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.board-footer { min-height: 48px; display: flex; align-items: center; gap: 10px; }
.board-footer p { min-width: 0; margin: 0; color: var(--footer-text); font-size: 13px; }
.history-navigation { margin-left: auto; display: flex; gap: 5px; }
.history-navigation .evaluation-toggle {
  min-height: auto;
  padding: 6px 9px;
  border-radius: 8px;
  font-size: 12px;
}
.history-button {
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface);
  font-size: 11px;
  cursor: pointer;
}
.history-button:hover:not(:disabled), .history-button:focus-visible { color: var(--accent); border-color: var(--accent-border); outline: none; }
.history-button:disabled { cursor: not-allowed; opacity: 0.38; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #829087; }
.status-dot[data-kind="ready"] { background: var(--accent); box-shadow: 0 0 0 4px rgba(169, 188, 131, 0.1); }
.status-dot[data-kind="thinking"] { background: #f5c85f; animation: pulse 1s ease-in-out infinite; }
.status-dot[data-kind="warning"] { background: #f5c85f; }
.status-dot[data-kind="error"] { background: #ff7a7a; }
.status-dot[data-kind="done"] { background: #87beff; }
@keyframes pulse { 50% { opacity: 0.45; } }

.side-panel {
  align-self: start;
  height: var(--board-size);
  min-height: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  background: var(--panel-bg);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.16);
}

.panel-section { padding: 28px; }
.setup-section { flex: 0 0 auto; padding: 22px 28px; border-bottom: 1px solid var(--line); }
.moves-section { padding: 22px 28px; }
.moves-section { min-height: 0; flex: 1 1 auto; display: flex; flex-direction: column; overflow: hidden; }
.eyebrow { margin: 0 0 8px; color: var(--accent); font-size: 9px; font-weight: 800; letter-spacing: 0.2em; }
h1, h2 { margin: 0; letter-spacing: -0.025em; }
h1 { font-size: 27px; }
h2 { font-size: 19px; }
.intro { margin: 10px 0 24px; color: var(--muted); font-size: 13px; line-height: 1.55; }
.field-label { display: block; margin-bottom: 8px; }
.wide-select { width: 100%; }

.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-bottom: 18px;
  padding: 4px;
  border-radius: 10px;
  background: var(--surface-2);
}
.mode-tab {
  min-width: 0;
  padding: 8px 7px;
  border: 0;
  border-radius: 7px;
  color: var(--muted);
  background: transparent;
  font-size: 11px;
  font-weight: 750;
  cursor: pointer;
}
.mode-tab:hover { color: var(--text); }
.mode-tab.is-active { color: var(--text); background: var(--surface); box-shadow: 0 2px 9px rgba(0, 0, 0, 0.14); }
.mode-tab:disabled { cursor: not-allowed; opacity: 0.45; }
.mode-tab:focus-visible { outline: 2px solid var(--accent-focus); outline-offset: 1px; }
.mode-panel { animation: reveal-panel 180ms ease; }
@keyframes reveal-panel { from { opacity: 0; transform: translateY(3px); } }

.model-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.model-field { display: block; }
.model-field select { padding-right: 26px; font-size: 12px; }
.color-disc {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 4px;
  border: 1px solid var(--line);
  border-radius: 50%;
  vertical-align: -1px;
}
.white-disc { background: #f2f3ed; }
.black-disc { background: #303a33; }

.sampling-switch {
  width: 100%;
  min-height: 44px;
  margin-top: 10px;
  padding: 7px 9px 7px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--text);
  text-align: left;
  background: var(--surface-2);
  cursor: pointer;
}
.sampling-switch:hover, .sampling-switch:focus-visible { border-color: var(--accent-border); outline: none; }
.sampling-copy { min-width: 0; }
.sampling-copy strong { display: block; font-size: 12px; }
.sampling-copy small { display: block; margin-top: 3px; color: var(--muted); font-size: 9px; }
.sampling-switch[data-enabled="true"] .color-switch-track { background: var(--accent-deep); }
.sampling-switch[data-enabled="true"] .color-switch-knob { transform: translateX(16px); }
#ai-vs-ai-panel .intro { margin-bottom: 16px; }
#ai-vs-ai-panel .primary-button { margin-top: 10px; }

.mcts-budget-control {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.mcts-budget-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  font-weight: 750;
}
.mcts-budget-heading output {
  min-width: 48px;
  color: var(--accent);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
#mcts-simulations {
  width: 100%;
  margin: 10px 0 0;
  accent-color: var(--accent);
  cursor: pointer;
}
#mcts-simulations:disabled { cursor: wait; }
#mcts-simulations.standard-mode-locked:disabled { cursor: not-allowed; }
.mcts-budget-scale {
  display: flex;
  justify-content: space-between;
  margin-top: -1px;
  color: var(--muted);
  font-size: 9px;
  font-variant-numeric: tabular-nums;
}
.mcts-budget-control small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 9px;
  line-height: 1.4;
}

.game-actions { display: flex; align-items: stretch; gap: 9px; }
.spaced-actions { margin-top: 14px; }
.color-switch {
  flex: 0 0 116px;
  min-width: 0;
  min-height: 45px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 9px 6px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--text);
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color 180ms ease, background-color 180ms ease;
}
.color-switch:hover, .color-switch:focus-visible { border-color: var(--accent-border); outline: none; }
.color-switch-label { font-size: 12px; font-weight: 750; }
.color-switch-track {
  width: 37px;
  height: 21px;
  flex: 0 0 auto;
  padding: 3px;
  border-radius: 999px;
  background: #d8ddd8;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
  transition: background-color 220ms ease;
}
.color-switch-knob {
  width: 15px;
  height: 15px;
  display: block;
  border-radius: 50%;
  background: #fafcf9;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.34);
  transition: transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1), background-color 220ms ease;
}
.color-switch[data-color="black"] .color-switch-track { background: #3c4740; }
.color-switch[data-color="black"] .color-switch-knob { transform: translateX(16px); background: #111714; }

.primary-button, .secondary-button {
  width: 100%;
  min-height: 45px;
  margin-top: 14px;
  border-radius: 9px;
  font-weight: 750;
  cursor: pointer;
}
.game-actions .primary-button { min-width: 0; flex: 1 1 auto; margin-top: 0; }
.primary-button { border: 0; color: var(--primary-text); background: var(--accent); }
.primary-button:hover { background: var(--primary-hover); }
.secondary-button { border: 1px solid var(--accent-border); color: var(--accent); background: transparent; }
button:disabled { cursor: wait; opacity: 0.55; }

.section-heading { display: flex; align-items: center; justify-content: space-between; }
.pill { min-width: 29px; padding: 4px 8px; border-radius: 999px; color: var(--muted); text-align: center; font-size: 11px; background: var(--surface-2); }
.empty-state { padding: 30px 0 6px; color: var(--empty-text); text-align: center; }
.empty-state span { font: 32px/1 "Segoe UI Symbol", serif; }
.empty-state p { margin: 8px 0 0; font-size: 12px; }
.move-list { min-height: 0; flex: 1 1 auto; margin: 12px 0 0; padding: 0; overflow-y: auto; list-style: none; }
.move-list li { display: grid; grid-template-columns: 28px 1fr 1fr; gap: 8px; min-height: 34px; align-items: center; border-bottom: 1px solid var(--row-line); font-size: 13px; }
.move-number { color: var(--move-number); font-size: 11px; }
.move-san { font-weight: 650; }
.move-san.ai { color: var(--accent); }
.move-san.white-ai { color: var(--text); }
.move-san.black-ai { color: var(--accent); }

.promotion-dialog {
  width: min(430px, calc(100% - 28px));
  padding: 24px;
  border: 1px solid var(--accent-border);
  border-radius: 14px;
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.45);
}
.promotion-dialog::backdrop { background: rgba(5, 9, 7, 0.73); backdrop-filter: blur(2px); }
.promotion-dialog form { margin: 0; }
.promotion-options { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 20px; }
.promotion-options button { min-height: 88px; border: 1px solid var(--line); border-radius: 10px; color: var(--text); background: var(--surface-2); font: 35px/1 "Segoe UI Symbol", serif; cursor: pointer; }
.promotion-options button:hover { border-color: var(--accent); color: var(--accent); }
.promotion-options small { display: block; margin-top: 7px; font: 10px/1 sans-serif; color: var(--muted); }

.pgn-dialog {
  width: min(720px, calc(100% - 28px));
  padding: 0;
  border: 1px solid var(--accent-border);
  border-radius: 14px;
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.45);
}
.pgn-dialog::backdrop {
  background: rgba(5, 9, 7, 0.73);
  backdrop-filter: blur(2px);
}
.pgn-dialog-shell { margin: 0; padding: 24px; }
.pgn-dialog-heading {
  display: flex;
  gap: 18px;
  align-items: flex-start;
  justify-content: space-between;
}
.pgn-dialog-heading .eyebrow { margin: 0 0 5px; }
.pgn-dialog-heading h2 { margin: 0; font-size: 21px; }
.pgn-dialog-close {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
  background: var(--surface-2);
  font: 25px/1 sans-serif;
  cursor: pointer;
}
.pgn-dialog-close:hover { border-color: var(--accent); color: var(--accent); }
.pgn-dialog-intro {
  margin: 13px 0 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}
.pgn-copy-field { position: relative; }
.pgn-text {
  display: block;
  box-sizing: border-box;
  width: 100%;
  min-height: 300px;
  padding: 15px 58px 15px 15px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  color: var(--text);
  background: var(--surface-2);
  font: 12px/1.55 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}
.pgn-text:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.pgn-copy-button {
  position: absolute;
  top: 10px;
  right: 10px;
  display: grid;
  width: 38px;
  height: 38px;
  padding: 8px;
  place-items: center;
  border: 1px solid var(--accent-border);
  border-radius: 8px;
  color: var(--accent);
  background: var(--surface);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.16);
  cursor: pointer;
}
.pgn-copy-button:hover { color: var(--primary-text); background: var(--accent); }
.pgn-copy-button svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.pgn-copy-message {
  min-height: 18px;
  margin: 9px 0 0;
  color: var(--accent);
  font-size: 12px;
}
.pgn-download-button {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
}
.pgn-download-button span { font-size: 18px; line-height: 1; }

[hidden] { display: none !important; }

html.evaluation-hidden .evaluation-bar { display: none; }
html.evaluation-hidden .board-with-evaluation {
  width: 100%;
  margin-left: 0;
  grid-template-columns: minmax(0, 1fr);
}

@media (max-width: 1160px) {
  :root { --board-size: min(calc(100vw - 84px), 680px, 72vh); }
  .game-layout { grid-template-columns: minmax(0, var(--board-size)); }
  .avatar-column { height: auto; }
  .teseo-avatar { width: 210px; }
  .side-panel { height: auto; min-height: var(--board-size); }
  .moves-section { min-height: 210px; }
  .model-fields { grid-template-columns: 1fr; gap: 13px; }
}

@media (min-width: 601px) and (max-width: 1160px) {
  .game-layout { gap: 0; }
  .board-column { position: relative; }
  .capture-tray-top:not(:has(.captured-piece)) { display: none; }
  .capture-tray-top:has(.captured-piece) {
    position: absolute;
    bottom: 100%;
    left: 8px;
    z-index: 6;
    width: calc(100% - 16px);
    min-height: 30px;
    margin: 0;
  }
  .side-panel { margin-top: clamp(16px, 1.8vw, 32px); }
}

@media (max-width: 600px) {
  .page-shell { width: min(100% - 20px, 520px); }
  .topbar { min-height: 76px; }
  .game-layout { padding-top: 22px; gap: 0; }
  .board-column { position: relative; }
  .teseo-avatar { width: 168px; }
  .capture-tray-top:not(:has(.captured-piece)) { display: none; }
  .capture-tray-top:has(.captured-piece) {
    position: absolute;
    bottom: 100%;
    left: 6px;
    z-index: 6;
    width: calc(100% - 12px);
    min-height: 28px;
    margin: 0;
    padding: 0;
  }
  .side-panel { margin-top: 22px; }
  .panel-section { padding: 23px; }
  .board-footer { flex-wrap: wrap; padding: 7px 0; }
  .history-navigation { order: 3; width: 100%; margin-left: 0; }
  .history-button { flex: 1 1 0; }
}

@media (max-width: 600px) and (orientation: portrait) {
  :root { --board-size: calc(100vw - 20px); }
  .game-layout { grid-template-columns: minmax(0, 1fr); }
  .board-column { width: 100%; }
  .board-with-evaluation {
    width: 100%;
    margin-left: 0;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto 18px;
    grid-template-areas:
      "board"
      "evaluation";
    gap: 6px;
    padding: 6px;
  }
  .board-frame { grid-area: board; }
  .evaluation-bar {
    grid-area: evaluation;
    min-height: 18px;
    border-radius: 5px;
  }
  .evaluation-white {
    inset: 0 0 0 auto;
    width: var(--evaluation-share);
    height: 100%;
    will-change: width;
  }
  .evaluation-divider {
    top: 0;
    right: var(--evaluation-share);
    bottom: 0;
    left: auto;
    width: 2px;
    height: auto;
    will-change: right;
  }
  .evaluation-bar[data-orientation="black"] .evaluation-white {
    inset: 0 auto 0 0;
  }
  .evaluation-bar[data-orientation="black"] .evaluation-divider {
    top: 0;
    right: auto;
    bottom: 0;
    left: var(--evaluation-share);
  }
  .evaluation-score,
  .evaluation-bar[data-orientation="black"] .evaluation-score {
    top: 50% !important;
    right: auto;
    bottom: auto !important;
    left: 50%;
    width: auto;
    padding: 2px 6px;
    transform: translate(-50%, -50%);
    font-size: 9px;
  }
  html.evaluation-hidden .board-with-evaluation {
    grid-template-rows: auto;
    grid-template-areas: "board";
  }
  .capture-tray {
    min-height: 28px;
    width: calc(100% - 12px);
    margin-left: 6px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .game-summary-overlay { animation: none; }
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}


.fen-panel {
  margin: 12px 0 24px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-bg);
}
.fen-panel summary { color: var(--accent); cursor: pointer; font-size: 12px; font-weight: 700; }
.fen-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 16px; }
.fen-heading button { flex-shrink: 0; }
.fen-field {
  display: block;
  width: 100%;
  min-height: 58px;
  margin-top: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--select-bg);
  color: var(--text);
  font: 12px/1.5 ui-monospace, Consolas, monospace;
  resize: vertical;
  overflow-wrap: anywhere;
}
.fen-field:focus { outline: 2px solid var(--accent-focus); outline-offset: 1px; }
.fen-field[aria-invalid="true"] { border-color: #d88173; }
#fen-form { margin-top: 16px; }
#fen-help, .fen-message { display: block; margin: 8px 0 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.fen-message:empty { display: none; }
.fen-message[data-kind="error"] { color: #d88173; }
#load-fen-button { min-height: 38px; margin-top: 10px; font-size: 12px; }

.upload-layout {
  min-height: calc(100vh - 91px);
  display: grid;
  place-items: center;
  padding: 42px 0 72px;
}
.upload-card {
  width: min(560px, 100%);
  padding: clamp(26px, 5vw, 44px);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel-bg);
  box-shadow: 0 26px 70px rgba(0, 0, 0, 0.24);
}
.upload-card h1 { margin: 7px 0 8px; font-size: clamp(25px, 5vw, 35px); }
.upload-card .intro { margin: 0 0 26px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.upload-card code { color: var(--accent); }
.upload-dropzone {
  position: relative;
  min-height: 176px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 7px;
  padding: 24px;
  border: 1px dashed var(--accent-border);
  border-radius: 13px;
  text-align: center;
  background: var(--accent-soft);
  cursor: pointer;
  overflow: hidden;
}
.upload-dropzone:hover, .upload-dropzone:focus-within { border-color: var(--accent); }
.upload-dropzone input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}
.upload-symbol { color: var(--accent); font-size: 38px; line-height: 1; }
.upload-dropzone strong { max-width: 100%; overflow-wrap: anywhere; font-size: 14px; }
.upload-dropzone small, .upload-field small {
  color: var(--muted);
  font-size: 10px;
  line-height: 1.45;
}
.upload-field { display: grid; gap: 7px; margin-top: 18px; }
.upload-field input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--text);
  background: var(--select-bg);
  outline: none;
}
.upload-field input:focus { border-color: var(--accent-focus); }
.upload-status { min-height: 22px; margin: 16px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.upload-status[data-kind="done"] { color: var(--accent); }
.upload-status[data-kind="error"] { color: #d88173; }

@media (max-width: 600px) {
  .upload-page .toolbar-link { display: none; }
  .upload-layout { padding: 24px 0 42px; }
  .upload-card { padding: 24px 20px; }
}

/* Persistent checkpoint tournament heatmap */
.heatmap-shell { width: min(1680px, calc(100% - 40px)); }
.heatmap-page { padding: 44px 0 64px; }
.heatmap-heading { display: flex; align-items: end; justify-content: space-between; gap: 32px; margin-bottom: 26px; }
.heatmap-heading h1 { margin: 8px 0 10px; font-size: clamp(28px, 4vw, 48px); }
.heatmap-heading p { max-width: 760px; margin: 0; color: var(--muted); line-height: 1.65; }
.tournament-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.tournament-summary article { min-width: 0; padding: 17px 18px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel-bg); }
.tournament-summary span { display: block; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.tournament-summary strong { display: block; margin-top: 7px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress-track { height: 6px; margin: 14px 0 28px; overflow: hidden; border-radius: 999px; background: var(--surface-2); }
.progress-value { width: 0; height: 100%; border-radius: inherit; background: var(--accent); transition: width 350ms ease; }
.heatmap-panel { overflow: hidden; border: 1px solid var(--line); border-radius: 18px; background: var(--panel-bg); }
.heatmap-panel > header { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 20px 22px; border-bottom: 1px solid var(--line); }
.heatmap-panel h2 { margin: 5px 0 0; font-size: 20px; }
.last-update { color: var(--muted); font-size: 13px; white-space: nowrap; }
.heatmap-scroll { max-height: calc(100vh - 310px); min-height: 280px; overflow: auto; }
.heatmap-table { width: max-content; min-width: 100%; border-collapse: separate; border-spacing: 0; font-variant-numeric: tabular-nums; }
.heatmap-table th, .heatmap-table td { min-width: 104px; height: 76px; padding: 9px 10px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); text-align: center; }
.heatmap-table thead th { position: sticky; top: 0; z-index: 3; height: 150px; vertical-align: bottom; background: var(--surface); }
.heatmap-table thead th span { display: inline-block; width: 25px; overflow: visible; transform: rotate(-52deg); transform-origin: left bottom; white-space: nowrap; text-align: left; }
.heatmap-table tbody th { position: sticky; left: 0; z-index: 2; max-width: 210px; overflow: hidden; text-align: left; text-overflow: ellipsis; white-space: nowrap; background: var(--surface); }
.heatmap-table .heatmap-corner { left: 0; z-index: 5; min-width: 210px; height: 150px; padding: 14px; vertical-align: bottom; text-align: left; color: var(--muted); font-size: 12px; }
.heatmap-cell { background: var(--surface-2); transition: background-color 180ms ease, box-shadow 180ms ease; }
.heatmap-cell strong { display: block; font-size: 18px; }
.heatmap-cell small { display: block; margin-top: 5px; color: var(--muted); font-size: 11px; }
.heatmap-cell.positive { background: color-mix(in srgb, #3c9b65 var(--cell-mix), var(--surface-2)); }
.heatmap-cell.negative { background: color-mix(in srgb, #b94c55 var(--cell-mix), var(--surface-2)); }
.heatmap-cell.neutral { background: var(--surface-2); }
.heatmap-cell.diagonal { color: var(--muted); background: repeating-linear-gradient(135deg, transparent 0 8px, var(--line) 8px 9px), var(--surface-2); }
.heatmap-cell.pending { color: var(--empty-text); }
.heatmap-cell.is-active { box-shadow: inset 0 0 0 2px var(--accent); }
.heatmap-empty { display: grid; min-height: 280px; margin: 0; padding: 30px; place-items: center; color: var(--muted); text-align: center; }
.checkpoint-errors { margin-top: 22px; padding: 20px 22px; border: 1px solid rgba(185, 76, 85, .45); border-radius: 14px; background: rgba(185, 76, 85, .08); }
.checkpoint-errors h2 { margin: 0 0 12px; font-size: 17px; }
.checkpoint-errors ul { margin: 0; padding-left: 20px; color: var(--muted); }
.heatmap-note { max-width: 900px; margin: 20px 2px 0; color: var(--muted); font-size: 13px; line-height: 1.6; }

@media (max-width: 820px) {
  .heatmap-shell { width: min(100% - 24px, 1680px); }
  .heatmap-page { padding-top: 28px; }
  .heatmap-heading { align-items: stretch; flex-direction: column; gap: 18px; }
  .heatmap-heading .secondary-button { align-self: flex-start; }
  .tournament-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .heatmap-panel > header { align-items: flex-start; flex-direction: column; }
  .heatmap-scroll { max-height: calc(100vh - 240px); }
}

@media (max-width: 520px) {
  .heatmap-shell .toolbar-link { display: none; }
  .tournament-summary { grid-template-columns: 1fr; }
  .heatmap-table .heatmap-corner, .heatmap-table tbody th { min-width: 155px; max-width: 155px; }
  .heatmap-table th, .heatmap-table td { min-width: 88px; }
}
