/* Google Fonts — must come before the Tailwind import */
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Lora:wght@500;600;700&display=swap");

@import "tailwindcss";

/* =============================================================================
   Mr. Drew's Assignment Creator — design system  ("Open Workspace")
   Identity: a well-kept teacher's desk, now laid out as a workspace.
   A solid chalkboard-green sidebar, flat ruled surfaces (elevation is earned,
   not decorative), Lora serif for authority, and the signature: everything
   in the answer key wears red pen — the color teachers actually grade in.
   ============================================================================= */

@layer base {
  :root {
    /* palette */
    --paper: #f0f4f1;
    --panel: #ffffff;
    --ink: #1e2d28;
    --ink-soft: #58706a;
    --ink-faint: #8aa099;
    --board: #2f6b58;
    --board-deep: #245546;
    --board-tint: #e4eeea;
    --board-glow: rgba(47, 107, 88, 0.12);
    --redpen: #b8412f;
    --redpen-ink: #8c3022;
    --redpen-tint: #faece9;
    --gold: #b98a23;
    --gold-ink: #7a5a14;
    --gold-tint: #faf3e2;
    --line: #dde4df;
    --line-strong: #c5d0cb;
    --field-bg: #ffffff;
    --hover-bg: #f2f6f4;
    --tab-track: #e6ecea;
    --chip-neutral-bg: #eaeeec;
    --empty-bg: #fafcfb;
    --disabled-bg: #eaeeec;
    --disabled-ink: #97a8a2;

    /* tokenized feedback colors (light) */
    --alert-error-bg: var(--redpen-tint);
    --alert-error-border: #e8c5be;
    --alert-error-ink: var(--redpen-ink);
    --alert-warn-bg: var(--gold-tint);
    --alert-warn-border: #e9d8a6;
    --alert-warn-ink: var(--gold-ink);
    --alert-info-bg: var(--board-tint);
    --alert-info-border: #cde0d8;
    --alert-info-ink: var(--board-deep);

    --shadow-sm: 0 1px 2px rgba(34, 49, 44, 0.05);
    /* elevation is reserved for things that truly float */
    --shadow-pop: 0 10px 34px rgba(34, 49, 44, 0.14), 0 2px 8px rgba(34, 49, 44, 0.06);
    --shadow-modal: 0 24px 60px rgba(20, 30, 26, 0.28), 0 4px 14px rgba(20, 30, 26, 0.14);
    color-scheme: light;

    /* type */
    --font-display: "Lora", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
    --font-body: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Consolas, Menlo, monospace;

    --radius: 12px;
    --radius-sm: 8px;
    --radius-xs: 5px;
    --transition: 0.18s ease;
    --transition-fast: 0.1s ease;

    --sidebar-w: 264px;
  }

  /* The same desk after dark */
  html[data-theme="dark"] {
    --paper: #111815;
    --panel: #1b2320;
    --ink: #e2eae5;
    --ink-soft: #92aaa2;
    --ink-faint: #6c847c;
    --board: #4d9c82;
    --board-deep: #7bc0a8;
    --board-tint: #1e3028;
    --board-glow: rgba(77, 156, 130, 0.15);
    --redpen: #e07a63;
    --redpen-ink: #f0a795;
    --redpen-tint: #38221e;
    --gold: #d3a94c;
    --gold-ink: #e2c47e;
    --gold-tint: #342d1a;
    --line: #263028;
    --line-strong: #374440;
    --field-bg: #151c18;
    --hover-bg: #1f2a26;
    --tab-track: #161d1a;
    --chip-neutral-bg: #262f2b;
    --empty-bg: #171e1a;
    --disabled-bg: #222b27;
    --disabled-ink: #5d726b;

    --alert-error-bg: var(--redpen-tint);
    --alert-error-border: #5a2f26;
    --alert-error-ink: #f0a795;
    --alert-warn-bg: var(--gold-tint);
    --alert-warn-border: #564820;
    --alert-warn-ink: #e2c47e;
    --alert-info-bg: var(--board-tint);
    --alert-info-border: #2d5040;
    --alert-info-ink: #8dcbb5;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-pop: 0 12px 36px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-modal: 0 24px 60px rgba(0, 0, 0, 0.6), 0 4px 14px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }

  html[data-theme="dark"] .toast { background: #e2eae5; color: #111815; }
  html[data-theme="dark"] .brand-mark { color: #f1f5f2; }

  * { box-sizing: border-box; }

  html, body {
    margin: 0;
    padding: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 14.75px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  /* Wider, clearer type ramp — levels separated by size AND family/weight */
  h1, h2, h3 {
    font-family: var(--font-display);
    font-weight: 700;
    letter-spacing: -0.012em;
    margin: 0;
    line-height: 1.2;
    color: var(--ink);
  }
  h1 { font-size: 2.1rem; }
  h2 { font-size: 1.35rem; }
  h3 { font-size: 1.08rem; }

  a { color: var(--board); text-decoration: none; }
  a:hover { text-decoration: underline; }

  :focus-visible {
    outline: 2px solid var(--board);
    outline-offset: 2px;
    border-radius: 4px;
  }

  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
  }
}

/* =====================================================================
   KEYFRAME ANIMATIONS  (used sparingly — overlays & real state changes)
   ===================================================================== */

@keyframes spin { to { transform: rotate(360deg); } }

@keyframes fade-in-up {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes slide-up {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

@keyframes step-complete {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.18); }
  100% { transform: scale(1); }
}

@keyframes skeleton-pulse {
  0%, 100% { opacity: 0.55; }
  50%      { opacity: 1; }
}

@layer components {

  /* =====================================================================
     APP SHELL — fixed left sidebar + scrolling content
     ===================================================================== */
  .app { display: flex; min-height: 100vh; align-items: stretch; }

  .content { flex: 1; min-width: 0; }
  /* pages opt into padding; the Create flow renders full-bleed */
  .page { padding: 36px 48px 90px; }
  .page-narrow { max-width: 1120px; }

  /* ---------- sidebar ---------- */
  .sidebar {
    width: var(--sidebar-w); flex: none;
    background: var(--panel);
    border-right: 1px solid var(--line);
    display: flex; flex-direction: column;
    position: sticky; top: 0; height: 100vh;
    z-index: 40;
  }
  .sidebar-brand {
    display: flex; align-items: center; gap: 11px;
    padding: 20px 18px 16px;
    white-space: nowrap; text-decoration: none;
  }
  .sidebar-brand:hover { text-decoration: none; }
  .brand-mark {
    width: 34px; height: 34px; border-radius: 9px; flex: none;
    background: linear-gradient(135deg, var(--board) 0%, var(--board-deep) 100%);
    color: #fff;
    display: inline-flex; align-items: center; justify-content: center;
    box-shadow: 0 2px 6px rgba(47, 107, 88, 0.35);
  }
  .brand-name { font-family: var(--font-display); font-weight: 700; font-size: 1.02rem; color: var(--ink); line-height: 1.15; }
  .brand-sub { font-size: 0.72rem; color: var(--ink-soft); font-weight: 500; }

  .sidebar-nav { padding: 4px 12px; display: flex; flex-direction: column; gap: 2px; }
  .navrow {
    display: flex; align-items: center; gap: 11px;
    height: 40px; padding: 0 12px; border-radius: var(--radius-sm);
    color: var(--ink-soft); font-weight: 500; font-size: 0.93rem; cursor: pointer;
    transition: background var(--transition), color var(--transition);
  }
  .navrow:hover { background: var(--hover-bg); color: var(--ink); text-decoration: none; }
  .navrow.active { background: var(--board-tint); color: var(--board-deep); font-weight: 600; }
  .navrow svg { flex: none; }

  .sidebar-scroll { flex: 1; overflow-y: auto; padding: 8px 12px 12px; }
  .sidebar-label {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 10px 8px;
    font-family: var(--font-mono); font-size: 0.66rem; font-weight: 700;
    letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-soft);
  }

  /* library folder tree */
  .tree-group { margin-bottom: 1px; }
  .tree-folder {
    display: flex; align-items: center; gap: 8px;
    width: 100%; text-align: left;
    padding: 7px 10px; border: 0; background: none;
    border-radius: var(--radius-xs); cursor: pointer;
    color: var(--ink); font-family: var(--font-body); font-weight: 600; font-size: 0.83rem;
    transition: background var(--transition);
  }
  .tree-folder:hover { background: var(--hover-bg); }
  .tree-folder .chev { transition: transform var(--transition); color: var(--ink-soft); flex: none; }
  .tree-folder .tree-count { margin-left: auto; font-size: 0.72rem; color: var(--ink-faint); font-weight: 600; }
  .tree-leaf {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 10px 6px 30px; border-radius: var(--radius-xs);
    color: var(--ink-soft); font-size: 0.82rem; cursor: pointer; text-decoration: none;
    transition: background var(--transition), color var(--transition);
  }
  .tree-leaf:hover { background: var(--hover-bg); color: var(--ink); text-decoration: none; }
  .tree-leaf.active { background: var(--board-tint); color: var(--board-deep); font-weight: 600; }
  .tree-leaf span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .sidebar-foot {
    padding: 12px; border-top: 1px solid var(--line);
    display: flex; align-items: center; gap: 10px;
  }

  /* mobile top-bar fallback */
  .sidebar-toggle { display: none; }

  /* ---------- page heading ---------- */
  .page-head { margin: 2px 0 26px; }
  .page-head p { color: var(--ink-soft); margin: 9px 0 0; max-width: 64ch; font-size: 0.97rem; }

  /* ---------- surfaces ---------- */
  /* Flat panel — ONE separator (a hairline border). No resting shadow. */
  .panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
  }
  .panel-pad { padding: 24px; }

  /* legacy alias kept lean: a flat bordered surface, no decorative shadow */
  .card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 24px;
    transition: border-color var(--transition);
  }
  .card + .card { margin-top: 16px; }

  /* The only things that float get real elevation */
  .pop {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-pop);
    animation: fade-in-up 0.16s ease both;
  }

  /* ---------- buttons ---------- */
  .btn {
    appearance: none;
    border: 1px solid var(--line-strong);
    background: var(--panel);
    color: var(--ink);
    font: inherit; font-family: var(--font-body); font-weight: 600; font-size: 0.9rem;
    padding: 9px 16px; border-radius: var(--radius-sm); cursor: pointer;
    display: inline-flex; align-items: center; gap: 7px;
    transition: background var(--transition), border-color var(--transition), box-shadow var(--transition), transform var(--transition-fast);
    white-space: nowrap; user-select: none;
  }
  .btn:hover { background: var(--hover-bg); border-color: var(--board); }
  .btn:active { transform: translateY(1px); }
  .btn:disabled {
    background: var(--disabled-bg); color: var(--disabled-ink);
    border-color: var(--line); cursor: not-allowed; transform: none;
  }

  .btn-primary {
    background: var(--board); border-color: var(--board); color: #fff;
    box-shadow: 0 2px 6px rgba(47, 107, 88, 0.25);
  }
  .btn-primary:hover { background: var(--board-deep); border-color: var(--board-deep); box-shadow: 0 4px 14px rgba(47, 107, 88, 0.32); }
  html[data-theme="dark"] .btn-primary { color: #0d1512; }
  .btn-primary:disabled { background: var(--disabled-bg); color: var(--disabled-ink); border-color: var(--line); box-shadow: none; }

  .btn-danger { color: var(--redpen); border-color: var(--line-strong); background: var(--panel); }
  .btn-danger:hover { background: var(--redpen-tint); border-color: var(--redpen); }

  .btn-ghost { border-color: transparent; background: none; }
  .btn-ghost:hover { background: var(--hover-bg); border-color: transparent; }

  .btn-sm { padding: 6px 12px; font-size: 0.83rem; border-radius: var(--radius-xs); }
  .btn-lg { padding: 12px 24px; font-size: 0.98rem; border-radius: var(--radius); }
  .btn-block { width: 100%; justify-content: center; }

  /* ---------- icon button (min 36px touch target) ---------- */
  .icon-btn {
    border: 1px solid var(--line); background: var(--field-bg); border-radius: var(--radius-xs);
    width: 36px; height: 36px; cursor: pointer; line-height: 1; flex: none;
    display: inline-flex; align-items: center; justify-content: center; color: var(--ink-soft);
    transition: background var(--transition), border-color var(--transition), color var(--transition), transform var(--transition-fast);
  }
  .icon-btn:hover { border-color: var(--board); color: var(--ink); background: var(--board-tint); }
  .icon-btn:disabled { background: var(--disabled-bg); color: var(--disabled-ink); border-color: var(--line); cursor: default; }
  .icon-btn.danger:hover { border-color: var(--redpen); color: var(--redpen); background: var(--redpen-tint); }
  .theme-toggle { width: 40px; height: 40px; border-radius: 9px; }

  /* ---------- forms ---------- */
  label.field { display: block; margin-bottom: 16px; }
  .field-label {
    display: block; font-family: var(--font-mono); font-weight: 700; font-size: 0.7rem;
    letter-spacing: 0.08em; text-transform: uppercase;
    margin-bottom: 7px; color: var(--ink-soft);
  }
  .field-hint { font-size: 0.82rem; color: var(--ink-soft); margin-top: 6px; line-height: 1.5; }

  input[type="text"], input[type="password"], input[type="number"], input[type="url"], select, textarea {
    width: 100%; font: inherit; font-family: var(--font-body);
    color: var(--ink); background: var(--field-bg);
    border: 1.5px solid var(--line-strong); border-radius: var(--radius-sm);
    padding: 9px 12px;
    transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
  }
  input:focus, select:focus, textarea:focus {
    border-color: var(--board); outline: none; box-shadow: 0 0 0 3px var(--board-glow);
  }
  textarea { resize: vertical; min-height: 80px; line-height: 1.6; }
  ::placeholder { color: var(--ink-faint); }

  /* underline-only "paper form" input — used on Settings */
  .ul-field { display: block; margin-bottom: 20px; }
  .ul-input {
    width: 100%; font: inherit; font-family: var(--font-body); font-size: 0.95rem;
    color: var(--ink); background: transparent;
    border: 0; border-bottom: 1.5px solid var(--line-strong);
    border-radius: 0; padding: 8px 2px;
    transition: border-color var(--transition);
  }
  .ul-input:focus { outline: none; border-bottom-color: var(--board); box-shadow: none; }
  select.ul-input { padding-left: 0; }

  .row { display: flex; gap: 18px; flex-wrap: wrap; }
  .row > * { flex: 1; min-width: 180px; }

  .check {
    display: flex; align-items: flex-start; gap: 11px; margin: 10px 0; cursor: pointer;
  }
  .check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--board); cursor: pointer; flex: none; }
  .check span { font-size: 0.94rem; }
  .check small { display: block; color: var(--ink-soft); margin-top: 1px; }

  /* ---------- create flow: split workspace ---------- */
  .create-split { display: flex; min-height: 100vh; align-items: stretch; }
  .create-source {
    flex: 0 0 58%; max-width: 58%;
    background: var(--empty-bg); border-right: 1px solid var(--line);
    padding: 36px 44px; display: flex; flex-direction: column;
  }
  .create-aside {
    flex: 1; background: var(--paper);
    padding: 36px 38px; display: flex; flex-direction: column;
  }
  .source-textarea {
    flex: 1; min-height: 360px; width: 100%; resize: none;
    border: 0; outline: none; background: transparent; box-shadow: none;
    font-family: var(--font-body); font-size: 1rem; line-height: 1.7; padding: 6px 0;
    color: var(--ink);
  }
  .source-textarea:focus { box-shadow: none; }

  /* vertical step tracker */
  .vsteps { position: relative; }
  .vsteps::before {
    content: ""; position: absolute; left: 17px; top: 18px; bottom: 18px;
    width: 2px; background: var(--line-strong);
  }
  .vstep { position: relative; display: flex; gap: 14px; padding-bottom: 22px; }
  .vstep:last-child { padding-bottom: 0; }
  .vstep-n {
    width: 36px; height: 36px; flex: none; border-radius: 50%; z-index: 1;
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 0.9rem;
    background: var(--paper); border: 2px solid var(--line-strong); color: var(--ink-soft);
    transition: background var(--transition), border-color var(--transition), color var(--transition);
  }
  .vstep.active .vstep-n { background: var(--board); border-color: var(--board); color: #fff; box-shadow: 0 0 0 4px var(--board-tint); }
  html[data-theme="dark"] .vstep.active .vstep-n { color: #0d1512; }
  .vstep.done .vstep-n { background: var(--board); border-color: var(--board); color: #fff; animation: step-complete 0.3s ease; }
  .vstep-title { font-family: var(--font-body); font-weight: 600; font-size: 0.98rem; color: var(--ink-soft); }
  .vstep.active .vstep-title { font-family: var(--font-display); font-weight: 700; color: var(--board-deep); font-size: 1rem; }
  .vstep-desc { color: var(--ink-soft); font-size: 0.84rem; margin-top: 2px; }

  .tip {
    display: flex; gap: 11px; padding: 14px 15px; border-radius: var(--radius);
    background: var(--board-tint); color: var(--board-deep); font-size: 0.86rem; line-height: 1.5;
  }
  .tip svg { flex: none; margin-top: 1px; }

  /* ---------- choice cards ---------- */
  .choice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 10px; }
  .choice {
    border: 1.5px solid var(--line-strong); border-radius: var(--radius); background: var(--field-bg);
    padding: 14px 15px; cursor: pointer; text-align: left; font: inherit; font-family: var(--font-body);
    transition: border-color var(--transition), background var(--transition), transform var(--transition-fast);
  }
  .choice:hover { border-color: var(--board); transform: translateY(-1px); }
  .choice.selected { border-color: var(--board); background: var(--board-tint); }
  .choice b { display: block; font-size: 0.93rem; font-weight: 600; }
  .choice small { color: var(--ink-soft); font-size: 0.79rem; line-height: 1.35; display: block; margin-top: 4px; }

  /* ---------- segmented tabs (source input) ---------- */
  .tabs {
    display: inline-flex; background: var(--tab-track);
    border-radius: var(--radius-sm); padding: 3px; gap: 2px; margin-bottom: 16px;
  }
  .tab {
    border: 0; background: none; font: inherit; font-family: var(--font-body);
    font-weight: 600; font-size: 0.87rem;
    padding: 7px 16px; border-radius: 6px; cursor: pointer; color: var(--ink-soft);
    transition: background var(--transition), color var(--transition);
  }
  .tab.active { background: var(--panel); color: var(--ink); box-shadow: var(--shadow-sm); }

  /* ---------- badges & chips ---------- */
  .chip {
    display: inline-flex; align-items: center; gap: 5px;
    font-family: var(--font-mono); font-size: 0.68rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
    padding: 3px 9px; border-radius: 6px; flex: none;
    background: var(--board-tint); color: var(--board-deep);
  }
  .chip-pill { border-radius: 99px; }
  .chip-neutral { background: var(--chip-neutral-bg); color: var(--ink-soft); }
  .chip-gold { background: var(--gold-tint); color: var(--gold-ink); }
  .chip-red { background: var(--redpen-tint); color: var(--redpen); }

  .stamp {
    display: inline-flex; align-items: center; gap: 4px;
    font-family: var(--font-mono); font-size: 0.68rem; font-weight: 700;
    letter-spacing: 0.07em; text-transform: uppercase;
    padding: 3px 8px; border: 1.5px solid currentColor; border-radius: 4px;
    transform: rotate(-1.2deg); flex: none;
  }
  .stamp-pass { color: var(--board); background: rgba(47, 107, 88, 0.07); }
  .stamp-warn { color: var(--gold); background: var(--gold-tint); transform: rotate(1deg); }

  /* ---------- answer key (red pen) ---------- */
  .answer-key {
    padding: 13px 15px;
    background: var(--redpen-tint);
    border-left: 3px solid var(--redpen);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  }
  .answer-key + .answer-key { margin-top: 10px; }
  .answer-key .ak-label {
    font-family: var(--font-mono); font-size: 0.67rem; font-weight: 700;
    letter-spacing: 0.1em; text-transform: uppercase; color: var(--redpen);
    display: block; margin-bottom: 7px;
  }
  .answer-key textarea, .answer-key input[type="text"] { background: var(--field-bg); font-size: 0.9rem; }
  .redpen { color: var(--redpen); font-weight: 600; }

  /* ---------- editor: continuous document ---------- */
  .doc { overflow: hidden; }      /* a .panel that holds the question rows */
  .qrow {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) minmax(300px, 360px);
    gap: 22px;
    padding: 24px 26px;
  }
  .qrow + .qrow { border-top: 1px solid var(--line); }
  .qrow.dragging { opacity: 0.4; }
  .qrow.drag-over { background: var(--board-tint); }
  .qrail { display: flex; flex-direction: column; align-items: center; gap: 8px; padding-top: 2px; }
  .qgrip {
    color: var(--ink-faint); cursor: grab; display: inline-flex;
    border: 0; background: none; padding: 2px; border-radius: 4px;
    transition: color var(--transition), background var(--transition);
  }
  .qgrip:hover { color: var(--board); background: var(--hover-bg); }
  .qgrip:active { cursor: grabbing; }
  .qnum { font-family: var(--font-display); font-size: 1.2rem; font-weight: 700; color: var(--board-deep); }

  /* editable assignment title — clear affordance */
  .title-edit { position: relative; display: flex; align-items: center; gap: 8px; margin-left: -8px; }
  .title-edit input {
    font-family: var(--font-display); font-size: 1.75rem; font-weight: 700; color: var(--ink);
    border: 1.5px solid transparent; background: transparent; padding: 4px 8px;
    border-radius: var(--radius-sm); width: 100%; border-bottom: 1.5px dashed var(--line-strong);
    transition: background var(--transition), border-color var(--transition);
  }
  .title-edit input:hover { background: var(--hover-bg); }
  .title-edit input:focus { outline: none; background: var(--field-bg); border-color: var(--board); border-bottom-style: solid; box-shadow: 0 0 0 3px var(--board-glow); }
  .title-edit .pen { color: var(--ink-faint); flex: none; opacity: 0; transition: opacity var(--transition); pointer-events: none; }
  .title-edit:hover .pen { opacity: 1; }
  .qmain { min-width: 0; }
  .qmargin { min-width: 0; }
  .qcard-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
  .qcard-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
  .q-prompt { font-size: 1.02rem; }

  .opt-row { display: flex; align-items: center; gap: 9px; margin: 7px 0; }
  .opt-row input[type="radio"] { accent-color: var(--redpen); width: 17px; height: 17px; flex: none; cursor: pointer; }
  .opt-letter { font-weight: 700; font-size: 0.82rem; color: var(--ink-soft); width: 18px; flex: none; }
  .points-input { width: 56px !important; text-align: center; padding: 6px 4px !important; }

  @media (max-width: 1180px) {
    .qrow { grid-template-columns: 44px minmax(0, 1fr); }
    .qmargin { grid-column: 1 / -1; padding-left: 22px; }
  }

  /* ---------- alerts & toasts (tokenized) ---------- */
  .alert {
    padding: 13px 16px; border-radius: var(--radius-sm); font-size: 0.92rem;
    margin: 14px 0; border: 1px solid; display: flex; gap: 9px; align-items: flex-start;
    animation: fade-in 0.2s ease;
  }
  .alert svg { flex: none; margin-top: 1px; }
  .alert-error { background: var(--alert-error-bg); border-color: var(--alert-error-border); color: var(--alert-error-ink); }
  .alert-warn { background: var(--alert-warn-bg); border-color: var(--alert-warn-border); color: var(--alert-warn-ink); }
  .alert-info { background: var(--alert-info-bg); border-color: var(--alert-info-border); color: var(--alert-info-ink); }

  .toast {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
    background: var(--ink); color: var(--panel);
    padding: 11px 22px; border-radius: 99px; font-size: 0.91rem; font-weight: 600;
    box-shadow: var(--shadow-modal); z-index: 100;
    animation: slide-up 0.22s cubic-bezier(0.34, 1.56, 0.64, 1) both;
    white-space: nowrap;
  }

  /* ---------- spinner ---------- */
  .spinner {
    width: 16px; height: 16px; border-radius: 50%; flex: none;
    border: 2px solid var(--board-glow); border-top-color: var(--board);
    animation: spin 0.7s linear infinite; display: inline-block; vertical-align: -3px;
  }

  /* ---------- generation progress ---------- */
  .progress-list { list-style: none; margin: 22px 0 0; padding: 0; }
  .progress-list li {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 0; font-size: 0.97rem; color: var(--ink-soft);
    border-bottom: 1px solid var(--line);
  }
  .progress-list li:last-child { border-bottom: none; }
  .progress-list li.active { color: var(--ink); font-weight: 600; }
  .progress-list li.done { color: var(--board); }
  .progress-dot { width: 20px; text-align: center; flex: none; }

  /* ---------- library: search + filters ---------- */
  .lib-toolbar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 28px; }
  .search-wrap { position: relative; flex: 1; max-width: 480px; min-width: 240px; }
  .search-wrap svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--ink-soft); }
  .search-wrap input { padding-left: 38px; }
  .fchip {
    font-size: 0.79rem; font-weight: 600; padding: 7px 14px; border-radius: 99px; cursor: pointer;
    border: 1.5px solid var(--line-strong); background: var(--panel); color: var(--ink-soft);
    transition: border-color var(--transition), color var(--transition), background var(--transition);
  }
  .fchip:hover { border-color: var(--board); color: var(--board-deep); }
  .fchip.active { border-color: var(--board); background: var(--board-tint); color: var(--board-deep); }

  /* grouped library lists */
  .lib-group { margin-bottom: 32px; }
  .lib-group-head {
    display: flex; align-items: center; gap: 11px;
    padding-bottom: 10px; margin-bottom: 14px; border-bottom: 1px solid var(--line);
  }
  .lib-group-head h2 { font-size: 1.3rem; }
  .lib-rows { overflow: hidden; }   /* a .panel */
  .lib-row { display: flex; align-items: center; gap: 16px; padding: 15px 18px; transition: background var(--transition); }
  .lib-row + .lib-row { border-top: 1px solid var(--line); }
  .lib-row:hover { background: var(--hover-bg); }
  .lib-row-title { font-family: var(--font-display); font-weight: 600; font-size: 1.02rem; color: var(--ink); cursor: pointer; }
  .lib-row-title:hover { color: var(--board-deep); text-decoration: underline; text-underline-offset: 2px; }
  .lib-meta { color: var(--ink-soft); font-size: 0.83rem; margin: 3px 0 0; }
  .lib-actions { display: flex; align-items: center; gap: 8px; flex: none; }

  /* skeletons */
  .skeleton-card { animation: skeleton-pulse 1.5s ease-in-out infinite; }
  .skeleton-line { background: var(--line); border-radius: 5px; height: 14px; margin-bottom: 10px; }
  .skeleton-line.short { width: 55%; }
  .skeleton-line.medium { width: 75%; }
  .skeleton-line.full { width: 100%; }
  .skeleton-chip { background: var(--line); border-radius: 6px; height: 20px; width: 56px; margin-bottom: 12px; }

  .empty {
    text-align: center; padding: 64px 24px; color: var(--ink-soft);
    border: 1.5px dashed var(--line-strong); border-radius: var(--radius);
    background: var(--empty-bg);
  }
  .empty h3 { color: var(--ink); margin-bottom: 8px; }

  /* ---------- settings: flush two-column ---------- */
  .settings-grid { display: flex; gap: 48px; align-items: flex-start; }
  .settings-toc {
    width: 210px; flex: none; position: sticky; top: 36px;
    display: flex; flex-direction: column; gap: 1px;
  }
  .toc-link {
    display: flex; align-items: center; gap: 9px; padding: 8px 12px;
    border-left: 2px solid transparent; color: var(--ink-soft);
    font-size: 0.87rem; font-weight: 500; cursor: pointer; text-decoration: none;
    transition: color var(--transition), background var(--transition);
  }
  .toc-link:hover { color: var(--ink); background: var(--hover-bg); text-decoration: none; }
  .toc-link.active { color: var(--board-deep); border-left-color: var(--board); font-weight: 600; }
  .settings-body { flex: 1; min-width: 0; }
  .sec { padding: 34px 0; border-top: 1px solid var(--line); }
  .sec:first-child { border-top: 0; padding-top: 4px; }
  .sec > h2 { margin-bottom: 6px; }
  .sec-hint { color: var(--ink-soft); font-size: 0.9rem; margin: 0 0 20px; max-width: 70ch; }

  /* provider list — flat rows, not nested cards */
  .provider-list { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
  .provider-row {
    display: flex; align-items: center; gap: 13px; padding: 14px 16px;
    cursor: pointer; background: var(--panel); border-left: 3px solid transparent;
    transition: background var(--transition);
  }
  .provider-row + .provider-row { border-top: 1px solid var(--line); }
  .provider-row:hover { background: var(--hover-bg); }
  .provider-row.selected { background: var(--board-tint); border-left-color: var(--board); }
  .provider-row input { accent-color: var(--board); width: 18px; height: 18px; flex: none; }
  .provider-row b { font-size: 0.95rem; }
  .provider-row .selected & b { color: var(--board-deep); }
  .provider-row small { color: var(--ink-soft); display: block; }
  .local-tag { margin-left: auto; }

  /* slider */
  input[type="range"] { accent-color: var(--board); }

  /* ---------- modal ---------- */
  .modal-scrim {
    position: fixed; inset: 0; z-index: 100; background: rgba(20, 30, 26, 0.5);
    display: flex; align-items: flex-start; justify-content: center;
    padding: 40px 16px; overflow-y: auto; animation: fade-in 0.15s ease;
  }
  .modal {
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow-modal); animation: fade-in-up 0.18s ease both;
  }

  /* ---------- misc helpers ---------- */
  .sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
  }
  .muted { color: var(--ink-soft); }
  .faint { color: var(--ink-faint); }
  .small { font-size: 0.84rem; }
  .spacer { flex: 1; }
  .hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }
  code { font-family: var(--font-mono); font-size: 0.88em; background: var(--chip-neutral-bg); padding: 1px 5px; border-radius: 4px; }

  /* =====================================================================
     RESPONSIVE — collapse the sidebar into a top bar on small screens
     ===================================================================== */
  @media (max-width: 880px) {
    .app { flex-direction: column; }
    .sidebar {
      width: 100%; height: auto; position: sticky; top: 0;
      flex-direction: row; align-items: center; gap: 6px;
      border-right: 0; border-bottom: 1px solid var(--line);
      padding: 0 12px;
    }
    .sidebar-brand { padding: 12px 6px; }
    .brand-sub { display: none; }
    .sidebar-nav { flex-direction: row; padding: 0; margin-left: 8px; }
    .navrow { height: 44px; }
    .navrow span.navrow-label { display: none; }
    .sidebar-scroll { display: none; }   /* tree hidden on mobile; Library page covers it */
    .sidebar-foot { margin-left: auto; border-top: 0; padding: 8px 0; }
    .sidebar-foot .btn-block { width: auto; }
    .page { padding: 24px 18px 80px; }
    .create-split { flex-direction: column; min-height: 0; }
    .create-source, .create-aside { flex: 1 1 auto; max-width: 100%; border-right: 0; }
    .create-source { border-bottom: 1px solid var(--line); }
    .settings-grid { flex-direction: column; gap: 18px; }
    .settings-toc { position: static; flex-direction: row; flex-wrap: wrap; width: 100%; gap: 4px; }
    .toc-link { border-left: 0; border-bottom: 2px solid transparent; }
    .toc-link.active { border-left: 0; border-bottom-color: var(--board); }
  }

  @media (max-width: 560px) {
    .page { padding: 20px 14px 72px; }
    .qrow { padding: 18px 14px; gap: 14px; }
    h1 { font-size: 1.6rem; }
  }
}
