:root {
  --bg: #f4f1ec;
  --panel: #ffffff;
  --text: #1f1d1a;
  --muted: #6c665d;
  --border: #ddd6cb;
  --accent: #b3261e;
  --accent-soft: rgba(179, 38, 30, 0.12);
  --good: #2e7d32;
  --board: min(92vw, calc(100vh - 48px), 680px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17181a;
    --panel: #212327;
    --text: #ecebe8;
    --muted: #a19d96;
    --border: #34373c;
    --accent: #ef5350;
    --accent-soft: rgba(239, 83, 80, 0.15);
    --good: #81c784;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #17181a; --panel: #212327; --text: #ecebe8; --muted: #a19d96;
  --border: #34373c; --accent: #ef5350; --accent-soft: rgba(239, 83, 80, 0.15); --good: #81c784;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }

.layout {
  display: flex;
  gap: 24px;
  justify-content: center;
  align-items: flex-start;
  padding: 24px 16px;
}
.board-col { position: relative; flex: 0 0 auto; }
.board-wrap { position: relative; width: var(--board); height: var(--board); }
.board { width: 100%; height: 100%; }
.scp-layer { position: absolute; inset: 0; pointer-events: none; z-index: 5; overflow: visible; }
.scp-piece { position: absolute; left: 0; top: 0; width: 12.5%; height: 12.5%; will-change: transform; }
.scp-piece[hidden] { display: none; }
.scp-piece img { width: 100%; height: 100%; object-fit: contain; display: block; user-select: none; }
.scp-piece.shake img { animation: shyShake 75ms linear infinite alternate; }
@keyframes shyShake {
  0% { transform: translate(-3%, 1%) rotate(-3deg); }
  50% { transform: translate(3%, -2%) rotate(2deg); }
  100% { transform: translate(-2%, 2%) rotate(4deg); }
}
.netinfo { font-size: 12.5px; color: var(--muted); min-height: 1em; }

/* board editor */
.mode-panel { display: flex; flex-direction: column; gap: 12px; }
.mode-panel[hidden] { display: none; }
.hint { margin: 0; font-size: 13px; color: var(--muted); }
.spares {
  width: var(--board); display: flex; justify-content: center; gap: 4px;
  margin: 6px 0; position: relative;
}
.spares[hidden] { display: none; }
.spare {
  width: calc(var(--board) / 8 * .82); aspect-ratio: 1; border-radius: 8px; cursor: pointer;
  display: grid; place-items: center; position: relative; background: var(--panel); border: 1px solid var(--border);
}
.spare.selected { background: var(--accent-soft); border-color: var(--accent); }
.cg-wrap.spares piece { position: absolute; inset: 6%; width: 88%; height: 88%; top: 6%; left: 6%; pointer-events: none; }
.spare img { width: 90%; height: 90%; object-fit: contain; pointer-events: none; }
.tool-icon { font-size: calc(var(--board) / 8 * .4); }
.board.placing cg-board { cursor: crosshair; }
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; margin: 0; display: flex; flex-direction: column; gap: 8px; }
legend { font-size: 13px; color: var(--muted); padding: 0 4px; }
.castling { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; }

.castling legend { grid-column: 1 / -1; }
.controls label, .mode-panel label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); flex: 1; }
.row { align-items: flex-end; }
button.inline { flex: 0 0 auto; }
input[type="text"] {
  font: 12.5px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 7px; padding: 7px 9px; width: 100%;
}

.banner {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  z-index: 10; background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px; padding: 18px 26px;
  box-shadow: 0 12px 40px rgba(0,0,0,.35); text-align: center; font-size: 20px;
  max-width: 80%;
}
.banner small { display: block; font-size: 14px; color: var(--muted); margin-top: 4px; }

.panel {
  width: 340px; max-width: 100%;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 18px; display: flex; flex-direction: column; gap: 14px;
}
h1 { font-size: 22px; margin: 0; letter-spacing: .2px; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 13.5px; }

.status-card { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.status { font-weight: 600; }
.eval { color: var(--muted); font-size: 13px; min-height: 1.2em; font-variant-numeric: tabular-nums; }

.controls { display: flex; flex-direction: column; gap: 10px; }
.controls label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); flex: 1; }
.row { display: flex; gap: 10px; }
select, button {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 7px; padding: 7px 9px;
}
button { cursor: pointer; flex: 1; white-space: nowrap; }
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }

.moves {
  margin: 0; padding: 0 0 0 2.4em; max-height: 210px; overflow-y: auto;
  font: 13.5px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace;
  border-top: 1px solid var(--border); padding-top: 8px;
}
.moves li span { display: inline-block; min-width: 5.5em; }
.moves .scp { color: var(--accent); font-weight: 600; }

.log { font-size: 13px; color: var(--accent); min-height: 1.2em; }

.rules { font-size: 13.5px; color: var(--muted); border-top: 1px solid var(--border); padding-top: 8px; }
.rules summary { cursor: pointer; color: var(--text); font-weight: 600; }
.rules ul { padding-left: 1.2em; margin: 8px 0 0; }
.rules li { margin-bottom: 4px; }

.promo { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 50; }
.promo[hidden] { display: none; }
.promo-card { background: var(--panel); border-radius: 12px; padding: 16px 20px; text-align: center; }
.promo-card p { margin: 0 0 10px; }
.promo-choices { display: flex; gap: 8px; }
.promo-choices button { font-size: 34px; width: 64px; height: 64px; padding: 0; }

/* SCP attack flash */
cg-board square.scp-flash { background: rgba(220, 20, 20, .55) !important; }

@media (max-width: 960px) {
  .layout { flex-direction: column; align-items: center; padding: 16px; }
  :root { --board: min(calc(100vw - 32px), 640px); }
  .panel { width: var(--board); }
}

.mode-panel .castling label { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: 13.5px; }
/* leave room for the piece trays while editing */
body.editing { --board: min(92vw, calc(100vh - 200px), 640px); }
