/* Onboarding: full-screen welcome flow and profile preferences.
 * Uses the Nanani/Reader tokens; the few onboarding-only tones are scoped here. */
.onb {
  --onb-purple: #3b2a6e; --onb-selection: #f1edf9; --onb-selected-border: #7d62b1;
  --onb-mark: #e1d4f4; --onb-focus: #7652bb; --onb-soft: #eff1f5; --onb-success: #24756a;
  position: fixed; inset: 0; z-index: 1000;
  display: flex; flex-direction: column; height: 100dvh;
  background: var(--bg); color: var(--ink);
  font: 16px/1.5 var(--sans); -webkit-tap-highlight-color: transparent;
}
[data-theme="reader"] .onb {
  --onb-purple: #dfc6f1; --onb-selection: #30263b; --onb-selected-border: #b594d0;
  --onb-mark: #604b73; --onb-focus: #d4b4ef; --onb-soft: #241f19; --onb-success: #9ac9b1;
}
.onb[hidden] { display: none; }
body.onb-open { overflow: hidden; }
.onb *, .onb *::before, .onb *::after { box-sizing: border-box; }
/* Zero-specificity resets: component classes below always win. */
:where(.onb) :where(button, input, textarea) { font: inherit; color: inherit; touch-action: manipulation; }
:where(.onb) button { cursor: pointer; }
:where(.onb) button:disabled { cursor: default; }
:where(.onb) :focus-visible { outline: 3px solid var(--onb-focus); outline-offset: 5px; }
:where(.onb) svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.onb-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; margin: 0; }

/* Top bar */
.onb-top { flex: none; width: min(1280px, 100%); margin: 0 auto; padding: 20px 40px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.onb-brand { display: inline-flex; gap: 11px; align-items: center; font: 650 19px var(--font-brand); letter-spacing: -.04em; white-space: nowrap; }
.onb-brand img { width: 37px; height: 43px; object-fit: contain; }
.onb-brand-rest { font-weight: 400; letter-spacing: -.025em; color: var(--muted); }
.onb-actions { display: flex; align-items: center; gap: 18px; }
/* The pressed state is a thumb behind two equal buttons; FLIP slides it on switch. */
.onb-lang { position: relative; display: inline-grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.onb-lang-thumb { position: absolute; top: 3px; bottom: 3px; left: 3px; width: calc(50% - 3px); border-radius: 7px; background: var(--onb-selection); }
.onb-lang[data-value="en"] .onb-lang-thumb { left: 50%; }
.onb-lang button { position: relative; border: 0; background: transparent; border-radius: 7px; padding: 5px 9px; font: 600 12px var(--font-brand); color: var(--muted); min-height: 30px; min-width: 34px; transition: color 200ms ease-out; }
.onb-lang button[aria-pressed="true"] { color: var(--ink); }
.onb-icon-button { width: 42px; height: 42px; display: inline-grid; place-items: center; background: transparent; border: 1px solid var(--line); border-radius: 12px; }
.onb-icon-button:hover { background: var(--hover); }
.onb-icon-button:active { transform: scale(.96); }
.onb-link { border: 0; background: transparent; padding: 8px 0; font: 500 14px var(--font-brand); }
.onb-link:hover { text-decoration: underline; text-underline-offset: 4px; }

/* Flow: questions may scroll, actions never cover them. */
.onb-flow { flex: 1; min-height: 0; width: min(640px, calc(100% - 48px)); margin: clamp(12px, 4vh, 36px) auto 0; display: grid; grid-template-rows: auto minmax(0, 1fr); padding-bottom: max(12px, env(safe-area-inset-bottom)); }
.onb[data-screen="tutorial"] .onb-flow, .onb[data-screen="ready"] .onb-flow { grid-template-rows: minmax(0, 1fr); }
.onb-way { display: flex; align-items: center; gap: 19px; margin-bottom: 28px; min-height: 32px; }
.onb-back { border: 0; width: 30px; height: 32px; display: grid; place-items: center; padding: 0; background: transparent; color: var(--muted); }
.onb-back:disabled { visibility: hidden; }
.onb-back:hover { color: var(--ink); }
.onb-progress { height: 4px; flex: 1; display: flex; gap: 6px; }
.onb-progress span { flex: 1; border-radius: 3px; background: var(--line); transition: background-color 200ms ease-out; }
.onb-progress span.done { background: var(--onb-purple); }
.onb-step { font: 500 12px var(--font-brand); font-variant-numeric: tabular-nums; color: var(--muted); min-width: 38px; text-align: right; }
.onb-panel { display: grid; grid-template-rows: minmax(0, 1fr) auto; min-height: 0; }
.onb-body { min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 6px; margin: 0 -6px; scrollbar-color: var(--line) var(--bg); scrollbar-width: thin; }
.onb-panel.enter > .onb-body { animation: onb-arrive 210ms cubic-bezier(.16, 1, .3, 1) both; }
@keyframes onb-arrive { from { opacity: .6; transform: translateX(12px); } to { opacity: 1; transform: none; } }
.onb h1 { font: 650 36px/1.18 var(--font-brand); letter-spacing: -.035em; margin: 0 0 24px; text-wrap: balance; }
.onb h1:focus { outline: none; }
.onb-lead { color: var(--muted); margin: -12px 0 20px; font-size: 15px; }
.onb-count { margin-left: 8px; color: var(--muted); font-weight: 400; font-size: 14px; font-variant-numeric: tabular-nums; }
.onb-error { color: var(--danger); font-size: 14px; margin: 16px 0 0; }

/* Choices */
.onb-choices { display: grid; gap: 12px; }
/* Resets the app-wide label style (muted 13px block with a bottom margin). */
.onb-choice { position: relative; display: flex; align-items: center; gap: 17px; min-height: 76px; margin: 0; padding: 18px 21px; color: var(--ink); font-size: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; cursor: pointer; transition: border-color 130ms, background-color 130ms, transform 130ms; }
.onb-choice:hover { border-color: var(--onb-selected-border); }
.onb-choice:active { transform: scale(.99); }
.onb-choice:has(input:checked) { background: var(--onb-selection); border-color: var(--onb-selected-border); }
.onb-choice:has(input:focus-visible) { outline: 3px solid var(--onb-focus); outline-offset: 4px; }
.onb-choice input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; padding: 0; border: 0; pointer-events: none; }
.onb-dot { margin-left: auto; width: 19px; height: 19px; border: 1.5px solid var(--line); border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--panel); }
.onb-choice input:checked ~ .onb-dot { border-color: var(--onb-purple); background: var(--onb-purple); }
.onb-dot svg { width: 12px; height: 12px; stroke: var(--panel); stroke-width: 2.5; opacity: 0; }
.onb-choice input:checked ~ .onb-dot svg { opacity: 1; }
.onb-choice-title { font: 550 16px var(--font-brand); }
.onb-languages { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.onb-language-cards { display: contents; }
.onb-variant-slot { display: flex; align-items: center; min-width: 0; }
.onb-variant-slot:empty { display: none; }
.onb-variant-slot .onb-variant { flex-direction: column; align-items: flex-start; padding: 0 0 0 6px; gap: 8px; }
.onb-variant-slot .onb-variant-label { margin: 0; }
.onb-variant-slot .onb-variant button { width: 100%; max-width: 220px; text-align: left; }
/* Five courses: compact enough for three rows without scrolling on laptops. */
.onb-choice.onb-language { display: block; min-height: 122px; padding: 20px 24px 18px; }
.onb-language .onb-dot { position: absolute; right: 20px; top: 20px; }
.onb-greeting { font: 500 34px/1.2 var(--serif); letter-spacing: -.03em; display: block; margin-bottom: 14px; }
.onb-language-name { display: flex; align-items: center; gap: 10px; font: 550 15px var(--font-brand); }
.onb-flag { width: 23px; height: 16px; border-radius: 3px; overflow: hidden; display: inline-block; flex: none; border: 1px solid rgba(0, 0, 0, .08); }
.onb-flag svg { width: 100%; height: 100%; stroke: none; }
.onb-variant { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; padding: 20px 0 4px; }
.onb-levels + .onb-variant, .onb-variant + .onb-levels { margin-top: 0; }
.onb-body > .onb-variant { padding: 0 0 20px; }
.onb-variant-label { font-size: 14px; color: var(--muted); margin-right: 3px; }
.onb-variant button { border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; background: var(--panel); font-size: 13px; min-height: 34px; }
.onb-variant button[aria-pressed="true"] { background: var(--onb-selection); border-color: var(--onb-selected-border); }
.onb-variant button:hover { border-color: var(--onb-selected-border); }
.onb-levels { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.onb-levels .onb-choice { padding: 20px 18px; gap: 13px; min-height: 84px; }
.onb-levels .onb-choice-title { font-size: 15px; }
.onb-level-code { font: 600 21px var(--font-brand); min-width: 32px; color: var(--onb-purple); }
.onb-goal-icon { width: 38px; height: 38px; display: grid; place-items: center; background: var(--onb-soft); border-radius: 10px; color: var(--onb-purple); }
.onb-other-field { margin-top: 4px; }
.onb-other-label { display: block; margin: 13px 0 8px; font-size: 14px; }
.onb-other { width: 100%; resize: vertical; min-height: 90px; max-height: 170px; padding: 14px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; caret-color: var(--onb-purple); font-size: 16px; margin-bottom: 8px; }
.onb-topics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.onb-topics .onb-choice { min-height: 72px; padding: 16px 18px; }
.onb-topics .onb-choice-title { font-size: 15px; }
.onb-topics .onb-dot { border-radius: 5px; }
.onb-topic-icon { color: var(--onb-purple); display: grid; place-items: center; }
.onb-times { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.onb-time { flex-direction: column; justify-content: center; gap: 4px; padding: 28px 12px; min-height: 132px; }
.onb-time .onb-dot { display: none; }
.onb-time-number { font: 600 34px/1.1 var(--font-brand); letter-spacing: -.035em; font-variant-numeric: tabular-nums; }
.onb-time-unit { color: var(--muted); font-size: 14px; }
.onb-preview { margin-top: 24px; padding: 16px 0; display: flex; align-items: center; gap: 14px; border-block: 1px solid var(--line); color: var(--muted); font-size: 15px; }
.onb-preview svg { color: var(--onb-purple); }
.onb-preview strong { font-weight: 500; color: var(--ink); }

/* Vocabulary suggestion */
.onb-word-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.onb-lexical { min-height: 72px; justify-content: center; padding: 16px 10px; gap: 10px; text-align: center; }
.onb-lexical .onb-choice-title { font: 500 22px/1.2 var(--serif); overflow-wrap: anywhere; }
.onb-lexical .onb-dot { display: none; }
.onb-lexical input:checked ~ .onb-choice-title { color: var(--onb-purple); }
.onb-survey-meta { display: flex; justify-content: space-between; align-items: center; gap: 12px; color: var(--muted); font-size: 14px; margin-bottom: 14px; }
.onb-survey-meta .onb-text { padding: 5px 0; font-size: 13px; }
.onb-survey-result { margin: 8px 0 22px; padding: 22px 0; border-block: 1px solid var(--line); display: flex; align-items: center; gap: 24px; }
.onb-survey-level { font: 600 54px/1.1 var(--serif); color: var(--onb-purple); }
.onb-survey-result p { margin: 0; font-size: 17px; }
.onb-correction { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
.onb-correction .onb-choice { padding: 12px 8px; justify-content: center; min-height: 48px; }
.onb-correction .onb-dot { display: none; }

/* Tutorial and ready */
.onb-demo-top { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 14px; margin-bottom: 24px; }
.onb-inline { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; }
.onb-inline svg { width: 17px; height: 17px; }
.onb-instruction { font-size: 16px; color: var(--muted); margin: -12px 0 24px; }
.onb-line { font: 400 38px/1.6 var(--serif); letter-spacing: -.015em; padding: 30px 0; margin: 0; border-block: 1px solid var(--line); text-wrap: balance; }
.onb-word-unit { white-space: nowrap; }
.onb-word { font: inherit; line-height: 1.25; display: inline; border: 0; padding: 1px 8px; margin: 0 1px; background: var(--onb-mark); color: var(--ink); border-radius: 6px; transition: background-color 150ms ease-out, color 150ms ease-out; }
.onb-word:hover { box-shadow: 0 0 0 2px var(--onb-selected-border); }
.onb-word.selected { background: var(--onb-purple); color: var(--panel); }
.onb-definition { min-height: 100px; padding: 20px 0; border-bottom: 1px solid var(--line); }
.onb-definition strong { display: block; font: 500 26px var(--serif); margin-bottom: 4px; }
.onb-meaning { margin: 0; color: var(--muted); font-size: 16px; }
.onb-summary { display: flex; flex-wrap: wrap; gap: 10px 18px; color: var(--muted); font-size: 15px; margin: -10px 0 26px; }
.onb-summary span:empty { display: none; }
.onb-celebrate { display: inline-block; margin-left: .3em; transform-origin: 50% 80%; animation: onb-pop 520ms cubic-bezier(.34, 1.56, .64, 1) 120ms both; }
@keyframes onb-pop { from { opacity: 0; transform: scale(.4) rotate(-18deg); } to { opacity: 1; transform: none; } }
.onb-ready-word { display: flex; justify-content: space-between; align-items: center; padding: 22px 0; border-block: 1px solid var(--line); gap: 20px; margin-bottom: 24px; }
.onb-ready-word > svg { color: var(--onb-success); }
.onb-ready-word strong { font: 500 27px var(--serif); }
.onb-ready-word span { display: block; color: var(--muted); font-size: 15px; margin-top: 4px; }
.onb-ready-lead { margin: 0 0 12px; }
.onb-ready-links { display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; }

/* Actions */
.onb-footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 76px; margin: 0; padding: 12px 0 4px; background: var(--bg); flex: none; }
.onb-spacer { flex: 1; }
.onb-text { background: transparent; border: 0; padding: 10px 0; color: var(--muted); font-size: 14px; text-decoration: underline; text-underline-offset: 4px; }
.onb-text:hover { color: var(--ink); }
.onb-footer .onb-text { text-decoration: none; }
.onb-primary { min-height: 52px; min-width: 168px; border: 0; border-radius: 10px; background: var(--accent); color: var(--primary-btn-ink); display: inline-flex; align-items: center; justify-content: center; gap: 16px; padding: 14px 23px; font: 600 15px var(--font-brand); transition: filter 130ms, transform 130ms; }
.onb-primary:not(:disabled):hover { filter: brightness(1.06); }
.onb-primary:not(:disabled):active { transform: scale(.98); }
.onb-primary:disabled { background: var(--line); color: var(--muted); }
.onb-primary svg { width: 19px; height: 19px; }

/* Sign-in card: link back to the welcome flow. */
.auth-welcome-back { margin-top: 4px; align-self: flex-start; }

@media (max-height: 760px) {
  .onb-top { padding-block: 14px; }
  .onb-flow { margin-top: 8px; }
  .onb-way { margin-bottom: 18px; }
  .onb h1 { font-size: 32px; margin-bottom: 20px; }
  .onb-choice { min-height: 64px; padding: 14px 18px; }
  .onb-choices { gap: 10px; }
  .onb-choice.onb-language { min-height: 108px; padding: 17px 22px; }
  .onb-greeting { font-size: 30px; margin-bottom: 10px; }
  .onb-levels .onb-choice { min-height: 72px; padding: 15px 16px; }
  .onb-topics .onb-choice { min-height: 62px; padding: 13px 16px; }
  .onb-time { min-height: 112px; padding: 22px 10px; }
  .onb-lexical { min-height: 62px; padding: 13px 8px; }
  .onb-line { padding: 22px 0; font-size: 34px; }
}
@media (max-width: 700px) {
  .onb-top { padding: 14px 20px; gap: 12px; }
  .onb-brand { font-size: 17px; }
  .onb-brand img { width: 29px; height: 35px; }
  .onb-brand-rest { display: none; }
  .onb-actions { gap: 10px; }
  .onb-link { font-size: 13px; }
  .onb-icon-button { width: 37px; height: 37px; border-radius: 10px; }
  .onb-flow { width: calc(100% - 40px); margin-top: 10px; }
  .onb-way { gap: 12px; margin-bottom: 20px; }
  .onb h1 { font-size: 28px; }
  .onb-languages { gap: 11px; }
  .onb-choice.onb-language { min-height: 108px; padding: 16px; }
  .onb-language .onb-dot { right: 14px; top: 14px; }
  .onb-greeting { font-size: 30px; margin-bottom: 14px; }
  .onb-language-name { font-size: 14px; gap: 8px; }
  .onb-choice { padding: 14px 16px; }
  .onb-levels .onb-choice { padding: 15px 12px; gap: 9px; min-height: 70px; }
  .onb-levels .onb-choice-title { font-size: 13px; }
  .onb-level-code { font-size: 19px; min-width: 29px; }
  .onb-levels .onb-dot { width: 16px; height: 16px; }
  .onb-topics .onb-choice { min-height: 60px; padding: 12px; gap: 8px; }
  .onb-topics .onb-choice-title { font-size: 13px; }
  .onb-topic-icon svg { width: 20px; height: 20px; }
  .onb-topics .onb-dot { width: 17px; height: 17px; }
  .onb-times { gap: 8px; }
  .onb-time { min-height: 112px; padding: 20px 6px; }
  .onb-time-number { font-size: 29px; }
  .onb-time-unit { font-size: 13px; }
  .onb-word-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .onb-lexical { min-height: 56px; padding: 12px 8px; }
  .onb-correction { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .onb-survey-level { font-size: 46px; }
  .onb-line { font-size: 30px; line-height: 1.55; }
  .onb-primary { min-width: 150px; gap: 12px; padding-inline: 18px; }
}
@media (max-width: 700px) and (max-height: 680px) {
  .onb-top { padding: 10px 18px; }
  .onb-flow { width: calc(100% - 36px); margin-top: 4px; }
  .onb-way { margin-bottom: 12px; }
  .onb h1 { font-size: 26px; margin-bottom: 16px; }
  .onb-choice { min-height: 56px; padding: 12px 14px; }
  .onb-choice.onb-language { min-height: 106px; padding: 16px; }
  .onb-greeting { font-size: 28px; margin-bottom: 12px; }
  .onb-footer { min-height: 66px; padding-top: 8px; gap: 12px; }
}
@media (max-width: 400px) {
  .onb-lang button { padding: 5px 7px; }
  .onb-greeting { font-size: clamp(24px, 7.5vw, 28px); }
  .onb-language .onb-dot, .onb-levels .onb-dot, .onb-topics .onb-dot { display: none; }
  .onb-variant-label { display: none; }
  .onb-footer .onb-text { font-size: 13px; }
  .onb-primary { min-width: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .onb-panel.enter > .onb-body, .onb-celebrate { animation: none; }
  .onb-choice, .onb-primary, .onb-word, .onb-progress span { transition: none; }
}
