:root {
  color-scheme: light;
  --bg: #f3f4f1;
  --ink: #111211;
  --muted: #6a6f68;
  --line: #d8dcd3;
  --soft: #ecefe8;
  --panel: #ffffff;
  --black: #111211;
  --white: #ffffff;
  --accent: #1d6f62;
  --accent-soft: #e8f5f1;
  --warn: #b15c16;
  --danger: #b42318;
  --danger-soft: #fff1ef;
  --board-light: #f0dfc1;
  --board-dark: #5f7f69;
  --last: #f1c84b;
  --focus: #101010;
  --board-max: 600px;
  --rail-width: 520px;
  --workspace-gap: 16px;
  --workspace-max: calc(var(--board-max) + var(--rail-width) + var(--workspace-gap));
}

body.dark {
  color-scheme: dark;
  --bg: #171817;
  --ink: #f4f1ec;
  --muted: #a6aaa1;
  --line: #3a3d37;
  --soft: #242723;
  --panel: #20221f;
  --black: #f4f1ec;
  --white: #151614;
  --accent: #6ed5be;
  --accent-soft: rgba(110, 213, 190, 0.14);
  --warn: #ffb15f;
  --danger: #ff8b7f;
  --danger-soft: rgba(255, 139, 127, 0.13);
  --board-light: #d9c7a6;
  --board-dark: #55705d;
  --last: #ffcf4d;
  --focus: #f4f1ec;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

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

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 32px;
  border: 1px solid var(--black);
  border-radius: 7px;
  background: var(--black);
  color: var(--white);
  padding: 0 10px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}

button:hover {
  filter: brightness(1.08);
}

button:disabled {
  cursor: default;
  opacity: 0.45;
}

button.secondary {
  border-color: var(--line);
  background: var(--panel);
  color: var(--ink);
}

button.secondary.active,
button.icon.secondary.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

button.danger,
.danger {
  color: var(--danger);
}

button.icon {
  width: 34px;
  min-width: 34px;
  padding: 0;
}

button svg,
.section-title svg,
.switch svg {
  width: 16px;
  height: 16px;
  stroke-width: 2.25;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--ink);
  padding: 7px 9px;
}

textarea {
  resize: vertical;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.app {
  width: 100%;
  margin: 0 auto;
  padding: 12px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: min(var(--workspace-max), 100%);
  min-height: 48px;
  margin: 0 auto 12px;
  border-bottom: 1px solid var(--line);
}

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

.brand h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0;
}

.brand span {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.top-actions,
.board-tools,
.section-head,
.button-row,
.nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 4px;
}

.mode-switch button {
  min-height: 28px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  padding: 0 10px;
}

.mode-switch button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.mode-switch button:disabled {
  filter: none;
  opacity: 0.42;
}

.section-head {
  justify-content: space-between;
  min-width: 0;
}

.section-head.spaced {
  margin-top: 18px;
  margin-bottom: 10px;
}

.status-pill {
  overflow: hidden;
  max-width: 100%;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  padding: 6px 11px;
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, var(--board-max)) minmax(380px, var(--rail-width));
  justify-content: center;
  gap: var(--workspace-gap);
  width: min(var(--workspace-max), 100%);
  margin: 0 auto;
  align-items: start;
  height: calc(100vh - 72px);
  overflow: hidden;
}

.board-column,
.side-column {
  min-width: 0;
  max-height: 100%;
  overflow: auto;
}

.library-panel {
  position: fixed;
  z-index: 40;
  inset: 0 auto 0 0;
  width: min(94vw, 380px);
  min-width: 0;
  padding: 18px;
  background: var(--bg);
  border-right: 1px solid var(--line);
  box-shadow: 18px 0 44px rgb(17 18 17 / 22%);
  transform: translateX(0);
  transition: transform 160ms ease;
}

.library-panel.collapsed {
  transform: translateX(-100%);
}

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

.board-area,
.side-column > .panel {
  border: 0;
  background: transparent;
  padding: 0;
}

.panel + .panel,
.board-area + .panel {
  margin-top: 12px;
}

.library-card {
  padding: 0;
  overflow: hidden;
}

.library-card > .section-head {
  padding: 14px 14px 10px;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 15px;
  font-weight: 800;
}

.filters {
  display: grid;
  gap: 10px;
  padding: 0 14px 14px;
  border-bottom: 1px solid var(--line);
}

.filter-grid,
.score-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.position-list {
  display: grid;
  max-height: calc(100vh - 250px);
  overflow: auto;
}

.position-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: start;
  gap: 10px;
  min-height: auto;
  border-width: 0 0 1px;
  border-color: var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  padding: 12px 14px;
  text-align: left;
}

.position-item:hover,
.position-item.active {
  background: var(--accent-soft);
}

.position-item.active {
  box-shadow: inset 4px 0 0 var(--accent);
}

.position-main {
  min-width: 0;
}

.position-title,
.position-meta {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.position-title {
  font-size: 13px;
  font-weight: 800;
}

.position-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.ratio-badge {
  border-radius: 999px;
  background: var(--soft);
  color: var(--warn);
  padding: 5px 8px;
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  font-weight: 800;
}

.board-area {
  padding: 0;
}

.board-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 6px;
}

.turn-block {
  min-width: 0;
}

.turn-block strong {
  display: block;
  overflow: hidden;
  font-size: 16px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.turn-block span {
  display: block;
  overflow: hidden;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board-tools {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.board-wrap {
  width: min(var(--board-max), 100%);
  margin: 0 auto;
}

#analysisBoard {
  position: relative;
  width: 100%;
  max-width: var(--board-max);
  touch-action: none;
}

#analysisBoard * {
  touch-action: none;
}

.piece-417db {
  transition: none !important;
}

body.board-dragging .square-55d63,
body.board-dragging .square-55d63:hover,
body.board-dragging .highlight1-32417,
body.board-dragging .highlight2-9c5d2 {
  box-shadow: none !important;
  outline: 0 !important;
}

.square-55d63 {
  position: relative;
}

.white-1e1d7 {
  background: var(--board-light) !important;
  color: var(--ink) !important;
}

.black-3c85d {
  background: var(--board-dark) !important;
  color: var(--white) !important;
}

.notation-322f9 {
  font-family: "JetBrains Mono", monospace !important;
  font-weight: 800 !important;
}

.square-55d63.last-move {
  box-shadow: inset 0 0 0 999px rgb(241 200 75 / 35%) !important;
}

.square-55d63.click-selected {
  box-shadow: inset 0 0 0 5px var(--accent) !important;
}

.board-arrow {
  position: absolute;
  inset: 0;
  z-index: 12;
  pointer-events: none;
  overflow: visible;
}

.board-arrow line {
  stroke: var(--accent);
  stroke-width: 12;
  stroke-linecap: round;
  opacity: 0.78;
}

.board-arrow polygon {
  fill: var(--accent);
  opacity: 0.78;
}

.under-board {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 10px;
}

.variation-line,
.variation-tree {
  display: block;
  line-height: 1.9;
  font-size: 14px;
}

.variation-line {
  min-height: 86px;
  max-height: min(24vh, 180px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--soft);
  padding: 8px 10px;
}

.variation-tree {
  min-height: 0;
  margin: 8px 0;
}

.variation-line .move-number,
.variation-line .variation-paren,
.variation-line .variation-ellipsis {
  color: var(--muted);
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  font-weight: 700;
}

.variation-line .variation-paren {
  display: inline;
  padding: 0 2px;
}

.variation-line button,
.variation-tree button {
  display: inline-flex;
  min-height: 0;
  margin: 0 2px 3px;
  border-color: transparent;
  background: transparent;
  color: var(--ink);
  padding: 2px 4px;
  font-size: 14px;
  font-weight: 650;
  line-height: 1.25;
}

.variation-line button:hover,
.variation-tree button:hover {
  background: var(--accent-soft);
  color: var(--accent);
  filter: none;
}

.variation-line button.active,
.variation-tree button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.variation-tree .branch-label {
  margin-right: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.variation-tree .branch-label-strong {
  color: var(--accent);
}

.variation-tree .branch-choices {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.variation-tree .branch-choices.choosing {
  border: 1px solid var(--accent);
  border-radius: 7px;
  background: var(--accent-soft);
  padding: 6px;
}

.variation-tree .branch-choice {
  min-height: 26px;
  border-color: var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 4px 8px;
  font-size: 12px;
}

.variation-tree .branch-choice.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.variation-tree .branch-choices.choosing .branch-choice.active {
  background: var(--accent);
  color: var(--white);
  box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--accent);
}

.variation-tree button {
  border-color: var(--line);
  background: var(--panel);
  font-size: 12px;
}

.move-browser {
  margin-top: 8px;
}

.analysis-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

#analysisPanel.explorer-open .analysis-main {
  grid-template-columns: minmax(0, 1fr);
}

.analysis-left {
  display: grid;
  gap: 8px;
  min-width: 0;
}

#analysisPanel.explorer-open .analysis-left {
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas:
    "engines"
    "explorer"
    "moves";
  align-items: start;
  gap: 8px;
}

#analysisPanel.explorer-open .engine-results {
  grid-area: engines;
}

#analysisPanel.explorer-open .explorer-drawer {
  grid-area: explorer;
}

#analysisPanel.explorer-open .move-browser {
  grid-area: moves;
}

.move-actions {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) repeat(3, 34px);
  gap: 8px;
  width: min(100%, 310px);
}

.move-actions select {
  height: 34px;
  padding-top: 0;
  padding-bottom: 0;
}

.move-stack {
  position: relative;
}

.explorer-drawer {
  display: none;
  position: relative;
  min-height: 270px;
  max-height: min(46vh, 360px);
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--ink);
  overflow: hidden;
}

#analysisPanel.explorer-open .explorer-drawer {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
}

.explorer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  border-bottom: 1px solid var(--line);
  background: var(--soft);
  padding: 6px;
}

.explorer-head-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.explorer-tabs {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  padding: 3px;
}

.explorer-tabs button {
  min-height: 28px;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  padding: 0 9px;
  font-size: 12px;
  font-weight: 750;
}

.explorer-tabs button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.explorer-status {
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 7px 8px;
}

.explorer-content {
  min-height: 0;
  overflow: auto;
  padding-bottom: 6px;
}

.explorer-settings {
  display: none;
  position: absolute;
  z-index: 11;
  top: 45px;
  right: 8px;
  left: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  box-shadow: 0 12px 30px rgb(17 18 17 / 18%);
  padding: 12px;
}

.explorer-drawer.settings-open .explorer-settings {
  display: grid;
}

.explorer-settings .field {
  gap: 4px;
}

.explorer-settings input,
.explorer-settings select {
  min-height: 32px;
  padding: 5px 7px;
  border-color: var(--line);
  background: var(--panel);
  color: var(--ink);
  font-size: 12px;
}

.explorer-segments {
  display: flex;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--soft);
}

.explorer-segments label {
  flex: 1;
  min-width: 0;
}

.explorer-segments input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.explorer-segments span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border-right: 1px solid var(--line);
  color: var(--muted);
  padding: 0 8px;
  font-size: 12px;
  font-weight: 750;
  cursor: pointer;
}

.explorer-segments label:last-child span {
  border-right: 0;
}

.explorer-segments input:checked + span {
  background: var(--accent);
  color: var(--white);
}

.explorer-segments svg {
  width: 15px;
  height: 15px;
}

.explorer-segments.ratings {
  grid-column: 1 / -1;
  flex-wrap: wrap;
}

.explorer-segments.ratings label {
  flex: 0 0 auto;
}

.explorer-segments.ratings span {
  min-width: 54px;
}

.explorer-drawer[data-source="masters"] .explorer-lichess-setting {
  display: none;
}

.explorer-table {
  display: grid;
  gap: 0;
}

.explorer-row {
  display: grid;
  grid-template-columns: minmax(42px, 64px) 48px 58px minmax(116px, 1fr);
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 32px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  padding: 5px 8px;
  text-align: left;
}

.explorer-row:hover {
  background: var(--accent-soft);
  filter: none;
}

.explorer-row strong,
.explorer-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.explorer-row strong {
  color: var(--ink);
}

.explorer-share,
.explorer-count,
.explorer-result {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-align: right;
}

.explorer-result {
  overflow-wrap: anywhere;
  white-space: normal !important;
}

.explorer-bar {
  display: grid;
  grid-template-columns: var(--w, 0%) var(--d, 0%) 1fr;
  height: 18px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--soft);
}

.explorer-bar i {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  font-style: normal;
}

.explorer-bar i:nth-child(1) {
  background: #f2f1ea;
  color: #1c1d1a;
}

.explorer-bar i:nth-child(2) {
  background: #a7aca2;
  color: #101110;
}

.explorer-bar i:nth-child(3) {
  background: #30332f;
  color: #f2f4ef;
}

.explorer-bar i span {
  overflow: hidden;
  max-width: 100%;
  padding: 0 4px;
  font-size: 11px;
  font-weight: 800;
  line-height: 18px;
  text-overflow: clip;
}

.explorer-bar i.hidden-label span {
  display: none;
}

.explorer-total-row {
  border-top: 1px solid var(--line);
  background: var(--soft) !important;
}

.panel-tabs {
  display: none;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.panel-tabs button {
  border-color: var(--line);
  background: var(--panel);
  color: var(--ink);
}

.panel-tabs button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.review-context {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--soft);
  color: var(--muted);
  padding: 10px;
  margin-bottom: 14px;
  font-size: 13px;
  font-weight: 700;
}

.panel-page {
  display: none;
}

.panel-page.active {
  display: block;
}

#analysisPanel.active {
  display: grid;
  gap: 8px;
}

.field-stack {
  display: grid;
  gap: 10px;
}

.field {
  display: grid;
  gap: 6px;
}

.field > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.field.spaced {
  margin-top: 16px;
}

.policy-list,
.history-list,
.engine-results {
  display: grid;
  gap: 9px;
}

.engine-results {
  grid-template-columns: 1fr;
  align-items: stretch;
  gap: 8px;
  min-height: 0;
}

.hidden-box,
.empty-state {
  min-height: 64px;
  border: 1px dashed var(--line);
  border-radius: 7px;
  color: var(--muted);
  padding: 12px;
  font-size: 13px;
  font-weight: 600;
}

.played-reveal,
.value-reveal,
.history-item {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--soft);
  padding: 10px;
  font-size: 13px;
}

.engine-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: none;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--soft);
  padding: 9px;
  font-size: 13px;
}

.engine-lines {
  overflow: auto;
  min-height: 0;
  padding-right: 4px;
}

.engine-card.lc0 .engine-lines {
  max-height: 190px;
}

.engine-card.stockfish .engine-lines {
  max-height: 190px;
}

#analysisPanel.explorer-open .engine-card.lc0 .engine-lines {
  max-height: 190px;
}

#analysisPanel.explorer-open .engine-card.stockfish .engine-lines {
  max-height: 190px;
}

#analysisPanel.explorer-open .engine-card {
  padding: 8px;
}

#analysisPanel.explorer-open .policy-row {
  grid-template-columns: minmax(48px, 68px) minmax(38px, 1fr) 42px;
  gap: 5px;
}

#analysisPanel.explorer-open .engine-line {
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 6px;
}

#analysisPanel.explorer-open .engine-line.has-toggle {
  grid-template-columns: 58px minmax(0, 1fr) 28px;
}

.policy-row {
  display: grid;
  grid-template-columns: minmax(54px, 82px) minmax(70px, 1fr) 48px;
  align-items: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 3px 5px;
  font-size: 12px;
  cursor: pointer;
}

.policy-row strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.policy-row.played-policy {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.policy-row:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.policy-scroll {
  max-height: 260px;
  overflow: auto;
  padding-right: 4px;
}

.review-policy-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

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

.metric-chip span,
.metadata-card span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.metric-chip strong {
  display: block;
  overflow: hidden;
  margin-top: 3px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metadata-card {
  color: var(--muted);
  line-height: 1.45;
}

.metadata-card strong {
  display: block;
  color: var(--ink);
}

.policy-bar {
  height: 10px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.policy-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--warn);
}

.score-row,
.outcome-grid,
.analysis-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.analysis-controls {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 0;
}

.engine-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
}

.engine-toggle {
  display: inline-flex;
}

.engine-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.engine-toggle span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
}

.engine-toggle input:checked + span {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.analysis-controls.running .engine-toggle input:checked + span {
  animation: enginePulse 900ms ease-in-out infinite alternate;
}

@keyframes enginePulse {
  from {
    box-shadow: inset 0 0 0 1px transparent;
  }
  to {
    box-shadow: inset 0 0 0 1px var(--accent);
  }
}

.engine-toggle svg {
  width: 17px;
  height: 17px;
}

.engine-settings {
  display: none;
  position: absolute;
  z-index: 12;
  top: calc(100% + 6px);
  right: 0;
  grid-template-columns: 100px 100px;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  box-shadow: 0 10px 28px rgb(17 18 17 / 16%);
  padding: 8px;
}

.analysis-controls.settings-open .engine-settings {
  display: grid;
}

.engine-settings input {
  min-height: 32px;
  padding: 5px 7px;
  font-size: 12px;
}

.outcome-grid button {
  width: 100%;
}

.button-row {
  flex-wrap: wrap;
  margin-top: 10px;
}

.button-row.inline-actions {
  margin-top: 0;
}

.history-item strong {
  text-transform: capitalize;
}

.history-item p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.engine-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.engine-card header strong {
  text-transform: capitalize;
}

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

.engine-card-head {
  display: grid !important;
  grid-template-columns: minmax(62px, 1fr) auto auto;
}

.engine-eval {
  color: var(--ink) !important;
  font-family: "JetBrains Mono", monospace;
  font-size: 24px !important;
  font-weight: 850 !important;
  line-height: 1;
}

.engine-eval.muted {
  color: var(--muted) !important;
  font-size: 14px !important;
}

.engine-card-head small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  white-space: nowrap;
}

.engine-line {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 8px;
  border: 1px solid transparent;
  border-top-color: var(--line);
  border-radius: 7px;
  padding: 6px;
  font-size: 12px;
  cursor: pointer;
}

.engine-line.has-toggle {
  grid-template-columns: 58px minmax(0, 1fr) 28px;
}

.engine-line + .engine-line {
  margin-top: 5px;
}

.engine-line:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.engine-line-text {
  display: -webkit-box;
  overflow: hidden;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.engine-line.expanded .engine-line-text,
.engine-line:not(.has-toggle) .engine-line-text {
  display: block;
  -webkit-line-clamp: unset;
}

.engine-line-expand {
  width: 28px !important;
  min-width: 28px !important;
  height: 28px;
  min-height: 28px;
  align-self: start;
}

.engine-line b {
  margin-right: 6px;
  font-family: "JetBrains Mono", monospace;
}

.analysis-tools {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.analysis-tools summary {
  width: max-content;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  padding: 7px 9px;
}

.switch.compact {
  justify-content: flex-start;
}

.switch .label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  color: var(--ink);
  font-size: 13px;
  font-weight: 750;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.knob {
  position: relative;
  flex: 0 0 auto;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: var(--line);
}

.knob::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--panel);
  transition: transform 140ms ease;
}

.switch input:checked + .knob {
  background: var(--accent);
}

.switch input:checked + .knob::after {
  transform: translateX(16px);
}

body.board-dragging {
  user-select: none;
}

@media (min-width: 1600px) {
  :root {
    --board-max: clamp(600px, calc(600px + (100vw - 1600px) * 0.375), 720px);
    --rail-width: clamp(520px, calc(520px + (100vw - 1600px) * 0.325), 624px);
    --workspace-gap: clamp(16px, calc(16px + (100vw - 1600px) * 0.01), 19.2px);
  }
}

@media (max-width: 1080px) {
  .workspace {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }

  .board-column,
  .side-column {
    max-height: none;
    overflow: visible;
  }
}

@media (max-width: 900px) {
  .app {
    padding: 12px;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .position-list {
    max-height: 360px;
  }

  .engine-results {
    grid-template-columns: 1fr;
  }

  .engine-card {
    max-height: 420px;
  }

  .engine-results {
    grid-template-columns: 1fr;
  }

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

  #analysisPanel.explorer-open .analysis-left {
    grid-template-columns: 1fr;
    grid-template-areas:
      "engines"
      "explorer"
      "moves";
  }

  .review-policy-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .board-head,
  .under-board {
    align-items: stretch;
    flex-direction: column;
  }

  .board-tools,
  .nav {
    justify-content: flex-start;
  }

  .move-browser .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .move-actions {
    width: 100%;
  }

  .explorer-drawer {
    position: static;
    min-height: 300px;
    max-height: none;
    margin-top: 8px;
    box-shadow: none;
  }

  #analysisPanel.explorer-open .analysis-main {
    grid-template-columns: 1fr;
  }

  .explorer-settings {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .filter-grid,
  .score-row,
  .outcome-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .brand {
    flex-wrap: wrap;
  }

  .mode-switch {
    width: 100%;
  }

  .explorer-settings {
    grid-template-columns: 1fr;
  }

  .review-policy-summary {
    grid-template-columns: 1fr;
  }
}
