/* Chess Classic — styles. System theme via prefers-color-scheme (no JS toggle).
 * [hidden] must beat every display rule (StretchBreak lesson). */
[hidden] { display: none !important; }

:root {
  --banner-h: 0px;
  --bg: #e8efe6;
  --bg2: #ffffff;
  --ink: #1c241c;
  --ink-dim: #5a6b5a;
  --accent: #2f7d46;
  --accent-ink: #ffffff;
  --line: #c9d4c9;
  --light-sq: #f0d9b5;
  --dark-sq: #b58863;
  --sel: rgba(47, 125, 70, 0.55);
  --last: rgba(205, 210, 60, 0.55);
  --check: rgba(200, 30, 58, 0.55);
  --sheet-bg: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101410;
    --bg2: #1a221a;
    --ink: #e8f0e8;
    --ink-dim: #9db09d;
    --accent: #4ade80;
    --accent-ink: #0d1f12;
    --line: #334033;
    --light-sq: #cbb28a;
    --dark-sq: #7d5a3c;
    --sheet-bg: #1e2a1e;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  color-scheme: light dark;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  padding-bottom: var(--banner-h, 0px);
}
button { font-family: inherit; -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; min-height: 48px; flex: 0 0 auto;
  background: var(--bg2); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 19px; }
.brand-mark { font-size: 24px; color: var(--accent); }
.top-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 40px; height: 40px; font-size: 20px; line-height: 1;
  background: transparent; color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; cursor: pointer;
}
.icon-btn[aria-pressed="false"] { opacity: 0.55; }

main#game {
  flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: column; align-items: center;
  padding: 8px 12px 6px; gap: 6px;
}
.hud {
  display: flex; justify-content: space-between; width: 100%;
  max-width: 420px; flex: 0 0 auto;
}
.hud-item { display: flex; flex-direction: column; align-items: center; min-width: 64px; }
.hud-label { font-size: 11px; color: var(--ink-dim); text-transform: uppercase; letter-spacing: 0.04em; }
.hud-value { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }

.diff-row {
  display: flex; align-items: center; gap: 6px; width: 100%;
  max-width: 420px; flex: 0 0 auto;
}
.diff-label { font-size: 13px; color: var(--ink-dim); }
.diff-btn {
  padding: 6px 12px; font-size: 13px; font-weight: 600;
  background: var(--bg2); color: var(--ink);
  border: 1px solid var(--line); border-radius: 999px; cursor: pointer;
}
.diff-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.status-line { margin-left: auto; font-size: 13px; color: var(--ink-dim); text-align: right; }
.status-line.check { color: #c81e3a; font-weight: 700; }

.board-wrap { flex: 0 0 auto; position: relative; }
.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: min(92vw, 400px, calc(100dvh - 300px));
  aspect-ratio: 1 / 1;
  border: 3px solid #4a3220;
  border-radius: 6px;
  overflow: hidden;
  touch-action: none;
}
.square {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: calc(min(92vw, 400px, calc(100dvh - 300px)) / 8 * 0.78);
  line-height: 1;
}
.square.light { background: var(--light-sq); }
.square.dark { background: var(--dark-sq); }
.square .coord {
  position: absolute; font-size: 9px; font-weight: 600; line-height: 1;
  color: rgba(0, 0, 0, 0.45); pointer-events: none;
}
.square .coord.file { right: 2px; bottom: 2px; }
.square .coord.rank { left: 2px; top: 2px; }
.square.light .coord { color: rgba(122, 82, 42, 0.75); }
.square.dark .coord { color: rgba(240, 217, 181, 0.8); }
.piece { pointer-events: none; z-index: 1; }
.piece.white { color: #fafafa; text-shadow: 0 0 2px #222, 0 1px 2px rgba(0, 0, 0, 0.7), 0 0 0 #222; }
.piece.black { color: #161616; text-shadow: 0 0 2px rgba(255, 255, 255, 0.45), 0 1px 2px rgba(0, 0, 0, 0.5); }
.square.selected { box-shadow: inset 0 0 0 3px var(--accent); }
.square.hint { box-shadow: inset 0 0 0 3px rgba(255, 193, 7, 0.9); }
.square.lastmove { background-image: linear-gradient(var(--last), var(--last)); }
.square.incheck { background-image: linear-gradient(var(--check), var(--check)); }
.square.dest::after {
  content: ""; position: absolute; width: 28%; height: 28%;
  border-radius: 50%; background: rgba(47, 125, 70, 0.55); z-index: 2;
  pointer-events: none;
}
.square.dest.capture::after {
  width: 92%; height: 92%; background: transparent;
  border: 3px solid rgba(200, 30, 58, 0.75); border-radius: 50%;
}
.drag-ghost {
  position: fixed; z-index: 60; pointer-events: none;
  font-size: 44px; line-height: 1; transform: translate(-50%, -50%);
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}
.drag-ghost.white { color: #fafafa; }
.drag-ghost.black { color: #161616; }

/* Fly layer (vc3): clones glide here while the real pieces stay hidden.
 * The layer is fixed to the viewport (board rects are viewport coords);
 * clones use class .fly-piece, NEVER .piece, so DOM piece counts in the
 * harness stay exact mid-flight. */
.fly-layer { position: fixed; inset: 0; pointer-events: none; z-index: 50; }
.fly-piece {
  position: fixed; display: flex; align-items: center; justify-content: center;
  pointer-events: none; line-height: 1;
  transition: left 0.18s ease, top 0.18s ease;
}
.fly-piece.white { color: #fafafa; text-shadow: 0 0 2px #222, 0 1px 2px rgba(0, 0, 0, 0.7), 0 0 0 #222; }
.fly-piece.black { color: #161616; text-shadow: 0 0 2px rgba(255, 255, 255, 0.45), 0 1px 2px rgba(0, 0, 0, 0.5); }

.captured-row {
  display: flex; justify-content: space-between; width: 100%;
  max-width: 420px; min-height: 22px; flex: 0 0 auto;
  font-size: 15px; line-height: 1.2; color: var(--ink-dim);
}
.captured { letter-spacing: 1px; }

.move-list-wrap {
  flex: 1 1 auto; min-height: 54px; width: 100%; max-width: 420px;
  overflow-y: auto; background: var(--bg2);
  border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px;
}
.move-list {
  margin: 0; padding: 0; list-style: none;
  display: flex; flex-wrap: wrap; gap: 2px 10px;
  font-size: 14px; font-variant-numeric: tabular-nums;
}
.move-list li { display: flex; gap: 8px; }
.move-list .mv-num { color: var(--ink-dim); }
.move-list .mv-last { font-weight: 700; color: var(--accent); }

.controls {
  display: flex; gap: 8px; width: 100%; max-width: 420px; flex: 0 0 auto;
}
.control-btn {
  flex: 1; padding: 11px 8px; font-size: 14px; font-weight: 600;
  border-radius: 10px; cursor: pointer; border: 1px solid var(--line);
  white-space: nowrap; /* three buttons must stay one line (vc3 Hint) */
}
.primary-btn { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.ghost-btn { background: var(--bg2); color: var(--ink); }
.control-btn:disabled { opacity: 0.45; cursor: default; }

/* Sheets: fixed overlays with their OWN banner offset (FairSplit lesson:
 * fixed elements do not inherit body padding-bottom). */
.sheet {
  position: fixed; left: 0; right: 0; bottom: var(--banner-h, 0px);
  max-height: calc(100dvh - var(--banner-h, 0px) - 40px);
  overflow-y: auto; z-index: 40;
  background: var(--sheet-bg); color: var(--ink);
  border-top: 1px solid var(--line); border-radius: 16px 16px 0 0;
  padding: 16px 18px calc(18px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.25);
  display: flex; flex-direction: column; gap: 10px;
}
.sheet h2 { margin: 0; font-size: 19px; }
.sheet p { margin: 0; font-size: 14px; line-height: 1.45; }
.sheet-note { font-size: 13px; color: var(--ink-dim); }
.sheet-actions { display: flex; gap: 10px; margin-top: 4px; }
.promo-row { display: flex; gap: 10px; justify-content: center; }
.promo-btn {
  width: 60px; height: 60px; font-size: 40px; line-height: 1;
  background: var(--bg2); color: var(--ink);
  border: 2px solid var(--line); border-radius: 12px; cursor: pointer;
}
.promo-btn:active { border-color: var(--accent); }
.setting-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; font-size: 14px;
}

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--banner-h, 0px) + 8px + 54px);
  z-index: 30; pointer-events: none;
  background: rgba(20, 28, 20, 0.92); color: #fff;
  padding: 8px 14px; border-radius: 999px; font-size: 13px;
  white-space: nowrap; max-width: 92vw; overflow: hidden; text-overflow: ellipsis;
}
body.cc_banner .toast { bottom: calc(var(--banner-h, 0px) + 8px + 54px); }
