/* Responsive module cards and course dialogs. Loaded last so it can safely
   normalize both the original dashboard and the learning-path redesign. */
.course-modules .module-strip {
  min-width: 0;
}

.course-modules .module-copy {
  min-width: 0;
  overflow-wrap: anywhere;
}

.course-modules .module-card-actions,
.course-modules .exam-card-actions {
  display: flex;
  flex: 0 0 min(260px, 32%);
  flex-direction: column;
  gap: .55rem;
  min-width: 210px;
}

.course-modules .module-card-actions > button,
.course-modules .exam-card-actions > button,
.course-modules .module-strip > .module-start {
  width: 100%;
  min-height: 48px;
  white-space: normal;
  line-height: 1.25;
  touch-action: manipulation;
}

.course-modules button:disabled {
  cursor: not-allowed;
  opacity: .62;
}

/* Author-level display rules on the exam panels must not override the native
   hidden attribute. Only one exam view should occupy the shell at a time. */
.exam-shell > [hidden] {
  display: none !important;
}

.exam-workspace:not([hidden]) {
  min-height: 0;
  overflow: hidden;
}

.exam-question {
  min-height: 0;
  overscroll-behavior: contain;
}

.exam-actions {
  position: sticky;
  bottom: -1px;
  z-index: 6;
  margin-right: -10px;
  margin-left: -10px;
  padding: 16px 10px max(16px, env(safe-area-inset-bottom));
  background: rgba(255,255,255,.98);
  box-shadow: 0 -10px 24px rgba(8,38,48,.1);
}

/* Diagnostic: keep long answer explanations scrollable while preserving the
   question counter, close control, and next action. */
#diagnostic .modal-card {
  display: flex;
  flex-direction: column;
  width: min(720px, 100%);
  max-height: min(880px, calc(100dvh - 40px));
  padding: 0;
  overflow: hidden;
}

#diagnostic .modal-top {
  flex: 0 0 auto;
  align-items: center;
  padding: 18px 22px 10px;
  background: #fff;
}

#diagnostic .modal-top button {
  width: 42px;
  height: 42px;
  padding: 0;
}

.diagnostic-scroll {
  min-height: 0;
  padding: 0 22px 18px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

#diagnostic #nextQuestion {
  flex: 0 0 auto;
  float: none;
  width: auto;
  min-height: 48px;
  margin: 0 22px 18px;
}

#diagnostic #nextQuestion[hidden] {
  display: none;
}

@media (max-width: 850px) {
  .course-modules .module-strip {
    align-items: stretch;
  }

  .course-modules .module-card-actions,
  .course-modules .exam-card-actions,
  .course-modules .module-strip > .module-start {
    flex-basis: auto;
    width: 100%;
    min-width: 0;
  }

  .lesson-modal {
    overflow: hidden;
  }

  .lesson-shell {
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    min-height: 0;
  }

  .lesson-content {
    min-width: 0;
    min-height: 0;
    padding-bottom: 0;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .lesson-content h1,
  .lesson-content p,
  .lesson-content li,
  .lesson-content button {
    overflow-wrap: anywhere;
  }

  .lesson-actions {
    position: sticky;
    bottom: 0;
    z-index: 4;
    margin: 18px -16px 0;
    padding: 12px 16px max(12px, env(safe-area-inset-bottom));
    background: rgba(255,255,255,.97);
    box-shadow: 0 -8px 22px rgba(8,38,48,.1);
  }
}

@media (max-width: 560px) {
  .learning-path {
    padding-left: 0;
  }

  .learning-path::before,
  .learning-path .module-strip::before {
    display: none;
  }

  .learning-path .path-tools-heading {
    margin-left: 0;
  }

  .course-modules .module-strip {
    padding: 18px 15px;
    border-radius: 16px;
  }

  .course-modules .module-strip h2 {
    font-size: 1.3rem;
  }

  dialog.module-quiz-shell {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border-radius: 0;
  }

  .module-quiz-head {
    position: sticky;
    top: 0;
    z-index: 5;
  }

  .module-quiz-answers button {
    min-height: 52px;
    touch-action: manipulation;
  }

  .exam-question {
    padding-bottom: 0;
  }

  .exam-header {
    min-height: 82px;
    padding: 10px 12px;
    gap: 8px;
  }

  .exam-header > div:first-child {
    min-width: 0;
  }

  .exam-header h2 {
    max-width: 190px;
    font-size: 1rem;
    line-height: 1.2;
  }

  .exam-clock small {
    font-size: .58rem;
  }

  .exam-clock strong {
    font-size: 1rem;
  }

  .exam-close {
    flex-basis: 40px;
    width: 40px;
    height: 40px;
  }

  .exam-nav {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    overflow: hidden;
  }

  .exam-grid {
    min-width: 0;
    margin: 0;
    padding: 1px 0;
  }

  .exam-grid button {
    flex-basis: 36px;
    width: 36px;
    height: 36px;
    border-radius: 9px;
    font-size: .82rem;
  }

  .exam-nav > .primary {
    width: auto;
    min-width: 76px;
    min-height: 40px;
    padding: 8px 10px;
    font-size: .78rem;
    white-space: nowrap;
  }

  .exam-question {
    padding: 16px 14px 0;
  }

  .exam-question-meta {
    font-size: .7rem;
  }

  .exam-question h1 {
    margin: 14px 0 16px;
    font-size: 1.3rem;
    line-height: 1.28;
  }

  .exam-answers {
    gap: 8px;
  }

  .exam-answers button {
    min-height: 48px;
    padding: 11px 12px;
    font-size: .95rem;
  }

  .exam-actions {
    display: grid;
    grid-template-columns: 1.15fr 1fr 1fr;
    align-items: stretch;
    gap: 7px;
    margin-right: -15px;
    margin-left: -15px;
    padding: 9px 12px max(9px, env(safe-area-inset-bottom));
  }

  .exam-actions > div {
    display: contents;
  }

  .exam-actions button,
  .exam-actions .primary {
    width: 100%;
    min-width: 0;
    min-height: 46px;
    padding: 8px 5px;
    font-size: .78rem;
    line-height: 1.15;
  }

  #diagnostic {
    padding: 0;
  }

  #diagnostic .modal-card {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
  }

  #diagnostic .modal-top {
    padding: max(10px, env(safe-area-inset-top)) 14px 6px;
  }

  .diagnostic-scroll {
    padding: 0 14px 14px;
  }

  #diagnostic .diagnostic-progress {
    margin: 8px 0 16px;
  }

  #diagnostic #questionTitle {
    margin: 8px 0 16px;
    font-size: 1.35rem;
    line-height: 1.28;
  }

  #diagnostic .answers {
    gap: 8px;
  }

  #diagnostic .answers button {
    min-height: 50px;
    padding: 11px 12px;
    font-size: .95rem;
    line-height: 1.35;
  }

  #diagnostic .rationale {
    margin-top: 12px;
    padding: 12px;
    font-size: .88rem;
    overflow-wrap: anywhere;
  }

  #diagnostic #nextQuestion {
    width: auto;
    min-height: 50px;
    margin: 8px 14px max(10px, env(safe-area-inset-bottom));
    box-shadow: 0 -8px 22px rgba(8,38,48,.1);
  }
}

@media (max-width: 370px) {
  .exam-header h2 {
    max-width: 155px;
    font-size: .92rem;
  }

  .exam-actions {
    grid-template-columns: 1.2fr .9fr .9fr;
  }

  .exam-actions button,
  .exam-actions .primary {
    font-size: .72rem;
  }
}
