:root {
  color-scheme: dark;
  font-family: Inter, Arial, sans-serif;
  background: #1a1d23;
  color: #e6ebf2;
  --shell-padding: 24px;
  --control-panel-width: 220px;
  --eval-rail-width: 72px;
  --board-gap: 14px;
  --board-max-width: 980px;
  --board-balance-width: calc(var(--control-panel-width) - var(--eval-rail-width) - var(--board-gap));
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: #1a1d23;
}

body {
  min-height: 100vh;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: auto auto auto;
  column-gap: var(--board-gap);
  row-gap: 24px;
  align-items: center;
  justify-content: center;
  padding: var(--shell-padding);
}

.app-shell::before {
  content: '';
  display: block;
  width: var(--board-balance-width);
}

.board-section {
  min-width: 0;
  width: min(
    calc(var(--eval-rail-width) + var(--board-gap) + var(--board-max-width)),
    calc(100vw - (2 * var(--shell-padding)) - var(--board-balance-width) - (2 * var(--board-gap)) - var(--control-panel-width))
  );
}

.board-area {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: var(--board-gap);
  width: 100%;
}

.eval-rail {
  flex: 0 0 var(--eval-rail-width);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  align-self: flex-start;
}

.eval-rail.is-hidden {
  visibility: hidden;
  pointer-events: none;
}

.eval-bar {
  position: relative;
  flex: none;
  width: 28px;
  border: 0;
  border-radius: 6px;
  overflow: hidden;
  background: #0b0f17;
}

.eval-fill {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 50%;
  background: #e6ebf2;
  transition: height 220ms ease;
}

.eval-label {
  position: absolute;
  z-index: 1;
  left: 0;
  width: 100%;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  text-align: center;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  pointer-events: none;
}

.eval-bar[data-leading='white'] .eval-label {
  top: 8px;
  color: #0b0f17;
}

.eval-bar[data-leading='black'] .eval-label {
  bottom: 8px;
  color: #e6ebf2;
}

.eval-bar[data-leading='even'] .eval-label {
  bottom: 8px;
  color: #e6ebf2;
}

.board-stack {
  flex: 1 1 auto;
  min-width: 0;
  max-width: min(100%, 980px);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.board-frame {
  width: 100%;
  min-width: 0;
}

.board-svg {
  display: block;
  width: 100%;
  height: auto;
  max-height: calc(88vh - 30px);
}

.board-svg [tabindex]:focus {
  outline: none;
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  align-self: stretch;
  justify-content: center;
  width: var(--control-panel-width);
}

.control-group,
.status-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.search-settings {
  gap: 10px;
  margin-top: 20px;
}

.setting-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.setting-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.setting-label {
  color: #aeb7c7;
  font-size: 13px;
  line-height: 1.2;
  padding-left: 6px;
}

.toggle-switch {
  position: relative;
  flex: 0 0 auto;
  width: 34px;
  height: 20px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: #e7ebf2;
  cursor: pointer;
  transition: background 160ms ease, opacity 160ms ease;
}

.toggle-switch:hover:not(:disabled),
.toggle-switch:focus-visible:not(:disabled) {
  outline: none;
  background: #f1f4f9;
}

.toggle-switch[aria-pressed='true'] {
  background: #4bc96a;
}

.toggle-switch[aria-pressed='true']:hover:not(:disabled),
.toggle-switch[aria-pressed='true']:focus-visible:not(:disabled) {
  background: #56d374;
}

.toggle-switch:disabled {
  opacity: 0.45;
  cursor: default;
}

.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 2px 8px rgba(11, 15, 23, 0.24);
  transition: transform 160ms ease;
}

.toggle-switch[aria-pressed='true'] .toggle-thumb {
  transform: translateX(14px);
}

.setting-input {
  appearance: textfield;
  width: 100%;
  border: 1px solid #505b73;
  border-radius: 6px;
  background: #333b4a;
  color: #e6ebf2;
  padding: 10px 12px;
  font: inherit;
  text-align: center;
  outline: none;
  transition: background 140ms ease, border-color 140ms ease;
}

.setting-input:hover,
.setting-input:focus-visible {
  background: #3b4557;
  border-color: #5f6d87;
}

.setting-input.is-inactive:not(:disabled) {
  opacity: 0.55;
}

.setting-input.is-inactive:not(:disabled):hover,
.setting-input.is-inactive:not(:disabled):focus-visible {
  opacity: 0.8;
}

.setting-input:disabled {
  opacity: 0.45;
  cursor: default;
}

.setting-input::-webkit-outer-spin-button,
.setting-input::-webkit-inner-spin-button {
  margin: 0;
}

.control-button {
  appearance: none;
  border: 1px solid #505b73;
  border-radius: 6px;
  background: #333b4a;
  color: #e6ebf2;
  padding: 12px 14px;
  font: inherit;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease;
}

.control-button:hover:not(:disabled),
.control-button:focus-visible:not(:disabled) {
  background: #3b4557;
  border-color: #5f6d87;
  outline: none;
}

.control-button[aria-pressed='true'] {
  background: #3b4557;
  border-color: #5f6d87;
  color: #e6ebf2;
}

.control-button[aria-pressed='true']:hover:not(:disabled),
.control-button[aria-pressed='true']:focus-visible:not(:disabled) {
  background: #444f63;
  border-color: #6a7893;
  color: #e6ebf2;
}

.control-button:disabled {
  opacity: 0.45;
  cursor: default;
}

.control-button[data-action='toggle-side'] {
  margin-top: 20px;
}

.position-editor {
  display: flex;
  align-items: center;
  gap: 8px;
}

.position-editor[hidden] {
  display: none !important;
}

.fen-label {
  flex: 0 0 auto;
  color: #aeb7c7;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.fen-input {
  appearance: none;
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  border: 1px solid #505b73;
  border-radius: 6px;
  background: #222733;
  color: #e6ebf2;
  padding: 10px 12px;
  font: inherit;
  font-size: 12px;
  line-height: 1.3;
  outline: none;
  transition: background 140ms ease, border-color 140ms ease;
}

.fen-input:hover,
.fen-input:focus-visible {
  background: #293140;
  border-color: #5f6d87;
}

.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;
}

.status-panel {
  align-items: center;
  justify-content: flex-start;
  height: 1.35em;
}

.search-info-text {
  margin: 0;
  color: #aeb7c7;
  font-size: 14px;
  line-height: 1.3;
  text-align: center;
}

.debug-panel {
  width: 100%;
  height: 112px;
  border: 1px solid #505b73;
  border-radius: 6px;
  background: #333b4a;
  padding: 10px 8px;
  transition: background 140ms ease, border-color 140ms ease, opacity 140ms ease;
}

.debug-setting {
  margin-top: 28px;
}

.debug-table {
  width: 100%;
  height: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  color: #aeb7c7;
  font-size: 13px;
  line-height: 1;
}

.debug-table th,
.debug-table td {
  padding: 0;
  vertical-align: middle;
}

.debug-table th {
  color: #aeb7c7;
  font-weight: 400;
  text-align: left;
  white-space: nowrap;
  width: 42%;
}

.debug-table td {
  color: #e6ebf2;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
  width: 58%;
}

.debug-panel[hidden] {
  display: block !important;
  visibility: hidden;
  pointer-events: none;
}

.notice-text {
  margin: 0;
  line-height: 1.35;
}

.notice-text {
  color: #aeb7c7;
  min-height: 1.35em;
  text-align: center;
  white-space: pre-line;
}

.notice-text[hidden] {
  display: none !important;
}

.thinking-dots {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
  height: 12px;
}

.thinking-dots[hidden] {
  display: inline-flex !important;
  visibility: hidden;
  pointer-events: none;
}

.thinking-dots span {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #e6ebf2;
  animation: pulse 1s infinite ease-in-out;
}

.board-thinking-dots {
  height: 18px;
  margin-top: 12px;
  gap: 9px;
}

.thinking-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.thinking-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes pulse {
  0%,
  80%,
  100% {
    opacity: 0.28;
    transform: scale(0.8);
  }

  40% {
    opacity: 1;
    transform: scale(1);
  }
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    row-gap: 20px;
    column-gap: 0;
    padding: 18px;
  }

  .app-shell::before {
    content: none;
  }

  .board-section {
    width: 100%;
  }

  .control-panel {
    max-width: 640px;
    width: 100%;
    justify-self: center;
  }
}
