/* 4.2.1, incremental shared foundation. No palette or persistence changes. */
.lumen-lang-menu {
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior-y: contain;
  scrollbar-width: thin;
}
.lumen-lang-trigger { display: flex; align-items: center; gap: .5rem; }
.lumen-lang-trigger .lang-name, .lumen-lang-option .lang-name { flex: 1; min-width: 0; white-space: normal; overflow-wrap: anywhere; text-align: left; }
.lang-symbol { width: 24px; height: 16px; flex: 0 0 24px; }
.lumen-lang-trigger .lang-check, .lumen-lang-option .lang-check { flex: 0 0 1em; margin-left: auto; }
.lumen-premium-select { position: relative; min-width: 0; width: 100%; }
.lumen-premium-select > select { position: absolute; width: 1px; height: 1px; min-width: 0; padding: 0; border: 0; clip-path: inset(50%); overflow: hidden; white-space: nowrap; opacity: 0; pointer-events: none; }
.settings-card .lumen-premium-select > select.form-control, .challenge-config .lumen-premium-select > select.form-control { min-width: 0; max-width: 1px; }
.lumen-premium-select .premium-trigger { width: 100%; text-align: left; }
.lumen-premium-select .premium-menu { left: 0; right: 0; }
.lumen-lang-select.open, .lumen-premium-select.open { z-index: 151; }
.lumen-lang-menu, .lumen-premium-select .premium-menu { overscroll-behavior-y: contain; scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--accent) 45%, transparent) transparent; }
.lumen-premium-select .premium-menu { opacity: 0; visibility: hidden; pointer-events: none; transform: translateY(-7px) scale(.985); transform-origin: top; transition: opacity .18s ease, transform .18s ease, visibility .18s ease; }
.lumen-premium-select .premium-menu[data-placement="top"] { transform-origin: bottom; }
.lumen-premium-select.open .premium-menu { opacity: 1; visibility: visible; pointer-events: auto; transform: translateY(0) scale(1); }
.lumen-premium-select .premium-trigger:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.lumen-premium-select .premium-menu .lumen-lang-option { min-height: 44px; }
.lumen-premium-select .premium-menu .lumen-lang-option[aria-selected="true"] .lang-check { color: var(--accent); font-weight: 800; }
.premium-select-icon { width: 20px; flex: 0 0 20px; color: var(--accent-ink); font-size: 1.1rem; text-align: center; }
.lumen-lang-option { min-height: 44px; white-space: normal; overflow-wrap: anywhere; }
.lumen-lang-option:hover, .lumen-lang-option:focus-visible { transform: none; }
/* Keep the translator's rounded top while allowing its dropdown to escape. */
.translator-card { overflow: visible; }
.translator-card .translator-controls { border-radius: inherit; border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.translator-input textarea { resize: none; overflow-y: auto; }
:root {
  --space-xs: .25rem;
  --space-sm: .5rem;
  --space-md: .75rem;
  --space-lg: 1rem;
  --space-xl: 1.5rem;
  --type-caption: .8125rem;
}
/* Shared treatment for native selects; language selects keep their accessible custom list. */
select.form-control {
  min-height: 44px;
  border: 1px solid color-mix(in srgb, var(--accent) 18%, var(--line));
  border-radius: 13px;
  background-color: var(--surface-2);
  color: var(--text);
  color-scheme: light dark;
  padding-inline: .75rem 2rem;
  transition: border-color .18s ease, box-shadow .18s ease;
}
select.form-control:hover { border-color: color-mix(in srgb, var(--accent) 55%, var(--line)); }
select.form-control:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.settings-card select.form-control, .challenge-config select.form-control { min-width: min(100%, 18rem); }
.page-heading { gap: var(--space-lg); }
.page-heading h2 { font-size: clamp(1.4rem, 1.1rem + 1.5vw, 1.8rem); }
.page-heading p { max-width: 72ch; line-height: 1.55; }
.toolbar, .result-actions, .library-entry-actions { flex-wrap: wrap; }
.page-heading > *, .toolbar > *, .edu-card, .library-entry-main,
.library-detail-grid > *, .report-grid > * { min-width: 0; }
.edu-card p, .library-entry-main p, .dialogue-line p,
.library-detail-grid, .report-grid { overflow-wrap: anywhere; }
.challenge-result-actions {
  justify-content: center;
  gap: .625rem;
  margin-top: 1.25rem;
}
.challenge-result-actions > .btn {
  flex: 0 1 auto;
  min-width: 0;
  min-height: 44px;
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.3;
  justify-content: center;
  text-align: center;
}
.challenge-result .result-reward { line-height: 1.45; }
.stat-note, .stat-top, .recent-meta, .library-category small,
.report-grid span, .phrase-position, .phrase-topic span,
.settings-desc, .rhythm-strip-foot, .rhythm-best {
  font-size: var(--type-caption);
  line-height: 1.45;
}
.btn { gap: var(--space-sm); }
.btn svg, .icon-btn svg { flex-shrink: 0; }
.library-entry-actions .btn { white-space: normal; }
.modal { max-height: calc(100dvh - 2rem); overflow-y: auto; }
.library-categories { grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr)); }
.edu-card-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr)); }
.luma-suggestion-copy .eyebrow { font-size: .75rem; }
.luma-suggestion-copy p { line-height: 1.5; }
.pronunciation-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.pronunciation-actions > .btn { min-width: 0; white-space: normal; overflow-wrap: anywhere; justify-content: center; }
.pronunciation-actions .btn svg { flex: 0 0 auto; }

/* Same seven dates and same streak source; only their presentation changes. */
.rhythm-strip { padding: var(--space-lg); }
.rhythm-strip-head, .rhythm-strip-foot { flex-wrap: wrap; }
.rhythm-strip-head > *, .rhythm-strip-foot > * { min-width: 0; }
.rhythm-best { color: var(--text); font-weight: 700; }
.rhythm-days .rhythm-day { font-size: .8125rem; gap: .25rem; }
.rhythm-days .rhythm-day b { font-size: .75rem; }
.rhythm-strip .rhythm-day { min-height: 0; padding: .5rem .125rem; }
.rhythm-days .rhythm-flame { width: clamp(26px, 3vw, 34px); height: clamp(26px, 3vw, 34px); color: var(--muted); }
.rhythm-days .studied .rhythm-flame { color: var(--warning); filter: drop-shadow(0 0 3px color-mix(in srgb, var(--warning) 30%, transparent)); }
.rhythm-days .studied { background: color-mix(in srgb, var(--warning) 10%, var(--surface)); }
.rhythm-days .today { border: 2px solid var(--accent); background: var(--accent-soft); }
.rhythm-days .future { opacity: 1; background: var(--surface-2); }
.rhythm-today { font-size: .6875rem; line-height: 1.2; min-height: 1.2em; color: var(--accent-ink); }
html[data-motion="off"] .rhythm-strip,
html[data-motion="off"] .rhythm-strip .rhythm-day { animation: none; transition: none; }
@media (max-width: 850px) {
  #mainNav > .nav-item span { font-size: .6875rem; }
  .settings-nav button span { font-size: .8125rem; }
  .mobile-more-head span { font-size: .75rem; }
}
@media (max-width: 620px) {
  .challenge-result { padding: clamp(16px, 4.5vw, 22px); }
  .challenge-result .result-mascot { max-width: 112px; margin-bottom: 6px; }
  .challenge-result .result-summary { margin: 14px auto; }
  .challenge-result-actions { flex-direction: column; align-items: stretch; margin-top: 16px; }
  .challenge-result-actions > .btn { width: 100%; flex: 0 0 auto; }
  input, textarea, select, .form-control { font-size: max(1rem, 16px); }
  .rhythm-strip { padding: var(--space-md) var(--space-sm); }
  .rhythm-strip .rhythm-days { gap: 3px; }
  .rhythm-strip-foot .text-link { min-height: 44px; }
  .rhythm-week .toolbar { gap: var(--space-sm); }
  .rhythm-week .btn { white-space: normal; }
  .pronunciation-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr)); }
  .pronunciation-actions > .btn { width: 100%; min-height: 44px; line-height: 1.25; }
  .settings-card .setting-control { min-width: 0; }
  .settings-card .lumen-premium-select { min-width: 0; }
  .library-panel, .library-tools, .library-list-header, .library-entry-list { min-width: 0; max-width: 100%; }
  .library-tools { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .library-tools .searchbox { min-width: 0; grid-column: 1 / -1; }
  .library-tools .lumen-premium-select { min-width: 0; }
  .library-category { min-width: 0; overflow-wrap: anywhere; }
}
@media (max-width: 420px) {
  .pronunciation-actions { grid-template-columns: minmax(0, 1fr); }
  .library-tools { grid-template-columns: minmax(0, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  .lumen-premium-select .premium-menu { transition: none; }
}
@media (pointer: coarse) {
  .text-link, .edu-tabs button, .library-category { min-height: 44px; }
}

/* 4.3: compact mobile finish; keeps layout, behavior, tokens and user font scale. */
@media (max-width: 620px) {
  .app-main { padding-inline: clamp(12px, 3.8vw, 16px); padding-bottom: calc(82px + env(safe-area-inset-bottom)); }
  .topbar { height: 64px; }
  .page-content { padding-top: 14px; }
  .page-heading { margin-bottom: 12px; gap: 8px; }
  .page-heading h2 { font-size: clamp(1.28rem, 5.4vw, 1.55rem); line-height: 1.18; }
  .page-heading p { font-size: .9rem; }
  .surface, .settings-card, .welcome-card, .daily-card, .stat-card { border-radius: clamp(14px, 4vw, 20px); }
  .surface-pad { padding: clamp(13px, 3.8vw, 17px); }
  .hero-grid { gap: 10px; }
  .welcome-card { min-height: 0; padding: 16px; }
  .welcome-card .welcome-title { max-width: 17ch; font-size: clamp(1.55rem, 7vw, 1.95rem); line-height: 1.09; margin: 4px 0 8px; }
  .welcome-card .welcome-copy { max-width: 35ch; font-size: .9rem; line-height: 1.42; margin: 0 0 12px; }
  .welcome-actions { gap: 7px; margin-top: 10px; }
  .welcome-actions .btn { min-height: 44px; flex: 1 1 145px; padding: 9px 11px; }
  .welcome-luma { width: clamp(92px, 29vw, 132px); min-height: 0; margin: 3px auto -5px; }
  .welcome-luma img { max-height: 116px; }
  .stats-grid, .home-stats { gap: 8px; margin-block: 11px; }
  .stat-card { min-height: 104px; padding: 11px; }
  .stat-top { gap: 5px; font-size: .72rem; }
  .stat-value { margin-top: 6px; font-size: clamp(1.25rem, 5vw, 1.55rem); }
  .stat-note { font-size: .72rem; line-height: 1.3; }
  .section-row { margin: 16px 0 9px; gap: 8px; }
  .daily-card { min-height: 164px; padding: 16px; }
  .luma-suggestion { gap: 10px; padding: 11px; margin: 7px 0 12px; }
  .luma-suggestion-image { width: 38px; height: 38px; flex-basis: 38px; }
  .luma-suggestion-copy p { font-size: .9rem; }
  .translator-controls { grid-template-columns: minmax(0,1fr) 42px minmax(0,1fr); gap: 5px; padding: 10px; }
  .language-field .lumen-lang-trigger { min-height: 44px; padding: 7px; font-size: clamp(12px, 3.3vw, 14px); }
  .language-field .lang-symbol { width: 20px; height: 14px; flex-basis: 20px; }
  .swap-btn { min-width: 42px; min-height: 44px; }
  .translator-input { padding: 11px; }
  .translator-input textarea { min-height: clamp(96px, 22vh, 142px); max-height: 36vh; padding: 11px; line-height: 1.45; }
  .translate-bottom { gap: 8px; }
  .result-actions { gap: 6px; }
  .result-actions .btn { min-height: 44px; padding: 8px; font-size: .88rem; }
  .translation-result { padding: 13px; }
  .result-text { font-size: clamp(1.05rem, 4.4vw, 1.2rem); line-height: 1.45; }
  .rhythm-strip { padding: 11px; }
  .rhythm-strip .rhythm-days { margin: 9px 0 7px; gap: 3px; }
  .rhythm-strip .rhythm-day { min-height: 52px; padding: 5px 1px; gap: 2px; border-radius: 10px; font-size: .68rem; }
  .rhythm-days .rhythm-day b { font-size: .7rem; }
  .rhythm-days .rhythm-flame { width: 25px; height: 25px; }
  .rhythm-strip-foot { gap: 6px; }
  .btn { border-radius: 12px; }
  .icon-btn, .swap-btn { border-radius: 12px; }
  .nav-item:hover { transform: none; }
}
@media (max-width: 380px) {
  .welcome-card { padding: 14px; }
  .welcome-card .welcome-title { font-size: clamp(1.45rem, 7vw, 1.7rem); }
  .welcome-luma { width: 92px; }
  .welcome-actions .btn { flex-basis: 100%; }
  .stat-card { padding: 9px; }
  .translator-controls { grid-template-columns: minmax(0,1fr) 38px minmax(0,1fr); }
  .swap-btn { min-width: 38px; }
  .language-field .lumen-lang-trigger { gap: 4px; font-size: 12px; }
  .rhythm-days .rhythm-flame { width: 22px; height: 22px; }
}
@media (orientation: landscape) and (max-height: 520px) and (max-width: 900px) {
  .page-content { padding-top: 10px; }
  .welcome-card { padding: 12px 14px; }
  .welcome-luma { width: 72px; }
  .welcome-luma img { max-height: 72px; }
  .translator-input textarea { min-height: 84px; max-height: 28vh; }
}

/* The button owns the whole visible hit surface, including its decorative children. */
.lumen-lang-trigger > *, .premium-trigger > * { pointer-events: none; }
.lumen-premium-select .premium-trigger { position: relative; display: flex; min-height: 44px; }

/* Mobile navigation: a single travelling outline behind the existing five buttons. */
#mainNav > .mobile-nav-wave { display: none; }
@media (max-width: 850px) {
  .sidebar {
    inset: auto max(8px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    width: auto;
    height: 74px;
    min-height: 74px;
    padding: 7px 8px;
    border: 1px solid color-mix(in srgb, var(--accent) 32%, var(--line));
    border-radius: 28px;
    background: color-mix(in srgb, var(--surface) 98%, transparent);
    box-shadow: 0 10px 28px rgba(0,0,0,.16);
  }
  @supports (backdrop-filter: blur(5px)) {
    .sidebar { backdrop-filter: blur(5px); }
  }
  .app-main { padding-bottom: calc(112px + env(safe-area-inset-bottom)); }
  body.mobile-keyboard-open .sidebar { visibility: hidden; opacity: 0; pointer-events: none; }
  #mainNav {
    position: relative;
    touch-action: pan-y;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
  }
  #mainNav > .nav-item { position: relative; z-index: 1; min-height: 55px; }
  #mainNav > .nav-item.active { background: color-mix(in srgb, var(--accent) 13%, var(--surface)); }
  #mainNav.mobile-nav-dragging > .nav-item.mobile-nav-candidate {
    background: color-mix(in srgb, var(--accent) 21%, var(--surface));
  }
  #mainNav.mobile-nav-dragging > .nav-item.mobile-nav-candidate svg {
    transform: scale(1.055);
    transition: transform 110ms ease-out;
  }
  #mainNav > .nav-item:hover { transform: none; }
  #mainNav .mobile-nav-wave {
    display: block;
    position: absolute;
    z-index: 0;
    left: 0;
    top: 0;
    width: min(64px, 20%);
    height: 55px;
    opacity: 0;
    overflow: hidden;
    pointer-events: none;
    transition: transform 300ms cubic-bezier(.22,1,.36,1), opacity 120ms ease;
  }
  #mainNav.mobile-nav-dragging .mobile-nav-wave { opacity: 1; will-change: transform; }
  #mainNav .mobile-nav-wave::before {
    content: "";
    position: absolute;
    top: 6px;
    left: 18%;
    width: 64%;
    height: 43px;
    border-radius: 16px;
    background: color-mix(in srgb, var(--accent) 14%, var(--surface));
  }
  #mainNav .mobile-nav-wave svg { position: relative; width: 100%; height: 100%; overflow: hidden; fill: none; stroke: var(--accent); stroke-width: 1.7; vector-effect: non-scaling-stroke; opacity: .8; }
  #mainNav.mobile-nav-still .mobile-nav-wave { transition: none; }
  #mainNav.mobile-nav-still.mobile-nav-dragging .mobile-nav-wave { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  #mainNav .mobile-nav-wave { transition: none; opacity: 0; }
  #mainNav.mobile-nav-dragging > .nav-item.mobile-nav-candidate svg { transform: none; transition: none; }
}

/* Grafite Premium: matte surfaces, scoped to the existing fifth theme. */
html[data-theme="premium"] {
  --bg: #0f1013;
  --surface: #202228;
  --surface-2: #191b20;
  --surface-3: #282a31;
  --text: #f5f5f7;
  --muted: #afb2bf;
  --line: rgba(255,255,255,.10);
  --accent: #9670f5;
  --accent-strong: #b59af9;
  --accent-soft: #30283f;
  --accent-ink: #d7c7ff;
  --shadow: 0 16px 40px rgba(0,0,0,.24);
  --shadow-sm: 0 4px 14px rgba(0,0,0,.20);
}
html[data-theme="premium"] .surface {
  background: linear-gradient(160deg,rgba(255,255,255,.018),transparent 55%),var(--surface);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.025),var(--shadow-sm);
}
html[data-theme="premium"] .btn {
  box-shadow: inset 0 1px 0 rgba(255,255,255,.06),0 3px 8px rgba(0,0,0,.18);
}
html[data-theme="premium"] .btn-primary {
  background: linear-gradient(180deg,#a582f8,#9670f5);
  border-color: #ad8cf8;
  color: #17121f;
}
html[data-theme="premium"] .btn-primary:hover {
  background: #ad8cf8;
  border-color: #c5adff;
}
html[data-theme="premium"] .btn:not(:disabled):not([aria-disabled="true"]):active {
  box-shadow: inset 0 2px 5px rgba(0,0,0,.22);
}
html[data-theme="premium"] :focus-visible { outline-color: #bda2ff; }
html[data-theme="premium"] :is(.lumen-lang-menu,.modal) {
  background: #202228;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.06),0 16px 40px rgba(0,0,0,.32);
}
@supports (backdrop-filter: blur(8px)) {
  html[data-theme="premium"] :is(.lumen-lang-menu,.modal) {
    background: rgba(32,34,40,.97);
    backdrop-filter: blur(8px);
  }
}
/* Keep the existing desktop scroll container and a discoverable, quiet thumb. */
@media (min-width:851px) {
  .sidebar .nav-list {
    scrollbar-width: thin;
    scrollbar-color: color-mix(in srgb,var(--muted) 28%,transparent) transparent;
  }
  .sidebar .nav-list:hover,.sidebar .nav-list:focus-within {
    scrollbar-color: color-mix(in srgb,var(--muted) 55%,transparent) transparent;
  }
  .sidebar .nav-list::-webkit-scrollbar { width: 5px; }
  .sidebar .nav-list::-webkit-scrollbar-track { background: transparent; }
  .sidebar .nav-list::-webkit-scrollbar-thumb {
    background: color-mix(in srgb,var(--muted) 28%,transparent);
    border-radius: 8px;
  }
  .sidebar .nav-list:hover::-webkit-scrollbar-thumb,
  .sidebar .nav-list:focus-within::-webkit-scrollbar-thumb {
    background: color-mix(in srgb,var(--muted) 55%,transparent);
  }
}

/* Touch feedback: keep selection and keyboard focus intact. */
:where(button, a[href], [role="button"], [data-action], [data-edu], [data-library], input[type="button"], input[type="submit"]) {
  -webkit-tap-highlight-color: transparent;
}
@media (hover: none) {
  :where(button, a[href], [role="button"], [data-action], [data-edu], [data-library]):not(:disabled):not([aria-disabled="true"]):not(.nav-item):active {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
  }
}
:where(button, a[href], [role="button"], [data-action], [data-edu], [data-library]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
