/* Responsive behavior — tablet (<=1080px) and mobile (<=760px). */

@media (max-width: 1080px) {
  .lesson-grid { grid-template-columns: minmax(0, 1fr); }
  .nav-journey, .topbar--home .nav-journey { display: inline-flex; }

  /* Dashboard hero & content grid responsiveness */
  .rich-hero-grid { grid-template-columns: 1fr 1fr; gap: 20px; }
  .hero-art-container { grid-column: 1 / -1; min-height: 180px; max-height: 200px; }
  .dash-content-body { grid-template-columns: 1fr; gap: 28px; padding: 24px 24px 12px 24px; }
  .study-cards-grid { grid-template-columns: repeat(2, 1fr); gap: 16px; }

  .library-wrap.dash-panel .dash-main-layout {
    grid-template-columns: 1fr;
  }
  .library-wrap.dash-panel .dash-sidebar {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: start;
  }
  .library-wrap.dash-panel .side-card {
    height: 100%;
  }
}

@media (max-width: 760px) {
  :root { --topbar-h: 62px; }
  .wrap, .topbar-inner { padding-left: var(--s-16); padding-right: var(--s-16); }
  .topbar-inner { gap: var(--s-8); }
  .topbar-controls { gap: var(--s-6); }
  .topbar-controls .icon-btn { width: 38px; height: 38px; }
  .topbar-controls .lesson-step-btn { width: 38px; height: 38px; font-size: 1.15rem; border-radius: 50%; }
  .topbar-all-lessons { padding: 4px 8px; font-size: .76rem; min-height: 34px; }
  .size-controls { gap: 0; }
  .size-controls .code { display: none; }
  .brand { transform: none; margin-left: 2px; margin-right: 2px; height: auto; gap: 6px; }
  .brand-logo-img { height: 62px; max-width: 200px; }
  .brand-name { font-size: 1.02rem; }
  .study-nav-btn { width: 42px; height: 42px; }
  .study-nav-icon { width: 34px; height: 34px; }
  .brand-tag { display: none; }
  .masthead h1 { font-size: 1.6rem; }
  .library-head h1 { font-size: 2.25rem; }
  .library-head .library-separator { display: none; }
  .library-head .library-ar { display: block; margin-top: var(--s-8); font-size: .54em; }
  .passage .para { grid-template-columns: 1fr; gap: 2px; }
  .passage { padding: var(--s-20) var(--s-16); }
  .passage .para-num { padding-top: 0; }
  .passage .lesson-illustration {
    float: none;
    width: 100%;
    margin: 0 0 var(--s-20);
    shape-outside: none;
  }
  .passage .lesson-illustration::after {
    background: linear-gradient(0deg, var(--surface) 0%, rgba(255,252,244,.6) 5%, transparent 20%);
  }
  .reading-heading {
    flex-wrap: nowrap;
    gap: var(--s-8);
  }
  .reading-heading h2 { font-size: 1.2rem; }
  .reading-heading .reading-rule { flex-basis: 10px; min-width: 10px; }
  .reading-heading .listen-btn { width: 40px; height: 40px; min-width: 40px; min-height: 40px; }
  .reading-heading .reading-count { padding-left: 8px; padding-right: 8px; }
  .mobile-bar .mb-progress { display: none; }
  .lesson-row { grid-template-columns: auto minmax(0, 1fr) auto; gap: var(--s-12); }
  .lesson-row .lr-code { grid-column: 1; grid-row: 1; }
  .lesson-row .lr-copy { grid-column: 2; grid-row: 1; }
  .lesson-row .library-status-wrap { grid-column: 2; grid-row: 2; justify-self: start; }
  .lesson-row .lr-arrow { display: block; grid-column: 3; grid-row: 1 / span 2; }
  .unit-toggle { align-items: center; flex-wrap: wrap; }
  .unit-toggle .unit-name { white-space: normal; overflow: visible; text-overflow: clip; }
  .tf-group { flex-direction: column; }
  .cloze-line select { min-width: 100%; }
  .report .total { font-size: 2.4rem; }

  /* New interaction controls stack cleanly at phone width. */
  .match-row { grid-template-columns: 1fr; gap: var(--s-8); }
  .match-row .match-arrow { display: none; }
  .match-row select { width: 100%; }
  .seq-item { grid-template-columns: auto minmax(0, 1fr); }
  .seq-controls { grid-column: 1 / -1; justify-content: flex-end; }
  .classify-row select { flex-basis: 100%; }
  .cloze-text { line-height: 2.6; }
  .cloze-text select { min-width: min(160px, 100%); display: inline-block; }

  /* Check answers bar: show it on mobile with a full-width, tappable button. */
  .check-bar { flex-wrap: wrap; gap: var(--s-8); }
  .check-bar .btn-primary { flex: 1 1 100%; min-height: 46px; }
  .check-bar .helper { flex: 1 1 100%; }
  .check-bar .sec-score { margin-left: 0; }

  /* Compact ink-note popup remains inset and readable on mobile. */
  .popover {
    position: fixed !important;
    left: var(--s-12) !important; right: var(--s-12); bottom: var(--s-12); top: auto !important;
    width: auto;
    max-height: calc(100vh - 24px);
    overflow-y: auto;
    border-radius: 4px;
  }

  /* Homepage redesign — phone layout. */
  .utility-bar-inner { flex-wrap: wrap; gap: var(--s-8); }
  .lib-search { flex: 1 1 100%; }
  .lib-chips { flex: 1 1 100%; }
  .lib-count { margin-left: 0; width: 100%; text-align: right; }
  .jump-nav {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: var(--s-12);
  }
  .jump-link { flex-shrink: 0; }
  .category-title { font-size: 1.2rem; }
  .back-to-top { bottom: 16px; right: 16px; padding: 8px 14px; font-size: .8rem; }

  /* Dashboard hero & study cards stack on phones. */
  .library-wrap.dash-panel { margin-top: 12px; margin-bottom: 12px; border-radius: 12px; }
  .rich-hero { padding: 24px 18px; }
  .rich-hero-grid { grid-template-columns: 1fr; gap: 20px; }
  .dash-content-body { padding: 20px 18px; }
  .study-cards-grid { grid-template-columns: 1fr; }
  .dash-user-controls { display: none; }
  .dash-hero-head { flex-direction: column; align-items: flex-start; gap: 14px; }
  .dash-hero-body { gap: 22px; }
  .progress-ring { width: 150px; height: 150px; }
  .achievements { flex-basis: 100%; min-width: 0; }
  .study-cards { grid-template-columns: 1fr; max-width: 340px; margin: 0 auto; }
  .topic-grid { grid-template-columns: 1fr; }

  .library-page.dash {
    padding: 12px 10px 24px;
    overflow-x: hidden;
  }
  .dash-unified-overlay {
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
  }
  .dash-unified-overlay .dash-nav {
    flex: 1 1 auto;
    min-width: 0;
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .dash-unified-overlay .dash-nav::-webkit-scrollbar {
    display: none;
  }
  .dash-unified-overlay .dash-nav-link {
    flex: 0 0 auto;
  }
  .library-wrap.dash-panel .dash-main-layout {
    gap: 22px;
    padding: 18px;
  }
  .library-wrap.dash-panel .dash-hero-banner {
    min-height: 0;
    padding: 30px 24px 26px;
    flex-direction: column;
    gap: 22px;
  }
  .library-wrap.dash-panel .dash-hero-banner::before {
    width: 100%;
    height: 48%;
    opacity: .14;
  }
  .library-wrap.dash-panel .hero-left-content {
    max-width: 100%;
    padding-right: 0;
  }
  .library-wrap.dash-panel .hero-title-main {
    max-width: 100%;
    font-size: clamp(2rem, 10vw, 2.55rem);
  }
  .library-wrap.dash-panel .hero-subtitle-main,
  .library-wrap.dash-panel .hero-blue-banner,
  .library-wrap.dash-panel .hero-divider {
    max-width: 100%;
  }
  .library-wrap.dash-panel .hero-progress-area {
    width: 100%;
    min-width: 0;
    padding: 8px 0 58px;
  }
  .library-wrap.dash-panel .hero-progress-stack {
    transform: none;
  }
  .library-wrap.dash-panel .progress-ring,
  .library-wrap.dash-panel .hero-progress-action {
    transform: none;
  }
  .library-wrap.dash-panel .hero-skyline {
    right: -8%;
    width: 116%;
    height: 150px;
    opacity: .17;
  }
  .library-wrap.dash-panel .hero-streak-float {
    right: 3px;
    bottom: 2px;
  }
  .library-wrap.dash-panel .study-cards-grid {
    grid-template-columns: 1fr;
  }
  .library-wrap.dash-panel .dash-sidebar {
    display: flex;
  }
  .library-wrap.dash-panel .dash-footer-banner {
    align-items: flex-start;
    grid-template-columns: 1fr;
    gap: 13px;
    margin: 0;
  }
  .library-wrap.dash-panel .df-right {
    justify-self: start;
    padding-left: 55px;
    white-space: normal;
  }

  /* Reference dashboard header and hero at phone width. */
  .topbar--dashboard .topbar-inner,
  .topbar--dashboard .dash-unified-overlay {
    min-height: 72px;
  }
  .topbar--dashboard .dash-unified-overlay {
    padding: 0 14px;
    gap: 10px;
  }
  .topbar--dashboard .brand-logo-img {
    width: 44px;
    height: 44px;
  }
  .topbar--dashboard .brand-name,
  .topbar--dashboard .brand-name .bn-accent {
    font-size: 1.08rem;
  }
  .topbar--dashboard .dash-nav-link {
    padding-top: 25px;
    padding-bottom: 23px;
    font-size: .82rem;
  }
  .topbar--dashboard .dash-nav-link::after {
    bottom: 16px;
  }
  .library-wrap.dash-panel .hero-left-content {
    width: 100%;
  }
  .library-wrap.dash-panel .hero-progress-area {
    width: 100%;
    padding: 8px 0 24px;
  }
  .library-wrap.dash-panel .progress-ring {
    width: 158px;
    height: 158px;
  }
  .library-wrap.dash-panel .ring-pct {
    font-size: 2.25rem;
  }
  .library-wrap.dash-panel .hero-streak-float {
    position: static;
    width: auto;
    min-width: 112px;
    margin-top: 4px;
    align-self: center;
  }
}
