:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #657084;
  --page: #f4f5f7;
  --panel: #ffffff;
  --line: #d8dde6;
  --line-strong: #aeb7c5;
  --red: #c91624;
  --red-dark: #7e0d16;
  --yellow: #e0a800;
  --yellow-dark: #8a6500;
  --blue: #91c9ec;
  --blue-dark: #2e6f9d;
  --blue-light: #e1f1fb;
  --green: #267a4b;
  --shadow: 0 14px 34px rgba(23, 32, 51, 0.1);
  --header-bg: #1a2232;
  --surface-2: #f6f7f9;
  --surface-hover: #f0f2f5;
  --button-bg: #ffffff;
  --text-soft: #3c4657;
  --text-list: #525e70;
  --text-faint: #8a94a3;
  --frame-bg: #edf6fc;
  --col-label: #526077;
  --grid-line: rgba(35, 91, 132, 0.72);
  --grid-center: #285f87;
  --ok-text: #267a4b;
  --ok-bg: #e8f5ec;
  --ok-line: #b9ddc5;
  --end-bg: #fdebed;
  --end-line: #efb5bb;
  --engine-line: #bad2e7;
  --warn-text: #8a5a00;
  --warn-bg: #fff6df;
  --warn-line: #ecd193;
  --score-bg: #f7fafc;
  --score-on-line: #9ac2df;
  --score-on-bg: #eaf5fd;
  --danger-bg: #fff5f5;
  --yellow-text: #b88600;
  --link: #2467a6;
  --dot-ring: #e6f3eb;
  --cache-a: #e9edf2;
  --cache-b: #ffffff;
  --cache-line: #6c7b8c;
  --win-ring: #173b55;
  --win-outline: #ffffff;
  --backdrop: rgba(18, 33, 49, 0.58);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #e6eaf2;
  --muted: #9aa5b8;
  --page: #0f141c;
  --panel: #171e29;
  --line: #2a3443;
  --line-strong: #3d4a5e;
  --red: #e0414d;
  --red-dark: #ff7a84;
  --yellow: #f2bd1d;
  --yellow-dark: #8a6500;
  --blue: #1f3c56;
  --blue-dark: #4f8fc0;
  --blue-light: #16283a;
  --green: #4cc27f;
  --shadow: 0 14px 34px rgba(0, 0, 0, 0.45);
  --header-bg: #0a0e14;
  --surface-2: #1d2532;
  --surface-hover: #222c3b;
  --button-bg: #1d2532;
  --text-soft: #c7cfdc;
  --text-list: #b4bdcc;
  --text-faint: #6f7a8b;
  --frame-bg: #121b26;
  --col-label: #8ea0b8;
  --grid-line: rgba(140, 185, 220, 0.42);
  --grid-center: #8cb9dc;
  --ok-text: #6fd79c;
  --ok-bg: #12291c;
  --ok-line: #24553a;
  --end-bg: #2e1418;
  --end-line: #6a2a31;
  --engine-line: #26425c;
  --warn-text: #f1c766;
  --warn-bg: #2c2410;
  --warn-line: #5c4a1c;
  --score-bg: #1a2230;
  --score-on-line: #33597a;
  --score-on-bg: #16293b;
  --danger-bg: #2e1418;
  --yellow-text: #f2bd1d;
  --link: #7cb8ec;
  --dot-ring: #173523;
  --cache-a: #2a3443;
  --cache-b: #1d2532;
  --cache-line: #7d8a9c;
  --win-ring: #e6eaf2;
  --win-outline: #0f141c;
  --backdrop: rgba(0, 0, 0, 0.7);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  transition: background-color 0.2s ease, color 0.2s ease;
  margin: 0;
  color: var(--ink);
  background: var(--page);
  font-family: "Segoe UI", Arial, sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.62;
}

[hidden] {
  display: none !important;
}

.site-header {
  color: #fff;
  background: var(--header-bg);
  border-bottom: 4px solid var(--red);
}

.header-inner {
  width: min(1120px, calc(100% - 32px));
  min-height: 74px;
  margin: 0 auto;
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 24px;
}

.brand-lockup {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 11px;
  color: inherit;
  text-decoration: none;
}

.brand-lockup img {
  flex: 0 0 auto;
}

.brand-lockup span {
  min-width: 0;
  display: grid;
}

.brand-lockup strong {
  font-size: 1.25rem;
}

.brand-lockup small {
  margin-top: 2px;
  color: #b9c3d4;
  font-size: 0.76rem;
  font-weight: 700;
}

.tabs {
  display: flex;
  align-items: stretch;
}

.tab {
  min-width: 96px;
  border: 0;
  border-bottom: 4px solid transparent;
  padding: 0 18px;
  color: #cbd4e1;
  background: transparent;
  font-weight: 800;
}

.tab:hover,
.tab.active {
  color: #fff;
  background: rgba(255, 255, 255, 0.07);
}

.tab.active {
  border-bottom-color: var(--yellow);
}

.tab-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
}

.tab-icon {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}


.tab:focus-visible,
.action-button:focus-visible,
.point:focus-visible,
.toggle-row:focus-within {
  outline: 3px solid rgba(36, 103, 166, 0.32);
  outline-offset: 2px;
}

.game-view,
.help-view {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 760px) minmax(260px, 320px);
  gap: 20px;
  align-items: start;
  justify-content: center;
}

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

.board-tool {
  min-width: 0;
  overflow: hidden;
}

.solver-strip {
  min-height: 64px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
}

.turn-block {
  display: flex;
  align-items: center;
  gap: 10px;
}

.turn-block span:last-child {
  display: grid;
}

.turn-block small {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.turn-block strong {
  font-size: 1.05rem;
}

.turn-stone,
.player-key {
  flex: 0 0 auto;
  display: inline-block;
  border-radius: 50%;
}

.turn-stone {
  width: 28px;
  height: 28px;
}

.player-key {
  width: 18px;
  height: 18px;
}

.turn-stone.black,
.stone.black,
.red-key {
  background: radial-gradient(circle at 34% 28%, #e33a45, var(--red) 48%, var(--red-dark) 100%);
  border: 2px solid #650810;
}

.turn-stone.white,
.stone.white,
.yellow-key {
  background: radial-gradient(circle at 34% 28%, #ffd84a, var(--yellow) 54%, var(--yellow-dark) 100%);
  border: 2px solid #705000;
}

.solver-status {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.status-pill,
.engine-label {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  border-radius: 5px;
  padding: 0 10px;
  font-size: 0.76rem;
  font-weight: 800;
}

.status-pill {
  color: var(--ok-text);
  background: var(--ok-bg);
  border: 1px solid var(--ok-line);
}

.status-pill.finished {
  color: var(--red-dark);
  background: var(--end-bg);
  border-color: var(--end-line);
}

.engine-label {
  color: var(--blue-dark);
  background: var(--blue-light);
  border: 1px solid var(--engine-line);
}

.board-frame {
  padding: 14px 16px 16px;
  background: var(--frame-bg);
}

.column-labels {
  padding: 0 12px 5px;
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  color: var(--col-label);
  font-size: 0.72rem;
  font-weight: 800;
  text-align: center;
}

.c5-board {
  width: 100%;
  aspect-ratio: 9 / 7;
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  grid-template-rows: repeat(7, minmax(0, 1fr));
  padding: 12px;
  background: var(--blue);
  border: 2px solid var(--blue-dark);
  border-radius: 6px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.55);
}

.point {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  border: 0;
  padding: 0;
  background: transparent;
}

.point:disabled {
  cursor: default;
  opacity: 1;
}

.point::before,
.point::after {
  content: "";
  position: absolute;
  z-index: 0;
  background: var(--grid-line);
}

.point::before {
  left: 0;
  right: 0;
  top: calc(50% - 0.5px);
  height: 1px;
}

.point::after {
  top: 0;
  bottom: 0;
  left: calc(50% - 0.5px);
  width: 1px;
}

.point.edge-left::before {
  left: 50%;
}

.point.edge-right::before {
  right: 50%;
}

.point.edge-top::after {
  top: 50%;
}

.point.edge-bottom::after {
  bottom: 50%;
}

.point.center::before,
.point.center::after {
  background: var(--grid-center);
}

.stone {
  width: 76%;
  height: 76%;
  z-index: 2;
  border-radius: 50%;
  box-shadow: 0 3px 7px rgba(17, 50, 73, 0.4);
}

.stone.winning {
  outline: 4px solid var(--win-outline);
  outline-offset: 2px;
  box-shadow: 0 0 0 6px var(--win-ring);
}

.board-actions {
  padding: 14px 16px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  border-top: 1px solid var(--line);
}

.column-guide {
  display: grid;
  gap: 8px;
  padding: 12px 16px 0;
}

.column-guide h2 {
  margin: 0;
  font-size: 0.78rem;
}

.column-guide .section-heading > span {
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 700;
}

.column-guide__scores {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 5px;
}

.column-score {
  display: grid;
  gap: 1px;
  justify-items: center;
  padding: 5px 1px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--score-bg);
  color: var(--muted);
  line-height: 1.1;
}

.column-score b {
  font-size: 0.68rem;
}

.column-score small {
  font-size: 0.64rem;
  font-weight: 800;
}

.column-score.scored {
  border-color: var(--score-on-line);
  background: var(--score-on-bg);
  color: var(--blue-dark);
}

.column-score.unavailable {
  opacity: 0.45;
}

.action-button {
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  padding: 0 12px;
  color: var(--ink);
  background: var(--button-bg);
  font-weight: 800;
}

.action-button:hover {
  background: var(--surface-hover);
}

.action-button.primary {
  color: #fff;
  background: var(--red);
  border-color: var(--red-dark);
}

.action-button.primary:hover {
  background: var(--red-dark);
}

.control-panel {
  display: grid;
  overflow: hidden;
}

.panel-section {
  padding: 17px;
  display: grid;
  gap: 13px;
  border-bottom: 1px solid var(--line);
}

.panel-section:last-child {
  border-bottom: 0;
}

.panel-section h2 {
  margin: 0;
  font-size: 0.95rem;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.clear-cache-button {
  padding: 4px 7px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  color: var(--muted);
  background: var(--button-bg);
  font-size: 0.72rem;
  font-weight: 800;
}

.clear-cache-button:hover {
  color: var(--red-dark);
  border-color: var(--red);
  background: var(--danger-bg);
}

.welcome-dialog {
  width: min(440px, calc(100% - 32px));
  padding: 0;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  background: var(--panel);
  box-shadow: 0 24px 60px rgba(17, 35, 55, 0.35);
}

.welcome-dialog::backdrop {
  background: var(--backdrop);
}

.welcome-dialog__content {
  display: grid;
  gap: 16px;
  padding: 26px;
}

.welcome-dialog h2,
.welcome-dialog p {
  margin: 0;
}

.welcome-dialog h2 {
  font-size: 1.25rem;
}

.welcome-dialog p {
  color: var(--muted);
  line-height: 1.55;
}

.welcome-dialog .action-button {
  justify-self: end;
  min-width: 96px;
}

.live-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px var(--dot-ring);
}

.toggle-row {
  min-height: 38px;
  display: grid;
  grid-template-columns: 20px 18px 1fr;
  align-items: center;
  gap: 9px;
  color: var(--text-soft);
  font-size: 0.88rem;
  font-weight: 700;
}

.toggle-row input {
  width: 19px;
  height: 19px;
  margin: 0;
  accent-color: var(--red);
}

.strength-section {
  gap: 11px;
}

.strength-section output {
  color: var(--red-dark);
  font-size: 0.76rem;
  font-weight: 800;
}

.strength-slider {
  width: 100%;
  margin: 1px 0;
  accent-color: var(--red);
}

.strength-scale {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  color: var(--muted);
  font-size: 0.66rem;
  font-weight: 700;
  line-height: 1.35;
}

.strength-scale span:not(:first-child):not(:last-child) {
  text-align: center;
}

.strength-scale span:last-child {
  text-align: right;
}

.cache-key {
  width: 15px;
  height: 15px;
  border: 2px solid var(--cache-line);
  border-radius: 3px;
  background: linear-gradient(135deg, var(--cache-a) 25%, var(--cache-b) 25%, var(--cache-b) 50%, var(--cache-a) 50%, var(--cache-a) 75%, var(--cache-b) 75%);
  background-size: 6px 6px;
}

.metrics {
  margin: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.metrics div {
  padding: 10px 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 5px;
}

.metrics dt {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.metrics dd {
  margin: 2px 0 0;
  font-size: 1.25rem;
  font-weight: 850;
}

.prediction-metrics {
  grid-template-columns: repeat(3, 1fr);
}

.prediction-metrics .draw-metric dd {
  color: var(--muted);
}

.prediction-metrics div:first-child dd {
  color: var(--red-dark);
}

.prediction-metrics div:last-child dd {
  color: var(--yellow-text);
}

.prediction-note {
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.35;
}

.move-panel {
  min-height: 0;
}

.move-list {
  height: 1.8em;
  min-height: 1.8em;
  max-height: 1.8em;
  overflow-x: hidden;
  overflow-y: auto;
  margin: 0;
  padding-left: 25px;
  color: var(--text-list);
  line-height: 1.65;
  white-space: nowrap;
}

.move-list:empty::before {
  content: "No moves yet";
  display: block;
  margin-left: -25px;
  color: var(--text-faint);
  font-size: 0.84rem;
}

.move-list li::marker {
  color: var(--red);
  font-weight: 800;
}

.help-view {
  max-width: 960px;
}

.help-header {
  padding: 8px 0 24px;
  border-bottom: 1px solid var(--line);
}

.kicker {
  margin: 0 0 6px;
  color: var(--red);
  font-size: 0.78rem;
  font-weight: 850;
  text-transform: uppercase;
}

.help-header h1 {
  margin: 0;
  font-size: 2rem;
}

.help-header p:last-child {
  margin: 8px 0 0;
  color: var(--muted);
}

.help-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
}

.help-grid section {
  position: relative;
  min-height: 170px;
  padding: 24px 24px 24px 58px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.help-grid section:nth-child(2n) {
  border-right: 0;
}

.help-grid section:nth-last-child(-n + 2) {
  border-bottom: 0;
}

.step-number {
  position: absolute;
  top: 24px;
  left: 18px;
  width: 27px;
  height: 27px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--red);
  font-size: 0.82rem;
  font-weight: 850;
}

.help-grid h2,
.help-notes h2 {
  margin: 0;
  font-size: 1rem;
}

.help-grid p,
.help-notes p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.58;
}

.help-notes {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 22px;
  padding: 26px 0;
}

/* Server-status variant of the engine label */
.engine-label.warn {
  color: var(--warn-text);
  background: var(--warn-bg);
  border-color: var(--warn-line);
}

.header-tools {
  display: flex;
  align-items: stretch;
  gap: 6px;
}

.theme-toggle {
  align-self: center;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  padding: 0;
  color: #e6eaf2;
  background: rgba(255, 255, 255, 0.06);
}

.theme-toggle:hover {
  background: rgba(255, 255, 255, 0.14);
}

.theme-toggle:focus-visible {
  outline: 3px solid rgba(124, 184, 236, 0.6);
  outline-offset: 2px;
}

.theme-toggle svg {
  width: 20px;
  height: 20px;
}

.theme-toggle .icon-sun,
:root[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}

:root[data-theme="dark"] .theme-toggle .icon-sun {
  display: block;
}

.welcome-dialog a {
  color: var(--link);
  font-weight: 700;
}

:root[data-theme="dark"] .point.center::before,
:root[data-theme="dark"] .point.center::after {
  opacity: 0.8;
}

:root[data-theme="dark"] .welcome-dialog {
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
  border: 1px solid var(--line);
}

@media (max-width: 880px) {
  .workspace {
    grid-template-columns: 1fr;
  }

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

  .move-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 620px) {
  .header-inner {
    width: calc(100% - 20px);
    min-height: 66px;
    gap: 8px;
  }

  .brand-lockup img {
    width: 36px;
    height: 36px;
  }

  .brand-lockup strong {
    font-size: 1rem;
  }

  .brand-lockup small {
    display: none;
  }

  .theme-toggle {
    width: 36px;
    height: 36px;
  }

  .tab-icon {
    display: none;
  }

  .brand-lockup {
    gap: 8px;
  }

  .brand-lockup strong {
    line-height: 1.15;
  }

  .tabs .tab {
    white-space: nowrap;
  }

  .tab {
    min-width: 0;
    padding: 0 9px;
    font-size: 0.82rem;
  }

  .game-view,
  .help-view {
    width: calc(100% - 20px);
    padding-top: 14px;
  }

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

  .solver-status {
    justify-content: flex-start;
  }

  .board-frame {
    padding: 10px 8px 9px;
  }

  .column-labels {
    padding-right: 9px;
    padding-left: 9px;
  }

  .c5-board {
    padding: 8px;
  }

  .board-actions {
    grid-template-columns: 1fr;
  }

  .control-panel {
    grid-template-columns: 1fr;
  }

  .move-panel {
    grid-column: auto;
  }

  .help-header h1 {
    font-size: 1.65rem;
  }

  .help-grid,
  .help-notes {
    grid-template-columns: 1fr;
  }

  .help-grid section,
  .help-grid section:nth-child(2n),
  .help-grid section:nth-last-child(-n + 2) {
    min-height: 0;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 380px) {
  .brand-lockup strong {
    font-size: 0.9rem;
  }

  .brand-lockup img {
    width: 30px;
    height: 30px;
  }

  .tab {
    padding: 0 7px;
    font-size: 0.78rem;
  }

  .theme-toggle {
    width: 34px;
    height: 34px;
  }
}

@media (max-width: 340px) {
  .brand-lockup img {
    display: none;
  }
}
