* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #fdf6ec;
  --card: #ffffff;
  --ink: #2d2a32;
  --muted: #8b8698;
  --accent: #7c5cff;
  --accent-soft: #ece6ff;
  --good: #22b573;
  --bad: #ff5a5f;
  --warn: #ffb020;
  --ring-track: #efe8db;
  --shadow: 0 6px 24px rgba(60, 40, 120, 0.12);
  --radius: 20px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1a24;
    --card: #2a2735;
    --ink: #f3f0fa;
    --muted: #a49fb5;
    --accent: #9d85ff;
    --accent-soft: #3a3352;
    --ring-track: #3a3646;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  }
}

html, body { height: 100%; }
/* No layout should ever scroll the page sideways on a phone. `clip` rather
   than `hidden`: `hidden` on one axis coerces the other from visible to
   auto, which would make <body> its own scroll container and stop the mobile
   URL bar collapsing. */
html, body { max-width: 100%; overflow-x: clip; }

/* THE COLOUR LIVES ON <html>, NOT ON <body>.
   <body>'s background used to propagate to the canvas, which is what paints the safe
   area behind the Dynamic Island and the overscroll at both ends. Colouring <html> to
   fix that (setBackdrop writes the sky's top colour there) stops the propagation — and
   body then paints its OWN background box, which in CSS painting order comes AFTER
   negative-z-index layers. #backdrop is z-index -1, so the sky, the glow and the ruled
   notebook pattern all vanished under a flat slab of cream. Body must stay transparent:
   inside the viewport the backdrop is the background, and outside it <html> is. */
/* ---------- The glass material ----------
   One definition, used by the phone's 菜单 board and by the question card (owner,
   2026-09-21: "now since the glass effect works, can you do the same effect to the
   question box for all devices"). It is a PANE OF EDGES: no fill and no backdrop
   filter, because the blur is what hides the page behind it. The rim is two-tone —
   white inside a darker ring — since a white-only edge disappears on a pale sky. */
:root {
  --glass-border: rgba(255, 255, 255, 0.95);
  --glass-edge:
    0 0 0 1.5px rgba(96, 72, 168, 0.26),           /* outer ring — the outline you see */
    inset 0 1.5px 0 rgba(255, 255, 255, 0.95),     /* lit top bevel */
    inset 0 -1.5px 0 rgba(95, 70, 165, 0.3),       /* shaded bottom bevel */
    inset 0 0 0 3px rgba(255, 255, 255, 0.25),     /* inner hairline = thickness */
    0 1px 0 rgba(255, 255, 255, 0.55),             /* the lip catching the light */
    0 16px 32px rgba(70, 45, 130, 0.22);           /* lift off the page */
}
@media (prefers-color-scheme: dark) {
  :root {
    --glass-border: rgba(255, 255, 255, 0.45);
    --glass-edge:
      0 0 0 1.5px rgba(0, 0, 0, 0.45),
      inset 0 1.5px 0 rgba(255, 255, 255, 0.5),
      inset 0 -1.5px 0 rgba(0, 0, 0, 0.55),
      inset 0 0 0 3px rgba(255, 255, 255, 0.1),
      0 16px 32px rgba(0, 0, 0, 0.5);
  }
}

/* ™ (U+2122) beside the wordmark. Small, raised, and it must add NO line height, or a
   header laid out in a nowrap row grows a pixel and the brand starts truncating.
   ™, not ®: ® may only be used once the mark is REGISTERED — in China putting it on a
   mark that is merely accepted for examination is 冒充注册商标 and fineable. */
.tm {
  font-size: 0.5em;
  font-weight: 700;
  vertical-align: super;
  line-height: 0;
  margin-left: 1px;
  opacity: 0.75;
}

html { background: var(--bg); }

body {
  font-family: "Fredoka", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background: transparent;
  color: var(--ink);
  overscroll-behavior: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 900px;
  margin: 0 auto;
  padding: 12px 16px;
  gap: 10px;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.brand {
  font-size: clamp(1.2rem, 4vw, 1.6rem);
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.5px;
  /* Acts as the "home" link, like a site logo */
  background: none;
  border: none;
  padding: 0;
  font-family: inherit;
  cursor: pointer;
  touch-action: manipulation;
}
.brand:active { transform: scale(0.97); }
.brand { display: inline-flex; align-items: center; gap: 7px; line-height: 1; }
.brand img { width: 1.45em; height: 1.45em; flex: 0 0 auto; }
/* 布狸词 after the English name, styled like the splash title's subline */
.brand-zh {
  font-size: 0.62em;
  font-weight: 600;
  letter-spacing: 0.2em;
  color: var(--ink);
  opacity: 0.62;
  white-space: nowrap;
}

.player {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  /* Must wrap: on narrow phones the toggles + 3 score boxes + help button
     are wider than the viewport and would force horizontal page scroll. */
  flex-wrap: wrap;
  gap: 6px 10px;
  min-width: 0;
  font-size: clamp(0.85rem, 3vw, 1rem);
}

.nick {
  background: var(--accent-soft);
  color: var(--accent);
  border: none;
  border-radius: 999px;
  padding: 4px 12px;
  font-family: inherit;
  font-size: inherit;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  max-width: 44vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

.scorebox { font-weight: 600; white-space: nowrap; }

/* 错题本 button (header) */
.nb-btn {
  background: var(--accent-soft);
  color: var(--accent);
  border: none;
  border-radius: 999px;
  padding: 4px 11px;
  font-family: inherit;
  font-size: inherit;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
}
.nb-btn:active { transform: scale(0.96); }
.review-btn { background: #dff5e6; color: #1d8a4e; }
.streakbox .goal-sep { color: var(--muted); }
.hint-step-btn {
  border: 2px solid var(--ring-track);
  background: var(--card);
  color: var(--ink);
  border-radius: 999px;
  padding: 3px 10px;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}
.hint-step-btn.used { border-color: var(--warn); color: var(--warn); }
.optin-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  text-align: left;
  font-size: 0.78rem;
  line-height: 1.6;
  color: var(--muted);
  margin: 8px 0 2px;
}
.optin-row input { margin-top: 3px; flex: 0 0 auto; }
.progress-box {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0 4px;
}
.progress-cell {
  background: var(--accent-soft);
  border-radius: 12px;
  padding: 8px 6px;
  text-align: center;
  font-size: 0.78rem;
  color: var(--muted);
}
.progress-cell b { display: block; font-size: 1.15rem; color: var(--ink); }
.badge-row { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.badge-chip { background: #fff3d1; color: #8a5a00; border-radius: 999px; padding: 3px 10px; font-size: 0.78rem; font-weight: 600; }
@media (prefers-color-scheme: dark) { .badge-chip { background: #4a3a12; color: #ffd98a; } }
/* Tap a word in the sentence for its meaning */
.word {
  cursor: help;
  border-bottom: 1px dotted transparent;
  transition: border-color .15s, background .15s;
  border-radius: 3px;
}
.word:hover, .word.on { border-bottom-color: var(--accent); background: var(--accent-soft); }
.word-card {
  position: fixed;
  z-index: 55;
  max-width: min(280px, 86vw);
  background: var(--card);
  color: var(--ink);
  border-radius: 14px;
  box-shadow: var(--shadow);
  border: 2px solid var(--accent-soft);
  padding: 10px 13px;
  text-align: left;
  font-size: 0.9rem;
  line-height: 1.5;
}
.word-head { display: flex; align-items: baseline; gap: 7px; flex-wrap: wrap; }
.word-head b { font-size: 1.05rem; color: var(--accent); }
.word-head #wordCardKana { font-size: 0.85rem; color: var(--muted); }
.word-pos {
  margin-left: auto;
  font-size: 0.72rem;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  padding: 1px 8px;
}
.word-zh { margin-top: 4px; font-weight: 600; }
.word-en { color: var(--muted); font-size: 0.82rem; }
.badge-toast {
  position: fixed;
  left: 50%;
  bottom: 18%;
  transform: translateX(-50%);
  z-index: 60;
  background: var(--card);
  color: var(--ink);
  border-radius: 999px;
  padding: 10px 20px;
  font-weight: 700;
  box-shadow: var(--shadow);
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 22px;
  /* A fixed box with only `left: 50%` may use HALF the viewport at most, so on a phone
     the two flex children were squeezed into ~195 px and the Chinese wrapped one
     character per line. `max-content` sizes it to its text and the max-width brings it
     back inside the screen; wrapping puts the second line under the first instead of
     beside it. */
  width: max-content;
  max-width: min(560px, calc(100vw - 28px));
  flex-wrap: wrap;
  justify-content: center;
  text-align: center;
}
.badge-toast .toast-main, .badge-toast .zh-sub { flex-basis: 100%; }
.badge-toast .badge-art { width: 62px; margin: 0; }
.exit-review {
  border: 2px solid var(--ring-track);
  background: var(--card);
  color: var(--accent);
  border-radius: 999px;
  padding: 3px 10px;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

@media (prefers-color-scheme: dark) { .review-btn { background: #234634; color: #7ae0a8; } }

/* 4. Sentences are our content: not selectable or copyable (the answer
   boxes stay fully editable). */
.sentence, .romaji, .translation, .lb, .card-meta, .vote-row {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.sentence .blank { -webkit-user-select: text; user-select: text; }

/* Realms/levels the free taster doesn't cover yet */
.realm-chip.locked, .diff-menu button.locked { opacity: 0.5; }
.realm-chip.locked::after, .diff-menu button.locked::after { content: " 🔒"; font-size: 0.8em; }

/* 👍/👎 on the resolved sentence */
.vote-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 2px;
}
.vote-q { font-size: 0.85rem; color: var(--muted); }
.vote-q .zh-sub { margin-left: 6px; }
.vote-btn {
  border: 2px solid var(--ring-track);
  background: var(--card);
  border-radius: 999px;
  padding: 4px 14px;
  font-size: 1.05rem;
  line-height: 1.4;
  cursor: pointer;
  touch-action: manipulation;
}
.vote-btn:active { transform: scale(0.95); }
.vote-btn.picked { border-color: var(--accent); background: var(--accent-soft); }

/* ---------- Avatar (header, top right) ---------- */
.avatar-btn {
  width: 38px;
  height: 38px;
  padding: 0;
  margin: 0 4px;
  border: 2px solid var(--accent-soft);
  border-radius: 50%;
  background: var(--card);
  box-shadow: var(--shadow);
  overflow: hidden;
  cursor: pointer;
  flex: 0 0 auto;
  touch-action: manipulation;
}
.avatar-btn img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-btn:active { transform: scale(0.95); }

/* ---------- Profile panel ---------- */
.profile-head { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: 4px; }
.profile-avatar {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--accent-soft);
  background: var(--card);
}
.avatar-note { margin: 0; font-size: 0.8rem; color: var(--muted); text-align: center; }
.gender-row { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 8px 0; flex-wrap: wrap; }
.gender-row label { font-weight: 600; font-size: 0.9rem; text-align: right; }
.gender-sel {
  font-family: inherit;
  font-size: 0.9rem;
  padding: 6px 10px;
  border-radius: 10px;
  border: 2px solid var(--ring-track);
  background: var(--card);
  color: var(--ink);
}
.login-fields { display: flex; flex-direction: column; gap: 8px; margin: 6px 0; }
/* Refund policy + refund requests (owner, 2026-09-23). */
.refund-policy { margin: 6px 0 10px; padding-left: 1.3em; display: grid; gap: 8px; text-align: left; font-size: 0.92rem; line-height: 1.5; }
.refund-policy .zh-sub { display: block; }
.consent-row { display: flex; align-items: flex-start; gap: 8px; margin: 10px 0 12px; text-align: left; font-size: 0.95rem; cursor: pointer; }
.consent-row input { margin-top: 4px; width: 18px; height: 18px; flex: 0 0 auto; }
.consent-row .zh-sub { display: block; }
.choice-row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.choice-row .retry-btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.refund-policy-box { margin-top: 12px; text-align: left; font-size: 0.9rem; }
.refund-policy-box summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.refund-hist { margin: 10px 0 0; padding: 0; list-style: none; display: grid; gap: 6px; text-align: left; font-size: 0.9rem; }
.refund-hist li { padding: 8px 10px; border-radius: 10px; background: var(--accent-soft); }
.refund-form { display: flex; flex-direction: column; align-items: stretch; gap: 8px; width: 100%; margin-top: 6px; text-align: left; }
.refund-form.hidden { display: none; }
.refund-form > .login-input { flex: 0 0 auto; width: 100%; max-width: none; box-sizing: border-box; margin: 0; }
.refund-form > .retry-btn { align-self: stretch; margin-top: 6px; }
.refund-label { font-weight: 700; font-size: 0.95rem; margin-top: 4px; }
.refund-label .zh-sub { display: inline; margin-left: 6px; font-weight: 500; }
.refund-est { margin: 0; text-align: left; }
.danger-link { color: #c0392b; margin-top: 10px; font-size: 0.9rem; }
.danger-box { text-align: left; line-height: 1.65; padding: 10px 14px; border-radius: 10px; border: 1px solid #e4a09a; background: rgba(231, 76, 60, 0.08); }
.danger-box ul { margin: 6px 0 4px; padding-left: 1.2em; }
.retry-btn.danger-btn { background: #c0392b; }
.retry-btn.danger-btn:disabled { opacity: 0.45; }
.refund-pending { text-align: left; line-height: 1.6; padding: 10px 12px; border-radius: 10px; border: 1px solid #e0b64a; background: rgba(255, 214, 102, 0.18); }
#refundReason { resize: vertical; min-height: 96px; font: inherit; line-height: 1.5; }
#refundPolicyLink { display: block; margin: 8px auto 2px; }

.link-btn {
  background: none;
  border: none;
  padding: 2px;
  color: var(--accent);
  font-family: inherit;
  font-size: 0.85rem;
  text-decoration: underline;
  cursor: pointer;
}
.link-btn .zh-sub { color: var(--accent); }

/* ---------- Avatar cropper ---------- */
.crop-stage {
  width: min(240px, 70vw);
  max-width: 100%;
  aspect-ratio: 1;
  margin: 10px auto 4px;
  border-radius: 50%;
  overflow: hidden;
  box-shadow: 0 0 0 3px var(--accent-soft);
  touch-action: none;
  cursor: grab;
}
.crop-stage canvas { width: 100%; height: 100%; display: block; }
.crop-zoom { display: block; width: min(240px, 70vw); max-width: 100%; margin: 6px auto; }

/* ---------- World ranking ---------- */
:root { --lb-row: 44px; }
.lb {
  width: 100%;
  max-width: 640px;
  margin: 4px auto 0;
  padding: 12px 10px 10px;
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.lb-head { display: flex; align-items: center; gap: 8px; padding: 0 4px 8px; border-bottom: 2px dashed var(--ring-track); }
.lb-civet { width: 30px; height: 30px; flex: 0 0 auto; }
.lb-title b { font-size: 1rem; }
.nick-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.nick-row label { font-size: 0.85rem; font-weight: 600; white-space: nowrap; text-align: left; }
.nick-input { flex: 1; min-width: 0; margin: 0; }
.nick-save { flex: 0 0 auto; width: auto; margin: 0; padding: 8px 14px; }
.lb-lang {
  margin-left: auto;
  font-family: inherit;
  font-size: 0.8rem;
  padding: 4px 6px;
  border-radius: 10px;
  border: 2px solid var(--ring-track);
  background: var(--card);
  color: var(--ink);
}
.lb-view {
  position: relative;
  height: calc(10 * var(--lb-row) + 16px);
  margin-top: 6px;
  overflow: hidden;
  touch-action: none; /* the board's own flick scrolling handles touch */
  cursor: grab;
  user-select: none;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 14px, #000 calc(100% - 14px), transparent 100%);
  mask-image: linear-gradient(to bottom, transparent 0, #000 14px, #000 calc(100% - 14px), transparent 100%);
}
.lb-view.dragging { cursor: grabbing; }
.lb-view.lb-fit { height: auto; } /* fewer than 10 learners: no blank space */
.lb-list { list-style: none; margin: 0; padding: 8px 0; will-change: transform; }
.lb-row { display: flex; align-items: center; gap: 8px; height: var(--lb-row); padding: 0 6px; border-radius: 12px; }
.lb-row.me { background: var(--accent-soft); }
.lb-rank {
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-weight: 700;
  font-size: 0.78rem;
  color: var(--muted);
}
.lb-row:nth-child(1) .lb-rank { background: #ffd65a; color: #6b4a00; }
.lb-row:nth-child(2) .lb-rank { background: #dfe3ea; color: #4b5160; }
.lb-row:nth-child(3) .lb-rank { background: #f3b98a; color: #6a3a12; }
.lb-avatar { width: 34px; height: 34px; flex: 0 0 auto; border-radius: 50%; object-fit: cover; background: var(--accent-soft); }
.lb-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: 0.88rem; }
.lb-score { font-weight: 700; font-size: 0.9rem; color: var(--accent); }
.lb-foot { padding-top: 6px; font-size: 0.8rem; color: var(--muted); text-align: center; }
.lb-empty { padding: 24px 8px; text-align: center; color: var(--muted); font-size: 0.9rem; }

/* Wide screens: one centred two-column layout — the header and realms span
   the full width, the ranking sits right beside the practice area. */
@media (min-width: 1200px) {
  .app {
    display: grid;
    max-width: 1240px;
    grid-template-columns: minmax(0, 1fr) 290px;
    grid-template-rows: auto auto 1fr auto;
    column-gap: 24px;
    row-gap: 10px;
    align-items: start;
  }
  .app > .topbar { grid-column: 1 / -1; }
  .app > .stage { grid-column: 1; grid-row: 3; align-self: stretch; justify-content: flex-end; } /* timer + card sit right beside the ranking */
  .app > .lb { grid-column: 2; grid-row: 3; align-self: center; width: auto; margin: 0; }
  .app > .hint { grid-column: 1 / -1; grid-row: 4; }
  .lb-view { height: min(calc(10 * var(--lb-row) + 16px), calc(100vh - 260px)); }
  .lb-view.lb-fit { height: auto; }
}
.scorebox.best { color: var(--muted); }

.help-btn {
  border: none;
  background: var(--card);
  border-radius: 50%;
  width: 30px;
  height: 30px;
  font-size: 0.85rem;
  cursor: pointer;
  box-shadow: var(--shadow);
  touch-action: manipulation;
}

.help-box {
  max-width: min(560px, 92vw);
  text-align: left;
}
.help-box h2 { font-size: 1.2rem; text-align: center; }
.help-body {
  max-height: 62vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 4px;
}
.help-body h3 { font-size: 0.98rem; margin-top: 8px; color: var(--accent); }
.help-body p { font-size: 0.9rem; line-height: 1.55; }
.help-box .retry-btn { align-self: center; }

/* ---------- Realm chips ---------- */
/* Now a child of .topbar (so one glass board can hold the whole header on a phone):
   a full-width flex item, which puts it on its own line exactly as before. */
.realms-row { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 100%; }
.realms-row > .realms { flex: 1 1 auto; min-width: 0; }
.avatar-big { display: none; } /* portrait phones keep the header avatar exactly as it was */
.realms {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 2px 8px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.realms::-webkit-scrollbar { display: none; }
/* Mouse/trackpad devices can't swipe: give the realm row a thin scrollbar
   that shows while the cursor is over it (space always reserved, so the row
   doesn't jump). Touch screens keep swiping with no bar. */
@media (hover: hover) and (pointer: fine) {
  /* Chrome/Safari: a styled ::-webkit-scrollbar is always drawn (macOS
     overlay bars would only appear mid-scroll). Chrome ignores these
     styles if scrollbar-width/-color are set, so reset them to auto. */
  .realms { scrollbar-width: auto; scrollbar-color: auto; }
  .realms::-webkit-scrollbar { display: block; height: 6px; }
  .realms::-webkit-scrollbar-track { background: transparent; }
  .realms::-webkit-scrollbar-thumb { background: transparent; border-radius: 3px; }
  .realms:hover::-webkit-scrollbar-thumb,
  .realms:focus-within::-webkit-scrollbar-thumb { background: var(--muted); }
  /* Firefox has no ::-webkit-scrollbar: use the standard properties. */
  @supports not selector(::-webkit-scrollbar) {
    .realms { scrollbar-width: thin; scrollbar-color: transparent transparent; }
    .realms:hover, .realms:focus-within { scrollbar-color: var(--muted) transparent; }
  }
}

.realm-chip {
  flex: 0 0 auto;
  border: 2px solid transparent;
  background: var(--card);
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 16px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.15s, border-color 0.15s, background 0.15s;
}
.realm-chip:active { transform: scale(0.94); }
.realm-chip.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ---------- Stage: timer + card ---------- */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 8px 0;
}

/* Landscape / wide screens: timer beside the card */
@media (min-width: 640px) and (orientation: landscape), (min-width: 820px) {
  .stage { flex-direction: row; }
}

.timer-wrap {
  position: relative;
  width: clamp(110px, 22vmin, 160px);
  height: clamp(110px, 22vmin, 160px);
  flex: 0 0 auto;
}

.timer-ring { width: 100%; height: 100%; transform: rotate(-90deg); }

.ring-bg {
  fill: none;
  stroke: var(--ring-track);
  stroke-width: 10;
}

.ring-fg {
  fill: none;
  stroke: var(--good);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-dasharray: 326.7;  /* 2πr, r=52 */
  stroke-dashoffset: 0;
}

.timer-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
}

/* Mascot in the countdown ring: one drawing, four expressions swapped by
   the timer as the remaining time drops. */
.timer-civet {
  width: clamp(2.3rem, 8.4vmin, 3.4rem);
  height: auto;
  display: block;
  overflow: visible;
}
.timer-civet .mood { display: none; }
.timer-civet[data-mood="happy"] .m-happy,
.timer-civet[data-mood="ok"] .m-ok,
.timer-civet[data-mood="worry"] .m-worry,
.timer-civet[data-mood="panic"] .m-panic { display: block; }
.timer-civet[data-mood="panic"] { animation: wb-tremble 0.32s linear infinite; }

@keyframes wb-tremble {
  0%, 100% { transform: translateX(0) rotate(0deg); }
  25%      { transform: translateX(-1.5px) rotate(-3deg); }
  75%      { transform: translateX(1.5px) rotate(3deg); }
}

@media (prefers-reduced-motion: reduce) {
  .timer-civet[data-mood="panic"] { animation: none; }
}
.timer-secs { font-size: clamp(1.1rem, 4vmin, 1.5rem); font-weight: 700; }

.timer-wrap.urgent { animation: pulse 0.5s infinite alternate; }
@keyframes pulse {
  from { transform: scale(1); }
  to { transform: scale(1.06); }
}

/* ---------- Sentence card ---------- */
/* The question box is glass on every device: the notebook rules and the sky run
   straight through it, and only its edges say where it is. */
.card {
  background: transparent;
  border: 1.5px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--glass-edge);
  padding: clamp(18px, 4vw, 32px);
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card-meta > * { flex-shrink: 0; white-space: nowrap; }
.card-meta {
  display: flex;
  flex-wrap: wrap; /* on a phone the buttons take a second row instead of squeezing into vertical text */
  align-items: center;
  gap: 6px 10px;
  font-size: 0.85rem;
  color: var(--muted);
}

.realm-label {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 8px;
  padding: 2px 10px;
  font-weight: 600;
  text-transform: capitalize;
}

.streak-label { margin-left: auto; font-weight: 600; color: var(--warn); }

.lang-wrap { position: relative; }

.lang-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  min-width: 140px;
  background: var(--card);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
#langMenu {
  max-height: min(70vh, 480px);
  overflow-y: auto;
}
.lang-menu button {
  border: none;
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: left;
  padding: 10px 14px;
  cursor: pointer;
}
.lang-menu button:hover { background: var(--accent-soft); }
.lang-menu button.active { color: var(--accent); }
.lang-menu button.active::after { content: " ✓"; }

.diff-icon {
  width: 1.35em;
  height: 1.35em;
  vertical-align: -0.32em;
  margin-right: 4px;
}

/* Voice dropdown: many voices, so it scrolls; the label can be a long
   system voice name, so it is capped. */
.voice-toggle {
  max-width: 8.5em;
  overflow: hidden;
  text-overflow: ellipsis;
}

.voice-menu {
  right: 0;
  left: auto;
  max-height: 58vh;
  overflow-y: auto;
  min-width: min(240px, 74vw);
  max-width: 74vw;
  padding-bottom: 2px;
}
.voice-menu button { white-space: normal; }

.voice-head {
  padding: 8px 14px 3px;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: .04em;
}

.voice-note {
  padding: 8px 14px 10px;
  font-size: 0.72rem;
  line-height: 1.5;
  color: var(--muted);
  border-top: 1px solid var(--ring-track);
}

.lang-toggle {
  border: none;
  background: var(--card);
  color: var(--ink);
  border-radius: 999px;
  padding: 4px 12px;
  font-family: inherit;
  font-size: inherit;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow);
  white-space: nowrap;
  touch-action: manipulation;
}

.speak-btn {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  border: 2px solid var(--ring-track);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 1px 10px 1px 5px;
  font-family: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
}
.speak-btn:active { background: var(--accent-soft); }
.bundle-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.speak-btn.hidden { display: none; }
/* the hint was used on this sentence (it now scores half) */
.speak-btn.used { border-color: var(--accent); color: var(--accent); }
.speak-icon { height: 1.55em; width: auto; }

.hint-title-icon { height: 1.5em; width: auto; vertical-align: -0.35em; margin-right: 6px; }
.hint-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }

.zh-toggle {
  border: 2px solid var(--ring-track);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 2px 10px;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  touch-action: manipulation;
}
.zh-toggle.on {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.translation {
  font-size: clamp(0.85rem, 3vw, 1rem);
  color: var(--muted);
  line-height: 1.6;
}

/* Romaji under a Japanese sentence (owner, 2026-09-26: "too difficult … even in easy mode,
   because they even don't know the romaji of the unblanked words"). The blanks' own words
   show as ＿＿ until the sentence is answered, so the line helps reading, never answers. */
.romaji {
  margin: -0.35em 0 0.35em;
  font-size: clamp(0.8rem, 2.9vw, 0.95rem);
  line-height: 1.5;
  color: var(--muted);
  letter-spacing: 0.01em;
  overflow-wrap: anywhere;
}
.sentence {
  font-size: clamp(1.15rem, 4.5vw, 1.6rem);
  line-height: 2;
  word-break: normal;
  overflow-wrap: break-word;
}

.blank {
  display: inline-block;
  border: none;
  border-bottom: 3px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-family: inherit;
  font-size: inherit;
  font-weight: 600;
  text-align: center;
  outline: none;
  padding: 0 2px;
  margin: 0 2px;
  border-radius: 4px 4px 0 0;
  min-width: 3.5ch;
  transition: background 0.15s, border-color 0.15s;
}
.blank:focus { background: var(--accent-soft); }
.blank.ok { color: var(--good); border-bottom-color: var(--good); }
.blank.nope { color: var(--bad); border-bottom-color: var(--bad); animation: shake 0.35s; }
.blank.fixed { color: var(--warn); border-bottom-color: var(--warn); }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}

.card-actions { display: flex; justify-content: center; }

.check-btn {
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 999px;
  padding: 12px 40px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.12s, opacity 0.12s;
  touch-action: manipulation;
}
.check-btn:active { transform: scale(0.95); }
.check-btn:disabled { opacity: 0.45; cursor: default; }

.feedback {
  min-height: 1.6em;
  text-align: center;
  font-weight: 600;
  font-size: 1.05rem;
}
.fb-icon {
  width: 1.7em;
  height: 1.7em;
  vertical-align: -0.5em;
  margin-right: 6px;
}
.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); }

.hint {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  padding-bottom: 6px;
}
.copyright {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.72rem;
  opacity: 0.8;
}
.copyright a { color: var(--muted); }

kbd {
  background: var(--card);
  border-radius: 5px;
  padding: 1px 6px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
  font-family: inherit;
}

/* ---------- Pause button (centered below the question card) ---------- */
.card-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
  max-width: 640px;
}

.pause-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 3px solid var(--accent-soft);
  background: var(--card);
  box-shadow: var(--shadow);
  font-size: 1.7rem;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.12s;
  touch-action: manipulation;
}
.pause-btn:active { transform: scale(0.9); }

/* A DELIBERATE pause hides the sentence (owner, 2026-09-20, reversing the 2026-09-15
   "no blur" rule: "the sentence blurs so paused time can't be used to think … this is
   more scientific for learning"). Blurred: the sentence with its answer boxes, the
   Chinese line, 💡 提示 and 朗读原句 — every way of working on the answer while the
   clock is stopped. pointer-events go with the blur, or a blurred 朗读原句 would still
   play and a blurred word would still open its meaning card.
   `think-lock` is set only for a real break (the ⏸️ button, or the page being hidden);
   a dialog or the handwriting download pauses `quiet`ly and leaves the sentence alone,
   because a dialog already covers it and the word card is read WITH the sentence.
   The answer boxes stay locked until Resume either way (pauseGame disables them). */
body.paused .timer-wrap { opacity: 0.55; }
body.paused .pause-btn { background: var(--accent); border-color: var(--accent); }
body.think-lock #sentence,
body.think-lock #romaji,
body.think-lock #translation,
body.think-lock #hintBtn,
body.think-lock #speakBtn {
  filter: blur(7px);
  pointer-events: none;
  user-select: none;
}
#sentence, #translation, #hintBtn, #speakBtn { transition: filter 0.18s ease; }
@media (prefers-reduced-motion: reduce) {
  #sentence, #translation, #hintBtn, #speakBtn { transition: none; }
}

/* ---------- Splash (main page) ---------- */
.splash {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  text-align: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 15%, var(--accent-soft), transparent 45%),
    radial-gradient(circle at 85% 80%, var(--accent-soft), transparent 40%),
    var(--bg);
  transition: opacity 0.35s ease;
}
/* The splash is hidden, not destroyed, so returning home keeps the drawn
   sentence queue (already paid for) intact. */
.splash.leaving {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transition: opacity 0.35s ease, visibility 0s linear 0.35s;
}

/* ---------- The front page's animation ----------
   Everything it draws is in public/intro.js; this only gives it a box. The box is WIDER than
   it is tall on purpose: the widest moment of the loop is the string, which is the circle
   unrolled and so 2πR long, and the tallest is the three circles. */
.logo-stage {
  position: relative;
  width: min(340px, 82vw);
  height: clamp(104px, 27vmin, 150px);
  margin-bottom: 2px;
}
.intro-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.splash-title {
  font-size: clamp(2rem, 8vmin, 3.2rem);
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 1px;
  line-height: 1.15;
}

.splash-title-zh {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.3em;
  font-size: 0.42em;
  font-weight: 600;
  letter-spacing: 0.34em;
  text-indent: 0.34em; /* balance the trailing letter-space */
  color: var(--ink);
  margin-top: 6px;
}
/* The fade is on the WORDS only — on the whole line it washed the logo out too. */
.splash-title-zh .zh-word { opacity: 0.62; text-indent: 0; }   /* the logo now sits where the indent was */
/* The civet beside 布狸词, as tall as the characters (owner, 2026-09-22). civet.svg keeps a
   ground shadow under the head, so the drawn head is only ~2/3 of the image: the image is
   sized up and its margins pulled in, so the HEAD matches the glyphs without making the
   line any taller. */
.zh-logo {
  display: block;
  height: 1.45em;
  width: auto;
  margin: -0.22em 0 -0.18em;
  flex: 0 0 auto;
}

.splash-tagline {
  font-size: clamp(0.95rem, 3.5vw, 1.15rem);
  color: var(--muted);
  max-width: 30em;
  line-height: 1.6;
}

.splash-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 600;
}
.splash-chips span {
  background: var(--card);
  border-radius: 999px;
  padding: 6px 14px;
  box-shadow: var(--shadow);
}

.start-btn {
  margin-top: 14px;
  font-family: inherit;
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 999px;
  padding: 14px 52px;
  cursor: pointer;
  box-shadow: 0 8px 28px rgba(124, 92, 255, 0.45);
  transition: transform 0.12s;
  touch-action: manipulation;
}
.start-btn:active { transform: scale(0.94); }
/* wordblitz.cn only: the ICP + 公安 filing numbers, which the Worker adds to relayed pages.
   Their own line, the two together, never split (owner, 2026-09-22). */
.cn-beian { display: block; margin-top: 3px; white-space: nowrap; }
.cn-beian a { color: inherit; text-decoration: none; }
.cn-beian img { vertical-align: -3px; margin-right: 2px; }
.cn-beian .cn-sep { opacity: 0.7; }
/* 关于我们 under 开始挑战 — wordblitz.cn only; the Worker adds it to relayed pages. Small and
   quiet on purpose: the big button is the one that starts learning. */
.about-link {
  margin-top: 4px;
  padding: 6px 14px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.9rem;
  text-decoration: none;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.25;
}
.about-link .about-en { font-size: 0.72em; opacity: 0.8; }
.about-link:hover { color: var(--accent); background: var(--accent-soft); }
.start-btn .zh-sub,
.start-btn .ja-sub { color: rgba(255, 255, 255, 0.85); margin-top: 1px; font-size: 0.7em; }

/* 📱 the app (owner, 2026-10-13) — a quiet pill under Start, and its dialog. */
.splash-links { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 6px 14px; margin-top: 8px; }
.splash-links .about-link { margin-top: 0; }
.app-promo {
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line, rgba(0, 0, 0, 0.08));
  border-radius: 999px;
  padding: 7px 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.25;
  touch-action: manipulation;
}
.app-promo .zh-sub, .app-promo .ja-sub { font-size: 0.78em; font-weight: 500; color: var(--muted); }
.app-promo:hover { color: var(--accent); }
.overlay-box.app-box { align-items: center; text-align: center; width: min(420px, 100%); max-width: 420px; gap: 8px; }
.app-icon { border-radius: 18px; box-shadow: var(--shadow); }
.app-title { margin: 2px 0 0; font-size: 1.15rem; }
.app-qr { width: 168px; height: 168px; background: #fff; border-radius: 12px; padding: 6px; }
.app-qr svg { width: 100%; height: 100%; display: block; }
.app-store-btn { text-decoration: none; display: inline-flex; flex-direction: column; align-items: center; }
.app-points { margin: 4px 0 0; padding: 0; list-style: none; display: grid; gap: 6px; font-size: 0.88rem; text-align: left; }
.app-points li::before { content: "✓ "; color: var(--accent); font-weight: 700; }
.app-regions { font-size: 0.78rem; }

/* Splash copyright: pinned near (not at) the bottom, out of the content flow */
.splash .copyright {
  position: absolute;
  left: 24px;
  right: 24px;
  bottom: calc(clamp(24px, 6vh, 56px) + env(safe-area-inset-bottom));
  margin-top: 0;
}

/* SHORT SCREENS: the pinned copyright sat ON the content (owner, 2026-10-13 — with 关于我们 and the two filing lines on
   .cn, then the 📱 app pill, a 1280×720 laptop, an iPhone SE and a landscape phone all overlapped). Below 800 px of height
   it joins the flow at the bottom: the two auto margins share the free space, so the content stays near the middle, and a
   screen too short for all of it scrolls instead of stacking text on text. */
@media (max-height: 800px) {
  .splash { justify-content: flex-start; overflow-y: auto; overscroll-behavior: contain; }
  .splash > .logo-stage { margin-top: auto; }
  .splash .copyright { position: static; margin-top: auto; padding-bottom: env(safe-area-inset-bottom); flex-shrink: 0; }
  .splash > * { flex-shrink: 0; }
}

/* ---------- Loading overlay ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 15, 40, 0.55);
  backdrop-filter: blur(3px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  /* Short screens (iPad landscape, landscape phones): the dialog must never
     grow past the viewport, or its ✕ ends up off-screen and unclickable. */
  padding: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
  overflow-y: auto;
}
.overlay.show { display: flex; }

.overlay-box {
  position: relative;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 36px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-width: 84vw;
  max-height: calc(100dvh - 20px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* .overlay-box is a column flexbox with a height cap and its own scroll, so its
   children inherit flex-shrink: 1 and are SQUEEZED when the content is taller than the
   screen. A text paragraph then collapses to its min-height and its words paint over
   whatever is beneath: the account panel's logout warning was four lines rendered in a
   16 px box, straight across the 发票 button (owner, 2026-09-21). Children keep their
   own height and the box scrolls, which is what the cap was for. */
.overlay-box > * { flex-shrink: 0; }

/* Invoice dialog: status block stays bounded however many orders exist */
#invIntro { max-height: 30vh; overflow-y: auto; }
/* Inner boxes no longer need their own caps — .overlay-box scrolls. */
.upgrade-box { max-height: none; }

/* Loading tips (random learning fact shown while anything loads) */
.tip-text {
  display: block;
  max-width: 22em;
  line-height: 1.7;
  font-size: 0.98rem;
}

/* Sticky, not absolute: the box itself scrolls, so ✕ must stay in view. */
.overlay-close {
  position: sticky;
  top: 0;
  align-self: flex-end;
  flex: 0 0 auto;
  margin: -12px -22px -22px auto;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  z-index: 2;
}

.spinner { font-size: 2.4rem; animation: bounce 0.9s infinite alternate; }
@keyframes bounce {
  from { transform: translateY(0) rotate(-8deg); }
  to { transform: translateY(-10px) rotate(8deg); }
}

/* ---------- Upgrade (WeChat Pay) ---------- */
.upgrade-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
  font-size: 0.95rem;
  max-height: 76vh;
  overflow-y: auto;
}
.upgrade-box .zh-sub { margin: 0 0 6px; }
.pay-qr {
  width: min(210px, 55vw);
  align-self: center;
  border-radius: 12px;
  margin: 6px 0;
}
.upgrade-box .retry-btn { align-self: center; margin-top: 6px; }
.paid-msg { text-align: center; font-weight: 600; color: var(--good); min-height: 1.2em; }
/* The spinning green ring for "being made" / "waiting for WeChat" (owner, 2026-09-23). */
.paid-msg.waiting { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px 8px; }
.paid-msg.waiting .zh-sub { flex-basis: 100%; }
.wb-spin {
  display: inline-block;
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: 3px solid rgba(34, 181, 115, 0.22);
  border-top-color: var(--good);
  animation: wb-spin 0.8s linear infinite;
}
@keyframes wb-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .wb-spin { animation-duration: 2.4s; } }
/* After a password is saved only the ✅ line stays; 修改密码 opens a fresh form. */
.pw-fields.pw-done > input, .pw-fields.pw-done > #pwSaveBtn { display: none; }
/* doubled class: must beat .retry-btn, which is declared later */
.ghost-btn.ghost-btn { background: var(--accent-soft); color: var(--accent); }
.ghost-btn.ghost-btn .zh-sub { color: var(--accent); opacity: 0.8; }

/* ---------- Account modal ---------- */
.acct-box { max-width: min(420px, 88vw); }
.acct-box h2 { font-size: 1.25rem; }

.id-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.id-chip {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 10px;
  padding: 8px 14px;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.5px;
  user-select: all;
  word-break: break-all;
}

.copy-btn {
  border: none;
  background: var(--card);
  box-shadow: var(--shadow);
  border-radius: 10px;
  width: 40px;
  height: 40px;
  font-size: 1.1rem;
  cursor: pointer;
}

.acct-hint { font-size: 0.9rem; color: var(--muted); line-height: 1.5; }
.buy-cn-note {
  display: block;
  margin-top: 0.75rem;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  background: #fff8e6;
  color: var(--ink);
  border: 1px solid rgba(180, 140, 40, 0.45);
}

/* Chinese sub-line shown under English UI text, smaller and muted. */
.zh-sub,
.ja-sub {
  display: block;
  font-size: 0.82em;
  font-weight: 500;
  color: var(--muted);
  margin-top: 3px;
  line-height: 1.5;
}
.retry-btn .zh-sub,
.retry-btn .ja-sub { color: rgba(255, 255, 255, 0.85); margin-top: 1px; }
.acct-plan {
  flex: 0 0 auto; /* in the flex column it must never be squeezed under the buttons */
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent);
  min-height: 1.2em;
  line-height: 1.55; /* it wraps to two lines for unlimited accounts */
  margin-bottom: 2px;
}

.login-row { display: flex; gap: 8px; }

.login-input {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 0.95rem;
  border: 2px solid var(--ring-track);
  border-radius: 10px;
  padding: 8px 12px;
  background: var(--bg);
  color: var(--ink);
  outline: none;
}
.login-input:focus { border-color: var(--accent); }

.login-err { color: var(--bad); font-size: 0.85rem; min-height: 1.2em; font-weight: 600; }

.retry-btn {
  font-family: inherit;
  font-weight: 700;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 10px 30px;
  cursor: pointer;
}
/* !important: components that set their own display (buttons, panels) used to beat this rule and stay visible. */
.hidden { display: none !important; }

/* ---------- Confetti + score float ---------- */
#confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
}

.score-float {
  position: fixed;
  z-index: 101;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--good);
  pointer-events: none;
  animation: floatUp 1.1s ease-out forwards;
}
@keyframes floatUp {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to { opacity: 0; transform: translateY(-70px) scale(1.3); }
}

/* ---------- v2: credits, email verification, bundle purchase ---------- */
.scorebox.credits { color: var(--accent); }

.pw-fields {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.pw-fields.hidden { display: none; } /* .hidden alone loses to the rule above */
.pw-fields .retry-btn { align-self: center; }

.buy-box { max-width: min(440px, 90vw); }

.bundles {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.bundle-btn {
  flex: 1 1 0;
  min-width: 96px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: var(--bg);
  border: 2px solid var(--ring-track);
  border-radius: 14px;
  padding: 12px 8px;
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--ink);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.12s;
  touch-action: manipulation;
}
.bundle-btn b { font-size: 1.25rem; color: var(--accent); }
.bundle-btn:active { transform: scale(0.96); }
.bundle-btn.active { border-color: var(--accent); background: var(--accent-soft); }
.bundle-btn .zh-sub { margin-top: 0; }

#qrBox {
  width: min(220px, 60vw);
  margin: 8px auto 4px;
  background: #fff;
  border-radius: 12px;
  padding: 8px;
  word-break: break-all;
}
#qrBox svg { display: block; width: 100%; height: auto; }

/* Very short viewports (landscape phones, spanned/half-screen windows):
   compress vertical rhythm so the pause control stays above the fold. */
@media (max-height: 470px) {
  .app { gap: 4px; padding: 6px 12px; }
  .stage { gap: 8px; padding: 2px 0; }
  .card-col { gap: 8px; }
  .card { gap: 8px; padding: 12px 16px; }
  .sentence { line-height: 1.7; }
  .pause-btn { width: 44px; height: 44px; font-size: 1.2rem; border-width: 2px; }
  .realms { padding: 2px 2px 4px; }
  .realm-chip { padding: 5px 12px; font-size: 0.85rem; }
  /* The ranking sits below the card on narrow screens and is ~300px tall,
     which pushed the pause control and footer off a landscape phone entirely.
     Practice comes first here; the ranking is still there in portrait. */
  .lb { display: none; }
  .timer-wrap { transform: scale(0.78); transform-origin: center; }
  .card-actions { margin-top: 2px; }
  /* Reclaim the last ~70px so the pause control AND the footer fit without
     scrolling on a landscape phone. */
  .app { gap: 2px; padding: 4px 10px; }
  .topbar { gap: 3px 6px; }
  .player { gap: 3px 6px; font-size: 0.76rem; }
  .avatar-btn { width: 30px; height: 30px; margin: 0 2px; }
  .card { padding: 8px 14px; gap: 6px; }
  .sentence { font-size: clamp(1rem, 3.4vw, 1.25rem); }
  .realms { padding: 0 2px 2px; }
  .feedback { min-height: 0; font-size: 0.78rem; }
  .vote-row { display: none; } /* 👍/👎 waits for a taller screen */
  .pause-btn { width: 38px; height: 38px; font-size: 1.05rem; }
  .hint { display: block; font-size: 0.68rem; padding-bottom: 0; }
  .hint #hintText { display: none; } /* the bilingual how-to is the tall part */
  .hint .copyright { margin-top: 2px; }
}

/* Small phones portrait: tighten paddings */
@media (max-width: 380px) {
  .app { padding: 8px 10px; }
  .card { padding: 16px 14px; }
  .player { gap: 5px 7px; }
  .brand { font-size: 1.05rem; }
}

/* ============================ 日语入门 · the starter book ============================
   Wide screens, iPads and landscape phones: a tab on the left edge that opens
   a drawer from the left. Portrait phones: a pill at the bottom-left that
   opens a bottom sheet. Shown only while learning Japanese (body.has-book). */
.book-btn {
  position: fixed;
  z-index: 40; /* under the splash (45) and dialogs (50) */
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
  padding: 20px 12px 20px 10px;
  padding-left: max(10px, env(safe-area-inset-left));
  border: none;
  border-radius: 0 20px 20px 0;
  background: var(--accent);
  color: #fff;
  font: inherit;
  /* Big and glowing on purpose: the owner found the small tab too easy to miss. */
  box-shadow: 0 8px 26px rgba(124, 92, 255, 0.45), var(--shadow);
  cursor: pointer;
  transition: padding 0.15s ease;
}
.book-btn[hidden] { display: none; }
.book-btn .bk-icon { font-size: 1.9rem; line-height: 1; }
.book-btn .bk-label { writing-mode: vertical-rl; letter-spacing: 0.16em; font-weight: 700; font-size: 1.18rem; }
.book-btn .bk-label-ja { writing-mode: vertical-rl; font-size: 0.78rem; opacity: 0.9; letter-spacing: 0.1em; }
@media (hover: hover) and (pointer: fine) { .book-btn:hover { padding-right: 18px; } }
.book-btn.nudge .bk-icon { animation: bk-nudge 1.8s ease-in-out infinite; }
@keyframes bk-nudge {
  0%, 70%, 100% { transform: rotate(0) scale(1); }
  78% { transform: rotate(-14deg) scale(1.15); }
  86% { transform: rotate(12deg) scale(1.15); }
}
/* Keep the tab from covering the page where the layout reaches the edge. */
@media (min-width: 700px) and (max-width: 1059px), (min-width: 1200px) and (max-width: 1399px), (max-height: 470px) {
  body.has-book .app, body.has-art .app { padding-left: 76px; }
}

/* The book is a page of its own on every device: it covers the practice
   screen completely, with a centred reading column (the "--bk-pad" padding
   keeps content at most 1080px wide however large the window is). */
.book-overlay {
  position: fixed;
  inset: 0;
  z-index: 49; /* just under dialogs, so buying or verifying opens on top of the book */
  display: none;
  background: var(--bg);
}
.book-overlay.show { display: block; }
body.book-open { overflow: hidden; }

/* A DIALOG TAKES THE SCROLL (owner, 2026-09-20: "when panel and pop-up window shows,
   the background page is still scrolling along with the finger … screen scrolling or
   clicking only control the most top layer"). `overflow: hidden` alone is not enough on
   iOS, which happily scrolls the body behind a fixed layer, so the locked body is also
   position: fixed with its scroll offset held in `top` and restored on close.
   overscroll-behavior stops a scroll that reaches the end of the dialog from chaining
   through to the page underneath. */
body.scroll-locked {
  position: fixed;
  left: 0;
  right: 0;
  width: 100%;
  overflow: hidden;
}
.overlay, .book-overlay { overscroll-behavior: contain; }
.book {
  --bk-pad: max(16px, env(safe-area-inset-left), calc((100vw - 1080px) / 2));
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  animation: bk-fade 0.18s ease-out;
}
@keyframes bk-fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.book-head {
  flex: 0 0 auto;
  background: var(--card);
  padding: max(12px, env(safe-area-inset-top)) var(--bk-pad) 0;
  box-shadow: 0 2px 10px rgba(20, 15, 40, 0.06);
}
.book-title { display: flex; align-items: center; gap: 8px; }
.book-name { flex: 1; min-width: 0; font-weight: 700; font-size: clamp(1.1rem, 2.2vw, 1.45rem); color: var(--accent); }
.book .bk-sub { font-weight: 400; font-size: 0.72rem; color: var(--muted); margin-left: 6px; }
.book-close {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  border-radius: 999px;
  padding: 7px 14px;
  background: var(--accent-soft);
  color: var(--accent);
  font: inherit;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
}
.bk-closelabel { font-size: 0.82rem; }
.bk-ro-toggle {
  flex: 0 0 auto;
  border: 1.5px solid var(--accent-soft);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 10px;
  font: inherit;
  font-size: 0.72rem;
  cursor: pointer;
}
.bk-ro-toggle { display: flex; flex-direction: column; align-items: center; line-height: 1.15; }
.bk-ro-toggle span { font-size: 0.58rem; opacity: 0.8; }
.bk-ro-toggle.on { background: var(--accent); color: #fff; border-color: transparent; }
.no-ro .bk-ro { display: none; }
/* Romaji off: the chart becomes a self-test — tap a kana to check it. */
.no-ro .bk-kana small { visibility: hidden; }
.book-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 10px 0 10px;
  scrollbar-width: none;
}
.book-tabs::-webkit-scrollbar { display: none; }
.book-tab {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.2;
  border: none;
  border-radius: 12px;
  padding: 6px 11px;
  background: var(--accent-soft);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}
.book-tab b { font-size: 0.86rem; font-weight: 600; }
.book-tab span { font-size: 0.62rem; opacity: 0.75; }
.book-tab.active { background: var(--accent); color: #fff; }

.book-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 14px var(--bk-pad) calc(40px + env(safe-area-inset-bottom));
}
.book .jp { font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", "Meiryo", sans-serif; }
.bk-loading { min-height: 120px; text-align: center; color: var(--muted); padding-top: 40px; line-height: 2; }
.bk-lead { font-size: 0.88rem; line-height: 1.65; margin: 8px 0 12px; }
.bk-note { font-size: 0.78rem; color: var(--muted); line-height: 1.55; margin: 2px 0 8px; }
.bk-muted { color: var(--muted); font-size: 0.82rem; }
.bk-h { font-size: 0.95rem; color: var(--ink); margin: 16px 0 6px; }

.bk-voices, .bk-chips, .bk-mode { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
#badgeLangTabs { flex-wrap: nowrap; overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; }
#badgeLangTabs .bk-chip { flex: 0 0 auto; }
.bk-voices > span { font-size: 0.78rem; color: var(--muted); margin-right: 2px; }
.bk-chips { margin: 10px 0 2px; }
.bk-mode { margin: 4px 0 12px; }
.bk-chip {
  border: none;
  border-radius: 999px;
  padding: 5px 12px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(20, 15, 40, 0.08);
}
.bk-chip.active { background: var(--accent); color: #fff; }

/* Kana charts */
.bk-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.bk-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.bk-kana {
  position: relative;
  min-height: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(20, 15, 40, 0.08);
  padding: 6px 2px;
}
.bk-kana b { font-size: 1.55rem; font-weight: 500; line-height: 1.1; }
.bk-grid.three .bk-kana b { font-size: 1.35rem; }
.bk-kana small { font-size: 0.7rem; color: var(--muted); }
.bk-kana.empty { background: transparent; box-shadow: none; cursor: default; border: 1.5px dashed var(--ring-track); }
.bk-kana.sel { outline: 2.5px solid var(--accent); outline-offset: -2px; }
.bk-kana.ok::after {
  content: "";
  position: absolute;
  top: 6px;
  right: 6px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--good);
}
.bk-playing { background: var(--accent-soft) !important; }

.bk-detail {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 86px;
  margin-bottom: 4px;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--card);
  box-shadow: 0 -14px 0 var(--bg), var(--shadow);
}
.bk-detail > .bk-muted { width: 100%; text-align: center; }
.bk-big {
  flex: 0 0 auto;
  min-width: 1.4em;
  border: none;
  background: transparent;
  color: var(--ink);
  font-size: 2.7rem;
  line-height: 1.1;
  cursor: pointer;
  border-radius: 12px;
}
.bk-info { flex: 1; min-width: 0; font-size: 0.84rem; line-height: 1.55; }
.bk-romaji { font-size: 1.05rem; color: var(--accent); margin-right: 10px; }
.bk-origin, .bk-twin { color: var(--muted); margin-right: 10px; white-space: nowrap; }
.bk-origin b, .bk-twin b { color: var(--ink); font-weight: 500; font-size: 1rem; }
.bk-tip { margin-top: 2px; }
.bk-ex {
  display: inline-block;
  margin: 6px 6px 0 0;
  border: none;
  border-radius: 999px;
  padding: 4px 11px;
  background: var(--accent-soft);
  color: var(--ink);
  font: inherit;
  font-size: 0.84rem;
  text-align: left;
  cursor: pointer;
}

/* Cards: start page, pronunciation, grammar */
.bk-card {
  background: var(--card);
  border-radius: 16px;
  padding: 12px 14px;
  margin-bottom: 10px;
  box-shadow: 0 1px 4px rgba(20, 15, 40, 0.06);
}
.bk-card h4 { font-size: 0.98rem; color: var(--accent); margin-bottom: 4px; }
.bk-card h4 .ja { font-weight: 400; font-size: 0.74rem; color: var(--muted); margin-left: 8px; }
.bk-card p { font-size: 0.88rem; line-height: 1.7; }
.bk-exrow, .bk-wordmain {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  margin-top: 8px;
  padding: 8px 10px;
  border: none;
  border-radius: 12px;
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.bk-play {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  margin-top: 1px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
}
.bk-exbody { display: flex; flex-direction: column; min-width: 0; gap: 1px; }
.bk-exbody .jp { font-size: 1.05rem; line-height: 1.45; }
.bk-kanaline { font-size: 0.8rem !important; color: var(--muted); }
.bk-ro { font-size: 0.76rem; color: var(--muted); font-style: italic; }
.bk-zh { font-size: 0.86rem; }
.bk-pos { margin-left: 8px; font-size: 0.7rem; color: var(--muted); }

.bk-hero {
  background: linear-gradient(135deg, var(--accent), #b58cff);
  color: #fff;
  border-radius: 18px;
  padding: 14px 16px;
  margin-bottom: 12px;
}
.bk-hero .bk-sub { color: rgba(255, 255, 255, 0.85); }
.bk-hero-t { font-size: 1.15rem; font-weight: 700; margin-bottom: 4px; }
.bk-hero p { font-size: 0.88rem; line-height: 1.6; }
.bk-steps { list-style: none; display: grid; gap: 8px; margin-bottom: 12px; }
.bk-steps button {
  width: 100%;
  border: none;
  border-radius: 16px;
  padding: 11px 14px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(20, 15, 40, 0.06);
}
.bk-steps b { color: var(--accent); }
.bk-steps p { font-size: 0.82rem; line-height: 1.6; margin-top: 3px; color: var(--ink); }
.bk-false { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.bk-false span { background: var(--bg); border-radius: 999px; padding: 3px 10px; font-size: 0.82rem; }
.bk-prog { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; font-size: 0.82rem; margin: 8px 0; }
.bk-prog em { font-style: normal; color: var(--muted); }
.bk-prog .bk-bar { grid-column: 1 / -1; }
.bk-bar { height: 6px; border-radius: 3px; background: var(--ring-track); overflow: hidden; margin: 6px 0 2px; }
.bk-bar i { display: block; height: 100%; background: var(--good); border-radius: 3px; transition: width 0.3s ease; }

/* Vocabulary */
.bk-words { display: grid; gap: 6px; }
.bk-word { background: var(--card); border-radius: 14px; padding: 2px 8px 8px; box-shadow: 0 1px 3px rgba(20, 15, 40, 0.06); position: relative; }
.bk-word .bk-wordmain { background: transparent; margin-top: 4px; padding: 4px 2px; }
.bk-word .bk-ex { margin-left: 40px; }
.bk-word.ok::after { content: "✓"; position: absolute; top: 10px; right: 12px; color: var(--good); font-weight: 700; }
.bk-w { font-size: 1.2rem !important; }

.bk-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 18px 0 6px; }
.bk-primary, .bk-secondary {
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  font: inherit;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
}
.bk-primary { background: var(--accent); color: #fff; }
.bk-secondary { background: var(--accent-soft); color: var(--accent); }
.bk-link { border: none; background: none; color: var(--accent); font: inherit; font-size: 0.85rem; cursor: pointer; padding: 0; }

/* Paid chapters: what unlocking gives */
.bk-paywall { background: var(--card); border-radius: 18px; padding: 18px 16px; text-align: center; margin-top: 4px; }
.bk-lockbig { font-size: 2.2rem; }
.bk-paywall h4 { font-size: 1.1rem; color: var(--accent); margin: 4px 0 10px; }
.bk-paywall h4 .bk-sub { display: block; margin: 2px 0 0; }
.bk-perks { list-style: none; text-align: left; display: grid; gap: 8px; margin: 0 0 12px; }
.bk-perks li { font-size: 0.86rem; line-height: 1.55; background: var(--bg); border-radius: 12px; padding: 8px 12px; }
.bk-perks li span { display: block; font-size: 0.72rem; color: var(--muted); }
.bk-titles { display: flex; flex-wrap: wrap; justify-content: center; gap: 5px; margin-bottom: 6px; }
.bk-titles span { font-size: 0.72rem; color: var(--muted); border: 1px solid var(--accent-soft); border-radius: 999px; padding: 2px 8px; }
.bk-locknote { display: inline-block; margin-top: 6px; font-size: 0.74rem; color: var(--accent); background: var(--accent-soft); border-radius: 999px; padding: 2px 10px; }
.bk-set.locked { opacity: 0.72; }
.bundle-btn.book-bundle { border-color: var(--accent); }

/* Drill */
.bk-sets { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.bk-set {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  border: none;
  border-radius: 14px;
  padding: 10px 12px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(20, 15, 40, 0.06);
}
.bk-set b { font-size: 0.86rem; }
.bk-set .bk-sub { margin: 0; }
.bk-set em { font-style: normal; font-size: 0.74rem; color: var(--muted); margin-top: 4px; }
.bk-set .bk-bar { width: 100%; }
.bk-qhead { display: flex; justify-content: space-between; align-items: center; font-size: 0.82rem; color: var(--muted); }
.bk-q { display: flex; flex-direction: column; align-items: center; padding: 18px 0 8px; min-height: 130px; justify-content: center; }
.bk-q .bk-big { font-size: 4rem; }
.bk-listen {
  width: 96px;
  height: 96px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 2.4rem;
  cursor: pointer;
  box-shadow: var(--shadow);
  margin-bottom: 6px;
}
.bk-opts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
.bk-opt {
  min-height: 56px;
  border: none;
  border-radius: 14px;
  padding: 10px 8px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 1.15rem;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(20, 15, 40, 0.08);
}
.bk-opt.big { font-size: 1.8rem; }
.bk-opt.small { font-size: 0.92rem; line-height: 1.4; }
.bk-opt.right { background: var(--good); color: #fff; }
.bk-opt.wrong { background: var(--bad); color: #fff; animation: shake 0.35s; }
.bk-opt:disabled { cursor: default; }
.bk-next { text-align: center; margin-top: 14px; }
.bk-reveal { font-size: 1.05rem; margin-bottom: 10px; }
.bk-result { text-align: center; background: var(--card); border-radius: 18px; padding: 16px; margin: 6px 0 10px; }
.bk-score { font-size: 2.4rem; font-weight: 700; color: var(--accent); }
.bk-missed { display: flex; flex-wrap: wrap; }

/* Portrait phones: a pill at the bottom-left, and the book as a bottom sheet. */
@media (max-width: 699px) and (min-height: 471px) {
  /* A small round button: it floats over the scrolling page, so it should
     cover as little as possible. */
  .book-btn {
    top: auto;
    transform: none;
    left: max(12px, env(safe-area-inset-left));
    bottom: calc(14px + env(safe-area-inset-bottom));
    width: 56px;
    height: 56px;
    gap: 1px;
    justify-content: center;
    padding: 0;
    border-radius: 50%;
  }
  .book-btn .bk-icon { font-size: 1.15rem; }
  .book-btn .bk-label { writing-mode: horizontal-tb; letter-spacing: 0; font-size: 0.6rem; }
  .book-btn .bk-label-ja { display: none; }
  @media (hover: hover) and (pointer: fine) { .book-btn:hover { padding-right: 0; } }
  /* The Japanese subtitle goes on its own line instead of wrapping mid-word. */
  .book-name .bk-sub { display: block; margin: 1px 0 0; }
  /* Room at the end of the page so the pill never sits on the footer text. */
  /* book.js places the button beside the countdown circle (.beside-timer);
     until it can (no circle on screen), it waits at the bottom-left. */
  .book-btn.beside-timer { position: absolute; bottom: auto; }
  .bk-kana b { font-size: 1.4rem; }
  .bk-closelabel { display: none; }
}

/* Landscape phones: a narrower drawer and tighter chrome. */
@media (max-height: 470px) {
  .book-btn { padding: 12px 8px; gap: 6px; }
  .book-btn .bk-icon { font-size: 1.4rem; }
  .book-btn .bk-label { font-size: 0.95rem; }
  .book-btn .bk-label-ja { display: none; }
  body.has-book .app, body.has-art .app { padding-left: 56px; }
  .book-head { padding-top: max(6px, env(safe-area-inset-top)); }
  .book-tabs { padding: 6px 0; }
  .book-tab { padding: 3px 9px; }
  .book-tab b { font-size: 0.8rem; }
  .book-tab span { font-size: 0.56rem; }
  .bk-detail { min-height: 70px; }
  .bk-big { font-size: 2.2rem; }
  .bk-q { min-height: 100px; padding: 8px 0 4px; }
  .bk-q .bk-big { font-size: 3rem; }
  .bk-listen { width: 72px; height: 72px; font-size: 1.8rem; }
}

@media (prefers-reduced-motion: reduce) {
  .book, .book-btn.nudge .bk-icon { animation: none; }
}

/* ---- Book page: layout pieces ---- */
.bk-kanawrap { display: flex; flex-direction: column; }
.bk-kanaside { position: sticky; top: 0; z-index: 2; }
.bk-search {
  width: 100%;
  margin: 12px 0 2px;
  padding: 11px 14px;
  border: 1.5px solid var(--accent-soft);
  border-radius: 14px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: 0.95rem;
}
.bk-search:focus { outline: none; border-color: var(--accent); }
.bk-secnav { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 6px; }
.bk-secnav .bk-sub { margin-left: 4px; }
.bk-sec { font-size: 1.15rem; color: var(--ink); margin: 22px 0 10px; padding-bottom: 6px; border-bottom: 2px solid var(--accent-soft); scroll-margin-top: 8px; }
.bk-tip2 { margin-top: 8px; background: var(--accent-soft); border-radius: 10px; padding: 7px 11px; font-size: 0.84rem !important; line-height: 1.6; }
.bk-tablewrap { overflow-x: auto; margin: 10px 0 2px; -webkit-overflow-scrolling: touch; }
.bk-table { border-collapse: collapse; font-size: 0.86rem; }
.book [hidden] { display: none !important; } /* flex/grid rules must not un-hide search-mode elements */
.bk-table th, .bk-table td { border: 1px solid var(--ring-track); padding: 6px 10px; text-align: left; white-space: nowrap; }
.bk-table th { background: var(--bg); font-weight: 600; color: var(--muted); }
.bk-table td.jp { font-size: 0.95rem; }

/* Wide screens: bigger type, two-column kana, vocabulary and drills in grids. */
@media (min-width: 900px) {
  .book-tab { padding: 8px 16px; }
  .book-tab b { font-size: 0.98rem; }
  .book-tab span { font-size: 0.7rem; }
  .bk-lead, .bk-card p { font-size: 0.98rem; }
  .bk-card { padding: 16px 20px; }
  .bk-card h4 { font-size: 1.08rem; }
  .bk-kanawrap { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 360px); gap: 22px; align-items: start; }
  .bk-kanaside { grid-column: 2; grid-row: 1; top: 0; }
  .bk-kanamain { grid-column: 1; grid-row: 1; }
  .bk-kanaside .bk-detail { flex-direction: column; align-items: flex-start; min-height: 260px; padding: 18px; box-shadow: var(--shadow); }
  .bk-kanaside .bk-big { font-size: 5rem; align-self: center; }
  .bk-kana { min-height: 72px; }
  .bk-kana b { font-size: 2rem; }
  .bk-grid.three .bk-kana b { font-size: 1.7rem; }
  .bk-words { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }
  .bk-sets { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
  .bk-q, .bk-opts, .bk-qhead, .bk-next, .bk-result { max-width: 620px; margin-left: auto; margin-right: auto; }
  .bk-q .bk-big { font-size: 5rem; }
  .bk-paywall { max-width: 720px; margin-left: auto; margin-right: auto; padding: 26px 30px; }
  .bk-hero { padding: 22px 26px; }
  .bk-hero-t { font-size: 1.4rem; }
  .bk-steps { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Account panel at the end of the free taster: the verify prompt leads. */
.acct-taster .profile-head { display: none; }
.acct-taster #acctHint { margin: 4px 0 2px; }

/* ---------- Practice backdrop ----------
   Behind everything (z-index -1 under the root stacking context): a sky
   gradient that follows the learner's local time of day, crossfaded between
   two layers when the period changes, and a warm glow from the bottom whose
   strength follows today's progress toward the goal. Colours are set from
   app.js (setBackdrop). Dialogs, the splash and the book cover it as before. */
.backdrop { position: fixed; inset: 0; z-index: -1; pointer-events: none; background: var(--bg); }
.bd-sky, .bd-glow { position: absolute; inset: 0; }
.bd-sky { opacity: 0; transition: opacity 4s ease; }
.bd-sky.on { opacity: 1; }
.bd-glow { transition: background 1.2s ease; }
/* Faint language texture over the sky: 青海波 waves for Japanese, a notebook
   dot grid for English (drawn by drawPattern in app.js, transparent between
   the lines so the sky shows through). */
.bd-pattern { position: absolute; top: 0; left: 0; opacity: 0.75; }
/* Answer glow at the screen edges: green when right, red when wrong. Above
   the page (it never takes taps), under the dialogs. A fade, not movement,
   so it stays on with reduced motion. */
.bd-edge { position: fixed; inset: 0; z-index: 25; pointer-events: none; opacity: 0; }
.bd-edge.ok  { box-shadow: inset 0 0 12vmin 1.2vmin rgba(34, 181, 115, 0.62); animation: edgeGlow 1.2s ease-out; }
.bd-edge.bad { box-shadow: inset 0 0 12vmin 1.2vmin rgba(255, 90, 95, 0.55); animation: edgeGlow 0.9s ease-out; }
@keyframes edgeGlow {
  0%   { opacity: 0; }
  18%  { opacity: 1; }
  100% { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .bd-sky, .bd-glow { transition: none; }
}

/* Reload on #book: the book is painted before the scripts run, and the start
   screen stays hidden underneath (no flash). book.js removes the class when
   the book closes. */
.boot-book #bookPanel { display: block; }
.boot-book .splash { opacity: 0; visibility: hidden; transition: none; }

/* ============================ 文章赏析 · listening articles ============================
   Same page chrome as the 日语入门 book (.book-overlay/.book/.book-head).
   The button is a second edge tab: alone (English) it takes the centre; with
   the book (Japanese) the two stack around the centre. Portrait phones: a
   round button right of the countdown circle (articles.js). */
.art-btn { background: #2f9e8f; box-shadow: 0 8px 26px rgba(47, 158, 143, 0.4), var(--shadow); }
@media not all and (max-width: 699px) and (min-height: 471px) {
  body.has-book .art-btn { top: calc(50% + 8px); transform: none; }
  body.has-book #bookBtn { top: calc(50% - 8px); transform: translateY(-100%); }
}
@media (max-width: 699px) and (min-height: 471px) {
  .art-btn { left: auto; right: max(12px, env(safe-area-inset-right)); }
  .art-btn .bk-label { display: none; }
  .art-btn .bk-label-short { font-size: 0.6rem; font-weight: 700; }
}
@media (max-height: 470px) {
  .art-btn .bk-label { font-size: 0.85rem; }
}

.art-back {
  flex: 0 0 auto;
  display: inline-flex; align-items: center; gap: 4px;
  border: none; border-radius: 999px; padding: 6px 12px;
  background: var(--accent-soft); color: var(--accent);
  font: inherit; font-weight: 700; font-size: 1rem; cursor: pointer;
}
.art-back[hidden], .art-player[hidden], #artZh[hidden] { display: none !important; }
.art-hname { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book.art .book-name .bk-sub { margin-left: 0; display: block; }

.art-player { display: flex; align-items: center; gap: 8px; padding: 8px 0 10px; }
.art-ctl {
  flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%;
  border: none; background: var(--accent-soft); color: var(--accent);
  font-size: 1rem; cursor: pointer; display: grid; place-items: center;
}
.art-ctl:disabled { opacity: 0.4; cursor: default; }
.art-ctl.art-play { width: 50px; height: 50px; font-size: 1.3rem; background: var(--accent); color: #fff; box-shadow: 0 4px 14px rgba(124, 92, 255, 0.35); }
.art-progress { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; }
.art-bar { flex: 1; height: 6px; border-radius: 3px; background: var(--ring-track); overflow: hidden; }
.art-bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 3px; transition: width 0.3s ease; }
#artPos { font-size: 0.78rem; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.art-ctl:focus-visible, .art-card:focus-visible, .art-back:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.art-intro span { display: block; color: var(--muted); font-size: 0.86em; margin-top: 4px; }
.art-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 12px; margin: 14px 0; }
.art-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px; text-align: left;
  background: var(--card); color: var(--ink); border: none; border-radius: 18px;
  padding: 14px 16px; box-shadow: var(--shadow); font: inherit; cursor: pointer;
  transition: transform 0.15s ease;
}
@media (hover: hover) { .art-card:hover { transform: translateY(-2px); } }
.art-card b { font-size: 1.12rem; line-height: 1.3; color: var(--accent); }
.art-tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 0.72rem; color: var(--muted); margin-bottom: 2px; }
.art-tags em { font-style: normal; background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 1px 8px; }
.art-zhtitle { font-size: 0.9rem; }
.art-author { font-size: 0.78rem; color: var(--muted); }
.art-read { align-self: stretch; height: 4px; border-radius: 2px; background: var(--ring-track); margin-top: 6px; overflow: hidden; }
.art-read i { display: block; height: 100%; background: var(--good); }
.art-readlabel { font-size: 0.7rem; color: var(--muted); }
.art-credit { text-align: center; margin-top: 8px; }

.art-head { max-width: 760px; margin: 4px auto 14px; text-align: center; }
.art-head h2 { font-size: clamp(1.4rem, 3.4vw, 2rem); color: var(--ink); line-height: 1.25; text-wrap: balance; }
.art-head .art-zhtitle { color: var(--accent); margin-top: 2px; }
.art-head .art-voices { justify-content: center; margin: 10px 0 4px; }
.art-how { margin-top: 6px; }
.art-how span { display: block; }

.art-text { max-width: 760px; margin: 0 auto; font-size: clamp(1.02rem, 1.6vw, 1.14rem); line-height: 1.85; }
.art-text.jp { line-height: 2; }
.art-p { margin: 0 0 1.05em; }
.art-text.jp .art-p { text-indent: 1em; }
.art-s { border-radius: 6px; cursor: pointer; transition: background 0.2s ease; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.art-s.now { background: var(--accent-soft); box-shadow: 0 0 0 2px var(--accent-soft); }
.art-zh { display: none; }
/* 显示中文: one sentence per block, its Chinese line right under it. */
.show-zh .art-p { text-indent: 0; }
.show-zh .art-s { display: block; padding: 4px 8px; margin: 0 -8px 6px; }
.show-zh .art-zh {
  display: block; font-family: "Fredoka", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 0.86em; line-height: 1.6; color: var(--muted); margin-top: 1px;
}
.art-s .word { cursor: pointer; }

.word-act {
  display: block; width: 100%; margin-top: 8px; border: none; border-radius: 10px;
  padding: 6px 10px; background: var(--accent-soft); color: var(--accent);
  font: inherit; font-size: 0.8rem; font-weight: 600; cursor: pointer;
}
.word-act[hidden] { display: none; }

/* Reload on #articles: painted before the scripts run (see index.html <head>). */
.boot-art #artPanel { display: block; }
.boot-art .splash { opacity: 0; visibility: hidden; transition: none; }
.art-break { text-align: center; color: var(--muted); letter-spacing: 1em; margin: 0.4em 0 1.2em; }
@media not all and (max-width: 699px) and (min-height: 471px) { .art-btn .bk-label-short { display: none; } }
/* With the Chinese shown each sentence is its own block: no paragraph indent. */
.show-zh .art-text.jp .art-p, .show-zh .art-s { text-indent: 0; }

/* Paid content is not selectable or copyable (see the copy/cut/contextmenu
   block in app.js): the book and 文章赏析 pages as a whole; typing fields stay
   normal. */
.book-body, .book-head { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.book-body input, .book-body textarea { -webkit-user-select: text; user-select: text; }
.art-paywall { margin: 10px auto 16px; max-width: 640px; }
.art-list.locked .art-card b { color: var(--muted); }
.art-lock { background: transparent !important; padding: 0 !important; }

/* Loading / load-error overlay (showSoftOverlay): no dim, no blur — the
   practice area fades out behind the tip card instead. The header and realm
   row stay, so switching realms doesn't flicker the whole page. */
.overlay.soft { background: transparent; -webkit-backdrop-filter: none; backdrop-filter: none; }
.overlay.soft .overlay-box { animation: soft-in 0.22s ease-out; box-shadow: 0 10px 40px rgba(60, 40, 120, 0.18); }
@keyframes soft-in { from { opacity: 0; transform: translateY(6px) scale(0.98); } to { opacity: 1; transform: none; } }
.app > .stage, .app > .lb, .app > .hint { transition: opacity 0.22s ease; }
body.stage-loading .app > .stage, body.stage-loading .app > .lb, body.stage-loading .app > .hint { opacity: 0; }
@media (prefers-reduced-motion: reduce) {
  .overlay.soft .overlay-box { animation: none; }
  .app > .stage, .app > .lb, .app > .hint { transition: none; }
}

/* Chinese name of a realm, shown instantly under the hovered chip (app.js). */
.realm-tip {
  position: fixed; z-index: 44; pointer-events: none;
  background: var(--ink); color: var(--card);
  font-size: 0.8rem; font-weight: 600; line-height: 1.2;
  padding: 4px 9px; border-radius: 8px; white-space: nowrap;
  box-shadow: 0 4px 14px rgba(20, 15, 40, 0.18);
}
.realm-tip::before {
  content: ""; position: absolute; top: -4px; left: 50%; margin-left: -4px;
  border: 4px solid transparent; border-top: 0; border-bottom-color: var(--ink);
}

/* 英语入门: the same book page; English text uses the page font, not the Japanese one. */
.bk-en .jp { font-family: inherit; }
.bk-grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.bk-letter b { font-size: 1.5rem; letter-spacing: 0.02em; }
.bk-ipa b { font-family: "Lucida Sans Unicode", "Segoe UI", "Helvetica Neue", Arial, sans-serif; font-size: 1.25rem; font-weight: 600; }
.bk-en .bk-big { font-family: "Lucida Sans Unicode", "Segoe UI", "Helvetica Neue", Arial, sans-serif; }
.bk-wordex { text-align: left; line-height: 1.5; }

/* Ranking: today's points (default) or all-time totals. */
.lb-period { display: flex; gap: 4px; margin: 6px 0 2px; padding: 3px; background: var(--bg); border-radius: 999px; }
.lb-period button {
  flex: 1; border: none; background: transparent; color: var(--muted); font: inherit; font-size: 0.82rem; font-weight: 600;
  padding: 4px 8px; border-radius: 999px; cursor: pointer; display: inline-flex; align-items: baseline; justify-content: center; gap: 4px;
}
.lb-period button span { font-size: 0.7rem; font-weight: 500; opacity: 0.8; }
.lb-period button.on { background: var(--accent); color: #fff; box-shadow: 0 2px 8px rgba(124, 92, 255, 0.3); }
.lb-period button:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }

/* Realm chips: on touch screens (no hover) the Chinese name sits under the realm name. */
.realm-chip .rc-zh { display: none; }
@media (hover: none) {
  .realm-chip { display: inline-flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.12; padding-top: 5px; padding-bottom: 5px; }
  .realm-chip .rc-zh { display: block; font-size: 0.66em; font-weight: 600; opacity: 0.72; margin-top: 1px; }
  .realm-chip.locked::after { position: absolute; top: 2px; right: 6px; font-size: 0.7em; }
  .realm-chip.locked { position: relative; }
}

/* Back to top: floats in the book / 文章赏析 page once you've scrolled a screen down. */
.bk-top {
  position: absolute; right: max(16px, env(safe-area-inset-right)); bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 3;
  width: 46px; height: 46px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--accent); color: #fff; font-size: 1.3rem; font-weight: 700; line-height: 1;
  box-shadow: 0 6px 18px rgba(124, 92, 255, 0.4);
  opacity: 0; transform: translateY(10px); pointer-events: none; transition: opacity 0.2s ease, transform 0.2s ease;
}
.bk-top.show { opacity: 1; transform: none; pointer-events: auto; }
.bk-top:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
@media (prefers-reduced-motion: reduce) { .bk-top { transition: none; } }
/* During a soft load the visible header and realm chips stay usable (the
   overlay lets clicks through); the faded practice area and ranking don't
   take clicks while invisible. */
.overlay.soft { pointer-events: none; }
.overlay.soft .overlay-box { pointer-events: auto; }
body.stage-loading .app > .stage, body.stage-loading .app > .lb { pointer-events: none; }

/* ---------- ✍️ 手写输入 (Japanese answers by handwriting) ---------- */
.hw-btn {
  border: 2px solid var(--ring-track);
  background: var(--card);
  color: var(--ink);
  border-radius: 999px;
  padding: 3px 10px;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}
.hw-btn.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.hw-panel {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  gap: 12px 16px;
  margin: 4px 0 14px;
}
.hw-panel.off { opacity: 0.55; }
.hw-panel.hidden { display: none; } /* .hw-panel sets display, which would beat the plain .hidden rule */
.hw-pad-wrap { position: relative; width: min(210px, 56vw); aspect-ratio: 1; max-width: 100%; }
.hw-pad {
  width: 100%;
  height: 100%;
  display: block;
  border: 2px solid var(--accent-soft);
  border-radius: 16px;
  background: var(--card);
  color: var(--ink);
  touch-action: none;
  cursor: crosshair;
  -webkit-user-select: none;
  user-select: none;
}
.hw-loading { position: absolute; inset: 0; display: grid; place-items: center; font-size: 0.8rem; color: var(--muted); text-align: center; padding: 10px; pointer-events: none; }
.hw-loading[hidden] { display: none; }
.hw-side { display: flex; flex-direction: column; gap: 8px; min-width: 0; flex: 1 1 180px; max-width: 280px; }
.hw-cands { display: flex; flex-wrap: wrap; gap: 6px; min-height: 42px; }
.hw-cand {
  min-width: 40px;
  height: 40px;
  border: 2px solid var(--ring-track);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  font-family: "Hiragino Sans", "Yu Gothic", "Noto Sans JP", "PingFang SC", sans-serif;
  font-size: 1.25rem;
  cursor: pointer;
  touch-action: manipulation;
}
.hw-cand.on { border-color: var(--accent); background: var(--accent-soft); }
.hw-keys { display: flex; gap: 8px; }
.hw-keys button[hidden] { display: none; }
.hw-keys button {
  flex: 1;
  border: none;
  border-radius: 12px;
  padding: 8px 6px;
  background: var(--accent-soft);
  color: var(--accent);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  touch-action: manipulation;
}
.hw-keys .zh-sub { display: block; font-size: 0.68rem; font-weight: 500; opacity: 0.8; }
.hw-tip { font-size: 0.74rem; color: var(--muted); line-height: 1.5; }
.hw-tip .zh-sub { display: block; }
.blank.hw-target { border-bottom-color: var(--accent); box-shadow: 0 3px 0 -1px var(--accent); }

/* 听音写字 drill (日语入门 → 练习) */
.bk-write { gap: 4px; }
.bk-wcells { display: flex; justify-content: center; align-items: flex-end; gap: 12px; margin: 10px 0 6px; max-width: 100%; }
.bk-wcell {
  --cell: min(300px, 74vw);
  width: var(--cell);
  aspect-ratio: 1;
  max-width: 100%;
  border: 3px solid var(--ring-track);
  border-radius: 22px;
  background: var(--card);
  transition: border-color 0.2s, box-shadow 0.25s;
}
.bk-wcells.two .bk-wcell { --cell: min(220px, 44vw); }
.bk-wcells.two .bk-wcell.small { --cell: min(140px, 28vw); }
.bk-wcell canvas { width: 100%; height: 100%; display: block; border-radius: 19px; touch-action: none; color: var(--ink); cursor: crosshair; }
.bk-wcell.right { border-color: var(--good); box-shadow: 0 0 0 4px rgba(34, 181, 115, 0.25), 0 0 28px rgba(34, 181, 115, 0.6); }
.bk-wcell.wrong { border-color: var(--bad); box-shadow: 0 0 0 4px rgba(255, 90, 95, 0.22), 0 0 28px rgba(255, 90, 95, 0.55); animation: shake 0.35s; }
.bk-wtime { width: min(300px, 74vw); height: 6px; border-radius: 999px; background: var(--ring-track); overflow: hidden; }
.bk-wtime i { display: block; height: 100%; width: 100%; background: var(--accent); border-radius: inherit; transform-origin: left; }
.bk-wtime.urgent i { background: var(--bad); }
.bk-wacts { display: flex; justify-content: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.bk-set.nowrite { opacity: 0.5; }
@media (prefers-reduced-motion: reduce) { .bk-wcell.wrong { animation: none; } }

/* ---------- 打卡徽章: badge wall and the progress panel (opened from the profile) ---------- */
.acct-links { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 12px 0 4px; flex: 0 0 auto; }
.profile-head, .id-row, .id-sub, .nick-row { flex: 0 0 auto; }
.acct-link-btn {
  background: var(--accent-soft);
  color: var(--accent);
  border: none;
  border-radius: 14px;
  padding: 10px 8px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
.acct-link-btn .zh-sub { display: block; font-size: 0.7rem; font-weight: 500; opacity: 0.85; }
/* Three to a row (📊 · 🏅 · 📤): the icon sits on its own line so a four-character label like
   我的进度 keeps one line in a third of a phone's width. */
.acct-link-btn { white-space: nowrap; }
.acct-link-btn .al-ico { display: block; font-size: 1.35rem; line-height: 1.2; margin-bottom: 2px; }
.overlay-back {
  position: sticky;
  top: 0;
  align-self: flex-start;
  flex: 0 0 auto;
  margin: -12px auto -10px -12px;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}
.badge-box { max-width: 560px; }
.stats-note { margin-top: 4px; grid-column: 1 / -1; }

.badge-wall { display: block; }
/* Always three to a row, evenly aligned (owner, 2026-09-16). */
.badge-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 6px; align-items: stretch; }
.badge-grid .badge-card { display: flex; flex-direction: column; justify-content: flex-start; }
.badge-art { display: block; width: 100%; max-width: 86px; margin: 0 auto 2px; }
.badge-card {
  background: var(--bg);
  border: 2px solid var(--ring-track);
  border-radius: 14px;
  padding: 8px 6px;
  text-align: center;
  line-height: 1.35;
}
.badge-card.earned { border-color: var(--accent); background: var(--accent-soft); }
.badge-card b { display: block; font-size: 0.78rem; color: var(--ink); }
.badge-card .zh-sub { display: block; font-size: 0.66rem; color: var(--muted); }
.badge-card em { display: block; font-style: normal; font-size: 0.66rem; color: var(--muted); margin-top: 2px; }
.badge-card.earned em { color: var(--accent); font-weight: 600; }
.badge-big-box { max-width: 380px; text-align: center; }
.badge-big-img { width: 100%; max-width: 320px; border-radius: 18px; box-shadow: var(--shadow); margin: 0 auto 10px; display: block; }
/* 📤 share: the poster is taller than a badge card, so cap it by the screen as well. */
.share-box .badge-big-img { max-height: calc(100dvh - 260px); width: auto; max-width: 100%; aspect-ratio: 720 / 1000; }
.share-open { display: block; margin: 14px auto 2px; }
.share-url { user-select: all; -webkit-user-select: all; word-break: break-all; }
.badge-card { cursor: pointer; }
.badge-group { font-size: 0.86rem; color: var(--ink); margin: 12px 0 2px; text-align: left; }
.badge-group .zh-sub { font-size: 0.7rem; font-weight: 500; color: var(--muted); margin-left: 6px; }
.badge-note { display: block; background: var(--accent-soft); color: var(--accent); border-radius: 12px; padding: 8px 10px; margin-bottom: 8px; font-weight: 600; }
.badge-note .zh-sub { display: block; font-weight: 500; opacity: 0.85; }


/* ---------- A badge just earned: glowing medal on a dimmed page ---------- */
.award-overlay { background: rgba(24, 16, 44, 0.55); backdrop-filter: blur(2px); }
.award-box { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px; max-width: 340px; text-align: center; }
.award-close { position: absolute; top: 18px; right: 18px; margin: 0; background: rgba(255, 255, 255, 0.9); }
.award-glow { position: relative; width: min(230px, 62vw); animation: award-float 3.2s ease-in-out infinite; }
.award-glow::before {
  content: "";
  position: absolute;
  inset: -18%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 236, 160, 0.85) 0%, rgba(255, 210, 120, 0.35) 45%, transparent 70%);
  animation: award-pulse 1.8s ease-in-out infinite;
}
.award-art { position: relative; }
.award-art svg { width: 100%; height: auto; display: block; filter: drop-shadow(0 6px 18px rgba(0, 0, 0, 0.45)); }
.award-name { color: #fff; font-size: 1.35rem; font-weight: 700; text-shadow: 0 2px 10px rgba(0, 0, 0, 0.45); }
.award-note { color: #fff3d6; font-size: 0.86rem; font-weight: 600; max-width: 300px; }
.award-note .zh-sub, .award-hint .zh-sub { display: block; font-weight: 500; opacity: 0.85; }
.award-hint { color: rgba(255, 255, 255, 0.85); font-size: 0.76rem; line-height: 1.6; }
/* a badge pays credits (2.2.3): a gold pill under its name */
.award-bonus { display: inline-block; margin: 6px auto 2px; padding: 6px 16px; border-radius: 999px; background: linear-gradient(135deg, #ffd34e, #ffad1f); color: #5a3a00; font-weight: 800; font-size: 1.05rem; box-shadow: 0 4px 14px rgba(255, 173, 31, 0.45); }
.award-bonus .zh-sub { display: block; font-size: 0.72rem; font-weight: 600; opacity: 0.85; }
@keyframes award-pulse { 0%, 100% { transform: scale(0.94); opacity: 0.75; } 50% { transform: scale(1.06); opacity: 1; } }
@keyframes award-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
@media (prefers-reduced-motion: reduce) { .award-glow, .award-glow::before { animation: none; } }

/* ---------- Profile panel: tap the avatar, tap the ID, nickname behind 修改 ---------- */
.avatar-pick { position: relative; border: none; background: none; padding: 0; cursor: pointer; border-radius: 50%; line-height: 0; }
.avatar-cam {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.85rem;
  line-height: 30px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(60, 40, 120, 0.3);
}
/* Sits inside .nick-row now, to the LEFT of 昵称 (owner, 2026-09-20) — it used to
   float under the photo with nothing to relate it to. */
.gender-mark { display: inline-block; font-size: 1.05rem; color: var(--accent); font-weight: 700; line-height: 1; }
.id-chip { cursor: pointer; border: none; font: inherit; }
.id-chip.copied { color: var(--good); }
.eye-btn {
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  line-height: 0;
  touch-action: manipulation;
}
.eye-btn:hover { color: var(--accent); }
.id-sub { font-size: 0.72rem; color: var(--muted); text-align: center; margin-top: 2px; line-height: 1.5; }
.id-sub .zh-sub { display: block; }
.nick-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 10px; }
.nick-label { font-size: 0.85rem; color: var(--muted); }
.nick-show { font-weight: 700; color: var(--ink); max-width: 12rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nick-edit { border: none; background: none; color: var(--accent); font: inherit; font-weight: 700; font-size: 0.85rem; cursor: pointer; padding: 2px 4px; }
.nick-state { font-size: 0.74rem; color: var(--muted); }
.nick-state.nick-ok { color: var(--good); }
.nick-state.nick-wait { color: var(--warn); }
.nick-state.nick-bad { color: var(--bad); }
.nick-input { max-width: 12rem; }

/* Profile panel (2026-09-16): a bigger avatar, the nickname under it, a labelled ID row. */
.profile-avatar { width: 192px; height: 192px; }
.avatar-cam { width: 44px; height: 44px; font-size: 1.2rem; line-height: 44px; right: 4px; bottom: 4px; }
.nick-row { margin-top: 8px; }
.nick-show { font-size: 1.15rem; }
.id-label { font-size: 0.8rem; color: var(--muted); }
.id-row { display: flex; align-items: center; justify-content: center; gap: 8px; }

/* Landscape / tablet / desktop: the profile avatar moves beside the realm row at three times its
   header size (owner, 2026-09-16). Portrait phones are untouched, and nothing else changes size. */
@media (min-width: 700px), (orientation: landscape) and (min-width: 560px) {
  .topbar .avatar-btn:not(.avatar-big) { display: none; }
  .avatar-big { display: block; width: 114px; height: 114px; margin: 0; }
}
.badge-card.mystery { border-style: dashed; cursor: default; }
.mystery-art { font-size: 2.6rem; line-height: 1.6; color: var(--muted); }
.goal-row { grid-column: 1 / -1; display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; font-size: 0.86rem; color: var(--muted); margin-top: 8px; }
.goal-row b { font-size: 1.15rem; color: var(--ink); min-width: 2.2rem; text-align: center; }
.goal-row .zh-sub { flex-basis: 100%; text-align: center; font-size: 0.72rem; }
.goal-step {
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font: inherit;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

/* ---------- 🎤 跟读练习 (shadowing + pitch mirror) ---------- */
/* Entry point sits in the resolved-sentence row beside 👍/👎. */
/* IT HAS TO BE NOTICED (owner, 2026-09-20: "increase the waving frequency … it's kind
   of small now, or could you think of another way to grab attention"). A slow wiggle on
   a grey ghost pill becomes wallpaper within a sentence or two. What the eye actually
   catches is MOTION ONSET and colour, so the button now: arrives with a pop the moment
   the sentence resolves, sends out two halo rings, carries the accent orange instead of
   sitting grey among grey, and keeps a faster, wider wave afterwards. */
.shadow-open {
  position: relative;
  border: 1.5px solid #f97316;
  background: #fff7ed;
  color: #c2410c;
  font-weight: 650;
  border-radius: 999px;
  padding: 5px 14px;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 650;
  cursor: pointer;
  box-shadow: 0 1px 6px rgba(249, 115, 22, 0.22);
}
.shadow-open:hover { background: #ffedd5; border-color: #ea580c; }
:root[data-theme="dark"] .shadow-open,
html.dark .shadow-open { background: #3a2410; color: #fdba74; }

/* The ring that spreads out of it twice when it appears — a notification, not a loop. */
.shadow-open::after {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: 999px;
  border: 2px solid #f97316;
  opacity: 0;
  pointer-events: none;
}
.shadow-open.pop { animation: so-pop 0.46s cubic-bezier(.34, 1.56, .64, 1) both; }
.shadow-open.pop::after { animation: so-ring 1.15s ease-out 2; }
@keyframes so-pop {
  0% { transform: scale(0.55); opacity: 0; }
  70% { transform: scale(1.09); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}
@keyframes so-ring {
  0% { transform: scale(1); opacity: 0.85; }
  100% { transform: scale(1.55); opacity: 0; }
}
/* 🎤 WAVES WHENEVER IT IS OFFERED (owner, 2026-09-20: "'跟读' is really an important
   and helpful feature, can you waving the button after sentence is finished so that
   the user can notice it"). The button only appears once a sentence is resolved, so
   "while visible" is exactly "after the sentence is finished". Same idea as the
   book tab's 📖, which the owner asked to keep waving for good. */
/* Faster and wider than before: a 1.25 s cycle that waves four times instead of a
   single flick every 2.2 s. */
.shadow-open .so-ico { display: inline-block; transform-origin: 70% 80%; animation: so-wave 1.25s ease-in-out infinite; }
@keyframes so-wave {
  0%, 46%, 100% { transform: rotate(0) scale(1); }
  54% { transform: rotate(-20deg) scale(1.22); }
  64% { transform: rotate(16deg) scale(1.22); }
  74% { transform: rotate(-12deg) scale(1.14); }
  84% { transform: rotate(8deg) scale(1.08); }
}
@media (prefers-reduced-motion: reduce) {
  .shadow-open .so-ico, .shadow-open.pop, .shadow-open.pop::after { animation: none; }
}

/* 跟读 chapter in the starter books */
.bk-shadow-grp { margin: 18px 0 26px; }
.bk-shrow { display: flex; align-items: stretch; gap: 8px; margin: 6px 0; }
.bk-shrow .bk-exrow { flex: 1; }
.bk-shtext { font-weight: 600; }
.bk-n { display: inline-block; min-width: 1.6em; opacity: 0.5; font-variant-numeric: tabular-nums; }
.bk-mic {
  flex: 0 0 auto; border: 1px solid var(--line, #d8d3e4); background: var(--card, #fff);
  border-radius: 12px; padding: 0 14px; font-size: 1.15rem; cursor: pointer; line-height: 1;
}
.bk-mic:hover { border-color: #f97316; }
.bk-tip { margin: 2px 0 10px; font-size: 0.86rem; opacity: 0.8; line-height: 1.5; }

/* The shared dim + blur scrim let everything behind show through as faint rounded
   rectangles — the card, the ranking, the edge tabs (owner, 2026-09-17: "transparent
   box border in the background … again"; the loading overlay lost its blur for the
   same reason). This panel sits on an OPAQUE sheet of the page's own background,
   like the 日语入门 book does, so there is nothing behind it to see. */
#shadowOverlay { background: var(--bg); backdrop-filter: none; }

.shadow-box { max-width: 620px; text-align: center; }
.shadow-title { margin: 0 0 10px; font-size: 1.15rem; }
.shadow-title .zh-sub { display: block; }

.shadow-tabs { display: flex; gap: 8px; justify-content: center; margin-bottom: 12px; }
.shadow-tab {
  flex: 1 1 0;
  border: 1px solid var(--line, #d8d3e4);
  background: transparent;
  color: var(--ink);
  border-radius: 10px;
  padding: 7px 10px;
  font: inherit;
  cursor: pointer;
}
.shadow-tab.on { border-color: #f97316; background: rgba(249, 115, 22, 0.12); font-weight: 700; }
.shadow-tab .zh-sub { display: block; font-weight: 400; }

.shadow-sentence { font-size: 1.15rem; line-height: 1.6; margin: 6px 0; user-select: none; }
.shadow-zh { opacity: 0.75; margin: 0 0 6px; user-select: none; }
.shadow-hidden-note { opacity: 0.7; font-size: 0.9rem; margin: 14px 0; }

.shadow-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; justify-content: center; margin: 8px 0; }
.shadow-lab { opacity: 0.7; font-size: 0.85rem; }
.shadow-chip {
  border: 1px solid var(--line, #d8d3e4);
  background: transparent;
  color: var(--ink);
  border-radius: 999px;
  padding: 5px 12px;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}
.shadow-chip.on { border-color: #3b82f6; background: rgba(59, 130, 246, 0.14); font-weight: 700; }
.shadow-chip .zh-sub { display: block; font-weight: 400; }

.shadow-stage { margin: 10px 0; }
.shadow-canvas { width: 100%; max-width: 100%; height: auto; border-radius: 10px; background: rgba(128, 128, 128, 0.08); }
.shadow-score { margin: 8px 0 0; font-size: 1.05rem; }
.shadow-score .zh-sub, .shadow-score .shadow-dur { display: block; font-size: 0.82rem; opacity: 0.75; font-weight: 400; }
.shadow-status { margin: 8px 0 0; min-height: 1.3em; opacity: 0.85; }

.shadow-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 12px 0 6px; }
.shadow-main {
  border: 0;
  border-radius: 999px;
  padding: 11px 26px;
  font: inherit;
  font-size: 1.02rem;
  font-weight: 700;
  color: #fff;
  background: #f97316;
  cursor: pointer;
}
.shadow-main.recording { background: #dc2626; animation: shadow-pulse 1.1s ease-in-out infinite; }
@keyframes shadow-pulse { 50% { opacity: 0.6; } }
@media (prefers-reduced-motion: reduce) { .shadow-main.recording { animation: none; } }
.shadow-play {
  border: 1px solid var(--line, #d8d3e4);
  background: var(--card, #fff);
  color: var(--ink);
  border-radius: 999px;
  padding: 10px 18px;
  font: inherit;
  cursor: pointer;
}
.shadow-tip, .shadow-count { margin: 6px 0 0; font-size: 0.82rem; }

/* Nickname row: say what the field IS. "— 设置" alone read as a stray dash
   (owner, 2026-09-17), and while editing the button must say 保存 so it is
   obvious how to commit the name that was just typed. */
.nick-label { opacity: 0.6; font-size: 0.82rem; }
.nick-edit.saving { background: var(--accent, #7c5cff); color: #fff; border-color: transparent; }

/* 在微信中支付: the phone path. The QR stays as a fallback for a second device,
   but shrinks so the button is clearly the primary action. */
.wx-pay-btn { display: block; background: #07c160; color: #fff; text-decoration: none; margin-bottom: 12px; }
.wx-pay-btn:hover { filter: brightness(1.05); }
#qrBox.qr-small { max-width: 190px; margin: 0 auto; opacity: 0.85; }

/* 📒 the yellow book — sentences LEARNED, tapped for free review. 📗 green is the
   unlocked set (tap to practise what is still unlearned), 📕 red the mistake notebook
   (owner, 2026-09-17: three books, three different numbers). */
.learned-btn { background: #fdf3cf; color: #8a6a00; }

/* 🎟️ credits explainer: which realms hold the sentences you unlocked but haven't
   practised. Answers "my credits are gone and this realm is empty" on demand, so the
   practice screen needs no permanent caption (owner, 2026-09-17). */
button.scorebox.credits { cursor: pointer; font: inherit; }
.credit-realms { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 4px 0 2px; }
.credit-realms button {
  border: 1px solid var(--line, #d8d3e4); background: var(--card, #fff); color: var(--ink);
  border-radius: 999px; padding: 5px 12px; font: inherit; font-size: 0.86rem; cursor: pointer;
}
.credit-realms button:hover { border-color: var(--accent, #7c5cff); }
.credit-realms b { color: var(--accent, #7c5cff); }

/* ============ The iOS app (specs/2026-09-26-ios-app-trd.md) ============
   html.in-app is set by app.js when the app's shell injected window.WB_APP. Refunds and
   invoices are the website's (web-only); outside the US App Store the app never mentions
   buying (buy-only, hidden under .app-nobuy). */
html.in-app .web-only, html.app-nobuy .buy-only, html:not(.in-app) .app-only { display: none !important; }
.remind-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; }
.remind-row .optin-row { flex: 1 1 220px; }
.remind-row input[type="time"] { font: inherit; padding: 6px 10px; border-radius: 10px; border: 1px solid var(--line, #ddd); background: transparent; color: inherit; }
.remind-row .acct-hint { flex-basis: 100%; margin: 0; }
/* Today's goal reached: the award panel's look, with the civet and two actions. */
.goal-overlay .goal-civet { width: 150px; height: 150px; display: block; animation: goal-bob 1.6s ease-in-out infinite; }
@keyframes goal-bob { 0%, 100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-8px) rotate(3deg); } }
.goal-actions { display: grid; gap: 10px; margin-top: 14px; width: min(320px, 100%); }
@media (prefers-reduced-motion: reduce) { .goal-overlay .goal-civet { animation: none; } }
/* The ranking row's ⋯ menu: two buttons a row (owner, 2026-09-26: "four buttons are too crowded"). */
.lb-menu { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }
.lb-menu .retry-btn { margin: 0; width: 100%; min-width: 0; padding: 10px 8px; font-size: 0.92rem; line-height: 1.3; white-space: normal; }
.lb-more { margin-left: 6px; border: 0; background: transparent; color: var(--muted); font-size: 1.1rem; line-height: 1; padding: 4px 6px; border-radius: 8px; cursor: pointer; }
.app-welcome { align-items: center; text-align: center; }
.app-welcome img { margin: 4px auto 0; }
.web-buy-id { display: flex; align-items: center; gap: 10px; justify-content: center; flex-wrap: wrap;
  padding: 10px 14px; border-radius: 12px; background: var(--card-soft, rgba(124, 92, 255, .08)); }
.web-buy-id b { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 1.05rem; user-select: all; -webkit-user-select: all; }

/* ===================== PHONES: ONE 菜单 BOARD =====================
   Owner, 2026-09-21, over three rounds: "too much buttons on a phone" → one switch for
   the header controls AND the realm chips → and then the board itself: "transparent
   glass with distinguishable edges … more like a 3-D glass so the edges is important to
   do the visual trick to make it 3D-ish, so the webpage background can be seen through
   the board, while the luster can also be seen clearly moving while tilt the screen".

   Deliberately the LAST block in this file: a landscape phone matches the tablet query
   further up as well (min-width 560 + landscape), and these rules have to win.

   The board is #barsPanel. On anything wider it is `display: contents`, so .player and
   .realms-row stay exactly the direct children of .topbar they were. */
.bar-toggle { display: none; }
.bar-glass { display: none; }
.bars-panel { display: contents; }

@media (max-width: 699px), (max-height: 470px) {
  .bar-toggle {
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
    /* An outline, so it reads as a button rather than a tinted word (owner, 2026-09-21). */
    border: 1.5px solid rgba(124, 92, 255, 0.45);
    border-radius: 999px;
    padding: 7px 15px;
    /* Sits beside the avatar, not marooned in the middle: the brand takes the slack. */
    margin-left: auto;
    margin-right: 0;
    background: var(--accent-soft);
    color: var(--accent);
    font: inherit;
    font-size: 0.9rem;
    font-weight: 700;
    line-height: 1.1;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .bar-toggle[aria-expanded="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }

  /* ---- closed: brand · 菜单 · a big avatar, on ONE line ----
     Left to wrap, the brand pushed the avatar onto a second line and away from the
     right edge, which is where a right-handed thumb looks for it. */
  /* Closed, the bar is one line and must NOT wrap (the brand would push the avatar off
     the right edge). Open, it MUST wrap, or the board — a 100%-basis flex item — is
     forced onto the same line and stretches the header to 1645 px on a 390 px screen. */
  .topbar { position: relative; }
  body:not(.bars-open) .topbar { flex-wrap: nowrap; }
  body.bars-open .topbar { flex-wrap: wrap; }
  .brand { min-width: 0; font-size: 1.05rem; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  /* 菜单 is wider than the ☰ it replaced, and with the 80 px avatar beside it the brand
     no longer fits: the ellipsis chopped 布狸词 to 布狸, which reads as a typo. The
     Chinese name steps out while the bar is closed and comes back with the board. */
  body:not(.bars-open) .brand-zh { display: none; }

  /* The ranking sat right under the pause button; give it room (owner, 2026-09-21). */
  /* And it is GLASS on a phone (owner, 2026-09-22: "please make the ranking board on phone
     devices glass board just like what we do for the headers yesterday") — the same
     material as the 菜单 board, defined once in --glass-border / --glass-edge: no fill and
     no blur, so the sky and the ruled lines show straight through it, and the EDGES are the
     whole object. Only the board goes transparent; the rows keep their own marks (the
     medals, and the tint on your own row) or the list would lose its reading order. */
  .lb {
    margin-top: 18px;
    background: transparent;
    border: 1.5px solid var(--glass-border);
    box-shadow: var(--glass-edge);
  }
  .lb-head { border-bottom-color: rgba(124, 92, 255, 0.28); }
  .lb-row.me { background: rgba(255, 255, 255, 0.55); box-shadow: inset 0 0 0 1.5px rgba(124, 92, 255, 0.35); }

  /* 英语大全/日语大全 and 文章赏析 live under the realm chips, and ONLY there on a phone.
     The buttons keep their own look — this only undoes the fixed positioning and the
     inline offsets their placeBtn() writes, so they can sit in a row. */
  .bars-extra { display: flex; justify-content: center; gap: 14px; margin-top: 10px; }
  .book-btn.in-board {
    position: static;
    top: auto;
    left: auto;
    bottom: auto;
    transform: none;
    margin: 0;
    /* The round form the portrait phone already uses — stated here rather than
       inherited, because a LANDSCAPE phone misses that media query and kept the tall
       vertical edge tab, which inside the board came out 39x147 and hung off it. */
    width: 56px;
    height: 56px;
    border-radius: 50%;
    padding: 0;
    gap: 1px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    writing-mode: horizontal-tb;
  }
  .book-btn.in-board .bk-icon { font-size: 1.15rem; }
  .book-btn.in-board .bk-label { writing-mode: horizontal-tb; letter-spacing: 0; font-size: 0.6rem; }
  .book-btn.in-board .bk-label-ja { display: none; }
  .book-btn.in-board[hidden] { display: none; }
  /* When the keyboard shrinks the page below 471 px, the edge-tab rule
     body.has-book #bookBtn { top: 50%; transform: translateY(-100%) } starts
     matching. It outranks .in-board, so the course button jumped up onto the
     realm chips (Xiaomi / in-app browsers that resize for the keyboard). */
  body.has-book #bookBtn.in-board,
  body.has-art #artBtn.in-board {
    position: static;
    top: auto;
    left: auto;
    right: auto;
    bottom: auto;
    transform: none;
  }
  #artBtn.in-board .bk-label { display: none; }
  #artBtn.in-board .bk-label-short {
    display: block;
    writing-mode: horizontal-tb;
    letter-spacing: 0;
    font-size: 0.6rem;
    font-weight: 700;
  }
  .topbar > .avatar-btn:not(.avatar-big) { display: block; width: 80px; height: 80px; border-width: 3px; margin: 0; flex: 0 0 auto; }
  body.bars-open .topbar > .avatar-btn:not(.avatar-big) { display: none; } /* the board carries its own */

  /* ---- the board ---- */
  .bars-panel { display: none; }
  body.bars-open .bars-panel {
    display: block;
    position: relative;
    flex: 1 1 100%;
    /* A flex item's min-width is `auto`, i.e. its content's min-content width — the 17
       realm chips in a nowrap row — so the board grew to 1682 px on a 390 px screen
       instead of scrolling them. Same reason .realms-row and .realms need it. */
    min-width: 0;
    margin-top: 8px;
    padding: 10px 12px;
    border-radius: 24px;
    /* Opens out of the 菜单 button, which always sits at the bar's top-right. Measuring
       the button instead was wrong: opening hides the big avatar, so it slides ~80 px
       right between the measurement and the animation. */
    transform-origin: calc(100% - 42px) -22px;
    animation: bar-open 0.34s cubic-bezier(0.22, 1.1, 0.36, 1) both;
  }
  body.bars-closing .bars-panel { animation: bar-close 0.22s ease-in both; }
  body.bars-open .player { display: flex; flex: 1 1 100%; justify-content: flex-start; }
  body.bars-open .realms-row { display: flex; flex-wrap: nowrap; gap: 8px; margin-top: 6px; min-width: 0; }
  body.bars-open .realms-row > .realms { flex: 1 1 auto; min-width: 0; }
  /* The avatar the board carries: its own, at the board's right edge. */
  body.bars-open .avatar-big { display: block; width: 54px; height: 54px; margin: 0; flex: 0 0 auto; }

  /* Above the glass — but only here, where a glass exists. Applied everywhere this put
     every header child in its own stacking context and the realm row painted OVER the
     language / level / voice dropdowns, so a tap on the menu hit a realm chip instead. */
  body.bars-open .bars-panel > *:not(.bar-glass) { position: relative; z-index: 1; }
  body.bars-open .bars-panel > .player { z-index: 2; }

  /* ---- the glass itself ----
     TOTALLY TRANSPARENT (owner, 2026-09-21: "still not transparent, I can't see the
     page background through the board, could you adjust it to total transparent? and
     keep the edges to prove it's a board anyway. You can remove the luster effect").
     No fill AND NO BLUR: a backdrop blur is what was really hiding the page — at 14 px
     the ruled lines behind it turned to fog, which reads as frosted, not as glass. The
     board is now literally see-through and the EDGES are the whole object: a bright
     outer rim, a lit top bevel, a shaded bottom one, and a drop shadow so it floats
     above the page instead of being painted onto it. */
  body.bars-open .bar-glass {
    display: block;
    position: absolute;
    inset: 0;
    z-index: 0;
    border-radius: inherit;
    pointer-events: none;
    background: transparent;
    border: 1.5px solid var(--glass-border);
    box-shadow: var(--glass-edge);
  }
}

@keyframes bar-open {
  from { opacity: 0; transform: scale(0.18) translateY(-10px); }
  60%  { opacity: 1; }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes bar-close {
  from { opacity: 1; transform: scale(1) translateY(0); }
  to   { opacity: 0; transform: scale(0.18) translateY(-10px); }
}
@media (prefers-reduced-motion: reduce) {
  body.bars-open .bars-panel, body.bars-closing .bars-panel { animation: none; }
}

/* THE RANKING BOARD STARTS BELOW THE FOLD ON A PHONE (owner, 2026-09-24: "move the ranking board
   down more, so that users don't even see it until they scroll down"). The practice area is at
   least one small-viewport screen minus the header (--topbar-h, measured live by app.js because
   the header's height depends on fonts and on the 菜单 board being open), so the board begins just
   past the bottom edge and only a scroll reveals it. svh, not dvh: the SMALL viewport, measured
   with the browser's toolbars showing, so it stays hidden however the toolbars move. */
@media (max-width: 699px), (max-height: 470px) {
  /* content anchored at the TOP: the sentence stays high on the screen, the room goes below it */
  .app > .stage { min-height: calc(100svh - var(--topbar-h, 96px) - 12px); justify-content: flex-start; }
}
