:root {
  --cell: 72px;
  --rows: 5;
  --pad: calc(var(--cell) * var(--pad-k, .35));
  --table: #ebe7df;
  --paper: #f7f4ee;
  --card: #fffdf9;
  --ink: #2b2a28;
  --muted: #6b665d;  /* was #8d877c; darkened to pass WCAG AA 4.5:1 */
  --accent: #e0532f;
  /* system fonts only; the CJK face is chosen per <html lang> so kanji get Japanese forms, hanzi Chinese */
  --latin: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial;
  font-family: var(--latin), "PingFang SC", "Hiragino Sans", "Apple SD Gothic Neo", "Microsoft YaHei", "Yu Gothic UI", "Malgun Gothic", "Noto Sans CJK SC", sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}
:root:lang(zh) { font-family: var(--latin), "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Noto Sans SC", sans-serif; }
:root:lang(ja) { font-family: var(--latin), "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Yu Gothic", Meiryo, "Noto Sans CJK JP", "Noto Sans JP", sans-serif; line-break: strict; }
:root:lang(ko) { font-family: var(--latin), "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans CJK KR", "Noto Sans KR", sans-serif; word-break: keep-all; }
[lang="zh-CN"] { font-family: var(--latin), "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif; }
[lang="ja"] { font-family: var(--latin), "Hiragino Sans", "Yu Gothic UI", Meiryo, "Noto Sans CJK JP", sans-serif; }
[lang="ko"] { font-family: var(--latin), "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans CJK KR", sans-serif; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--table); overflow: hidden; }
body { display: flex; flex-direction: column; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

/* ---------- header ---------- */
.top {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: max(14px, env(safe-area-inset-top)) 20px 0;
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand b { font-size: 24px; font-weight: 600; }
.brand span { font-size: 12px; letter-spacing: .18em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
:root:lang(en) .brand span { letter-spacing: .14em; }
:root:lang(zh) .brand span, :root:lang(ja) .brand span, :root:lang(ko) .brand span { letter-spacing: .08em; font-size: 13px; }
.tools { display: flex; justify-content: flex-end; align-items: center; gap: 12px; }
.lang { display: flex; gap: 1px; padding: 2px; border-radius: 999px; background: rgba(0, 0, 0, .045); }
.lang button {
  min-width: 30px; height: 26px; padding: 0 7px; border-radius: 999px; font-size: 12px; color: #5d584f; line-height: 26px;
}
.lang button[aria-pressed="true"] { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }
body.hc .lang button[aria-pressed="true"] { box-shadow: 0 0 0 2px #000; }
.title { text-align: center; }
#level-name { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: .02em; }
#level-line { font-size: 13px; color: var(--muted); margin-top: 3px; min-height: 1em; }
nav { display: flex; justify-content: flex-end; gap: 4px; }
nav button { white-space: nowrap; }
nav button, .presets button {
  font-size: 13px; padding: 7px 12px; border-radius: 999px; color: #5d584f;
  transition: background .2s, color .2s;
}
nav button:hover, .presets button:hover { background: rgba(0, 0, 0, .05); color: var(--ink); }

/* ---------- the book ---------- */
.stage {
  flex: 1; display: grid; place-items: center;
  perspective: calc(var(--cell) * 22); perspective-origin: 32% -10%;
}
.book {
  position: relative; display: flex; transform-style: preserve-3d;
  transform: rotateX(16deg);
  transform-origin: 50% 50%;
}
.page {
  position: relative;
  width: calc(var(--cell) * 4 + var(--pad) * 2);
  height: calc(var(--cell) * var(--rows) + var(--pad) * 2);
  background: var(--paper);
  backface-visibility: visible;
}
.page.left {
  border-radius: 16px 0 0 16px;
  box-shadow: 0 40px 60px -40px rgba(70, 55, 35, .45), 0 1px 2px rgba(0, 0, 0, .06);
  background-image: linear-gradient(90deg, transparent 92%, rgba(0, 0, 0, .035));
}
.page.right {
  border-radius: 0 16px 16px 0;
  transform-origin: left center;
  box-shadow: 0 40px 60px -40px rgba(70, 55, 35, .45), 0 1px 2px rgba(0, 0, 0, .06);
  background-image: linear-gradient(90deg, rgba(0, 0, 0, .045), transparent 8%);
  will-change: transform, opacity;
}
.book[data-mode="fold"] .page.right { pointer-events: none; }
.shade, .light { position: absolute; inset: 0; pointer-events: none; border-radius: inherit; opacity: 0; }
.shade { background: linear-gradient(270deg, rgba(60, 45, 30, .35), rgba(60, 45, 30, .08) 45%, transparent 80%); }
.light { background: rgba(40, 30, 20, 1); }

.grab {
  position: absolute; top: -10px; bottom: -10px; left: 50%; width: 36px; margin-left: -18px;
  cursor: ew-resize; transform: translateZ(4px); touch-action: none;
}
.grab::after {
  content: ""; position: absolute; left: 50%; bottom: -2px; width: 22px; height: 4px; margin-left: -11px;
  border-radius: 2px; background: rgba(0, 0, 0, .14); transition: background .2s;
}
.grab:hover::after { background: var(--accent); }

/* ---------- cells ---------- */
.cell {
  position: absolute;
  left: calc(var(--pad) + var(--x) * var(--cell)); top: calc(var(--pad) + var(--y) * var(--cell));
  width: var(--cell); height: var(--cell);
  display: grid; place-items: center;
}
.cell::before { /* paper grain dot for empty space */
  content: ""; width: 3px; height: 3px; border-radius: 50%; background: #ddd6c9; grid-area: 1 / 1;
}
.cell[data-kind]:not([data-kind="empty"])::before { display: none; }
.tile {
  grid-area: 1 / 1; width: 88%; height: 88%; border-radius: 22%;
  background: var(--card); display: grid; place-items: center; cursor: pointer;
  box-shadow: 0 1px 0 rgba(0, 0, 0, .05), 0 8px 14px -10px rgba(70, 50, 25, .45);
  transition: background .3s, box-shadow .3s;
}
.tile svg { width: 64%; height: 64%; }
.cell[data-kind="stone"] .tile {
  background: linear-gradient(160deg, #d3ccbf, #b9b1a3); border-radius: 32%; cursor: default;
  box-shadow: 0 2px 0 rgba(0, 0, 0, .08), 0 12px 18px -10px rgba(50, 35, 20, .6);
}
.cell[data-kind="loose"] .tile {   /* vol. 3: a loose stone is round (a stone is square-ish); high contrast: dots vs the stone's hatching */
  background: radial-gradient(circle at 38% 32%, #e0d9cc, #b3aa9a 70%); border-radius: 50%; cursor: default;
  box-shadow: 0 2px 0 rgba(0, 0, 0, .08), 0 12px 18px -10px rgba(50, 35, 20, .6);
}
.cell[data-kind="mirror"] .tile {   /* vol. 4 ch. 15: a mirror is a stone with one bright diagonal (the SVG) — same card, a touch cooler */
  background: linear-gradient(160deg, #d6d2c9, #b5b2a9); border-radius: 32%; cursor: default;
  box-shadow: 0 2px 0 rgba(0, 0, 0, .08), 0 12px 18px -10px rgba(50, 35, 20, .6);
}
.cell[data-kind="mirror"] .tile svg { width: 100%; height: 100%; }
.cell[data-kind="ice"] .tile { background: linear-gradient(135deg, #eef5f8, #d9e8ef); box-shadow: inset 0 0 0 1px rgba(111, 143, 166, .35); }   /* vol. 4 ch. 13: ice — a pale translucent square with a crack (SVG) */
.cell[data-kind="ice"] .tile svg { width: 78%; height: 78%; opacity: .8; }
.cell[data-kind="water"] .tile { background: transparent; box-shadow: none; cursor: default; }   /* water is a gap: no card, only the ripples */
.cell[data-kind="water"] .tile svg { width: 80%; height: 80%; opacity: .7; }
.cell[data-kind="door"] .tile { background: #3a3835; cursor: default; }
.cell[data-kind="open"] .tile { outline: 1.5px dashed var(--accent); outline-offset: -5px; }
.cell[data-kind="pop"] .tile { background: linear-gradient(90deg, var(--card) 70%, #fbe6dd); }
.cell[data-kind="ink"] .tile svg { width: 80%; height: 80%; }
.cell[data-kind="crane"] .tile svg { width: 82%; height: 82%; }   /* vol. 3 ch. 10: the crane is paper (walkable) with a folded outline on it */
.cell[data-kind="wet"] .tile svg { width: 96%; height: 96%; filter: blur(.7px); opacity: .88; }   /* wet ink (ch. 7): the blot has not dried — softer edge, a size up */
/* glue (vol. 2): an amber smear on the paper, glossy while wet; it is paper, so it stays clickable */
.cell[data-kind="glue"] .tile {
  background: radial-gradient(ellipse 58% 48% at 50% 56%, rgba(232, 184, 72, .62) 0 60%, rgba(232, 184, 72, .22) 78%, var(--card) 92%);
  box-shadow: inset 0 -2px 4px rgba(140, 90, 20, .12), 0 1px 0 rgba(0, 0, 0, .05), 0 8px 14px -10px rgba(70, 50, 25, .45);
}
.cell[data-kind="glue"] .tile svg { width: 52%; height: 52%; opacity: .85; }
/* vol. 2 letter paper: a faint printed grid aligned to the cells, the hinge-side shading kept */
body[data-paper="letter"] .page {
  background-color: #f6f3ec;
  background-image:
    repeating-linear-gradient(0deg, transparent 0 calc(var(--cell) - 1px), rgba(84, 96, 118, .16) calc(var(--cell) - 1px) var(--cell)),
    repeating-linear-gradient(90deg, transparent 0 calc(var(--cell) - 1px), rgba(84, 96, 118, .16) calc(var(--cell) - 1px) var(--cell));
  background-position: var(--pad) var(--pad), var(--pad) var(--pad);
  background-size: 100% calc(var(--cell) * var(--rows)), calc(var(--cell) * 4) 100%;
  background-repeat: no-repeat;
}

.cell.flash .tile { animation: flash .9s ease-out; }
.cell.link .tile { animation: link .9s ease-out; }
.cell.nope { animation: nope .3s; }
@keyframes flash { 0% { box-shadow: 0 0 0 0 var(--accent); transform: scale(.92); } 40% { box-shadow: 0 0 0 6px rgba(224, 83, 47, .25); transform: scale(1.04); } 100% { transform: none; } }
@keyframes link { 0% { box-shadow: 0 0 0 2px var(--accent); } 100% { box-shadow: 0 0 0 10px rgba(224, 83, 47, 0); } }
@keyframes nope { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }

/* ---------- pop-up tab: a V-fold that rises at half the hinge angle ---------- */
.tab {
  position: absolute; left: 100%;
  top: calc(var(--pad) + var(--y) * var(--cell) + var(--cell) * .2);
  width: calc(var(--cell) * .7); height: calc(var(--cell) * .6);
  transform-origin: left center; pointer-events: none;
  background: var(--card); border-left: 2px solid var(--accent); border-radius: 0 6px 6px 0;
  box-shadow: 0 6px 12px -6px rgba(70, 50, 25, .5);
  transition: background .25s;
}
.tab.up { background: #fde9e1; box-shadow: 0 0 0 1.5px var(--accent), 0 10px 18px -6px rgba(224, 83, 47, .45); }

/* ---------- shadow cast by a stone on the leaning page ---------- */
.shadow {
  position: absolute; pointer-events: none; z-index: 1;
  left: calc(var(--pad) + var(--x) * var(--cell)); top: calc(var(--pad) + var(--y) * var(--cell));
  width: var(--cell); height: var(--cell); display: grid; place-items: center;
  transition: left .18s ease-out;
}
.shadow::before {
  content: ""; width: calc(88% * var(--squash)); height: 88%; border-radius: 22%;
  background: rgba(60, 45, 30, .5); filter: blur(2px);
  transition: width .15s;
}
.cell { z-index: 0; }
.char { z-index: 3; }

/* ---------- character ---------- */
.char {
  position: absolute; pointer-events: none;
  left: calc(var(--pad) + var(--x) * var(--cell)); top: calc(var(--pad) + var(--y) * var(--cell));
  width: var(--cell); height: var(--cell); display: grid; place-items: center;
  transition: left .18s ease-in-out, top .18s ease-in-out;
}
.char.instant { transition: none; }
.char i {
  width: 46%; height: 46%; border-radius: 50%; background: var(--ink); position: relative;
  box-shadow: 0 10px 12px -6px rgba(0, 0, 0, .45);
}
.char i::after { content: ""; position: absolute; width: 22%; height: 22%; border-radius: 50%; background: #fff; top: 30%; left: 56%; }
.char.hop i { animation: hop .19s ease-out; }
.char.joy i { animation: joy .7s ease-out; }
@keyframes hop { 50% { transform: translateY(-18%) scale(1.04, .96); } }
@keyframes joy { 30% { transform: translateY(-40%) scale(1.1); } 60% { transform: translateY(0) scale(1.15, .85); } }
.char.fall i { animation: fall .26s ease-in forwards; }
/* vol. 5 ch. 17 「应」: her — the figure's mirror, a woman with a letter (a paler ink, the letter a small white fold, the eye on the other side) */
.char.her { z-index: 2; }
.char.her i { background: color-mix(in srgb, var(--ink) 62%, #fff); box-shadow: 0 8px 10px -6px rgba(0, 0, 0, .35); }
.char.her i::after { left: 22%; }
.char.her i::before { content: ""; position: absolute; width: 34%; height: 24%; background: #fff; border: 1px solid var(--ink); bottom: 4%; right: -14%; transform: rotate(-12deg); }
@keyframes fall { to { transform: translateY(60%) scale(.4); opacity: 0; } }

/* ---------- controls ---------- */
.controls {
  width: min(560px, calc(100% - 40px)); margin: 0 auto; padding: 0 0 max(18px, env(safe-area-inset-bottom));
}
.readout { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
#mode-word { color: var(--ink); font-weight: 600; }
#fold {
  -webkit-appearance: none; appearance: none; width: 100%; height: 28px; background: transparent; margin: 0;
}
#fold::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px;
  background: linear-gradient(90deg, #d6cfc2 0 33.3%, #f0b8a6 33.3% 50.5%, #c9b9b3 50.5% 66.7%, #b9b1ad 66.7% 86.1%, var(--accent) 86.1%);
}
#fold::-moz-range-track {
  height: 4px; border-radius: 2px;
  background: linear-gradient(90deg, #d6cfc2 0 33.3%, #f0b8a6 33.3% 50.5%, #c9b9b3 50.5% 66.7%, #b9b1ad 66.7% 86.1%, var(--accent) 86.1%);
}
#fold::-webkit-slider-thumb {
  -webkit-appearance: none; width: 22px; height: 22px; margin-top: -9px; border-radius: 50%;
  background: var(--card); box-shadow: 0 2px 6px rgba(0, 0, 0, .25), 0 0 0 1px rgba(0, 0, 0, .05); cursor: grab;
}
#fold::-moz-range-thumb { width: 22px; height: 22px; border: 0; border-radius: 50%; background: var(--card); box-shadow: 0 2px 6px rgba(0, 0, 0, .25); }
.presets { display: flex; justify-content: space-between; margin-top: 2px; }
.presets button { padding: 6px 10px; }
.presets .tilt.on { background: var(--accent); color: #fff; }

/* ---------- toast & sheets ---------- */
.toast {
  position: fixed; left: 50%; bottom: 120px; transform: translate(-50%, 10px); opacity: 0;
  max-width: min(420px, calc(100% - 40px)); padding: 12px 18px; border-radius: 14px;
  background: rgba(43, 42, 40, .92); color: #f7f4ee; font-size: 14px; line-height: 1.5; text-align: center;
  transition: opacity .25s, transform .25s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.sheet {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center;
  background: rgba(235, 231, 223, .55); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  animation: fade .25s;
}
.sheet[hidden] { display: none; }
.card {
  background: var(--card); border-radius: 22px; padding: 26px; width: min(380px, calc(100% - 40px));
  box-shadow: 0 30px 60px -20px rgba(60, 45, 25, .35); animation: rise .35s cubic-bezier(.2, .9, .3, 1.2);
}
.card h2 { margin: 0 0 16px; font-size: 17px; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.lv {
  border-radius: 14px; padding: 14px 6px 12px; background: var(--paper); font-size: 13px; color: #5d584f;
  display: flex; flex-direction: column; align-items: center; gap: 4px; position: relative;
}
.lv span { font-size: 20px; font-weight: 600; color: var(--ink); }
.lv-vol, .lv-ch { grid-column: 1 / -1; margin: 6px 0 -2px; font-size: 13px; font-weight: 600; color: var(--muted); }
.lv-vol { margin-top: 12px; font-size: 14px; color: var(--ink); letter-spacing: .08em; }
.lv-vol:first-child { margin-top: 0; }
#level-grid { max-height: 62vh; overflow-y: auto; }
.lv.current { box-shadow: inset 0 0 0 1.5px var(--ink); }
.lv.done::after { content: ""; position: absolute; top: 9px; right: 9px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.close { margin-top: 16px; width: 100%; padding: 10px; border-radius: 12px; color: var(--muted); }
.win { text-align: center; }
.seal {
  width: 56px; height: 56px; margin: 4px auto 14px; border-radius: 12px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-size: 26px; font-weight: 600; transform: rotate(-6deg);
}
.win p { margin: 0 0 20px; font-size: 15px; line-height: 1.6; }
.primary { background: var(--ink); color: #f7f4ee; padding: 11px 28px; border-radius: 999px; font-size: 14px; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(16px) scale(.97); } }

@media (max-width: 560px) {
  .top { grid-template-columns: auto 1fr; row-gap: 10px; padding: max(12px, env(safe-area-inset-top)) 14px 0; }
  .tools { display: contents; }
  .lang { grid-column: 2; grid-row: 1; justify-self: end; }
  nav { grid-column: 1 / -1; grid-row: 2; justify-content: space-between; margin: 0 -6px; }
  .title { grid-column: 1 / -1; grid-row: 3; }
  nav button { padding: 6px 9px; }
}
.book[data-mode="fold"] .page.right .cell::before { opacity: 0; }
#sheet-win { place-items: end center; padding-bottom: 118px; background: transparent; backdrop-filter: none; -webkit-backdrop-filter: none; pointer-events: none; }
#sheet-win .card { pointer-events: auto; display: flex; align-items: center; gap: 16px; width: auto; padding: 14px 16px 14px 18px; text-align: left; }
#sheet-win .seal { width: 40px; height: 40px; margin: 0; font-size: 19px; border-radius: 10px; flex: none; }
#sheet-win p { margin: 0; }
.book[data-mode="fold"] .page.right .tile { opacity: .62; }
.page.right .tile { transition: opacity .3s, background .3s; }

/* ---------- onboarding ---------- */
.tag {
  position: absolute; left: 50%; bottom: 100%; transform: translate(-50%, -2px); z-index: 2;
  padding: 3px 8px; border-radius: 999px; white-space: nowrap; pointer-events: none;
  background: var(--ink); color: var(--paper); font-size: 11px; font-weight: 500; letter-spacing: .04em;
}
.cell .tag { bottom: auto; top: 100%; transform: translate(-50%, 2px); }
.char .tag { bottom: 88%; }
.cell .tag.coach, .coach-slider { background: #bf4220;  /* accent darkened: 4.8:1 with paper text */ opacity: 0; transition: opacity .4s; }
.coach-tap .cell .tap-tip.coach, .coach-fold .coach-slider { opacity: 1; animation: bob 1.6s ease-in-out infinite; }
.cell .tap-tip { top: 50%; left: 100%; transform: translate(4px, -50%); }
/* stays on the left page in every language: wraps rather than running under the crease */
.cell .tap-tip { white-space: normal; width: max-content; max-width: calc(var(--cell) * 2 + var(--pad) - 6px); line-height: 1.3; border-radius: 10px; letter-spacing: 0; padding: 3px 7px; }
.controls { position: relative; }
.coach-slider { left: auto; right: 44px; bottom: auto; top: -22px; transform: none; }
@keyframes bob { 50% { translate: 0 -3px; } }
.cell.glow .tile { box-shadow: 0 0 0 2px var(--accent), 0 0 26px 6px rgba(224, 83, 47, .35); transition: box-shadow .4s; }
.finger {
  position: fixed; left: 0; top: 0; width: 34px; height: 34px; margin: -17px 0 0 -17px; z-index: 50;
  border-radius: 50%; background: rgba(255, 255, 255, .55); border: 1.5px solid rgba(43, 42, 40, .55);
  box-shadow: 0 6px 16px rgba(0, 0, 0, .18); pointer-events: none; opacity: 0;
  transition-property: left, top, opacity, transform; transition-timing-function: cubic-bezier(.45, 0, .2, 1);
}
.finger.on { opacity: 1; }
.finger.tap { transform: scale(.78); background: rgba(224, 83, 47, .35); }

/* ================= accessibility ================= */
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.suggest {
  position: fixed; left: 50%; top: 8px; z-index: 60; transform: translate(-50%, -160%);
  padding: 10px 18px; border-radius: 999px; background: var(--ink); color: var(--paper); font-size: 14px;
}
.suggest:focus { transform: translate(-50%, 0); }
:focus-visible { outline: 3px solid #1d4ed8; outline-offset: 2px; }

/* the ARIA grid: invisible boxes laid exactly over the tiles, so VoiceOver touch-exploring finds them */
.a11y-grid { position: fixed; inset: 0; pointer-events: none; z-index: 20; }
.a11y-grid [role=gridcell] { position: fixed; border-radius: 20%; outline: none; }
.a11y-grid [role=gridcell]:focus {
  box-shadow: 0 0 0 3px #fff, 0 0 0 6px #1d4ed8; background: rgba(29, 78, 216, .08);
}

.badge { padding: 1px 8px; border-radius: 999px; background: var(--ink); color: var(--paper); font-size: 11px; }
.badge[hidden] { display: none; }

/* large, timing-free controls */
.bigbar { display: grid; gap: 8px; margin-top: 10px; }
.bigbar[hidden] { display: none; }
.bigbar > div { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; }
@media (max-width: 560px) { .bigbar > div { gap: 5px; } .bigbar button { font-size: 13px; padding: 6px 0; min-height: 48px; white-space: nowrap; letter-spacing: -.02em; } }
.bigbar button {
  min-height: 52px; padding: 8px 6px; border-radius: 14px; font-size: 16px; font-weight: 600;
  background: var(--card); color: var(--ink); box-shadow: 0 1px 0 rgba(0, 0, 0, .06), 0 4px 10px -6px rgba(60, 45, 25, .4);
}
.bigbar button:active { transform: translateY(1px); background: var(--paper); }
.bb-walk button[data-act^="go"] { background: var(--paper); }

/* settings sheet */
.switches { display: grid; gap: 8px; }
.switches button {
  display: grid; grid-template-columns: 1fr auto; text-align: left; align-items: center; gap: 2px 12px;
  padding: 12px 14px; border-radius: 14px; background: var(--paper);
}
.switches b { font-size: 15px; }
.switches small { grid-column: 1; font-size: 12px; color: #5d584f; }
.switches button::after {
  content: var(--t-off, "关"); grid-column: 2; grid-row: 1 / span 2; min-width: 44px; padding: 4px 0; text-align: center;
  border-radius: 999px; border: 2px solid #5d584f; font-size: 13px; font-weight: 600; color: #5d584f;
}
.switches button[aria-checked="true"]::after { content: var(--t-on, "开"); background: var(--ink); border-color: var(--ink); color: var(--paper); }
#sheet-a11y .card { max-height: calc(100% - 40px); overflow: auto; }
.help { font-size: 12px; line-height: 1.7; color: #5d584f; margin: 14px 0 0; }

/* big tiles: thicker marks */
body.big .tag { font-size: 14px; }
body.big .tile svg { width: 72%; height: 72%; }

/* ---------- high contrast: thick outlines + patterns; nothing relies on red alone ---------- */
body.hc { --table: #ffffff; --paper: #ffffff; --card: #ffffff; --ink: #000000; --muted: #222222; --accent: #b00020; }
body.hc .page { box-shadow: 0 0 0 3px #000; background-image: none; }
body.hc .shade, body.hc .light { display: none; }
body.hc .cell::before { width: 7px; height: 7px; background: #555; }
body.hc .tile { border: 3px solid #000; box-shadow: none; }
body.hc .cell[data-kind="stone"] .tile {
  background: repeating-linear-gradient(45deg, #000 0 4px, #fff 4px 9px); border-radius: 32%;
}
body.hc .cell[data-kind="mirror"] .tile { background: #000; border-radius: 32%; }   /* ch. 15: solid black with the white diagonal */
body.hc .cell[data-kind="mirror"] .tile svg path { stroke: #fff; stroke-opacity: 1; }
body.hc .cell[data-kind="door"] .tile { background: #000; }
body.hc .cell[data-kind="door"] .tile svg * { fill: #fff; stroke: #fff; }
body.hc .cell[data-kind="open"] .tile { outline: 4px dashed #000; outline-offset: -9px; }
body.hc .cell[data-kind="pop"] .tile { background: repeating-linear-gradient(90deg, #fff 0 6px, #000 6px 8px); }
body.hc .cell[data-kind="goal"] .tile { border-width: 5px; border-style: double; border-width: 7px; }
body.hc .cell[data-kind="ink"] .tile { background: radial-gradient(circle, #fff 55%, #ddd 56%); }
body.hc .cell[data-kind="glue"] .tile { background: radial-gradient(circle, #000 0 2.5px, transparent 3px) 0 0 / 9px 9px; box-shadow: none; }
body.hc .cell[data-kind="glue"] .tile svg * { stroke: #000; }
body.hc[data-paper="letter"] .page { background-image: none; }
body.hc .shadow::before {
  filter: none; border: 3px dashed #000;
  background: repeating-linear-gradient(-45deg, rgba(0, 0, 0, .55) 0 3px, transparent 3px 8px);
}
body.hc .tab { border: 3px solid #000; background: repeating-linear-gradient(0deg, #fff 0 5px, #000 5px 7px); }
body.hc .char i { box-shadow: 0 0 0 4px #ffd400, 0 0 0 7px #000; }
body.hc .book[data-mode="fold"] .page.right .tile { opacity: .8; }
body.hc .cell.link .tile, body.hc .cell.flash .tile { animation: none; outline: 5px solid #000; outline-offset: 2px; }
body.hc nav button, body.hc .presets button { color: #000; text-decoration: underline; text-underline-offset: 3px; }
body.hc .bigbar button { border: 3px solid #000; box-shadow: none; }
body.hc #fold::-webkit-slider-runnable-track {
  height: 8px; background: linear-gradient(90deg, #fff 0 33.3%, #000 33.3% 34%, #fff 34% 50.5%, #000 50.5% 51.2%, #fff 51.2% 86.1%, #000 86.1%);
  border: 2px solid #000;
}
body.hc #fold::-webkit-slider-thumb { margin-top: -10px; background: #ffd400; box-shadow: 0 0 0 3px #000; }
body.hc .a11y-grid [role=gridcell]:focus { box-shadow: 0 0 0 4px #ffd400, 0 0 0 8px #000; background: transparent; }
body.hc .toast { background: #000; border: 3px solid #ffd400; }

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
  .cell.link .tile, .cell.flash .tile { outline: 3px solid var(--accent); outline-offset: 2px; }
  .coach-tap .cell .tap-tip.coach, .coach-fold .coach-slider { animation: none; }
}

/* vol. 2 ch. 6 「翻页」: the third page is the back of the right leaf — a shade warmer, and the printed grid runs the other
   way, so the turned face reads as "the other side of the same sheet" (design-ch6.md §2). The turn itself is a short flip. */
body[data-face="1"] .page.right { filter: sepia(.18) brightness(.985); }
/* the front's writing bleeds through the letter paper (透光 0.14), mirrored because we see it from behind; no extra grid
   lines — they competed with the tiles. High contrast: no bleed (the dashed frame below says which face this is). */
body[data-face="1"][data-paper="letter"] .page.right::after {
  content: ''; position: absolute; inset: 6% 8%; pointer-events: none; opacity: .14; transform: scaleX(-1);
  background: repeating-linear-gradient(0deg, transparent 0 .62em, rgba(31, 27, 23, .9) .62em .7em, transparent .7em 1.25em) 0 0 / 100% 1.25em,
    repeating-linear-gradient(90deg, rgba(31, 27, 23, 0) 0 .9em, rgba(31, 27, 23, .55) .9em 1.2em, rgba(31, 27, 23, 0) 1.2em 1.7em);
  -webkit-mask: linear-gradient(90deg, transparent, #000 12%, #000 88%, transparent); mask: linear-gradient(90deg, transparent, #000 12%, #000 88%, transparent);
}
body.hc[data-face="1"] .page.right::after { display: none; }
.page.right.turned { animation: turned .5s ease-out; }
@keyframes turned { 0% { opacity: .2; } 100% { opacity: 1; } }
.presets .flip { font-weight: 600; }
@media (prefers-reduced-motion: reduce) { .page.right.turned { animation: none; } }
body.hc[data-face="1"] .page.right { filter: none; outline: 3px dashed #000; outline-offset: -6px; }

/* ---------- vol. 3 ch. 12 「三折」: the third page on its own crease (docs/design-ch12.md §1) ---------- */
/* the third page is a child of the right page: flat, it lifts with it as one rigid leaf; with the book flat (face 2) it
   turns on its own left edge. Folded onto the right page (face 3) it is hidden and the right page shows the two-layer leaf. */
body.trifold .page.right { transform-style: preserve-3d; border-radius: 0; }
.page.third {
  position: absolute; left: 100%; top: 0;
  transform-origin: left center;
  border-radius: 0 16px 16px 0;
  box-shadow: 0 40px 60px -40px rgba(70, 55, 35, .45), 0 1px 2px rgba(0, 0, 0, .06);
  background-image: linear-gradient(90deg, rgba(0, 0, 0, .06), transparent 6%);
  will-change: transform;
}
body.trifold[data-face="3"] .page.right {   /* the leaf is two sheets thick now: an edge peeks out */
  border-radius: 0 16px 16px 0;
  box-shadow: 3px 3px 0 -1px #e7e0d2, 0 40px 60px -40px rgba(70, 55, 35, .45);
}
/* a square of the folded leaf that shows the RIGHT page through a hole in the third page */
.cell.through::after {
  content: ""; position: absolute; inset: 9%; border-radius: 6px; pointer-events: none;
  border: 1.5px dashed rgba(60, 50, 40, .35);
}
body.hc .cell.through::after { border: 3px dashed #000; }
/* face 2: the left page lies aside, out of reach; the right page is the flat page, the third page the lifted one */
body.trifold[data-face="2"] .page.left { opacity: .45; filter: grayscale(.4); }
body.trifold[data-face="2"] .page.left .cell { pointer-events: none; }
body.trifold[data-face="2"] .book[data-mode="fold"] .page.right { pointer-events: auto; }
body.trifold[data-face="2"] .book[data-mode="fold"] .page.third { pointer-events: none; }
body.trifold[data-face="2"] .book[data-mode="fold"] .page.right > .cell::before { opacity: 1; }
body.trifold[data-face="2"] .book[data-mode="fold"] .page.right > .cell .tile { opacity: 1; }
body.trifold[data-face="2"] .book[data-mode="fold"] .page.third .tile { opacity: .62; }
.presets .crease.on { background: var(--accent); color: #fff; }
/* vol. 5 ch. 19 「封」: the wax is paper with a vermilion drop; sealed, a narrow bridge runs across the crease onto the square it is stuck to */
.cell[data-kind="wax"] .tile svg, .cell[data-kind="sealed"] .tile svg { width: 72%; height: 72%; }
.cell[data-kind="sealed"] .tile svg { width: 100%; height: 100%; }
.cell.sealed-mate { position: relative; }
.cell.sealed-mate::after { content: ''; position: absolute; left: -4%; right: 50%; top: 47%; height: 6%; background: #b8342a; border-radius: 2px; pointer-events: none; }
