@import url('https://fonts.googleapis.com/css2?family=DM+Serif+Display:ital@0;1&family=DM+Sans:wght@400;500;600&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-padding-top: 80px; }

/* ── ROOT VARIABLES (unified warm palette) ── */
:root {
  --font: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --serif: 'DM Serif Display', Georgia, serif;
  --bg: #f0ece4;
  --header: #5a1212;
  --header-text: #ffffff;
  --accent: #b0342c;
  --accent-hover: #8b1a1a;
  --link: var(--accent);   /* accent used as text; a scheme overrides it when its accent is too light to read on cards */
  --card: #ffffff;
  --card-shadow: 0 2px 8px rgba(0,0,0,0.10);
  --text: #1c1814;
  --muted: #6b6259;
  --border: #d8d0c4;
  --btn-secondary-bg: #e8e2d8;
  --btn-primary-text: #ffffff;
  --radius: 8px;
  --gold: #a07030;
  --green: #2d6a4f;
  --green-light: #eaf3ee;
  --danger: #dc2626;
  --success: #16a34a;
  --warning-bg: #fef9c3;
  --warning-border: #ca8a04;
  --warning-text: #713f12;
  /* Height of the fixed educational-use footer. Every full-viewport layout below
     subtracts this, so changing it here keeps all of them in step. */
  --disclaimer-h: 32px;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: var(--disclaimer-h);
}

/* ── GLOBAL UTILITIES ── */
.hidden { display: none !important; }
.app-wrapper { min-height: calc(100vh - var(--disclaimer-h)); }

/* ── GLOBAL DISCLAIMER FOOTER ── */
#global-disclaimer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--disclaimer-h);
  padding: 0 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.14);
  background: var(--header);
  color: rgba(255, 255, 255, 0.74);
  font-size: 0.72rem;
  line-height: 1.3;
  text-align: center;
}
#global-disclaimer strong { color: rgba(255, 255, 255, 0.95); font-weight: 600; }
#global-disclaimer .disclaimer-sep { opacity: 0.4; }
#global-disclaimer .disclaimer-link { color: rgba(255, 255, 255, 0.95); text-underline-offset: 2px; }
@media (max-width: 640px) {
  :root { --disclaimer-h: 44px; }
  #global-disclaimer { font-size: 0.66rem; }
  #global-disclaimer .disclaimer-sep,
  #global-disclaimer .disclaimer-link { display: none; } /* a third line would overflow the 44px footer */
  #global-disclaimer { flex-wrap: wrap; gap: 0 6px; }
}

/* ── LANDING SCREEN ── */
#home-screen {
  min-height: calc(100vh - var(--disclaimer-h));
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 72px 24px 80px;
  position: relative;
}

.settings-btn-light {
  width: 36px; height: 36px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.settings-btn-light:hover {
  background: var(--card);
  border-color: var(--muted);
  color: var(--text);
}

.home-wordmark {
  font-family: var(--serif);
  font-size: clamp(2.4rem, 6vw, 3.6rem);
  font-weight: 400;
  color: var(--text);
  line-height: 1;
  text-align: center;
}

.home-subtitle {
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
  margin-top: 10px;
  text-align: center;
}

.home-rule {
  border: none;
  border-top: 1px solid var(--border);
  width: 60px;
  margin: 16px auto 44px;
}

/* ── LANDING GROUPS (Law of AI vs. AI in Legal Practice) ── */
.exercise-group {
  width: 100%;
  align-self: stretch;
}

.exercise-group + .exercise-group {
  margin-top: 52px;
}

.group-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 16px;
  padding-bottom: 12px;
  margin-bottom: 22px;
  border-bottom: 1px solid var(--border);
}

.group-title {
  font-family: var(--serif);
  font-size: 1.75rem;
  font-weight: 400;
  line-height: 1.2;
  color: var(--text);
}

.group-desc {
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--muted);
}

.exercise-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
  width: 100%;
  align-self: stretch;
}

@media (min-width: 700px) {
  .exercise-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 1000px) {
  .exercise-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.exercise-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 32px 28px 28px;
  cursor: pointer;
  transition: box-shadow 0.18s, border-color 0.18s, transform 0.12s;
  display: flex;
  flex-direction: column;
  text-align: left;
  text-decoration: none;
  color: inherit;
}

.exercise-card:hover {
  box-shadow: 0 4px 20px rgba(0,0,0,0.13);
  border-color: var(--accent);
  transform: translateY(-2px);
}

.exercise-card-eyebrow {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 10px;
}

.exercise-card-title {
  font-family: var(--serif);
  font-size: 1.55rem;
  font-weight: 400;
  color: var(--text);
  margin-bottom: 12px;
  line-height: 1.2;
}

.exercise-card-desc {
  font-size: 0.88rem;
  line-height: 1.7;
  color: var(--muted);
  flex: 1;
}

.exercise-card-arrow {
  margin-top: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--link);
}

/* Card with a secondary link beside the primary "Open" action */
.exercise-card-footer {
  margin-top: 20px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}

.exercise-card-footer .exercise-card-arrow {
  margin-top: 0;
  text-decoration: none;
}

.exercise-card-source {
  font-size: 0.75rem;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.exercise-card-source:hover {
  color: var(--link);
}

/* ── SHARED HEADER BAR ──
   Painted in the theme's header color. The text/muted/border tokens are
   re-pointed at --header-text inside the bar so every control in it
   (title, icon buttons, nav label, IOF tools) stays legible on it. */
.mod-header-bar {
  --text: var(--header-text);
  --muted: color-mix(in srgb, var(--header-text) 68%, transparent);
  --border: color-mix(in srgb, var(--header-text) 28%, transparent);
  --btn-secondary-bg: color-mix(in srgb, var(--header-text) 14%, transparent);
  background: var(--header);
  color: var(--text);
  border-bottom: 2px solid var(--accent);
  padding: 11px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.07);
}

.header-left { display: flex; align-items: center; gap: 10px; }
.header-title { font-size: 1.05rem; font-weight: 700; color: var(--text); }
.header-subtitle { font-size: 0.73rem; color: var(--muted); margin-top: 2px; letter-spacing: 0.04em; text-transform: uppercase; }
.header-right { display: flex; gap: 8px; align-items: center; }
.header-nav { display: flex; align-items: center; gap: 6px; }

.header-btn {
  width: 34px; height: 34px;
  border-radius: 6px;
  border: 1.5px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, border-color 0.15s;
  flex-shrink: 0;
  user-select: none;
  line-height: 1;
}
.header-btn:hover { background: var(--btn-secondary-bg); border-color: var(--muted); }
.header-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.header-btn:disabled:hover { background: transparent; border-color: var(--border); }

/* ── SHARED FORM CONTROLS ── */
label { font-size: 0.9rem; font-weight: 600; color: var(--muted); display: block; margin-bottom: 6px; }
input[type="text"], input[type="number"] {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 1rem;
  font-family: var(--font);
  color: var(--text);
  background: var(--card);
  outline: none;
  transition: border-color 0.15s;
}
input[type="text"]:focus, input[type="number"]:focus { border-color: var(--accent); }
input[type="number"] { width: 72px; text-align: center; }

/* ── SHARED BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: 6px;
  border: none;
  font-size: 0.95rem;
  font-family: var(--font);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  text-decoration: none;
}
/* Button roles — pick by what the button does, not how prominent it should feel:
   .btn-primary   the one action that moves the screen forward (Start, Submit, Generate,
                  Save & Push). At most one per screen, or per self-contained card (a
                  settings section, the presentation timer).
   .btn-secondary supporting form actions (Create Groups, Assign, Quick Fill, Add, Clear, Reset).
   .btn-ghost     tool and view controls on presentation screens (Export, Copy link, Reset
                  view, sample-data toggles, Show issues) — quiet so they don't pull focus.
   .btn-danger    permanent deletion only. */
.btn-primary { background: var(--accent); color: var(--btn-primary-text, #fff); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--btn-secondary-bg); color: var(--text); }
.btn-secondary:hover { filter: brightness(0.92); }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--muted); }
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-sm { padding: 7px 14px; font-size: 0.85rem; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 16px; }

/* ── SHARED MODAL ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 500;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: var(--card);
  box-shadow: var(--card-shadow);
  border-radius: 10px;
  padding: 32px;
  max-width: 560px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
}
.modal-close {
  position: absolute;
  top: 14px; right: 16px;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-box h2 { font-size: 1.3rem; margin-bottom: 18px; color: var(--text); }
.modal-box h3 { font-size: 1rem; font-weight: 700; margin: 16px 0 8px; color: var(--text); }
.modal-box h4 { font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); margin: 18px 0 8px; }
.modal-box p { font-size: 0.95rem; line-height: 1.65; color: var(--text); margin-bottom: 10px; }
.modal-box ul { padding-left: 20px; }
.modal-box ul li { font-size: 0.95rem; line-height: 1.65; color: var(--text); margin-bottom: 6px; }

.shortcut-list { list-style: none; padding: 0; margin: 0 0 4px; }
.shortcut-list li { display: flex; align-items: center; gap: 12px; padding: 5px 0; border-bottom: 1px solid var(--border); font-size: 0.9rem; color: var(--text); }
.shortcut-list li:last-child { border-bottom: none; }
.shortcut-list kbd { font-family: monospace; background: var(--bg); border: 1px solid var(--border); border-radius: 4px; padding: 1px 7px; font-size: 0.82rem; min-width: 44px; text-align: center; white-space: nowrap; flex-shrink: 0; color: var(--text); }
.token-help-note {
  margin-top: 10px;
  padding: 10px 12px;
  border-left: 3px solid var(--accent);
  border-radius: 0 5px 5px 0;
  background: var(--bg);
  color: var(--text);
  font-size: 0.84rem;
  line-height: 1.55;
}
.token-help-note strong { color: var(--text); }
.token-help-note a {
  color: var(--link);
  font-weight: 600;
  text-underline-offset: 2px;
}
.token-whitespace-help code {
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--link);
  font-weight: 700;
}
.help-credit { font-size: 0.78rem; color: var(--muted); text-align: center; margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--border); }

/* ── SETTINGS MODAL TABS ── */
.settings-tabs { display: flex; border-bottom: 2px solid var(--border); margin: 0 0 22px; }
.settings-tab {
  background: none; border: none; border-bottom: 3px solid transparent; margin-bottom: -2px;
  padding: 10px 16px; font-size: 0.88rem; font-weight: 600; color: var(--muted);
  cursor: pointer; transition: color 0.15s; white-space: nowrap; font-family: inherit;
}
.settings-tab:hover { color: var(--text); }
.settings-tab.active { color: var(--link); border-bottom-color: var(--accent); }
.settings-tab-panel { display: none; }
.settings-tab-panel.active { display: block; }

/* ── PLOTTER HINT TEXT ── */
.plotter-hint { font-size: 0.8rem; color: var(--muted); margin: 5px 0 0; line-height: 1.4; }

/* ── PANEL EXERCISE STYLES ── */

/* Loading / Error */
#loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  gap: 18px;
  position: relative;
}
.spinner {
  width: 48px; height: 48px;
  border: 5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { color: var(--muted); font-size: 1rem; }

#error-screen {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  gap: 16px;
  padding: 32px;
  text-align: center;
  position: relative;
}
.error-icon { font-size: 3rem; }
.error-msg { font-size: 1.05rem; color: var(--danger); max-width: 520px; line-height: 1.6; }
.error-hint { font-size: 0.9rem; color: var(--muted); max-width: 480px; line-height: 1.5; }

/* Screens */
.screen { display: none; }
.screen.active { display: block; }
.counsel-screen { display: none; }
.counsel-screen.active { display: block; }

/* Section cards */
.section-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  padding: 24px;
  margin-bottom: 24px;
}
.section-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text);
  border-bottom: 2px solid var(--border);
  padding-bottom: 10px;
}

/* Names textarea */
#names-textarea {
  width: 100%;
  min-height: 130px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 1rem;
  font-family: var(--font);
  color: var(--text);
  background: var(--card);
  resize: vertical;
  outline: none;
  transition: border-color 0.15s;
  line-height: 1.6;
}
#names-textarea:focus { border-color: var(--accent); }
.names-hint { font-size: 0.82rem; color: var(--muted); margin-top: 6px; }

/* Stepper */
.stepper-row { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }

/* Warnings */
.inline-warning {
  display: none;
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
  color: var(--warning-text);
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 0.9rem;
  margin-top: 12px;
}
.inline-warning.show { display: block; }

/* ── SHARED LABEL STYLES ── */
/* Caps labels (panel exercise) — theme label color, like the landing-page eyebrows */
.group-card-title, .opening-card-name, .qa-drawn-label, .advanced-subtitle {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--gold);
}
/* Gold caps labels (dark surfaces — counsel result card) */
.called-label, .scenario-label, .risks-label {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
}

/* Groups */
#groups-display { margin-top: 18px; }
.groups-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
  margin-top: 10px;
}
.group-card {
  background: transparent;
  border: 1.5px solid var(--accent);
  border-radius: var(--radius);
  padding: 14px;
}
.group-card-title { margin-bottom: 8px; }
.group-member { padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 0.95rem; }
.group-member:last-child { border-bottom: none; }
.group-member-name { font-weight: 600; color: var(--text); }
.group-member-prompt { font-size: 1rem; color: var(--text); margin-top: 4px; line-height: 1.45; }

/* Opening remarks */
.opening-cards { display: flex; flex-direction: column; gap: 14px; }
.opening-card {
  background: transparent;
  border: 1.5px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px;
}
.opening-card-name { margin-bottom: 6px; }
.opening-card-script { font-size: 1.05rem; line-height: 1.65; color: var(--text); }

/* Q&A */
.qa-drawn-card {
  background: transparent;
  border: 1.5px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 14px;
}
.qa-drawn-label { margin-bottom: 6px; }
.qa-drawn-script { font-size: 1.1rem; line-height: 1.65; color: var(--text); }
.qa-exhausted { display: none; text-align: center; color: var(--muted); font-size: 0.95rem; padding: 12px; margin-top: 10px; }
.qa-exhausted.show { display: block; }

/* Question history */
#q-secondary-buttons { margin-top: 16px; }
#q-history-list { display: none; margin-top: 12px; border-top: 1px solid var(--border); padding-top: 12px; }
#q-history-list.show { display: block; }
.history-item { padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 0.9rem; color: var(--muted); line-height: 1.5; }
.history-item:last-child { border-bottom: none; }
.history-num { font-weight: 700; color: var(--text); margin-right: 6px; }

/* Timer */
.collapsible-header { display: flex; align-items: center; justify-content: space-between; cursor: pointer; user-select: none; }
.collapsible-header .toggle-icon { font-size: 0.85rem; color: var(--muted); }
.collapsible-body { display: none; margin-top: 16px; }
.collapsible-body.expanded { display: block; }

.timer-display {
  font-size: 3.5rem;
  font-weight: 700;
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  margin: 18px 0;
  letter-spacing: 0.03em;
}
.timer-controls { display: flex; flex-direction: column; gap: 14px; align-items: center; }
.timer-mode-row { display: flex; gap: 20px; align-items: center; }
.timer-mode-row label { display: flex; align-items: center; gap: 6px; font-size: 0.95rem; font-weight: 600; color: var(--text); cursor: pointer; margin: 0; }
.timer-countdown-inputs { display: flex; align-items: center; gap: 8px; font-size: 0.95rem; }
.timer-countdown-inputs input[type="number"] { width: 64px; }
.timer-btn-row { display: flex; gap: 10px; }
.timer-warn-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 0.88rem; color: var(--muted); margin-top: 6px; }
.timer-warn-row input[type="number"] { width: 56px; }
.timer-warn-row label { margin: 0; font-size: 0.88rem; }

@keyframes timer-flash {
  0%, 100% { background: var(--card); }
  50% { background: rgba(220,38,38,0.18); }
}
.timer-flash-active { animation: timer-flash 0.7s ease-in-out 2; }
.timer-flash-done { background: rgba(220,38,38,0.22) !important; }

.warn-entry-row { display:flex; align-items:center; gap:8px; margin-bottom:6px; }
.warn-entry-row label { margin:0; font-size:0.88rem; font-weight:500; color:var(--text); display:flex; align-items:center; gap:4px; cursor:pointer; }
.warn-entry-row input[type="number"] { width:60px; }
.warn-remove-btn { background:none; border:none; cursor:pointer; color:var(--muted); font-size:1rem; padding:2px 5px; line-height:1; }
.warn-remove-btn:hover { color:var(--danger); }

/* Mod nav */
.group-nav-label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
  white-space: nowrap;
}

/* Advanced section */
.advanced-subsection { padding: 16px 0; }
.advanced-subsection:first-child { padding-top: 4px; }
.advanced-subtitle { margin-bottom: 12px; }
.advanced-divider { border: none; border-top: 1px solid var(--border); margin: 4px 0; }

/* Settings color controls */
.scheme-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.scheme-row label { margin: 0; }
.scheme-row select {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 0.95rem;
  font-family: var(--font);
  color: var(--text);
  background: var(--card);
  cursor: pointer;
  outline: none;
}
.color-grid { display: flex; flex-wrap: wrap; gap: 18px; margin-top: 8px; }
.color-row { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; min-width: 100px; }
.color-row label { margin: 0; font-size: 0.85rem; }
.color-row input[type="color"] {
  width: 52px; height: 52px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px;
  cursor: pointer;
  background: var(--card);
  display: block;
}
.color-hex-input {
  width: 90px;
  font-size: 0.82rem;
  font-family: monospace;
  padding: 4px 7px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--card);
  color: var(--text);
  outline: none;
}
.color-hex-input:focus { border-color: var(--accent); }

/* ── COUNSEL EXERCISE STYLES ── */
.counsel-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 20px 72px;
  width: 100%;
}

#counsel-app .c-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 24px 28px;
  width: 100%;
  max-width: 640px;
  margin-bottom: 12px;
}

.field-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  display: block;
  margin-bottom: 8px;
}

.field-hint {
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 10px;
  display: block;
  line-height: 1.5;
}

.field-hint code {
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.7rem;
  color: var(--link);
}

#counsel-app input[type="text"] {
  width: 100%;
  background: var(--bg);
}

#counsel-app textarea {
  width: 100%;
  min-height: 100px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--bg);
  font-family: var(--font);
  font-size: 0.95rem;
  color: var(--text);
  resize: vertical;
  outline: none;
  padding: 10px 12px;
  line-height: 1.7;
  transition: border-color 0.15s;
}
#counsel-app textarea:focus { border-color: var(--accent); }
#counsel-app textarea::placeholder { color: #b0a898; }

#csv-status { font-size: 0.75rem; margin-top: 8px; min-height: 18px; color: var(--muted); }
#csv-status.ok { color: var(--green); }
#csv-status.err { color: var(--link); }

.c-btn-row {
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 640px;
  margin-bottom: 32px;
}



#counsel-result {
  width: 100%;
  max-width: 640px;
  display: none;
}
#counsel-result.visible { display: block; }

.result-card {
  background: var(--card);
  color: var(--text);
  border-radius: 4px;
  padding: 36px 36px 28px;
  position: relative;
  overflow: hidden;
  margin-bottom: 12px;
  box-shadow: var(--card-shadow);
}
.result-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--gold));
}

.called-label { margin-bottom: 6px; }
.called-name {
  font-family: var(--serif);
  font-size: clamp(2.2rem, 6vw, 3.4rem);
  line-height: 1.1;
  margin-bottom: 30px;
  animation: rise 0.35s ease both;
}
.scenario-sep { border: none; border-top: 1px solid var(--border); margin-bottom: 22px; }
.scenario-label { margin-bottom: 8px; }
.scenario-title {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1.15rem;
  color: var(--text);
  margin-bottom: 12px;
  animation: rise 0.35s 0.08s ease both;
}
.scenario-text {
  font-size: 0.92rem;
  line-height: 1.8;
  color: var(--muted);
  animation: rise 0.35s 0.16s ease both;
}

.btn-reveal {
  display: block;
  width: 100%;
  margin-top: 22px;
  padding: 11px;
  font-family: var(--font);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  border-radius: 3px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.risks-panel { display: none; margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border); animation: rise 0.3s ease both; }
.risks-panel.visible { display: block; }
.risks-label { margin-bottom: 10px; font-weight: 600; color: var(--text); }

.risks-md { color: var(--muted); font-size: 0.88rem; line-height: 1.75; }
.risks-md p { margin-bottom: 0.6em; }
.risks-md ul, .risks-md ol { padding-left: 1.2em; margin-bottom: 0.6em; }
.risks-md li { margin-bottom: 0.35em; color: var(--muted); }
.risks-md strong { color: var(--text); font-weight: 600; }
.risks-md em { color: var(--text); }
.risks-md p:last-child, .risks-md li:last-child { margin-bottom: 0; }


@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ══════════════════════════════════════════════════
   3D PLOTTER — structural styles only.
   Colors use the main app's CSS variables so the
   sidebar automatically follows the active scheme.
   ══════════════════════════════════════════════════ */

#plotter-app {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--disclaimer-h));
  overflow: hidden;
}

#plotter-shell {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

#plotter-panel {
  width: 220px;
  flex-shrink: 0;
  background-color: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  box-shadow: var(--card-shadow);
}
#plotter-panel::-webkit-scrollbar { width: 5px; }
#plotter-panel::-webkit-scrollbar-track { background: transparent; }
#plotter-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.plotter-section {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.plotter-checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .88rem;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  color: var(--text);
  margin: 0;
}
.plotter-checkbox-label input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.plotter-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.plotter-input-row > input[type="checkbox"] {
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}
.plotter-input-row > label {
  font-size: .85rem;
  font-weight: 700;
  width: 14px;
  flex-shrink: 0;
  margin: 0;
}
.plotter-input-row > input[type="text"] {
  flex: 1;
  min-width: 0;
  font-size: .85rem;
  padding: 5px 8px;
}

.plotter-status-text {
  font-size: .8rem;
  color: var(--muted);
  line-height: 1.5;
  word-break: break-word;
}
.plotter-status-text.loading { opacity: .7; }
.plotter-status-text.error   { color: var(--danger); }

.plotter-stats-text {
  font-size: .73rem;
  color: var(--muted);
  opacity: .7;
  line-height: 1.6;
  font-family: 'Consolas', 'Menlo', monospace;
  white-space: pre;
}

#plotter-qr-placeholder { width: 100%; }
.plotter-qr-empty {
  width: 100%;
  aspect-ratio: 1;
  border: 2px dashed var(--border);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .72rem;
  color: var(--muted);
  opacity: .5;
  letter-spacing: .06em;
  text-transform: uppercase;
}

#plotter-plot-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background-color: var(--bg);
  position: relative;
}
#plotter-plot { flex: 1; width: 100%; height: 100%; }

#plotter-demo-badge,
#cite-demo-badge {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  pointer-events: none;
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background-color: var(--card);
  color: var(--link);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  opacity: .9;
}

/* ── TOKEN EXPLORER ── */
#token-app {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--disclaimer-h));
  overflow: hidden;
}

#token-shell {
  display: flex;
  flex: 1;
  min-height: 0;
}

#token-main {
  flex: 1;
  min-width: 0;
  padding: 28px 20px;
  max-width: 1500px;
  margin: 0 auto;
  width: 100%;
  overflow-y: auto;
}

#token-panel {
  width: 220px;
  flex-shrink: 0;
  background-color: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

#token-layout {
  display: flex;
  flex-direction: column;
  gap: 20px;
}
#token-prompt-card { margin-bottom: 0; }

#token-temperature { accent-color: var(--accent); }
#token-temperature:disabled { opacity: 0.5; }

.token-compare-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 10px 0 0;
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}
.token-compare-toggle input {
  margin: 0;
  accent-color: var(--accent);
}
.token-info-icon {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border: 1px solid var(--muted);
  border-radius: 50%;
  color: var(--muted);
  font-family: Georgia, serif;
  font-size: 0.7rem;
  font-weight: 700;
  cursor: help;
}
.token-info-icon::after {
  content: attr(data-tooltip);
  position: absolute;
  z-index: 20;
  left: 50%;
  bottom: calc(100% + 8px);
  width: 230px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--text);
  color: var(--card);
  box-shadow: var(--card-shadow);
  font-family: var(--font);
  font-size: 0.75rem;
  font-weight: 400;
  line-height: 1.4;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 4px);
  transition: opacity 0.15s, transform 0.15s;
}
.token-info-icon:hover::after,
.token-info-icon:focus::after {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* The side panel is only ~220px wide and scrolls (overflow:auto), so it clips the
   hover tooltip used elsewhere. Panel info icons expand an inline note instead,
   which cannot be clipped and also works on touch, where hover never fires. */
.token-info-toggle {
  padding: 0;
  background: none;
  font-family: Georgia, serif;
  cursor: pointer;
}
.token-info-toggle::after { content: none; }
.token-info-toggle[aria-expanded="true"] {
  border-color: var(--accent);
  color: var(--link);
}
.token-info-note {
  margin: 8px 0 0;
  padding: 8px 10px;
  border-left: 2px solid var(--accent);
  border-radius: 0 4px 4px 0;
  background: var(--bg);
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.5;
}

.token-alt-row.chosen .token-alt-label { font-weight: 700; color: var(--link); }

.token-param-warning {
  margin: 14px 0 0;
  padding: 9px 11px;
  border: 1px solid var(--warning-border);
  border-left-width: 3px;
  border-radius: 5px;
  background: var(--warning-bg);
  color: var(--warning-text);
  font-size: 0.78rem;
  line-height: 1.5;
}

.token-privacy-notice {
  margin-bottom: 12px;
  padding: 10px 12px;
  border: 1px solid var(--warning-border);
  border-left-width: 3px;
  border-radius: 5px;
  background: var(--warning-bg);
  color: var(--warning-text);
  font-size: 0.79rem;
  line-height: 1.55;
}
.token-privacy-notice strong { display: block; margin-bottom: 3px; font-weight: 700; }

.token-advanced-field { margin-bottom: 14px; }
.token-advanced-field:last-child { margin-bottom: 0; }
.token-advanced-label {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 6px;
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 600;
}

#token-system-card { margin-bottom: 0; }
.token-optional-tag {
  margin-left: 8px;
  padding: 2px 7px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  vertical-align: middle;
}
.token-system-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  padding: 9px 12px;
  border-left: 3px solid var(--accent);
  border-radius: 0 5px 5px 0;
  background: var(--bg);
  color: var(--text);
  font-size: 0.84rem;
  line-height: 1.5;
}
.token-system-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
}
.token-system-meta .plotter-hint { margin: 0; }
.token-system-meta .plotter-hint.error { color: var(--danger); font-weight: 600; }

.token-request-viewer {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.token-request-viewer > summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  user-select: none;
}
.token-request-viewer > summary:hover { color: var(--text); }
.token-request-viewer > .plotter-hint { margin: 8px 0 0; }
.token-request-block { margin-top: 10px; }
.token-request-block-title {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.token-request-block pre {
  max-height: 320px;
  margin: 0;
  padding: 10px 12px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.78rem;
  line-height: 1.5;
  white-space: pre;
}

.token-prompt-actions { width: 100%; }
.token-live-actions {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.token-sample-control {
  display: inline-flex;
  align-items: stretch;
  gap: 8px;
  min-width: 0;
  margin-left: auto;
}
.token-sample-control .btn { white-space: nowrap; }
.token-sample-control select {
  width: min(310px, 42vw);
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 8px 30px 8px 10px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#token-results {
  display: flex;
  flex-direction: column;
  gap: 20px;
}
#token-results > .section-card { margin-bottom: 0; }

.token-single-alternatives {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

#token-comparison-results {
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.token-comparison-response { margin-bottom: 0; }
.token-comparison-error {
  margin: 0;
  color: var(--danger);
  font-size: 0.88rem;
  line-height: 1.5;
}
.token-comparison-loading {
  color: var(--muted);
  font-size: 0.88rem;
}

#token-cached-card { margin-bottom: 0; }
.token-cached-intro { margin: 0 0 16px; }
.token-cached-controls {
  display: flex;
  align-items: flex-end;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.token-cached-controls > label {
  flex: 1 1 320px;
  margin: 0;
  font-size: 0.85rem;
  font-weight: 700;
}
.token-cached-controls select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.token-temperature-options {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 0;
  padding: 0;
  border: 0;
}
.token-temperature-options legend {
  margin-bottom: 6px;
  font-size: 0.85rem;
  font-weight: 700;
}
.token-temperature-options label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin: 0;
  font-size: 0.9rem;
  cursor: pointer;
}
.token-temperature-options input { accent-color: var(--accent); }
#token-cached-responses {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.token-cached-response {
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 6px;
  padding: 14px 16px;
  background: var(--bg);
}
.token-cached-response-title {
  margin-bottom: 8px;
  color: var(--link);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.token-cached-output {
  color: var(--text);
  line-height: 1.9;
  white-space: pre-wrap;
}
.token-cached-instructions {
  margin: 8px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}
.token-cached-alternatives {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.token-cached-alternatives-title {
  margin-bottom: 8px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
}
.token-cached-empty { color: var(--muted); font-size: 0.88rem; }

@media (min-width: 820px) {
  #token-output-card .token-single-response-layout,
  #token-comparison-results .token-comparison-response,
  #token-cached-responses .token-cached-response {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(280px, 0.85fr);
    column-gap: 24px;
    align-items: start;
  }

  #token-comparison-results .token-cached-response-title,
  #token-cached-responses .token-cached-response-title {
    grid-column: 1 / -1;
  }

  #token-comparison-results .token-cached-output,
  #token-comparison-results .token-usage,
  #token-comparison-results .token-cached-instructions,
  #token-cached-responses .token-cached-output,
  #token-cached-responses .token-cached-instructions {
    grid-column: 1;
  }

  #token-output-card .token-single-alternatives,
  #token-comparison-results .token-cached-alternatives,
  #token-cached-responses .token-cached-alternatives {
    grid-column: 2;
    margin-top: 0;
    padding: 0 0 0 24px;
    border-top: 0;
    border-left: 1px solid var(--border);
  }

  #token-output-card .token-single-alternatives {
    grid-row: 1;
  }

  #token-comparison-results .token-cached-alternatives,
  #token-cached-responses .token-cached-alternatives {
    grid-row: 2 / span 4;
  }

  #token-comparison-results .token-comparison-loading,
  #token-comparison-results .token-comparison-error {
    grid-column: 1 / -1;
  }
}

@media (max-width: 620px) {
  .token-prompt-actions { align-items: stretch; }
  .token-live-actions { width: 100%; }
  .token-sample-control { width: 100%; margin-left: 0; }
  .token-sample-control select { flex: 1; width: auto; }
}


#token-output {
  line-height: 1.9;
  font-size: 1rem;
  white-space: pre-wrap;
}

.token-output-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.token-usage {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}
.token-usage-item:not(:last-child)::after {
  content: ' · ';
  color: var(--border);
}
.token-usage-item:first-child {
  color: var(--text);
  font-weight: 600;
}

.token-render-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.token-render-toggle input { margin: 0; }

.token-rendered { line-height: 1.6; overflow-wrap: anywhere; }
.token-rendered > :first-child { margin-top: 0; }
.token-rendered > :last-child { margin-bottom: 0; }
.token-rendered blockquote {
  margin: 0.8em 0;
  padding: 0.15em 0 0.15em 1em;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}
.token-pill {
  display: inline;
  padding: 1px 1px 1px 0;
  border-radius: 3px;
  border-right: 1px solid rgba(120, 110, 95, 0.22);
  cursor: pointer;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  transition: outline-color 0.1s;
  outline: 2px solid transparent;
  outline-offset: -1px;
}
.token-pill:last-child { border-right: none; }
.token-pill:hover { outline-color: var(--muted); }
.token-pill.active { outline-color: var(--accent); font-weight: 600; }
.token-pill.locked { outline: 2px solid var(--accent); outline-offset: 1px; }

.token-alt-row {
  display: grid;
  grid-template-columns: 90px 1fr 48px;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
  font-size: 0.85rem;
}
.token-alt-label {
  font-family: 'Consolas', 'Menlo', monospace;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.token-alt-bar-track {
  height: 10px;
  border-radius: 5px;
  background: var(--border);
  overflow: hidden;
  display: block;
}
.token-alt-bar-fill {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 5px;
}
.token-alt-pct {
  color: var(--muted);
  text-align: right;
  font-size: 0.8rem;
}

/* ── HALLUCINATED CITATIONS ── */
/* Same column pattern as #plotter-app and #token-app: fixed header, scrolling body. */
#citation-app {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--disclaimer-h));
  overflow: hidden;
}

#cite-shell {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

#cite-panel {
  width: 220px;
  flex-shrink: 0;
  background-color: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  box-shadow: var(--card-shadow);
}
#cite-panel::-webkit-scrollbar { width: 5px; }
#cite-panel::-webkit-scrollbar-track { background: transparent; }
#cite-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

#cite-main {
  position: relative;
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 26px 24px 32px;
}

.cite-block { margin-bottom: 30px; }
.cite-block:last-child { margin-bottom: 0; }

.cite-block-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  padding-bottom: 8px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.cite-block-head h3 {
  font-family: var(--serif);
  font-size: 1.35rem;
  font-weight: 400;
  color: var(--text);
  margin: 0;
}
.cite-block-count {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

/* The instructor's prompt, echoed on the projected view so the class can see
   what was asked. Set in ⚙ Exercises. */
.cite-prompt-line {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: -4px 0 14px;
  font-size: 0.9rem;
  line-height: 1.5;
  color: var(--muted);
}
.cite-prompt-tag {
  flex-shrink: 0;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold);
}

/* ── Submitted citations ── */
.cite-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 8px;
}
@media (max-width: 700px) {
  .cite-list { grid-template-columns: 1fr; }
}

.cite-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 5px;
  padding: 9px 13px;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text);
  word-break: break-word;
}
/* Italic only — the display serif gets muddy at citation-list sizes. */
.cite-item-name { font-style: italic; }
.cite-item-rest { color: var(--text); }

/* New submissions land with a brief flash so the class can see them arrive. */
@keyframes cite-flash {
  from { background: var(--accent); color: var(--card); border-left-color: var(--gold); }
  to   { background: var(--card); }
}
.cite-item.is-new { animation: cite-flash 1.4s ease-out; }

.cite-empty {
  font-size: 0.88rem;
  color: var(--muted);
  padding: 18px 2px;
}

/* ── Part-by-part cards ── */
/* Equal columns while they fit; scrolls sideways rather than squeezing. */
.cite-parts-row {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 6px;
  align-items: stretch;
}
.cite-parts-row::-webkit-scrollbar { height: 7px; }
.cite-parts-row::-webkit-scrollbar-track { background: transparent; }
.cite-parts-row::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.cite-part-card {
  flex: 1 1 0;
  min-width: 150px;
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.cite-part-head {
  padding: 9px 12px 8px;
  border-bottom: 1px solid var(--border);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold);
}

.cite-part-values {
  flex: 1;
  overflow-y: auto;
  max-height: 42vh;
  padding: 6px 0;
}
.cite-part-values::-webkit-scrollbar { width: 5px; }
.cite-part-values::-webkit-scrollbar-track { background: transparent; }
.cite-part-values::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.cite-part-value {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 12px;
  font-size: 0.88rem;
  line-height: 1.4;
  color: var(--text);
  word-break: break-word;
}
.cite-part-value + .cite-part-value { border-top: 1px solid var(--border); }
.cite-part-value.has-records { cursor: help; }
.cite-part-value.has-records:hover { background: var(--bg); }
.cite-part-count {
  flex-shrink: 0;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--link);
  font-variant-numeric: tabular-nums;
}

.cite-part-foot {
  padding: 7px 12px;
  border-top: 1px solid var(--border);
  font-size: 0.73rem;
  line-height: 1.4;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
/* The punchline: a part where no two students landed on the same value. */
.cite-part-foot.all-distinct { color: var(--danger); font-weight: 600; }

/* Hover readout for a part value — every citation that value came from. */
.cite-tooltip {
  position: fixed;
  z-index: 200;
  pointer-events: none;
  max-width: min(480px, 90vw);
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  background: var(--card);
  box-shadow: 0 6px 22px rgba(0,0,0,0.18);
  font-size: 0.88rem;
  line-height: 1.5;
  color: var(--text);
}
.cite-tooltip-head {
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 6px;
}
.cite-tooltip-line + .cite-tooltip-line { margin-top: 4px; }
.cite-tooltip-more {
  margin-top: 6px;
  font-size: 0.78rem;
  color: var(--muted);
}

/* ── Student submit view (tabbed, every exercise on one page) ── */
#submit-view {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px;
  box-sizing: border-box;
  overflow-y: auto;
  background: var(--bg);
}
/* Top-aligned, not centered: the forms differ in height, and centering would
   make the name field and tabs jump every time a student switches tabs. */
.submit-shell { width: 100%; max-width: 440px; margin: 8px auto 0; }
.submit-name { margin-bottom: 16px; }

.submit-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  margin-bottom: 18px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.submit-tab {
  padding: 10px 8px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font: 600 0.95rem var(--font);
  cursor: pointer;
}
.submit-tab[aria-selected="true"] {
  background: var(--accent);
  color: var(--btn-primary-text, #fff);
}
.submit-tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.submit-intro {
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.5;
  text-align: center;
  margin-bottom: 16px;
}

/* ── Student submit form ── */
.cite-sub-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}
.cite-sub-input {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  font-family: var(--font);
}
.cite-sub-input:focus { outline: none; border-color: var(--accent); }

.cite-sub-row {
  display: grid;
  grid-template-columns: 0.8fr 1.5fr 0.9fr;
  gap: 10px;
}
.cite-sub-row-2 { grid-template-columns: 1.6fr 1fr; }

.cite-sub-preview {
  border: 1px dashed var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 0.95rem;
  line-height: 1.55;
  color: var(--text);
  min-height: 1.55em;
  word-break: break-word;
}
.cite-sub-preview-empty { color: var(--muted); font-style: italic; }

/* ── RESEARCH EXERCISE ── */
/* Fills whatever the header leaves, rather than assuming a fixed header height —
   the old `100vh - 58px` was 5px short of the real 63px bar. Same column pattern
   as #token-app and #plotter-app. */
#research-app {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--disclaimer-h));
  overflow: hidden;
}
#research-app > .mod-header-bar { flex-shrink: 0; }

.research-shell {
  display: flex;
  gap: 0;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.research-left {
  width: 50%;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  padding: 28px 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
  background: var(--card);
}

.research-right {
  flex: 1;
  min-width: 0;
  padding: 28px 32px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.research-section-label {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 4px;
}

.research-type-selector {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.research-type-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.research-type-option:has(input:checked) {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 6%, transparent);
}

.research-type-option input[type="radio"] {
  accent-color: var(--accent);
  width: 16px; height: 16px;
  flex-shrink: 0;
}

.research-type-label {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--text);
}

.research-instructions-area {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px 16px;
  background: var(--bg);
  font-size: 0.88rem;
  line-height: 1.65;
  color: var(--text);
  min-height: 100px;
  overflow-y: auto;
}

.research-instructions-placeholder {
  color: var(--muted);
  font-style: italic;
}

.research-names-textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 0.95rem;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  resize: vertical;
  outline: none;
  transition: border-color 0.15s;
  display: block;
}

.research-names-textarea:focus { border-color: var(--accent); }

.research-assign-btn {
  align-self: flex-start;
}

.research-status {
  font-size: 0.88rem;
  color: var(--danger);
  min-height: 1.2em;
}

.research-results {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.research-result-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
  box-shadow: var(--card-shadow);
}

.research-result-name {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.research-result-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}

.research-result-cell {
  display: flex;
  gap: 10px;
  font-size: 0.88rem;
  line-height: 1.5;
}

.research-cell-label {
  font-weight: 600;
  color: var(--gold);
  min-width: 100px;
  flex-shrink: 0;
  text-transform: capitalize;
}

.research-cell-value {
  color: var(--text);
}

@media (max-width: 680px) {
  .research-shell { flex-direction: column; height: auto; overflow: visible; }
  .research-left { width: 100%; border-right: none; border-bottom: 1px solid var(--border); }
  .research-right { padding: 20px 16px; }
}

/* ── INPUT · FUNCTION · OUTPUT ── */
/* Presentation board: three columns of draggable cards. Colors come from the
   theme tokens so saved color schemes restyle it along with everything else. */
#iof-app {
  --iof-in:  var(--gold);
  --iof-fn:  var(--link);   /* used as text, so it follows the link color */
  --iof-out: var(--text);   /* the one theme color that stays legible on every scheme, light or dark */
  --iof-scale: 1;
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--disclaimer-h));
  overflow: hidden;
}
#iof-app[data-size="s"] { --iof-scale: 0.85; }
#iof-app[data-size="l"] { --iof-scale: 1.3; }

.iof-size {
  display: flex;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  margin-right: 4px;
}
.iof-size-btn {
  width: 30px; height: 31px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: var(--serif);
  cursor: pointer;
  line-height: 1;
}
.iof-size-btn[data-iof-size="s"] { font-size: 0.8rem; }
.iof-size-btn[data-iof-size="m"] { font-size: 1rem; }
.iof-size-btn[data-iof-size="l"] { font-size: 1.25rem; }
.iof-size-btn + .iof-size-btn { border-left: 1px solid var(--border); }
.iof-size-btn:hover { background: var(--btn-secondary-bg); }
.iof-size-btn[aria-pressed="true"] { background: var(--btn-secondary-bg); color: var(--text); }

#iof-main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 22px 28px 40px;
  display: flex;
  flex-direction: column;
}

#iof-main .iof-title {
  width: 100%;
  font-family: var(--serif);
  font-size: calc(2rem * var(--iof-scale));
  line-height: 1.2;
  color: var(--text);
  background: transparent;
  border: 0;
  border-bottom: 1px dashed transparent;
  border-radius: 0;
  padding: 2px 0 6px;
  margin-bottom: 18px;
}
#iof-main .iof-title:hover { border-bottom-color: var(--border); }
#iof-main .iof-title:focus { border-bottom-color: var(--accent); }
.iof-title::placeholder { color: var(--muted); opacity: 0.6; }

.iof-board {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 0 14px;
  align-items: stretch;
}

.iof-arrow {
  align-self: start;
  padding-top: calc(14px * var(--iof-scale));
  font-size: calc(2rem * var(--iof-scale));
  line-height: 1;
  color: var(--muted);
  opacity: 0.55;
  user-select: none;
}

.iof-col {
  --col: var(--iof-in);
  display: flex;
  flex-direction: column;
  min-height: 320px;
  background: color-mix(in srgb, var(--col) 5%, var(--bg));
  border: 1px solid color-mix(in srgb, var(--col) 22%, var(--border));
  border-top: 4px solid var(--col);
  border-radius: var(--radius);
  transition: background 0.12s, border-color 0.12s;
}
.iof-col[data-col="fn"]  { --col: var(--iof-fn); }
.iof-col[data-col="out"] { --col: var(--iof-out); }
.iof-col.is-drop-target {
  background: color-mix(in srgb, var(--col) 11%, var(--bg));
  border-color: var(--col);
}

.iof-col-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: calc(12px * var(--iof-scale)) 16px 10px;
}
.iof-col-head h3 {
  font-size: calc(1.05rem * var(--iof-scale));
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--col);
  margin: 0;
}
.iof-col-head span {
  font-size: calc(0.8rem * var(--iof-scale));
  color: var(--muted);
}

/* The list itself is the click-to-add target: clicking empty space in a
   column starts a new card there. */
.iof-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: calc(12px * var(--iof-scale));
  padding: 4px 14px 14px;
  min-height: 80px;
  cursor: copy;
}
.iof-list:empty::before {
  content: 'Click to add';
  margin: auto;
  font-size: 0.85rem;
  color: var(--muted);
  opacity: 0.6;
  pointer-events: none;
}

.iof-add {
  margin: 0 14px 14px;
  padding: 9px;
  border: 1.5px dashed color-mix(in srgb, var(--col) 40%, var(--border));
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.iof-add:hover {
  color: var(--col);
  border-color: var(--col);
  background: color-mix(in srgb, var(--col) 6%, transparent);
}

/* ── Cards ── */
.iof-card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 5px solid var(--col);
  border-radius: 6px;
  padding: calc(12px * var(--iof-scale)) 66px calc(12px * var(--iof-scale)) 14px;
  box-shadow: var(--card-shadow);
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.iof-card:hover .iof-card-btn,
.iof-card.is-selected .iof-card-btn { opacity: 1; }
.iof-card.is-selected {
  outline: 2px solid var(--col);
  outline-offset: 2px;
}
.iof-card.is-editing { cursor: text; touch-action: auto; }

.iof-card-text {
  font-size: calc(1.15rem * var(--iof-scale));
  font-weight: 600;
  line-height: 1.35;
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  outline: none;
  min-height: 1.35em;
}
.iof-card-text:empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
  font-weight: 400;
  opacity: 0.7;
}
.iof-card.is-editing .iof-card-text,
.iof-card.is-editing .iof-card-sub-text {
  user-select: text;
  cursor: text;
}

.iof-card-actions {
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  gap: 2px;
}
.iof-card-btn {
  opacity: 0;
  transition: opacity 0.12s, background 0.12s;
  width: 26px; height: 26px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
}
.iof-card-btn:hover { background: var(--btn-secondary-bg); color: var(--text); }
.iof-card-btn[data-act="delete"]:hover { color: var(--danger); }
/* ⧉ stays on screen whenever the card has a sub-process, shown or hidden,
   so a collapsed one still announces itself. Tinted while the line is open. */
.iof-card.is-sub .iof-card-btn[data-act="sub"] { opacity: 1; color: var(--col); }
.iof-card-btn[data-act="sub"][aria-pressed="true"] { background: color-mix(in srgb, var(--col) 14%, transparent); }

/* Sub-process: the card is itself the product of another
   input → function → output chain. Two offset sheets behind it read as a
   stack — "there is more underneath this". The stack stays whether the
   process line is shown (.is-sub-open) or tucked away. */
.iof-card.is-sub {
  margin: 0 10px 10px 0;
  box-shadow:
    5px 5px 0 -1px var(--card), 5px 5px 0 0 color-mix(in srgb, var(--col) 45%, var(--border)),
    10px 10px 0 -1px var(--card), 10px 10px 0 0 color-mix(in srgb, var(--col) 30%, var(--border)),
    var(--card-shadow);
}

.iof-card-sub {
  display: none;
  align-items: flex-start;
  gap: 8px;
  margin-top: calc(9px * var(--iof-scale));
  padding-top: calc(8px * var(--iof-scale));
  border-top: 1px dashed color-mix(in srgb, var(--col) 35%, var(--border));
  margin-right: -52px;   /* past the action-button gutter: only the name line needs to clear it */
}
.iof-card.is-sub-open .iof-card-sub { display: flex; }

/* One click on the process line edits it — no double-click needed. */
.iof-card.is-sub-open .iof-card-sub-text { cursor: text; }

.iof-card-btn.iof-sub-remove {
  width: auto;
  height: auto;
  flex-shrink: 0;
  padding: 2px 6px;
  font-family: var(--font);
  font-size: calc(0.72rem * var(--iof-scale));
  font-weight: 600;
  letter-spacing: 0.04em;
}
.iof-card-btn.iof-sub-remove:hover { color: var(--danger); }
.iof-card.is-editing .iof-sub-remove { opacity: 1; }

/* A miniature of the board itself: three boxes and two arrows. */
.iof-glyph {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  margin-top: calc(5px * var(--iof-scale));
}
.iof-glyph i {
  display: block;
  width: calc(8px * var(--iof-scale));
  height: calc(8px * var(--iof-scale));
  border-radius: 2px;
  border: 1.5px solid var(--iof-in);
}
.iof-glyph i:nth-of-type(2) { border-color: var(--iof-fn); }
.iof-glyph i:nth-of-type(3) { border-color: var(--iof-out); }
.iof-glyph b {
  display: block;
  width: calc(5px * var(--iof-scale));
  height: 1.5px;
  background: var(--muted);
}

.iof-card-sub-text {
  flex: 1;
  min-width: 0;
  font-size: calc(0.88rem * var(--iof-scale));
  font-style: italic;
  line-height: 1.4;
  color: var(--muted);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  outline: none;
}
.iof-card-sub-text:empty::before {
  content: attr(data-placeholder);
  opacity: 0.6;
}
/* Outside of editing, an unnamed sub-process just shows the label. */
.iof-card:not(.is-editing) .iof-card-sub-text:empty::before { content: 'Its own process'; opacity: 0.85; }

/* ── Dragging ── */
.iof-card.is-placeholder {
  opacity: 0.35;
  box-shadow: none;
  border-style: dashed;
}
.iof-card.is-placeholder .iof-card-btn { opacity: 0; }
.iof-drag-clone {
  position: fixed;
  z-index: 500;
  margin: 0;
  pointer-events: none;
  transform: rotate(-1.5deg);
  box-shadow: 0 14px 30px rgba(0,0,0,0.22);
}
body.iof-dragging, body.iof-dragging * { cursor: grabbing !important; }

/* ── Undo toast ── */
.iof-toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--disclaimer-h) + 18px);
  transform: translateX(-50%);
  z-index: 400;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 12px 10px 16px;
  border-radius: 8px;
  background: var(--header);
  color: var(--header-text, #fff);
  font-size: 0.88rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}
.iof-toast button {
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 5px;
  background: transparent;
  color: inherit;
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 5px 10px;
  cursor: pointer;
}
.iof-toast button:hover { background: rgba(255,255,255,0.12); }

@media (max-width: 760px) {
  #iof-main { padding: 16px 16px 32px; }
  .iof-board { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .iof-arrow { justify-self: center; padding-top: 0; transform: rotate(90deg); }
  .iof-col { min-height: 180px; }
  .iof-size, .iof-tool-btn { display: none; }
}
@media (hover: none) {
  .iof-card-btn { opacity: 1; }
}

/* ── Arrows between cards ── */
/* The SVG layer sits over the column backgrounds but under the cards. */
.iof-board { position: relative; }
.iof-card { z-index: 2; }
.iof-links {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
  z-index: 1;
}
.iof-link-line {
  fill: none;
  stroke: var(--lc);
  stroke-width: 2;
  stroke-linecap: round;
  opacity: 0.55;
  transition: opacity 0.12s;
}
.iof-link-head { fill: var(--lc); opacity: 0.55; transition: opacity 0.12s; }
/* A wide invisible stroke so a 2px line is easy to click. */
.iof-link-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 14;
  pointer-events: stroke;
  cursor: pointer;
}
/* Mid-drag, arrows must not sit between the pointer and the column under it. */
body.iof-dragging .iof-link-hit,
body.iof-linking .iof-link-hit { pointer-events: none; }
.iof-link:hover .iof-link-line, .iof-link:hover .iof-link-head,
.iof-link.is-hot .iof-link-line, .iof-link.is-hot .iof-link-head,
.iof-link.is-selected .iof-link-line, .iof-link.is-selected .iof-link-head,
.iof-link.is-drawing .iof-link-line, .iof-link.is-drawing .iof-link-head { opacity: 1; }
.iof-link.is-hot .iof-link-line { stroke-width: 3; }
.iof-link.is-selected .iof-link-line { stroke-width: 3.5; }
.iof-link.is-drawing .iof-link-line { stroke-width: 2.5; stroke-dasharray: 6 5; }

.iof-link-del { pointer-events: all; cursor: pointer; }
.iof-link-del circle { fill: var(--card); stroke: var(--lc); stroke-width: 1.5; }
.iof-link-del path { stroke: var(--lc); stroke-width: 2; stroke-linecap: round; }
.iof-link-del:hover circle { fill: var(--lc); }
.iof-link-del:hover path { stroke: var(--card); }

/* The dot to drag an arrow from. */
.iof-link-handle {
  position: absolute;
  top: 50%;
  right: -8px;
  width: 15px;
  height: 15px;
  margin-top: -7.5px;
  border-radius: 50%;
  border: 2px solid var(--col);
  background: var(--card);
  cursor: crosshair;
  touch-action: none;
  opacity: 0;
  transition: opacity 0.12s, transform 0.12s, background 0.12s;
  z-index: 3;
}
.iof-card:hover .iof-link-handle,
.iof-card.is-selected .iof-link-handle { opacity: 1; }
.iof-link-handle:hover { transform: scale(1.3); background: var(--col); }
.iof-card.is-placeholder .iof-link-handle,
.iof-drag-clone .iof-link-handle { display: none; }
.iof-card.is-link-target {
  outline: 2px dashed var(--col);
  outline-offset: 3px;
}
body.iof-linking, body.iof-linking * { cursor: crosshair !important; }

@media (hover: none) {
  .iof-link-handle { opacity: 1; }
}
/* Stacked phone layout: there is no sensible way to draw the arrows. */
@media (max-width: 760px) {
  .iof-links, .iof-link-handle { display: none; }
}
