/* Shared narrow-screen density. Loaded after page styles; desktop stays unchanged.
   Keep explicit selectors so diagrams, artwork and scroll containers retain their geometry. */
@media screen and (max-width: 1023px) {
  :root {
    --density-panel-padding: 20px;
    --density-gap: 16px;
    --density-title: clamp(26px, 3.4vw, 32px);
    --density-heading: clamp(20px, 2.6vw, 25px);
  }

  body { font-size: 15px; }

  body :is(.page-title, .library-panel .section-heading, .consent-intro h1),
  body :is(#libraryView, #profileView, #createView, #coursesView, #quickFactsView,
    #factLibraryView, #catalogView, #examsView, #gapsView, #growthView, #coachView) .page-title,
  #createView .create-page-head .page-title {
    font-size: var(--density-title);
    line-height: 1.2;
    overflow-wrap: anywhere;
  }

  body :is(.lesson-pane h2, .learning-modal-header h2, #createView .creation-guide h2,
    .facts-purpose h2, .facts-purpose-head h2, .standalone-result-head h2,
    .home-section-heading h2, .home-panel-heading h2, .spotlight-copy h2,
    .continue-hero h2, .exam-page-topbar h1, .er-title),
  #libraryView :is(.continue-hero h2, .home-panel-heading h2) {
    font-size: var(--density-heading);
    line-height: 1.3;
  }

  body :is(.panel, #createView .create-page-grid .create-card, .creation-guide, .progress-card, .lesson-pane,
    .teach-prompt, .evaluation-report, .repeat-card, .sequential-question,
    .modal-question, .quick-facts, .facts-purpose, .facts-hero-banner,
    .fact-library-hero, .saved-facts-library, .library-panel,
    .profile-identity, .profile-setting-card, .profile-achievement,
    .analytics-main-card, .activities-card, .rewards-hero-card,
    .home-progress-panel, .home-activity-panel, .loop-workspace .loop-card,
    .loop-form-body, .sc-conversation-panel, .sc-next-panel, .sc-quick-dialog,
    .exam-page-topbar, .exam-question-card, .er-hero-card, .er-section-panel) {
    padding: var(--density-panel-padding);
  }

  body :is(.dash-hero-bento, .home-action-grid, .home-overview-grid,
    .profile-settings-grid, .sc-coach-layout, .loop-workspace,
    .learning-layout, .course-grid, .saved-facts-grid) {
    gap: var(--density-gap);
  }

  #createView .create-page-grid { grid-template-columns: minmax(0, 1fr); gap: var(--density-gap); }
  #createView .creation-guide { position: static; min-width: 0; }

  body :is(.lesson-text, .modal-repeat-text) { font-size: 17px; line-height: 1.7; }
  body :is(.lesson-summary, .facts-hero-desc) { font-size: 15px; }
  body :is(.sequential-question h4, .modal-question h4) { font-size: 22px; line-height: 1.4; }

  body .learning-modal-header { padding: 16px 20px; gap: 12px; }
  body .learning-modal-content { padding: 20px; }
  body .generation-overlay .generation-head { padding: 18px 20px; }
  body .generation-overlay .generation-scroll { padding: 20px; }

  /* Admin has its own theme, but shares the same density breakpoints. */
  .ops-container { padding: 16px 20px 40px; gap: var(--density-gap); }
  .ops-header, .ops-controls, .admin-panel-actions { flex-wrap: wrap; }
  .ops-header > *, .admin-panel-card, .admin-panel-actions { min-width: 0; max-width: 100%; }
  .admin-panel-actions :is(input, select) { min-width: 0; max-width: 100%; }
  :is(.admin-panel-card, .ops-kpi-card, .ops-active-banner, .ops-detail-content) { padding: 16px; }
  .kpi-value { font-size: 24px; }
  .ops-active-cards { grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); }
}

@media screen and (max-width: 600px) {
  :root {
    --density-panel-padding: 16px;
    --density-gap: 12px;
    --density-title: clamp(23px, 6vw, 27px);
    --density-heading: clamp(19px, 5vw, 22px);
  }

  body { font-size: 14px; }
  main { padding-block: 20px 32px; }
  body.has-app-nav main { padding: 18px 16px 32px; }

  body :is(.dashboard-heading, .home-heading, .profile-page-heading) { margin-bottom: 20px; gap: 12px; }
  body :is(.dash-hero-bento, .home-action-grid) { margin-bottom: 24px; }
  body :is(.dashboard-intro, .continue-hero-lead, .profile-page-heading p:not(.eyebrow),
    .consent-intro > p:last-of-type) { font-size: 13px; line-height: 1.6; }
  #createView .create-page-head { padding: 20px; }
  #createView .create-page-head > p:not(.eyebrow) { font-size: 14px; line-height: 1.6; }

  body :is(.panel, .library-panel, .profile-identity, .profile-setting-card,
    .home-progress-panel, .home-activity-panel, .facts-hero-banner,
    .fact-library-hero, .sc-conversation-panel, .sc-next-panel) { border-radius: 18px; }

  #libraryView .continue-hero { min-height: 0; padding: 20px 18px 0; }
  #libraryView .continue-hero-copy { padding-bottom: 16px; gap: 12px; }
  #libraryView :is(.home-progress-panel, .home-activity-panel) { padding: 16px; }
  #libraryView :is(.dashboard-intro, .continue-hero-lead) { font-size: 13px; line-height: 1.6; }
  #libraryView :is(.home-heading, .dash-hero-bento, .home-action-grid) { margin-bottom: 24px; gap: 12px; }
  #libraryView .continue-hero-mascot { min-height: 180px; }
  #libraryView .continue-hero-mascot img { height: 210px; max-width: 230px; }
  #libraryView .home-learning-path { padding-block: 12px; gap: 8px; }
  #libraryView .home-section-heading { margin-bottom: 14px; }
  .has-app-nav #libraryView .home-action-grid:has([data-home-catalog]) button {
    min-height: 132px;
    padding: 16px;
    gap: 12px;
  }
  #libraryView .home-action-copy strong { font-size: 18px; }
  #libraryView .home-action-grid img { max-height: 120px; object-fit: contain; }

  body .create-spotlight { min-height: 0; padding: 20px 18px; }
  body .progress-card { min-height: 0; }
  body .library-panel .section-title { margin-bottom: 16px; gap: 12px; }
  body .library-panel .course-card { min-height: 0; border-radius: 18px; }
  body .library-panel .course-card-top { min-height: 70px; padding: 12px 16px; }
  body .library-panel .course-card-icon { width: 44px; height: 44px; flex-basis: 44px; border-radius: 13px; }
  body .library-panel .course-card-body { padding: 14px 16px; gap: 8px; }
  body .library-panel .course-card h3 { font-size: 17px; line-height: 1.4; }
  body .library-panel .course-card-footer { padding: 12px 16px; }
  body :is(.empty-state, .error-state, .library-panel .empty-state, .library-panel .error-state) {
    min-height: 0;
    padding: 24px 16px;
  }

  body .profile-score-card { padding: 14px; gap: 12px; }
  body #profileView .profile-score-number strong { font-size: 30px; }
  body #profileView .profile-card-heading h2 { font-size: 18px; }
  body #profileView .profile-tabs button { min-height: 52px; gap: 4px; }
  body .profile-tabs { margin-block: 18px; }

  body :is(.lesson-text, .modal-repeat-text, .quick-fact-title strong, .quick-fact-answer p) {
    font-size: 16px;
    line-height: 1.65;
  }
  body .lesson-summary { font-size: 14px; line-height: 1.6; }
  body .quick-facts-heading h3 { font-size: 21px; }
  body :is(.quick-fact-question-zone, .quick-fact-answer-zone) { padding: 12px; }
  body .learning-modal-header { padding: 14px 16px; }
  body .learning-modal-content { padding: 16px; }
  body .learning-modal-header h2 { font-size: 22px; }
  body :is(.modal-question h4, .sequential-question h4) { font-size: 20px; }
  body .generation-overlay .generation-head { padding: 16px; }
  body .generation-overlay .generation-head h2 { font-size: 20px; }
  body .generation-overlay .generation-scroll { padding: 16px; }
  body .generation-overview { padding: 16px; }

  body :is(.saved-fact-set, .standalone-result-head.saved-detail-head) { padding: 16px; }
  body .sc-conversation-thread { padding-block: 16px; gap: 12px; }
  body :is(.sc-coach-message, .sc-user-message) { padding: 12px; line-height: 1.6; }
  body :is(.sc-conversation-heading h2, .sc-next-panel h2, .sc-dialog-heading h2) { font-size: 18px; }
  body .sc-next-panel h3 { font-size: 17px; }
  body .loop-form-panel > summary { padding: 16px; gap: 12px; }
  body :is(.loop-item, .loop-kpi) { padding: 12px; }
  body .exam-screen { padding: 16px 0 32px; }

  /* Public pages use larger display type; reduce it without flattening the hierarchy. */
  body :is(.landing-hero, .landing-story, .landing-about, .auth-panel, .intro-journey) { padding: 20px; border-radius: 22px; }
  body :is(.landing-hero h1, .hero-copy h1) { font-size: clamp(32px, 9vw, 44px); line-height: 1.12; }
  body :is(.landing-section-heading h2, .story-copy h2, .landing-about h2, .intro-heading h2) {
    font-size: 27px;
    line-height: 1.25;
  }
  body :is(.landing-hero-copy > p, .story-copy > p:not(.eyebrow), .hero-copy > p:not(.eyebrow)) { font-size: 14px; }
  body .landing-marquee { margin-bottom: 40px; }
  body :is(.landing-story, .landing-about) { margin-top: 40px; }
  body .landing-feature h3 { font-size: 21px; }

  /* Editable text stays at 16px to avoid focus zoom on phone browsers.
     Compact padding must not reduce the established 44px control height. */
  input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=hidden]),
  textarea, select,
  #profileView .field input, #profileView .field select {
    /* Override page-specific filter sizes for the focus-zoom safeguard. */
    font-size: 16px !important;
    min-height: 44px;
    padding: 8px 12px;
  }
  .password-field input { padding-right: 85px; }
  body :is(button, .ops-btn) { min-height: 44px; }
  body :is(.button-primary, .button-secondary) { padding: 9px 12px; }

  .ops-container { padding: 12px 12px 32px; gap: 12px; }
  .ops-header { padding: 10px 12px; gap: 12px; }
  :is(.ops-controls, .ops-kpi-grid, .ops-workspace) { gap: 12px; }
  :is(.admin-panel-head h2, .ops-section-header h2, .ops-sidebar-header h2) { font-size: 16px; }
  .kpi-value { font-size: 22px; }
}
