/* Student surfaces. Brand artwork is always displayed in its original colours. */
:root {
  --brand-cobalt: #1f5bff;
  --brand-coral: #ff7a59;
  --brand-yellow: #ffd54f;
  --color-background: #fdfbf7;
  --color-surface: #fff;
  --color-surface-elevated: #fffdf9;
  --color-surface-soft: #f4f1eb;
  --color-text-primary: #1a1f3d;
  --color-text-secondary: #555c70;
  --color-border: #e1ded7;
  --color-control-border: #898e9e;
  --color-primary-action: var(--brand-cobalt);
  --color-primary-action-text: #fff;
  --color-link: #264dbd;
  --color-selected: #e9efff;
  --color-focus: #8d4600;
  --color-success: #226343;
  --color-success-surface: #e5f4ec;
  --color-warning: #79510e;
  --color-warning-surface: #fff0d5;
  --color-error: #943c2b;
  --color-error-surface: #fceae3;
  --color-violet: #6a45a4;
  --color-violet-surface: #f2eaf9;
  --color-coral-ink: #a3492a;
  --color-coral-surface: #ffebe0;
  --color-hero: #f6e7d5;
  --color-hero-tint: #fbf3e9;
  --color-hero-ink: #1a1f3d;
  --color-meter: #dadfe9;
  --color-overlay: #131a3385;
  --color-toast: #263248;
  --color-toast-text: #fff;
  --color-nav: #fffdf9f5;
  --color-header-start: #f4ece0;
  --color-header-end: #fdfbf7;
  --shadow-card: 0 2px 3px #36261404, 0 8px 24px #36261407;
  --shadow-float: 0 10px 36px #1820361a;
  --radius-card: 22px;
  --radius-inset: 14px;
  --radius-control: 12px;
  --blue: var(--color-link);
  --coral: var(--brand-coral);
  --yellow: var(--brand-yellow);
  --navy: var(--color-text-primary);
  --bg: var(--color-background);
  --ivory: var(--color-hero-tint);
  --muted: var(--color-text-secondary);
  --line: var(--color-border);
  --shadow: var(--shadow-card);
  --radius: var(--radius-card);
  color-scheme: light;
}

html[data-theme='dark'] {
  --color-background: #0b1120;
  --color-surface: #151f31;
  --color-surface-elevated: #202d42;
  --color-surface-soft: #1b273a;
  --color-text-primary: #f4f2ee;
  --color-text-secondary: #bcc5d4;
  --color-border: #334157;
  --color-control-border: #76869f;
  --color-link: #a6c1ff;
  --color-selected: #293b63;
  --color-focus: #ffd54f;
  --color-success: #a0e3bb;
  --color-success-surface: #1b372f;
  --color-warning: #f6d493;
  --color-warning-surface: #3b3125;
  --color-error: #ffb8a9;
  --color-error-surface: #402b32;
  --color-violet: #d6b8ff;
  --color-violet-surface: #342b4d;
  --color-coral-ink: #ffb499;
  --color-coral-surface: #402f30;
  --color-hero: #263343;
  --color-hero-tint: #18283a;
  --color-hero-ink: #f8f5ed;
  --color-meter: #39485f;
  --color-overlay: #02060db3;
  --color-toast: #e8edf4;
  --color-toast-text: #162036;
  --color-nav: #182336f5;
  --color-header-start: #bdc8d0;
  --color-header-end: #1c293b;
  --shadow-card: 0 2px 12px #02060e26;
  --shadow-float: 0 14px 42px #02060e70;
  color-scheme: dark;
}

body { background: var(--color-background); color: var(--color-text-primary); }
:where(button, a, input, textarea, select, summary):focus-visible {
  outline: 3px solid var(--color-focus);
  outline-offset: 3px;
}
.app-shell { max-width: 1120px; padding-bottom: calc(116px + env(safe-area-inset-bottom)); }
.app-shell main { padding-top: clamp(12px, 2vw, 25px); }
.topbar {
  position: relative;
  isolation: isolate;
  border-bottom: 1px solid var(--color-border);
  min-height: 74px;
}
.topbar::before {
  content: '';
  position: absolute;
  inset: -20px max(-40px, -4vw) 0;
  z-index: -1;
  pointer-events: none;
  background: linear-gradient(105deg, var(--color-header-start) 0 24%, var(--color-header-end) 65%);
  mask-image: linear-gradient(to right, transparent, black 3% 97%, transparent);
}
.logo { mix-blend-mode: normal; }
.header-actions .profile-shortcut { display: grid; }
.app-shell :is(h1, h2, h3), .modal-card h2 {
  font-family: 'Nunito Rounded', var(--font);
  font-weight: 750;
  text-wrap: balance;
  overflow-wrap: anywhere;
}
.app-shell h1 { letter-spacing: -.042em; }
.app-shell h2 { letter-spacing: -.032em; }
.app-shell h3 { letter-spacing: -.018em; }
.app-shell p { line-height: 1.55; }
.app-shell .page-heading { padding-block: 6px; margin-block: 8px 24px; }
.page-heading h1, .detail-main h1 { font-size: clamp(28px, 3.6vw, 42px); }
.app-shell .small, .app-shell small { line-height: 1.5; }
.card { border: 1px solid var(--color-border); }
.icon-button, .edit-avatar, .favorite-button { color: var(--color-text-primary); background: var(--color-surface-elevated); }
.icon-button.blue { color: var(--color-link); background: var(--color-selected); }
.app-shell .primary, .modal-card .primary, .hero .primary, .chip.selected, .node.done, .switch.on,
.favorite-button.selected { background: var(--color-primary-action); color: var(--color-primary-action-text); }
.primary, .secondary { min-height: 46px; border-radius: var(--radius-control); box-shadow: none; }
.app-shell .primary, .app-shell .secondary, .modal-card .primary, .modal-card .secondary { font-weight: 700; }
.secondary { color: var(--color-link); background: var(--color-selected); }
:is(.primary,.secondary,.answer,.chip,.nav-item,.skill,.icon-button,.menu-row,.appearance-option) { transition: background-color .14s, border-color .14s; }
:is(.primary,.secondary,.answer,.chip,.nav-item,.skill,.icon-button,.menu-row):active:not(:disabled) { box-shadow: inset 0 0 0 2px var(--color-control-border); }
@media (hover: hover) {
  .app-shell .primary:hover:not(:disabled), .modal-card .primary:hover:not(:disabled) { background: #1747cf; }
  :is(.chip,.answer,.icon-button,.menu-row,.secondary):hover:not(:disabled):not(.selected) { background-color: var(--color-surface-soft); }
  .card:has(.lesson-card-main:hover), .skill:hover { border-color: var(--color-control-border); }
}
.welcome { gap: 14px; margin: 0 0 24px; }
.welcome h1 { font-size: clamp(26px, 3.2vw, 40px); }
.welcome p, .lesson-body > p, .demo-note { color: var(--color-text-secondary); }
.welcome .avatar-initial { border-radius: 18px; }
.goal-card { background: var(--color-surface-elevated); box-shadow: none; }
.goal-meta, .metric, .stat strong, .score, .lesson-step-count { font-variant-numeric: tabular-nums; }
.progress-track { background: var(--color-meter); }
.progress-fill { background: var(--brand-cobalt); }
.hero {
  display: flex;
  align-items: center;
  min-height: clamp(245px, 32vw, 355px);
  color: var(--color-hero-ink);
  background: var(--color-hero-tint);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-card);
}
.hero::after { background: linear-gradient(90deg, var(--color-hero-tint) 0 33%, color-mix(in srgb, var(--color-hero-tint) 94%, transparent) 42%, transparent 74%); }
.hero-copy { max-width: 57%; padding: clamp(23px, 3.2vw, 40px); }
.hero h2 { font-size: clamp(26px, 3.45vw, 45px); line-height: 1.08; max-width: 13ch; margin: 14px 0; }
.hero .meta { flex-wrap: wrap; line-height: 1.5; }
.hero .waves { display: none; }
.hero .primary { min-width: 0; padding-inline: 23px; }
.skill { border-radius: var(--radius-inset); box-shadow: none; }
.skill span:last-child { font-weight: 700; }
.journey, .progress-detail, .lesson-body, .settings-card { padding: clamp(20px, 3vw, 34px); }
.streak-card { background: linear-gradient(115deg, var(--color-warning-surface), var(--color-coral-surface)); }
.lesson-card { border-radius: var(--radius-inset); }
.lesson-card:is(:hover,:focus-within) { transform: none; }
.lesson-card-main { display: flex; flex-direction: column; align-items: stretch; }
.lesson-card img, .lesson-list .lesson-card img, .recommendations .lesson-card img { display: block; height: auto; aspect-ratio: 1.95; object-fit: cover; }
.lesson-card-content { flex: 1; display: flex; flex-direction: column; align-items: flex-start; }
.lesson-card-content .lesson-status { margin-top: auto; }
.lesson-card h3 { margin-bottom: 12px; }
.lesson-card .small, .lesson-card .lesson-status { font-size: 12px; }
.bottom-nav { border: 1px solid var(--color-border); background: var(--color-nav); box-shadow: var(--shadow-float); }
.nav-item { color: var(--color-text-secondary); }
.nav-item.active { color: var(--color-link); background: var(--color-selected); }
.search-box, .field :is(input, textarea, select), .match-row select, .speech-controls select, .modal-card input {
  background: var(--color-surface-elevated); color: var(--color-text-primary);
  border: 1px solid var(--color-control-border); border-radius: var(--radius-control);
}
.search-box:focus-within { outline: 2px solid var(--color-focus); outline-offset: 2px; }
.search-box input { background: transparent; }
.app-shell :is(input, textarea)::placeholder { color: var(--color-text-secondary); }
.modal-card input { padding: 12px; min-height: 44px; max-width: 100%; }
.field :is(input, textarea, select) { min-height: 46px; scroll-margin-block: 72px 20vh; }
.chip { min-height: 44px; }
.filters, .lesson-state-tabs { gap: 8px; }
.empty, .progress-detail, .vocab-note, .settings-card { background: var(--color-surface); }
.stat { box-shadow: none; }
.chart { padding: 20px 12px 0; border-bottom: 1px solid var(--color-border); }
.day-bar { background: var(--color-meter); }
.day-bar.today { background: var(--brand-cobalt); }
.lesson-player, .detail-main { max-width: 720px; }
.lesson-top { padding-block: 6px; }
.lesson-context { margin-block: 0 10px; color: var(--color-text-secondary); font-size: 14px; font-weight: 700; }
.lesson-body { margin-block: 16px; }
.lesson-body h1 { font-size: clamp(24px, 3vw, 32px); }
.lesson-body > p { max-width: 65ch; }
.dialogue { padding-block: 18px; }
.dialogue .grow { flex: 1; }
.dialogue strong { font-size: 17px; line-height: 1.5; }
.dialogue p, .vocab-item p { font-size: 14px; }
.speaker { font-size: 12px; }
.answer { border: 1px solid var(--color-control-border); background: var(--color-surface-elevated); border-radius: var(--radius-inset); line-height: 1.5; }
.answer.selected { background: var(--color-selected); border-color: var(--color-link); box-shadow: inset 3px 0 var(--color-link); }
.answer.correct { background: var(--color-success-surface); border-color: var(--color-success); }
.answer.wrong { background: var(--color-error-surface); border-color: var(--color-error); }
.feedback { border-inline-start: 3px solid var(--color-success); color: var(--color-success); background: var(--color-success-surface); }
.feedback.wrong { border-color: var(--color-error); color: var(--color-error); background: var(--color-error-surface); }
.word-slots, .speaking-phrase, .mini-game { background: var(--color-surface-soft); border-color: var(--color-control-border); }
.record-button { color: var(--color-coral-ink); background: var(--color-coral-surface); }
.record-button.recording { color: var(--color-primary-action-text); background: #a33325; }
.notice, .notice.info, .feedback, .word-slots, .speaking-phrase { border-radius: var(--radius-inset); }
.modal-card { background: var(--color-surface-elevated); color: var(--color-text-primary); box-shadow: var(--shadow-float); }
.modal-backdrop { background: var(--color-overlay); }
.toast { background: var(--color-toast); color: var(--color-toast-text); }
.readonly { opacity: 1; color: var(--color-text-secondary); }
.appearance-options { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 8px; margin-block: 16px; padding: 0; border: 0; }
.appearance-option { position: relative; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px; min-height: 52px; padding: 9px 4px; text-align: center; border: 1px solid var(--color-control-border); border-radius: var(--radius-control); background: var(--color-surface); color: var(--color-text-primary); cursor: pointer; }
.appearance-option:has(:checked), .appearance-option[aria-checked='true'], .appearance-option[aria-pressed='true'] { color: var(--color-link); border-color: var(--color-link); background: var(--color-selected); }
.appearance-option:focus-within { outline: 3px solid var(--color-focus); outline-offset: 2px; }
.appearance-option input { margin: 0; accent-color: var(--color-primary-action); }
@media (min-width: 850px) {
  .app-shell[data-page="home"] main:has(> .welcome) {
    display: grid;
    grid-template-columns: minmax(0,1fr) minmax(0,.95fr);
    gap: 18px 28px;
    align-items: center;
  }
  .app-shell[data-page="home"] main > :is(.welcome,.goal-card) { margin: 0; }
  .app-shell[data-page="home"] main > :not(.welcome,.goal-card) { grid-column: 1 / -1; }
  .lesson-list { grid-template-columns: repeat(3,minmax(0,1fr)); gap: 20px; }
  .welcome { margin-block: 5px 30px; }
  .skills { margin-block: 20px 28px; }
  .bottom-nav { width: min(620px,92%); border-radius: 20px; }
  .lesson-player .lesson-top { margin-top: 12px; }
}
@media (max-width: 650px) {
  .app-shell { padding-inline: max(16px,env(safe-area-inset-left)) max(16px,env(safe-area-inset-right)); }
  .topbar::before { inset-inline: -16px; mask-image: none; }
  .topbar { height: calc(74px + env(safe-area-inset-top)); }
  .header-actions .icon-button, .header-actions .streak-pill, .profile-head .edit-avatar, .dialogue .icon-button { min-width: 44px; min-height: 44px; }
  .header-actions .icon-button { background: var(--color-surface-elevated); }
  .hero { min-height: 222px; }
  .hero-copy { max-width: 76%; padding: 20px; }
  .hero::after { background: linear-gradient(90deg, var(--color-hero-tint) 0 30%, color-mix(in srgb,var(--color-hero-tint) 92%,transparent) 52%, transparent 92%); }
  .hero h2 { max-width: 12ch; }
  .hero .meta, .hero .pill { font-size: 12px; }
  .skill { padding-inline: 2px; }
  .skill span:last-child { font-size: clamp(10px,2.85vw,13px); overflow-wrap: anywhere; }
  .goal-meta, .goal-title, .nav-item, .stat p, .menu-row small, .lesson-card .small, .lesson-card .lesson-status { font-size: 12px; }
  .goal-title { font-size: 14px; }
  .nav-item { font-size: 11px; }
  .search-box input, .field :is(input,textarea,select), .speech-controls select, .match-row select { font-size: 16px; }
  .chip { padding-inline: 12px; font-size: 13px; }
  .lesson-card .lesson-card-content { padding: 12px; }
  .lesson-card h3 { font-size: 16px; }
  .bottom-nav { bottom: max(8px,env(safe-area-inset-bottom)); border-radius: 20px; }
  .bottom-nav .nav-item { border-radius: 13px; }
  .lesson-controls { flex-wrap: wrap; }
}
@media (max-width: 320px) {
  .header-actions { flex-wrap: wrap; }
  .topbar { height: auto; flex-wrap: wrap; }
  .skills { grid-template-columns: repeat(auto-fit,minmax(60px,1fr)); }
  .goal-card,.stats,.recommendations,.lesson-list,.appearance-options { grid-template-columns: 1fr; }
  .bottom-nav { position: static; margin: 0 auto; transform: none; width: 100%; grid-template-columns: repeat(auto-fit,minmax(50px,1fr)); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}

/* Container queries also cover CSS zoom, where layout width and media-query
   viewport width may differ. The inner layout always reflows to available space. */
.app-shell { container: student / inline-size; }
.app-shell, .app-shell main, .lesson-top, .lesson-step-count { min-inline-size: 0; }
@container student (max-width: 310px) {
  .topbar { height: auto; min-height: 0; gap: 6px; flex-wrap: wrap; padding-block: 8px; }
  .logo { max-width: 100%; }
  .header-actions { flex-wrap: wrap; max-width: 100%; }
  .lesson-top, .lesson-controls, .study-toolbar { flex-wrap: wrap; }
  .lesson-top .lesson-step-count { overflow-wrap: anywhere; }
  .goal-card, .summary-grid, .stats, .lesson-list, .recommendations, .appearance-options { grid-template-columns: minmax(0,1fr); }
  .goal-half + .goal-half { border: 0; padding: 0; }
  .skills { grid-template-columns: repeat(auto-fit,minmax(min(65px,100%),1fr)); }
  .hero-copy { padding: 12px; max-width: 100%; }
  .hero .primary { min-width: 0; width: 100%; padding-inline: 8px; }
  .journey .nodes, .welcome, .profile-head { flex-wrap: wrap; }
  .nodes::before { content: none; }
  .modal-card, .lesson-body, .settings-card, .journey, .progress-detail { padding: 14px; }
  .daily-card, .match-row { display: flex; flex-wrap: wrap; }
  .calendar-art { display: none; }
  .section-head, .lesson-controls .primary { flex-wrap: wrap; }
  .speaking-phrase, .answer { overflow-wrap: anywhere; }
  .speaking-outcome { min-width: 0; }
  .app-shell .speech-controls label { flex-wrap: wrap; min-width: 0; }
}
.bottom-nav { container-type: inline-size; inset-inline: 0; margin-inline: auto; transform: none; }
@container (max-width: 280px) {
  .nav-item { min-width: 0; font-size: 10px; overflow-wrap: anywhere; }
  .nav-item .icon { width: 18px; height: 18px; }
}

@media (max-width: 650px) {
  .topbar { flex-wrap: wrap; height: auto; min-height: calc(74px + env(safe-area-inset-top)); padding-block-end: 6px; }
  .logo-button, .header-actions { min-inline-size: 0; max-inline-size: 100%; }
  .logo { max-inline-size: 100%; }
  .header-actions { flex-wrap: wrap; }
  .lesson-controls, .lesson-top, .study-toolbar, .speech-controls label { flex-wrap: wrap; }
  .lesson-body button, .speech-controls label { max-inline-size: 100%; min-inline-size: 0; }
  .speech-controls select { min-inline-size: 0; max-inline-size: 100%; }
  .lesson-body .audio-button, .lesson-controls .primary { white-space: normal; overflow-wrap: anywhere; }
}

/* The native voice menu can contain long system-provided voice names. Bound
   its intrinsic width on WebKit while keeping the full control operable. */
.speech-controls label { display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; min-width: 0; }
.speech-controls select { display: block; box-sizing: border-box; width: 100%; min-width: 0; max-width: 100%; text-overflow: ellipsis; }
.speech-controls label { overflow: clip; padding: 4px; }
