.student-body,
.student-body * {
  box-sizing: border-box;
}

html:has(.student-body) {
  height: 100%;
  overflow: hidden;
}

.student-body {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100svh;
  min-height: 100vh;
  background: #eef2f7;
  overflow: hidden;
}

.student-topbar {
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 78px;
  padding: 12px clamp(18px, 5vw, 52px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(10px);
}

.student-topbar h1 {
  margin: 2px 0 0;
  color: #111827;
  font-size: clamp(20px, 3vw, 30px);
  line-height: 1.25;
}

.student-output-status {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.student-output-status.ok {
  color: #15803d;
}

.student-output-status.warn {
  color: #b45309;
}

#student-kicker {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.student-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.student-actions button {
  min-height: 34px;
  padding: 5px 11px;
}

.student-actions button.active {
  border-color: #2563eb;
  background: #eff6ff;
  color: #1d4ed8;
  font-weight: 800;
}

.student-viewer-root {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  justify-items: center;
  gap: 12px;
  min-height: 0;
  padding: clamp(12px, 2.4vh, 26px) clamp(14px, 3vw, 36px) clamp(12px, 2.4vh, 26px);
}

.student-card-reader {
  position: relative;
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) 46px;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 920px;
  min-height: 0;
  height: 100%;
}

.student-card-viewport {
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-behavior: smooth;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  overscroll-behavior: contain;
  border-radius: 18px;
}

.student-card-viewport::-webkit-scrollbar {
  display: none;
}

.student-card-track {
  display: flex;
  width: 100%;
  height: 100%;
}

.student-card-slide {
  display: grid;
  flex: 0 0 100%;
  place-items: center;
  min-width: 0;
  min-height: 0;
  padding: 4px;
  scroll-snap-align: center;
  scroll-snap-stop: always;
}

.student-nav-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 64px;
  border: 1px solid #d8dded;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  color: #48556b;
  box-shadow: 0 10px 26px rgba(28, 39, 54, 0.12);
  font-size: 34px;
  line-height: 1;
  cursor: pointer;
}

.student-nav-button:disabled {
  opacity: 0.32;
  cursor: default;
}

.student-card-progress {
  display: grid;
  grid-template-columns: auto minmax(96px, 220px);
  align-items: center;
  gap: 12px;
  color: #56637a;
  font-size: 13px;
  font-weight: 800;
}

.student-progress-track {
  width: 100%;
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: #dfe5ef;
}

.student-progress-track span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--flow-accent), var(--rose-accent));
}

.student-card {
  --student-card-scale: 1;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
  width: min(430px, calc(100vw - 132px), calc(56.25svh - 112px));
  aspect-ratio: 9 / 16;
  padding: 22px;
  border: 1px solid var(--card-line);
  border-radius: var(--card-radius);
  background: linear-gradient(180deg, #ffffff 0%, var(--card-soft) 100%);
  box-shadow: 0 12px 30px rgba(28, 39, 54, 0.12);
  overflow: hidden;
}

.student-card.is-paired {
  gap: 12px;
}

.student-card-kicker,
.student-page-kicker {
  width: fit-content;
  padding: 4px 9px;
  border: 1px solid #e0d8f2;
  border-radius: 999px;
  color: #596579;
  background: #ffffff;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.2;
}

.student-card-body {
  display: grid;
  align-content: start;
  gap: 13px;
  min-height: 0;
  overflow: hidden;
}

.student-card-section {
  min-height: 0;
}

.student-card .textbook-block {
  margin: 0;
  font-size: calc(15px * var(--student-card-scale));
  line-height: 1.68;
}

.student-card .textbook-block h1 {
  max-width: 100%;
  font-size: calc(25px * var(--student-card-scale));
}

.student-card .textbook-block h2 {
  font-size: calc(20px * var(--student-card-scale));
}

.student-card .textbook-block h3 {
  font-size: calc(18px * var(--student-card-scale));
}

.student-card mjx-container {
  max-width: 100%;
}

.student-card mjx-container[jax="CHTML"][display="true"] {
  display: block;
  width: auto;
  margin: 0.42em auto;
}

.student-card mjx-container.student-math-fit {
  transform-origin: center center;
}

.student-card.is-tight .textbook-block {
  font-size: calc(14px * var(--student-card-scale));
  line-height: 1.56;
}

.student-card.is-tight .textbook-block h1 {
  font-size: calc(23px * var(--student-card-scale));
}

.student-card.is-tight .textbook-block h2 {
  font-size: calc(18px * var(--student-card-scale));
}

.student-card.is-tight .textbook-block h3 {
  font-size: calc(16.5px * var(--student-card-scale));
}

.student-card.is-tight .student-card-body {
  gap: 10px;
}

.student-card.is-very-tight {
  padding: 18px;
}

.student-card.is-very-tight .textbook-block {
  font-size: calc(13.2px * var(--student-card-scale));
  line-height: 1.48;
}

.student-card.is-very-tight .textbook-block h1 {
  font-size: calc(21px * var(--student-card-scale));
}

.student-card.is-very-tight .textbook-block h2 {
  font-size: calc(17px * var(--student-card-scale));
}

.student-card.is-very-tight .textbook-block h3 {
  font-size: calc(15.5px * var(--student-card-scale));
}

.student-card.is-very-tight .student-card-body {
  gap: 8px;
}

.student-card.is-overflowing {
  outline: 2px solid rgba(180, 35, 24, 0.42);
  outline-offset: 3px;
}

.student-card:has(.block-chapter_title) {
  border-color: #d8d3f4;
  background:
    linear-gradient(135deg, rgba(143, 140, 247, 0.12), rgba(233, 165, 194, 0.1) 52%, rgba(255, 255, 255, 0.94)),
    #fffafd;
}

.student-card .block-chapter_title {
  margin: 0;
  padding: 24px 24px 26px;
  border: 1px solid #ded8f6;
  border-left: 6px solid var(--flow-accent);
  border-radius: var(--card-radius);
  background:
    linear-gradient(90deg, rgba(143, 140, 247, 0.12), rgba(233, 165, 194, 0.08) 52%, rgba(255, 255, 255, 0.94)),
    #fffafd;
}

.student-landscape-stack {
  display: grid;
  gap: 22px;
  justify-items: center;
  width: 100%;
}

.student-landscape-page {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  row-gap: 6mm;
  width: min(297mm, calc(100vw - 32px));
  aspect-ratio: 297 / 210;
  padding: 22mm 14mm 9mm 16mm;
  background: #ffffff;
  box-shadow: 0 12px 34px rgba(28, 39, 54, 0.18);
  overflow: hidden;
}

.student-landscape-header,
.student-landscape-footer {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 9pt;
}

.student-landscape-header strong {
  color: var(--text);
  font-size: 10pt;
}

.student-landscape-header span:last-child {
  text-align: right;
}

.student-landscape-footer {
  border-top: 1px solid #e5e7eb;
  padding-top: 3mm;
}

.student-landscape-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6mm;
  align-items: start;
  min-height: 0;
}

.student-landscape-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: 100%;
  aspect-ratio: 9 / 16;
  min-height: 0;
  padding: 4mm;
  border: 1px solid var(--card-line);
  border-radius: var(--card-radius);
  background: linear-gradient(180deg, #ffffff 0%, var(--card-soft) 100%);
  box-shadow: inset 0 0 0 1px #f7f4fb;
  overflow: hidden;
}

.student-landscape-card.overflowing {
  outline: 2px solid rgba(180, 35, 24, 0.5);
}

.student-landscape-card-body {
  display: grid;
  align-content: start;
  gap: 2.4mm;
  min-height: 0;
  overflow: hidden;
}

.student-landscape-card .textbook-block {
  margin: 0;
  font-size: 8.1pt;
  line-height: 1.46;
}

.student-landscape-card .textbook-block h1 {
  max-width: 100%;
  font-size: 13.8pt;
}

.student-landscape-card .textbook-block h2 {
  font-size: 10.6pt;
}

.student-landscape-card .textbook-block h3 {
  font-size: 9.8pt;
}

.student-landscape-card.is-long .student-landscape-card-body {
  gap: 1.8mm;
}

.student-landscape-card.is-long .textbook-block {
  font-size: 7.55pt;
  line-height: 1.34;
}

.student-landscape-card.is-long .textbook-block h3 {
  font-size: 9pt;
}

.student-landscape-card.is-long .role-question,
.student-landscape-card.is-long .role-answer,
.student-landscape-card.is-long .role-bridge,
.student-landscape-card.is-long .role-principle,
.student-landscape-card.is-long .role-recap,
.student-landscape-card.is-long .role-formula,
.student-landscape-card.is-long .role-example,
.student-landscape-card.is-long .role-warning {
  padding: 1.25mm 1.45mm;
}

.student-landscape-card .block-content p {
  margin-bottom: 1.2mm;
}

.student-landscape-card .block-content ul {
  margin-bottom: 1.4mm;
  padding-left: 4mm;
}

.student-landscape-card .block-content li {
  margin-bottom: 0.5mm;
}

.student-landscape-card .block-eyebrow {
  margin-bottom: 1.3mm;
  padding: 0.45mm 1.5mm;
  font-size: 6.5pt;
}

.student-landscape-card .role-question,
.student-landscape-card .role-answer,
.student-landscape-card .role-bridge,
.student-landscape-card .role-principle,
.student-landscape-card .role-recap,
.student-landscape-card .role-formula,
.student-landscape-card .role-example,
.student-landscape-card .role-warning {
  padding: 1.55mm 1.8mm;
  border-radius: 7px;
}

.student-landscape-card .role-question {
  border-color: var(--rose-line);
  border-left-color: var(--flow-accent);
  background: #fff9fc;
}

.student-landscape-card .role-principle,
.student-landscape-card .role-recap {
  border-color: var(--flow-accent-line);
  border-left-color: var(--flow-accent);
  background: #fbfaff;
}

.student-landscape-card .role-answer,
.student-landscape-card .role-bridge {
  border-color: var(--card-line);
  background: #ffffff;
}

.student-landscape-card .role-formula {
  border-color: var(--formula-line);
  background: var(--formula-soft);
}

.student-landscape-card .block-chapter_title {
  margin: 0;
  padding: 4.5mm 4.8mm 5mm;
  border: 1px solid #ded8f6;
  border-left: 5px solid var(--flow-accent);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(143, 140, 247, 0.12), rgba(233, 165, 194, 0.08) 52%, rgba(255, 255, 255, 0.9)),
    #fffafd;
}

.student-landscape-card .block-chapter_title::before {
  content: "";
  display: block;
  width: 22mm;
  height: 1.4mm;
  margin-bottom: 4mm;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--flow-accent), var(--rose-accent));
}

.student-error {
  max-width: 720px;
  padding: 18px;
  border: 1px solid #fda29b;
  border-radius: 8px;
  background: #fff4f3;
  color: #b42318;
  white-space: pre-wrap;
}

@media (max-width: 760px) {
  .student-body {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .student-topbar {
    align-items: flex-start;
    min-height: 76px;
    padding: 10px 16px;
  }

  .student-topbar h1 {
    font-size: clamp(19px, 5.2vw, 24px);
  }

  .student-viewer-root {
    padding: 8px 10px 12px;
  }

  .student-card-reader {
    grid-template-columns: minmax(0, 1fr);
    max-width: none;
  }

  .student-nav-button {
    position: absolute;
    z-index: 2;
    top: 50%;
    width: 36px;
    height: 54px;
    background: rgba(255, 255, 255, 0.78);
    transform: translateY(-50%);
  }

  .student-prev-button {
    left: 4px;
  }

  .student-next-button {
    right: 4px;
  }

  .student-card {
    width: min(calc(100vw - 42px), calc(56.25svh - 74px));
    padding: 20px;
  }

  .student-card-progress {
    grid-template-columns: auto minmax(92px, 1fr);
    width: min(430px, calc(100vw - 42px));
  }

  .student-landscape-page {
    transform: scale(0.52);
    transform-origin: top center;
    margin-bottom: -96mm;
    width: 297mm;
    height: 210mm;
    aspect-ratio: auto;
  }
}

@page {
  size: A4 landscape;
  margin: 0;
}

@media print {
  body {
    background: #ffffff;
  }

  .student-topbar,
  .student-card-deck {
    display: none !important;
  }

  .student-viewer-root {
    display: block;
    padding: 0;
  }

  .student-landscape-stack {
    display: block;
  }

  .student-landscape-page {
    width: 297mm;
    height: 210mm;
    break-after: page;
    box-shadow: none;
  }
}
