:root {
  --bg: #fdf8ef;
  --ink: #2b2b2b;
  --muted: #6d6d6d;
  --card: #ffffff;
  --line: #eadfca;
  --accent: #d91e2a;
  --board: #5c9a2b;
  --board-dark: #4d8723;
  --cellc: #6aa832;
  --starter: #8cbb14; --junior: #f0a000; --expert: #e3262e; --master: #8e3a96; --wizard: #1a73b8;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}
html[data-lang="zh"] .en { display: none; }
html[data-lang="en"] .zh { display: none; }
a { color: #1a5fa8; }
.wrap { max-width: 760px; margin: 0 auto; padding: 0 16px; }

header.top { background: #fff; border-bottom: 1px solid var(--line); }
header.top .wrap { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 52px; flex-wrap: wrap; }
header.top h1 { font-size: 18px; margin: 0; white-space: nowrap; }
header.top h1 a { color: var(--ink); text-decoration: none; }
nav { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; }
nav a { color: #555; text-decoration: none; padding: 6px 8px; border-radius: 6px; font-size: 15px; }
nav a:hover, nav a.on { background: #f6eedd; color: var(--ink); }
#lang-toggle { font: inherit; font-size: 13px; color: #555; background: #f4f4f4; border: 1px solid #ddd; border-radius: 4px; padding: 3px 8px; cursor: pointer; margin-left: 4px; }

main { padding: 18px 0 40px; }
.head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.head h2 { margin: 0; font-size: 22px; }
.badge { display: inline-block; color: #fff; font-size: 13px; font-weight: 600; padding: 1px 9px; border-radius: 99px; vertical-align: middle; letter-spacing: .02em; }
.lv-starter { background: var(--starter); } .lv-junior { background: var(--junior); } .lv-expert { background: var(--expert); }
.lv-master { background: var(--master); } .lv-wizard { background: var(--wizard); } .lv-free { background: #777; }
.sub { color: var(--muted); font-size: 14px; margin: 4px 0 12px; }

/* ── board ─────────────────────────────────────────────────── */
.play { display: grid; grid-template-columns: minmax(0, 440px) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 720px) { .play { grid-template-columns: minmax(0, 1fr); } }
.board-col { max-width: 440px; width: 100%; margin: 0 auto; }
#board {
  position: relative; width: 100%; aspect-ratio: 1 / 1;
  background: url(/img/board.webp) center / 100% 100% no-repeat;
  touch-action: none; user-select: none; -webkit-user-select: none;
  filter: drop-shadow(0 4px 10px rgba(60, 90, 20, .25));
}
/* booklet geometry: grid starts 39px into the 478px board, 4 x 99.75px */
#grid { position: absolute; left: 8.159%; top: 8.159%; width: 83.473%; height: 83.473%; }
.exit-mark { position: relative; height: 34px; }
.exit-mark i { display: block; width: 0; height: 0; margin: 0 auto 1px; border: 7px solid transparent; border-top: 9px solid #3d7a1d; border-bottom: 0; }
.exit-mark span { position: absolute; left: 39.46%; transform: translateX(-50%); top: 4px; text-align: center; line-height: 1.2; color: #3d7a1d; font-size: 13px; font-weight: 700; white-space: nowrap; }
.coords-f, .coords-r { position: absolute; color: rgba(255, 255, 255, .8); font-size: 11px; font-weight: 700; pointer-events: none; z-index: 3; }
.coords-f { left: 8.159%; width: 83.473%; top: 0.4%; display: flex; }
.coords-r { top: 8.159%; height: 83.473%; left: 0.6%; display: flex; flex-direction: column; justify-content: space-around; }
.coords-f b, .coords-r b { flex: 1; text-align: center; }
.coords-r b { flex: 0 0 auto; }
.piece { position: absolute; transition: top .11s ease-out, left .11s ease-out, opacity .3s; cursor: grab; touch-action: none; z-index: 2; }
.piece img { position: absolute; max-width: none; pointer-events: none; user-select: none; -webkit-user-drag: none; }
.piece.house { cursor: default; z-index: 1; }
.piece.locked { cursor: not-allowed; }
.piece.sel img { filter: drop-shadow(0 0 4px #fff) drop-shadow(0 0 2px #fff); }
.piece.out { opacity: 0; pointer-events: none; }
.piece .tag { position: absolute; right: 7%; bottom: 7%; width: 16px; height: 16px; border-radius: 50%; background: rgba(255, 255, 255, .7); color: #3b6e17; font: 700 11px/16px system-ui, sans-serif; text-align: center; pointer-events: none; }
.piece.bump[data-dir="←"] { animation: bumpL .18s; } .piece.bump[data-dir="→"] { animation: bumpR .18s; }
.piece.bump[data-dir="↑"] { animation: bumpU .18s; } .piece.bump[data-dir="↓"] { animation: bumpD .18s; }
@keyframes bumpL { 50% { transform: translateX(-5%); } } @keyframes bumpR { 50% { transform: translateX(5%); } }
@keyframes bumpU { 50% { transform: translateY(-5%); } } @keyframes bumpD { 50% { transform: translateY(5%); } }

.stats { display: flex; gap: 14px; align-items: center; justify-content: center; margin: 4px 0 10px; font-size: 15px; flex-wrap: wrap; }
.stats b { font-size: 20px; }
.btns { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
button, .btn {
  font: inherit; font-size: 15px; padding: 8px 16px; border-radius: 10px; border: 1px solid #d9ccb2;
  background: #fff; color: var(--ink); cursor: pointer; text-decoration: none; display: inline-block; min-height: 40px;
}
button:disabled { opacity: .45; cursor: default; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.best { text-align: center; color: #3f7d16; font-size: 14px; min-height: 1.2em; margin: 8px 0 0; }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; }
.panel h3 { margin: 0 0 6px; font-size: 15px; }
.panel p { margin: 6px 0; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 14px; }
#fen { font-size: 15px; background: #f6f1e6; padding: 2px 6px; border-radius: 5px; word-break: break-all; }
#copyfen { padding: 2px 10px; min-height: 30px; font-size: 13px; margin-left: 4px; }
#copyfen.ok { background: #e7f5da; }
#log { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 14px; line-height: 1.9; }
#log .mv { margin-right: 6px; }
#solmoves { padding-left: 2em; margin: 8px 0; }
#solmoves li { margin: 4px 0; }
#solmoves button { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; padding: 2px 10px; min-height: 30px; }
#solmoves code { color: var(--muted); font-size: 12px; }
.hint { color: var(--muted); font-size: 13px; }
.err { color: var(--accent); }
#fenform { display: flex; gap: 6px; flex-wrap: wrap; }
#fenin { flex: 1; min-width: 180px; font: 15px ui-monospace, Menlo, monospace; padding: 8px; border: 1px solid #d9ccb2; border-radius: 8px; }

/* ── overlay ───────────────────────────────────────────────── */
#overlay { position: fixed; inset: 0; background: rgba(30, 30, 30, .45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
#overlay[hidden] { display: none; }
#overlay .card { position: relative; overflow: hidden; background: #fff; border-radius: 18px; padding: 22px 20px 18px; max-width: 380px; width: 100%; text-align: center; box-shadow: 0 10px 40px rgba(0, 0, 0, .3); animation: pop .3s ease-out; }
#overlay h2 { margin: 6px 0; font-size: 24px; }
#overlay .big { font-size: 18px; }
#overlay .perfect { color: #b87800; font-weight: 600; }
@keyframes pop { from { transform: scale(.8); opacity: 0; } }
.confetti { position: absolute; inset: 0; pointer-events: none; }
.confetti i { position: absolute; top: -12px; width: 8px; height: 12px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(420px) rotate(540deg); opacity: 0; } }

/* ── archive / rules ───────────────────────────────────────── */
.levels h3 { margin: 22px 0 8px; font-size: 17px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.tiles a { display: block; text-align: center; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px 2px 6px; text-decoration: none; color: var(--ink); position: relative; }
.tiles a b { display: block; font-size: 18px; }
.tiles a small { color: var(--muted); font-size: 12px; }
.tiles a.done { background: #eef8e4; border-color: #b9dd98; }
.tiles a.done::after { content: "✓"; position: absolute; top: 2px; right: 6px; color: #3f7d16; font-size: 13px; font-weight: 700; }
.dlist { list-style: none; padding: 0; margin: 0; }
.dlist li { display: flex; justify-content: space-between; gap: 8px; padding: 9px 4px; border-bottom: 1px solid var(--line); }
.dlist li.done a::after { content: " ✓"; color: #3f7d16; font-weight: 700; }
.prose h3 { margin-top: 22px; }
.prose table { border-collapse: collapse; margin: 8px 0; font-size: 15px; }
.prose td, .prose th { border: 1px solid var(--line); padding: 4px 10px; text-align: left; vertical-align: top; }
.prose th { background: #f6eedd; }
.pager { display: flex; justify-content: space-between; margin-top: 14px; font-size: 15px; }

footer { border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; padding: 18px 0 30px; }
footer p { margin: 4px 0; }

/* long move records / position strings must wrap inside their panel */
.side { min-width: 0; }
.panel { overflow-wrap: anywhere; }
#log .mv { white-space: normal; overflow-wrap: anywhere; display: inline-block; max-width: 100%; }
#solmoves code { overflow-wrap: anywhere; }
