:root {
  --color-bg: #FFF8F0;
  --color-surface: #FFFFFF;
  --color-border: #F2E4D2;

  --color-primary: #F07824;
  --color-primary-dark: #C85E12;
  --color-primary-light: #FF9950;
  --color-primary-tint: #FFEAD4;

  --color-accent-teal: #FCC024;
  --color-accent-teal-tint: #FFF3D0;
  --color-accent-lavender: #FFE9D2;

  --color-text: #12172B;
  --color-text-muted: #6B7280;
  --color-text-faint: #9CA3AF;

  --color-danger: #E0455C;
  --color-success: #22B27D;

  --tag-biology: #3355CC;
  --tag-history: #1FA97A;
  --tag-mathematics: #12172B;
  --tag-literature: #E0455C;
  --tag-chemistry: #2E6BE0;
  --tag-default: var(--color-primary);

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --radius-pill: 999px;

  --shadow-card: 0 1px 2px rgba(18, 23, 43, 0.04), 0 8px 24px rgba(18, 23, 43, 0.06);
  --shadow-float: 0 12px 28px rgba(240, 120, 36, 0.24);

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;

  --nav-height: 68px;
  --header-height: 56px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #16110B;
    --color-surface: #211810;
    --color-border: #362415;

    --color-primary: #FF9640;
    --color-primary-dark: #E67A1F;
    --color-primary-light: #FFB870;
    --color-primary-tint: #3A2410;

    --color-accent-teal: #FFCD3C;
    --color-accent-teal-tint: #3A2E0A;
    --color-accent-lavender: #3A2410;

    --color-text: #EEF0F8;
    --color-text-muted: #A2A8C0;
    --color-text-faint: #6B7290;

    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
    --shadow-float: 0 12px 28px rgba(255, 150, 64, 0.3);
  }
}

:root[data-theme="light"] {
  --color-bg: #FFF8F0;
  --color-surface: #FFFFFF;
  --color-border: #F2E4D2;

  --color-primary: #F07824;
  --color-primary-dark: #C85E12;
  --color-primary-light: #FF9950;
  --color-primary-tint: #FFEAD4;

  --color-accent-teal: #FCC024;
  --color-accent-teal-tint: #FFF3D0;
  --color-accent-lavender: #FFE9D2;

  --color-text: #12172B;
  --color-text-muted: #6B7280;
  --color-text-faint: #9CA3AF;

  --shadow-card: 0 1px 2px rgba(18, 23, 43, 0.04), 0 8px 24px rgba(18, 23, 43, 0.06);
  --shadow-float: 0 12px 28px rgba(240, 120, 36, 0.24);
}

:root[data-theme="dark"] {
  --color-bg: #16110B;
  --color-surface: #211810;
  --color-border: #362415;

  --color-primary: #FF9640;
  --color-primary-dark: #E67A1F;
  --color-primary-light: #FFB870;
  --color-primary-tint: #3A2410;

  --color-accent-teal: #FFCD3C;
  --color-accent-teal-tint: #3A2E0A;
  --color-accent-lavender: #3A2410;

  --color-text: #EEF0F8;
  --color-text-muted: #A2A8C0;
  --color-text-faint: #6B7290;

  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-float: 0 12px 28px rgba(255, 150, 64, 0.3);
}

*, *::before, *::after { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

body { min-height: 100vh; }

h1, h2, h3, p, dl, dd, figure { margin: 0; }

button, input, select, textarea { font-family: inherit; color: inherit; }

button { cursor: pointer; background: none; border: none; }

a { color: inherit; text-decoration: none; }

img { max-width: 100%; display: block; }

.app-shell {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  margin: 0 auto;
  background: var(--color-bg);
  position: relative;
  padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 12px);
}

.screen {
  padding: var(--space-4) var(--space-4) var(--space-8);
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

/* Invisible on mobile (#tab-home is still a plain flex-column .screen, so
   these two wrappers just stack like everything else always did) -- exist
   only so the desktop breakpoint below can turn them into a 2-column grid's
   two columns without touching any other markup in the file. */
.home-col-main, .home-col-side { display: flex; flex-direction: column; gap: var(--space-6); }

.eyebrow {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.screen-title { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.01em; }
.screen-sub { font-size: 0.92rem; color: var(--color-text-muted); line-height: 1.4; }

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  padding: var(--space-5);
}

.section-heading-row { display: flex; align-items: baseline; justify-content: space-between; }
.section-heading { font-size: 1.05rem; font-weight: 700; }
.link-btn { font-size: 0.85rem; font-weight: 600; color: var(--color-primary); display: inline-flex; align-items: center; gap: 4px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border-radius: var(--radius-pill);
  padding: 14px 20px;
  font-size: 0.95rem;
  font-weight: 700;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn--primary { background: var(--color-primary); color: #fff; box-shadow: var(--shadow-float); }
.btn--outline { background: transparent; border: 1.5px solid var(--color-primary); color: var(--color-primary); }
.btn--danger.btn--outline { border-color: var(--color-danger); color: var(--color-danger); }
.btn--block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.field-label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin-bottom: var(--space-2);
  display: block;
}

.text-input, .select-input {
  width: 100%;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  font-size: 0.95rem;
  color: var(--color-text);
}
.text-input::placeholder { color: var(--color-text-faint); }
.text-input:focus, .select-input:focus { outline: 2px solid var(--color-primary-light); outline-offset: 1px; }
textarea.text-input { resize: vertical; font-family: inherit; }

.empty-note { font-size: 0.86rem; color: var(--color-text-muted); text-align: center; padding: var(--space-4); }

/* Header */
.app-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-4);
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--color-bg);
}
.app-header-back { color: var(--color-primary); display: flex; align-items: center; justify-content: center; width: 32px; height: 32px; flex-shrink: 0; }
.app-header-title { flex: 1; display: flex; align-items: center; }
.app-header-logo { height: 26px; width: auto; display: block; }
.app-header-version { font-size: 0.6rem; font-weight: 600; color: var(--color-text-muted); letter-spacing: 0; vertical-align: middle; margin-left: 6px; }
.app-header-avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--color-primary-tint); color: var(--color-primary); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  height: var(--nav-height);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 30;
}
.bottom-nav-item { display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--color-text-faint); padding: 6px 10px; border-radius: var(--radius-md); flex: 1; }
.bottom-nav-icon { width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center; transition: background 0.15s ease, color 0.15s ease; }
.bottom-nav-label { font-size: 0.68rem; font-weight: 600; }
.bottom-nav-item.is-active { color: var(--color-primary); }
.bottom-nav-item.is-active .bottom-nav-icon { background: var(--color-primary); color: #fff; }

/* Home */
.recent-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-3); }
.recent-item { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3); border: 1px solid var(--color-border); border-radius: var(--radius-sm); color: var(--color-text-faint); }
.recent-item-icon { width: 40px; height: 40px; flex-shrink: 0; border-radius: var(--radius-sm); background: var(--color-primary-tint); color: var(--color-primary); display: flex; align-items: center; justify-content: center; }
.recent-item-body { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.recent-item-title { color: var(--color-text); font-weight: 700; font-size: 0.92rem; }
.recent-item-meta { font-size: 0.78rem; color: var(--color-text-muted); }

.stat-card-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.stat-card { border-radius: var(--radius-md); padding: var(--space-5); color: #fff; display: flex; flex-direction: column; gap: var(--space-1); min-height: 120px; justify-content: center; }
.stat-card--primary { background: linear-gradient(155deg, var(--color-primary) 0%, var(--color-primary-dark) 100%); }
.stat-card--teal { background: linear-gradient(155deg, var(--color-accent-teal) 0%, #E0A000 100%); color: #4A3300; }
.stat-card-label { font-size: 0.68rem; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; opacity: 0.85; }
.stat-card-value { font-size: 1.7rem; font-weight: 800; }
.stat-card-sub { font-size: 0.76rem; opacity: 0.85; }

.card--lavender { background: var(--color-accent-lavender); border-color: transparent; display: flex; flex-direction: column; gap: var(--space-3); }
.topic-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.topic-item { display: flex; align-items: center; justify-content: space-between; background: var(--color-surface); border-radius: var(--radius-sm); padding: 11px 14px; font-size: 0.88rem; font-weight: 600; }
.topic-add-btn { width: 24px; height: 24px; border-radius: 50%; border: 1px solid var(--color-border); color: var(--color-primary); font-size: 1rem; line-height: 1; display: flex; align-items: center; justify-content: center; }

.tip-card { padding: 0; overflow: hidden; display: flex; flex-direction: column; gap: var(--space-2); }
.tip-card-banner { height: 110px; background: linear-gradient(135deg, #C85E12 0%, #F07824 45%, #FCC024 130%); }
.tip-card > .section-heading, .tip-card > .screen-sub { padding-left: var(--space-5); padding-right: var(--space-5); }
.tip-card > .screen-sub { padding-bottom: var(--space-5); }

/* Library */
.library-toggle { display: flex; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-pill); padding: 4px; gap: 4px; }
.library-toggle-btn { flex: 1; padding: 9px 0; border-radius: var(--radius-pill); font-size: 0.86rem; font-weight: 700; color: var(--color-text-muted); }
.library-toggle-btn.is-active { background: var(--color-primary); color: #fff; }
.library-search { display: flex; align-items: center; gap: var(--space-2); color: var(--color-text-faint); }

/* Create screen's mode toggle has 4 options (vs. Library's 2) -- equal-flex
   division squeezes labels like "Manual Build" past comfortable width, so
   scroll horizontally with fixed-width pills instead of shrinking text. */
#modeToggle { overflow-x: auto; }
#modeToggle .library-toggle-btn { flex: 0 0 auto; padding: 9px 14px; white-space: nowrap; }
.library-search input { border: none; outline: none; flex: 1; font-size: 0.9rem; background: transparent; color: var(--color-text); }
.library-list { display: flex; flex-direction: column; gap: var(--space-4); }
.exam-card { background: var(--color-surface); border: 1px solid var(--color-border); border-top: 4px solid var(--tag-default); border-radius: var(--radius-md); box-shadow: var(--shadow-card); padding: var(--space-4) var(--space-5) var(--space-5); display: flex; flex-direction: column; gap: var(--space-2); }
.exam-card--tag--biology { border-top-color: var(--tag-biology); }
.exam-card--tag--history { border-top-color: var(--tag-history); }
.exam-card--tag--mathematics { border-top-color: var(--tag-mathematics); }
.exam-card--tag--literature { border-top-color: var(--tag-literature); }
.exam-card--tag--chemistry { border-top-color: var(--tag-chemistry); }
.exam-tag { align-self: flex-start; font-size: 0.68rem; font-weight: 700; padding: 3px 10px; border-radius: var(--radius-pill); color: #fff; background: var(--tag-default); }
.tag--biology { background: var(--tag-biology); }
.tag--history { background: var(--tag-history); }
.tag--mathematics { background: var(--tag-mathematics); }
.tag--literature { background: var(--tag-literature); }
.tag--chemistry { background: var(--tag-chemistry); }
.exam-card-title { font-size: 1.02rem; font-weight: 700; }
.exam-card-meta { font-size: 0.78rem; color: var(--color-text-muted); }
.exam-card-excerpt { font-size: 0.84rem; font-style: italic; color: var(--color-text-muted); background: var(--color-bg); border-radius: var(--radius-sm); padding: var(--space-3); }
.exam-card-history { font-size: 0.76rem; color: var(--color-text-muted); font-variant-numeric: tabular-nums; }
.exam-card-foot { display: flex; align-items: center; justify-content: space-between; margin-top: var(--space-1); gap: var(--space-3); }
.exam-card-actions { display: flex; align-items: center; gap: var(--space-4); flex-wrap: wrap; }
.exam-badge { width: 26px; height: 26px; border-radius: 50%; background: var(--color-primary-tint); color: var(--color-primary); font-size: 0.7rem; font-weight: 800; display: flex; align-items: center; justify-content: center; }
.library-create-card { width: 100%; margin-top: var(--space-4); border: 1.5px dashed var(--color-border); border-radius: var(--radius-md); padding: var(--space-6) var(--space-5); display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; color: var(--color-text-muted); }
.library-create-icon { width: 40px; height: 40px; border-radius: 50%; background: var(--color-primary-tint); color: var(--color-primary); font-size: 1.3rem; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.library-create-title { font-weight: 700; color: var(--color-text); }

/* Profile */
.profile-hero { display: flex; align-items: center; gap: var(--space-4); }
.profile-avatar { width: 64px; height: 64px; border-radius: 50%; background: var(--color-primary-tint); color: var(--color-primary); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.theme-toggle-row { display: flex; align-items: center; gap: var(--space-3); margin-top: var(--space-3); }
.theme-toggle-icon { font-size: 1.1rem; }
.switch { position: relative; display: inline-block; width: 44px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-track { position: absolute; inset: 0; background: var(--color-border); border-radius: var(--radius-pill); transition: background 0.15s ease; cursor: pointer; }
.switch-thumb { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); transition: transform 0.15s ease; }
.switch input:checked + .switch-track { background: var(--color-primary); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(18px); }

/* Create: source step */
.field-block { display: block; }
.manual-choice-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.manual-choice-row .text-input { flex: 1; }
.key-row { display: flex; align-items: center; gap: 8px; }
.key-row .text-input { flex: 1; }
.key-row-masked { font-size: 0.78rem; color: var(--color-text-muted); white-space: nowrap; }
.backup-btn-row { display: flex; gap: var(--space-3); margin-top: 8px; }
.backup-btn-row .btn { flex: 1; }
.source-cards { display: flex; flex-direction: column; gap: var(--space-3); }
.source-card { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); box-shadow: var(--shadow-card); padding: var(--space-5) var(--space-4); width: 100%; }
.source-card-icon { width: 52px; height: 52px; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin-bottom: 4px; }
.source-card-icon--primary { background: var(--color-primary-tint); color: var(--color-primary); }
.source-card-icon--teal { background: var(--color-accent-teal-tint); color: #8A5A00; }
.source-card-icon--muted { background: var(--color-bg); color: var(--color-text-muted); }
.source-card-title { font-weight: 700; font-size: 0.95rem; }
.source-card-sub { font-size: 0.8rem; color: var(--color-text-muted); }
.source-preview-row { display: flex; gap: var(--space-3); overflow-x: auto; padding-bottom: 4px; }
.source-preview-thumb { position: relative; width: 84px; height: 84px; flex-shrink: 0; border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--color-border); }
.source-preview-thumb img { width: 100%; height: 100%; object-fit: cover; }
.source-preview-remove { position: absolute; top: 4px; right: 4px; width: 20px; height: 20px; border-radius: 50%; background: rgba(0, 0, 0, 0.6); color: #fff; font-size: 0.65rem; display: flex; align-items: center; justify-content: center; }
.banner-card { background: linear-gradient(135deg, #C85E12 0%, #F07824 60%, #FCC024 140%); color: #fff; border: none; }
.banner-card .screen-sub { color: rgba(255, 255, 255, 0.85); margin-top: 4px; }
.tip-inline-card { display: flex; gap: var(--space-3); align-items: flex-start; background: var(--color-primary-tint); border-color: transparent; }
.tip-inline-icon { font-size: 1.2rem; }
.tip-inline-title { font-weight: 700; font-size: 0.88rem; margin-bottom: 2px; }

/* Create: configure step */
.type-list { display: flex; flex-direction: column; gap: var(--space-3); }
.type-option { display: flex; align-items: center; gap: var(--space-3); text-align: left; border: 1.5px solid var(--color-border); border-radius: var(--radius-sm); padding: var(--space-4); transition: border-color 0.15s ease, background 0.15s ease; width: 100%; }
.type-option.is-active { border-color: var(--color-primary); background: var(--color-primary-tint); }
.type-option-icon { width: 34px; height: 34px; border-radius: var(--radius-sm); background: var(--color-bg); display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 1rem; }
.type-option-body { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.type-option-title { font-weight: 700; font-size: 0.92rem; }
.type-option-sub { font-size: 0.78rem; color: var(--color-text-muted); }
.type-checkbox { width: 20px; height: 20px; border-radius: 5px; border: 1.5px solid var(--color-border); flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: #fff; }
.type-checkbox.is-checked { background: var(--color-primary); border-color: var(--color-primary); }
.difficulty-slider { width: 100%; accent-color: var(--color-primary); margin-bottom: var(--space-3); }
.difficulty-labels { display: flex; justify-content: space-between; }
.difficulty-label { display: flex; flex-direction: column; align-items: center; gap: 4px; opacity: 0.55; }
.difficulty-label.is-active { opacity: 1; }
.difficulty-pill { font-size: 0.65rem; font-weight: 800; padding: 3px 10px; border-radius: var(--radius-pill); background: var(--color-bg); color: var(--color-text-muted); }
.difficulty-label.is-active .difficulty-pill { background: var(--color-primary); color: #fff; }
.difficulty-sub { font-size: 0.68rem; color: var(--color-text-muted); }
.count-card { display: flex; flex-direction: column; align-items: center; gap: var(--space-3); }
.count-circle { width: 132px; height: 132px; border-radius: 50%; background: var(--color-primary-tint); display: flex; flex-direction: column; align-items: center; justify-content: center; }
.count-value { font-size: 2.2rem; font-weight: 800; color: var(--color-primary); line-height: 1; }
.count-unit { font-size: 0.65rem; font-weight: 700; letter-spacing: 0.08em; color: var(--color-primary); margin-top: 4px; }
.count-controls { display: flex; gap: var(--space-4); }
.count-btn { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--color-border); font-size: 1.2rem; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.quote-card { background: linear-gradient(135deg, #2a2f45 0%, #1b1f33 100%); color: #fff; font-style: italic; font-size: 0.92rem; text-align: center; }

/* Generating */
.generating-screen { align-items: center; justify-content: center; min-height: 60vh; text-align: center; }
.generating-spinner { width: 56px; height: 56px; border-radius: 50%; border: 4px solid var(--color-primary-tint); border-top-color: var(--color-primary); animation: spin 0.9s linear infinite; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.generating-error-card { border-color: var(--color-danger); }

/* Quiz runner */
.quiz-header-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--space-2); }
.quiz-header-row #quizExamTitle { font-weight: 700; font-size: 0.92rem; }
.quiz-live-score { font-size: 0.9rem; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--color-primary); background: var(--color-primary-tint); padding: 3px 12px; border-radius: var(--radius-pill); }
.quiz-timer { position: absolute; left: 50%; transform: translateX(-50%); font-size: 0.9rem; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--color-text); }
.quiz-timer.is-low { color: var(--color-danger); }
.quiz-header-row { position: relative; }
.progress-track { height: 6px; border-radius: var(--radius-pill); background: var(--color-border); overflow: hidden; }
.progress-fill { height: 100%; background: var(--color-primary); transition: width 0.2s ease; }
.quiz-runner-meta { display: flex; justify-content: space-between; font-size: 0.78rem; color: var(--color-text-muted); margin-top: var(--space-2); }
.quiz-nav-row { display: flex; gap: 6px; overflow-x: auto; margin-top: var(--space-2); padding-bottom: 4px; }
.quiz-nav-pill { flex-shrink: 0; width: 28px; height: 28px; border-radius: 50%; border: 1.5px solid var(--color-border); background: var(--color-surface); color: var(--color-text-muted); font-size: 0.72rem; font-weight: 700; display: flex; align-items: center; justify-content: center; font-variant-numeric: tabular-nums; }
.quiz-nav-pill.is-answered { border-color: var(--color-primary); background: var(--color-primary-tint); color: var(--color-primary); }
.quiz-nav-pill.is-current { border-color: var(--color-primary); background: var(--color-primary); color: #fff; }
.question-card { display: flex; flex-direction: column; gap: var(--space-4); }
.question-type-tag { align-self: flex-start; font-size: 0.68rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; background: var(--color-primary-tint); color: var(--color-primary); padding: 4px 10px; border-radius: var(--radius-pill); }
.question-prompt { font-size: 1.02rem; font-weight: 600; line-height: 1.4; }
.choice-list { display: flex; flex-direction: column; gap: var(--space-2); }
.choice-option { display: flex; align-items: center; gap: var(--space-3); text-align: left; border: 1.5px solid var(--color-border); border-radius: var(--radius-sm); padding: var(--space-3) var(--space-4); font-size: 0.92rem; width: 100%; }
.choice-option.is-selected { border-color: var(--color-primary); background: var(--color-primary-tint); font-weight: 700; }
.choice-option.is-correct { border-color: var(--color-success); background: color-mix(in srgb, var(--color-success) 14%, var(--color-surface)); font-weight: 700; }
.choice-option.is-incorrect { border-color: var(--color-danger); background: color-mix(in srgb, var(--color-danger) 14%, var(--color-surface)); font-weight: 700; }
.choice-option.is-locked { cursor: default; opacity: 0.92; }
.choice-radio { width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid var(--color-border); flex-shrink: 0; }
.choice-radio.is-selected { border-color: var(--color-primary); border-width: 5px; }
.choice-radio.is-correct { border-color: var(--color-success); background: var(--color-success); }
.choice-radio.is-incorrect { border-color: var(--color-danger); background: var(--color-danger); }
.answer-input-locked { opacity: 0.75; }
.matching-list { display: flex; flex-direction: column; gap: var(--space-3); }
.matching-row { display: flex; align-items: center; gap: var(--space-3); border: 1.5px solid var(--color-border); border-radius: var(--radius-sm); padding: var(--space-3); }
.matching-row.is-correct { border-color: var(--color-success); background: color-mix(in srgb, var(--color-success) 14%, var(--color-surface)); }
.matching-row.is-incorrect { border-color: var(--color-danger); background: color-mix(in srgb, var(--color-danger) 14%, var(--color-surface)); }
.matching-left { flex: 1; font-size: 0.9rem; font-weight: 600; }
.matching-select { flex: 1; }
.scratchpad-card { border: 1px solid var(--color-border); border-radius: var(--radius-sm); overflow: hidden; margin-bottom: var(--space-3); }
.scratchpad-mode-tabs { display: flex; background: var(--color-bg); border-bottom: 1px solid var(--color-border); }
.scratchpad-mode-tab { flex: 1; padding: 8px 6px; font-size: 0.82rem; font-weight: 600; color: var(--color-text-muted, inherit); background: transparent; border: none; border-bottom: 2px solid transparent; }
.scratchpad-mode-tab.is-active { color: var(--color-primary-dark); border-bottom-color: var(--color-primary); background: var(--color-surface); }
.scratchpad-toolbar { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; padding: 8px 10px; background: var(--color-bg); border-bottom: 1px solid var(--color-border); }
.scratchpad-colors { display: flex; align-items: center; gap: 6px; }
.scratchpad-swatch { width: 22px; height: 22px; border-radius: 50%; border: 2px solid transparent; padding: 0; }
.scratchpad-swatch.is-active { border-color: var(--color-text); }
.scratchpad-tool { width: 26px; height: 26px; border-radius: var(--radius-sm); border: 1px solid var(--color-border); background: var(--color-surface); font-size: 0.85rem; display: flex; align-items: center; justify-content: center; }
.scratchpad-tool.is-active { background: var(--color-primary-tint); border-color: var(--color-primary); }
.scratchpad-thickness { width: 70px; }
.scratchpad-actions { display: flex; gap: 4px; margin-left: auto; }
.scratchpad-actions .count-btn { width: 26px; height: 26px; font-size: 0.8rem; }
.scratchpad-viewport { position: relative; height: 450px; overflow: auto; background: #fff; touch-action: none; }
.scratchpad-viewport canvas { display: block; touch-action: none; }
.scratchpad-fs-close { display: none; }
.scratchpad-viewport.is-fullscreen {
  position: fixed; inset: 0; z-index: 3000; height: 100vh;
  display: flex; align-items: center; justify-content: center;
}
.scratchpad-viewport.is-fullscreen .scratchpad-fs-close {
  display: block; position: fixed; top: 12px; right: 12px; z-index: 3001;
  padding: 8px 14px; border-radius: 999px; border: 1px solid var(--color-border);
  background: var(--color-surface); font-size: 0.8rem; font-weight: 600;
}
body.scratchpad-fs-lock { overflow: hidden; }

/* ---- Grid Solve pad: column arithmetic with a borrow gesture ---- */
.gridpad-toolbar { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; padding: 8px 10px; background: var(--color-bg); border-bottom: 1px solid var(--color-border); }
.gridpad-hint { font-size: 0.78rem; color: var(--color-text-muted, #8a7a68); padding: 6px 10px 0; }
.gridpad-grid { display: flex; flex-direction: column; gap: 4px; padding: 10px; overflow-x: auto; background: #fff; }
.gridpad-row { display: flex; gap: 4px; }
.gridpad-cell { position: relative; flex: none; width: 34px; height: 36px; }
.gridpad-cell[data-carry]::before {
  content: attr(data-carry); position: absolute; top: -3px; left: 1px;
  font-size: 0.6rem; font-weight: 700; color: var(--color-danger); line-height: 1;
}
.gridpad-input {
  width: 100%; height: 100%; text-align: center; font-size: 0.95rem; font-weight: 600;
  border: 1px solid var(--color-border); border-radius: 6px; background: var(--color-surface);
  color: var(--color-text); padding: 0;
}
.gridpad-input:focus { outline: none; border-color: var(--color-primary); background: var(--color-primary-tint); }
/* Carry present -- shrink the cell's own digit a touch so the raised carry
   mark plus the digit read as a clean two-digit pair instead of crowding. */
.gridpad-cell[data-carry] .gridpad-input { font-size: 0.8rem; }
/* Borrowed-from cell -- a small dot in the opposite corner from the carry
   mark (top-right, vs. the carry's top-left) instead of recoloring the
   whole digit, so a cell that's both a lender and a recipient (a cascading
   borrow through a zero) shows both states clearly at once. */
.gridpad-cell.is-borrowed::after {
  content: ''; position: absolute; top: 3px; right: 3px;
  width: 5px; height: 5px; border-radius: 50%; background: var(--color-danger);
}
.gridpad-cell.gridpad-flash .gridpad-input { animation: gridpadFlash 0.3s ease; }
@keyframes gridpadFlash {
  0%, 100% { background: var(--color-surface); }
  50% { background: color-mix(in srgb, var(--color-danger) 20%, var(--color-surface)); }
}
.quiz-runner-nav { display: flex; gap: var(--space-3); }
.quiz-runner-nav .btn { flex: 1; }
.quiz-safety-note { font-size: 0.76rem; color: var(--color-text-muted); text-align: center; margin-top: var(--space-2); }

/* Results */
.score-card { text-align: center; background: linear-gradient(155deg, var(--color-primary) 0%, var(--color-primary-dark) 100%); color: #fff; border: none; }
.score-card .eyebrow { color: rgba(255, 255, 255, 0.75); }
.score-value { font-size: 2.6rem; font-weight: 800; margin: 4px 0; }
.score-card .screen-sub { color: rgba(255, 255, 255, 0.85); }
.results-list { display: flex; flex-direction: column; gap: var(--space-3); }
.result-item { display: flex; flex-direction: column; gap: 6px; border-left: 4px solid var(--color-border); }
.result-item.is-correct { border-left-color: var(--color-success); }
.result-item.is-incorrect { border-left-color: var(--color-danger); }
.result-item-index { font-size: 0.72rem; font-weight: 700; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.result-answer { font-size: 0.86rem; }
.result-explanation { font-size: 0.84rem; color: var(--color-text-muted); background: var(--color-bg); border-radius: var(--radius-sm); padding: var(--space-3); }
.essay-grade { display: flex; flex-direction: column; gap: 6px; }
.essay-score { align-self: flex-start; font-weight: 800; font-size: 0.85rem; color: var(--color-primary); background: var(--color-primary-tint); padding: 3px 10px; border-radius: var(--radius-pill); }

/* Version Popup */
.version-popup {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.version-popup.is-visible {
  opacity: 1;
  visibility: visible;
}

.version-popup-content {
  background: white;
  border-radius: 8px;
  padding: 24px;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
  transform: translateY(-20px);
  transition: transform 0.3s ease;
}

.version-popup.is-visible .version-popup-content {
  transform: translateY(0);
}

.version-popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.version-popup-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--color-text);
}

.version-popup-version {
  background-color: var(--color-primary);
  color: #fff;
  padding: 4px 8px;
  border-radius: 4px;
  font-weight: 600;
}

.version-popup-content p {
  margin-bottom: 16px;
  line-height: 1.5;
  color: var(--color-text-muted);
}

.version-popup-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.update-btn {
  background-color: var(--color-primary);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
  transition: background-color 0.2s;
}

.update-btn:hover {
  background-color: var(--color-primary-dark);
}

.update-btn:disabled {
  background-color: #6c757d;
  cursor: not-allowed;
}

.update-badge {
  display: inline-block;
  margin-top: var(--space-2);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: var(--color-danger);
  color: #fff;
}

/* Legibility check modal -- blocks continuing with a source image Gemini
   flagged as hard to read, until the user reuploads or ignores it. Uses the
   app's real design tokens (unlike .version-popup above, which hardcodes
   colors and doesn't adapt to dark mode) so it looks correct in both themes. */
.legibility-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: var(--space-4);
}
.legibility-modal-content {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  padding: var(--space-5);
  max-width: 380px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.legibility-modal-thumb {
  width: 100%;
  max-height: 200px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-bg);
}
.legibility-modal-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--color-text);
}
.legibility-modal-reason {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  line-height: 1.5;
}
.legibility-modal-actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

/* Student Identity modal -- same tokens/pattern as .legibility-modal above
   (theme-correct, no hardcoded colors), just taller/scrollable to fit the
   full field list. */
.identity-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: var(--space-4);
}
.identity-modal-content {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  padding: var(--space-5);
  max-width: 420px;
  width: 100%;
  max-height: calc(100vh - var(--space-8));
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.identity-modal-headrow { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); }
.identity-modal-title { font-size: 1.1rem; font-weight: 700; }
.identity-photo-row { display: flex; align-items: center; gap: var(--space-4); }
.identity-photo-preview {
  width: 72px; height: 72px; border-radius: 50%; flex-shrink: 0; overflow: hidden;
  background: var(--color-primary-tint); color: var(--color-primary);
  display: flex; align-items: center; justify-content: center;
}
.identity-photo-preview img { width: 100%; height: 100%; object-fit: cover; }
.identity-photo-actions { display: flex; flex-direction: column; gap: var(--space-2); flex: 1; }
.identity-photo-actions .btn { padding: 10px 16px; font-size: 0.85rem; }
.identity-field-grid { display: flex; flex-direction: column; gap: var(--space-3); }
.identity-modal-error { font-size: 0.85rem; color: var(--color-danger); }

/* Monitoring tab -- list uses the same card rhythm as .library-list/.exam-card,
   the detail modal reuses .identity-modal's positioning/sizing rules exactly. */
.monitoring-list { display: flex; flex-direction: column; gap: var(--space-4); }
.monitoring-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); box-shadow: var(--shadow-card); padding: var(--space-4) var(--space-5); display: flex; flex-direction: column; gap: var(--space-2); align-items: flex-start; }
.monitoring-detail-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: var(--space-4);
}
.monitoring-detail-modal-content {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  padding: var(--space-5);
  max-width: 420px;
  width: 100%;
  max-height: calc(100vh - var(--space-8));
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.monitoring-attempt-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-3) 0; border-bottom: 1px solid var(--color-border); }
.monitoring-attempt-row:last-child { border-bottom: none; }
.monitoring-attempt-score { font-size: 1.05rem; font-weight: 700; color: var(--color-primary); flex-shrink: 0; }

/* Class Sessions tab -- list uses the same card rhythm as .monitoring-list.
   The call overlay reuses .camera-overlay's full-screen black takeover
   almost verbatim (see index.html); only the mount container needs its own
   rule, since it holds a Jitsi-injected <iframe> rather than a <video>. */
.class-session-list { display: flex; flex-direction: column; gap: var(--space-4); }
.class-session-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); box-shadow: var(--shadow-card); padding: var(--space-4) var(--space-5); display: flex; flex-direction: column; gap: var(--space-2); align-items: flex-start; }
.class-call-mount iframe { width: 100%; height: 100%; border: 0; }

/* ============ Class tab + live call: "Obsidian Orbit" skin ============
   Deliberately scoped to the Class tab and the call overlay only -- rest
   of the app keeps its current warm cream/orange theme. switchTab() (see
   app.js) sets #appShell[data-active-tab] so the shared header/nav also
   go dark while Class is the active tab, so it reads as one unified dark
   surface top-to-bottom instead of a black panel dropped under an
   otherwise light header. Colors/shapes are lifted from the reference
   design doc; fonts are approximated with system stacks (Space
   Grotesk/Inter/Geist would need self-hosted font files to use for real,
   can't be linked from a CDN here). */
/* #tab-class only bleeds its own dark background as tall as its content
   (e.g. the empty "No classes yet" state is short), but .app-shell itself
   -- the actual full-viewport-height element sitting behind it -- keeps
   its own cream/near-black background, which then shows through as a
   seam below short content, down to the fixed bottom-nav. Recoloring
   .app-shell directly (it's already min-height:100vh) removes that seam
   regardless of content length, instead of trying to guess a min-height
   for #tab-class across breakpoints. */
#appShell[data-active-tab="class"] {
  background: #131313;
  --oo-bg: #131313;
  --oo-bg-deep: #0e0e0e;
  --oo-surface: #201f1f;
  --oo-border: #3a3939;
  --oo-primary: #ffbd8a;
  --oo-on-primary: #4e2600;
  --oo-secondary: #98cbff;
  --oo-text: #e5e2e1;
  --oo-text-muted: #a38c7d;
}

#appShell[data-active-tab="class"] .app-header {
  background: var(--oo-bg-deep);
  border-bottom: 1px solid var(--oo-border);
}
#appShell[data-active-tab="class"] .app-header-back,
#appShell[data-active-tab="class"] #versionButton { color: var(--oo-text-muted); }
#appShell[data-active-tab="class"] .app-header-version { color: var(--oo-text-muted); }

#appShell[data-active-tab="class"] .bottom-nav {
  background: var(--oo-bg-deep);
  border-color: var(--oo-border);
}
#appShell[data-active-tab="class"] .bottom-nav-item { color: var(--oo-text-muted); }
#appShell[data-active-tab="class"] .bottom-nav-item.is-active { color: var(--oo-primary); }
#appShell[data-active-tab="class"] .bottom-nav-item.is-active .bottom-nav-icon {
  background: transparent;
  color: var(--oo-primary);
  filter: drop-shadow(0 0 6px rgba(255, 149, 51, 0.65));
}

/* Bleeds the dark background flush to the header/nav edges by canceling
   .screen's own padding with an equal negative margin, then re-applying
   the same padding as internal padding -- content sits in the exact same
   place, only the background now fills the whole panel instead of a
   padded-in patch. */
#appShell[data-active-tab="class"] #tab-class {
  background: var(--oo-bg);
  color: var(--oo-text);
  margin: calc(var(--space-4) * -1) calc(var(--space-4) * -1) calc(var(--space-8) * -1);
  padding: var(--space-4) var(--space-4) var(--space-8);
}
#appShell[data-active-tab="class"] #tab-class .screen-title { color: var(--oo-text); }
#appShell[data-active-tab="class"] #tab-class .screen-sub { color: var(--oo-text-muted); }
#appShell[data-active-tab="class"] #btnStartClass {
  background: var(--oo-primary);
  color: var(--oo-on-primary);
  box-shadow: 0 0 20px rgba(255, 149, 51, 0.35);
}
#appShell[data-active-tab="class"] .class-session-card {
  background: var(--oo-surface);
  border-color: var(--oo-border);
  box-shadow: none;
  border-radius: 10px;
}
#appShell[data-active-tab="class"] .class-session-card .exam-card-title { color: var(--oo-text); }
#appShell[data-active-tab="class"] .class-session-card .exam-card-meta { color: var(--oo-text-muted); }
/* Join/Resume is the primary action (orange); Copy Link is secondary
   (blue) -- same primary/secondary split as the reference doc's button
   guidance, using the existing js-class-join/js-class-share hooks as
   styling selectors since they're already unique per button. */
#appShell[data-active-tab="class"] .js-class-join { color: var(--oo-primary); }
#appShell[data-active-tab="class"] .js-class-share { color: var(--oo-secondary); }
#appShell[data-active-tab="class"] .empty-note { color: var(--oo-text-muted); }

/* Call overlay: .camera-overlay is already a black takeover by default,
   so this only needs to layer the accent treatment on top -- header
   surface, glowing title/close button -- not a background swap. */
.class-call-overlay { background: #131313; }
.class-call-overlay .camera-overlay-head {
  background: #0e0e0e;
  border-bottom: 1px solid #3a3939;
}
.class-call-overlay #classCallTitle {
  color: #ffbd8a;
  font-weight: 800;
  letter-spacing: 0.01em;
}
.class-call-overlay .camera-close-btn {
  background: #201f1f;
  border: 1px solid #3a3939;
  color: #e5e2e1;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.class-call-overlay .camera-close-btn:hover {
  border-color: #ffbd8a;
  color: #ffbd8a;
}

.identity-summary-row { display: flex; align-items: center; gap: var(--space-3); margin-top: 10px; }
.identity-summary-avatar {
  width: 48px; height: 48px; border-radius: 50%; flex-shrink: 0; overflow: hidden;
  background: var(--color-primary-tint); color: var(--color-primary);
  display: flex; align-items: center; justify-content: center;
}
.identity-summary-avatar img { width: 100%; height: 100%; object-fit: cover; }
.identity-summary-body { flex: 1; min-width: 0; }
.identity-summary-name { font-weight: 700; font-size: 0.94rem; }
.identity-summary-meta { font-size: 0.78rem; color: var(--color-text-muted); }

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 20px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: .4s;
  border-radius: 34px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 12px;
  width: 12px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--color-primary);
}

input:checked + .slider:before {
  transform: translateX(20px);
}

.toggle-label {
  font-size: 14px;
  color: var(--text-secondary);
  margin-left: 8px;
  vertical-align: middle;
}

/* Quiz Toggle Switch */
.quiz-toggle-container {
  margin-top: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Library Menu */
.library-menu {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 100;
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  padding: 8px 0;
  min-width: 160px;
}

.library-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 16px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-primary);
  transition: background-color 0.2s;
}

.library-menu button:hover {
  background-color: #f5f5f5;
}

/* Library History */
.library-history {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #eee;
  font-size: 12px;
  color: var(--text-secondary);
}

.history-item {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

/* Camera overlay */
.camera-overlay { position: fixed; inset: 0; background: #000; z-index: 100; display: flex; flex-direction: column; max-width: 480px; margin: 0 auto; }
.camera-overlay-head { display: flex; align-items: center; justify-content: space-between; padding: var(--space-4); color: #fff; font-weight: 700; }
.camera-close-btn { width: 32px; height: 32px; border-radius: 50%; background: rgba(255, 255, 255, 0.15); color: #fff; display: flex; align-items: center; justify-content: center; }
.camera-viewport { flex: 1; display: flex; align-items: center; justify-content: center; overflow: hidden; background: #000; }
.camera-video { width: 100%; height: 100%; object-fit: cover; }
.camera-error { color: #fff; text-align: center; padding: var(--space-6); font-size: 0.9rem; }
.camera-controls { padding: var(--space-6) var(--space-4); display: flex; flex-direction: column; align-items: center; gap: var(--space-3); }
.camera-shutter-btn { width: 68px; height: 68px; border-radius: 50%; background: #fff; border: 4px solid rgba(255, 255, 255, 0.4); }
.camera-shutter-btn:disabled { opacity: 0.4; }
.camera-hint { color: rgba(255, 255, 255, 0.7); font-size: 0.78rem; text-align: center; max-width: 280px; }

/* ============ Desktop/laptop layout (>=960px) ============
   Everything above this point is the mobile-first base -- this block is
   purely additive, no rule above depends on anything here. 960px is a
   judgment call ("catches most laptops, not most phones/small tablets"),
   not derived from a specific device; adjust if it triggers at an awkward
   width once actually seen rendered. instructor.html has its own separate
   .instructor-shell and is NOT covered by this block -- out of scope, see
   the plan this was built from. */
@media (min-width: 960px) {
  .app-shell {
    max-width: min(1200px, 94vw);
    padding-left: 96px; /* clears the left nav rail below */
    padding-bottom: var(--space-8); /* no bottom nav left to clear */
  }

  /* .app-shell is normally centered with a capped width, which is
     invisible on every other tab (cream content against the shell's own
     cream background) but turns into a visible gap of stray body-cream
     down the right edge once the shell goes near-black for Class -- same
     fix as .class-call-overlay below: let it actually fill the viewport
     instead of floating centered in it. */
  #appShell[data-active-tab="class"] {
    max-width: none;
    margin: 0;
  }

  /* Bottom tab bar -> left icon rail. .bottom-nav-item/.bottom-nav-icon/
     .bottom-nav-label need zero changes -- each item is already an
     icon-over-label vertical stack, so this is purely repositioning the
     container, not restyling its children. */
  .bottom-nav {
    left: 0;
    transform: none;
    top: 0;
    bottom: 0;
    width: 88px;
    max-width: none;
    height: auto;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    gap: var(--space-2);
    padding-top: calc(var(--header-height) + var(--space-4));
    padding-bottom: 0;
    border-top: none;
    border-right: 1px solid var(--color-border);
  }

  /* Live class call: today .class-call-overlay just inherits
     .camera-overlay's phone-capture sizing verbatim (fixed, inset:0,
     capped at 480px and centered) -- fine for a quick photo capture, but
     it means an active class call sits in a narrow floating column with
     the left nav rail buried underneath it, even on a 1440px monitor.
     Widen it to start after the rail and fill the rest of the viewport;
     the video grid/filmstrip/toolbar inside are Jitsi's own iframe
     content (meet.jit.si, cross-origin) and already lay themselves out
     responsively -- we can't restyle them directly, but handing Jitsi a
     realistically-sized box instead of a phone-width one lets its own
     responsive layout do the rest. */
  .class-call-overlay {
    left: 88px;
    max-width: none;
    margin: 0;
  }

  /* List-heavy screens -> responsive multi-column grids. Cards already
     render as flat sibling elements (renderLibrary()/renderMonitoring()/
     renderClassTab() in app.js), so this is a pure CSS swap. */
  .library-list, .monitoring-list, .class-session-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    align-items: start;
  }

  /* Home tab: 2-column layout via the .home-col-main/.home-col-side
     wrapper divs added to index.html specifically for this. (Confirmed by
     screenshot: only 2 stat cards exist today, so the base 2-col rule
     already fits -- no override needed here; a 4-up assumption looked
     wrong once actually rendered.) */
  #tab-home {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: var(--space-6);
    align-items: start;
  }

  /* Quiz-taking/results/generating/source all stay at a comfortable
     reading width, centered, rather than stretching across the full
     widened shell -- confirmed by screenshot: an uncapped Source step just
     left its 3 upload-option cards very wide with a lot of dead horizontal
     padding, not actually more useful. Configure and Manual Builder are
     the two steps that get a wide 2-col treatment instead (see below),
     since they're controls/editor+list, not a single piece of content. */
  #stepQuiz, #stepResults, #stepGenerating, #stepSource {
    max-width: 720px;
    margin-left: auto;
    margin-right: auto;
    width: 100%;
  }

  /* Configure step: these are controls, not reading content, so pairing
     them is a real win. Title/Question-Types/empty-note/Generate button
     span the full width (Question Types is the tallest card -- a list of
     6 type toggles -- so pairing it beside a short card would leave one
     side awkwardly empty); Complexity+Count and Time-Limit+Quote pair up
     two-per-row in the remaining space. */
  #stepConfigure {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-4);
    align-items: start;
  }
  #stepConfigure > div:first-child,
  #stepConfigure #typeCard,
  #stepConfigure #configureEmptyNote,
  #stepConfigure #btnGenerateExam {
    grid-column: 1 / -1;
  }

  /* Manual Builder: the question-entry form and the live "Questions
     Added" list are a natural editor/preview pair -- side by side lets you
     see what you've built so far without scrolling past the form every
     time. Time Limit + the action buttons span full width below, since
     they're finalization controls, not part of the editor pair. */
  #stepManualBuilder {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-4);
    align-items: start;
  }
  #stepManualBuilder > div:first-child,
  #manualTimeLimitCard,
  #btnRegenerateQuiz, #btnStartManualExam, #btnSaveAsNewCopy, #btnDeleteQuiz {
    grid-column: 1 / -1;
  }

  /* Scratchpad (math/calculation question canvas) grows since it's a
     drawing surface, not text. */
  .scratchpad-viewport { height: 600px; }

  /* Profile: cards vary a lot in height (Gemini Keys and Backup & Restore
     are tall; Appearance/About/Data are one-liners), and the DOM order
     interleaves big and small cards -- a naive grid-auto-flow 2-up would
     pair a tiny card against a tall one and leave an ugly gap, and a
     wrapper-div split (like Home's) would require physically reordering
     the DOM, changing the card order on mobile too. Explicit placement
     sidesteps both: each card gets a hand-picked column+row (bigger
     account-level cards on the left, smaller settings/info cards on the
     right) with zero effect on source order or the mobile layout, since
     grid-column/grid-row only apply inside this breakpoint. */
  #tab-profile {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: var(--space-6);
    align-items: start;
    max-width: 900px;
  }
  #tab-profile > .profile-hero { grid-column: 1 / -1; grid-row: 1; }
  #profileIdentityCard  { grid-column: 1; grid-row: 2; }
  #profileGeminiCard    { grid-column: 1; grid-row: 3; }
  #profileBackupCard    { grid-column: 1; grid-row: 4; }
  #profileAppearanceCard{ grid-column: 2; grid-row: 2; }
  #profileUpdatesCard   { grid-column: 2; grid-row: 3; }
  #profileAboutCard     { grid-column: 2; grid-row: 4; }
  #profileDataCard      { grid-column: 2; grid-row: 5; }
  #profileInstructorCard{ grid-column: 2; grid-row: 6; }
}
