/* Interactive Lectures Portal - Production Styles
   Approved Design: The Handbook (ADR-0018) */

:root {
  --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;
  --blue: #d9481f;
  --canvas: var(--paper);
  --bg: var(--paper);
  --line: var(--hair);
  --border: var(--hair);
  --muted: var(--slate);
  --error: #c92a2a;
  --error-bg: #fff5f5;
  --error-ink: #7f1d1d;
  --error-line: #fca5a5;
  --success: #1a7a40;
  --success-bg: #f0fdf4;
  --success-ink: #0f4023;
  --success-line: #86efac;
  --warning: #b45309;
  --warning-bg: #fef9c3;
  --warning-line: #fde047;
  --focus: #e3ab43;
  --radius: 0px;
  --radius-sm: 0px;
  --radius-md: 0px;
  --radius-lg: 0px;
  --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;
}

* {
  box-sizing: border-box;
}

html {
  font-family: var(--font-body);
  background-color: var(--paper);
  color: var(--ink);
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--paper);
  color: var(--ink);
  line-height: 1.65;
}

/* Accessibility: Utility & Typography */
.bc {
  font-family: var(--font-num);
  font-weight: 600;
}

.mn {
  font-family: var(--font-mono);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Skip link for keyboard accessibility */
.skip-link {
  position: absolute;
  top: -60px;
  left: 10px;
  background: var(--ink);
  color: var(--paper);
  padding: 8px 16px;
  z-index: 1000;
  border-radius: 0;
  border: 1px solid var(--orange);
  text-decoration: none;
  font-weight: 600;
  transition: top 0.15s ease;
}

.skip-link:focus {
  top: 10px;
  outline: 2px solid var(--focus) !important;
  outline-offset: 2px !important;
}

/* Accessibility: Reduced motion preference */
@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;
  }
}

/* Focus styles: Amber 2px outline */
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--focus) !important;
  outline-offset: 2px !important;
}

/* Zero shadows and flat surfaces enforcement */
.card,
.course-card,
.btn,
.panel,
.stat-card,
.stat-box,
.alert,
.form-control,
.modal,
.user-badge,
.brand-badge {
  box-shadow: none !important;
  background-image: none !important;
  border-radius: 0 !important;
}

/* Flat plane discipline across all cards */
.studio-body .card {
  border-radius: 0 !important;
}

/* Header & Masthead */
.portal-header,
.d-mast {
  background: #ffffff;
  border-bottom: 1px solid var(--hair);
  padding: 0 24px;
  min-height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.d-mast-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand,
.d-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; /* Accessible touch target */
}

.brand-symbol {
  flex-shrink: 0;
  display: block;
}

.brand-wordmark {
  display: inline-flex;
  flex-direction: column;
  line-height: 1.05;
  font-family: var(--font-num);
}

.brand-title {
  font-size: 13.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--ink);
}

.brand-sub {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--orange-press);
}

.brand-badge {
  background: var(--tint);
  color: var(--slate);
  padding: 2px 7px;
  border: 1px solid var(--hair);
  font-size: 0.72rem;
  font-weight: 600;
}

.portal-nav,
.d-mast-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-link,
.d-mast-link {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--slate);
  padding: 7px 12px;
  border: 1px solid transparent;
  min-height: 36px;
  background: transparent;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  border-radius: 0;
  cursor: pointer;
}

.nav-link:hover,
.d-mast-link:hover {
  color: var(--ink);
  background: var(--paper);
}

.nav-link.active,
.d-mast-link.active,
.nav-link[aria-current="page"],
.d-mast-link[aria-current="page"] {
  font-weight: 600;
  color: var(--ink);
  background: var(--paper);
  border-color: var(--hair);
}

.header-user,
.d-who {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  min-width: 0;
  max-width: 100%;
}

.user-badge,
.d-acct {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--hair);
  background: #ffffff;
  padding: 6px 12px;
  font-weight: 600;
  font-size: 12.5px;
  color: var(--ink);
  min-height: 32px;
  border-radius: 0;
}

.user-badge .mn,
.d-acct .mn {
  font-size: 11px;
  font-weight: 400;
  color: var(--slate);
}

.d-out {
  font-size: 12.5px;
  color: var(--slate);
  text-decoration: underline;
  text-underline-offset: 3px;
  padding: 6px 8px;
  background: transparent;
  border: 0;
  cursor: pointer;
  min-height: 44px;
}

.d-out:hover {
  color: var(--ink);
}

/* Main Layout */
.main-content {
  flex: 1;
  padding: 2rem 1.5rem 4rem;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

/* Cards & Ruled Panels */
.card,
.course-card {
  background: var(--surface);
  border: 1px solid var(--hair);
  border-radius: 0;
  padding: 2rem;
  box-shadow: none;
}

.d-ruled-box {
  background: var(--surface);
  border: 1px solid var(--hair);
  border-radius: 0;
  padding: 1.5rem 1.75rem;
  box-shadow: none;
}

/* Handbook Dashboard Header Band */
.d-band {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: auto;
  padding: 18px 24px;
  margin-bottom: 1.5rem;
  border: 1px solid var(--hair);
  background: var(--paper);
  flex-wrap: wrap;
}

.d-band-left {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.d-secnum {
  font-size: 32px;
  line-height: 1;
  color: var(--slate);
  flex-shrink: 0;
}

.d-band-headings {
  min-width: 0;
}

.d-band-title {
  font-family: var(--font-num);
  font-size: 1.6rem;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.01em;
}

.d-resume {
  display: flex;
  flex-direction: column;
  text-align: right;
  gap: 2px;
}

.d-pos {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.08em;
}

.d-bm {
  font-size: 10px;
  color: var(--slate);
  letter-spacing: 0.06em;
}

/* Handbook Dashboard Resume Card */
.d-resume-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  background: #ffffff;
  border: 2px solid var(--ink);
  padding: 24px 28px;
  margin-top: 1.5rem;
  border-radius: 0;
  box-shadow: none;
  flex-wrap: wrap;
}

.d-resume-left {
  display: flex;
  align-items: baseline;
  gap: 20px;
  min-width: 0;
}

.d-resume-sec {
  font-size: 72px;
  line-height: 0.88;
  letter-spacing: 0.02em;
  color: var(--ink);
  flex-shrink: 0;
}

.d-resume-heading {
  font-family: var(--font-num);
  font-size: 28px;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.15;
  color: var(--ink);
  margin: 0 0 4px 0;
}

.d-resume-sub {
  font-size: 13px;
  color: var(--slate);
  margin: 0 0 4px 0;
}

.d-resume-bm {
  font-size: 11px;
  color: var(--slate);
  display: block;
}

.d-btn-resume-lg {
  min-height: 48px;
  padding: 12px 24px;
  font-size: 14px;
  font-weight: 600;
}

/* Ruled Box Apparatus */
.d-box-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  border-bottom: 1px solid var(--hair);
  background: var(--paper);
}

.d-box-head h3 {
  font-size: 12.5px;
  letter-spacing: 0.1em;
  color: var(--ink);
  margin: 0;
}

.d-box-head .mn {
  font-size: 11px;
  color: var(--slate);
}

.d-box-body {
  padding: 18px;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.d-box-lead {
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--slate);
  margin-bottom: 14px;
}

.d-param-table-wrap,
.d-table-wrap,
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 16px;
}

.d-param-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.d-param-table th {
  font: 600 11px var(--font-body);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--slate);
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--ink);
}

.d-param-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--hair);
}

.d-param-table tr:last-child td {
  border-bottom: 0;
}

.d-param-table .d-k {
  color: var(--slate);
  width: 34%;
}

.d-support-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

/* Status Pills */
.d-status-pill {
  display: inline-block;
  padding: 2px 8px;
  font: 500 11px var(--font-body);
  border: 1px solid var(--hair);
  color: var(--slate);
  background: var(--paper);
  border-radius: 0;
  vertical-align: middle;
}

.d-status-pill.on {
  border-color: var(--ink);
  color: var(--ink);
  font-weight: 600;
}

.d-status-pill.alert {
  border-color: var(--orange);
  color: var(--orange-press);
  background: rgba(217, 72, 31, 0.06);
  font-weight: 600;
}

.d-status-pill.done {
  border-color: var(--success);
  background: var(--success-bg);
  color: var(--success-ink);
  font-weight: 600;
}

.d-status-pill.locked {
  background: var(--chip);
  color: var(--slate);
  border-color: var(--hair);
}

/* Syllabus & Path Section */
.d-path-section {
  border: 1px solid var(--hair);
  background: #ffffff;
}

.d-section-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--ink);
  background: var(--paper);
}

.d-bar-title {
  font-size: 13px;
  letter-spacing: 0.12em;
  color: var(--ink);
}

.d-bar-count {
  font-size: 11.5px;
  color: var(--slate);
}

.d-handbook-path {
  list-style: none;
  margin: 0;
  padding: 0;
}

.d-path-item {
  border-bottom: 1px solid var(--hair);
}

.d-path-item:last-child {
  border-bottom: 0;
}

.d-path-btn {
  display: flex;
  align-items: center;
  gap: 18px;
  width: 100%;
  padding: 16px 20px;
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--ink);
  min-height: 54px;
  cursor: pointer;
  text-decoration: none;
}

.d-path-btn:hover {
  background: var(--paper);
}

.d-path-item.current .d-path-btn {
  background: var(--paper);
}

.d-path-item.current .d-path-title {
  font-weight: 600;
}

.d-path-marker {
  font-size: 13px;
  width: 18px;
  text-align: center;
  flex-shrink: 0;
}

.d-path-marker.ghosted {
  color: var(--slate);
}

.d-path-marker.current {
  color: var(--orange);
}

.d-path-marker.upcoming {
  color: var(--slate);
}

.d-path-num {
  font-size: 26px;
  line-height: 1;
  width: 48px;
  color: var(--ink);
  flex-shrink: 0;
}

.d-path-body {
  flex: 1;
  min-width: 0;
}

.d-path-title {
  display: block;
  font-size: 15px;
  line-height: 1.4;
}

.d-path-topic {
  display: block;
  font-size: 12px;
  color: var(--slate);
  margin-top: 3px;
}

.d-path-time {
  font-size: 11.5px;
  color: var(--slate);
  padding: 0 16px;
}

.d-path-action {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
}

.d-path-btn:hover .d-path-action {
  color: var(--orange);
}

/* Login Page Layout & Handbook Auth Card */
.login-container,
.d-login-screen {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: calc(100vh - 120px);
  padding: 1.5rem 1rem;
  background: var(--paper);
}

.login-card,
.d-login-card {
  width: 100%;
  max-width: 440px;
  background: #ffffff;
  border: 2px solid var(--ink);
  padding: 24px 22px;
  border-radius: 0;
  box-shadow: none;
}

.d-login-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--slate);
  margin-bottom: 14px;
}

.d-login-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--ink);
  margin-bottom: 14px;
}

.d-login-header h1 {
  font-size: 24px;
  letter-spacing: 0.02em;
  line-height: 1;
  margin: 0;
  font-family: var(--font-num);
}

.d-login-header .mn {
  font-size: 11px;
  color: var(--slate);
}

.login-card h1 {
  font-size: 1.65rem;
  font-weight: 700;
  margin: 0 0 0.5rem 0;
  letter-spacing: -0.02em;
  line-height: 1.3;
}

.login-card p.subtitle {
  color: var(--slate);
  margin: 0 0 1rem 0;
  font-size: 0.95rem;
  line-height: 1.5;
}

/* Forms */
.form-group,
.d-field {
  margin-bottom: 1.25rem;
}

.form-group label,
.d-field label {
  display: block;
  font-weight: 600;
  font-size: 0.875rem;
  margin-bottom: 0.4rem;
  color: var(--ink);
}

.form-control {
  width: 100%;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--hair);
  border-radius: 0;
  font-family: inherit;
  font-size: 0.95rem;
  background: var(--paper);
  color: var(--ink);
  min-height: 40px;
  box-sizing: border-box;
}

.form-control:focus {
  border-color: var(--ink);
  background: #ffffff;
  outline: 2px solid var(--focus) !important;
  outline-offset: 2px !important;
}

.otp-field {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.25em;
  text-align: center;
  font-family: var(--font-mono);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 0;
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  min-height: 40px; /* Accessible touch target */
  box-shadow: none;
  background-image: none;
}

.btn-primary,
.d-btn-pri {
  /* The press shade gives small white labels at least 4.5:1 contrast. */
  background: var(--orange-press);
  border-color: var(--orange-press);
  color: #ffffff;
}

.btn-primary:hover,
.d-btn-pri:hover {
  background: var(--orange-press);
  border-color: var(--orange-press);
  color: #ffffff;
}

.btn-secondary {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--hair);
}

.btn-secondary:hover {
  background: var(--paper);
  border-color: var(--ink);
}

.btn-block,
.d-btn-block {
  width: 100%;
}

.btn-link {
  background: transparent;
  border: none;
  color: var(--slate);
  padding: 0.5rem 0;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  min-height: 44px;
}

.btn-link:hover {
  color: var(--ink);
}

/* Alerts */
.alert {
  padding: 0.85rem 1rem;
  border-radius: 0;
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
  line-height: 1.5;
  box-shadow: none;
}

.alert-error {
  background: var(--error-bg);
  border: 1px solid var(--error-line);
  color: var(--error-ink);
}

.alert-success {
  background: var(--success-bg);
  border: 1px solid var(--success-line);
  color: var(--success-ink);
}

.alert-warning {
  background: var(--warning-bg);
  border: 1px solid var(--warning-line);
  color: var(--warning);
}

.alert-info {
  background: var(--tint);
  border: 1px solid var(--hair);
  color: var(--slate);
}

/* Admin Dashboard Specific */
.admin-header {
  margin-bottom: 2rem;
}

.admin-header h1 {
  font-size: 1.85rem;
  letter-spacing: -0.02em;
  margin: 0 0 0.5rem 0;
}

.admin-meta {
  color: var(--muted);
  font-size: 0.95rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--hair);
  border-radius: 0;
  padding: 1.25rem 1.5rem;
}

.stat-label {
  font-family: var(--font-num);
  font-size: 0.85rem;
  color: var(--slate);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat-value {
  font-family: var(--font-num);
  font-size: 1.85rem;
  font-weight: 600;
  color: var(--ink);
  margin-top: 0.25rem;
  letter-spacing: -0.01em;
}

.section-title {
  font-family: var(--font-num);
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin: 0 0 1rem 0;
}

/* Tables and Contained Layouts (Contained at 320/360/390px, 768px, desktop) */
.table-container,
.d-table-wrap {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1rem 0;
  border: 1px solid var(--hair);
  border-radius: 0;
  background: var(--surface);
  box-sizing: border-box;
}

/* Secondary Production Screens (ADR-0018 Handbook Design System) */
.d-sub-card {
  background: #ffffff;
  border: 1px solid var(--hair);
  border-radius: 0;
  box-shadow: none;
  padding: 24px 28px;
  margin-bottom: 24px;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

.d-narrow-card {
  max-width: 520px;
  width: 100%;
  box-sizing: border-box;
  margin: 20px auto 40px;
  background: #ffffff;
  border: 2px solid var(--ink);
  border-radius: 0;
  box-shadow: none;
  padding: 28px 32px;
}

.d-grid-2col {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
  min-width: 0;
  max-width: 100%;
}

@media (max-width: 820px) {
  .d-grid-2col {
    grid-template-columns: minmax(0, 1fr);
  }
}

.d-sub-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 1px solid var(--hair);
  padding-bottom: 14px;
  margin-bottom: 18px;
  gap: 16px;
  flex-wrap: wrap;
}

.d-table-wrap[tabindex]:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.d-sub-tag {
  font-family: var(--font-body);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: normal;
  color: var(--slate);
  text-transform: none;
  display: block;
}

.d-sub-title {
  font-family: var(--font-num);
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--ink);
  margin: 4px 0 0;
  letter-spacing: -0.01em;
}

.d-sub-meta {
  font-family: var(--font-body);
  font-size: 13px;
  line-height: 1.5;
  color: var(--slate);
  margin: 4px 0 0;
}

.d-sub-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.d-desc-p {
  font-size: 14px;
  line-height: 1.6;
  color: var(--slate);
  margin: 0 0 16px;
}

/* Crisp Handbook Status Pills */
.d-status-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  border: 1px solid var(--hair);
  background: var(--paper);
  color: var(--ink);
  border-radius: 0;
}

.d-status-pill.done {
  border-color: var(--success-line);
  background: var(--success-bg);
  color: var(--success-ink);
}

.d-status-pill.alert {
  border-color: var(--error-line);
  background: var(--error-bg);
  color: var(--error-ink);
}

.d-status-pill.open { border-color: var(--orange-press); background: #fbe9e3; color: var(--orange-press); }
.d-status-pill.locked { border-color: var(--hair); background: var(--tint); color: var(--slate); }

.d-status-pill.info {
  border-color: var(--hair);
  background: var(--tint);
  color: var(--ink);
}

/* Badge reset to 0 radius & mono */
.badge {
  border-radius: 0 !important;
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 2px 7px;
  border: 1px solid var(--hair);
}

.badge-success {
  background: var(--success-bg) !important;
  color: var(--success-ink) !important;
  border-color: var(--success-line) !important;
}

.badge-error {
  background: var(--error-bg) !important;
  color: var(--error-ink) !important;
  border-color: var(--error-line) !important;
}

.badge-warning {
  background: var(--warning-bg) !important;
  color: var(--warning) !important;
  border-color: var(--warning-line) !important;
}

.badge-accent,
.badge-primary {
  background: var(--tint) !important;
  color: var(--ink) !important;
  border-color: var(--hair) !important;
}

/* Demos Grid & Cards */
.d-demos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px;
  margin-top: 1.5rem;
}

.d-demo-card {
  border: 1px solid var(--hair);
  border-radius: 0;
  background: #ffffff;
  display: flex;
  flex-direction: column;
}

.d-demo-media {
  background: var(--ink);
  color: #ffffff;
  height: 140px;
  position: relative;
  display: grid;
  place-items: center;
  padding: 12px;
}

.d-demo-num {
  position: absolute;
  top: 10px;
  left: 12px;
  font-family: var(--font-num);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--orange);
}

.d-demo-dur {
  position: absolute;
  bottom: 8px;
  right: 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: #ffffff;
  background: rgba(0, 0, 0, 0.6);
  padding: 2px 6px;
}

.d-play-btn {
  width: 48px;
  height: 48px;
  border-radius: 0;
  background: var(--orange-press);
  color: #ffffff;
  border: none;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 150ms ease;
}

.d-play-btn:hover {
  transform: scale(1.06);
}

.d-play-btn:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.d-demo-body {
  padding: 14px 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.d-demo-title {
  font-family: var(--font-num);
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  margin: 0;
}

.d-demo-desc {
  font-size: 13px;
  line-height: 1.5;
  color: var(--slate);
  margin: 0;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.925rem;
  min-width: 520px;
}

.data-table th {
  background: var(--canvas);
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--line);
}

.data-table td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  vertical-align: middle;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.data-table tr:hover td {
  background: #fafafc;
}

.bulk-panel { min-width: 0; margin-block: 1.25rem; }
.bulk-panel p, .bulk-panel code { overflow-wrap: anywhere; }
.bulk-csv { display: block; width: 100%; resize: vertical; font-family: monospace; margin-block: .5rem 1rem; }
.bulk-table-region { max-width: 100%; max-height: 32rem; overflow: auto; }
.bulk-table-region:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.bulk-table-region td { vertical-align: top; }
.bulk-table-region input[type="checkbox"] { width: 24px; height: 24px; margin: 0; flex-shrink: 0; }
.bulk-select-hit { display: flex; align-items: center; justify-content: center; width: 44px; min-height: 44px; padding: 10px; cursor: pointer; }
.bulk-table-region tbody th { text-transform: none; letter-spacing: normal; font-size: inherit; color: var(--ink); vertical-align: top; }
.bulk-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 250px), 1fr)); gap: 1rem; margin-block: 1rem; }
.bulk-fields > div { min-width: 0; }
.bulk-fields input, .bulk-fields select { width: 100%; min-width: 0; }
.bulk-choice { display: flex; align-items: center; gap: .5rem; min-height: 44px; }
.bulk-choice input { width: 24px; height: 24px; }
.bulk-row-error { color: var(--error); margin: 0 0 .5rem; }

/* Expanded inspection belongs to the record, rather than a narrow overview cell. */
.inspection-table td {
  vertical-align: top;
}

.inspection-table .inspection-row td {
  padding-top: 0;
}

.inspection-details {
  width: min(52rem, calc(100vw - 4rem));
  overflow-wrap: anywhere;
}

.inspection-details summary {
  cursor: pointer;
  min-height: 44px;
  padding: 0.6rem 0;
}

.inspection-panel {
  box-sizing: border-box;
  width: 100%;
  max-height: 28rem;
  overflow: auto;
  padding: 1rem;
  margin: 0 0 0.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--canvas);
  white-space: normal;
  overflow-wrap: anywhere;
  font-size: 0.85rem;
  line-height: 1.65;
}

.inspection-panel dl {
  margin: 0;
  white-space: normal;
}

pre.inspection-panel {
  white-space: pre-wrap;
}

.inspection-panel dt {
  font-weight: 600;
  margin-top: 0.65rem;
}

.inspection-panel dt:first-child {
  margin-top: 0;
}

.inspection-panel dd {
  margin-left: 0;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-success {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid var(--success-line);
}

.badge-warning {
  background: #fffbeb;
  color: #b45309;
  border: 1px solid #fde68a;
}

.badge-accent {
  background: var(--accent-light);
  color: var(--accent);
}

.badge-error {
  background: var(--error-bg);
  color: var(--error);
  border: 1px solid var(--error-line);
}

.badge-muted {
  background: var(--canvas);
  color: var(--muted);
  border: 1px solid var(--line);
}

/* Nav Subbar */
.nav-subbar {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .main-content,
  .portal-shell .main-content {
    padding: 1rem 1rem 2.5rem;
  }

  .login-container {
    padding: 1rem 0.5rem;
  }

  .card {
    padding: 1.25rem;
  }

  .portal-header,
  .d-mast {
    padding: 0.5rem 1rem;
    min-height: 54px;
    gap: 8px;
  }

  .d-band {
    padding: 14px 18px;
    margin-bottom: 1rem;
  }

  .d-resume-card {
    padding: 18px 20px;
    margin-top: 1rem;
    gap: 16px;
  }

  .d-resume-sec {
    font-size: 48px;
  }

  .d-resume-heading {
    font-size: 22px;
  }
}

@media (max-width: 480px) {
  .main-content,
  .portal-shell .main-content {
    padding: 0.75rem 0.75rem 2rem;
  }

  .d-band {
    padding: 10px 14px;
    margin-bottom: 0.75rem;
  }

  .d-secnum {
    display: none;
  }

  .d-resume {
    display: none;
  }

  .d-band-title {
    font-size: 1.25rem;
  }

  .d-resume-card {
    padding: 14px 14px;
    margin-top: 0.75rem;
    gap: 12px;
  }

  .d-resume-sec {
    font-size: 36px;
  }

  .d-resume-heading {
    font-size: 20px;
  }

  .d-btn-resume-lg {
    width: 100%;
    justify-content: center;
  }

  .card {
    padding: 1rem 0.85rem;
  }

  .login-card h1 {
    font-size: 1.45rem;
  }

  .btn {
    padding: 0.65rem 1rem;
    font-size: 0.9rem;
  }
}

@media (max-width: 320px) {
  .login-container {
    padding: 0.5rem;
  }

  .card {
    padding: 0.85rem 0.65rem;
    border-radius: 0;
  }

  .portal-header,
  .d-mast {
    flex-direction: column;
    align-items: flex-start;
  }
}


/* ========================================================
   Lecture Studio Hybrid Architecture (ADR-0003 & Skill)
   ======================================================== */

.studio-body {
  background-color: var(--canvas);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Sticky Header & Reading Progress Bar */
.studio-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 0.75rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.studio-header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.rail-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--canvas);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 12px;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  min-height: 44px; /* Accessible touch target */
}

.rail-toggle-btn:hover {
  background: #ebebf5;
}

.studio-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--ink);
}

.lecture-badge {
  background: var(--accent-light);
  color: var(--accent);
  padding: 4px 8px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 0.8rem;
  white-space: nowrap;
}

.lecture-name-header {
  font-weight: 700;
  font-size: 1rem;
}

.studio-header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.watermark-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
}

.watermark-chip .wm-dot {
  width: 6px;
  height: 6px;
  background: #dc2626;
  border-radius: 50%;
}

.btn-header {
  font-size: 0.85rem;
  padding: 0.4rem 0.8rem;
  min-height: 44px;
}

/* Reading Progress Bar Track & Fill */
.reading-progress-track {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: transparent;
}

.reading-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.1s linear;
}

/* Reading Save Status Indicator */
.save-status-indicator {
  font-size: 0.8rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
  line-height: 1.4;
  white-space: nowrap;
  transition: opacity 0.2s ease, background-color 0.2s ease, color 0.2s ease;
}

.save-status-indicator.saved {
  color: var(--success);
  background: var(--success-bg);
  border: 1px solid var(--success-line);
}

.save-status-indicator.saving {
  color: var(--muted);
  background: var(--canvas);
  border: 1px solid var(--line);
}

.save-status-indicator.failed {
  color: var(--error);
  background: var(--error-bg);
  border: 1px solid var(--error-line);
}

.lecture-read-completion-card {
  padding: 1.25rem 1.5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

/* 2-Zone Studio Layout: Collapsible 210px Rail & Reading Column */
.studio-layout-container {
  display: grid;
  grid-template-columns: 210px minmax(0, 1fr);
  gap: 1.5rem;
  max-width: 1380px;
  margin: 0 auto;
  width: 100%;
  padding: 1.5rem 1.25rem 4rem;
  flex: 1;
  transition: grid-template-columns 0.2s ease;
}

.studio-layout-container.rail-collapsed {
  grid-template-columns: 44px minmax(0, 1fr);
}

.studio-rail {
  position: sticky;
  top: 75px;
  height: fit-content;
  max-height: calc(100vh - 90px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
}

.rail-collapsed .studio-rail {
  padding: 0.75rem 0.25rem;
}

.rail-inner {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.rail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.5rem;
}

.rail-collapsed .rail-header {
  display: none;
}

.rail-title {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.05em;
}

.rail-meta {
  font-size: 0.75rem;
  color: var(--muted);
}

.rail-nav {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.rail-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  color: var(--ink);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  min-height: 44px; /* Accessible hit target */
}

.rail-link:hover, .rail-link.active {
  background: var(--accent-light);
  color: var(--accent);
}

.rail-pill {
  width: 24px;
  height: 24px;
  background: var(--canvas);
  border: 1px solid var(--line);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}

.rail-collapsed .rail-text {
  display: none;
}

.rail-collapsed .rail-link {
  justify-content: center;
  padding: 0.4rem 0;
}

/* Studio Main */
.studio-main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Watermark Banner */
.watermark-banner {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #7f1d1d;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.85rem;
}

.watermark-badge {
  background: #fee2e2;
  color: #991b1b;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}

/* Lesson Section */
.lesson-section {
  padding: 2rem;
}

.section-tag {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.08em;
  margin-bottom: 0.5rem;
}

.lesson-title {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 1rem 0;
}

.lesson-lead {
  font-size: 1rem;
  line-height: 1.7;
  color: var(--ink);
  margin-bottom: 1.5rem;
}

/* Slide Card & Inspection */
.slide-card {
  background: var(--canvas);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 1.25rem;
  margin: 1.25rem 0;
}

.slide-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.slide-preview-container {
  background: white;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  max-width: 600px;
  margin-bottom: 0.75rem;
}

.slide-preview-img {
  width: 100%;
  height: auto;
  display: block;
}

.btn-inspect {
  min-height: 44px;
}

/* 4-Level Symbol Provenance Tagging & Equation Card */
.equation-box {
  background: white;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 1.5rem;
  margin: 1.25rem 0;
}

.equation-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.equation-name {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--ink);
}

.equation-math {
  font-size: 1.15rem;
  overflow-x: auto;
  padding: 0.75rem 0;
  margin-bottom: 1rem;
}

.symbol-breakdown {
  display: grid;
  gap: 0.4rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
  font-size: 0.875rem;
}

.symbol-item {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  line-height: 1.6;
}

/* Provenance Badges */
.badge-provenance {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge-prev {
  background: #dcfce7;
  color: #166534;
}

.badge-new {
  background: #fef9c3;
  color: #854d0e;
}

.badge-derived {
  background: #dbeafe;
  color: #1e40af;
}

.badge-general {
  background: #f3e8ff;
  color: #6b21a8;
}

/* Proof Revealer Drawer */
.proof-container {
  margin: 1.25rem 0;
}

.btn-reveal-proof {
  width: 100%;
  text-align: left;
  justify-content: flex-start;
  padding: 0.85rem 1.25rem;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: 0;
  min-height: 44px;
}

.reveal-content {
  margin-top: 0.75rem;
}

.proof-card {
  background: var(--surface);
  border: 1px solid var(--hair);

  border-radius: 0;
  padding: 1.5rem;
  font-size: 0.95rem;
  line-height: 1.7;
}

.proof-card h4 {
  margin: 0 0 0.75rem 0;
  font-size: 1.05rem;
  font-family: var(--font-num);
  letter-spacing: -0.01em;
}

.proof-qed {
  margin-top: 1rem;
  font-weight: 700;
  color: var(--ink);
  text-align: right;
  font-family: var(--font-num);
}

/* Simulator Sandbox */
.sim-sandbox {
  background: var(--canvas);
  border: 1px solid var(--hair);
  border-radius: 0;
  padding: 1.25rem;
  margin: 1.25rem 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 240px;
  gap: 1.25rem;
  align-items: center;
}

.sim-canvas-box {
  background: white;
  border: 1px solid var(--hair);
  border-radius: 0;
  overflow: hidden;
  display: flex;
  justify-content: center;
}

.sim-canvas-box canvas {
  width: 100%;
  max-width: 460px;
  height: auto;
  display: block;
}

/* Concept Check Quiz */
.interactive-check-card {
  background: white;
  border: 1px solid var(--hair);
  border-radius: 0;
  padding: 1.5rem;
  margin: 1.25rem 0;
}

.check-question {
  font-size: 1rem;
  line-height: 1.6;
  margin: 0 0 1rem 0;
}

.check-options {
  display: grid;
  gap: 0.6rem;
}

.check-opt-btn {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--canvas);
  border: 1px solid var(--hair);
  border-radius: 0;
  padding: 0.75rem 1rem;
  font-size: 0.925rem;
  line-height: 1.5;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 44px; /* Accessible touch target */
}

.check-opt-btn:hover {
  background: #ebebf5;
}

.check-opt-btn .opt-letter {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: white;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.check-opt-btn.opt-correct {
  background: var(--success-bg) !important;
  border-color: var(--success-line) !important;
  color: var(--success) !important;
  font-weight: 600;
}

.check-opt-btn.opt-correct .opt-letter {
  background: var(--success);
  color: white;
  border-color: var(--success);
}

.check-opt-btn.opt-incorrect {
  background: var(--error-bg) !important;
  border-color: var(--error-line) !important;
  color: var(--error) !important;
}

.check-opt-btn.opt-incorrect .opt-letter {
  background: var(--error);
  color: white;
  border-color: var(--error);
}

.check-feedback {
  margin-top: 1rem;
}

.feedback-card {
  padding: 1rem 1.25rem;
  border-radius: 0;
  font-size: 0.9rem;
  line-height: 1.6;
}

.feedback-correct {
  background: var(--success-bg);
  border: 1px solid var(--success-line);
  color: #14532d;
}

.feedback-correct h4 {
  margin: 0 0 0.35rem 0;
  color: var(--success);
}

/* Computational Exercise */
.exercise-card {
  background: var(--surface);
  border: 1px solid var(--hair);
  border-radius: 0;
  padding: 1.25rem;
  margin: 1.25rem 0;
}

.exercise-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.exercise-actions {
  display: flex;
  gap: 0.5rem;
}

.code-container {
  background: #1e293b;
  border-radius: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.matlab-code-block {
  margin: 0;
  padding: 1.25rem;
  color: #f8fafc;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.85rem;
  line-height: 1.6;
}

/* Lightbox Modal */
.lightbox-dialog {
  border: none;
  border-radius: 12px;
  padding: 0;
  background: transparent;
  max-width: 90vw;
  max-height: 90vh;
}

.lightbox-dialog::backdrop {
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(4px);
}

.lightbox-content {
  background: white;
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

.lightbox-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: var(--canvas);
}

.lightbox-title {
  font-weight: 700;
  font-size: 0.95rem;
}

.lightbox-close-btn {
  min-height: 44px;
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
}

.lightbox-image-container {
  padding: 1rem;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #0f172a;
}

.lightbox-img {
  max-width: 100%;
  max-height: 70vh;
  object-fit: contain;
  display: block;
}

.lightbox-footer {
  padding: 0.6rem 1.25rem;
  font-size: 0.75rem;
  color: var(--muted);
  background: var(--canvas);
  border-top: 1px solid var(--line);
  text-align: center;
}

/* Access Denied / Locked Overlay */
.access-locked-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(6px);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1.5rem;
}

.access-locked-overlay[hidden] {
  display: none !important;
}

.access-locked-card {
  max-width: 480px;
  width: 100%;
  text-align: center;
  background: white;
  padding: 2.5rem 2rem;
  border-radius: var(--radius);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2);
}

/* Responsive Collapses for Intermediate Widths & Phones */
@media (max-width: 1024px) {
  .studio-layout-container {
    grid-template-columns: 1fr;
  }

  .studio-rail {
    position: static;
    max-height: none;
    margin-bottom: 1rem;
  }

  .sim-sandbox {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .studio-header {
    flex-wrap: wrap;
    padding: 0.75rem 1rem;
  }

  .lesson-section {
    padding: 1.25rem;
  }
}

@media (max-width: 390px) {
  .studio-header-right .watermark-chip {
    display: none;
  }

  .lesson-title {
    font-size: 1.25rem;
  }

  .exercise-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .exercise-actions {
    width: 100%;
    flex-direction: column;
  }

  .exercise-actions .btn {
    width: 100%;
  }
}

@media (max-width: 320px) {
  .studio-layout-container {
    padding: 1rem 0.5rem 3rem;
  }

  .lesson-section {
    padding: 1rem 0.75rem;
  }
}


/* ==========================================================================
   MATLAB & README Companion Styles (T09)
   ========================================================================== */

.lecture-companion {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.companion-lead {
  color: var(--muted, #64748b);
  font-size: 0.9rem;
  margin: 0 0 0.5rem 0;
  line-height: 1.5;
}

.companion-selector-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

.companion-selector-label {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text, #1e293b);
}

.companion-select {
  min-height: 44px;
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--hair, #e5e2da);
  border-radius: 0;
  font-size: 0.85rem;
  background: var(--surface, #ffffff);
  color: var(--ink, #141413);
  max-width: 100%;
  flex: 1 1 auto;
}

.companion-tabs {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  border-bottom: 2px solid var(--line, #e2e8f0);
  padding-bottom: 0.5rem;
}

.companion-tab {
  min-height: 44px;
  padding: 0.5rem 1rem;
  border: 1px solid transparent;
  border-radius: 0;
  background: transparent;
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--muted, #64748b);
  cursor: pointer;
  transition: all 0.15s ease;
}

.companion-tab:hover {
  background: var(--canvas, #f8fafc);
  color: var(--text, #1e293b);
}

.companion-tab.active {
  background: transparent;
  color: var(--ink);
  border-bottom: 2px solid var(--orange-press);
}

.code-view-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.code-mode-toggles,
.code-editor-controls {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn-mode {
  min-height: 44px;
  padding: 0.35rem 0.75rem;
  border-radius: 0;
  border: 1px solid var(--hair);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
}

.btn-mode.active {
  background: var(--ink);
  color: #ffffff;
  border-color: var(--ink);
}

.code-status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.825rem;
  margin-bottom: 0.5rem;
}

.save-status-text {
  color: var(--slate);
  font-weight: 500;
}

.save-status-text.text-success {
  color: var(--success);
}

.save-status-text.text-warning {
  color: var(--warning);
}

.scratch-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--paper);
  border-radius: 0;
  border: 1px solid var(--hair);
  margin-bottom: 0.5rem;
}

.snippet-group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.toolbar-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--slate);
  margin-right: 0.25rem;
}

.btn-snippet,
.btn-toggle-setting {
  min-height: 44px;
  padding: 0.35rem 0.65rem;
  border-radius: 0;
  border: 1px solid var(--hair);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.85rem;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-snippet:hover,
.btn-toggle-setting:hover {
  background: var(--paper);
  border-color: var(--ink);
  color: var(--ink);
}

.function-hint-box {
  padding: 0.65rem 0.85rem;
  background: var(--tint);
  border: 1px solid var(--hair);
  border-radius: 0;
  font-size: 0.825rem;
  color: var(--ink);
  margin-bottom: 0.5rem;
}

.hint-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.hint-header select {
  min-height: 44px;
  padding: 0.25rem 0.5rem;
  border-radius: 0;
  border: 1px solid var(--hair);
  background: #ffffff;
  color: var(--ink);
  font-size: 0.8rem;
}

.function-hint-details {
  margin: 0;
  line-height: 1.45;
}

.editor-suggestions-list {
  position: absolute;
  z-index: 100;
  max-height: 180px;
  overflow-y: auto;
  background: #ffffff;
  border: 1px solid var(--hair);
  border-radius: 0;
  box-shadow: none;
  padding: 0.25rem 0;
  list-style: none;
  margin: 0;
  font-size: 0.85rem;
}

.suggestion-item {
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.suggestion-item:hover,
.suggestion-item:focus {
  background: var(--paper);
  color: var(--ink);
  outline: none;
}

.code-editor-frame {
  position: relative;
  border: 1px solid var(--hair);
  border-radius: 0;
  background: #ffffff;
  display: flex;
  overflow: hidden;
  min-height: 320px;
  max-height: 600px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
}

.editor-gutter {
  padding: 0.75rem 0.5rem;
  background: #f8fafc;
  border-right: 1px solid var(--line, #e2e8f0);
  color: #94a3b8;
  text-align: right;
  user-select: none;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  overflow: hidden;
  white-space: pre;
  min-width: 2.5rem;
}

.editor-layers {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  height: 100%;
  overflow: hidden;
}

.code-highlight-layer {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 0.75rem;
  overflow: hidden;
  white-space: pre;
  word-wrap: normal;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  pointer-events: none;
  color: transparent;
  background: transparent;
  box-sizing: border-box;
}

.code-textarea-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0.75rem;
  box-sizing: border-box;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  white-space: pre;
  word-wrap: normal;
  overflow: auto;
  caret-color: #0f172a;
}

/* Enhanced Editor Syntax Highlighting */
.code-editor-frame.enhanced .code-textarea-layer {
  color: transparent;
  -webkit-text-fill-color: transparent;
}

.code-editor-frame.enhanced .code-highlight-layer {
  color: #1e293b;
}

.code-editor-frame:not(.enhanced) .code-textarea-layer {
  color: #1e293b;
  -webkit-text-fill-color: #1e293b;
}

.code-editor-frame:not(.enhanced) .code-highlight-layer {
  display: none;
}

/* MATLAB Syntax Tokens */
.tok-comment { color: var(--slate); font-style: italic; }
.tok-string { color: #8a3b14; }
.tok-number { color: #2b6254; }
.tok-keyword { color: var(--ink); font-weight: 600; }
.tok-builtin { color: var(--ink); font-weight: 500; }
.tok-operator { color: var(--ink); }
.tok-bracket { color: var(--slate); font-weight: 700; }

/* README Content Formatting */
.readme-content-wrap {
  padding: 0.5rem 0;
}

.readme-body {
  line-height: 1.65;
  color: var(--text, #1e293b);
  font-size: 0.95rem;
  overflow-wrap: anywhere;
}

.readme-table-wrap {
  max-width: 100%;
  overflow-x: auto;
  margin: 1rem 0;
}

.readme-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
}

.readme-table th,
.readme-table td {
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--line, #e2e8f0);
}

.readme-table th {
  background: var(--canvas, #f8fafc);
  font-weight: 600;
}

.readme-code-block {
  max-width: 100%;
  overflow-x: auto;
  background: #0f172a;
  color: #f8fafc;
  padding: 0.75rem 1rem;
  border-radius: 0;
  font-size: 0.85rem;
}

.readme-math {
  overflow-x: auto;
  max-width: 100%;
  margin: 0.75rem 0;
}

.readme-img {
  max-width: 100%;
  height: auto;
  border-radius: 0;
  border: 1px solid var(--hair);
}

.readme-link {
  color: var(--orange);
  text-decoration: underline;
}

/* Figures Gallery */
.figures-gallery-wrap {
  padding: 0.5rem 0;
}

.figures-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}

.figure-card {
  border: 1px solid var(--hair);
  border-radius: 0;
  padding: 0.75rem;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.figure-preview-img {
  width: 100%;
  height: 150px;
  object-fit: contain;
  background: var(--ink);
  border-radius: 0;
  display: block;
}

.figure-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.figure-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

/* Downloads Pane */
.downloads-pane-wrap {
  padding: 0.5rem 0;
}

.downloads-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.download-item-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border: 1px solid var(--hair);
  border-radius: 0;
  background: var(--surface);
  flex-wrap: wrap;
  gap: 0.5rem;
}

.download-item-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.download-meta {
  font-size: 0.8rem;
  color: var(--muted, #64748b);
}

/* Studio Layout & Slide Grid Containment */
.lecture-content-grid {
  min-width: 0;
  max-width: 100%;
}

.slide-body-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 340px);
  gap: 1.75rem;
  align-items: start;
  min-width: 0;
}

.slide-body-grid > * {
  min-width: 0;
  max-width: 100%;
}

.lecture-companion {
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.lecture-companion pre {
  min-width: 0;
  max-width: 100%;
  overflow-x: auto;
}

/* Responsive Stacking & Tool disclosures */
@media (max-width: 1100px) {
  .lecture-content-grid {
    grid-template-columns: 1fr;
  }

  .lecture-companion {
    width: 100%;
    margin-top: 1.5rem;
  }
}

@media (max-width: 768px) {
  .companion-tabs {
    flex-wrap: wrap;
  }

  .companion-tab {
    flex: 1 1 calc(50% - 0.25rem);
    text-align: center;
  }

  .code-view-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .code-mode-toggles,
  .code-editor-controls {
    width: 100%;
  }

  .btn-mode,
  .btn-secondary {
    flex: 1 1 auto;
    text-align: center;
  }
}

.preparation-notice { margin: 1rem 0; padding: 1rem; border-left: 4px solid var(--accent); overflow-wrap: anywhere; }
.preparation-notice .btn { margin: 0.2rem 0.4rem 0.2rem 0; white-space: normal; }
.preparation-compact { margin: 0.25rem 0 0; font-size: 0.85rem; }
