/* Tablet layout: keep lesson navigation legible above the reading area. */
@media (max-width: 800px) {
  .course-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 18px;
    padding-bottom: 32px;
  }

  .lesson-sidebar {
    position: static;
  }

  .lesson-sidebar nav {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  .lesson-tab {
    min-width: 0;
  }

  .lesson-content {
    min-height: 0;
  }
}

/* Phones: compact header and employee identity, with one clear lesson list. */
@media (max-width: 700px) {
  .academy-header {
    gap: 8px;
    padding: 10px 16px;
  }

  .identity {
    gap: 9px;
    font-size: 16px;
  }

  .identity-mark {
    width: 42px;
    height: 42px;
    border-radius: 12px 4px 12px 4px;
    font-size: 27px;
  }

  .identity-mark span {
    right: 6px;
    bottom: 3px;
    font-size: 11px;
  }

  .identity small {
    font-size: 10px;
    line-height: 1.45;
  }

  .academy-header nav {
    width: 100%;
    min-width: 0;
    justify-content: space-between;
    flex-wrap: nowrap;
    gap: 4px;
    font-size: 12px;
  }

  .academy-header nav a {
    padding: 6px 2px;
    white-space: nowrap;
  }

  .academy-header nav .nav-lab {
    flex: 0 0 auto;
    padding: 6px 8px;
    font-size: 12px;
  }

  .academy-header nav .theme-toggle {
    flex: 0 0 auto;
    margin-right: 0;
    padding: 6px 8px;
    font-size: 12px;
  }

  main {
    padding-inline: 16px;
  }

  .breadcrumb {
    flex-wrap: wrap;
    gap: 4px 8px;
    padding: 18px 0 12px;
    font-size: 12px;
  }

  .employee-identity {
    align-items: center;
    flex-direction: row;
    gap: 10px;
    margin: 8px 0 18px;
    padding: 10px 12px;
  }

  .employee-identity-details {
    flex: 1 1 auto;
  }

  .employee-identity-kicker {
    font-size: 11px;
  }

  .employee-identity-name {
    font-size: 18px;
    line-height: 1.4;
  }

  .employee-identity-meta {
    font-size: 12px;
    line-height: 1.55;
    overflow-wrap: anywhere;
  }

  .employee-identity-action {
    align-self: center;
    min-height: 40px;
    padding: 6px 9px;
    font-size: 12px;
    white-space: nowrap;
  }

  .course-intro {
    display: block;
    padding: 4px 0 22px;
  }

  .course-intro h1 {
    font-size: 30px;
    line-height: 1.4;
  }

  .course-intro p {
    margin-top: 7px;
    font-size: 14px;
    line-height: 1.8;
  }

  .course-intro-actions {
    display: flex;
    max-width: none;
    flex-wrap: nowrap;
    gap: 8px;
    margin-top: 14px;
  }

  .course-intro-actions .button {
    flex: 1 1 0;
    min-width: 0;
    min-height: 44px;
    padding: 8px 9px;
    font-size: 14px;
    white-space: nowrap;
  }

  .course-layout {
    display: block;
    padding-bottom: 28px;
  }

  .lesson-sidebar {
    margin-bottom: 16px;
  }

  .lesson-sidebar nav {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }

  .lesson-tab {
    width: 100%;
    min-height: 46px;
    gap: 10px;
    padding: 9px 12px;
    font-size: 14px;
    line-height: 1.5;
  }

  .lesson-tab span {
    min-width: 24px;
    text-align: center;
  }

  .lesson-sidebar > .source-note {
    display: none;
  }

  .lesson-content {
    min-width: 0;
    min-height: 0;
    padding: 20px 18px;
    border-radius: 12px;
  }

  .lesson-content h2 {
    margin-bottom: 12px;
    font-size: 22px;
    line-height: 1.5;
    overflow-wrap: anywhere;
  }

  .lesson-lead,
  .lesson-content > p {
    font-size: 15px;
    line-height: 1.85;
  }

  .lesson-content ul {
    margin: 16px 0;
    padding-inline-start: 21px;
    line-height: 1.9;
  }

  .lesson-content li {
    min-width: 0;
    padding: 3px 0;
    font-size: 15px;
    line-height: 1.8;
    overflow-wrap: anywhere;
  }

  .lesson-content [dir="ltr"] {
    direction: ltr;
    unicode-bidi: isolate;
  }

  .lesson-content bdi[dir="ltr"] {
    display: block;
    max-width: 100%;
    text-align: left;
    overflow-wrap: anywhere;
  }

  .chemistry-equation {
    max-width: 100%;
    min-width: 0;
    margin-top: 16px;
    padding: 14px 10px;
    font-size: clamp(16px, 5vw, 22px);
    line-height: 1.6;
    overflow-wrap: anywhere;
  }

  .endpoint-image,
  .lesson-content img,
  .lesson-content video {
    display: block;
    max-width: 100%;
    height: auto;
  }

  .lesson-content table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
  }

  .reagent-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    margin-top: 16px;
  }

  .reagent-grid > div {
    min-width: 0;
    padding: 10px 12px;
  }

  .steps-list li {
    align-items: flex-start;
    gap: 10px;
    padding: 11px 0 !important;
  }

  .steps-list li::before {
    flex: 0 0 28px;
    width: 28px;
    height: 28px;
    line-height: 28px;
  }

  .endpoint-tabs {
    gap: 6px;
    margin-top: 16px;
  }

  .endpoint-tabs button {
    min-width: 0;
    min-height: 44px;
    padding: 8px 5px;
    font-size: 12px;
  }

  .endpoint-detail {
    min-height: 60px;
    gap: 9px;
    padding: 12px;
    font-size: 14px;
    line-height: 1.7;
  }

  .calc-box,
  .quality-callout {
    min-width: 0;
    margin-top: 16px;
    padding: 14px;
    font-size: 14px;
    line-height: 1.8;
    overflow-wrap: anywhere;
  }

  .calc-box input {
    max-width: 100%;
    min-height: 44px;
  }

  .calc-output {
    font-size: 24px;
    overflow-wrap: anywhere;
  }

  .lesson-sources {
    max-width: 100%;
    padding: 12px;
    overflow-wrap: anywhere;
  }

  .lesson-sources a {
    overflow-wrap: anywhere;
  }

  .lesson-footer {
    align-items: stretch;
    gap: 8px;
    margin-top: 20px;
    padding-top: 14px;
  }

  .lesson-footer > .button {
    flex: 1 1 0;
    min-width: 0;
    min-height: 44px;
    padding: 8px 10px;
    font-size: 14px;
    text-align: center;
  }

  .quiz-intro {
    padding: 24px 0 40px;
  }

  .quiz-intro h1 {
    font-size: 26px;
    line-height: 1.5;
  }

  .quiz-intro > p {
    margin: 12px 0;
    font-size: 15px;
    line-height: 1.8;
  }

  .quiz-rules {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin: 18px 0;
  }

  .quiz-rules > span {
    min-width: 0;
    padding: 12px 6px;
    font-size: 11px;
    line-height: 1.55;
    overflow-wrap: anywhere;
  }

  .quiz-rules strong {
    font-size: 19px;
  }

  .question-card {
    min-width: 0;
    padding: 16px 12px;
  }

  .question-card legend {
    max-width: 100%;
    font-size: 18px;
    line-height: 1.65;
    overflow-wrap: anywhere;
  }

  .answer-option {
    min-width: 0;
    align-items: flex-start;
    gap: 9px;
    padding: 12px 10px;
    font-size: 15px;
    line-height: 1.7;
    overflow-wrap: anywhere;
  }

  .answer-option input {
    flex: 0 0 auto;
    margin-top: 5px;
  }

  .quiz-actions > .button,
  .submit-quiz {
    min-height: 44px;
  }

  .score-hero {
    padding: 20px;
  }

  .review-item {
    min-width: 0;
    padding: 16px;
    overflow-wrap: anywhere;
  }

  .academy-footer {
    padding: 18px 16px;
    gap: 4px;
  }
}

/* Very narrow phones: allow long navigation labels to wrap without page overflow. */
@media (max-width: 360px) {
  .academy-header nav {
    gap: 2px;
    font-size: 11px;
  }

  .academy-header nav a {
    padding-inline: 1px;
  }

  .academy-header nav .nav-lab,
  .academy-header nav .theme-toggle {
    padding-inline: 6px;
    font-size: 11px;
  }

  .employee-identity {
    gap: 7px;
    padding-inline: 9px;
  }

  .employee-identity-name {
    font-size: 16px;
  }

  .employee-identity-action {
    padding-inline: 7px;
    font-size: 11px;
  }

  .course-intro h1 {
    font-size: 28px;
  }

  .course-intro-actions .button {
    padding-inline: 6px;
    font-size: 13px;
  }

  .lesson-content {
    padding: 16px 14px;
  }

  .quiz-rules > span {
    padding-inline: 4px;
    font-size: 10px;
  }
}

/* Mobile course navigation: select a lesson while retaining the existing desktop list. */
.lesson-select-label,
#lessonSelect {
  display: none;
}

@media (max-width: 767px) {
  .lesson-select-label {
    display: block;
    margin: 0 0 8px;
    color: var(--muted);
    font-size: 13px;
  }

  #lessonSelect {
    display: block;
    width: 100%;
    min-height: 48px;
    margin-bottom: 12px;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--panel);
    color: var(--text);
    font: inherit;
    text-align: right;
    direction: rtl;
  }

  #lessonSelect:focus-visible {
    outline: 3px solid var(--mint);
    outline-offset: 3px;
  }

  #lessonNav {
    display: none;
  }

  .lesson-footer {
    display: flex;
    justify-content: space-between;
    gap: 10px;
  }

  .lesson-footer .button {
    min-width: 110px;
    min-height: 44px;
  }

  .lesson-footer .button:disabled {
    opacity: 0.42;
  }
}

/* Mobile-only compact academy layout. Desktop and tablet rules above stay intact. */
.mobile-menu-button,
.mobile-menu-dialog,
.mobile-course-title,
.employee-action-short {
  display: none;
}

@media (max-width: 767px) {
  html.mobile-menu-open {
    overflow: hidden;
  }

  .academy-header {
    flex-wrap: nowrap;
    gap: 10px;
    padding: 8px 14px;
  }

  html[data-theme="swa"] .academy-header {
    padding-block: 8px;
    border-top-width: 0;
  }

  .identity {
    min-width: 0;
    gap: 8px;
    font-size: 15px;
    line-height: 1.4;
  }

  .identity > span:last-child {
    white-space: nowrap;
  }

  .identity small {
    display: none;
  }

  .identity-mark {
    flex: 0 0 36px;
    width: 36px;
    height: 36px;
    border-radius: 10px 4px 10px 4px;
    font-size: 23px;
  }

  .identity-mark span {
    right: 5px;
    bottom: 2px;
    font-size: 9px;
  }

  .academy-header > nav {
    display: none;
  }

  .mobile-menu-button {
    display: inline-grid;
    flex: 0 0 40px;
    width: 40px;
    height: 40px;
    place-items: center;
    margin-inline-start: auto;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: var(--panel);
    color: var(--text);
    font-size: 23px;
    line-height: 1;
  }

  .mobile-menu-button:focus-visible,
  .mobile-menu-close:focus-visible,
  .mobile-menu-link:focus-visible,
  .mobile-theme-toggle:focus-visible {
    outline: 3px solid var(--mint);
    outline-offset: 3px;
  }

  .mobile-menu-dialog {
    position: fixed;
    inset: 0 0 0 auto;
    width: min(84vw, 340px);
    height: 100vh;
    height: 100dvh;
    max-height: none;
    margin: 0;
    padding: 24px 20px;
    border: 1px solid var(--line);
    border-radius: 20px 0 0 20px;
    background: var(--panel);
    color: var(--text);
    box-shadow: -18px 0 55px #0004;
    overflow-y: auto;
  }

  .mobile-menu-dialog[open] {
    display: flex;
    flex-direction: column;
    animation: mobile-drawer-in 180ms ease-out;
  }

  .mobile-menu-dialog::backdrop {
    background: rgb(3 14 20 / 68%);
  }

  .mobile-menu-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--line);
  }

  .mobile-menu-header h2 {
    font-size: 19px;
  }

  .mobile-menu-close {
    display: grid;
    flex: 0 0 40px;
    width: 40px;
    height: 40px;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: transparent;
    color: var(--text);
    font-size: 26px;
    line-height: 1;
  }

  .mobile-menu-nav {
    display: grid;
    gap: 8px;
    margin: 16px 0;
  }

  .mobile-menu-link {
    display: block;
    padding: 12px 13px;
    border: 1px solid transparent;
    border-radius: 9px;
    color: var(--text);
    text-align: right;
  }

  .mobile-menu-link:hover,
  .mobile-menu-link[aria-current] {
    border-color: var(--line);
    background: color-mix(in srgb, var(--mint) 10%, var(--panel));
    color: var(--mint);
  }

  .mobile-theme-toggle {
    display: inline-flex;
    width: 100%;
    min-height: 46px;
    justify-content: flex-start;
    margin-top: 4px;
    padding: 10px 13px;
    color: var(--text);
    text-align: right;
  }

  main {
    padding-inline: 14px;
  }

  .breadcrumb {
    gap: 4px 7px;
    padding-block: 10px 6px;
  }

  .employee-identity {
    align-items: center;
    flex-direction: row;
    gap: 8px;
    margin: 4px 0 9px;
    padding: 7px 9px;
    border-radius: 9px;
  }

  .employee-identity-details {
    min-width: 0;
    flex: 1 1 auto;
    gap: 0;
    text-align: right;
  }

  .employee-identity-kicker {
    display: none;
  }

  .employee-identity-name {
    font-size: 15px;
    line-height: 1.4;
  }

  .employee-identity-meta {
    font-size: 10.5px;
    line-height: 1.45;
  }

  .employee-identity-action {
    flex: 0 0 auto;
    align-self: center;
    min-height: 36px;
    padding: 5px 6px;
    border: 0;
    font-size: 12px;
    white-space: nowrap;
  }

  .employee-action-full {
    display: none;
  }

  .employee-action-short {
    display: inline;
  }

  .course-intro {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 0 0 10px;
  }

  .course-intro-copy {
    display: none;
  }

  .mobile-course-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-width: 0;
    margin-bottom: 5px;
    color: var(--mint);
    font-size: clamp(10px, 2.8vw, 13px);
    font-weight: 650;
    line-height: 1.5;
    white-space: nowrap;
  }

  .mobile-course-title-ar,
  .mobile-course-title-en {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .mobile-course-title-ar {
    flex: 1 1 auto;
    text-align: right;
  }

  .mobile-course-title-en {
    flex: 0 1 42%;
    text-align: left;
  }

  .course-intro-actions {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    margin-top: 5px;
  }

  .course-intro-actions .button {
    flex: 1 1 0;
    min-width: 0;
    min-height: 44px;
    padding: 7px 8px;
    font-size: 13px;
    white-space: nowrap;
  }

  .lesson-sidebar {
    margin-bottom: 9px;
  }

  .lesson-sidebar > .eyebrow {
    margin-bottom: 5px;
    font-size: 12px;
  }

  .lesson-select-label {
    display: none;
  }

  #lessonSelect {
    min-height: 44px;
    margin-bottom: 8px;
    padding: 7px 10px;
    font-size: 14px;
  }

  .lesson-content,
  html[data-theme="swa"] .lesson-content {
    padding: 16px 13px;
    border-radius: 11px;
    background: #e9f0ee;
  }

  .lesson-content h2 {
    margin-bottom: 10px;
    font-size: 20px;
    line-height: 1.5;
  }

  .lesson-content h2:focus:not(:focus-visible) {
    outline: none;
  }

  .lesson-content h2:focus-visible {
    outline: 3px solid var(--mint);
    outline-offset: 3px;
    border-radius: 3px;
  }

  .academy-footer {
    padding: 15px 14px;
  }
}

@keyframes mobile-drawer-in {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

@media (prefers-reduced-motion: reduce) {
  .mobile-menu-dialog[open] {
    animation: none;
  }
}
