/* PeakFour v1.0.21 | UI polish for existing components.
 * Loaded last in both entry points. No content, IDs, JavaScript, or request contracts changed.
 * Never recolor score/mistake states, CEFR badges, or media contents as neutral surfaces.
 */
:root[data-pf-theme="light"] {
  --pf21-canvas:#f4f6fb;
  --pf21-panel:#ffffff;
  --pf21-subtle:#f0f4fb;
  --pf21-input:#ffffff;
  --pf21-line:#d9e2f1;
  --pf21-ink:#142544;
  --pf21-muted:#526680;
  --pf21-accent:#2563eb;
  --pf21-accent-soft:#e9f0ff;
  --pf21-focus:#2563eb;
  --pf21-shadow:0 3px 16px rgba(14,35,76,.045);
  color-scheme:light;
}
:root[data-pf-theme="dark"] {
  --pf21-canvas:#0c0f20;
  --pf21-panel:#1c213d;
  --pf21-subtle:#252b48;
  --pf21-input:#252b48;
  --pf21-line:#2a2f4c;
  --pf21-ink:#f1f5ff;
  --pf21-muted:#b4c0d9;
  --pf21-accent:#7c9fff;
  --pf21-accent-soft:#2d3761;
  --pf21-focus:#82b2ff;
  --pf21-shadow:none;
  color-scheme:dark;
}

/* App shell. Preserve existing active navigation and account/avatar identity. */
:root[data-pf-theme] :is(html,body,.app-shell,.peak-layout){min-width:0}
:root[data-pf-theme] .peak-layout{min-width:0}
:root[data-pf-theme] .peak-main{min-width:0;max-width:100%;}
:root[data-pf-theme] .peak-main > main[id^="page-"] {min-width:0;max-width:100%;}
:root[data-pf-theme] .peak-header{
  min-height:66px;
  border-bottom:1px solid var(--pf21-line)!important;
  box-shadow:none!important;
}
:root[data-pf-theme] .pf17-header-skills{min-width:0}
:root[data-pf-theme] .pf17-header-skills > button{
  min-height:42px;white-space:nowrap;line-height:1.25;
  transition:background-color .15s ease,color .15s ease,border-color .15s ease;
}
:root[data-pf-theme] .peak-sidebar :is(.category-tab,.peak-overview-button){
  min-height:42px;line-height:1.4;
  transition:background-color .15s ease,color .15s ease,border-color .15s ease;
}
:root[data-pf-theme] .peak-header :is(#pf-theme-toggle,#pf-header-profile,#peak-menu-toggle){
  border-radius:12px;
}

/* Unified visual rhythm. Set geometry only on scoped learning surfaces. */
:root[data-pf-theme] :is(
  #page-discover,#page-lessons,#page-grammar,#page-profile,#page-vocabulary,
  #page-pronunciation,#page-listening,#page-counting,#page-numbers,
  #page-chunking,#page-dictation,#page-shadowing,
  #page-alphabet,#page-recall,#page-guess,#page-cloze
) {
  font-family:Inter,"Be Vietnam Pro",system-ui,sans-serif;
  min-width:0;
}
:root[data-pf-theme] :is(
  #page-discover,#page-lessons,#page-grammar,#page-profile,#page-vocabulary,
  #page-pronunciation,#page-listening,#page-counting,#page-numbers,
  #page-chunking,#page-dictation,#page-shadowing,
  #page-alphabet,#page-recall,#page-guess,#page-cloze
) :is(input,select,textarea,button){font-family:inherit;}
:root[data-pf-theme] :is(
  #page-discover,#page-lessons,#page-grammar,#page-profile,#page-vocabulary,
  #page-pronunciation,#page-listening,#page-counting,#page-numbers,
  #page-chunking,#page-dictation,#page-shadowing,
  #page-alphabet,#page-recall,#page-guess,#page-cloze
) :is(input,select,textarea){max-width:100%;min-width:0;box-sizing:border-box;}
:root[data-pf-theme] :is(
  #page-discover,#page-lessons,#page-grammar,#page-profile,#page-vocabulary,
  #page-pronunciation,#page-listening,#page-counting,#page-numbers,
  #page-chunking,#page-dictation,#page-shadowing,
  #page-alphabet,#page-recall,#page-guess,#page-cloze
) :is(button,a,input,select,textarea,[role="button"]):focus-visible {
  outline:2px solid var(--pf21-focus)!important;
  outline-offset:3px!important;
}
:root[data-pf-theme] :is(
  #page-discover,#page-lessons,#page-grammar,#page-profile,#page-vocabulary,
  #page-pronunciation,#page-listening,#page-counting,#page-numbers,
  #page-chunking,#page-dictation,#page-shadowing,
  #page-alphabet,#page-recall,#page-guess,#page-cloze
) button:disabled{cursor:not-allowed;}

/* Only neutral form fields; do not paint feedback or answer-status pills. */
:root[data-pf-theme="dark"] :is(
  #page-grammar,#page-profile,#page-dictation,#page-recall,#page-guess,
  #page-cloze,#page-shadowing,#page-numbers,#page-counting
) :is(input:not([type="checkbox"]):not([type="radio"]),select,textarea):not(.is-correct):not(.is-wrong):not(.pf36-is-correct):not(.pf36-is-wrong){
  background:var(--pf21-input)!important;
  color:var(--pf21-ink)!important;
  border-color:var(--pf21-line)!important;
}
:root[data-pf-theme="dark"] :is(
  #page-grammar,#page-profile,#page-dictation,#page-recall,#page-guess,
  #page-cloze,#page-shadowing,#page-numbers,#page-counting
) :is(input,textarea)::placeholder{color:#aab8d2!important;opacity:1;}

/* Correct inconsistencies from dark/light CSS overlap in non-scoring containers. */
:root[data-pf-theme="dark"] #page-alphabet :is(
  .pf-alpha-intro,.pf-alpha-card,.pf-alpha-status,.pf-alpha-section,
  .pf-alpha-toolbar
){color:var(--pf21-ink)}
:root[data-pf-theme="dark"] #page-alphabet .pf-alpha-card{
  background:var(--pf21-panel)!important;border-color:var(--pf21-line)!important;box-shadow:none!important;
}
:root[data-pf-theme="dark"] #page-alphabet .pf-alpha-card :is(.pf-alpha-pair,.pf-alpha-pair strong){color:var(--pf21-ink)!important}
:root[data-pf-theme="dark"] #page-alphabet .pf-alpha-status{
  background:var(--pf21-subtle)!important;border-color:var(--pf21-line)!important;color:var(--pf21-ink)!important;
}
:root[data-pf-theme="dark"] #page-counting :is(
  .pf-counting-index,.pf-counting-workspace,.pf-counting-head,
  .pf-counting-item:not(.is-selected),.pf-counting-ranges button:not(.is-active)
){background:var(--pf21-panel)!important;border-color:var(--pf21-line)!important;box-shadow:none!important}
:root[data-pf-theme="dark"] #page-listening :is(.pf-ipa-sound-card,.ipa-sound,.phoneme-study-example){
  background:var(--pf21-panel)!important;border-color:var(--pf21-line)!important;color:var(--pf21-ink)!important;
}
:root[data-pf-theme="dark"] #page-listening .pf-ipa-word-row{border-color:var(--pf21-line)!important}
:root[data-pf-theme="dark"] #page-listening .pf-ipa-word-row>span{color:var(--pf21-muted)!important}
:root[data-pf-theme="dark"] #page-shadowing :is(
  .pfs-library,.pfs-primary,.pfs-clip-card:not(.is-selected),
  .pfs-transcript-wrap,.pfs-record
){background:var(--pf21-panel)!important;border-color:var(--pf21-line)!important;color:var(--pf21-ink)!important;box-shadow:none!important}
:root[data-pf-theme="dark"] #page-grammar :is(
  .pf-grammar-card,.pf-grammar-detail,.pf-grammar-lesson,.pf-grammar-practice,
  .pf-grammar-concept,.pf-grammar-example
){border-color:var(--pf21-line)!important;box-shadow:none!important}
:root[data-pf-theme="dark"] #page-profile :is(
  .pf85-profile-widgets .pf85-widget,.pf85-skills-grid article,.pf85-attendance,
  .pf-profile-settings,.pf-profile-panel
){background:var(--pf21-panel)!important;border-color:var(--pf21-line)!important;color:var(--pf21-ink)!important;box-shadow:none!important}
:root[data-pf-theme="dark"] #page-profile :is(
  .pf85-profile-welcome h2,.pf85-widget-head h2,.pf85-attendance h2,
  .pf85-attendance strong,.pf85-skills-grid strong
){color:var(--pf21-ink)!important}
:root[data-pf-theme="dark"] #page-profile :is(
  .pf85-widget p,.pf85-profile-welcome small,.pf85-attendance>p,
  .pf85-skills-grid small
){color:var(--pf21-muted)!important}

/* Standalone activities are intentionally dark, but should match the rest of PeakFour. */
:root[data-pf-theme="dark"] :is(#page-recall,#page-guess,#page-cloze){
  background:var(--pf21-canvas)!important;color:var(--pf21-ink)!important;
}
:root[data-pf-theme="dark"] :is(#page-recall,#page-guess,#page-cloze) :is(
  .pf38-topic-card,.pf38-lesson-card,.pf38-practice,.pf36-card
){background:var(--pf21-panel)!important;border-color:var(--pf21-line)!important;color:var(--pf21-ink)!important}
:root[data-pf-theme="dark"] :is(#page-recall,#page-guess,#page-cloze) :is(
  .pf38-heading h1,.pf38-lesson-stage h2,.pf38-practice-heading h2,
  .pf38-topic-card strong,.pf38-lesson-card strong,.pf36-card h3
){color:var(--pf21-ink)!important}

/* Library tile/footer alignment: no vertical single-letter wrapping. */
#page-lessons .pf-directory-card-grid{align-items:stretch;gap:clamp(12px,1.8vw,19px)}
#page-lessons .pf-directory-card-grid > .pf-academic-card-wrap{
  min-width:0;align-self:stretch;
}
#page-lessons .pf-academic-card-wrap > .pf-directory-card{
  min-height:132px!important;
}
#page-lessons .pf-academic-card-footer{min-width:0}
#page-lessons .pf-academic-card-footer :is(.pf-academic-favorite,.pf-academic-progress-status){
  line-height:1.3!important;white-space:nowrap!important;word-break:normal!important;
}
#page-lessons .pf-directory-card :is(strong,small){overflow-wrap:break-word}

/* Chunking: action column and progress footer line up despite variable title length. */
#page-chunking #chunk-lessons .pf100-lesson-card{box-sizing:border-box;min-width:0;}
#page-chunking .pf100-lesson-card .pf-ch94-lesson-main{min-height:0}
#page-chunking .pf100-lesson-card .pf-ch94-lesson-main p{overflow-wrap:anywhere}
#page-chunking .pf100-lesson-card .pf-ch94-lesson-actions{box-sizing:border-box}
#page-chunking .pf100-lesson-card .pf-ch94-lesson-actions button{min-width:0;line-height:1.3}
#page-chunking #chunk-lessons .pf100-lesson-ring{flex:0 0 auto}

/* Numbers: neutral surface and text rules must come from one mode, not a light block nested in dark. */
:root[data-pf-theme="dark"] #page-numbers :is(
  .numbers-catalog,.numbers-exercise,.numbers-stats > div,.numbers-stage,
  .numbers-audio,.numbers-hint,.numbers-practice-summary
){background:var(--pf21-panel)!important;border-color:var(--pf21-line)!important;color:var(--pf21-ink)!important;box-shadow:none!important}
:root[data-pf-theme="dark"] #page-numbers :is(
  .numbers-lesson-item:not(.is-active):not(.is-current),.numbers-lesson-list>button:not(.is-active):not(.is-current),
  .numbers-speak-controls #numbers-upload
){background:var(--pf21-subtle)!important;border-color:var(--pf21-line)!important;color:var(--pf21-ink)!important}
#page-numbers .numbers-exercise > .numbers-stage{min-width:0}
#page-numbers .numbers-stats>div{min-width:0;box-sizing:border-box}
#page-numbers .numbers-exercise>.numbers-nav{min-width:0}
#page-numbers .numbers-speak-controls #numbers-record{
  aspect-ratio:1/1!important;border-radius:50%!important;flex:0 0 auto;
}

/* IPA practice and score views retain their intentionally prominent spoken target. */
#page-pronunciation #practice #record-btn,
#page-pronunciation .pfux-compact .pfux-compact-mic,
#ipa-diff-path .ipa-path-mic,
#page-numbers #numbers-record{aspect-ratio:1/1!important;border-radius:50%!important;}
#ipa-diff-path :is(.ipa-path-step-content,.ipa-flow-page,.ipa-path-mic-zone){min-width:0}
#page-pronunciation :is(#pf117-score,#practice,.pfux-compact){min-width:0}
#page-pronunciation .pfux-compact :is(.pfux-compact-tools,.pfux-compact-mic-zone){min-width:0}

/* App dialogs, not a second page: bounded vertical size and scroll. */
:root[data-pf-theme] :is(#voice-dialog,.pfux-word-dialog,.pfux-session-dialog){
  max-height:min(90dvh,920px);max-width:calc(100vw - 24px);overflow-y:auto;
}

/* Responsive content widths; avoid sideways-scroll on phone-sized layouts. */
@media(max-width:980px){
  #page-chunking .pf100-catalog-grid{gap:12px}
  #page-numbers .numbers-exercise{gap:12px!important}
  #page-lessons .pf-directory-card-grid{gap:12px}
}
@media(max-width:720px){
  :root[data-pf-theme] :is(
    #page-discover,#page-lessons,#page-grammar,#page-profile,#page-vocabulary,
    #page-pronunciation,#page-listening,#page-counting,#page-numbers,
    #page-chunking,#page-dictation,#page-shadowing,#page-alphabet,
    #page-recall,#page-guess,#page-cloze
  ){max-width:100%;min-width:0;}
  #page-chunking .pf100-lesson-card .pf-ch94-meter-track{max-width:100%;}
  #page-numbers .numbers-stats{gap:8px!important}
  #page-numbers .numbers-speak-controls{min-width:0}
  #page-lessons .pf-directory-card-grid{grid-template-columns:repeat(auto-fit,minmax(min(100%,230px),1fr))}
}
@media(max-width:420px){
  #page-numbers .numbers-nav button{min-width:0;white-space:normal}
  #page-pronunciation :is(.pfux-compact-tools,.pfux-chips){gap:7px}
  #page-chunking .pf100-lesson-card .pf-ch94-lesson-actions{gap:8px}
}
@media(prefers-reduced-motion:reduce){
  :root[data-pf-theme] :is(.peak-sidebar .category-tab,.pf17-header-skills>button){transition:none!important}
  #page-pronunciation .record-button,
  #ipa-diff-path .ipa-path-mic,
  #page-numbers #numbers-record{animation:none!important;transition:none!important}
}

/* Final ordering and equal-card-width corrections from visual QA. */
#page-numbers .numbers-exercise > *{grid-row:auto!important}
:root[data-pf-theme="dark"] #page-numbers :is(
  .numbers-heading-row h2,.numbers-description,.numbers-stats strong,
  .numbers-stage h3,#numbers-play-title,.numbers-practice-summary-copy>strong
){color:var(--pf21-ink)!important}
:root[data-pf-theme="dark"] #page-numbers :is(
  .numbers-heading-row p,.numbers-stage>p,.numbers-stats small,
  #numbers-play-status,.numbers-practice-summary-copy>span
){color:var(--pf21-muted)!important}
#page-chunking #chunk-lessons .pf100-lesson-card{
  width:100%!important;max-width:100%!important;flex:0 0 auto!important;
}

/* Numbers catalog really renders .numbers-lesson / .is-current (not .numbers-lesson-item).
   Keep selected and normal tiles readable in each theme. */
:root[data-pf-theme="dark"] #page-numbers .numbers-lesson-list .numbers-lesson{
  background:var(--pf21-subtle)!important;color:var(--pf21-ink)!important;
  border:1px solid var(--pf21-line)!important;box-shadow:none!important;
}
:root[data-pf-theme="dark"] #page-numbers .numbers-lesson-list .numbers-lesson.is-current{
  background:var(--pf21-accent-soft)!important;border-color:#6489f3!important;
  box-shadow:inset 3px 0 0 #6489f3!important;
}
:root[data-pf-theme="dark"] #page-numbers .numbers-lesson :is(strong,.numbers-lesson-head b){color:var(--pf21-ink)!important}
:root[data-pf-theme="dark"] #page-numbers .numbers-lesson :is(small,.numbers-lesson-head small){color:var(--pf21-muted)!important}
:root[data-pf-theme="light"] #page-numbers .numbers-lesson-list .numbers-lesson:not(.is-current){
  background:#fff!important;border-color:var(--pf21-line)!important;color:var(--pf21-ink)!important;
}
:root[data-pf-theme="light"] #page-numbers .numbers-lesson-list .numbers-lesson.is-current{
  background:#edf3ff!important;border-color:#6992ed!important;color:var(--pf21-ink)!important;
}
