:root {
  color-scheme: dark;
  --bg: #151817;
  --surface: #202523;
  --surface-2: #2a302d;
  --line: #3d4641;
  --text: #f4f0e7;
  --muted: #aeb7b1;
  --board: #d7a85e;
  --gold: #e3ba60;
  --green: #56b68f;
  --yellow: #d5c84c;
  --orange: #e08a3e;
  --red: #d05a54;
  --radius: 6px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  letter-spacing: 0;
  overscroll-behavior: none;
}

button {
  color: inherit;
  font: inherit;
  letter-spacing: 0;
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: min(100%, 760px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
}

.app-header {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
}

.app-header h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
  font-weight: 760;
}

.mode-control,
.size-control {
  display: grid;
  gap: 3px;
  padding: 3px;
  border-radius: var(--radius);
  background: var(--surface);
}

.mode-control {
  height: 38px;
  grid-template-columns: repeat(2, 1fr);
  margin-top: 6px;
}

.mode-control button,
.size-control button {
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}

.mode-control button.active,
.size-control button.active {
  background: var(--surface-2);
  color: var(--gold);
  box-shadow: inset 0 0 0 1px #4b554f;
}

.app-header h1 span {
  color: var(--gold);
  font-weight: 650;
}

.app-header p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.engine-badge {
  min-width: 94px;
  min-height: 32px;
  padding: 0 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.engine-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #8c938f;
}

.engine-badge.online {
  color: #ccebdd;
  border-color: #356653;
}

.engine-badge.online .engine-dot {
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(86, 182, 143, 0.13);
}

.score-strip {
  height: 50px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-bottom: 1px solid var(--line);
}

.score-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  position: relative;
}

.score-item + .score-item::before {
  content: "";
  position: absolute;
  left: 0;
  top: 13px;
  bottom: 13px;
  width: 1px;
  background: var(--line);
}

.score-item span {
  color: var(--muted);
  font-size: 11px;
}

.score-item strong {
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.board-section {
  width: 100%;
  aspect-ratio: 1;
  margin: 6px 0;
  position: relative;
  overflow: hidden;
  border: 1px solid #6d4a25;
  border-radius: 4px;
  background: var(--board);
  touch-action: none;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.22);
}

#board {
  display: block;
  width: 100%;
  height: 100%;
}

.thinking-veil {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(21, 24, 23, 0.58);
  backdrop-filter: blur(1px);
}

.thinking-veil[hidden] {
  display: none;
}

.thinking-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.turn-band {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.turn-band > div {
  display: flex;
  align-items: center;
  gap: 8px;
}

.turn-band strong {
  color: var(--text);
  font-size: 14px;
}

.turn-band > #lastMoveText {
  margin-left: auto;
}

#returnCurrentButton {
  min-height: 28px;
  padding: 0 9px;
  border: 1px solid #6d5c35;
  border-radius: 4px;
  background: #342f22;
  color: var(--gold);
  font-size: 11px;
  white-space: nowrap;
}

.move-history {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 5px;
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--line);
}

.move-history::-webkit-scrollbar {
  display: none;
}

.move-history:empty::before {
  content: "逐手目损将在这里显示";
  color: #77817b;
  font-size: 11px;
}

.move-chip {
  height: 30px;
  flex: 0 0 auto;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-left-width: 3px;
  border-radius: 4px;
  background: var(--surface);
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.move-chip strong {
  color: var(--text);
  margin-right: 4px;
}

.move-chip.excellent { border-left-color: var(--green); }
.move-chip.small { border-left-color: var(--yellow); }
.move-chip.large { border-left-color: var(--orange); }
.move-chip.blunder { border-left-color: var(--red); }
.move-chip.previewing { background: #383326; color: var(--gold); }

.turn-marker {
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
  border-radius: 50%;
}

.turn-marker.black {
  background: #080908;
  border: 1px solid #666b67;
}

.turn-marker.white {
  background: #f2eee5;
  border: 1px solid #ffffff;
}

.suggestions {
  min-height: 43px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 7px 0;
}

.suggestion {
  height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
}

.suggestion strong {
  color: var(--text);
  margin-right: 5px;
}

.suggestion:first-child {
  border-color: #77423e;
  background: #342524;
}

.size-control {
  height: 36px;
  grid-template-columns: repeat(3, 1fr);
}

.action-bar {
  height: 58px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding-top: 8px;
}

.action-bar button {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
}

.action-bar button span {
  height: 18px;
  font-size: 18px;
  line-height: 18px;
}

.action-bar button.danger {
  color: #f0aaa4;
  border-color: #66413e;
}

button:disabled {
  opacity: 0.42;
}

button:not(:disabled):active {
  transform: translateY(1px);
  background: #333a36;
}

.error-banner {
  position: fixed;
  z-index: 20;
  left: 12px;
  right: 12px;
  bottom: max(14px, env(safe-area-inset-bottom));
  max-width: 520px;
  margin: 0 auto;
  padding: 12px 14px;
  border: 1px solid #81504b;
  border-radius: var(--radius);
  background: #3a2422;
  color: #ffd9d5;
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

@media (min-width: 640px) {
  .app-shell {
    padding-left: 20px;
    padding-right: 20px;
  }

  .board-section {
    width: min(100%, 590px);
    margin-left: auto;
    margin-right: auto;
  }
}

@media (max-height: 720px) and (orientation: portrait) {
  .app-header {
    min-height: 50px;
  }

  .score-strip {
    height: 44px;
  }

  .board-section {
    margin: 6px 0;
  }

  .suggestions {
    min-height: 42px;
    padding: 4px 0;
  }

  .move-history {
    min-height: 36px;
  }
}
