/* Wu Wei Flow - ink-wash night, Generation 1. All colour derives from the theme variables. */
:root {
  --bg0: #06080c; --bg1: #0d1219; --bg2: #141019;
  --ink: #f3ecdc; --dim: rgba(243, 236, 220, .55); --faint: rgba(243, 236, 220, .3);
  --accent: #d9b45f; --accent-rgb: 217, 180, 95;
  --brush: "WWF Brush", "WWF Kai", "Ma Shan Zheng", "LXGW WenKai", KaiTi, STKaiti, "Kaiti SC", "BiauKai", serif;
  --kai: "WWF Kai", "LXGW WenKai", KaiTi, STKaiti, "Kaiti SC", "BiauKai", serif;
  --latin: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --ease: cubic-bezier(.22, .8, .24, 1);
  --dock-w: 344px;
  --g: min(44vh, 60vw, 430px);          /* glyph box */
  --stg: .3s;                           /* entrance stagger, set per cadence */
}
body[data-theme="jade"]  { --accent: #86cfae; --accent-rgb: 134, 207, 174; --bg2: #0b1614; }
body[data-theme="pearl"] { --accent: #e9e3d6; --accent-rgb: 233, 227, 214; --bg2: #13131a; }

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg0); color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none;
  touch-action: none; overscroll-behavior: none;
  font-family: var(--latin);
}
button { font: inherit; color: inherit; }
kbd { font: 10px/1 var(--latin); padding: 2px 5px; border-radius: 4px; border: 1px solid rgba(255,255,255,.12); color: var(--dim); }

/* ---------------------------------------------------------------- atmosphere */
#atmos { position: fixed; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; }
.sky, .grain { display: none; position: fixed; pointer-events: none; }
body.gl-off .sky, body.gl-off .grain { display: block; }
.sky {
  inset: -30%;
  background:
    radial-gradient(40% 35% at 30% 30%, rgba(var(--accent-rgb), .07), transparent 70%),
    radial-gradient(45% 40% at 70% 70%, rgba(90, 120, 160, .08), transparent 70%),
    radial-gradient(60% 60% at 50% 50%, var(--bg2), transparent 75%),
    linear-gradient(160deg, var(--bg0), var(--bg1) 50%, var(--bg0));
  animation: drift 60s ease-in-out infinite alternate;
}
body.gl-off #atmos { mix-blend-mode: screen; }
.grain {
  inset: 0; opacity: .5; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .5 0 0 0 0 .5 0 0 0 0 .5 0 0 0 .12 0'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}
@keyframes drift {
  0%   { transform: translate(0, 0) rotate(0deg) scale(1); }
  50%  { transform: translate(4%, -3%) rotate(8deg) scale(1.08); }
  100% { transform: translate(-3%, 4%) rotate(-6deg) scale(1.04); }
}

/* ---------------------------------------------------------------- stage & card */
#stage {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  padding: calc(env(safe-area-inset-top) + 4vh) 4vw calc(env(safe-area-inset-bottom) + 9vh);
  transition: padding .7s var(--ease);
}
#drag { will-change: transform; max-width: 100%; }
#card { text-align: center; display: flex; flex-direction: column; align-items: center; }
#glyphwrap { position: relative; width: var(--g); height: var(--g); display: grid; place-items: center; flex: none; }
#glow {
  position: absolute; inset: -12%; border-radius: 50%; pointer-events: none;
  background: radial-gradient(closest-side, rgba(var(--accent-rgb), .20), rgba(var(--accent-rgb), .07) 55%, transparent 75%);
  will-change: opacity, transform;
}
#halo { position: absolute; inset: -14%; width: 128%; height: 128%; pointer-events: none; }
#breather { will-change: transform; position: relative; }
#hanzi {
  font-family: var(--brush);
  font-size: calc(var(--g) * .86);
  line-height: 1; color: var(--ink);
  text-shadow: 0 0 18px rgba(var(--accent-rgb), .35), 0 0 60px rgba(var(--accent-rgb), .18);
  transition: text-shadow 1.2s, color 1.2s;
}
body[data-font="kai"] #hanzi { font-family: var(--kai); }
#textcol { display: flex; flex-direction: column; align-items: center; max-width: min(92vw, 36em); }
#pinyin {
  margin-top: .5em; font-size: clamp(22px, 4vmin, 38px); letter-spacing: .1em;
  color: rgba(var(--accent-rgb), .92); text-shadow: 0 0 16px rgba(var(--accent-rgb), .35);
}
#english { margin-top: .3em; font-style: italic; font-size: clamp(16px, 2.7vmin, 25px); letter-spacing: .04em; color: var(--dim); }
#context { margin-top: .9em; display: flex; flex-direction: column; gap: .35em; }
.ctx { margin: 0; display: flex; align-items: baseline; justify-content: center; gap: .8em; color: rgba(243, 236, 220, .46); }
.ctx-t { font: clamp(15px, 2.3vmin, 21px)/1.5 var(--kai); letter-spacing: .12em; }
.ctx-t mark { background: none; color: rgba(var(--accent-rgb), 1); text-shadow: 0 0 10px rgba(var(--accent-rgb), .6); }
.ctx-ch { font-size: 11px; letter-spacing: .16em; text-transform: uppercase; color: var(--faint); white-space: nowrap; }
body[data-mode="slideshow"] .ctx:nth-child(n+2), body[data-mode="find"] .ctx:nth-child(n+2) { display: none; }
#pairs { display: none; }
#meta { margin-top: 1.1em; font: 11px/1.4 var(--latin); letter-spacing: .18em; text-transform: uppercase; color: rgba(243, 236, 220, .24); }

/* staggered entrance: glyph → pinyin → meaning → context → pairs / meta */
#card.ink-in #glyphwrap { animation: inkIn 1.5s var(--ease) both; }
#card.ink-in #pinyin  { animation: rise 1.2s calc(var(--stg) * 1.6) ease-out both; }
#card.ink-in #english { animation: rise 1.2s calc(var(--stg) * 2.6) ease-out both; }
#card.ink-in #context { animation: rise 1.4s calc(var(--stg) * 3.6) ease-out both; }
#card.ink-in #pairs, #card.ink-in #meta { animation: rise 1.4s calc(var(--stg) * 4.6) ease-out both; }
#card.ink-in.relayout #glyphwrap { animation-duration: .9s; }
@keyframes inkIn {
  0%   { opacity: 0; filter: blur(16px); transform: scale(1.07); }
  60%  { opacity: .92; filter: blur(1.5px); }
  100% { opacity: 1; filter: blur(0); transform: scale(1); }
}
@keyframes rise { from { opacity: 0; transform: translateY(9px); } to { opacity: 1; transform: none; } }

/* outgoing: opacity / transform on the column, blur only on the glyph */
#card.breath-out #glyphwrap { animation: breathOut 1s cubic-bezier(.4, 0, .6, 1) both; }
#card.breath-out #textcol   { animation: fadeAway .6s ease-in both; }
@keyframes breathOut {
  0%   { opacity: 1; filter: blur(0); transform: translateY(0) scale(1); }
  30%  { opacity: 1; filter: blur(0); transform: translateY(-1vh) scale(1.04); }
  100% { opacity: 0; filter: blur(12px); transform: translateY(-8vh) scale(1.16); }
}
#card.fade-out #glyphwrap { animation: fadeOutG 1.1s ease-in both; }
#card.fade-out #textcol   { animation: fadeAway .9s ease-in both; }
@keyframes fadeOutG { to { opacity: 0; filter: blur(8px); transform: scale(.97); } }
#card.swap-out #glyphwrap { animation: swapOut .46s ease-in both; }
#card.swap-out #textcol   { animation: fadeAway .3s ease-in both; }
@keyframes swapOut { to { opacity: 0; filter: blur(8px); transform: scale(.96); } }
@keyframes fadeAway { to { opacity: 0; transform: translateY(4px); } }
#card.known-pulse #hanzi { animation: kpulse 1.4s ease-out; }
@keyframes kpulse { 30% { text-shadow: 0 0 30px rgba(var(--accent-rgb), .8), 0 0 90px rgba(var(--accent-rgb), .5); } }

.ripple {
  position: fixed; width: 20vmin; aspect-ratio: 1; border-radius: 50%;
  left: 50%; top: 46%; transform: translate(-50%, -50%) scale(.3);
  border: 1px solid rgba(var(--accent-rgb), .5);
  animation: ripple 1.4s ease-out forwards; pointer-events: none;
}
@keyframes ripple { to { transform: translate(-50%, -50%) scale(4); opacity: 0; } }

/* ---------------------------------------------------------------- step: monumental */
body[data-mode="step"] { --g: min(46vh, 70vw, 520px); }
body[data-mode="step"] #pairs { display: flex; flex-direction: column; gap: 6px; margin-top: 1.1em; }
body[data-mode="step"] #pairs[hidden] { display: none; }
.pair {
  display: grid; grid-template-columns: auto 1fr auto; align-items: baseline; gap: 12px;
  padding: 6px 12px; border-radius: 12px; cursor: pointer; text-align: left;
  border: 1px solid rgba(255, 255, 255, .05); background: rgba(255, 255, 255, .02);
  transition: background .4s, border-color .4s;
}
.pair:hover, .pair:focus-visible { background: rgba(var(--accent-rgb), .08); border-color: rgba(var(--accent-rgb), .25); outline: none; }
.pair-z { font: 24px/1 var(--brush); letter-spacing: .06em; }
.pair-z i { font-style: normal; color: var(--dim); }
.pair-z b { font-weight: 400; color: var(--accent); text-shadow: 0 0 10px rgba(var(--accent-rgb), .5); }
.pair-l { font: 15px/1.4 var(--kai); color: rgba(243, 236, 220, .5); letter-spacing: .08em; }
.pair-ch { font-size: 10px; letter-spacing: .16em; text-transform: uppercase; color: var(--faint); }
@media (min-width: 900px) and (min-aspect-ratio: 5/4) {
  body[data-mode="step"] { --g: min(66vh, 44vw, 640px); }
  body[data-mode="step"] #card { flex-direction: row; align-items: center; gap: 5vw; text-align: left; }
  body[data-mode="step"] #textcol { align-items: flex-start; max-width: min(34em, 38vw); }
  body[data-mode="step"] .ctx { justify-content: flex-start; }
  body[data-mode="step"] #pinyin { margin-top: 0; font-size: clamp(28px, 4.6vmin, 50px); }
  body[data-mode="step"] #english { font-size: clamp(18px, 3vmin, 30px); }
  body[data-mode="step"] .ctx-t { font-size: clamp(17px, 2.5vmin, 24px); }
}
body[data-mode="step"] .ctx-t { font-size: clamp(15px, 2.4vmin, 23px); }

/* ---------------------------------------------------------------- freeze */
#frozen-note {
  position: fixed; left: 50%; top: max(18px, env(safe-area-inset-top)); transform: translate(-50%, -8px);
  display: flex; align-items: center; gap: 10px; pointer-events: none;
  opacity: 0; transition: opacity 1.2s var(--ease), transform 1.2s var(--ease);
  color: rgba(var(--accent-rgb), .8);
}
#frozen-note span { font: 26px/1 var(--brush); text-shadow: 0 0 14px rgba(var(--accent-rgb), .6); }
#frozen-note i { font-size: 11px; letter-spacing: .2em; text-transform: uppercase; font-style: normal; color: var(--faint); }
body.frozen #frozen-note { opacity: 1; transform: translate(-50%, 0); }
body.frozen #hanzi { text-shadow: 0 0 22px rgba(var(--accent-rgb), .5), 0 0 80px rgba(var(--accent-rgb), .25); }

/* ---------------------------------------------------------------- constellation */
#constellation { position: absolute; inset: -14%; pointer-events: none; }
.cn-threads { position: absolute; inset: 0; overflow: visible; }
.cn-thread {
  fill: none; stroke: rgb(var(--accent-rgb)); stroke-linecap: round;
  stroke-opacity: 0; stroke-dasharray: var(--len, 400); stroke-dashoffset: var(--len, 400);
  transition: stroke-dashoffset 1.6s var(--ease), stroke-opacity 1.2s var(--ease);
}
.cn-thread.in { stroke-dashoffset: 0; stroke-opacity: var(--o, .3); }
.cn-layer { position: absolute; inset: 0; }
.cn-node {
  position: absolute; left: 0; top: 0; width: 42px; height: 42px; padding: 0; border-radius: 50%;
  display: grid; place-items: center; pointer-events: auto; cursor: pointer;
  border: 1px solid rgba(var(--accent-rgb), .12);
  background: radial-gradient(closest-side, rgba(var(--accent-rgb), .12), rgba(6, 8, 12, .35));
  font: 24px/1 var(--brush); color: rgba(243, 236, 220, .78);
  opacity: 0; transition: opacity 1.1s var(--ease), border-color .4s, color .4s, box-shadow .4s;
}
body[data-font="kai"] .cn-node { font-family: var(--kai); }
.cn-node.in { opacity: .82; }
.cn-node:hover, .cn-node:focus-visible { opacity: 1; color: #fff8e8; outline: none; border-color: rgba(var(--accent-rgb), .55); box-shadow: 0 0 18px rgba(var(--accent-rgb), .45); }
body[data-mode="find"].dock-open .cn-node { pointer-events: auto; }
.cn-tip {
  position: fixed; left: 0; top: 0; z-index: 9; max-width: min(320px, 90vw); pointer-events: none;
  padding: 10px 14px; border-radius: 14px; opacity: 0; transition: opacity .35s;
  background: rgba(12, 14, 20, .55); border: 1px solid rgba(255, 255, 255, .1);
  backdrop-filter: blur(20px) saturate(1.3); -webkit-backdrop-filter: blur(20px) saturate(1.3);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08), 0 18px 40px rgba(0, 0, 0, .4);
}
.cn-tip.show { opacity: 1; }
.cn-h { display: flex; align-items: baseline; gap: 10px; }
.cn-h b { font: 400 26px/1 var(--brush); color: var(--accent); }
.cn-py { color: rgba(var(--accent-rgb), .9); font-size: 14px; }
.cn-en { color: var(--dim); font-size: 13px; font-style: italic; }
.cn-line { margin: 8px 0 2px; font: 17px/1.5 var(--kai); letter-spacing: .1em; color: rgba(243, 236, 220, .6); }
.cn-line mark { background: none; color: var(--accent); }
.cn-line mark.self { color: #fff8e8; text-shadow: 0 0 8px rgba(var(--accent-rgb), .7); }
.cn-src { font-size: 10px; letter-spacing: .16em; text-transform: uppercase; color: var(--faint); }

/* ---------------------------------------------------------------- quiet chrome */
#controls {
  position: fixed; right: max(14px, env(safe-area-inset-right)); bottom: max(14px, env(safe-area-inset-bottom));
  display: flex; gap: 6px; opacity: .3; transition: opacity .6s; z-index: 4;
}
#controls:hover, #controls:focus-within { opacity: .9; }
#controls button {
  width: 34px; height: 34px; padding: 0; border: 0; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
  background: rgba(255, 255, 255, .05); font: 16px/1 var(--brush);
}
#controls button[aria-pressed="true"] { color: var(--accent); background: rgba(var(--accent-rgb), .14); box-shadow: 0 0 14px rgba(var(--accent-rgb), .35); }
body.frozen #controls { opacity: .9; }
.wave { opacity: .25; }
[aria-pressed="true"] .wave { opacity: 1; }
button:focus-visible { outline: 1px solid rgba(var(--accent-rgb), .7); outline-offset: 2px; }

#stagenav {
  position: fixed; left: 50%; bottom: max(22px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: none; gap: 18px; align-items: center; z-index: 3;
  opacity: .22; transition: opacity .6s, left .7s var(--ease);
}
body[data-mode="slideshow"] #stagenav, body[data-mode="step"] #stagenav { display: flex; }
#stagenav:hover, #stagenav:focus-within { opacity: .8; }
#stagenav button { min-width: 40px; height: 40px; padding: 0 10px; border: 0; border-radius: 20px; background: transparent; cursor: pointer; font: 26px/1 var(--latin); }
#stagenav #nav-mid { font: 15px/1 var(--kai); letter-spacing: .1em; }
.notice { color: var(--dim); max-width: 32em; text-align: center; line-height: 1.6; }

/* ---------------------------------------------------------------- dock (glass) */
@media (min-width: 900px) {
  body.dock-open #stage { padding-right: calc(var(--dock-w) + 4vw); }
  body.dock-open #stagenav, body.dock-open #frozen-note { left: calc(50% - var(--dock-w) / 2); }
}
#scrim { display: none; position: fixed; inset: 0; z-index: 5; background: rgba(0, 0, 0, .28); }
#handle {
  position: fixed; right: 0; top: 50%; transform: translateY(-50%);
  width: 22px; height: 96px; padding: 0; border: 0; background: transparent; cursor: pointer;
  display: grid; place-items: center; z-index: 5; opacity: .35; transition: opacity .5s;
}
#handle span { width: 3px; height: 46px; border-radius: 2px; background: linear-gradient(transparent, rgba(var(--accent-rgb), .9), transparent); box-shadow: 0 0 10px rgba(var(--accent-rgb), .5); }
#handle:hover, #handle:focus-visible { opacity: .9; outline: none; }
body.dock-open #handle { opacity: 0; pointer-events: none; }

#dock {
  position: fixed; top: 12px; right: 12px; bottom: 12px; width: var(--dock-w); z-index: 6;
  display: flex; flex-direction: column; gap: 14px;
  padding: max(18px, env(safe-area-inset-top)) 18px 14px; border-radius: 24px;
  background:
    linear-gradient(160deg, rgba(255, 255, 255, .07), rgba(255, 255, 255, .015) 40%, rgba(var(--accent-rgb), .04)),
    rgba(10, 12, 18, .42);
  backdrop-filter: blur(20px) saturate(1.35); -webkit-backdrop-filter: blur(20px) saturate(1.35);
  border: 1px solid rgba(255, 255, 255, .10);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .14), inset 1px 0 0 rgba(255, 255, 255, .05),
              inset 0 -1px 0 rgba(0, 0, 0, .3), 0 30px 80px rgba(0, 0, 0, .45);
  transform: translateX(calc(100% + 24px)); opacity: 0;
  transition: transform .7s var(--ease), opacity .7s var(--ease);
  color: var(--ink); touch-action: pan-y; overflow: hidden;
}
body.dock-open #dock { transform: none; opacity: 1; }
body.dock-open #controls { opacity: .6; }
@media (min-width: 900px) { body.dock-open #controls { right: calc(var(--dock-w) + 26px); } }
@media (max-width: 899px) { body.dock-open #controls { opacity: 0; pointer-events: none; } }
#controls { transition: opacity .6s, right .7s var(--ease); }
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) { #dock { background: rgba(12, 14, 20, .94); } }

.d-head { display: flex; align-items: center; justify-content: space-between; }
.d-title { font: 22px/1 var(--brush); letter-spacing: .3em; color: rgba(var(--accent-rgb), .85); text-shadow: 0 0 14px rgba(var(--accent-rgb), .4); }
.d-x { width: 30px; height: 30px; border: 0; border-radius: 50%; background: transparent; color: var(--dim); font-size: 20px; line-height: 1; cursor: pointer; }
.d-x:hover { color: var(--ink); background: rgba(255, 255, 255, .06); }

.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.modes button {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 0 9px; border-radius: 14px; cursor: pointer;
  border: 1px solid rgba(255, 255, 255, .06); background: rgba(255, 255, 255, .03);
  color: var(--dim); transition: all .5s var(--ease);
}
.modes b { font: 400 24px/1 var(--brush); }
.modes i { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; font-style: normal; }
.modes kbd { position: absolute; top: 5px; right: 6px; border: 0; padding: 0; opacity: .4; }
.modes button:hover { color: var(--ink); }
.modes button[aria-selected="true"] { color: var(--ink); border-color: rgba(var(--accent-rgb), .35); background: rgba(var(--accent-rgb), .09); box-shadow: 0 0 22px rgba(var(--accent-rgb), .12) inset; }
.modes button[aria-selected="true"] b { color: var(--accent); text-shadow: 0 0 12px rgba(var(--accent-rgb), .6); }

.d-sec { display: none; flex-direction: column; gap: 12px; min-height: 0; animation: rise .6s ease-out both; }
body[data-mode="slideshow"] .d-sec[data-for="slideshow"],
body[data-mode="step"] .d-sec[data-for="step"],
body[data-mode="find"] .d-sec[data-for="find"] { display: flex; }
.d-sec.find { flex: 1; }
.d-label { font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: rgba(243, 236, 220, .4); }
.d-hint { margin: 2px 0 0; font-size: 13px; line-height: 1.9; color: rgba(243, 236, 220, .45); }
.d-hint em { color: rgba(var(--accent-rgb), .8); }

.cadence { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.cadence button {
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px; padding: 9px 12px; border-radius: 14px; cursor: pointer;
  border: 1px solid rgba(255, 255, 255, .07); background: rgba(255, 255, 255, .02); color: var(--dim); text-align: left;
  transition: all .4s var(--ease);
}
.cadence b { font-size: 16px; font-weight: 400; color: var(--ink); }
.cadence i { font-size: 11px; letter-spacing: .06em; }
.cadence button:hover { border-color: rgba(var(--accent-rgb), .3); }
.cadence button[aria-pressed="true"] { border-color: rgba(var(--accent-rgb), .55); background: rgba(var(--accent-rgb), .12); box-shadow: 0 0 18px rgba(var(--accent-rgb), .18); }
.cadence button[aria-pressed="true"] b { color: var(--accent); }
.custom-row { display: grid; grid-template-columns: auto 1fr 4.5em; align-items: center; gap: 10px; font-size: 12px; color: var(--dim); padding: 4px 4px; border-radius: 12px; }
.custom-row.active { color: var(--accent); }
.custom-row output { text-align: right; font-variant-numeric: tabular-nums; }
#custom { width: 100%; accent-color: var(--accent); }
.d-wide, .chips button {
  padding: 9px 11px; border-radius: 999px; cursor: pointer;
  border: 1px solid rgba(255, 255, 255, .08); background: transparent; color: var(--dim);
  font-size: 12px; letter-spacing: .12em; text-transform: uppercase; transition: all .4s var(--ease);
}
.d-wide:hover, .chips button:hover { color: var(--ink); border-color: rgba(var(--accent-rgb), .3); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { letter-spacing: .04em; text-transform: none; padding: 6px 10px; }
.chips button[aria-pressed="true"] { color: var(--bg0); background: var(--accent); border-color: var(--accent); box-shadow: 0 0 14px rgba(var(--accent-rgb), .45); }

/* ---------------------------------------------------------------- music (js/music.js) */
.d-music { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.d-sec.find ~ .d-music { margin-top: 0; }
.d-music ~ .toggles { margin-top: 0; }
.music-enter {
  position: relative; display: flex; align-items: center; gap: 14px; width: 100%; padding: 10px 14px; border-radius: 18px;
  border: 1px solid rgba(var(--accent-rgb), .22); cursor: pointer; text-align: left; color: var(--ink); overflow: hidden;
  background: linear-gradient(100deg, rgba(var(--accent-rgb), .10), rgba(255, 255, 255, .02) 70%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08); transition: all .6s var(--ease);
}
.music-enter::after {                                   /* a slow shimmer: the invitation */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(100deg, transparent 30%, rgba(var(--accent-rgb), .14) 50%, transparent 70%);
  transform: translateX(-100%); animation: invite 7s var(--ease) infinite;
}
@keyframes invite { 55%, 100% { transform: translateX(100%); } }
.music-enter b { flex: none; font: 400 26px/1 var(--brush); color: var(--accent); text-shadow: 0 0 14px rgba(var(--accent-rgb), .55); letter-spacing: .05em; }
.music-enter span { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.music-enter em { font-style: normal; font-size: 13.5px; letter-spacing: .06em; }
.music-enter small { font-size: 10.5px; letter-spacing: .06em; color: var(--faint); }
.music-enter:hover { border-color: rgba(var(--accent-rgb), .45); box-shadow: 0 0 24px rgba(var(--accent-rgb), .18), inset 0 1px 0 rgba(255, 255, 255, .1); }
.music-enter[aria-pressed="true"] { background: linear-gradient(100deg, rgba(var(--accent-rgb), .2), rgba(var(--accent-rgb), .04) 80%); border-color: rgba(var(--accent-rgb), .5); }
.music-enter[aria-pressed="true"]::after { animation: none; }
.music-enter[aria-pressed="true"] b { animation: music-breath 10s ease-in-out infinite; }
@keyframes music-breath { 50% { text-shadow: 0 0 26px rgba(var(--accent-rgb), .95); } }
.music-opts { display: none; flex-direction: column; gap: 8px; }
.d-music.on .music-opts { display: flex; animation: rise .8s var(--ease) both; }
.moods button { flex: 1 1 auto; }
.d-music .vol { display: grid; grid-template-columns: auto 1fr 2.4em; align-items: center; gap: 10px; font-size: 12px; color: var(--dim); padding: 0 4px; }
.d-music .vol output { text-align: right; font-variant-numeric: tabular-nums; }
#music-vol { width: 100%; accent-color: var(--accent); }
.d-music .entrain { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--dim); padding: 0 4px; cursor: pointer; }
.d-music .entrain input { accent-color: var(--accent); margin: 0; }
.d-music .entrain b { font-weight: 500; color: var(--ink); }
.d-music .entrain small { color: var(--faint); font-size: 10.5px; }
#controls button[data-act="music"][aria-pressed="true"] span { animation: music-breath 10s ease-in-out infinite; }

.toggles { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; margin-top: auto; padding-top: 4px; border-top: 1px solid rgba(255, 255, 255, .06); }
.d-sec.find ~ .toggles { margin-top: 0; }
.toggles button {
  display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 8px 0 6px; border: 0; border-radius: 12px;
  background: transparent; color: var(--dim); cursor: pointer; transition: all .4s var(--ease);
}
.toggles b { height: 20px; display: grid; place-items: center; font: 400 19px/1 var(--brush); }
.toggles i { font-size: 9.5px; letter-spacing: .1em; text-transform: uppercase; font-style: normal; }
.toggles button:hover { color: var(--ink); background: rgba(255, 255, 255, .04); }
.toggles button[aria-pressed="true"] { color: var(--accent); }
.toggles button[aria-pressed="true"] b { text-shadow: 0 0 10px rgba(var(--accent-rgb), .7); }
.dot { width: 11px; height: 11px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.d-foot { display: flex; justify-content: space-between; gap: 8px; font-size: 10px; letter-spacing: .08em; color: rgba(243, 236, 220, .26); }

/* ---------------------------------------------------------------- search */
.search { position: relative; }
#q {
  width: 100%; padding: 11px 36px 11px 14px; border-radius: 14px;
  border: 1px solid rgba(var(--accent-rgb), .2); background: rgba(0, 0, 0, .25);
  color: var(--ink); font: 16px/1.2 var(--latin); outline: none;
  user-select: text; -webkit-user-select: text; transition: border-color .4s, box-shadow .4s;
}
#q::placeholder { color: rgba(243, 236, 220, .3); font-style: italic; }
#q:focus { border-color: rgba(var(--accent-rgb), .5); box-shadow: 0 0 18px rgba(var(--accent-rgb), .15); }
#q::-webkit-search-cancel-button { display: none; }
.search .d-x { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); display: none; }
.search.has-q .d-x { display: block; }
.q-status { display: none; font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--faint); margin-top: -6px; text-align: right; }
.find.searching .q-status { display: block; }
#results { display: none; flex: 1; min-height: 0; overflow-y: auto; margin: 0 -8px; padding: 0 8px; scrollbar-width: thin; touch-action: pan-y; }
.find.searching #results { display: block; }
.find.searching #browse { display: none; }
#results mark { background: rgba(var(--accent-rgb), .22); color: inherit; border-radius: 3px; padding: 0 1px; }
.r-item {
  display: grid; grid-template-columns: 48px 1fr; align-items: center; gap: 4px 12px;
  width: 100%; padding: 8px 10px; border: 0; border-radius: 12px; background: transparent;
  text-align: left; cursor: pointer; transition: background .3s;
}
.r-item:hover, .r-item:focus-visible { background: rgba(var(--accent-rgb), .09); outline: none; }
.r-item .wh-char { font: 36px/1 var(--brush); text-align: center; text-shadow: 0 0 12px rgba(var(--accent-rgb), .3); }
.r-tx, .r-ptx { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.wh-py { color: rgba(var(--accent-rgb), .9); font-size: 15px; }
.wh-en { color: var(--dim); font-size: 13px; font-style: italic; }
.r-why { font-size: 10.5px; letter-spacing: .06em; color: var(--faint); }
.r-phrase {
  display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 4px 12px; margin: 2px 0 6px; padding: 8px 10px;
  border-radius: 14px; border: 1px solid rgba(var(--accent-rgb), .18); background: rgba(var(--accent-rgb), .05);
}
.r-pc-wrap { display: flex; gap: 2px; }
.r-pc { display: block; width: auto; padding: 4px 6px; font: 34px/1 var(--brush); text-shadow: 0 0 12px rgba(var(--accent-rgb), .35); }
.r-head { padding: 8px 10px 10px; border-bottom: 1px solid rgba(255, 255, 255, .06); margin-bottom: 6px; display: flex; flex-direction: column; gap: 4px; }
.r-head-t { font-size: 12px; letter-spacing: .18em; text-transform: uppercase; color: var(--accent); }
.r-head-x { font: 15px/1.4 var(--kai); color: var(--dim); letter-spacing: .08em; }
.r-none { padding: 18px 4px; color: rgba(243, 236, 220, .38); font-style: italic; font-size: 14px; }

/* ---------------------------------------------------------------- wheel (3D drum) */
#browse { display: flex; flex-direction: column; gap: 10px; flex: 1; min-height: 0; }
.wheel {
  position: relative; flex: 1; min-height: 240px; overflow: hidden; outline: none;
  perspective: 900px; cursor: grab; touch-action: none; border-radius: 18px;
  -webkit-mask-image: linear-gradient(transparent, #000 18%, #000 82%, transparent);
          mask-image: linear-gradient(transparent, #000 18%, #000 82%, transparent);
}
.wheel:active { cursor: grabbing; }
.wheel-drum { position: absolute; inset: 0; transform-style: preserve-3d; }
.wheel-item {
  position: absolute; left: 0; right: 0; top: 50%; height: 58px; margin-top: -29px;
  display: grid; grid-template-columns: 58px 1fr; align-items: center; gap: 12px; padding: 0 16px;
  backface-visibility: hidden; will-change: transform, opacity; color: rgba(243, 236, 220, .7);
}
.wheel-item .wh-char { font: 34px/1 var(--brush); text-align: center; transition: color .25s, text-shadow .25s; }
.wheel-item .wh-meta { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.wheel-item .wh-py { font-size: 14px; color: rgba(var(--accent-rgb), .7); }
.wheel-item .wh-en { font-size: 12px; color: rgba(243, 236, 220, .4); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wheel-item.center { color: var(--ink); }
.wheel-item.center .wh-char { color: #fff8e8; text-shadow: 0 0 10px rgba(var(--accent-rgb), .8), 0 0 28px rgba(var(--accent-rgb), .5); }
.wheel-item.center .wh-py { color: var(--accent); }
.wheel-item.center .wh-en { color: rgba(243, 236, 220, .78); }
.wheel-reticle {   /* centre reticle: a lit band with brush-bracket ends */
  position: absolute; left: 6px; right: 6px; top: 50%; height: 60px; transform: translateY(-50%); pointer-events: none; border-radius: 14px;
  background: radial-gradient(70% 130% at 28% 50%, rgba(var(--accent-rgb), .13), transparent 70%);
  box-shadow: inset 0 1px 0 rgba(var(--accent-rgb), .22), inset 0 -1px 0 rgba(var(--accent-rgb), .22);
}
.wheel-reticle i { position: absolute; top: 8px; bottom: 8px; width: 7px; border: 1.5px solid rgba(var(--accent-rgb), .6); }
.wheel-reticle i:first-child { left: 2px; border-right: 0; border-radius: 6px 0 0 6px; }
.wheel-reticle i:last-child { right: 2px; border-left: 0; border-radius: 0 6px 6px 0; }
.wheel:focus-visible .wheel-reticle { box-shadow: inset 0 1px 0 rgba(var(--accent-rgb), .55), inset 0 -1px 0 rgba(var(--accent-rgb), .55); }

/* ---------------------------------------------------------------- small screens */
@media (max-width: 899px) {
  #dock { top: 0; right: 0; bottom: 0; width: min(90vw, 380px); border-radius: 22px 0 0 22px; }
  body.dock-open #scrim { display: block; }
  .cn-node { width: 36px; height: 36px; font-size: 20px; }
}
@media (max-height: 600px) { .wheel { min-height: 160px; } #dock { gap: 10px; } .cadence button { padding: 6px 10px; } }
@media (max-width: 520px) {
  :root { --g: min(38vh, 64vw); }
  body[data-mode="step"] { --g: min(38vh, 70vw); }
  .ctx { flex-direction: column; align-items: center; gap: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .sky { animation: none; }
  #card.ink-in #glyphwrap, #card.ink-in #pinyin, #card.ink-in #english, #card.ink-in #context, #card.ink-in #pairs, #card.ink-in #meta,
  #card.breath-out #glyphwrap, #card.fade-out #glyphwrap, #card.swap-out #glyphwrap { animation-duration: .35s; animation-delay: 0s; }
  .cn-thread { transition-duration: .3s; }
  .music-enter::after, .music-enter[aria-pressed="true"] b, #controls button[data-act="music"][aria-pressed="true"] span { animation: none; }
}
.moods { flex-wrap: nowrap; }
.moods button { padding: 6px 4px; font-size: 11px; white-space: nowrap; flex: 1 1 0; }
