/* ============================================================
   ClassicalCoach — Design System
   Palette: parchment, forest, antique gold
   Type: Boska (display) + Source Serif 4 (body)
   ============================================================ */

:root {
  /* ---------- Color: Parchment & Forest ---------- */
  --parchment-50:  #fbf6e9;
  --parchment-100: #f6efdc;
  --parchment-200: #efe4c4;
  --parchment-300: #e6d6a8;
  --parchment-400: #d9c389;

  --ink-900: #1f1a12;   /* near-black ink, warm */
  --ink-800: #2c2519;
  --ink-700: #3d3424;
  --ink-600: #534632;
  --ink-500: #6e6045;
  --ink-400: #8c7d62;
  --ink-300: #a89a7d;

  --forest-900: #0f2a1f;
  --forest-800: #143524;
  --forest-700: #1b4730;   /* PRIMARY accent */
  --forest-600: #235a3d;
  --forest-500: #2f7150;
  --forest-300: #6ea089;
  --forest-100: #cfdfd4;

  --gold-700: #8a6a1f;
  --gold-600: #a47e25;     /* HIGHLIGHT accent */
  --gold-500: #b8902c;
  --gold-400: #c9a44a;
  --gold-300: #ddc079;
  --gold-200: #ecd9a5;
  --gold-100: #f5e9c6;

  --crimson-700: #843a2a;  /* markup/red-ink for revision */
  --crimson-500: #a64a36;
  --rule-line:   rgba(31, 26, 18, 0.14);
  --rule-strong: rgba(31, 26, 18, 0.28);

  /* ---------- Surfaces ---------- */
  --bg:        var(--parchment-100);
  --bg-soft:   var(--parchment-50);
  --bg-card:   #fdf9ec;
  --bg-deep:   var(--parchment-200);
  --bg-shadow: rgba(60, 42, 18, 0.08);

  /* ---------- Type ---------- */
  --font-display: 'Boska', 'Cormorant Garamond', 'Georgia', serif;
  --font-body:    'Source Serif 4', 'Source Serif Pro', 'Georgia', serif;
  --font-ui:      'Source Serif 4', 'Georgia', serif;
  --font-dyslexic: 'OpenDyslexic', 'Source Serif 4', serif;

  --fs-xs:   0.78rem;   /* 12.5px */
  --fs-sm:   0.92rem;   /* 14.7px */
  --fs-base: 1.05rem;   /* 16.8px */
  --fs-lg:   1.18rem;
  --fs-xl:   1.45rem;
  --fs-2xl:  1.85rem;
  --fs-3xl:  2.45rem;
  --fs-4xl:  3.2rem;
  --fs-hero: 4.2rem;

  --lh-tight: 1.15;
  --lh-snug:  1.35;
  --lh-body:  1.65;
  --lh-loose: 1.85;

  /* ---------- Spacing ---------- */
  --s-1: 0.25rem;
  --s-2: 0.5rem;
  --s-3: 0.75rem;
  --s-4: 1rem;
  --s-5: 1.5rem;
  --s-6: 2rem;
  --s-7: 3rem;
  --s-8: 4rem;
  --s-9: 6rem;

  /* ---------- Radii & Shadows ---------- */
  --r-sm: 4px;
  --r-md: 8px;
  --r-lg: 14px;
  --r-xl: 22px;

  --shadow-sm: 0 1px 2px rgba(60,42,18,0.06), 0 2px 6px rgba(60,42,18,0.05);
  --shadow-md: 0 4px 14px rgba(60,42,18,0.10), 0 1px 3px rgba(60,42,18,0.06);
  --shadow-lg: 0 18px 40px rgba(60,42,18,0.14), 0 4px 10px rgba(60,42,18,0.08);

  --max-w: 1240px;

  /* ---------- A11y settings (toggled via .root classes) ---------- */
  --reading-scale: 1;
  --reading-spacing: 1;
}

/* OpenDyslexic — loaded only if user enables it (free CDN) */
@font-face {
  font-family: 'OpenDyslexic';
  src: url('https://cdn.jsdelivr.net/npm/open-dyslexic@1.0.3/woff/OpenDyslexic-Regular.woff') format('woff');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'OpenDyslexic';
  src: url('https://cdn.jsdelivr.net/npm/open-dyslexic@1.0.3/woff/OpenDyslexic-Bold.woff') format('woff');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* ============================================================
   BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-body);
  font-size: calc(var(--fs-base) * var(--reading-scale));
  line-height: var(--lh-body);
  color: var(--ink-800);
  background:
    radial-gradient(1200px 800px at 12% -10%, rgba(184,144,44,0.10), transparent 60%),
    radial-gradient(900px 700px at 110% 110%, rgba(27,71,48,0.08), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Subtle parchment grain via SVG noise */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.32;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.55  0 0 0 0 0.42  0 0 0 0 0.18  0 0 0 0.18 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

/* Reading-friendly modes (toggled on <html>) */
html.dys-font, html.dys-font body { font-family: var(--font-dyslexic) !important; letter-spacing: 0.01em; }
html.dys-spacing { --reading-spacing: 1.25; }
html.dys-spacing p, html.dys-spacing li, html.dys-spacing .doc { letter-spacing: 0.02em; word-spacing: 0.08em; line-height: calc(var(--lh-body) * var(--reading-spacing)); }
html.low-stim body::before { display: none; }
html.low-stim { --bg: #f4ecd8; }
html.low-stim body { background: var(--bg); }

/* Headings */
h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 500;
  color: var(--ink-900);
  letter-spacing: -0.005em;
  line-height: var(--lh-tight);
  margin: 0 0 var(--s-3);
}
h1 { font-size: calc(var(--fs-3xl) * var(--reading-scale)); font-weight: 500; }
h2 { font-size: calc(var(--fs-2xl) * var(--reading-scale)); }
h3 { font-size: calc(var(--fs-xl)  * var(--reading-scale)); }
h4 { font-size: calc(var(--fs-lg)  * var(--reading-scale)); font-family: var(--font-body); font-weight: 700; letter-spacing: 0.01em; text-transform: uppercase; color: var(--ink-700); }

p { margin: 0 0 var(--s-4); }
a { color: var(--forest-700); text-decoration-color: var(--gold-400); text-underline-offset: 3px; }
a:hover { color: var(--forest-600); }

::selection { background: var(--gold-200); color: var(--ink-900); }

/* Utility */
.eyebrow {
  font-family: var(--font-body);
  font-size: var(--fs-xs);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold-700);
  font-weight: 600;
}
.script {
  font-family: var(--font-display);
  font-style: italic;
  font-weight: 400;
  color: var(--forest-700);
}
.divider {
  display: flex; align-items: center; gap: var(--s-3);
  color: var(--ink-400);
  font-family: var(--font-body); font-size: var(--fs-xs);
  letter-spacing: 0.2em; text-transform: uppercase;
}
.divider::before, .divider::after {
  content: ""; flex: 1; height: 1px;
  background: linear-gradient(90deg, transparent, var(--rule-line), transparent);
}
hr.rule {
  border: 0; height: 1px;
  background: linear-gradient(90deg, transparent, var(--rule-strong), transparent);
  margin: var(--s-6) 0;
}

/* ============================================================
   APP SHELL
   ============================================================ */
.app {
  position: relative; z-index: 1;
  display: grid;
  grid-template-columns: 264px 1fr;
  min-height: 100vh;
}
@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
}

.sidebar {
  position: sticky; top: 0;
  align-self: start;
  height: 100vh;
  padding: var(--s-6) var(--s-5);
  border-right: 1px solid var(--rule-line);
  background:
    linear-gradient(180deg, rgba(255,250,232,0.6), rgba(255,250,232,0.2)),
    var(--bg-soft);
  display: flex; flex-direction: column; gap: var(--s-5);
  overflow-y: auto;
}
@media (max-width: 960px) {
  .sidebar {
    position: static; height: auto;
    border-right: none;
    border-bottom: 1px solid var(--rule-line);
  }
}

.brand {
  display: flex; align-items: center; gap: var(--s-3);
  text-decoration: none; color: var(--ink-900);
}
.brand .logo { width: 36px; height: 36px; flex-shrink: 0; }
.brand .wordmark {
  font-family: var(--font-display);
  font-size: 1.25rem;
  letter-spacing: 0.005em;
  font-weight: 500;
  line-height: 1;
}
.brand-tag {
  font-size: 9.5px;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--gold-700);
  font-family: var(--font-body);
  margin-top: 4px;
  font-weight: 600;
  line-height: 1.3;
}

.nav {
  display: flex; flex-direction: column; gap: 2px;
  margin-top: var(--s-3);
}
.nav .label {
  font-size: var(--fs-xs);
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-400);
  margin: var(--s-4) var(--s-3) var(--s-2);
}
.nav a {
  display: flex; align-items: center; gap: var(--s-3);
  padding: 10px 12px;
  border-radius: var(--r-md);
  color: var(--ink-700);
  text-decoration: none;
  font-family: var(--font-body);
  font-size: var(--fs-base);
  transition: background 0.18s ease, color 0.18s ease;
}
.nav a:hover { background: rgba(184,144,44,0.10); color: var(--ink-900); }
.nav a.active {
  background: linear-gradient(90deg, rgba(27,71,48,0.10), rgba(27,71,48,0.02));
  color: var(--forest-800);
  box-shadow: inset 3px 0 0 var(--gold-500);
  font-weight: 500;
}
.nav .ico {
  width: 18px; height: 18px;
  color: var(--forest-600); opacity: 0.85;
}

.sidebar .footer-card {
  margin-top: auto;
  padding: var(--s-4);
  border: 1px solid var(--rule-line);
  border-radius: var(--r-lg);
  background: var(--bg-card);
  font-size: var(--fs-sm);
  color: var(--ink-600);
}
.sidebar .footer-card strong { color: var(--ink-900); font-weight: 600; }

/* MAIN */
.main {
  padding: var(--s-6) clamp(var(--s-4), 4vw, var(--s-8));
  max-width: var(--max-w);
  width: 100%;
  min-width: 0;
}
@media (max-width: 480px) {
  .main { padding: var(--s-4) var(--s-4); }
}
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-4);
  padding-bottom: var(--s-5);
  margin-bottom: var(--s-6);
  border-bottom: 1px solid var(--rule-line);
  flex-wrap: wrap;
}
.topbar .title { min-width: 0; flex: 1 1 280px; }
.topbar .title h1 { margin-bottom: 4px; overflow-wrap: break-word; font-size: clamp(1.7rem, 3.4vw, calc(var(--fs-3xl) * var(--reading-scale))); }
.topbar .title .crumbs {
  font-size: var(--fs-xs);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold-700);
  font-weight: 600;
}
.topbar .actions {
  display: flex; gap: var(--s-3); align-items: center; flex-wrap: wrap;
  justify-content: flex-end;
}
@media (max-width: 1100px) {
  .topbar { flex-direction: column; align-items: stretch; gap: var(--s-3); }
  .topbar .title { flex: none; }
  .topbar .actions { justify-content: flex-start; }
}
@media (max-width: 480px) {
  .topbar .actions .btn,
  .topbar .actions select,
  .topbar .actions .mobile-menu { flex: 1 1 auto; justify-content: center; }
}

/* Mobile menu toggle */
.mobile-menu { display: none; }
@media (max-width: 960px) {
  .sidebar { display: none; }
  .sidebar.open { display: flex; }
  .mobile-menu {
    display: inline-flex; align-items: center; gap: var(--s-2);
    padding: 10px 14px; border-radius: var(--r-md);
    background: var(--bg-card); border: 1px solid var(--rule-line);
    font-family: var(--font-body); font-size: var(--fs-sm);
    cursor: pointer;
  }
}

/* ============================================================
   COMPONENTS
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px;
  border-radius: var(--r-md);
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  font-weight: 500;
  letter-spacing: 0.02em;
  text-decoration: none;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.06s ease, background 0.18s ease, border-color 0.18s ease, color 0.18s ease;
  background: var(--bg-card);
  color: var(--ink-800);
  border-color: var(--rule-line);
}
.btn:hover { background: var(--parchment-200); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--forest-700); color: #f5e9c6; border-color: var(--forest-800);
}
.btn-primary:hover { background: var(--forest-600); color: #fff; }
.btn-gold {
  background: linear-gradient(180deg, var(--gold-500), var(--gold-600));
  color: #fffbe9; border-color: var(--gold-700);
  box-shadow: 0 1px 0 rgba(255,255,255,0.25) inset, var(--shadow-sm);
}
.btn-gold:hover { filter: brightness(1.04); }
.btn-ghost { background: transparent; border-color: var(--rule-line); }
.btn-lg { padding: 14px 22px; font-size: var(--fs-base); }
.btn-sm { padding: 7px 12px; font-size: var(--fs-xs); }
.btn:focus-visible { outline: 2px solid var(--gold-600); outline-offset: 2px; }
.btn-block { width: 100%; justify-content: center; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--rule-line);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  box-shadow: var(--shadow-sm);
  position: relative;
}
.card.ornate {
  background:
    linear-gradient(var(--bg-card), var(--bg-card)) padding-box,
    linear-gradient(135deg, var(--gold-300), transparent 35%, transparent 65%, var(--gold-300)) border-box;
  border: 1px solid transparent;
}
.card h3 { margin-bottom: var(--s-3); }
.card .meta {
  font-size: var(--fs-xs);
  color: var(--ink-500);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.tag {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: var(--fs-xs);
  font-family: var(--font-body);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: var(--gold-100);
  color: var(--gold-700);
  border: 1px solid var(--gold-200);
}
.tag.green { background: rgba(27,71,48,0.10); color: var(--forest-700); border-color: rgba(27,71,48,0.20); }
.tag.ink { background: rgba(31,26,18,0.06); color: var(--ink-700); border-color: var(--rule-line); }
.tag.crimson { background: rgba(166,74,54,0.10); color: var(--crimson-700); border-color: rgba(166,74,54,0.25); }

input[type=text], input[type=email], input[type=password], input[type=number], textarea, select {
  width: 100%;
  font-family: var(--font-body);
  font-size: var(--fs-base);
  line-height: var(--lh-body);
  color: var(--ink-900);
  background: var(--bg-soft);
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-md);
  padding: 12px 14px;
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}
textarea { resize: vertical; min-height: 120px; line-height: var(--lh-loose); }
input:focus, textarea:focus, select:focus {
  border-color: var(--forest-600);
  box-shadow: 0 0 0 3px rgba(27,71,48,0.15);
  background: #fffaea;
}
label.field {
  display: block;
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--ink-700);
  margin-bottom: 6px;
  letter-spacing: 0.02em;
}
.help {
  font-size: var(--fs-xs);
  color: var(--ink-500);
  margin-top: 6px;
}

/* Toggle switch */
.switch { position: relative; display: inline-block; width: 46px; height: 26px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; cursor: pointer;
  background: var(--parchment-300);
  border-radius: 999px;
  border: 1px solid var(--rule-line);
  transition: 0.2s;
}
.switch .slider::before {
  content: "";
  position: absolute; height: 20px; width: 20px;
  left: 2px; top: 2px;
  background: #fffbe9;
  box-shadow: var(--shadow-sm);
  border-radius: 50%;
  transition: 0.2s;
}
.switch input:checked + .slider { background: var(--forest-600); border-color: var(--forest-700); }
.switch input:checked + .slider::before { transform: translateX(20px); }

/* Stats / KPIs */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s-4); }
@media (max-width: 1100px) { .stats { grid-template-columns: repeat(4, 1fr); gap: var(--s-3); } }
@media (max-width: 900px)  { .stats { grid-template-columns: repeat(2, 1fr); gap: var(--s-3); } }
@media (max-width: 480px)  { .stats { grid-template-columns: 1fr; } }
.stat {
  background: var(--bg-card);
  border: 1px solid var(--rule-line);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  position: relative;
  overflow: hidden;
}
.stat::after {
  content: ""; position: absolute; right: -20px; bottom: -20px;
  width: 100px; height: 100px;
  background: radial-gradient(circle, rgba(184,144,44,0.18), transparent 65%);
}
.stat .num {
  font-family: var(--font-display);
  font-size: var(--fs-3xl);
  font-weight: 500;
  color: var(--forest-800);
  line-height: 1;
}
.stat .lbl {
  font-size: var(--fs-xs);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-500);
  margin-top: 8px;
  line-height: 1.3;
}
@media (max-width: 1180px) {
  .stat { padding: var(--s-4); }
  .stat .num { font-size: var(--fs-2xl); }
  .stat .lbl { letter-spacing: 0.10em; font-size: 0.7rem; }
}
.stat .trend { font-size: var(--fs-sm); color: var(--gold-700); margin-top: 6px; }

/* Progress */
.progress {
  height: 8px; border-radius: 999px;
  background: var(--parchment-300);
  overflow: hidden;
}
.progress > span {
  display: block; height: 100%;
  background: linear-gradient(90deg, var(--forest-600), var(--gold-500));
  border-radius: 999px;
}

/* Table */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}
table th, table td {
  text-align: left;
  padding: 14px 16px;
  border-bottom: 1px solid var(--rule-line);
}
table th {
  font-family: var(--font-body);
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: var(--fs-xs);
  color: var(--ink-500);
}
table tr:hover td { background: rgba(184,144,44,0.06); }

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-shell {
  position: relative; z-index: 1;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.05fr 1fr;
}
@media (max-width: 900px) {
  .login-shell { grid-template-columns: 1fr; }
  .login-art { min-height: 280px; padding: var(--s-6) var(--s-5); }
  .login-art .footnote { display: none; }
}

.login-art {
  position: relative;
  background:
    linear-gradient(160deg, rgba(15,42,31,0.92), rgba(20,53,36,0.85)),
    radial-gradient(circle at 30% 30%, rgba(220,180,90,0.30), transparent 55%);
  color: var(--parchment-100);
  padding: clamp(var(--s-6), 5vw, var(--s-9));
  display: flex; flex-direction: column; justify-content: space-between;
  overflow: hidden;
}
.login-art::after {
  content: ""; position: absolute; inset: 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='320' height='320' viewBox='0 0 320 320'><g fill='none' stroke='rgba(220,180,90,0.18)' stroke-width='1'><circle cx='160' cy='160' r='140'/><circle cx='160' cy='160' r='110'/><circle cx='160' cy='160' r='80'/><path d='M20 160 L300 160 M160 20 L160 300'/></g></svg>");
  background-position: 70% 110%; background-repeat: no-repeat;
  opacity: 0.7; pointer-events: none;
}
.login-art .quote {
  position: relative; z-index: 1;
  max-width: 460px;
}
.login-art .quote .mark {
  font-family: var(--font-display); font-size: 5rem; line-height: 0.6;
  color: var(--gold-400); display: block; margin-bottom: var(--s-3);
}
.login-art blockquote {
  font-family: var(--font-display); font-style: italic;
  font-size: clamp(1.4rem, 2.4vw, 2rem);
  line-height: 1.35;
  color: var(--parchment-100);
  margin: 0 0 var(--s-4);
}
.login-art cite {
  font-family: var(--font-body); font-style: normal;
  font-size: var(--fs-sm); letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--gold-300);
}
.login-art .brand-strip { position: relative; z-index: 1; display: flex; align-items: center; gap: var(--s-3); color: var(--parchment-100); }
.login-art .brand-strip .logo { color: var(--gold-300); width: 42px; height: 42px; }
.login-art .brand-strip .wordmark { font-family: var(--font-display); font-size: 1.5rem; }
.login-art .footnote {
  position: relative; z-index: 1;
  font-size: var(--fs-xs); letter-spacing: 0.2em; text-transform: uppercase;
  color: rgba(245, 233, 198, 0.7);
}

.login-form {
  padding: clamp(var(--s-5), 5vw, var(--s-9));
  display: flex; align-items: center; justify-content: center;
}
.login-form .inner { width: 100%; max-width: 440px; }
.login-form h1 { font-size: clamp(2rem, 3vw, 2.6rem); margin-bottom: var(--s-2); }
.login-form .sub { color: var(--ink-600); margin-bottom: var(--s-6); font-size: var(--fs-base); }
.login-form .field-row { margin-bottom: var(--s-4); }
.login-form input[type=text],
.login-form input[type=email],
.login-form input[type=password] { padding: 13px 14px; }
.login-form .btn-lg { width: 100%; justify-content: center; margin-top: var(--s-2); }
.login-form .divider { margin: var(--s-5) 0; }

.role-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s-2); margin-bottom: var(--s-5); }
.role-picker label {
  display: block; cursor: pointer;
  border: 1px solid var(--rule-line);
  background: var(--bg-card);
  padding: 10px 6px;
  border-radius: var(--r-md);
  text-align: center;
  font-family: var(--font-body); font-size: var(--fs-sm);
  transition: all 0.18s ease;
}
.role-picker input { display: none; }
.role-picker input:checked + label {
  background: var(--forest-700); color: var(--gold-100);
  border-color: var(--forest-800);
  box-shadow: var(--shadow-sm);
}
.role-picker label:hover { background: var(--parchment-200); }
.role-picker input:checked + label:hover { background: var(--forest-600); color: #fff; }

.field-row { margin-bottom: var(--s-4); }
.error-msg {
  display: none;
  padding: 10px 12px;
  margin-bottom: var(--s-4);
  border-radius: var(--r-md);
  background: rgba(166,74,54,0.10);
  border: 1px solid rgba(166,74,54,0.30);
  color: var(--crimson-700);
  font-size: var(--fs-sm);
}
.error-msg.show { display: block; }

/* ============================================================
   WORKSPACE (the heart of the product)
   ============================================================ */
.ws {
  display: grid;
  grid-template-columns: 264px 1fr;
  gap: var(--s-5);
}
@media (max-width: 1280px) { .ws { grid-template-columns: 240px 1fr; gap: var(--s-4); } }
@media (max-width: 960px)  {
  .ws { grid-template-columns: 1fr; gap: var(--s-4); }
  /* Mobile order: stage first, rail below */
  .ws-stage { order: 1; }
  .ws-rail  { order: 2; }
}

.ws-rail { display: flex; flex-direction: column; gap: var(--s-4); }
@media (max-width: 960px) {
  .ws-rail { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-3); }
  .ws-rail > .ladder { grid-column: 1 / -1; }
}
@media (max-width: 560px) {
  .ws-rail { grid-template-columns: 1fr; }
}
.ladder {
  display: flex; flex-direction: column; gap: 0;
  background: var(--bg-card);
  border: 1px solid var(--rule-line);
  border-radius: var(--r-lg);
  padding: var(--s-4);
}
.ladder h4 { margin-bottom: var(--s-3); color: var(--gold-700); }
.ladder ol { list-style: none; counter-reset: step; padding: 0; margin: 0; }
.ladder li {
  position: relative;
  padding: 12px 12px 12px 46px;
  border-radius: var(--r-md);
  font-family: var(--font-body); font-size: var(--fs-sm);
  color: var(--ink-700);
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}
.ladder li::before {
  counter-increment: step;
  content: counter(step, upper-roman);
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center;
  font-family: var(--font-display); font-size: 0.95rem;
  background: var(--parchment-200); color: var(--ink-600);
  border: 1px solid var(--rule-line);
}
.ladder li.done::before { background: var(--forest-700); color: var(--gold-100); border-color: var(--forest-800); }
.ladder li.active {
  background: linear-gradient(90deg, rgba(184,144,44,0.18), rgba(184,144,44,0.04));
  color: var(--ink-900); font-weight: 500;
  border-color: var(--gold-300);
}
.ladder li.active::before { background: var(--gold-500); color: #fffbe9; border-color: var(--gold-700); }
.ladder li:hover { background: rgba(184,144,44,0.10); }

.ws-stage {
  background: var(--bg-card);
  border: 1px solid var(--rule-line);
  border-radius: var(--r-lg);
  padding: clamp(var(--s-5), 3vw, var(--s-7));
  position: relative;
  min-height: 540px;
}
.ws-stage .stage-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-4);
  flex-wrap: wrap;
  padding-bottom: var(--s-4);
  border-bottom: 1px solid var(--rule-line);
  margin-bottom: var(--s-5);
}
.ws-stage .stage-head > div:first-child { min-width: 0; flex: 1 1 260px; }
.ws-stage h2 { margin-bottom: 4px; overflow-wrap: break-word; }
.ws-stage .stage-sub { color: var(--ink-600); font-style: italic; }
.ws-stage .stage-meta {
  display: inline-flex; flex-wrap: wrap; gap: var(--s-2);
  font-size: var(--fs-xs); letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--gold-700); font-weight: 600; margin-bottom: 6px;
}

.timer {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--gold-300);
  background: var(--gold-100);
  border-radius: var(--r-md);
  font-family: var(--font-display);
}
.timer .clock { font-size: 1.3rem; min-width: 70px; text-align: center; color: var(--ink-900); white-space: nowrap; }
.timer .lbl { font-family: var(--font-body); font-size: var(--fs-xs); letter-spacing: 0.18em; text-transform: uppercase; color: var(--gold-700); }

.prompt-card {
  background: linear-gradient(180deg, var(--gold-100), var(--parchment-100));
  border: 1px solid var(--gold-300);
  border-left: 4px solid var(--gold-500);
  border-radius: var(--r-md);
  padding: var(--s-4) var(--s-5);
  margin-bottom: var(--s-5);
}
.prompt-card .lbl { font-size: var(--fs-xs); letter-spacing: 0.2em; text-transform: uppercase; color: var(--gold-700); font-weight: 600; }
.prompt-card .txt { font-family: var(--font-display); font-style: italic; font-size: var(--fs-lg); color: var(--ink-800); margin-top: 4px; }

.doc {
  font-family: var(--font-body);
  font-size: calc(var(--fs-base) * var(--reading-scale));
  line-height: calc(var(--lh-loose) * var(--reading-spacing));
  background: var(--bg-soft);
  border: 1px solid var(--rule-line);
  border-radius: var(--r-md);
  padding: var(--s-5);
  min-height: 240px;
  white-space: pre-wrap;
}
.doc:focus { outline: none; border-color: var(--forest-600); box-shadow: 0 0 0 3px rgba(27,71,48,0.15); }

.markup-doc {
  position: relative;
  background:
    repeating-linear-gradient(0deg, transparent, transparent calc(1.85em * var(--reading-scale) - 1px), rgba(31,26,18,0.07) calc(1.85em * var(--reading-scale) - 1px), rgba(31,26,18,0.07) calc(1.85em * var(--reading-scale)));
  background-attachment: local;
}
.markup-doc mark.add { background: rgba(184,144,44,0.30); padding: 0 2px; }
.markup-doc s.cut { color: var(--crimson-700); text-decoration-color: var(--crimson-500); text-decoration-thickness: 2px; }
.markup-doc u.note { text-decoration: underline wavy var(--forest-600); }

.tools-row {
  display: flex; flex-wrap: wrap; gap: var(--s-2);
  margin-bottom: var(--s-4);
}

.kw-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s-3);
}
@media (max-width: 720px) { .kw-grid { grid-template-columns: 1fr 1fr; } }
.kw-grid .kw {
  background: var(--bg-soft);
  border: 1px dashed var(--rule-strong);
  border-radius: var(--r-md);
  padding: 10px 12px;
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  color: var(--ink-700);
}
.kw-grid .kw input {
  border: none; padding: 0; background: transparent;
  font-size: inherit; color: inherit;
}

/* Stage navigation */
.stage-nav {
  margin-top: var(--s-5);
  padding-top: var(--s-5);
  border-top: 1px solid var(--rule-line);
  display: flex; justify-content: space-between; gap: var(--s-3); flex-wrap: wrap;
}
@media (max-width: 480px) {
  .stage-nav { flex-direction: column; }
  .stage-nav .btn { width: 100%; justify-content: center; }
}

/* Floating reading ruler */
.ruler {
  position: fixed; left: 0; right: 0; height: 36px;
  pointer-events: none; z-index: 50;
  background: rgba(220, 180, 90, 0.18);
  border-top: 1px solid rgba(184,144,44,0.4);
  border-bottom: 1px solid rgba(184,144,44,0.4);
  display: none;
}
html.ruler-on .ruler { display: block; }

/* Toasts */
.toast-stack {
  position: fixed; right: 20px; bottom: 20px; z-index: 60;
  display: flex; flex-direction: column; gap: 10px;
}
.toast {
  background: var(--ink-900); color: var(--parchment-100);
  border: 1px solid var(--gold-500);
  border-radius: var(--r-md); padding: 12px 16px;
  font-family: var(--font-body); font-size: var(--fs-sm);
  box-shadow: var(--shadow-lg);
  animation: rise 0.25s ease-out;
}
.toast strong { color: var(--gold-300); }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Reflection / journal */
.reflection {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s-4);
}
@media (max-width: 800px) { .reflection { grid-template-columns: 1fr; } }
.reflection textarea { min-height: 100px; }

/* Document preview */
.doc-preview {
  background: var(--bg-soft);
  border: 1px solid var(--rule-line);
  border-radius: var(--r-md);
  padding: var(--s-5);
  font-family: var(--font-body);
  line-height: var(--lh-loose);
}
.doc-preview h3 { font-family: var(--font-display); margin-bottom: var(--s-3); }

/* ============================================================
   GRID HELPERS
   ============================================================ */
.row { display: grid; gap: var(--s-5); }
.row.cols-2 { grid-template-columns: 1fr 1fr; }
.row.cols-3 { grid-template-columns: repeat(3, 1fr); }
.row.cols-2-1 { grid-template-columns: 2fr 1fr; }
@media (max-width: 900px) {
  .row.cols-2, .row.cols-3, .row.cols-2-1 { grid-template-columns: 1fr; }
}

.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: var(--s-3); margin-bottom: var(--s-4);
  flex-wrap: wrap;
}
.section-head h2, .section-head h3 { margin: 0; }
.section-head .more {
  font-size: var(--fs-sm); color: var(--forest-700);
  white-space: nowrap;
  flex-shrink: 0;
}

/* Assignment continue card — consistent layout */
.assign-card {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) auto;
  gap: var(--s-4);
  align-items: center;
}
.assign-card .assign-meta { min-width: 0; }
.assign-card .assign-meta .meta { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.assign-card .assign-meta h3 { margin: 6px 0 4px; overflow-wrap: break-word; word-break: normal; }
.assign-card .assign-progress { min-width: 0; }
.assign-card .assign-cta { display: flex; }
.assign-card .assign-cta .btn { white-space: nowrap; }
@media (max-width: 1180px) {
  .assign-card { grid-template-columns: 1fr auto; }
  .assign-card .assign-progress { grid-column: 1 / -1; order: 2; }
  .assign-card .assign-meta { grid-column: 1; order: 1; }
  .assign-card .assign-cta { grid-column: 2; grid-row: 1; order: 1; align-self: start; }
}
@media (max-width: 560px) {
  .assign-card { grid-template-columns: 1fr; gap: var(--s-3); }
  .assign-card .assign-cta { width: 100%; }
  .assign-card .assign-cta .btn { width: 100%; justify-content: center; }
}

/* Profile card */
.profile {
  display: flex; gap: var(--s-4); align-items: center;
}
.avatar {
  width: 56px; height: 56px; border-radius: 50%;
  background: linear-gradient(135deg, var(--forest-700), var(--gold-600));
  color: #fffbe9; display: grid; place-items: center;
  font-family: var(--font-display); font-size: 1.2rem;
  border: 2px solid var(--gold-300);
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}
.avatar.lg { width: 84px; height: 84px; font-size: 1.8rem; }

/* Crest decorative */
.crest {
  display: inline-block; color: var(--gold-600);
}

/* Helper text */
.muted { color: var(--ink-500); }
.small { font-size: var(--fs-sm); }
.mt-2 { margin-top: var(--s-2); }
.mt-3 { margin-top: var(--s-3); }
.mt-4 { margin-top: var(--s-4); }
.mt-5 { margin-top: var(--s-5); }
.mb-3 { margin-bottom: var(--s-3); }
.mb-4 { margin-bottom: var(--s-4); }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-3 { gap: var(--s-3); }
.gap-4 { gap: var(--s-4); }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.right { text-align: right; }
.center { text-align: center; }
.hide-sm { }
@media (max-width: 720px) { .hide-sm { display: none; } }

/* Range slider on-brand */
input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 8px; background: var(--parchment-300);
  border-radius: 999px; outline: none;
  border: 1px solid var(--rule-line);
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 22px; height: 22px; border-radius: 50%;
  background: linear-gradient(180deg, var(--gold-500), var(--gold-600));
  border: 1px solid var(--gold-700);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}
input[type=range]::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%;
  background: linear-gradient(180deg, var(--gold-500), var(--gold-600));
  border: 1px solid var(--gold-700);
  cursor: pointer;
}

/* Focus visible everywhere */
:focus-visible {
  outline: 2px solid var(--gold-600);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Print friendliness for documents */
@media print {
  .sidebar, .topbar, .stage-nav, .tools-row { display: none !important; }
  body::before { display: none; }
  .main { padding: 0; }
}
