html, body.viewer-page { min-height: 100%; }
body.viewer-page { overflow-x: hidden; background: #ecebea; }

.viewer-masthead {
  display: flex;
  min-height: 60px;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .65rem 1rem;
  border-bottom: 1px solid var(--rule);
  background: var(--bg);
}
.viewer-brand { color: var(--ink); font-family: var(--mono); font-size: .84rem; font-weight: 600; letter-spacing: .035em; text-decoration: none; }
.viewer-brand span { color: var(--muted); font-weight: 400; }
.viewer-masthead nav { display: flex; align-items: center; gap: .65rem; }
.viewer-masthead nav a { color: var(--ink-soft); font-family: var(--mono); font-size: .82rem; text-decoration: none; text-transform: lowercase; }
.viewer-masthead nav a:hover { color: var(--accent); }
.viewer-masthead .viewer-home-link {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  gap: .4rem;
  padding: .55rem .8rem;
  border: 2px solid var(--ink);
  border-radius: 3px;
  background: white;
  color: var(--ink);
  font-size: .92rem;
  font-weight: 600;
  text-transform: none;
}
.viewer-masthead .viewer-home-link:hover { border-color: var(--accent); background: var(--accent); color: white; }

.viewer-app { width: 100%; outline: 0; }
.lecture-heading {
  display: flex;
  max-width: 1500px;
  align-items: end;
  justify-content: space-between;
  gap: 2rem;
  margin: 0 auto;
  padding: 1.05rem 1rem .9rem;
}
.lecture-heading h1 { margin-top: .1rem; font-size: clamp(1.55rem, 3vw, 2.25rem); font-weight: 500; }
.document-actions { display: flex; gap: 1rem; white-space: nowrap; }

.viewer-loading,
.viewer-error {
  max-width: 700px;
  margin: 9vh auto;
  padding: 2rem;
  text-align: center;
}
.viewer-loading { display: flex; align-items: center; justify-content: center; gap: .8rem; color: var(--muted); font-family: var(--mono); font-size: .86rem; }
.loading-mark { width: 18px; height: 18px; border: 2px solid #c8cdd2; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(1turn); } }
.viewer-error { border: 1px solid #dababa; background: #fff8f7; }
.viewer-error h2 { font-size: 1.5rem; }

.presentation-shell {
  --toolbar-height: auto;
  display: flex;
  min-height: calc(100vh - 150px);
  flex-direction: column;
}

.toolbar {
  position: relative;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: .45rem;
  padding: .45rem max(.55rem, env(safe-area-inset-right)) .45rem max(.55rem, env(safe-area-inset-left));
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid #cfd2d5;
  background: color-mix(in srgb, var(--bg), white 20%);
  box-shadow: 0 1px 8px rgb(20 24 29 / 5%);
}

.toolbar-group { display: flex; min-height: 46px; align-items: center; gap: .2rem; padding: 0 .4rem; border-right: 1px solid var(--rule); }
.toolbar-group:last-child { border-right: 0; }
.toolbar button,
.toolbar select,
.toolbar-home,
.more-menu summary {
  min-width: 46px;
  min-height: 46px;
  padding: .48rem .62rem;
  border: 1px solid transparent;
  border-radius: 2px;
  background: transparent;
  color: var(--ink);
  font-family: var(--mono);
  font-size: .76rem;
  line-height: 1;
}
.toolbar-home {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  border-color: var(--ink);
  background: white;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.toolbar button:hover,
.toolbar select:hover,
.toolbar-home:hover,
.more-menu summary:hover { border-color: #ccd1d6; background: white; }
.toolbar-home:hover { border-color: var(--accent); background: var(--accent); color: white; }
.toolbar button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent); color: white; }
.toolbar .page-indicator { min-width: 76px; color: var(--muted); }
.toolbar select { max-width: 108px; appearance: auto; }
.toolbar kbd { margin-left: .25rem; font-size: .68rem; }

.laser-icon { display: inline-block; width: 10px; height: 10px; border: 2px solid currentColor; border-radius: 50%; vertical-align: -.08em; }

.ink-options[hidden] { display: none; }
.color-options { display: flex; gap: .2rem; margin: 0; padding: 0; border: 0; }
.color-choice { display: grid; width: 44px; height: 46px; place-items: center; }
.color-choice::after { width: 21px; height: 21px; border: 2px solid white; border-radius: 50%; background: var(--swatch); box-shadow: 0 0 0 1px #b7bdc3; content: ""; }
.color-choice:has(input:checked)::after { box-shadow: 0 0 0 2px var(--accent); }
.color-choice input { position: absolute; opacity: 0; pointer-events: none; }
.color-navy { --swatch: #153d63; }
.color-maroon { --swatch: #861f41; }
.color-red { --swatch: #c43b32; }
.color-green { --swatch: #2f6b4f; }
.color-black { --swatch: #14181d; }
.width-label { color: var(--muted); font-family: var(--mono); font-size: .72rem; }

.more-menu { position: relative; }
.more-menu summary { display: grid; place-items: center; list-style: none; }
.more-menu summary::-webkit-details-marker { display: none; }
.more-menu-panel {
  position: absolute;
  z-index: 30;
  top: calc(100% + .5rem);
  right: 0;
  display: grid;
  min-width: 250px;
  padding: .45rem;
  border: 1px solid #cfd3d7;
  background: var(--bg);
  box-shadow: 0 12px 30px rgb(20 24 29 / 16%);
}
.more-menu-panel button { width: 100%; justify-content: start; text-align: left; }
.more-menu-panel .danger-action { color: var(--danger); }

.progress-track { height: 3px; background: #d8d9da; }
#progress-fill { display: block; width: 0; height: 100%; background: var(--course-accent); transition: width .18s ease; }

.stage-container {
  position: relative;
  display: flex;
  min-height: 320px;
  height: max(320px, calc(100dvh - 270px));
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: clamp(.55rem, 2vw, 1.5rem) clamp(2.7rem, 5vw, 4.5rem);
  background:
    radial-gradient(circle at 25% 15%, rgb(255 255 255 / 35%), transparent 34%),
    #dededd;
  overscroll-behavior: contain;
}

.page-stage {
  position: relative;
  flex: 0 0 auto;
  overflow: hidden;
  border: 1px solid #c7c8c9;
  background: white;
  box-shadow: 0 14px 38px rgb(20 24 29 / 18%);
  user-select: text;
}
.page-stage.is-drawing { cursor: crosshair; touch-action: none; user-select: none; }
.page-stage.is-erasing { cursor: cell; touch-action: none; user-select: none; }
.page-stage.is-laser { cursor: none; }
.page-stage.is-whiteboard { background: #fff; }

#pdf-canvas,
#annotation-canvas,
.text-layer { position: absolute; inset: 0; width: 100%; height: 100%; }
#pdf-canvas { z-index: 1; display: block; }
.text-layer {
  --min-font-size: 1;
  --text-scale-factor: calc(var(--total-scale-factor) * var(--min-font-size));
  --min-font-size-inv: calc(1 / var(--min-font-size));
  z-index: 2;
  overflow: clip;
  color-scheme: only light;
  caret-color: CanvasText;
  line-height: 1;
  letter-spacing: normal;
  word-spacing: normal;
  opacity: 1;
  text-align: initial;
  text-size-adjust: none;
  transform-origin: 0 0;
  forced-color-adjust: none;
  user-select: text;
}
.text-layer span,
.text-layer br {
  position: absolute;
  color: transparent;
  white-space: pre;
  cursor: text;
  transform-origin: 0 0;
  user-select: text;
}
.text-layer > :not(.markedContent),
.text-layer .markedContent span:not(.markedContent) {
  --font-height: 0;
  --scale-x: 1;
  --rotate: 0deg;
  z-index: 1;
  font-size: calc(var(--text-scale-factor) * var(--font-height));
  transform: rotate(var(--rotate)) scaleX(var(--scale-x)) scale(var(--min-font-size-inv));
}
.text-layer .markedContent { display: contents; }
.text-layer span[role="img"] { cursor: default; user-select: none; }
.text-layer ::selection { background: color-mix(in srgb, AccentColor, transparent 50%); color: transparent; }
.text-layer br::selection { background: transparent; }
.text-layer .end-of-content {
  position: absolute;
  z-index: 0;
  display: block;
  inset: 100% 0 0;
  cursor: default;
  user-select: none;
}
.text-layer.selecting .end-of-content { top: 0; }
.text-layer[hidden] { display: none; }
#annotation-canvas { z-index: 4; pointer-events: none; }
.page-stage.is-drawing #annotation-canvas,
.page-stage.is-erasing #annotation-canvas { pointer-events: auto; }
.laser-pointer { position: absolute; z-index: 8; display: none; width: 18px; height: 18px; transform: translate(-50%, -50%); border: 3px solid rgb(255 255 255 / 90%); border-radius: 50%; background: #e3282f; box-shadow: 0 0 9px 4px rgb(227 40 47 / 48%); pointer-events: none; }
.page-stage.is-laser .laser-pointer { display: block; }
.whiteboard-label { position: absolute; z-index: 3; top: 1rem; left: 1rem; color: #737b83; font-family: var(--mono); font-size: .8rem; pointer-events: none; }

.stage-arrow {
  position: absolute;
  z-index: 10;
  top: 50%;
  width: 52px;
  height: 78px;
  transform: translateY(-50%);
  border: 1px solid rgb(20 24 29 / 12%);
  border-radius: 2px;
  background: rgb(253 252 249 / 86%);
  color: var(--ink);
  font-size: 2rem;
  line-height: 1;
}
.stage-arrow:hover { background: white; }
.stage-arrow-previous { left: .5rem; }
.stage-arrow-next { right: .5rem; }

.viewer-instructions { margin: 0; padding: .55rem 1rem max(.55rem, env(safe-area-inset-bottom)); background: var(--bg); color: #5e6872; font-family: var(--mono); font-size: .72rem; text-align: center; }

.viewer-dialog {
  width: min(920px, calc(100vw - 2rem));
  max-height: min(82vh, 760px);
  padding: 0;
  border: 1px solid #bec3c8;
  border-radius: 2px;
  background: var(--bg);
  color: var(--ink);
  box-shadow: 0 30px 80px rgb(20 24 29 / 25%);
}
.viewer-dialog::backdrop { background: rgb(20 24 29 / 62%); backdrop-filter: blur(2px); }
.dialog-heading { position: sticky; z-index: 2; top: 0; display: flex; align-items: center; justify-content: space-between; padding: 1.1rem 1.2rem; border-bottom: 1px solid var(--rule); background: var(--bg); }
.dialog-heading h2 { margin-top: .08rem; font-size: 1.6rem; }
.dialog-heading button { width: 44px; height: 44px; border: 1px solid var(--rule); background: transparent; color: var(--ink); font-size: 1.45rem; }

.thumbnail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(145px, 1fr)); gap: 1rem; padding: 1rem; }
.thumbnail-button { min-height: 145px; padding: .65rem; border: 1px solid var(--rule); background: var(--bg-soft); color: var(--ink); font-family: var(--mono); font-size: .76rem; }
.thumbnail-button:hover, .thumbnail-button[aria-current="page"] { border-color: var(--accent); background: white; }
.thumbnail-button canvas { display: block; max-width: 100%; height: auto; margin: 0 auto .45rem; box-shadow: 0 2px 8px rgb(20 24 29 / 12%); }

.help-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 0; padding: 1rem 1.2rem 1.5rem; }
.help-grid div { display: grid; grid-template-columns: minmax(130px, 1fr) 1fr; gap: .7rem; padding: .7rem 0; border-bottom: 1px solid var(--rule); }
.help-grid div:nth-child(odd) { padding-right: 1rem; }
.help-grid div:nth-child(even) { padding-left: 1rem; border-left: 1px solid var(--rule); }
.help-grid dd { margin: 0; color: var(--muted); font-size: .98rem; }

.checkpoint-dialog { width: min(640px, calc(100vw - 2rem)); }
#checkpoint-form { padding: 1.3rem; }
.checkpoint-question { margin: 0 0 1.2rem; color: var(--ink); font-size: 1.4rem; }
#checkpoint-choices { display: grid; gap: .55rem; margin: 0 0 1.2rem; padding: 0; border: 0; }
.checkpoint-choice { display: flex; min-height: 52px; align-items: center; gap: .7rem; padding: .7rem .85rem; border: 1px solid var(--rule); background: white; }
.checkpoint-feedback { min-height: 1.6em; margin-bottom: 0; font-weight: 600; }
.checkpoint-feedback.is-correct { color: #245c43; }
.checkpoint-feedback.is-incorrect { color: var(--danger); }

.exploration-button:not([hidden]) { border-color: var(--accent); color: var(--accent); }
.exploration-button .control-label { display: inline !important; }
.exploration-dialog { width: min(760px, calc(100vw - 2rem)); max-height: min(86vh, 900px); overflow: auto; }
.exploration-content { padding: 1.25rem; }
.exploration-intro { margin: 0 0 1rem; color: var(--ink-soft); font-size: 1.08rem; }
.exploration-items { display: grid; gap: .75rem; }
.exploration-card { border: 1px solid var(--rule); background: white; }
.exploration-card summary { display: grid; min-height: 58px; cursor: pointer; gap: .2rem; padding: .85rem 2.5rem .85rem 1rem; list-style-position: outside; }
.exploration-card summary:hover { background: var(--bg-soft); }
.exploration-card-title { color: var(--ink); font-size: 1.12rem; font-weight: 750; }
.exploration-card-summary { color: var(--muted); line-height: 1.4; }
.exploration-details { display: grid; gap: .85rem; margin: 0; padding: .15rem 1rem 1rem; border-top: 1px solid var(--rule); }
.exploration-details div { padding-top: .8rem; }
.exploration-details dt { margin: 0 0 .35rem; color: var(--course-accent); font-weight: 750; }
.exploration-details dd { margin: 0; color: var(--ink-soft); line-height: 1.5; }

.handout-view { min-height: calc(100vh - 54px); padding: 1rem; background: var(--bg-soft); }
.handout-toolbar { position: sticky; z-index: 20; top: .5rem; display: flex; max-width: 1100px; align-items: center; justify-content: space-between; gap: 1rem; margin: 0 auto 1rem; padding: .85rem 1rem; border: 1px solid var(--rule); background: rgb(253 252 249 / 95%); box-shadow: 0 7px 20px rgb(20 24 29 / 8%); }
.handout-toolbar h2 { margin-top: .08rem; font-size: 1.45rem; }
.handout-toolbar > div:last-child { display: flex; gap: .6rem; }
#handout-status { max-width: 1000px; margin: .7rem auto; color: var(--muted); font-family: var(--mono); font-size: .8rem; }
.handout-pages { display: grid; max-width: 1000px; gap: 1.5rem; margin: 0 auto; }
.handout-page { position: relative; overflow: hidden; border: 1px solid #ccd0d4; background: white; box-shadow: 0 8px 24px rgb(20 24 29 / 10%); }
.handout-page > canvas { display: block; width: 100%; height: auto; }
.handout-page-label { position: absolute; right: .5rem; bottom: .35rem; padding: .18rem .4rem; background: rgb(255 255 255 / 88%); color: var(--muted); font-family: var(--mono); font-size: .68rem; }

.plugin-panel { max-width: 1100px; margin: 1rem auto; padding: 1rem; border: 1px solid var(--rule); background: var(--bg); }

.file-loader { max-width: 760px; margin: 0 auto; padding: clamp(3rem, 8vw, 6.5rem) 1rem 2.5rem; }
.file-loader h1 { margin: .15rem 0 .8rem; font-size: clamp(2.35rem, 7vw, 4.8rem); }
.file-loader > p { max-width: 660px; }
.drop-zone { display: grid; min-height: 180px; place-items: center; align-content: center; gap: .35rem; margin: 2rem 0 1rem; padding: 1.5rem; border: 1.5px dashed #aeb5bc; background: var(--bg-soft); color: var(--muted); text-align: center; }
.drop-zone:hover, .drop-zone.is-dragging { border-color: var(--accent); background: white; }
.drop-title { color: var(--ink); font-size: 1.3rem; }
.drop-zone input { max-width: 100%; margin-top: .8rem; font-family: var(--mono); font-size: .8rem; }
.persist-choice { display: flex; align-items: start; gap: .55rem; color: var(--ink-soft); font-size: 1rem; }
.persist-choice input { width: 22px; height: 22px; margin-top: .22rem; }

@media (max-width: 1060px) {
  .control-label { display: none; }
  .toolbar { justify-content: flex-start; overflow: visible; }
  .toolbar-group { flex: 0 0 auto; }
  .view-group { margin-left: auto; }
}

@media (max-width: 760px) {
  .viewer-masthead { min-height: 54px; }
  .viewer-brand span { display: none; }
  .viewer-masthead nav a:last-child { display: none; }
  .lecture-heading { align-items: start; flex-direction: column; gap: .55rem; }
  .document-actions { width: 100%; }
  .presentation-shell { min-height: calc(100dvh - 133px); }
  .toolbar { max-height: 142px; padding-bottom: .4rem; overflow-x: auto; justify-content: flex-start; flex-wrap: nowrap; }
  .toolbar button, .toolbar select, .toolbar-home, .more-menu summary { min-width: 48px; min-height: 48px; }
  .toolbar-group { border-right: 1px solid var(--rule); }
  .zoom-group { display: none; }
  .ink-options { position: fixed; z-index: 50; right: .5rem; bottom: max(.5rem, env(safe-area-inset-bottom)); left: .5rem; justify-content: center; padding: .45rem; border: 1px solid #bcc2c7; background: rgb(253 252 249 / 97%); box-shadow: 0 10px 30px rgb(20 24 29 / 20%); }
  .stage-container { min-height: 300px; height: max(300px, calc(100dvh - 250px)); padding: .45rem 2.8rem; }
  .stage-arrow { width: 44px; height: 64px; }
  .stage-arrow-previous { left: .25rem; }
  .stage-arrow-next { right: .25rem; }
  .help-grid { grid-template-columns: 1fr; }
  .help-grid div:nth-child(n) { padding-right: 0; padding-left: 0; border-left: 0; }
  .handout-toolbar { align-items: stretch; flex-direction: column; }
  .handout-toolbar > div:last-child { flex-wrap: wrap; }
}

@media (max-width: 480px) {
  .lecture-heading { padding-block: .7rem; }
  .lecture-heading h1 { font-size: 1.4rem; }
  .toolbar { padding-inline: .25rem; }
  .toolbar-group { padding-inline: .2rem; }
  .navigation-group .page-indicator { min-width: 58px; }
  .viewer-instructions { display: none; }
  .thumbnail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .55rem; padding: .55rem; }
}

@media (display-mode: fullscreen) {
  .viewer-masthead, .lecture-heading { display: none; }
  .presentation-shell { min-height: 100dvh; }
  .stage-container { min-height: 0; height: calc(100dvh - 108px); }
}

:fullscreen .viewer-masthead,
:fullscreen .lecture-heading { display: none; }
:fullscreen .presentation-shell { min-height: 100vh; }
:fullscreen .stage-container { min-height: 0; height: calc(100dvh - 108px); }
