/* Workstream I (UX, onboarding, accessibility). Kept in its own file so the
   shared styles.css stays untouched by this workstream. Loaded after it. */

/* ---------- Onboarding dialog ---------- */
.ob-backdrop {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background: rgba(0, 0, 0, 0.6);
}
.ob-dialog {
  display: flex;
  flex-direction: column;
  width: min(560px, 100%);
  max-height: 100%;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  overflow: hidden;
}
.ob-dialog:focus { outline: none; }
.ob-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px 0; color: var(--muted); font-size: 0.85rem; }
.ob-skip { min-height: 44px; }
.ob-body { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 20px 12px; }
.ob-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 16px; border-top: 1px solid var(--border); }
.ob-title { margin: 8px 0 6px; font-size: 1.35rem; }
.ob-title:focus { outline: none; }
.ob-sub { margin: 16px 0 6px; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.ob-lead { margin: 0 0 12px; color: var(--muted); }
.ob-big { margin: 8px 0; font-size: 1.25rem; font-weight: 600; }
.ob-honest { margin: 12px 0 0; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--r-md); background: color-mix(in srgb, var(--accent-2) 8%, transparent); color: var(--muted); font-size: 0.9rem; }
.ob-passage { margin: 8px 0 16px; font-family: var(--font-serif); font-size: 1.15rem; line-height: 1.7; }
.ob-inline { display: flex; flex-wrap: wrap; gap: 8px; }
.ob-choices { display: grid; gap: 8px; }
.ob-choices.ob-row-choices { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); }
.ob-choice { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; padding: 12px 14px; border-radius: var(--r-lg); }
.ob-choice span { color: var(--muted); font-size: 0.85rem; }
.ob-choice[aria-checked="true"] span { color: var(--text); }
.ob-choice[aria-checked="true"] { border-color: var(--accent-2); background: color-mix(in srgb, var(--accent-2) 14%, var(--control)); box-shadow: inset 0 0 0 1px var(--accent-2); }
.ob-toggle { display: flex; align-items: flex-start; gap: 12px; padding: 8px 0; cursor: pointer; }
.ob-toggle input { margin-top: 4px; width: 18px; height: 18px; accent-color: var(--accent-2); flex: none; }
.ob-toggle small { display: block; color: var(--muted); }
.ob-q { margin: 0 0 12px; padding: 0; border: 0; }
.ob-q legend { padding: 0; margin-bottom: 6px; font-weight: 600; }
.ob-opt { display: flex; align-items: center; gap: 10px; padding: 8px 10px; margin-bottom: 4px; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--control); cursor: pointer; }
.ob-opt input { accent-color: var(--accent-2); }
.ob-opt:has(input:checked) { border-color: var(--accent-2); }
.ob-opt:has(input:focus-visible) { outline: 2px solid var(--accent-2); outline-offset: 2px; }

/* ---------- Modal shell (modal.js), command palette and shortcut cheat sheet ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: max(12vh, env(safe-area-inset-top)) 16px 16px;
  background: rgba(0, 0, 0, 0.55);
}
.modal-dialog {
  display: flex;
  flex-direction: column;
  width: min(580px, 100%);
  max-height: min(70vh, 560px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  overflow: hidden;
}
.pal-input {
  flex: none;
  width: 100%;
  padding: 16px 18px;
  font: 1.05rem var(--font-sans);
  color: var(--text);
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
}
.pal-input:focus-visible { outline: 2px solid var(--accent-2); outline-offset: -2px; }
.pal-list { flex: 1; min-height: 0; margin: 0; padding: 6px; list-style: none; overflow-y: auto; }
.pal-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border-radius: var(--r-md); cursor: pointer; }
.pal-item.active { background: var(--control-hover); border-left: 3px solid var(--accent-2); }
.pal-main { display: flex; flex-direction: column; min-width: 0; }
.pal-title { overflow-wrap: anywhere; }
.pal-group { color: var(--muted); font-size: 0.78rem; }
.pal-keys { flex: none; }
.pal-empty { margin: 0; padding: 20px 18px; color: var(--muted); }
.pal-foot { flex: none; display: flex; gap: 16px; padding: 8px 18px; border-top: 1px solid var(--border); color: var(--muted); font-size: 0.8rem; }
.pal-head { flex: none; display: flex; align-items: center; justify-content: space-between; padding: 10px 12px 4px 20px; }
.pal-heading { margin: 0; font-size: 1.1rem; }
.pal-heading:focus { outline: none; }
.pal-body { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 20px 8px; columns: 2 240px; column-gap: 28px; }
.ks-group { break-inside: avoid; margin-bottom: 14px; }
.ks-group h3 { margin: 10px 0 2px; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.pal-foot-note { flex: none; margin: 0; padding: 10px 20px 14px; border-top: 1px solid var(--border); color: var(--muted); font-size: 0.85rem; }
.pal-shortcuts { max-height: min(80vh, 640px); }
.kb-chord { display: inline-flex; gap: 3px; }
.kb-or { color: var(--muted); padding: 0 2px; }
@media (max-width: 640px) {
  .modal-backdrop { padding-top: max(8vh, env(safe-area-inset-top)); }
  .pal-body { columns: 1; }
}

/* ---------- Settings: search and advanced options ---------- */
.sp-search { flex: none; padding: 10px 18px; border-bottom: 1px solid var(--border); }
.sp-search input {
  width: 100%;
  padding: 9px 12px;
  font: inherit;
  color: var(--text);
  background: var(--control);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.s-miss { display: none !important; }
.sp-body.searching .sp-nav { display: none; }
.sp-body.searching .spane > :not(.setting):not(h3):not(details) { display: none; }
.s-empty { margin: 16px 0; color: var(--muted); overflow-wrap: anywhere; }
details.adv { margin: 10px 0; border: 1px solid var(--border); border-radius: var(--r-md); padding: 0 14px; }
details.adv > summary { padding: 10px 0; cursor: pointer; color: var(--muted); }
details.adv[open] > summary { color: var(--text); }
details.adv .setting:last-child { border-bottom: 0; }

/* ---------- Notices (offline, storage, errors) ---------- */
.notices {
  position: fixed;
  bottom: calc(68px + env(safe-area-inset-bottom)); /* above the toast */
  left: 50%;
  z-index: 65; /* above the settings and library panels (50), below the setup dialog (70) */
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: min(640px, calc(100vw - 24px));
  transform: translateX(-50%);
  pointer-events: none;
}
.notice {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px 10px 14px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-size: 0.9rem;
  pointer-events: auto;
}
.notice-warn { border-left-color: #e0a526; }
.notice-error { border-left-color: var(--accent); }
.notice-text { min-width: 0; overflow-wrap: anywhere; }
.notice-actions { display: inline-flex; align-items: center; gap: 8px; flex: none; }
.notice-x { min-width: 32px; min-height: 32px; padding: 0 8px; background: transparent; border-color: transparent; color: var(--muted); font-size: 1.2rem; line-height: 1; }
body.playing .notices { display: none; }

/* ---------- Empty states ---------- */
.lib-empty { margin: 0; padding: 12px 14px; border: 1px dashed var(--border); border-radius: var(--r-md); color: var(--muted); font-size: 0.9rem; }

/* ---------- Upgrade flow (visuals only; billing fills them in) ---------- */
.up-dialog { width: min(720px, 100%); max-height: min(720px, calc(100dvh - 12dvh - 24px)); }
.up-head { flex: none; display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 0 20px; }
.up-chip, .pro-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border: 1px solid color-mix(in srgb, var(--accent-2) 55%, var(--border));
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent-2) 14%, transparent);
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 600;
}
.pro-badge { min-height: 0; cursor: pointer; }
.up-lock { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.up-body { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 20px 12px; }
.up-title { margin: 8px 0 6px; font-size: 1.4rem; }
.up-title:focus { outline: none; }
.up-benefit { margin: 0 0 14px; color: var(--muted); }
.up-demo { margin: 0 0 12px; padding: 6px 10px; border-radius: var(--r-md); background: color-mix(in srgb, #e0a526 18%, transparent); font-size: 0.85rem; }
.up-plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.up-plan { position: relative; display: flex; flex-direction: column; gap: 6px; padding: 16px; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--stage); }
.up-plan-hl { border-color: var(--accent-2); box-shadow: inset 0 0 0 1px var(--accent-2); }
.up-plan h3 { margin: 0; font-size: 1.1rem; }
.up-tag { position: absolute; top: 14px; right: 14px; padding: 1px 8px; border-radius: 999px; background: var(--control-hover); font-size: 0.75rem; }
.up-tagline { margin: 0; color: var(--muted); font-size: 0.9rem; }
.up-price { margin: 4px 0; font-size: 1.15rem; font-weight: 600; min-height: 1.5em; }
.up-bullets { flex: 1; margin: 0 0 8px; padding: 0; list-style: none; font-size: 0.92rem; }
.up-bullets li { position: relative; padding: 3px 0 3px 22px; }
.up-bullets li::before { content: "\2713"; position: absolute; left: 0; color: var(--accent-2); font-weight: 700; }
.up-note { margin: 0; color: var(--muted); font-size: 0.82rem; }
.up-fine { margin: 12px 0 0; color: var(--muted); font-size: 0.82rem; }
.up-interval { display: inline-flex; margin: 0 0 12px; padding: 3px; border: 1px solid var(--border); border-radius: 999px; background: var(--control); }
.up-seg { border: 0; border-radius: 999px; background: transparent; padding: 6px 16px; color: var(--muted); }
.up-seg[aria-checked="true"] { background: var(--accent-2); color: var(--on-accent, #fff); }
.up-foot { flex: none; display: flex; align-items: center; justify-content: flex-end; gap: 12px; padding: 12px 20px 16px; border-top: 1px solid var(--border); }
.up-locked { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 14px 16px; border: 1px dashed var(--border); border-radius: var(--r-lg); }
.up-locked .up-lock { width: 22px; height: 22px; color: var(--muted); flex: none; }
.up-locked-text { flex: 1 1 200px; display: flex; flex-direction: column; min-width: 0; }
.up-locked-text span { color: var(--muted); font-size: 0.9rem; }

/* ---------- Accessibility ---------- */
.skip-link {
  position: fixed;
  top: 8px;
  left: 8px;
  z-index: 90;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  box-sizing: border-box;
  padding: 8px 14px;
  border-radius: var(--r-md);
  background: var(--accent-2);
  color: var(--on-accent, #fff);
  font-weight: 600;
  text-decoration: none;
  transform: translateY(-200%);
}
.skip-link:focus { transform: none; }
/* WCAG 2.2 target size: the small "i" help buttons were 20px. */
.info-btn { width: 24px; height: 24px; position: relative; }
/* The drawn "i" stays 24 px; its touch area is 44 px (principle 36). */
.info-btn::after { content: ""; position: absolute; inset: -11px; } /* 24 px box with a 1 px border: -11px each side makes 44 px */
/* The system asks for reduced motion: no animation or transition anywhere, whatever the in-app switch says. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; transition-delay: 0s !important; scroll-behavior: auto !important; }
}

/* ---------- Phone layout ---------- */
.empty-state svg { flex: none; } /* it was squashed to 11px when the stage was short */
@media (max-width: 640px) {
  /* The empty invitation grows the stage instead of being squeezed into it. */
  body[data-state="empty"] .stage { height: auto; min-height: 220px; }
  body[data-state="empty"] .stage:not(.showing-msg) .empty-state { position: relative; inset: auto; padding: 28px 20px; }
  .empty-actions { flex-direction: column; align-items: stretch; width: 100%; max-width: 300px; }
  .empty-actions button { width: 100%; }
}
/* The header holds eleven buttons (about 530px). On a phone they overflowed the screen
   and stretched the whole page sideways, so let them wrap onto a second row. */
@media (max-width: 700px) {
  .top { flex-wrap: wrap; row-gap: 8px; }
  .top-actions { flex: 1 1 100%; flex-wrap: wrap; justify-content: center; }
}
/* Three buttons left of play and one right of it did not fit beside a centered play button
   on a phone, so the grid grew on the left and pushed play off center. Make them smaller. */
@media (max-width: 480px) {
  .controls { gap: 6px; }
  .ctl-left, .ctl-right { gap: 4px; }
  .controls .icon-btn { width: 40px; height: 40px; }
}
@media (max-width: 480px) {
  .top { padding-bottom: 0; }
  .settings-panel { width: 100vw; }
  .ob-body { padding-left: 16px; padding-right: 16px; }
  .ob-head, .ob-foot { padding-left: 16px; padding-right: 16px; }
}
body[data-state="empty"] .word { display: none; } /* it kept 100% width and pushed the empty invitation sideways */
@media (max-width: 480px) and (pointer: coarse) {
  #btnHelp { display: none; } /* keyboard shortcuts mean little on a phone; the command button stays */
}
@media (max-width: 360px) {
  .round-btn { width: 42px; height: 42px; }
  .top-actions { gap: 2px; }
  .top h1 { font-size: 1.35rem; }
}

/* ---------- Long texts ---------- */
/* A closed side panel still held a laid-out textarea; with 150,000 words that cost
   ~150 ms on every text change. Skip its rendering until the panel opens, after the
   slide-out has finished (browsers without allow-discrete just skip it at once). */
.settings-panel:not(.open) .sp-content {
  content-visibility: hidden;
  transition: content-visibility 0s linear 0.3s;
  transition-behavior: allow-discrete;
}

/* ---------- About this text (shown when a new text is first started) ---------- */
.details-dialog { max-width: 460px; }
.details-title { margin: 0 0 6px; font-size: 1.2rem; }
.details-note { margin: 0 0 14px; color: var(--muted); line-height: 1.45; }
.details-field { display: block; margin: 0 0 12px; }
.details-label { display: block; margin-bottom: 4px; font-size: 0.82rem; color: var(--muted); }
.details-field input { width: 100%; box-sizing: border-box; }
.details-hint { display: block; margin-top: 3px; font-size: 0.78rem; color: var(--muted); }
.details-never { display: flex; align-items: center; gap: 8px; margin: 4px 0 14px; font-size: 0.88rem; color: var(--muted); }
.details-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Your texts: search, filter chips and cards (design principles 26 and 27) ---------- */
.lib-toolbar { display: flex; flex-direction: column; align-items: stretch; gap: 10px; margin-bottom: 12px; }
.lib-search { width: 100%; box-sizing: border-box; min-height: 44px; }
.lib-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.lib-chip { min-height: 36px; padding: 4px 12px; border-radius: 999px; font-size: 0.85rem; background: var(--control); border-color: var(--border); color: var(--muted); }
.lib-chip[aria-pressed="true"] { background: var(--accent-2); border-color: var(--accent-2); color: var(--on-accent, #fff); }
.lib-tools { display: flex; flex-wrap: wrap; gap: 6px; }
.lib-cards { display: flex; flex-direction: column; gap: 10px; }
.lib-card { display: flex; flex-direction: column; gap: 8px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); }
.lib-card.is-selected { border-color: var(--accent-2); box-shadow: 0 0 0 2px var(--accent-2); }
.lib-card-top { display: flex; align-items: flex-start; gap: 6px; min-width: 0; }
.lib-card-main { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 2px 4px; text-align: left; background: transparent; border-color: transparent; font: inherit; }
.lib-card-main strong { max-width: 100%; font-weight: 650; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.lib-sub { font-size: 0.82rem; color: var(--muted); line-height: 1.4; }
.lib-meter { width: 100%; height: 5px; border-radius: var(--r-sm); background: var(--control); overflow: hidden; }
.lib-meter i { display: block; height: 100%; background: var(--accent-2); }
.lib-card-actions { display: flex; gap: 8px; }
.lib-card-go { flex: 1 1 auto; min-height: 44px; background: var(--accent-2); border-color: var(--accent-2); color: var(--on-accent, #fff); font-weight: 600; }
.lib-collection .lib-card-go { background: var(--control); border-color: var(--border); color: var(--text); }
.lib-card-more { flex: none; min-height: 44px; }
.lib-more { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.lib-more button { min-height: 40px; }
.lib-danger { color: var(--accent); border-color: var(--accent); background: transparent; margin-left: auto; }
.lib-empty-card { display: flex; flex-direction: column; gap: 6px; padding: 18px; border: 1px dashed var(--border); border-radius: var(--radius); }
.lib-empty-card span { color: var(--muted); line-height: 1.5; font-size: 0.9rem; }
@media (min-width: 640px) { #collectionList.lib-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); } }

/* ---------- Top bar: labelled sections on the left, tools on the right ---------- */
.top-actions { align-items: center; justify-content: flex-end; gap: 8px 14px; }
.top-nav, .top-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.top-tools { padding-left: 12px; border-left: 1px solid var(--border); }
.round-btn.has-label .rb-label { display: none; font-size: 0.9rem; font-weight: 500; }
@media (min-width: 1040px) {
  .top { max-width: 1180px; }
  .top-nav .round-btn.has-label { width: auto; padding: 0 14px 0 11px; gap: 7px; border-radius: 999px; color: var(--text); }
  .round-btn.has-label .rb-label { display: inline; }
  .top-nav .round-btn.has-label[aria-expanded="true"] { background: var(--control); }
}
@media (max-width: 560px) { .top-tools { padding-left: 0; border-left: 0; } }

/* ---------- Panels: one look for Your texts, Notes, Train, Import, Progress and Settings ---------- */
.settings-panel { background: var(--bg); }
.sp-head { position: sticky; top: 0; z-index: 2; padding: 16px 18px 16px 24px; background: var(--card); }
.sp-head h2 { font-size: 1.3rem; letter-spacing: 0.005em; }
.sp-content { padding-top: 18px; }
.lib-content { background: var(--bg); }
.lib-section { padding: 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); margin-bottom: 14px; }
.lib-section > h3 { font-size: 0.8rem; margin-bottom: 12px; }
.lib-section .row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.lib-section textarea { width: 100%; box-sizing: border-box; min-height: 120px; }
.sp-content .tr-card, .sp-content .st-card-box { border-radius: var(--radius); }
@media (max-width: 560px) { .sp-content { padding-left: 14px; padding-right: 14px; } .lib-section { padding: 14px; } }

/* ---------- Full-screen pages: Your texts, Settings, Train, Progress and Import use the whole window ---------- */
.settings-panel.page, .settings-panel.left.page, .settings-panel.stats-panel.page {
  left: 0; right: 0; width: 100vw; max-width: none; border: 0; box-shadow: none;
  transform: translateY(18px); opacity: 0;
  transition: transform 0.25s ease, opacity 0.25s ease, visibility 0s linear 0.25s;
}
.settings-panel.page.open, .settings-panel.left.page.open, .settings-panel.stats-panel.page.open {
  transform: none; opacity: 1; transition: transform 0.25s ease, opacity 0.25s ease;
}
.settings-panel.page .sp-head { padding-left: max(24px, calc((100% - 1120px) / 2)); padding-right: max(18px, calc((100% - 1120px) / 2)); }
.settings-panel.page .sp-search { max-width: 1120px; width: 100%; margin: 0 auto; box-sizing: border-box; }
.settings-panel.page .sp-body { width: 100%; max-width: 1120px; margin: 0 auto; }
.settings-panel.page .sp-nav { width: 230px; }
.settings-panel.page .sp-content { padding-left: max(20px, 3vw); padding-right: max(20px, 3vw); }
#trainPanel .sp-content, #statsPanel .sp-content, #importPanel .sp-content {
  padding-left: max(20px, calc((100% - 1040px) / 2)); padding-right: max(20px, calc((100% - 1040px) / 2));
}
#libraryPanel .lib-content { padding-left: max(20px, calc((100% - 1120px) / 2)); padding-right: max(20px, calc((100% - 1120px) / 2)); }
/* The padding above already centres the panel at 1120 px; the 1100 px cap on .shelf-content as well squeezed the shelf narrower the wider the window got. */
#libraryPanel .lib-content.shelf-content { max-width: none; }

/* ---------- Progress: tabs instead of one long page ---------- */
.st-tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin: 0 0 16px; overflow-x: auto; }
.st-tab { flex: 0 0 auto; min-height: 44px; padding: 8px 16px; border: 0; border-bottom: 3px solid transparent; border-radius: 8px 8px 0 0; background: transparent; color: var(--muted); font: inherit; }
.st-tab:hover { background: var(--control); color: var(--text); }
.st-tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent-2); font-weight: 600; }
@media (min-width: 900px) { #statsPanel .st-pane { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 20px; align-items: start; } #statsPanel .st-pane > .st-empty { grid-column: 1 / -1; } }

/* Settings: two columns on a wide page so there is less to scroll through */
@media (min-width: 1000px) {
  .settings-panel.page .spane { column-count: 2; column-gap: 44px; }
  .settings-panel.page .spane > h3, .settings-panel.page .spane > .lead { break-after: avoid; }
  .settings-panel.page .spane .setting, .settings-panel.page .spane .info-text, .settings-panel.page .spane .row, .settings-panel.page .spane .note { break-inside: avoid; }
  .settings-panel.page .spane .theme-grid { column-span: all; }
  /* The account block (fields, buttons, message) and the plan block stay in one column, never split between two. */
  .settings-panel.page .spane #accountBlock, .settings-panel.page .spane .plan-block, .settings-panel.page .spane .acct-form, .settings-panel.page .spane #accountOut { break-inside: avoid; }
}

/* ---------- Every text field and menu follows the theme, wherever it appears (dialogs, panels, pages) ---------- */
:where(input:not([type]), input[type="text"], input[type="url"], input[type="search"], input[type="number"], input[type="email"], input[type="password"], select) {
  font: inherit;
  color: var(--text);
  background-color: var(--control);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 8px 10px;
  box-sizing: border-box;
  color-scheme: inherit;
}
:where(input, select, textarea)::placeholder { color: var(--muted); opacity: 1; }
:where(input[type="checkbox"], input[type="radio"]) { accent-color: var(--accent-2); }
:where(input, select, textarea):disabled { opacity: 0.6; }
.details-field input { width: 100%; min-height: 44px; }

/* Labels and callouts (design audit) */
.ob-sub, .ks-group h3 { text-transform: none; letter-spacing: 0; font-size: 0.9rem; font-weight: 600; }
.ob-honest { border: 1px solid color-mix(in srgb, var(--accent-2) 40%, var(--border)); border-radius: var(--r-lg); }

/* ---------- Motion (design principles 33 and 52: movement that answers what you did, quiet by default) ----------
   Everything below goes still with Settings > Appearance > Screen animations off (body.no-anim) and when the system asks for reduced motion,
   by the two rules above that switch every animation and transition off. Nothing here touches the stage, the flashing word or the guides, and
   nothing glows: it is movement, fades and a small scale, never a tinted shadow. */
:root { --mo-fast: 0.16s; --mo-base: 0.26s; --mo-slow: 0.42s; }
@keyframes mo-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes mo-fade-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes mo-rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes mo-pop { from { opacity: 0; transform: translateY(10px) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes mo-pop-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(6px) scale(0.98); } }
@keyframes mo-slide-next { from { opacity: 0; transform: translateX(26px); } to { opacity: 1; transform: none; } }
@keyframes mo-slide-prev { from { opacity: 0; transform: translateX(-26px); } to { opacity: 1; transform: none; } }
@keyframes mo-bar-in { from { opacity: 0; transform: translate(-50%, 18px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes mo-bar-out { from { opacity: 1; transform: translate(-50%, 0); } to { opacity: 0; transform: translate(-50%, 12px); } }
@keyframes mo-star { from { opacity: 0; transform: scale(0.3) rotate(-40deg); } 60% { opacity: 1; transform: scale(1.18) rotate(8deg); } to { opacity: 1; transform: none; } }
@keyframes mo-mark { from { outline-offset: 8px; outline-color: transparent; } to { outline-offset: 1px; } }

/* Every button, list and choice eases between its states, and gives a little when pressed. (:where keeps these the weakest rules, so any
   control with its own transition keeps it.) The book covers have their own one-transform motion and are left alone. */
:where(button, select, .chip, .stab) { transition: background-color var(--mo-fast) ease, color var(--mo-fast) ease, border-color var(--mo-fast) ease, opacity var(--mo-fast) ease, transform var(--mo-fast) var(--ease-out); }
:where(button:not(:disabled):not(.cover)):active { transform: scale(0.96); }
body { transition: background-color var(--mo-slow) ease, color var(--mo-slow) ease; }
body.no-anim { transition: none !important; } /* the switch rule above covers what is inside the body, not the body itself */
html .toast { transform: translate(-50%, 10px); transition: opacity 0.2s ease, transform var(--mo-base) var(--ease-out); }
html .toast.show { transform: translate(-50%, 0); }

/* Pages and tabs: what you open rises into place. */
.spane, .st-pane { animation: mo-rise var(--mo-base) var(--ease-out) both; }
.settings-panel.open .lib-section, .settings-panel.open .tr-card, .settings-panel.open .st-card-box { animation: mo-rise var(--mo-slow) var(--ease-out) both; }
.settings-panel.open .lib-section:nth-child(2), .settings-panel.open .tr-card:nth-child(2) { animation-delay: 0.06s; }
.settings-panel.open .lib-section:nth-child(3), .settings-panel.open .tr-card:nth-child(3) { animation-delay: 0.12s; }
.settings-panel.open .lib-section:nth-child(n+4), .settings-panel.open .tr-card:nth-child(n+4) { animation-delay: 0.18s; }

/* Windows, menus and pop-ups: they fade in and settle, and the scrim fades with them. */
dialog[open] { animation: mo-pop var(--mo-base) var(--ease-out); }
dialog::backdrop { animation: mo-fade var(--mo-base) ease; }
.modal-backdrop, .move-dialog { animation: mo-fade var(--mo-base) ease; }
.modal-backdrop > *, .move-card { animation: mo-pop var(--mo-base) var(--ease-out) both; }
.info-pop, .help-pop:not([hidden]) { animation: mo-pop var(--mo-base) var(--ease-out) both; }
.coll-menu:not([hidden]) { transform-origin: top right; animation: mo-pop var(--mo-fast) var(--ease-out) both; }

/* The "This Text" page. Opening a tab rises its parts in turn; moving to the next or previous section slides the text the way you are going. */
.tt-enter > * { animation: mo-rise var(--mo-slow) var(--ease-out) both; }
.tt-enter > *:nth-child(2) { animation-delay: 0.06s; }
.tt-enter > *:nth-child(3) { animation-delay: 0.12s; }
.tt-enter.tt-enter-next > * { animation-name: mo-slide-next; animation-duration: var(--mo-base); animation-delay: 0s; }
.tt-enter.tt-enter-prev > * { animation-name: mo-slide-prev; animation-duration: var(--mo-base); animation-delay: 0s; }
.tt-enter .tt-top > *, .tt-enter .tt-take, .tt-enter .tt-section, .tt-enter .annot-all-row { animation: mo-rise var(--mo-slow) var(--ease-out) both; }
.tt-enter .tt-top > *:nth-child(2), .tt-enter .tt-take:nth-child(2), .tt-enter .tt-section:nth-child(2), .tt-enter .annot-all-row:nth-child(2) { animation-delay: 0.05s; }
.tt-enter .tt-take:nth-child(3), .tt-enter .tt-section:nth-child(3), .tt-enter .annot-all-row:nth-child(3) { animation-delay: 0.1s; }
.tt-enter .tt-take:nth-child(4), .tt-enter .tt-section:nth-child(4), .tt-enter .annot-all-row:nth-child(4) { animation-delay: 0.15s; }
.tt-enter .tt-take:nth-child(n+5), .tt-enter .tt-section:nth-child(n+5), .tt-enter .annot-all-row:nth-child(n+5) { animation-delay: 0.2s; }
.tt-enter:not(.tt-enter-next):not(.tt-enter-prev) .annot-bar { animation: mo-bar-in var(--mo-slow) var(--ease-out) 0.15s both; }
.tt-edit > * { animation: mo-fade var(--mo-base) ease both; }
.tt-take.tt-new { animation: mo-pop var(--mo-base) var(--ease-out) both; }
button.tt-icon svg { transition: transform var(--mo-base) var(--ease-out); }
button.tt-icon:hover svg { transform: rotate(-12deg) scale(1.12); }
.ai-star { animation: mo-star 0.6s var(--ease-out) both; }
.annot-mark-open { animation: mo-mark var(--mo-base) var(--ease-out); }
.annot-mark { transition: background-color var(--mo-fast) ease; }
button.annot-all-row { transition: background-color var(--mo-fast) ease, transform var(--mo-fast) var(--ease-out); }
button.annot-all-row:hover:not(:disabled) { transform: translateX(3px); }

/* The note window and the undo bar come in and go out. */
.annot-pop-back { animation: mo-fade var(--mo-fast) ease both; }
.annot-pop { animation: mo-pop var(--mo-base) var(--ease-out) both; }
.annot-pop-back.is-leaving { pointer-events: none; animation: mo-fade-out 0.16s ease both; }
.annot-pop-back.is-leaving .annot-pop { animation: mo-pop-out 0.16s ease both; }
.annot-undo { animation: mo-bar-in var(--mo-base) var(--ease-out) both; }
.annot-undo.is-leaving { pointer-events: none; animation: mo-bar-out 0.18s ease both; }
