:root, body.mode-dark {
  --bg: #0e131a;
  --panel: #18202b;
  --panel2: #212b39;
  --text: #f5f7fa;
  --muted: #b3bece;
  --accent: #5b8cff;
  --accent2: #84a8ff;
  --gold: #f4c15d;
  --success: #31d487;
  --warning: #ffb15e;
  --danger: #ff7070;
  --sq-light: #ecdab9;
  --sq-dark: #ae8a68;
  --hl: rgba(91, 140, 255, .45);
  --tab-active-bg: rgba(91, 140, 255, .18);
  --radius: 12px;
  --input-border: #2a3441;
  --shadow: rgba(0, 0, 0, .5);
  --btn-text: #0b1526;
  --disabled: #5c6675;
}

body.mode-light {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --panel2: #edf0f6;
  --text: #1a202c;
  --muted: #6b7280;
  --accent: #102a43;
  --accent2: #3659d9;
  --gold: #f5b942;
  --success: #2bb673;
  --warning: #f2994a;
  --danger: #eb5757;
  --sq-light: #ecdab9;
  --sq-dark: #ae8a68;
  --hl: rgba(54, 89, 217, .35);
  --tab-active-bg: rgba(16, 42, 67, .12);
  --radius: 12px;
  --input-border: #b6bdc8;
  --shadow: rgba(0, 0, 0, .12);
  --btn-text: #f6f7fb;
  --disabled: #b6bdc8;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  height: 100%;
  overscroll-behavior: none;
}

body { display: flex; flex-direction: column; height: 100dvh; }

#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px;
  padding-top: calc(8px + env(safe-area-inset-top));
  background: var(--panel);
  font-weight: 700; font-size: 17px;
  flex: 0 0 auto;
}
#app-title { display: flex; align-items: center; gap: 8px; }
.brand-logo { height: 24px; width: auto; display: block; filter: brightness(0) invert(1); }
body.mode-light .brand-logo { filter: none; }
.streak-badge { font-size: 15px; font-weight: 700; white-space: nowrap; display: inline-flex; align-items: center; gap: 4px; }
.streak-badge.zero { opacity: .5; }
.streak-icon-img { height: 20px; width: auto; }
.icon-btn { background: none; border: none; font-size: 20px; cursor: pointer; padding: 4px 8px; }

/* ── splash screen ─────────────────────── */
#splash {
  position: fixed; inset: 0; z-index: 1000;
  background: #f5f3ef;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
  transition: opacity .45s ease;
}
#splash.hide { opacity: 0; pointer-events: none; }
#splash-logo {
  width: min(30vw, 120px); height: auto;
  clip-path: inset(0 100% 0 0);
  transform: scale(.92);
  animation: splash-logo-draw 850ms cubic-bezier(.22,.8,.25,1) forwards;
}
#splash-title {
  font-weight: 700; font-size: 21px; letter-spacing: .6px; text-align: center;
  color: #102a43;
  opacity: 0; transform: translateY(8px);
  animation: splash-title-in 650ms ease forwards;
  animation-delay: 520ms;
}
@keyframes splash-logo-draw {
  from { clip-path: inset(0 100% 0 0); transform: scale(.92); }
  to { clip-path: inset(0 0% 0 0); transform: scale(1); }
}
@keyframes splash-title-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── decorative watermark ──────────────── */
.watermark {
  position: absolute; z-index: -1;
  top: 10%; right: -8%;
  width: 62%; height: auto;
  opacity: .09;
  filter: brightness(0) invert(1);
  pointer-events: none;
}
body.mode-light .watermark { filter: none; }
#play-setup, #trainer-setup, #rush-intro, #base-list-view, #endgame-list-view, #learn-cat-view {
  position: relative; isolation: isolate; overflow: hidden;
}
/* Screens with a single "start" action: keep the button anchored to the
   same spot near the bottom of the viewport no matter how much option
   content sits above it, so switching between these tabs feels uniform. */
#play-setup, #trainer-setup, #rush-intro {
  display: flex; flex-direction: column;
  min-height: calc(100dvh - 190px);
}
#play-setup .btn.big, #trainer-setup .btn.big, #rush-intro .btn.big { margin-top: auto; }
/* List-style landing screens don't have a single bottom button to anchor,
   but still need full-viewport height so the watermark isn't clipped short
   like it would be if it only sized to the (short) list content. */
#base-list-view, #endgame-list-view, #learn-cat-view { min-height: calc(100dvh - 190px); }

/* ── board color themes ────────────────── */
body.theme-wood { --sq-light: #ecdab9; --sq-dark: #ae8a68; }
body.theme-green { --sq-light: #eeeed2; --sq-dark: #769656; }
body.theme-blue { --sq-light: #dee3e6; --sq-dark: #8ca2ad; }

main { flex: 1 1 auto; overflow-y: auto; padding: 10px; }

#tabbar {
  flex: 0 0 auto;
  display: flex;
  background: var(--panel);
  border-top: 1px solid var(--input-border);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabbar button {
  flex: 1; background: transparent; border: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px; padding: 7px 2px 6px; cursor: pointer;
  border-radius: 10px 10px 0 0;
  transition: background-color .25s ease, color .25s ease;
}
#tabbar button.on { color: var(--accent); background: var(--tab-active-bg); }
.tab-ico { font-size: 20px; line-height: 1; }

.screen { max-width: 560px; margin: 0 auto; }
.hidden { display: none !important; }

h2 { margin: 4px 0 10px; font-size: 20px; }
.screen-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

/* ── board ─────────────────────────────── */
.board-wrap { width: 100%; max-width: 560px; margin: 0 auto; }
.board {
  position: relative; width: 100%; aspect-ratio: 1/1;
  border-radius: 6px; overflow: hidden;
  box-shadow: 0 3px 14px var(--shadow);
  touch-action: none;
  user-select: none;
}
.sq { position: absolute; width: 12.5%; height: 12.5%; }
.sq img.dragging-source { opacity: 0; }
.drag-ghost {
  position: fixed; top: 0; left: 0; pointer-events: none; z-index: 1000;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,.5));
  transform: scale(1.15);
}
.sq.light { background: var(--sq-light); }
.sq.dark { background: var(--sq-dark); }
.sq img { width: 100%; height: 100%; display: block; pointer-events: none; }
.sq.lastmove::before {
  content: ''; position: absolute; inset: 0; background: var(--hl);
}
.sq.lastmove-outbook::before {
  content: ''; position: absolute; inset: 0; background: rgba(230, 190, 40, .55);
}
.sq.selected::before {
  content: ''; position: absolute; inset: 0; background: rgba(20, 85, 30, .5);
}
.sq.dest::after {
  content: ''; position: absolute; left: 36%; top: 36%; width: 28%; height: 28%;
  border-radius: 50%; background: rgba(0,0,0,.25);
}
.sq.capture-dest::after {
  content: ''; position: absolute; inset: 0;
  border: 4px solid rgba(0,0,0,.3); border-radius: 50%;
}
.sq.check { background: radial-gradient(circle, #e05a4d 30%, transparent 75%); }
.sq.check.light { background-color: var(--sq-light); }
.sq.check.dark { background-color: var(--sq-dark); }
.sq.hintsq::before {
  content: ''; position: absolute; inset: 0; background: rgba(70, 130, 220, .55);
}
.shapes-layer { position: absolute; inset: 0; pointer-events: none; width: 100%; height: 100%; z-index: 3; }
.coords { position: absolute; inset: 0; pointer-events: none; font-size: 9px; font-weight: 700; }
.coord { position: absolute; color: rgba(0,0,0,.45); }
.coord.rank { left: 2px; }
.coord.file { bottom: 1px; }

.promo-overlay {
  position: absolute; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; gap: 8px; z-index: 5;
}
.promo-btn { width: 18%; aspect-ratio: 1; background: var(--panel2); border: 2px solid var(--accent); border-radius: 10px; cursor: pointer; }
.promo-btn img { width: 100%; }

@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-7px)} 75%{transform:translateX(7px)} }
.shake { animation: shake .3s 1; }

/* ── toolbar & buttons ─────────────────── */
.toolbar { display: flex; gap: 4px; margin: 8px 0; }
.tool-btn {
  flex: 1; background: var(--panel2); color: var(--text);
  border: none; border-radius: 8px; font-size: 18px; padding: 9px 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.tool-btn.on { background: var(--accent2); }
.tool-btn:active { transform: scale(.96); }

.btn {
  background: var(--panel2); color: var(--text); border: none;
  border-radius: var(--radius); padding: 10px 16px; font-size: 15px; cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--btn-text); font-weight: 700; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.big { width: 100%; padding: 14px; font-size: 17px; margin-top: 12px; }
.btn:active { transform: scale(.97); }

.row { display: flex; gap: 8px; margin: 8px 0; align-items: center; }
.row.wrap, .wrap { flex-wrap: wrap; }

.input {
  width: 100%; background: var(--panel2); color: var(--text);
  border: 1px solid var(--input-border); border-radius: 8px; padding: 10px; font-size: 15px; margin: 6px 0;
}

.hint { color: var(--muted); font-size: 13px; line-height: 1.45; }

/* segmented control */
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.seg.scroll::-webkit-scrollbar { display: none; }
.seg.scroll button { flex: 0 0 auto; }
.elo-badge {
  background: var(--accent2); color: #fff; font-weight: 700;
  padding: 4px 12px; border-radius: 20px; font-size: 14px;
}
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .cat-count { color: var(--muted); font-size: 13px; }
.badge-practice { display:inline-block; background:#3a5a2a; color:#c7e8a8; font-size:11px; padding:2px 7px; border-radius:10px; margin-left:6px; }

/* ── profile ───────────────────────────── */
.profile-card {
  background: var(--panel); border-radius: var(--radius);
  padding: 14px; margin: 10px 0;
}
.profile-card h3 { margin: 0 0 8px; font-size: 15px; color: var(--muted); }
.google-btn {
  width: 100%; display: flex; align-items: center; justify-content: center; gap: 10px;
  background: #fff; color: #3c4043; font-weight: 600; padding: 11px;
}
.google-btn img { width: 20px; height: 20px; }
.avatar { width: 40px; height: 40px; border-radius: 50%; }
.avatar-badge {
  border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  color: #fff; flex: 0 0 auto; line-height: 1; overflow: hidden;
}
.avatar-badge img { width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }
.avatar-pick-cell {
  background: var(--panel2); border-radius: 10px; padding: 8px 4px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; position: relative;
  border: 2px solid transparent;
}
.avatar-pick-cell.selected { border-color: var(--accent); }
.avatar-pick-cell.locked .avatar-badge { opacity: .35; filter: grayscale(.6); }
.avatar-lock { position: absolute; font-size: 16px; text-shadow: 0 1px 3px rgba(0,0,0,.6); }
.avatar-edit-wrap { position: relative; flex: 0 0 auto; display: inline-flex; }
.avatar-edit-btn {
  position: absolute; right: -4px; bottom: -4px; width: 22px; height: 22px;
  border-radius: 50%; background: var(--accent); color: #fff; border: 2px solid var(--panel);
  display: flex; align-items: center; justify-content: center; font-size: 11px;
  padding: 0; cursor: pointer; line-height: 1;
}

/* ── streak timeline ──────────────────── */
.streak-timeline {
  display: flex; align-items: center; gap: 6px;
  overflow-x: auto; overflow-y: hidden; padding: 6px 2px 10px;
  scrollbar-width: thin;
}
.streak-timeline-tier { flex: 0 0 auto; display: flex; align-items: center; justify-content: center; padding: 4px 6px; }
/* Fixed height, auto width: the source art ranges from tall/narrow (early
   tiers) to short/wide (later tiers), so forcing a square box made later
   tiers look shrunken. Sharing one height instead keeps every icon reading
   as the same size regardless of its natural aspect ratio. */
.streak-timeline-tier img { height: 46px; width: auto; display: block; }
.streak-timeline-tier.locked img {
  filter: grayscale(1) brightness(0) invert(1); opacity: .28;
}
.streak-timeline-tier.current { position: relative; }
.streak-timeline-tier.current::after {
  content: ''; position: absolute; inset: 0; border: 2px solid var(--accent); border-radius: 10px;
}

/* ── Kael (mascot) ─────────────────────── */
.kael-modal-head { display: flex; justify-content: center; margin: -6px 0 10px; }
.kael-portrait {
  width: 130px; height: auto; border-radius: 16px;
  background: #f2eee6; padding: 6px; box-shadow: 0 4px 16px var(--shadow);
}
.kael-bubble {
  background: var(--panel2); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 12px; text-align: center;
}
.kael-bubble b { display: block; font-size: 17px; margin-bottom: 4px; }
.kael-bubble p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
.kael-level-grid { display: flex; flex-direction: column; gap: 8px; margin-bottom: 4px; }
.kael-level-cell {
  display: grid; grid-template-columns: auto 1fr; column-gap: 10px; row-gap: 2px;
  align-items: center; text-align: left;
  background: var(--panel2); border: 2px solid transparent; border-radius: var(--radius);
  padding: 10px 12px; cursor: pointer; font-family: inherit;
}
.kael-level-cell:active { transform: scale(.98); }
.kael-level-cell:hover { border-color: var(--tier-color); }
.kael-level-icon {
  grid-row: 1 / 3; width: 38px; height: 38px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; color: #fff;
}
.kael-level-cell b { font-size: 15px; color: var(--text); }
.kael-level-range { font-size: 11px; color: var(--muted); }
.kael-level-desc { grid-column: 2; font-size: 12px; color: var(--muted); line-height: 1.35; }

/* ── puzzle theme picker ───────────────── */
.theme-pick-row {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 4px; font-size: 15px; cursor: pointer;
  border-bottom: 1px solid var(--input-border);
}
.theme-pick-row input { width: 18px; height: 18px; accent-color: var(--accent); flex: 0 0 auto; }
#tp-random { }
label.theme-pick-row:first-of-type { font-weight: 700; }
.btn.small { padding: 5px 10px; font-size: 13px; margin-top: 4px; }
.profile-elo-row { gap: 8px; }
.elo-card {
  flex: 1 1 100px; background: var(--panel); border-radius: var(--radius);
  padding: 10px; text-align: center; font-size: 12px; color: var(--muted);
  display: flex; flex-direction: column; gap: 4px;
  border: none; cursor: pointer; font-family: inherit;
}
.elo-card:active { transform: scale(.97); }
.elo-card b { font-size: 20px; color: var(--text); }
.elo-history-timeframe { display: flex; gap: 6px; margin: 12px 0; }
.elo-history-timeframe button { flex: 1; }
.elo-peak { text-align: center; color: var(--muted); font-size: 14px; margin-top: 10px; }
.elo-peak b { color: var(--accent); font-size: 18px; }
.elo-history-wrap { position: relative; width: 100%; height: 220px; }
.radar-wrap { position: relative; width: 100%; max-width: 420px; margin: 0 auto; aspect-ratio: 1/1; }

/* ── trophy case ───────────────────────── */
.daily-missions-list { display: flex; flex-direction: column; }
.daily-mission-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--input-border); background: none; border-left: none; border-right: none; border-top: none; width: 100%; text-align: left; cursor: pointer; color: var(--text); font: inherit; }
.daily-mission-row:last-child { border-bottom: none; }
.daily-mission-check {
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--muted);
  display: flex; align-items: center; justify-content: center; font-size: 12px;
  flex: 0 0 auto; color: transparent;
}
.daily-mission-row.done .daily-mission-check { background: var(--success); border-color: var(--success); color: #fff; }
.daily-mission-label { flex: 1; font-size: 14px; }
.daily-mission-row.done .daily-mission-label { color: var(--muted); text-decoration: line-through; }
.daily-mission-arrow { color: var(--muted); font-size: 14px; }

.trophy-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 8px; }
.badge-cell {
  background: var(--panel2); border-radius: 10px; padding: 8px 4px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  opacity: .3; filter: grayscale(1);
}
.badge-cell.earned { opacity: 1; filter: none; background: var(--accent2); }
.badge-icon { font-size: 22px; width: 44px; height: 44px; }
.badge-icon img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
.badge-name { font-size: 9px; text-align: center; color: var(--text); line-height: 1.2; }

/* ── auth modal ────────────────────────── */
.auth-tabs { display: flex; gap: 8px; margin-bottom: 14px; }
.auth-tabs button { flex: 1; padding: 10px; border-radius: 10px; background: var(--panel2); border: none; color: var(--text); font-weight: 700; cursor: pointer; }
.auth-tabs button.on { background: var(--accent); color: var(--btn-text); }
.auth-error { color: var(--danger); font-size: 13px; margin: 6px 0; min-height: 16px; }
.auth-divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; margin: 14px 0; }
.auth-divider::before, .auth-divider::after { content: ''; flex: 1; height: 1px; background: var(--input-border); }
.auth-link { display: block; width: 100%; text-align: center; background: none; border: none; color: var(--accent); text-decoration: underline; font-size: 14px; padding: 10px 0 0; cursor: pointer; }
.auth-consent { display: flex; align-items: flex-start; gap: 8px; font-size: 13px; color: var(--muted); margin: 10px 0; cursor: pointer; }
.auth-consent input { margin-top: 2px; flex: 0 0 auto; }
.auth-consent a { color: var(--accent); }

/* ── legal (terms / privacy) ───────────── */
.legal-h { margin: 16px 0 4px; font-size: 15px; }
.legal-h:first-of-type { margin-top: 8px; }
.legal-p { margin: 0 0 4px; font-size: 14px; line-height: 1.5; color: var(--muted); }
.seg button {
  background: var(--panel2); border: none; color: var(--text);
  padding: 9px 14px; border-radius: 20px; font-size: 14px; cursor: pointer;
}
.seg button.on { background: var(--accent); color: var(--btn-text); font-weight: 700; }
.option-group { margin: 14px 0; }
.option-group > label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 14px; }

/* ── move list ─────────────────────────── */
.movelist {
  background: var(--panel); border-radius: var(--radius);
  padding: 10px 12px; margin-top: 8px; line-height: 1.9;
  min-height: 60px; max-height: 30dvh; overflow-y: auto;
  font-size: 16px;
}
.movelist.small { font-size: 14px; max-height: 20dvh; line-height: 1.6; color: var(--muted); }
.mv { cursor: pointer; padding: 2px 3px; border-radius: 5px; white-space: nowrap; }
.mv.current { background: var(--accent2); color: #fff; }
.mv-brilliant { color: #1fb6a6; font-weight: 700; }
.mv-mistake { color: var(--warning); font-weight: 700; }
.mv-blunder { color: var(--danger); font-weight: 700; }
.mv-comment { color: #8fbc8f; font-style: italic; cursor: pointer; }
.variation { color: var(--muted); font-size: 14px; }
.variation.d2 { font-size: 13px; }
.variation.d3 { font-size: 12px; }

/* ── NAG symbol picker ─────────────────── */
.nag-bar {
  display: flex; flex-wrap: nowrap; gap: 4px; margin: 6px 0;
  overflow-x: auto; scrollbar-width: none; padding-bottom: 2px;
}
.nag-bar::-webkit-scrollbar { display: none; }
.nag-bar button {
  flex: 0 0 auto; min-width: 30px; background: var(--panel2); color: var(--text);
  border: none; border-radius: 7px; font-size: 14px; padding: 6px 5px; cursor: pointer;
}
.nag-bar button.on { background: var(--accent2); color: #fff; }
.nag-bar button:active { transform: scale(.94); }

/* ── annotate toolbar (arrows/squares) ─── */
.annotate-bar {
  display: flex; gap: 10px; align-items: center; justify-content: center;
  background: var(--panel); border-radius: var(--radius);
  padding: 10px; margin: 8px 0;
}
.annotate-btn {
  width: 38px; height: 38px; border-radius: 50%; border: 3px solid transparent;
  cursor: pointer; padding: 0;
}
.annotate-btn.green { background: #3aa53a; }
.annotate-btn.yellow { background: #e0b400; }
.annotate-btn.red { background: #d0392b; }
.annotate-btn.clear { background: var(--panel2); border-radius: 10px; font-size: 16px; width: auto; padding: 0 14px; }
.annotate-btn.active { border-color: #fff; }

/* ── engine panel ──────────────────────── */
.engine-panel {
  background: var(--panel); border-radius: var(--radius);
  margin-top: 8px; padding: 6px 10px;
}
.engine-line {
  padding: 5px 2px; font-size: 14px; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  border-bottom: 1px solid #35302b;
}
.engine-line:last-child { border-bottom: none; }
.engine-line b.good { color: var(--success); }
.engine-line b.bad { color: var(--danger); }
.engine-line .depth { color: var(--muted); font-size: 11px; }
.engine-lines-row { display: flex; align-items: flex-start; gap: 8px; }
.engine-lines-row .engine-lines { flex: 1; min-width: 0; }
.engine-lines-control {
  display: flex; align-items: center; gap: 4px; flex: 0 0 auto;
  padding-top: 3px;
}
.engine-lines-btn {
  width: 24px; height: 24px; border-radius: 50%; border: none;
  background: var(--panel2); color: var(--text); font-size: 15px; line-height: 1;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.engine-lines-btn:disabled { opacity: 0.4; cursor: default; }
#ana-lines-count { font-size: 13px; color: var(--muted); min-width: 12px; text-align: center; }

/* ── lists (bases, games) ──────────────── */
.list { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.list-item {
  text-align: left; background: var(--panel); border: none; color: var(--text);
  border-radius: var(--radius); padding: 12px 14px; cursor: pointer;
  display: flex; flex-direction: column; gap: 3px; font-size: 15px;
}
.list-item:active { background: var(--panel2); }
.list-item .sub { color: var(--muted); font-size: 13px; }
.list-item .result { color: var(--accent); }

/* ── status bars & badges ──────────────── */
.status-bar {
  background: var(--panel); border-radius: var(--radius);
  padding: 10px 14px; margin: 8px 0; font-size: 15px; min-height: 42px;
  display: flex; align-items: center;
}
.status-bar.good { background: #2e4620; color: #b8e08c; }
.status-bar.bad { background: #4a2626; color: #f0aaaa; }
.book-badge { margin: 6px 0; font-size: 14px; padding: 4px 10px; border-radius: 20px; display: inline-block; }
.book-badge.in { background: #2e4620; color: #b8e08c; }
.book-badge.out { background: #46331f; color: #e0bd8c; }

/* ── blind puzzles ─────────────────────── */
.blind-countdown {
  text-align: center; font-size: 46px; font-weight: 800; color: var(--accent);
  padding: 4px 0;
}
.blind-turn {
  text-align: center; margin: -4px 0 6px; font-weight: 600;
}

/* ── comment box ───────────────────────── */
.comment-box { margin-top: 8px; }
.comment-box textarea {
  width: 100%; background: var(--panel2); color: var(--text);
  border: 1px solid var(--input-border); border-radius: 8px; padding: 10px; font-size: 15px;
}

/* ── palette (setup) ───────────────────── */
.palette { display: flex; flex-wrap: wrap; gap: 5px; margin: 10px 0; justify-content: center; }
.pal-btn {
  width: 44px; height: 44px; background: var(--panel2); border: 2px solid transparent;
  border-radius: 8px; cursor: pointer; font-size: 20px; padding: 2px;
}
.pal-btn img { width: 100%; height: 100%; }
.pal-btn.on { border-color: var(--accent); background: var(--accent2); }
.castling-row { gap: 14px; }
.castling-row label { font-size: 14px; display: flex; align-items: center; gap: 4px; }

/* ── toast & modal ─────────────────────── */
#toast {
  position: fixed; bottom: 76px; left: 50%; transform: translateX(-50%);
  background: #000c; color: #fff; padding: 10px 20px; border-radius: 24px;
  font-size: 14px; z-index: 100; max-width: 90vw;
}
.modal-back {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}

/* ── Kael corner (quotes & encouragement) ── */
#kael-corner {
  position: fixed; right: 12px;
  bottom: calc(62px + env(safe-area-inset-bottom));
  z-index: 40; display: flex; flex-direction: column; align-items: flex-end; gap: 8px;
}
#kael-fab {
  width: 48px; height: 48px; border-radius: 50%; padding: 0; border: none;
  background: #f2eee6; box-shadow: 0 3px 10px var(--shadow); cursor: pointer;
  overflow: hidden; flex: 0 0 auto;
}
#kael-fab img { width: 100%; height: 100%; object-fit: cover; }
#kael-fab:active { transform: scale(.94); }
.kael-quote-bubble {
  max-width: 240px; background: var(--panel); color: var(--text);
  border-radius: 14px; padding: 10px 12px; font-size: 13px; line-height: 1.4;
  box-shadow: 0 4px 14px var(--shadow);
  opacity: 0; transform: translateY(6px) scale(.97); pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
}
.kael-quote-bubble.show { opacity: 1; transform: translateY(0) scale(1); }
.kael-quote-bubble .kael-quote-author {
  display: block; margin-top: 4px; color: var(--muted); font-size: 11px; text-align: right;
}
.kael-quote-row { display: flex; align-items: center; gap: 10px; }
.kael-quote-badge { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; flex: 0 0 auto; }
.kael-quote-title { display: block; font-size: 13px; margin-bottom: 2px; }
.modal-box {
  background: var(--panel); border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  width: 100%; max-width: 560px; max-height: 85dvh; overflow-y: auto;
}
.modal-box h3 { margin: 0 0 12px; }
.fld-label { display: block; color: var(--muted); font-size: 13px; margin-top: 10px; }
.sheet-btn {
  display: block; width: 100%; text-align: left; background: var(--panel2);
  border: none; color: var(--text); font-size: 16px; padding: 13px 14px;
  border-radius: 10px; margin-bottom: 7px; cursor: pointer;
}
.sheet-btn.danger { color: var(--danger); }
.sheet-btn.cancel { text-align: center; color: var(--muted); }

@media (min-width: 700px) {
  .modal-back { align-items: center; }
  .modal-box { border-radius: 18px; }
}

/* ── game review ────────────────────────── */
.gr-spinner {
  width: 36px; height: 36px; margin: 22px auto 8px;
  border: 4px solid var(--panel2); border-top-color: var(--accent);
  border-radius: 50%; animation: gr-spin .9s linear infinite;
}
@keyframes gr-spin { to { transform: rotate(360deg); } }
.gr-progress { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.gr-chart { width: 100%; height: 110px; display: block; margin: 10px 0; }
.gr-players { display: flex; justify-content: space-between; margin: 6px 0 14px; gap: 8px; }
.gr-player { text-align: center; flex: 1; min-width: 0; }
.gr-player b { display: block; font-size: 13px; margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gr-accuracy { font-size: 26px; font-weight: 700; }
.gr-table { width: 100%; border-collapse: collapse; font-size: 14px; margin-bottom: 12px; }
.gr-table td { padding: 6px 4px; text-align: center; }
.gr-table td:first-child { text-align: left; }
.gr-table tr:not(:last-child) td { border-bottom: 1px solid var(--panel2); }
.gr-cpl { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.gr-actions { display: flex; gap: 8px; }
.gr-actions .btn { flex: 1; }
