/* Shared sizing rules keep content inside the viewport, including long lesson links. */
body { overflow-wrap: anywhere; }
.shell > *,
.hero-stats > *,
.impression-card > *,
.early-access-card > *,
.lesson-pagination > *,
.readiness-subject-top > * { min-width: 0; }
fieldset { min-inline-size: 0; }
input, textarea, select { min-width: 0; max-width: 100%; }
img, svg, video, canvas { max-width: 100%; height: auto; }
.brand-mark { flex: none; }
.button { max-width: 100%; white-space: normal; text-align: center; }
.impression-form textarea { width: 100%; }
.early-access-form > small { display: block; margin-top: 12px; line-height: 1.6; }
.early-access-consent input, .feedback-types input, .diagnostic-options input { flex: none; }
.markdown-body pre { max-width: 100%; }
.markdown-body table { display: block; max-width: 100%; overflow-x: auto; }
.markdown-body th, .markdown-body td { min-width: 7rem; }
.markdown-body pre code { overflow-wrap: normal; }
.diagnostic-actions-after { flex-wrap: wrap; }

.nav-toggle {
  display: none;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
.nav-toggle:focus-visible, .nav-links a:focus-visible, .theme-button:focus-visible,
.back-link:focus-visible, .cockpit-close:focus-visible,
.impression-options input:focus-visible + span, .score-row input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* Collapse before the desktop links collide with the brand. Without JS they wrap. */
@media (max-width: 1100px) {
  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    height: auto;
    min-height: 68px;
    gap: 0 12px;
    padding: 12px 16px;
  }
  .brand-copy small { display: none; }
  .back-link { display: inline-flex; min-height: 44px; align-items: center; }
  .cockpit-close { width: 44px; height: 44px; }
  .nav-toggle:not([hidden]) { display: inline-flex; align-items: center; justify-content: center; }
  .nav-links {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    width: 100%;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--line);
    max-height: calc(100vh - 100px);
    max-height: calc(100dvh - 100px);
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .topbar[data-nav-ready] .nav-links:not(.is-open) { display: none; }
  .nav-links a, .nav-links a:first-child, .nav-links .theme-button {
    display: flex;
    min-height: 44px;
    align-items: center;
    padding: 10px 12px;
  }
}

@media (max-width: 760px) {
  .hero h1, .page-intro h1, .course-intro h1, .readiness-hero h1 {
    font-size: clamp(30px, 7.5vw, 44px);
    line-height: 1.12;
  }
  .lesson-reader-header h1 { font-size: clamp(28px, 7vw, 40px); line-height: 1.15; }
  .hero-actions .button, .lesson-actions .button, .course-diagnostic-cta .button { width: 100%; }
  .hero-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
  .hero-instrument { min-height: 0; padding: 20px; }
  .course-hero-card h2, .readiness-method-note h2 { font-size: clamp(25px, 6.5vw, 32px); }
  .impression-card, .early-access-card, .lesson-feedback, .foundation-status-card, .readiness-method-note {
    padding: 20px;
    gap: 24px;
  }
  .impression-copy h2 { font-size: 29px; }
  .impression-options span { text-align: center; }
  .score-row { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .score-row span { min-height: 44px; }
  .score-labels { gap: 12px; }
  .score-labels > :last-child { text-align: right; }
  .impression-actions .button, .early-access-actions .button, .feedback-actions .button { width: 100%; }
  .impression-form textarea, .early-access-form input[type="email"], .lesson-feedback textarea { font-size: 16px; }
  .readiness-hero { padding-top: 36px; }
  .foundation-status-actions { justify-items: stretch; }
  .lesson-layout { gap: 24px; padding-top: 24px; }
  .lesson-sidebar { gap: 10px; }
  .lesson-reader-header { padding-top: 0; }
  .lesson-row { gap: 10px; }
  .lesson-pagination { grid-template-columns: minmax(0, 1fr); }
  .lesson-pagination .next { text-align: left; }
  .markdown-body h2 { font-size: 23px; }
  .markdown-body ul, .markdown-body ol { padding-inline-start: 24px; }
  .admin-data-card { padding: 16px; }
}

/* The welcome remains scrollable on a short phone screen, including landscape. */
.cockpit-welcome { overflow-y: auto; }
.cockpit-welcome-panel {
  width: min(980px, 100%);
  max-height: calc(100vh - 44px);
  max-height: calc(100dvh - 44px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
@media (max-width: 700px) {
  .cockpit-welcome-panel { max-height: calc(100vh - 20px); max-height: calc(100dvh - 20px); }
  .cockpit-enter { min-width: 0; }
}
@media (max-height: 600px) {
  .cockpit-photo { height: 35vh; height: 35dvh; aspect-ratio: auto; }
}
/* Keep the answers visible when the screen has little vertical space. */
@media (max-height: 500px) {
  .diagnostic-submit { position: static; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .cockpit-welcome, .cockpit-welcome-panel { animation: none; }
}
