/* ==========================================================================
   Interactive Lectures Portal - Production Workspace Design System
   Approved Design: The Handbook (ADR-0018)
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Shared Application Identity & Authoritative Tokens
   -------------------------------------------------------------------------- */
:root,
body.portal-shell {
  --paper: #f7f8f6;
  --surface: #ffffff;
  --ink: #22262b;
  --slate: #5b6770;
  --hair: #d7d9d6;
  --tint: #e9ebee;
  --ghost: #fafbfa;
  --chip: #f0f2f0;
  --ghost-text: #5f6870;
  --orange: #d9481f;
  --orange-press: #c13e19;
  --accent: #d9481f;
  --accent-hover: #c13e19;
  --accent-light: #fef1ed;
  --canvas: var(--paper);
  --surface: #ffffff;
  --ink: #22262b;
  --muted: #5b6770;
  --line: var(--hair);
  --border: var(--line);
  --bg: var(--canvas);
  --text: var(--ink);
  --focus: #e3ab43;
  --success: #1a7a40;
  --success-bg: #f0fdf4;
  --success-line: #86efac;
  --success-ink: #0f4023;
  --warning: #b45309;
  --warning-bg: #fef9c3;
  --warning-line: #fde047;
  --error: #c92a2a;
  --error-bg: #fff5f5;
  --error-line: #fca5a5;
  --error-ink: #7f1d1d;
  --font-stack: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-body: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-num: "Barlow Condensed", sans-serif-condensed, sans-serif;
  --font-mono: "IBM Plex Mono", Consolas, monospace;
  --mono-stack: "IBM Plex Mono", Consolas, monospace;
  --radius-sm: 0px;
  --radius-md: 0px;
  --radius-lg: 0px;
  --radius: 0px;
}

body {
  font-family: var(--font-body);
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

/* Base form controls inherit typography */
.btn,
button,
input,
select,
textarea {
  font-family: inherit;
  border-radius: 0;
}

/* Primary actions using authoritative signal orange */
.btn.btn-primary {
  background: var(--orange-press);
  border-color: var(--orange-press);
  color: #ffffff;
  border-radius: 0;
  box-shadow: none;
}

.btn.btn-primary:hover {
  background: var(--orange-press);
  border-color: var(--orange-press);
}

/* --------------------------------------------------------------------------
   2. Global Shell & Navigation
   -------------------------------------------------------------------------- */
.portal-shell {
  --muted: #5b6770;
  background: var(--paper);
  color: var(--ink);
}

.portal-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 clamp(1rem, 3.5vw, 2rem);
  min-height: 64px;
  background: var(--surface);
  border-bottom: 1px solid var(--hair);
  box-shadow: none;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--ink);
  text-decoration: none;
  min-height: 44px;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  border-radius: 0;
  box-shadow: none;
}

.brand-mark-sm {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  border-radius: 0;
  box-shadow: none;
}

.brand-badge {
  background: var(--tint);
  color: var(--slate);
  border: 1px solid var(--hair);
  border-radius: 0;
  padding: 2px 8px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.portal-nav {
  margin-right: auto;
  display: flex;
  align-items: center;
  gap: 4px;
}

.portal-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 7px 12px;
  color: var(--slate);
  font-weight: 500;
  font-size: 12.5px;
  text-decoration: none;
  border-radius: 0;
  border: 1px solid transparent;
  transition: all 0.16s ease;
}

.portal-nav a:hover {
  background: var(--paper);
  color: var(--ink);
}

.portal-nav a[aria-current="page"] {
  background: var(--paper);
  color: var(--ink);
  border-color: var(--hair);
  font-weight: 600;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.85rem;
  color: var(--ink);
}

.header-user .user-badge {
  font-size: 0.85rem;
  color: var(--muted);
}

.header-user .user-badge strong {
  color: var(--ink);
}

.main-content {
  width: 100%;
  max-width: 1240px;
  padding: clamp(1.25rem, 3.5vw, 2.5rem);
  margin-inline: auto;
}

.portal-shell .main-content {
  padding-top: 2rem;
  padding-bottom: 4rem;
}

.portal-shell h1 {
  letter-spacing: -0.04em;
  line-height: 1.2;
}

.portal-shell .card,
.portal-shell .course-card {
  border-color: var(--hair);
  box-shadow: none;
}

.portal-shell .d-resume-card,
.portal-shell .d-login-card { border-color: var(--ink); }

.portal-shell .btn {
  min-height: 44px;
  border-radius: 0;
  font-weight: 600;
  box-shadow: none;
  transition: background 0.16s, border-color 0.16s;
}

.portal-shell .btn-primary {
  box-shadow: none;
}

.portal-shell .btn-primary:hover {
  box-shadow: none;
}

.portal-shell .form-control {
  min-height: 44px;
  border-radius: 0;
  border: 1px solid var(--hair);
  background: var(--paper);
  font-size: 0.95rem;
  box-shadow: none;
  transition: border-color 0.16s;
}

.portal-shell .form-control:focus {
  border-color: var(--ink);
  outline: 2px solid var(--focus) !important;
  outline-offset: 2px !important;
  box-shadow: none;
}

.eyebrow {
  display: block;
  font-size: 0.68rem;
  font-weight: 750;
  letter-spacing: 0.17em;
  color: var(--accent);
  text-transform: uppercase;
}

/* --------------------------------------------------------------------------
   3. Sign-In Screen (Split Studio Entry)
   -------------------------------------------------------------------------- */
.login-container {
  padding-block: 0;
}

.studio-entry.login-container {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  min-height: 680px;
  padding: 0;
  border: 1px solid #e1e3ee;
  border-radius: 24px;
  overflow: hidden;
  background: #ffffff;
  box-shadow: 0 20px 65px rgba(37, 34, 62, 0.08);
}

.entry-story {
  align-self: stretch;
  padding: clamp(2rem, 4vw, 3.8rem);
  background: radial-gradient(ellipse at top right, #2a254d 0%, #1e1b38 100%);
  color: #ffffff;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.entry-story h2 {
  font-size: clamp(2rem, 3.3vw, 3.15rem);
  line-height: 1.16;
  font-weight: 650;
  letter-spacing: -0.04em;
  margin: 0 0 1.2rem;
}

.entry-story h2 span {
  color: #bfb7ff;
}

.entry-story p {
  font-size: 0.95rem;
  color: #d2cfe4;
  max-width: 36ch;
  line-height: 1.65;
}

.entry-diagram {
  position: relative;
  height: 235px;
  max-width: 360px;
  margin: 2rem auto;
}

.diagram-orbit {
  position: absolute;
  inset: 22px 25px;
  border: 1px dashed rgba(169, 158, 231, 0.4);
  border-radius: 50%;
  transform: rotate(-28deg);
}

.orbit-two {
  inset: 45px 5px;
  border-style: solid;
  border-color: rgba(125, 117, 173, 0.3);
  transform: rotate(32deg);
}

.diagram-core {
  position: absolute;
  top: 75px;
  left: calc(50% - 42px);
  width: 84px;
  height: 84px;
  display: grid;
  place-items: center;
  border: 1px solid #a99ee7;
  border-radius: 24px;
  background: radial-gradient(circle at center, #483f73 0%, #2f294d 100%);
  color: #ffffff;
  font: italic 2rem Georgia, serif;
  box-shadow: 0 0 65px rgba(184, 164, 255, 0.25);
}

.diagram-node {
  position: absolute;
  border: 1px solid rgba(125, 117, 173, 0.45);
  border-radius: 20px;
  padding: 0.35rem 0.85rem;
  background: rgba(48, 42, 74, 0.85);
  color: #ded8f4;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  backdrop-filter: blur(4px);
}

.node-one { top: 25px; left: 0; }
.node-two { right: 0; top: 93px; }
.node-three { bottom: 5px; left: 30px; }

.entry-caption {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: space-between;
  color: #bcb6d8;
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.entry-form {
  padding: clamp(1.5rem, 4vw, 3.5rem);
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.entry-form .login-card {
  border: 0;
  box-shadow: none;
  padding: 0;
  margin: 0;
  max-width: none;
  width: 100%;
}

.entry-form .login-card h1 {
  font-size: 2rem;
  letter-spacing: -0.03em;
  margin-bottom: 0.5rem;
}

.entry-footnote {
  text-align: center;
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line);
  font-size: 0.78rem;
  color: var(--muted);
}

/* --------------------------------------------------------------------------
   4. Student Dashboard & Course Roadmap
   -------------------------------------------------------------------------- */
.learning-welcome {
  position: relative;
  padding: clamp(1.25rem, 3.5vw, 2.5rem);
  border: 1px solid var(--hair);
  border-radius: 0;
  background: var(--paper);
  margin-bottom: 2rem;
  overflow-wrap: anywhere;
}

.learning-welcome h1 {
  font-size: clamp(1.75rem, 3vw, 2.6rem);
  margin: 0.5rem 0;
  letter-spacing: -0.04em;
  line-height: 1.2;
}

.learning-welcome .admin-meta {
  margin-bottom: 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.learning-home {
  margin-block: 1.5rem 2rem;
}

.learning-section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.2rem;
}

.learning-section-heading .section-title {
  margin: 0.2rem 0 0;
  font-size: 1.35rem;
  letter-spacing: -0.025em;
}

.course-count {
  white-space: nowrap;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.3rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: #ffffff;
}

.portal-shell .learning-home .course-card {
  border: 1px solid var(--hair);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
  background: var(--surface);
  border-radius: 0;
  box-shadow: none;
  transition: border-color 0.16s ease;
}

.portal-shell .learning-home .course-card:hover {
  border-color: #cbcae4;
  box-shadow: 0 4px 14px rgba(37, 34, 62, 0.06);
}

.course-card > div {
  min-width: 0;
}

.course-card h3 {
  overflow-wrap: anywhere;
  font-size: 1.2rem;
  letter-spacing: -0.02em;
}

.course-reading-status {
  margin-top: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--paper);
  border-radius: 0;
  border: 1px solid var(--hair);
  font-size: 0.875rem;
}

.course-reading-status progress {
  display: block;
  width: min(100%, 22rem);
  height: 8px;
  border-radius: 6px;
  accent-color: var(--accent);
  margin: 0.35rem 0;
}

/* Collapsible account & registered browsers panel */
.account-details {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0;
  padding: 1.25rem;
  margin-top: 2.5rem;
}

.account-details > summary {
  cursor: pointer;
  font-weight: 600;
  min-height: 44px;
  padding: 0.5rem;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.account-details > summary .badge {
  margin-left: 0.5rem;
}

.account-chevron { flex: 0 0 16px; }
.account-details[open] > summary .account-chevron { transform: rotate(90deg); }

.portal-shell .learning-home .handbook-course-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
  margin: 0;
  padding: 1rem;
  border: 0;
  border-bottom: 1px solid var(--hair);
  background: var(--surface);
  box-shadow: none;
}
.portal-shell .learning-home .handbook-course-row:last-child { border-bottom: 0; }
.handbook-course-row .course-reading-status {
  padding: 0;
  border: 0;
  background: transparent;
}

.table-container {
  max-width: 100%;
  overflow-x: auto;
  border-radius: 0;
  border: 1px solid var(--hair);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.data-table th {
  background: #f8f9fd;
  padding: 0.75rem 1rem;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
}

.data-table td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid #f0f0f5;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.data-table tr:hover td {
  background: #fafbfe;
}

/* --------------------------------------------------------------------------
   5. Course Syllabus & Curriculum Path Steps
   -------------------------------------------------------------------------- */
.course-resume {
  border: 1px solid var(--hair);
  margin-block: 1.25rem;
  padding: 1.25rem 1.5rem;
  border-radius: 0;
  background: var(--surface);
  box-shadow: none;
}

.course-path-step {
  border: 1px solid var(--hair);
  border-radius: 0;
  padding: 1.15rem 1.4rem;
  background: var(--surface);
  margin-bottom: 0.85rem;
  box-shadow: none;
  transition: border-color 0.16s ease;
}

.course-path-step:hover,
.course-path-step:focus-within {
  border-color: #cbcae4;
  box-shadow: 0 4px 14px rgba(87, 80, 189, 0.06);
}

.preparation-compact {
  font-size: 0.85rem;
  margin: 0.3rem 0 0 0;
  color: var(--muted);
}

/* --------------------------------------------------------------------------
   6. Studio Lecture Header & Roadmap
   -------------------------------------------------------------------------- */
.studio-body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
}

.studio-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--hair);
  gap: 0.65rem;
  padding: 0 clamp(0.75rem, 2vw, 1.5rem);
  min-height: 64px;
  box-shadow: none;
  box-sizing: border-box;
}

.studio-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex-wrap: wrap;
}

.studio-header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex-wrap: wrap;
}

.studio-header-right .workspace-tools {
  background: var(--surface);
  border: 1px solid var(--hair);
  color: var(--ink);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 12.5px;
  border-radius: 0;
  padding: 6px 12px;
  min-height: 38px;
  box-shadow: none;
  transition: all 0.14s ease;
}

.studio-header-right .workspace-tools:hover {
  background: var(--paper);
  border-color: var(--ink);
  color: var(--ink);
}

.studio-header-right .workspace-tools[aria-expanded="true"] {
  background: var(--orange-press);
  color: #ffffff;
  border-color: var(--orange-press);
  box-shadow: none;
}

.studio-header-right a.btn-secondary {
  background: transparent;
  border: 1px solid transparent;
  color: var(--slate);
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 12.5px;
  min-height: 38px;
  padding: 6px 10px;
  border-radius: 0;
  box-shadow: none;
  transition: all 0.14s ease;
}

.studio-header-right a.btn-secondary:hover {
  background: var(--paper);
  color: var(--ink);
  border-color: var(--hair);
}

.studio-header-right form .btn-secondary {
  background: transparent;
  border: 1px solid var(--hair);
  color: var(--slate);
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 12px;
  min-height: 38px;
  padding: 6px 10px;
  border-radius: 0;
  box-shadow: none;
  transition: all 0.14s ease;
}

.studio-header-right form .btn-secondary:hover {
  background: var(--paper);
  color: var(--ink);
  border-color: var(--ink);
}

.studio-brand {
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--ink);
  min-height: 44px;
}

.lecture-badge {
  background: var(--paper);
  color: var(--slate);
  border: 1px solid var(--hair);
  padding: 2px 7px;
  border-radius: 0;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 11px;
  white-space: nowrap;
}

.lecture-name-header {
  overflow-wrap: anywhere;
  font-family: var(--font-num);
  font-weight: 600;
  font-size: 18px;
  color: var(--ink);
  letter-spacing: 0.01em;
}

.rail-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--paper);
  border: 1px solid var(--hair);
  border-radius: 0;
  padding: 6px 12px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 12.5px;
  cursor: pointer;
  min-height: 44px; /* Accessible touch target */
  color: var(--ink);
  box-shadow: none;
  transition: all 0.14s ease;
}

.rail-toggle-btn:hover {
  background: var(--surface);
  border-color: var(--ink);
  color: var(--ink);
}

/* Reading Save Status Indicator */
.save-status-indicator {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 0;
  border: 1px solid var(--hair);
  background: var(--paper);
  color: var(--slate);
  line-height: 1.4;
  white-space: nowrap;
  box-shadow: none;
  transition: all 0.15s ease;
}

.save-status-indicator::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 0;
  flex-shrink: 0;
}

.save-status-indicator.saved {
  color: var(--success-ink);
  background: var(--success-bg);
  border-color: var(--success);
}

.save-status-indicator.saved::before {
  background: var(--success);
}

.save-status-indicator.saving {
  color: var(--slate);
  background: var(--paper);
  border-color: var(--hair);
}

.save-status-indicator.saving::before {
  background: var(--orange-press);
  opacity: 0.8;
}

.save-status-indicator.failed {
  color: var(--error-ink);
  background: var(--error-bg);
  border-color: var(--error);
}

.save-status-indicator.failed::before {
  background: var(--error);
}

/* Reading Progress Bar */
.reading-progress-track {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100% !important;
  height: 2px;
  background: var(--hair);
}

.reading-progress-fill {
  height: 100%;
  background: var(--orange-press);
  transition: width 0.1s linear;
}

/* --------------------------------------------------------------------------
   6b. Handbook Section Band
   -------------------------------------------------------------------------- */
.studio-body .handbook-section-band,
.handbook-section-band {
  margin-bottom: 0;
  border-top: none;
  border-left: none;
  border-right: none;
  border-bottom: 1px solid var(--hair);
  background: var(--paper);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px clamp(1rem, 3vw, 2.5rem);
  gap: 20px;
  box-sizing: border-box;
}

.d-band-left {
  display: flex;
  align-items: baseline;
  gap: 16px;
  min-width: 0;
}

.d-secnum {
  font-family: var(--font-num);
  font-size: 56px;
  line-height: 0.88;
  letter-spacing: 0.02em;
  color: var(--ink);
  font-weight: 600;
  flex-shrink: 0;
}

.d-band-headings {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.d-band-part {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--slate);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.d-band-title {
  font-family: var(--font-num);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.15;
  color: var(--ink);
  margin: 0;
  overflow-wrap: anywhere;
}

.d-band-topic {
  font-size: 12.5px;
  color: var(--slate);
  overflow-wrap: anywhere;
}

.d-resume {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex-shrink: 0;
}

.d-pos {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--slate);
}

.d-go {
  background: var(--orange-press);
  border: 1px solid var(--orange-press);
  color: #ffffff;
  border-radius: 0;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 16px;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  box-shadow: none;
}

.d-go:hover {
  background: var(--orange-press);
  color: #ffffff;
}

.d-bm {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--slate);
}


/* Studio Layout Container */
.studio-layout-container {
  max-width: 1800px;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 1.5rem;
  padding: 1.5rem clamp(1rem, 2.5vw, 2rem);
  margin: 0 auto;
  box-sizing: border-box;
}

/* Frame-mode studio layout: the sandboxed content frame fills the reading
   column; the computational companion sits beside it in the trusted shell on
   wide screens and uses the tools drawer below 1400px, matching the legacy
   companion behavior. */
.studio-layout-container.studio-frame-layout {
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
}

@media (min-width: 1400px) {
  .studio-layout-container.studio-frame-layout {
    grid-template-columns: minmax(0, 1fr) clamp(300px, 24vw, 420px);
  }
}

.studio-content-frame {
  display: block;
  width: 100%;
  height: calc(100dvh - var(--studio-header-height, 64px) - 24px);
  min-height: 320px;
  border: 1px solid var(--hair);
  border-radius: 6px;
  background: var(--paper);
  box-sizing: border-box;
}

.studio-layout-container.rail-collapsed {
  grid-template-columns: 48px minmax(0, 1fr);
}

.studio-main {
  min-width: 0;
}

.watermark-banner {
  background: var(--paper);
  border: 1px solid var(--hair);
  color: var(--slate);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.5;
  padding: 8px 12px;
  border-radius: 0;
  margin-bottom: 0.75rem;
  display: block;
  overflow-wrap: anywhere;
  box-shadow: none;
}

.watermark-banner strong {
  color: var(--ink);
  font-weight: 600;
}

.watermark-banner code {
  font-family: inherit;
  font-size: 1em;
  background: var(--chip);
  padding: 1px 4px;
  border: 1px solid var(--hair);
  border-radius: 0;
  color: var(--ink);
}

/* Dynamic positioning for roadmap rail */
.studio-rail {
  top: calc(var(--studio-header-height, 80px) + 16px);
  max-height: calc(100dvh - var(--studio-header-height, 80px) - 32px);
  background: var(--surface);
  border: 1px solid var(--hair);
  border-radius: 0;
  padding: 0.75rem;
  box-shadow: none;
  overflow-y: auto;
  box-sizing: border-box;
}

.rail-search-input {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 10px;
  font-size: 12.5px;
  border: 1px solid var(--hair);
  border-radius: 0;
  background: var(--paper);
  color: var(--ink);
  transition: border-color 0.14s;
}

.rail-search-input:focus {
  border-color: var(--ink);
  outline: 2px solid var(--focus);
  outline-offset: 1px;
  box-shadow: none;
}

.rail-title {
  font-family: var(--font-body);
  font-size: 10px;
  font-weight: 600;
  color: var(--slate);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  padding: 8px 8px 4px;
}

.rail-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.rail-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 0;
  border: 1px solid transparent;
  color: var(--ink);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  min-height: 40px;
  transition: all 0.12s ease;
  box-sizing: border-box;
}

.rail-link:hover {
  background: var(--paper);
  border-color: var(--hair);
  color: var(--ink);
}

.rail-link.active,
.rail-link[aria-current="location"] {
  background: var(--surface);
  border-color: var(--hair);
  color: var(--ink);
  font-weight: 600;
}

.rail-pill {
  width: 22px;
  height: 22px;
  background: var(--paper);
  border: 1px solid var(--hair);
  border-radius: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--slate);
  flex-shrink: 0;
  transition: all 0.12s ease;
}

.rail-link.active .rail-pill,
.rail-link[aria-current="location"] .rail-pill {
  background: var(--orange-press);
  color: #ffffff;
  border-color: var(--orange-press);
}

@media (min-width: 1025px) {
  .rail-collapsed .rail-search,
  .rail-collapsed .rail-title,
  .rail-collapsed .rail-text { display: none; }
  .rail-collapsed .studio-rail { padding-inline: 0.25rem; }
  .rail-collapsed .rail-link { justify-content: center; padding-inline: 0; }
}

#slideLightbox {
  position: fixed;
  inset: 0;
  margin: auto;
  width: min(1100px, 94vw);
  max-width: 94vw;
  height: fit-content;
  max-height: 90dvh;
  animation: none;
  transform: none;
  border: 2px solid var(--ink);
  border-radius: 0;
  background: var(--surface);
  box-shadow: 0 16px 48px rgba(34, 38, 43, 0.2);
}
#slideLightbox .lightbox-content { max-height: 90dvh; }
#slideLightbox .lightbox-header { flex-wrap: wrap; gap: 0.5rem; flex-shrink: 0; border-bottom: 1px solid var(--hair); padding: 12px 16px; }
#slideLightbox .lightbox-image-container { display: block; min-height: 0; overflow: auto; }
#slideLightbox .lightbox-img { margin-inline: auto; flex-shrink: 0; }
#slideLightbox .lightbox-footer { flex-shrink: 0; border-top: 1px solid var(--hair); padding: 8px 16px; font-family: var(--font-mono); font-size: 11px; color: var(--slate); }

.lecture-companion:focus { outline: 2px solid var(--focus); outline-offset: 2px; }
.lecture-course-navigation {
  margin-block: 0.5rem 1rem;
  padding: 0.6rem 1rem;
  background: var(--surface);
  border: 1px solid var(--hair);
  border-radius: 0;
  box-shadow: none;
}

.lecture-course-navigation details {
  border-bottom: 1px solid var(--hair);
  padding-bottom: 0.35rem;
  margin-bottom: 0.4rem;
}

.lecture-course-navigation details:not([open]) {
  border-bottom: none;
  padding-bottom: 0;
  margin-bottom: 0;
}

.lecture-course-navigation summary {
  cursor: pointer;
  min-height: 44px;
  display: flex;
  align-items: center;
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--ink);
  user-select: none;
}

.lecture-course-navigation ol {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1.25rem;
  padding: 0.5rem 0 0.5rem 1.25rem;
  margin: 0;
  font-size: 0.85rem;
}

.lecture-course-navigation a {
  color: var(--slate);
  text-decoration: none;
  font-size: 0.85rem;
}

.lecture-course-navigation a:hover {
  color: var(--ink);
  text-decoration: underline;
}

.lecture-course-navigation a[aria-current="page"] {
  font-weight: 700;
  color: var(--ink);
}

.lecture-neighbors {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  padding-top: 0.25rem;
}

.lecture-neighbors a {
  color: var(--orange-press);
  text-decoration: none;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0.2rem 0.4rem;
  border-radius: 0;
}

.lecture-neighbors a:hover {
  background: var(--paper);
}

.demo-card { min-width: 0; }
.demo-video {
  display: block;
  width: 100%;
  height: auto;
  max-width: min(960px, calc(65dvh * var(--demo-aspect, 1.44)));
  max-height: 65dvh;
  aspect-ratio: var(--demo-aspect, 1.44);
  object-fit: contain;
  margin: 1rem auto;
  border-radius: 0;
  background: var(--ink);
}

/* --------------------------------------------------------------------------
   7. Reading Column & Typography Containment
   -------------------------------------------------------------------------- */
.lecture-content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 1.5rem;
  align-items: start;
  min-width: 0;
  max-width: 100%;
}

/* --------------------------------------------------------------------------
   7. Lecture Content & Article Styling (Handbook Discipline)
   -------------------------------------------------------------------------- */
#lectureArticle {
  min-width: 0;
  max-width: 100%;
  font-family: var(--font-body);
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--ink);
}

#lectureArticle p,
#lectureArticle li {
  font-family: var(--font-body);
  max-width: 74ch;
  line-height: 1.6;
  color: var(--ink);
}

/* Headings in lecture article */
#lectureArticle h1,
#lectureArticle h2,
#lectureArticle h3,
#lectureArticle h4,
#lectureArticle .section-heading,
#lectureArticle .math-def-title,
#lectureArticle .proof-title,
#lectureArticle .check-title {
  font-family: var(--font-num);
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ink);
  overflow-wrap: anywhere;
}

#lectureArticle h1 {
  font-size: clamp(24px, 3.2vw, 32px);
  line-height: 1.15;
  margin: 0 0 0.75rem;
}

#lectureArticle h2 {
  font-size: clamp(20px, 2.5vw, 24px);
  line-height: 1.2;
  margin: 0 0 0.5rem;
}

#lectureArticle h3 {
  font-size: clamp(17px, 2vw, 20px);
  line-height: 1.25;
}

/* Monospace for code, parameters, mathematical notation markers */
#lectureArticle code,
#lectureArticle pre,
#lectureArticle kbd,
#lectureArticle samp,
#lectureArticle .mn,
#lectureArticle .math-code {
  font-family: var(--font-mono);
}

/* Adapted Hero Banner: flat paper/surface, ruled border, no blue gradient or bubble */
#lectureArticle .lecture-hero,
#lectureArticle .hero-banner {
  background: var(--surface);
  border: 1px solid var(--hair);
  border-radius: 0;
  padding: clamp(1.25rem, 2.5vw, 2rem);
  margin-bottom: 2rem;
  box-shadow: none;
  position: relative;
  overflow: hidden;
}

#lectureArticle .lecture-hero::after,
#lectureArticle .hero-banner::after {
  display: none;
}

#lectureArticle .hero-meta {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 0.85rem;
}

#lectureArticle .meta-pill {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 0;
  background: var(--chip);
  color: var(--ink);
  border: 1px solid var(--hair);
}

#lectureArticle .meta-pill.pill-orange,
#lectureArticle .meta-pill.pill-accent,
#lectureArticle .meta-pill.accent {
  background: #b83a15;
  color: #ffffff;
  border-color: #b83a15;
}

#lectureArticle .hero-title {
  font-family: var(--font-num);
  font-size: clamp(26px, 3.5vw, 36px);
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ink);
  margin: 0 0 0.5rem;
}

#lectureArticle .hero-subtitle {
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.6;
  color: var(--slate);
  max-width: 74ch;
  margin: 0;
}

/* Hide purely decorative eyebrow labels while keeping factual course context */
#lectureArticle .course-eyebrow,
#lectureArticle .decorative-eyebrow {
  display: none;
}

/* Cards & Sections */
#lectureArticle .lesson-section.card,
#lectureArticle .slide-card,
#lectureArticle .portal-card,
#lectureArticle .proof-card,
#lectureArticle .interactive-check-card {
  padding: clamp(1rem, 2vw, 1.6rem);
  border-radius: 0;
  border: 1px solid var(--hair);
  background: var(--surface);
  box-shadow: none;
  margin-bottom: 1.5rem;
}

#lectureArticle .slide-body-grid {
  grid-template-columns: minmax(0, 1fr);
}

/* Math Definition Box */
#lectureArticle .math-definition-box {
  background: #fafbfa;
  border: 1px solid var(--hair);
  border-left: 3px solid var(--orange);
  border-radius: 0;
  padding: 1.25rem 1.5rem;
  margin: 1.25rem 0;
}

#lectureArticle .math-def-title {
  font-size: 14px;
  margin-bottom: 0.5rem;
}

/* Equation Box */
#lectureArticle .equation-box {
  background: var(--surface);
  border: 1px solid var(--hair);
  border-radius: 0;
  padding: 1.25rem 1.5rem;
  margin: 1.25rem 0;
  overflow-x: auto;
}

#lectureArticle .equation-box:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* Balanced MathJax rendering */
#lectureArticle mjx-container[display="true"] {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.4rem 0;
}

#lectureArticle mjx-container:not([display]) {
  display: inline-block;
  vertical-align: middle;
  max-width: 100%;
}

/* Symbol Provenance Tagging */
#lectureArticle .symbol-breakdown {
  display: block;
  font-size: 13px;
  margin: 1.25rem 0;
}

#lectureArticle .symbol-breakdown dt {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--ink);
  margin-top: 0.75rem;
}

#lectureArticle .symbol-breakdown dd {
  color: var(--slate);
  margin: 0.25rem 0 0.75rem 0;
}

#lectureArticle .badge-provenance {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 0;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  display: inline-block;
}

#lectureArticle .badge-new {
  background: #b83a15;
  color: #ffffff;
}

#lectureArticle .badge-prev {
  background: var(--chip);
  color: var(--ink);
  border: 1px solid var(--hair);
}

#lectureArticle .badge-general {
  background: #eef2f6;
  color: var(--slate);
  border: 1px solid var(--hair);
}

#lectureArticle .badge-derived {
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--hair);
}

/* Practice & Exercise States (Preserve semantic status colors) */
#lectureArticle .check-options {
  display: grid;
  gap: 0.75rem;
  margin: 1rem 0;
}

#lectureArticle .check-option-btn,
#lectureArticle .check-opt-btn {
  font-family: var(--font-body);
  font-size: 13.5px;
  border-radius: 0;
  border: 1px solid var(--hair);
  background: var(--surface);
  color: var(--ink);
  padding: 0.75rem 1rem;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
  width: 100%;
  min-height: 44px;
}

#lectureArticle .check-option-btn:hover:not(:disabled),
#lectureArticle .check-opt-btn:hover:not(:disabled) {
  border-color: var(--ink);
}

#lectureArticle .check-option-btn:focus-visible,
#lectureArticle .check-opt-btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

#lectureArticle .opt-correct,
#lectureArticle .check-option-btn.opt-correct {
  border: 2px solid var(--success);
  background: var(--success-bg);
  color: var(--success-ink);
  font-weight: 600;
}

#lectureArticle .opt-incorrect,
#lectureArticle .check-option-btn.opt-incorrect {
  border: 2px solid var(--error);
  background: var(--error-bg);
  color: var(--error-ink);
}

#lectureArticle #checkFeedback {
  padding: 1rem;
  margin: 1rem 0;
  border-radius: 0;
  border: 1px solid var(--hair);
  border-left: 3px solid var(--success);
  background: var(--success-bg);
  line-height: 1.6;
  font-size: 13.5px;
}

/* Proof details drawer */
#lectureArticle details.proof-details-drawer {
  margin-top: 1rem;
  border-top: 1px solid var(--hair);
  padding-top: 0.75rem;
}

#lectureArticle details.proof-details-drawer summary {
  font-family: var(--font-num);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--ink);
  cursor: pointer;
  padding: 0.5rem 0;
}

#lectureArticle details.proof-details-drawer summary:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

#lectureArticle #proofDrawer {
  padding: 0.75rem 0 0.5rem;
  font-size: 13px;
  color: var(--slate);
  line-height: 1.6;
}

#lectureArticle .mimo-dashboard-grid,
#lectureArticle .mimo-card,
#lectureArticle .mimo-card-title {
  min-width: 0;
  max-width: 100%;
}

#lectureArticle .mimo-card-title {
  flex-wrap: wrap;
}

#lectureArticle .mimo-card-title > * {
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.lecture-read-completion-card {
  border: 2px solid var(--ink);
  padding: 1.5rem 1.8rem;
  background: var(--surface);
  border-radius: 0;
  box-shadow: none;
}

/* --------------------------------------------------------------------------
   8. Handbook Worked-Example Progressive Assembly (Build-Sheet Grammar)
   -------------------------------------------------------------------------- */
.assembly-stage,
.assembly-stage *,
.assembly-stage *::before,
.assembly-stage *::after {
  box-sizing: border-box;
}

.assembly-stage {
  max-width: 100%;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
  margin: 1.5rem 0;
  outline: none;
}
.assembly-stage:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 4px;
}

/* 1. Assembled Equation Box */
.assembly-eq-box {
  background: var(--surface);
  border: 2px solid var(--ink);
  padding: clamp(16px, 2.5vw, 24px);
  position: relative;
  z-index: 2;
}
.assembly-eq-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--hair);
  padding-bottom: 10px;
  margin-bottom: 16px;
}
.assembly-eq-tag {
  font-family: var(--font-num);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--ink);
}
.assembly-eq-num {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--slate);
}
.assembly-eq-formula {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  font-size: clamp(17px, 2.2vw, 21px);
  font-family: var(--font-body);
  color: var(--ink);
  margin: 12px 0 18px;
  min-height: 48px;
}
.assembly-eq-lhs,
.assembly-eq-op {
  font-weight: 600;
  color: var(--ink);
}
.assembly-term {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid transparent;
  padding: 6px 12px;
  border-radius: 0;
  cursor: pointer;
  color: var(--ink);
  font-family: inherit;
  font-size: inherit;
  min-height: 40px;
  transition: background 250ms cubic-bezier(0.16, 1, 0.3, 1), border-color 250ms cubic-bezier(0.16, 1, 0.3, 1);
}
.assembly-term:hover:not(.active) {
  border-color: var(--ink);
}
.assembly-term:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
.assembly-term.active {
  border: 2px solid var(--orange);
  background: rgba(217, 72, 31, 0.08);
  font-weight: 700;
}
.assembly-term.done {
  border: 1px solid var(--hair);
  background: var(--ghost);
  font-weight: 500;
}
.assembly-term.upcoming {
  border: 1px dashed var(--hair);
  color: var(--slate);
  opacity: 1;
}
.assembly-seat-marker {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  color: var(--orange);
}
.assembly-term.done .assembly-seat-marker {
  color: var(--slate);
}
.assembly-eq-key {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 22px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--slate);
  padding-top: 12px;
  border-top: 1px solid var(--hair);
}
.assembly-eq-key b {
  color: var(--ink);
}

/* 2. Leader Connector SVG */
.assembly-connector {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
  z-index: 5;
}
.assembly-leader-svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}
.assembly-leader-line {
  fill: none;
  stroke: var(--orange);
  stroke-width: 2px;
  stroke-dasharray: 4 3;
  transition: d 300ms cubic-bezier(0.16, 1, 0.3, 1);
}
.assembly-leader-head {
  fill: var(--orange);
  transition: points 300ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* 3. Assembly Body & Toolbar */
.assembly-body {
  background: var(--paper);
  border: 1px solid var(--hair);
  border-top: none;
  padding: 20px 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: relative;
  z-index: 2;
}
.assembly-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  border-bottom: 1px solid var(--hair);
  padding-bottom: 12px;
}
.assembly-step-counter {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--slate);
}
.assembly-step-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.assembly-btn-sm {
  padding: 6px 14px;
  font-size: 13px;
  min-height: 36px;
  font-family: var(--font-body);
  border-radius: 0;
  cursor: pointer;
}
.assembly-btn-sm:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* 4. Steps Stack */
.assembly-steps-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.assembly-step-row {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  text-align: left;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--hair);
  border-radius: 0;
  cursor: pointer;
  position: relative;
  min-height: 52px;
  font-family: inherit;
  transition: border-color 200ms ease;
}
.assembly-step-row:hover:not(.active) {
  border-color: var(--ink);
}
.assembly-step-row:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
.assembly-step-row.active {
  border: 2px solid var(--orange);
  background: var(--surface);
}
.assembly-step-row.done {
  border: 1px solid var(--hair);
  background: var(--ghost);
}
.assembly-step-row.upcoming {
  border: 1px solid var(--hair);
  background: var(--paper);
  opacity: 1;
}
.assembly-step-col-marker {
  display: flex;
  align-items: center;
  justify-content: center;
}
.assembly-step-marker {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 700;
}
.assembly-step-row.active .assembly-step-marker {
  color: var(--orange);
}
.assembly-step-row.done .assembly-step-marker {
  color: var(--slate);
}
.assembly-step-row.upcoming .assembly-step-marker {
  color: var(--hair);
}
.assembly-step-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}
/* The frame viewport is slightly narrower than the inline article was, so the
   assembly rows must be allowed to shrink below their text min-content instead
   of pushing the document wider (containment per the B4 gate). */
.assembly-step-row > * {
  min-width: 0;
}
.assembly-step-header > * {
  min-width: 0;
  max-width: 100%;
}
.assembly-step-desc {
  overflow-wrap: anywhere;
}
.assembly-step-title {
  font-family: var(--font-num);
  font-size: 13.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--ink);
}
.assembly-step-term {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink);
  background: var(--chip);
  padding: 2px 7px;
  border: 1px solid var(--hair);
}
.assembly-step-desc {
  font-size: 13px;
  line-height: 1.5;
  color: var(--slate);
  margin: 4px 0 0;
}
.assembly-step-row.active .assembly-step-desc {
  color: var(--ink);
}
.assembly-badge-active {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 4px 8px;
  background: #b83a15;
  color: #ffffff;
  white-space: nowrap;
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  .assembly-leader-line,
  .assembly-leader-head,
  .assembly-term,
  .assembly-step-row {
    transition: none !important;
    animation: none !important;
  }
}

/* Responsive */
@media (max-width: 640px) {
  .assembly-toolbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .assembly-step-row {
    grid-template-columns: 24px 1fr;
    gap: 10px;
    padding: 12px 14px;
  }
  .assembly-step-col-badge {
    grid-column: 2;
    margin-top: 4px;
  }
  .assembly-eq-formula {
    font-size: 16px;
  }
}

/* No-JS progressive enhancement */
body:not(.js) .assembly-toolbar {
  display: none;
}
body:not(.js) .assembly-connector {
  display: none;
}
body:not(.js) .assembly-step-row {
  cursor: default;
  opacity: 1;
  background: var(--surface);
  border: 1px solid var(--hair);
}
body:not(.js) .assembly-term {
  cursor: default;
}

/* --------------------------------------------------------------------------
   8. MATLAB Computational Companion (>= 1400px: Sticky Adjacent 340px Pane)
   -------------------------------------------------------------------------- */
.lecture-companion {
  position: sticky;
  top: calc(var(--studio-header-height, 64px) + 12px);
  max-height: calc(100dvh - var(--studio-header-height, 64px) - 28px);
  overflow: auto;
  margin: 0;
  padding: 1.25rem;
  background: var(--paper) !important;
  border: 1px solid var(--hair) !important;
  border-radius: 0 !important;
  scroll-margin-top: calc(var(--studio-header-height, 64px) + 24px);
  box-shadow: none !important;
}

.lecture-companion h2 {
  font-family: var(--font-num);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--ink);
  margin-top: 0;
}

.companion-lead {
  font-size: 13px;
  line-height: 1.55;
  color: var(--slate);
  margin-bottom: 1rem;
}

.companion-close {
  display: none;
}

.companion-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--hair);
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.companion-tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 0.5rem 0.85rem;
  font-family: var(--font-num);
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--slate);
  cursor: pointer;
  min-height: 44px;
  border-radius: 0;
  transition: color 0.12s ease, border-color 0.12s ease;
}

.companion-tab:hover {
  color: var(--ink);
}

.companion-tab.active,
.companion-tab[aria-selected="true"] {
  background: transparent;
  color: var(--ink);
  font-weight: 700;
  border-bottom-color: var(--orange-press);
}

.code-view-controls,
.code-editor-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.btn-mode {
  border-radius: 0;
  padding: 0.35rem 0.75rem;
  font-family: var(--font-num);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid var(--hair);
  background: var(--paper-2);
  color: var(--ink);
  cursor: pointer;
  min-height: 44px;
  transition: background 0.12s ease, color 0.12s ease;
}

.btn-mode:hover {
  background: var(--surface);
}

.btn-mode.active,
.btn-mode[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.code-status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin: 0.75rem 0 0.5rem;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--slate);
  flex-wrap: wrap;
}

.scratch-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem;
  background: var(--paper-2);
  border: 1px solid var(--hair);
  border-bottom: none;
  flex-wrap: wrap;
}

.snippet-group {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.toolbar-label {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--slate);
  margin-right: 0.25rem;
}

.btn-snippet {
  background: var(--surface);
  border: 1px solid var(--hair);
  border-radius: 0;
  padding: 0.25rem 0.6rem;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  color: var(--ink);
  cursor: pointer;
  min-height: 44px;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.btn-snippet:hover {
  background: var(--paper);
  border-color: var(--ink);
}

.btn-toggle-setting {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--surface);
  border: 1px solid var(--hair);
  border-radius: 0;
  padding: 0.25rem 0.5rem;
  min-height: 44px;
  cursor: pointer;
}

/* Keep editor layers and gutter on the same typography and light palette. */
.code-editor-frame {
  border: 1px solid var(--hair);
  border-radius: 0;
  background: var(--surface);
  font-family: var(--font-mono);
}

.figure-card {
  border: 1px solid var(--hair);
  border-radius: 0;
  overflow: hidden;
  background: var(--surface);
  box-shadow: none;
}

.lecture-companion .companion-select,
.lecture-companion textarea {
  max-width: 100%;
  min-width: 0;
}

.workspace-tools {
  min-height: 44px;
}

[hidden] {
  display: none !important;
}

/* --------------------------------------------------------------------------
   9. Responsive Views: Under 1400px (< 1400px: Fixed Nonmodal Tools Drawer)
   -------------------------------------------------------------------------- */
@media (max-width: 1399px) {
  .lecture-content-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .lecture-companion {
    display: none;
  }

  .tools-open .lecture-companion {
    display: block;
    position: fixed;
    z-index: 70;
    inset: auto 1rem 1rem auto;
    width: min(600px, calc(100% - 2rem));
    max-height: calc(100dvh - var(--studio-header-height, 100px) - 24px);
    box-shadow: none;
    border: 2px solid var(--ink) !important;
    border-radius: 0 !important;
    background: var(--paper) !important;
  }

  .companion-close {
    display: inline-flex;
    align-items: center;
    margin-bottom: 0.75rem;
    border-radius: 0;
    min-height: 44px;
  }
}

/* --------------------------------------------------------------------------
   10. Responsive Views: Tablet & Mobile (<= 1024px: Compact Outline Disclosure)
   -------------------------------------------------------------------------- */
@media (max-width: 1024px) {
  .studio-layout-container,
  .studio-layout-container.rail-collapsed {
    display: block;
    padding: 0.75rem;
  }

  .studio-rail {
    display: none;
  }

  .outline-open .studio-rail {
    display: block;
    position: fixed;
    z-index: 65;
    top: calc(var(--studio-header-height, 120px) + 8px);
    left: 1rem;
    right: 1rem;
    width: auto;
    max-height: 60dvh;
    overflow-y: auto;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
    border: 2px solid var(--ink);
    border-radius: 0;
    background: var(--surface);
  }

  .rail-collapsed .rail-text,
  .rail-collapsed .rail-title {
    display: initial;
  }

  .rail-collapsed .rail-link {
    justify-content: flex-start;
    padding: 0.5rem;
  }

  .studio-layout-container.rail-collapsed .rail-nav { display: block; }
}

/* --------------------------------------------------------------------------
   11. Intermediate & Small Screen Adaptations (<= 800px & <= 600px)
   -------------------------------------------------------------------------- */
@media (max-width: 800px) {
  .studio-entry.login-container {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .entry-form {
    order: 1;
    padding: 1.75rem 1.5rem 1.25rem;
  }

  .entry-story {
    order: 2;
    padding: 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
  }

  .entry-story h2 {
    font-size: 1.4rem;
    margin: 0.5rem 0;
  }

  .entry-diagram,
  .entry-caption {
    display: none;
  }

  .entry-story p {
    max-width: 52ch;
    margin-bottom: 0;
    font-size: 0.88rem;
  }
}

@media (max-width: 600px) {
  .portal-header {
    padding: 0.75rem 1rem;
    gap: 0.5rem;
  }

  .brand {
    font-size: 0.95rem;
  }

  .header-user {
    width: 100%;
    justify-content: space-between;
    font-size: 0.8rem;
  }

  .portal-nav {
    order: 3;
    width: 100%;
    flex-wrap: wrap;
  }

  .main-content {
    padding: 1rem;
  }

  .admin-meta {
    font-size: 0.85rem;
    overflow-wrap: anywhere;
  }

  .studio-header {
    padding: 6px 10px;
    gap: 4px;
    min-height: auto;
  }

  .studio-header .brand-wordmark,
  .d-mast .brand-wordmark {
    display: none !important;
  }

  .studio-header-left {
    width: auto;
    flex: 1 1 auto;
    gap: 6px;
  }

  .studio-header-center {
    flex: 1 0 100%;
    min-height: 38px;
  }

  .studio-header-center #saveStatus {
    width: auto !important;
  }

  .studio-header-right {
    width: 100%;
    gap: 0.35rem;
    justify-content: space-between;
  }

  .studio-header-right .workspace-tools,
  .studio-header-right a.btn-secondary,
  .studio-header-right form .btn-secondary {
    padding: 0.35rem 0.55rem;
    font-size: 0.8rem;
    min-height: 40px;
  }

  .studio-header .lecture-name-header {
    display: none;
  }

  .studio-layout-container {
    padding: 0.75rem;
  }

  .watermark-banner {
    margin-top: 0;
  }

  .account-details {
    padding: 0.75rem;
  }

  .learning-home {
    margin-top: 1rem;
  }

  .studio-body .handbook-section-band,
  .handbook-section-band {
    margin-bottom: 0 !important;
    padding: 8px 10px;
    gap: 8px;
    min-height: auto;
  }

  .handbook-section-band .d-secnum {
    font-size: 28px;
    line-height: 1;
  }

  .handbook-section-band .d-band-headings {
    gap: 2px;
  }

  .handbook-section-band .d-band-part {
    font-size: 10px;
  }

  .handbook-section-band .d-band-title {
    font-size: 16px;
    line-height: 1.15;
  }

  .handbook-section-band .d-resume {
    width: 100%;
    align-items: center;
    border-top: 1px solid var(--hair);
    padding-top: 6px;
    flex-direction: row;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 4px;
  }

  .handbook-section-band .d-go {
    width: 100%;
    justify-content: center;
    min-height: 38px;
    padding: 6px 12px;
  }

  .handbook-section-band .d-bm {
    display: none;
  }
}

@media (max-width: 480px) {
  .portal-header {
    padding: 0.6rem 0.85rem;
    gap: 0.35rem;
  }

  .portal-shell .main-content {
    padding: 1rem 0.85rem 3rem;
  }

  .portal-shell .brand {
    flex-wrap: wrap;
    font-size: 0.85rem;
  }

  .portal-shell .brand-badge {
    display: none;
  }

  .portal-nav a {
    padding: 0.35rem 0.6rem;
  }

  .studio-entry.login-container {
    border-radius: 0;
  }

  .entry-story,
  .entry-form {
    padding: 1.25rem 1rem;
  }

  .learning-welcome {
    padding: 0.85rem 1rem;
    margin-bottom: 1rem;
  }

  .learning-welcome h1 {
    font-size: 1.4rem;
    margin: 0.3rem 0;
  }

  .learning-welcome .admin-meta {
    font-size: 0.8rem;
  }

  .learning-section-heading {
    margin-bottom: 0.65rem;
    align-items: start;
  }

  .learning-section-heading .section-title {
    font-size: 1.15rem;
  }

  .portal-shell .learning-home .course-card {
    padding: 1rem;
  }

  .learning-home .course-card h3 {
    margin-top: 0;
  }

  .handbook-section-band {
    padding: 10px 12px;
    gap: 8px;
  }

  .handbook-section-band .d-secnum {
    font-size: 30px;
  }

  .handbook-section-band .d-band-title {
    font-size: 17px;
  }
}

/* --------------------------------------------------------------------------
   12. Progressive Enhancement: Accessible No-JS Fallbacks
   -------------------------------------------------------------------------- */
body:not(.js) #btnToggleSidebar,
body:not(.js) #btnWorkspaceTools {
  display: none;
}

@media (max-width: 1024px) {
  body:not(.js) .studio-rail {
    display: block;
    position: static;
    max-height: none;
    margin-bottom: 1.5rem;
  }
}

@media (max-width: 1399px) {
  body:not(.js) .lecture-companion {
    display: block;
    position: static;
    width: 100%;
    max-height: none;
    margin-top: 1.5rem;
  }

  body:not(.js) .companion-close {
    display: none;
  }
}

/* Keep keyboard focus and motion preferences authoritative after refinements. */
.portal-shell .form-control:focus-visible,
.rail-search-input:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Keep lecture numbering visible independently of dashboard mobile rules. */
.handbook-section-band .d-secnum { display: block; }

.assembly-stage.assembled .assembly-term { color: var(--ink); background: var(--paper); border: 1px solid var(--ink); }
#lectureArticle .hero-badge { border-radius: 0; background: var(--paper); color: var(--ink); }

/* Fikra: full symbol at 38px in mastheads; fluid bilingual lockup (max 240px) on authentication cards. */
.brand-identity { display: block; flex: 0 0 auto; }
.brand-identity img { display: block; width: 100%; height: 100%; object-fit: contain; }
.d-mast .brand-identity,
.brand .brand-identity,
.studio-brand .brand-identity,
.brand-identity.brand-symbol { width: 38px; height: 38px; }
.d-login-brand .brand-identity { width: 240px; max-width: 100%; height: auto; aspect-ratio: 760 / 220; }
.d-login-brand .brand-identity img { width: 100%; height: auto; }

/* Desktop companion can collapse without leaving an empty grid column. */
@media (min-width: 1400px) {
  .tools-collapsed .lecture-content-grid,
  .tools-collapsed .studio-layout-container.studio-frame-layout { grid-template-columns: minmax(0, 1fr) !important; }
  .tools-collapsed .lecture-companion { display: none; }
  body.js .companion-close { display: inline-flex; min-height: 44px; margin-bottom: 0.75rem; }
}

/* Slide previews sit beside the explanation when the card has room. */
#lectureArticle .slide-card { container-type: inline-size; }
#lectureArticle .slide-body-grid:has(> .slide-img-thumb-container) {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
}
#lectureArticle .slide-body-grid > .slide-img-thumb-container {
  grid-row: 1;
  justify-self: end;
  width: min(100%, 340px);
  box-sizing: border-box;
  margin: 0;
}
#lectureArticle .slide-body-grid > .explanation-content { min-width: 0; }
#lectureArticle .slide-img-thumb-container > img.slide-img-thumb[loading="lazy"]:not([width]):not([height]) {
  /* Reserve the preview space before a slide above the reading position loads. */
  aspect-ratio: 16 / 9;
  object-fit: contain;
}
@container (min-width: 640px) {
  #lectureArticle .slide-body-grid:has(> .slide-img-thumb-container) {
    grid-template-columns: minmax(0, 1fr) minmax(220px, 34%);
  }
  #lectureArticle .slide-body-grid > .explanation-content {
    grid-column: 1;
    grid-row: 1;
  }
  #lectureArticle .slide-body-grid > .slide-img-thumb-container {
    grid-column: 2;
    grid-row: 1;
  }
}
