/* ---------- self-hosted fonts ---------- */
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/static/fonts/inter-400.woff2") format("woff2");
}

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/static/fonts/inter-600.woff2") format("woff2");
}

@font-face {
  font-family: "Source Serif 4";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/static/fonts/source-serif-4-600.woff2") format("woff2");
}

@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/static/fonts/ibm-plex-mono-400.woff2") format("woff2");
}

@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/static/fonts/ibm-plex-mono-500.woff2") format("woff2");
}

:root {
  color-scheme: light dark;

  /* domain-coloring palette: accents drawn from the arg(z) wheel */
  --ink-950: #0a0d14;
  --ink-100: #edeff4;
  --arg-0: light-dark(#b5761e, #e8a33d);   /* amber, arg=0° */
  --arg-90: light-dark(#1e7f72, #3fb9a8);  /* teal, arg=90° */
  --arg-180: light-dark(#9c3e6e, #c1548c); /* rose, arg=180° */
  --arg-270: light-dark(#3f5fb0, #6c8fe0); /* periwinkle, arg=270° */

  --bg: light-dark(var(--ink-100), var(--ink-950));
  --fg: light-dark(var(--ink-950), var(--ink-100));

  --pill-lecture: var(--arg-0);
  --pill-worksheet: var(--arg-180);
  --pill-visualization: var(--arg-90);
  --link: var(--arg-270);

  --status-ok: light-dark(#15803d, #16a34a);
  --status-warn: light-dark(#b45309, #d97706);
  --status-bad: light-dark(#b91c1c, #dc2626);
  --badge-type-neutral: light-dark(#334155, #475569);

  --canvas-stroke-z: var(--arg-270);
  --canvas-stroke-w: var(--arg-0);

  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Source Serif 4", Georgia, "Times New Roman", serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, monospace;
  --font-symbol: "Cambria Math", "Segoe UI Symbol", var(--font-mono);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--fg);
}

header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid color-mix(in srgb, var(--fg) 15%, transparent);
}

.user-switcher-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.4rem 1.25rem;
  font-size: 0.85rem;
  background: color-mix(in srgb, var(--fg) 4%, transparent);
  border-bottom: 1px solid color-mix(in srgb, var(--fg) 10%, transparent);
}

.user-switcher-form select {
  border-radius: 6px;
  border: 1px solid color-mix(in srgb, var(--fg) 20%, transparent);
  background: var(--bg);
  color: inherit;
  font-size: 0.85rem;
  padding: 0.2rem 0.4rem;
}

header h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.25rem;
}

.eyebrow {
  margin: 0 0 0.2rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.65;
}

.eyebrow .symbol {
  font-family: var(--font-symbol);
  letter-spacing: 0;
}

.header-top {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

#home-motif {
  width: 2.75rem;
  height: 2.75rem;
  flex-shrink: 0;
}

.back-link {
  color: var(--link);
  text-decoration: none;
  font-size: 0.85rem;
}

.back-link:hover {
  text-decoration: underline;
}

main {
  padding: 0.75rem 1.25rem 2rem;
  max-width: 720px;
  margin: 0 auto;
}

body.page-info main {
  max-width: 1080px;
}

.empty {
  opacity: 0.7;
}

.form-errors {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;
  border: 1px solid color-mix(in srgb, var(--status-bad) 40%, transparent);
  border-radius: 8px;
  background: color-mix(in srgb, var(--status-bad) 10%, transparent);
  color: var(--status-bad);
  font-size: 0.9rem;
}

.form-errors li + li {
  margin-top: 0.25rem;
}

.btn-secondary,
#fn-select,
.mapping-toolbar button {
  min-height: 2.15rem;
  border-radius: 6px;
  border: 1px solid color-mix(in srgb, var(--fg) 20%, transparent);
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 0.9rem;
  padding: 0.25rem 0.6rem;
  cursor: pointer;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}

body.page-home {
  background-image:
    linear-gradient(color-mix(in srgb, var(--fg) 5%, transparent) 1px, transparent 1px),
    linear-gradient(90deg, color-mix(in srgb, var(--fg) 5%, transparent) 1px, transparent 1px);
  background-size: 32px 32px;
}

.week-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.week-row {
  padding: 0.85rem 0;
  border-bottom: 1px solid color-mix(in srgb, var(--fg) 10%, transparent);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}

.week-number {
  font-family: var(--font-mono);
  font-weight: 600;
  min-width: 5.5rem;
}

.week-items {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.pill {
  display: inline-block;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  color: white;
  text-decoration: none;
  font-size: 0.85rem;
}

.pill-lecture { background: var(--pill-lecture); }
.pill-worksheet { background: var(--pill-worksheet); }
.pill-visualization { background: var(--pill-visualization); }
.pill-danger { background: var(--status-bad); }

.delete-course-form { display: contents; }
.delete-course-form .pill { border: none; cursor: pointer; font: inherit; }

.viewer-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 2;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-width: 0;
}

.home-link {
  color: inherit;
  text-decoration: none;
  font-size: 1.75rem;
  line-height: 1;
}

.viewer-title {
  font-size: 0.95rem;
  opacity: 0.85;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lecture-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  justify-self: center;
}

.viewer-toolbar {
  position: sticky;
  top: 3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 0.5rem;
  background: var(--bg);
  border-bottom: 1px solid color-mix(in srgb, var(--fg) 10%, transparent);
  z-index: 2;
}

.viewer-toolbar button,
.lecture-nav-link {
  min-width: 2.25rem;
  min-height: 2.25rem;
  border-radius: 6px;
  border: 1px solid color-mix(in srgb, var(--fg) 20%, transparent);
  background: transparent;
  color: inherit;
  font-size: 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.viewer-toolbar button svg,
.lecture-nav-link svg {
  width: 1.1rem;
  height: 1.1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.lecture-nav-link-text {
  min-width: 0;
  min-height: 0;
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
  white-space: nowrap;
}

.visualization-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.65rem;
  border-radius: 999px;
  font-size: 0.75rem;
  color: white;
  background: var(--pill-visualization);
  text-decoration: none;
  white-space: nowrap;
}

.visualization-badge:hover {
  filter: brightness(0.88);
}

#viewer-container {
  display: flex;
  justify-content: center;
  padding: 0.5rem;
  overflow: auto;
}

body.presenting .viewer-header,
body.presenting .viewer-toolbar {
  display: none;
}

body.presenting #viewer-container {
  position: fixed;
  inset: 0;
  align-items: center;
  padding: 0;
  background: var(--ink-950);
  z-index: 10;
}

#page-wrapper {
  position: relative;
  max-width: 100%;
}

#pdf-canvas {
  display: block;
  max-width: 100%;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

.textLayer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  line-height: 1;
  text-size-adjust: none;
  forced-color-adjust: none;
  transform-origin: 0 0;
  caret-color: CanvasText;
  z-index: 1;
}

.textLayer span,
.textLayer br {
  color: transparent;
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0% 0%;
}

.textLayer span.markedContent {
  top: 0;
  height: 0;
}

.textLayer ::selection {
  background: color-mix(in srgb, Highlight 40%, transparent);
}

.textLayer br::selection {
  background: transparent;
}

.qb-layout {
  display: flex;
  align-items: flex-start;
  max-width: 1080px;
  margin: 0 auto;
}

.qb-sidebar {
  flex: 0 0 220px;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  position: sticky;
  top: 0;
  max-height: 100vh;
  overflow-y: auto;
  padding: 1rem 0.75rem 2rem;
  border-right: 1px solid color-mix(in srgb, var(--fg) 10%, transparent);
}

.qb-nav-topic,
.qb-nav-subtopic {
  color: inherit;
  text-decoration: none;
  padding: 0.3rem 0.5rem;
  border-radius: 6px;
  font-size: 0.9rem;
}

.qb-nav-topic {
  font-weight: 600;
  margin-top: 0.5rem;
}

.qb-nav-subtopic {
  margin-left: 0.75rem;
  opacity: 0.8;
  font-size: 0.82rem;
}

.qb-nav-topic.active,
.qb-nav-subtopic.active {
  background: color-mix(in srgb, var(--fg) 10%, transparent);
}

.qb-content {
  flex: 1 1 auto;
  min-width: 0;
  padding: 1rem 1.25rem 2rem;
}

[data-qb-section] {
  display: none;
}

[data-qb-section].active {
  display: block;
}

@media (max-width: 700px) {
  .qb-layout {
    flex-direction: column;
  }

  .qb-sidebar {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    position: static;
    max-height: none;
    width: 100%;
    border-right: none;
    border-bottom: 1px solid color-mix(in srgb, var(--fg) 10%, transparent);
    gap: 0.35rem;
  }

  .qb-nav-topic {
    margin-top: 0;
    white-space: nowrap;
  }

  .qb-nav-subtopic {
    display: none;
  }
}

.topic-block {
  margin-bottom: 2rem;
}

.topic-block h2 {
  font-family: var(--font-display);
}

.topic-week {
  font-weight: 400;
  opacity: 0.7;
}

.topic-description,
.topic-sources {
  opacity: 0.85;
  font-size: 0.9rem;
}

.subtopic-heading {
  margin-top: 1.25rem;
  font-family: var(--font-mono);
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  opacity: 0.7;
}

.question-card {
  border: 1px solid color-mix(in srgb, var(--fg) 12%, transparent);
  border-radius: 8px;
  padding: 0.85rem 1rem;
  margin: 0.6rem 0;
}

.question-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.question-id {
  font-weight: 600;
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  color: white;
}

.badge-difficulty-easy { background: var(--status-ok); }
.badge-difficulty-medium { background: var(--status-warn); }
.badge-difficulty-hard { background: var(--status-bad); }
.badge-type { background: var(--badge-type-neutral); }

.question-prompt {
  margin-bottom: 0.5rem;
}

.question-answer summary {
  cursor: pointer;
  font-size: 0.85rem;
  opacity: 0.85;
}

.answer-body {
  margin-top: 0.4rem;
  padding: 0.5rem 0.75rem;
  background: color-mix(in srgb, var(--fg) 6%, transparent);
  border-radius: 6px;
}

.question-sources {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
  opacity: 0.7;
}

.mapping-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid color-mix(in srgb, var(--fg) 10%, transparent);
}

.mapping-fn-label {
  font-weight: 600;
}

.mapping-mode-toggle {
  display: flex;
  gap: 0.35rem;
}

.mode-btn.active {
  background: color-mix(in srgb, var(--fg) 12%, transparent);
  font-weight: 600;
}

.mapping-toolbar button.hidden {
  display: none;
}

.mapping-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1.5rem 1.25rem 0.5rem;
}

.mapping-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}

.mapping-panel canvas {
  width: min(38vw, 380px);
  height: min(38vw, 380px);
  border: 1px solid color-mix(in srgb, var(--fg) 15%, transparent);
  border-radius: 8px;
  touch-action: none;
  background: color-mix(in srgb, var(--fg) 2%, transparent);
}

#z-canvas { color: var(--canvas-stroke-z); }
#w-canvas { color: var(--canvas-stroke-w); }

.mapping-caption {
  font-size: 0.9rem;
  opacity: 0.75;
}

.mapping-arrow {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 4.5rem;
  gap: 0.15rem;
}

.mapping-arrow-label {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1.3rem;
  font-weight: 600;
}

.mapping-arrow-shaft {
  width: 100%;
  height: 3px;
  background: color-mix(in srgb, var(--fg) 55%, transparent);
  position: relative;
}

.mapping-arrow-shaft::after {
  content: "";
  position: absolute;
  right: -1px;
  top: 50%;
  transform: translateY(-50%);
  border-style: solid;
  border-width: 6px 0 6px 9px;
  border-color: transparent transparent transparent color-mix(in srgb, var(--fg) 55%, transparent);
}

.mapping-arrow-sub {
  font-size: 0.75rem;
  font-style: italic;
  opacity: 0.65;
}

.limit-slider-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.9rem;
  white-space: nowrap;
}

.limit-slider {
  width: 7rem;
}

#epsilon-value,
#delta-value {
  font-family: var(--font-mono);
}

.limit-status {
  text-align: center;
  max-width: 640px;
  margin: 0.75rem auto 0;
  padding: 0.5rem 1.25rem;
  font-size: 0.9rem;
  font-weight: 600;
  min-height: 1.2em;
}

.limit-status.status-ok { color: var(--status-ok); }
.limit-status.status-bad { color: var(--status-bad); }
.limit-status.status-warn { color: var(--status-warn); }

.mapping-hint {
  text-align: center;
  max-width: 640px;
  margin: 0.75rem auto 1.5rem;
  padding: 0 1.25rem;
  font-size: 0.9rem;
  opacity: 0.8;
}

@media (max-width: 700px) {
  .mapping-stage {
    flex-direction: column;
  }

  .mapping-arrow {
    flex-direction: row;
    min-width: 0;
    width: min(38vw, 380px);
  }

  .mapping-arrow-shaft {
    height: 3px;
  }

  .mapping-panel canvas {
    width: min(78vw, 380px);
    height: min(78vw, 380px);
  }
}
