:root {
  --bg: #f4f4ef;
  --surface: #ffffff;
  --surface-soft: #fafaf6;
  --ink: #1c211e;
  --ink-soft: #454d48;
  --muted: #737b75;
  --line: #e1e1d8;
  --line-strong: #cdcec4;
  --accent: #1d5a46;
  --accent-hover: #164838;
  --accent-soft: #e9f1ec;
  --warm: #a45d3d;
  --danger: #9f3f36;
  --danger-soft: #fbeeec;
  --warning: #7d5b1f;
  --radius: 10px;
  --sans: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --mono: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  --shadow: 0 1px 2px rgba(28, 33, 30, 0.04);
}

html[data-theme="dark"] {
  --bg: #141713;
  --surface: #1c211e;
  --surface-soft: #202621;
  --ink: #eef2ed;
  --ink-soft: #c5cec6;
  --muted: #939f96;
  --line: #30372f;
  --line-strong: #465148;
  --accent: #7fc7a9;
  --accent-hover: #9ad9be;
  --accent-soft: #203a31;
  --warm: #d79a75;
  --danger: #e08a7f;
  --danger-soft: #3a2320;
  --warning: #d3b06a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}
html[data-theme="dark"] .app-sidebar { background: #171b18; }
html[data-theme="dark"] code { background: #252b26; }
html[data-theme="dark"] .side-link:hover { background: #252b26; }
html[data-theme="dark"] .segmented, html[data-theme="dark"] .auth-tabs { background: #252b26; }
html[data-theme="dark"] .turn-answer { background: #242a25; }
html[data-theme="dark"] .turn-hint { background: #2b241d; }
html[data-theme="dark"] .reveal-box { background: #1f3026; border-color: #365b45; }
html[data-theme="dark"] .segmented .segment.is-selected, html[data-theme="dark"] .auth-tab.is-active { background: #343c35; color: var(--ink); }
html[data-theme="dark"] .topbar { background: rgba(20, 23, 19, 0.92); }

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  min-height: 100vh;
}

a { color: var(--accent); }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: #f1f1eb;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
}

.app-shell { display: flex; min-height: 100vh; }

/* Sidebar */
.app-sidebar {
  width: 224px;
  flex: 0 0 224px;
  background: #fbfbf8;
  border-right: 1px solid var(--line);
  padding: 24px 16px 20px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  padding: 0 8px;
  margin-bottom: 34px;
}
.brand-logo { width: 26px; height: 26px; border-radius: 7px; object-fit: cover; }
.brand-mark {
  width: 27px;
  height: 27px;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: var(--surface);
  border-radius: 6px;
  font-family: var(--serif);
  font-size: 17px;
  font-style: italic;
}
.brand-name { font-size: 15px; font-weight: 650; letter-spacing: -0.01em; }

.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-link {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  text-align: left;
  padding: 9px 10px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 550;
  text-decoration: none;
}
.side-link:hover { background: #f1f1eb; color: var(--ink); }
.side-link.is-active { background: var(--accent-soft); color: var(--accent); }
.nav-glyph { font-family: var(--mono); font-size: 9px; color: var(--muted); width: 15px; }
.side-link.is-active .nav-glyph { color: var(--accent); }

.sidebar-note { margin-top: auto; padding: 0 10px; }
.note-rule { display: block; width: 28px; border-top: 1px solid var(--line-strong); margin-bottom: 12px; }
.sidebar-note p { margin: 0 0 2px; font-size: 11.5px; font-weight: 650; color: var(--ink-soft); }
.sidebar-note small { color: var(--muted); font-size: 10.5px; line-height: 1.45; display: block; }
.account-block { margin-top: auto; padding: 0 8px; border-top: 0; display: flex; flex-direction: column; gap: 10px; }
.account-name { color: var(--ink-soft); font-size: 11px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.owner-link { color: var(--muted); font-size: 11px; font-weight: 400; text-decoration: none; }
.owner-link:hover { color: var(--accent); }
.logout-button { text-align: left; border: 1px solid var(--line); background: transparent; border-radius: 6px; color: var(--ink-soft); padding: 6px 8px; font-size: 10.5px; }
.logout-button:hover { border-color: var(--danger); color: var(--danger); }

/* Settings */
.settings-backdrop { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 20px; background: rgba(10, 14, 11, 0.45); }
.settings-panel { width: min(480px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 20px; box-shadow: 0 18px 60px rgba(0, 0, 0, 0.22); }
.settings-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.settings-head h2 { margin: 2px 0 0; font-size: 22px; }
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 12px 0; border-top: 1px solid var(--line); }
.settings-row strong { display: block; font-size: 12px; }
.settings-row small { display: block; margin-top: 2px; color: var(--muted); font-size: 10.5px; line-height: 1.4; }
.settings-row input { width: 110px; flex: 0 0 110px; }
.choice-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 12px 0; }
.choice-button { display: flex; align-items: center; gap: 10px; text-align: left; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); border-radius: 8px; padding: 11px 12px; font: inherit; font-size: 12.5px; cursor: pointer; transition: border-color 140ms ease, background 140ms ease, color 140ms ease; }
.choice-button:hover { border-color: var(--accent); }
.choice-button.is-selected { border-color: var(--accent); background: var(--accent); color: #fff; }
.choice-letter { display: inline-grid; place-items: center; flex: 0 0 24px; height: 24px; border-radius: 6px; border: 1px solid currentColor; font-size: 11px; font-weight: 750; }
.choice-button.is-selected .choice-letter { background: rgba(255,255,255,0.16); }
.answer-label { color: var(--muted); font-size: 10.5px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.exam-choice-grid { margin-top: 8px; }

@media (max-width: 620px) {
  .choice-grid { grid-template-columns: 1fr; }
}
.switch { position: relative; display: inline-flex; flex: 0 0 44px; width: 44px; height: 24px; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 2; }
.switch-track { width: 44px; height: 24px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface-soft); transition: background 140ms ease, border-color 140ms ease; }
.switch-track::after { content: ""; display: block; width: 18px; height: 18px; margin: 2px; border-radius: 50%; background: var(--muted); transition: transform 140ms ease, background 140ms ease; }
.switch input:checked + .switch-track { background: var(--accent-soft); border-color: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(20px); background: var(--accent); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.settings-row select { width: 130px; flex: 0 0 130px; }
.settings-actions { display: flex; justify-content: flex-end; padding-top: 12px; border-top: 1px solid var(--line); }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; background: rgba(8, 12, 9, 0.55); }
.modal-card { width: min(420px, 100%); background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 12px; padding: 20px; box-shadow: 0 22px 70px rgba(0, 0, 0, 0.3); }
.modal-title { margin: 0 0 6px; font-size: 18px; letter-spacing: -0.01em; }
.modal-message { margin: 0; color: var(--ink-soft); font-size: 12.5px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.modal-label { display: flex; flex-direction: column; gap: 5px; margin-top: 14px; color: var(--muted); font-size: 10.5px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.modal-input { width: 100%; margin-top: 2px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.danger-button { border: 1px solid #b9574c; background: #a8443a; color: #fff; border-radius: 6px; padding: 7px 13px; font-size: 11.5px; font-weight: 650; }
.danger-button:hover { background: #92372e; }
.settings-view-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; align-items: start; }
.settings-card { padding: 17px 18px; }
.settings-card .settings-row:first-of-type { border-top: 0; }
.settings-card .settings-actions { border-top: 0; }
.feedback-form { display: flex; flex-direction: column; gap: 10px; }
.onboarding-card { margin-bottom: 18px; border: 1px solid var(--accent); border-radius: 10px; padding: 17px 19px; background: var(--accent-soft); }
.onboarding-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.onboarding-kicker { color: var(--accent); font-size: 9.5px; font-weight: 750; letter-spacing: 0.09em; text-transform: uppercase; }
.onboarding-card h2 { margin: 8px 0 4px; font-family: var(--serif); font-size: 22px; font-weight: 500; letter-spacing: -0.02em; }
.onboarding-card > p { margin: 0 0 13px; color: var(--ink-soft); font-size: 12px; }
.onboarding-steps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; }
.onboarding-steps li { display: flex; gap: 8px; align-items: flex-start; border: 1px solid var(--line); border-radius: 7px; padding: 9px; background: var(--surface); }
.onboarding-steps li.is-done { border-color: var(--accent); }
.onboarding-number { display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 10px; font-weight: 750; flex: 0 0 20px; }
.onboarding-steps li.is-done .onboarding-number { background: var(--accent); color: #fff; }
.onboarding-steps strong { display: block; font-size: 11px; }
.onboarding-steps small { display: block; margin-top: 2px; color: var(--muted); font-size: 9.5px; line-height: 1.4; }
.onboarding-actions { display: flex; gap: 8px; margin-top: 12px; }
@media (max-width: 700px) { .onboarding-steps { grid-template-columns: 1fr; } }
.rating-block { border: 1px solid var(--line); border-radius: 8px; padding: 11px 12px; background: var(--surface-soft); display: flex; flex-direction: column; gap: 8px; }
.rating-title { margin: 0; color: var(--muted); font-size: 10px; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase; }
.rating-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.rating-row > span { color: var(--ink-soft); font-size: 11.5px; }
.rating-buttons { display: inline-flex; gap: 4px; }
.rating-button { width: 28px; height: 26px; border: 1px solid var(--line-strong); border-radius: 5px; background: var(--surface); color: var(--ink-soft); font-size: 11px; font-weight: 650; }
.rating-button:hover { border-color: var(--accent); color: var(--accent); }
.rating-button.is-selected { background: var(--accent); border-color: var(--accent); color: #fff; }
.feedback-form textarea { resize: vertical; }

@media (max-width: 900px) {
  .settings-view-grid { grid-template-columns: 1fr; }
}

/* Main */
.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  border-bottom: 1px solid var(--line);
  background: rgba(251, 251, 248, 0.92);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(8px);
}
.topbar-label { font-size: 12px; font-weight: 650; color: var(--muted); letter-spacing: 0.01em; }
.topbar-actions { display: flex; gap: 7px; align-items: center; }
.quiet-button {
  background: transparent;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--ink-soft);
  padding: 5px 10px;
  font-size: 11.5px;
  font-weight: 600;
}
.quiet-button:hover { border-color: var(--accent); color: var(--accent); }

.content { width: 100%; max-width: 1160px; margin: 0 auto; padding: 34px 34px 60px; flex: 1; }
.view { display: none; animation: fade-in 180ms ease both; }
.view.is-active { display: block; }
@keyframes fade-in { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

.page-heading { margin-bottom: 22px; }
.page-heading h1 { margin: 0; font-size: 27px; line-height: 1.2; letter-spacing: -0.025em; font-weight: 650; }
.page-heading p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }

.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #eeeee8;
  margin-bottom: 18px;
}
.segment {
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  border-radius: 5px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
}
.segment:hover { color: var(--ink); }
.segment.is-selected { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,0.07); }

.tutor-layout { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(280px, 0.72fr); gap: 16px; align-items: start; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.session-card { padding: 20px; min-height: 350px; }
.references-card { padding: 18px; position: sticky; top: 76px; }

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.card-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card-tools select { width: auto; min-width: 150px; max-width: 230px; padding: 5px 8px; font-size: 10.5px; }
.card-head h2 { margin: 0; font-size: 13px; font-weight: 650; }
.count { color: var(--muted); font-family: var(--mono); font-size: 10px; }
.card-note { margin: 0 0 14px; color: var(--muted); font-size: 11px; line-height: 1.5; }

.mode-panel { border-bottom: 1px solid var(--line); padding-bottom: 18px; margin-bottom: 18px; }
.start-form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field-row { display: flex; gap: 10px; align-items: flex-end; }
.field-row .field:first-child { flex: 1; }
.field-row .field-compact { flex: 0 0 155px; }
.field label, .answer-head label, .extracted-text label {
  color: var(--ink-soft);
  font-size: 11.5px;
  font-weight: 650;
}
.field-note { color: var(--muted); font-size: 9.5px; line-height: 1.35; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], textarea, select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  padding: 9px 11px;
  outline: none;
  line-height: 1.55;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
input[type="text"], input[type="email"], input[type="password"], input[type="number"], select { height: 38px; }
select { cursor: pointer; }
textarea { resize: vertical; min-height: 82px; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(29, 90, 70, 0.1); }
::placeholder { color: #9ba19b; }

.form-foot { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.hint { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.primary-button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #f8f7f1;
  border-radius: 7px;
  padding: 8px 13px;
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
  transition: background 120ms ease;
}
.primary-button:hover { background: var(--accent-hover); }
.primary-button:disabled { opacity: 0.55; cursor: wait; }
.text-button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0;
  font-size: 11px;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.text-button:hover { color: var(--danger); }

.upload-line { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.file-button {
  display: inline-block;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
}
.file-button:hover { border-color: var(--accent); color: var(--accent); }
.file-name { color: var(--muted); font-size: 11px; max-width: 250px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.extracted-text { display: flex; flex-direction: column; gap: 5px; background: var(--surface-soft); border: 1px solid var(--line); border-radius: 7px; padding: 10px; }
.extracted-text label span { font-weight: 400; color: var(--muted); }
.extracted-text textarea { min-height: 90px; background: var(--surface); font-size: 12.5px; }

.alert { margin: 14px 0; padding: 10px 12px; border: 1px solid var(--danger); border-radius: 7px; background: var(--danger-soft); color: var(--danger); font-size: 12px; }

/* Conversation */
.conversation { display: flex; flex-direction: column; gap: 16px; min-height: 120px; }
.conversation-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0 2px; margin-top: 4px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 9.5px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.conversation-tools { display: flex; align-items: center; gap: 8px; }
.timer-chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 999px; padding: 3px 8px; color: var(--ink-soft); background: var(--surface-soft); font-size: 9.5px; letter-spacing: 0; text-transform: none; }
.timer-chip strong { font-family: var(--mono); font-size: 11px; color: var(--accent); }
.timer-chip.is-expired { border-color: var(--danger); color: var(--danger); }
.timer-chip.is-expired strong { color: var(--danger); }
.exam-question-timer { margin-left: auto; }
.empty-state { border: 1px dashed var(--line-strong); border-radius: 8px; padding: 22px; color: var(--muted); background: var(--surface-soft); }
.empty-state p { margin: 0; max-width: 540px; font-size: 12px; line-height: 1.6; }
.empty-state .empty-kicker { margin-bottom: 4px; color: var(--ink-soft); font-size: 11.5px; font-weight: 650; }

.turn { display: flex; flex-direction: column; gap: 5px; }
.turn-label { color: var(--muted); font-size: 9.5px; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; }
.turn-body { color: var(--ink-soft); font-size: 13px; line-height: 1.7; }
.turn-body p { margin: 0 0 9px; }
.turn-body p:last-child { margin-bottom: 0; }
.turn-body strong { color: var(--ink); font-weight: 650; }
.turn-question { border-left: 2px solid var(--accent); padding: 2px 0 2px 14px; }
.turn-question .turn-body { color: var(--ink); font-family: var(--serif); font-size: 15px; line-height: 1.6; }
.turn-answer { align-self: flex-end; max-width: 88%; background: #f3f5f1; border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; }
.turn-answer .turn-label { text-align: right; }
.turn-feedback { border-top: 1px solid var(--line); padding-top: 12px; }
.turn-hint { border-left: 2px solid var(--warm); padding: 2px 0 2px 14px; background: #fcf7ef; border-radius: 0 6px 6px 0; padding-right: 10px; }
.turn-hint .turn-body { font-size: 12.5px; }
.turn-feedback .turn-body { font-size: 12.5px; }
.lineage { margin-top: 9px; border-top: 1px dashed var(--line); padding-top: 8px; color: var(--muted); font-size: 10.5px; }
.lineage strong { color: var(--ink-soft); }

.answer-block { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }
.answer-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.attempt-label { color: var(--muted); font-size: 10.5px; font-family: var(--mono); }
.answer-foot { display: flex; justify-content: space-between; align-items: center; gap: 14px; margin-top: 9px; }
.answer-upload { margin-top: 8px; }
.answer-upload .file-name { font-size: 10.5px; }
.attempt-dots { display: flex; gap: 5px; }
.attempt-dot { width: 6px; height: 6px; border-radius: 50%; background: #d9dad1; }
.attempt-dot.is-filled { background: var(--accent); }
.answer-block .hint { margin-top: 7px; }

.reveal-box { margin-top: 16px; padding: 13px 14px; border: 1px solid #cfe0d3; border-radius: 8px; background: #f0f7f1; font-size: 12.5px; line-height: 1.65; }
.reveal-box h3 { margin: 0 0 5px; font-size: 13px; }
.reveal-box .key { font-family: var(--mono); font-size: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 5px; padding: 7px 8px; margin: 7px 0; white-space: pre-wrap; }

/* References */
.source-list { display: flex; flex-direction: column; gap: 8px; max-height: 500px; overflow: auto; padding-right: 2px; }
.source-item { border: 1px solid var(--line); border-radius: 7px; padding: 10px; background: var(--surface-soft); }
.source-top { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.source-ref { font-family: var(--mono); font-size: 9px; color: var(--accent); background: var(--accent-soft); border-radius: 3px; padding: 1px 4px; }
.source-page { color: var(--warm); font-family: var(--mono); font-size: 9.5px; }
.source-kind { margin-left: auto; color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: 0.05em; }
.source-item h3 { margin: 0 0 3px; font-size: 11.5px; font-weight: 650; line-height: 1.35; }
.source-item p { margin: 0; color: var(--muted); font-size: 10.5px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.source-item footer { margin-top: 5px; color: #969d96; font-family: var(--mono); font-size: 8.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-note { color: var(--muted); font-size: 11px; line-height: 1.5; margin: 0; }

/* Exam */
.exam-builder { padding: 18px 20px; margin-bottom: 16px; }
.exam-form { display: flex; flex-direction: column; gap: 11px; }
.exam-form .field { max-width: 560px; }
.exam-foot { max-width: 900px; }
.exam-config-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; max-width: 760px; }
.exam-config-grid .field { max-width: none; }
.course-checks { display: flex; flex-wrap: wrap; gap: 6px; }
.type-checks { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 5px; }
.type-check { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; font-size: 11px; color: var(--ink-soft); background: var(--surface-soft); cursor: pointer; }
.type-check input { accent-color: var(--accent); }
.type-check:hover { border-color: var(--accent); }
.course-check { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; font-size: 11px; color: var(--ink-soft); background: var(--surface-soft); cursor: pointer; }
.course-check input { accent-color: var(--accent); }
.course-check:hover { border-color: var(--accent); }
.course-note { border-left: 2px solid var(--accent); padding: 2px 0 2px 12px; }
.course-note strong { display: block; font-size: 12px; margin-bottom: 2px; }
.course-note p { margin: 0; color: var(--muted); font-size: 11.5px; line-height: 1.5; }

.loading-card { display: flex; align-items: center; gap: 12px; padding: 16px 18px; margin-bottom: 16px; }
.loading-card strong { display: block; font-size: 12.5px; }
.loading-card p { margin: 2px 0 0; color: var(--muted); font-size: 11.5px; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin 700ms linear infinite; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }
.exam-empty { margin-top: 16px; }

.exam-sheet { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 16px; }
.exam-cover { padding: 25px 28px 22px; border-bottom: 1px solid var(--line); background: var(--surface-soft); }
.exam-cover .kicker { margin: 0 0 7px; color: var(--warm); font-size: 9.5px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; }
.exam-cover h2 { margin: 0 0 12px; font-size: 24px; font-weight: 620; letter-spacing: -0.02em; }
.exam-meta { display: flex; flex-wrap: wrap; gap: 5px; }
.exam-cover-actions { margin-top: 12px; }
.exam-cover-actions .quiet-button { border-color: rgba(255,255,255,0.35); color: #f4f1e8; }
.exam-cover-actions .quiet-button:hover { border-color: #fff; color: #fff; }
.exam-scoreboard { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 14px; }
.exam-scoreboard > div { border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; background: var(--surface); }
.exam-scoreboard span { display: block; color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: 0.06em; }
.exam-scoreboard strong { display: block; margin-top: 3px; color: var(--ink); font-size: 13px; }
.exam-marks-note { margin: 7px 0 0; color: var(--muted); font-size: 9.5px; }
.exam-question-score { margin-top: 4px; color: var(--accent); font-size: 9.5px; font-weight: 650; }
@media (max-width: 620px) { .exam-scoreboard { grid-template-columns: 1fr; } }
.exam-chip { border: 1px solid var(--line-strong); border-radius: 4px; padding: 2px 7px; color: var(--ink-soft); font-size: 10px; }
.exam-instructions { padding: 15px 28px; border-bottom: 1px solid var(--line); color: var(--ink-soft); font-size: 12px; line-height: 1.6; }
.exam-instructions strong { color: var(--ink); }
.exam-format { padding: 12px 28px 0; color: var(--muted); font-size: 10.5px; }
.exam-questions { padding: 10px 28px 26px; display: flex; flex-direction: column; gap: 12px; }
.exam-question { border: 1px solid var(--line); border-radius: 8px; padding: 16px 17px; background: var(--surface); }
.exam-question-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.question-number { font-family: var(--mono); font-size: 11px; color: var(--accent); background: var(--accent-soft); border-radius: 4px; padding: 2px 6px; }
.question-marks { color: var(--warm); font-size: 9.5px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; }
.question-type { color: var(--muted); font-size: 9px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; }
.question-options { margin: 9px 0 0; padding: 9px 12px 9px 30px; background: var(--surface-soft); border: 1px solid var(--line); border-radius: 7px; font-size: 12px; color: var(--ink-soft); }
.question-options li { margin: 3px 0; }
.exam-question-prompt { white-space: pre-wrap; font-family: var(--serif); font-size: 14px; line-height: 1.65; color: var(--ink); }
.question-sources { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 9px; }
.source-chip { font-family: var(--mono); font-size: 8.5px; color: var(--accent); background: var(--accent-soft); border-radius: 3px; padding: 1px 5px; }
.exam-answer-box { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); }
.exam-answer-box label { display: block; margin-bottom: 4px; color: var(--ink-soft); font-size: 10.5px; font-weight: 650; }
.exam-answer-box textarea { min-height: 72px; font-size: 12px; }
.exam-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 7px; }
.small-button { border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-soft); border-radius: 6px; padding: 5px 8px; font-size: 10.5px; font-weight: 600; }
.small-button:hover { border-color: var(--accent); color: var(--accent); }
.small-button:disabled { opacity: 0.45; cursor: not-allowed; }
.delete-button { border: 1px solid var(--line-strong); background: var(--surface); color: var(--danger); border-radius: 6px; padding: 5px 10px; font-size: 10.5px; font-weight: 600; }
.delete-button:hover { background: var(--danger-soft); border-color: var(--danger); }
.delete-button:disabled { opacity: 0.45; cursor: not-allowed; }
.key-lock { color: var(--muted); font-size: 10px; }
.exam-feedback { margin-top: 9px; padding: 10px 11px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-soft); font-size: 11.5px; line-height: 1.6; }
.exam-feedback.is-correct { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); }
.exam-feedback.is-blocked { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.policy-note { margin-top: 4px; color: var(--muted); font-size: 9px; font-family: var(--mono); }
.key-reveal { margin-top: 9px; padding: 11px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--surface-soft); color: var(--ink); font-size: 11.5px; line-height: 1.6; }
.key-reveal h4 { margin: 0 0 4px; font-size: 11.5px; }
.key-value { font-family: var(--mono); font-size: 11px; background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 6px 7px; margin: 5px 0; white-space: pre-wrap; }

.footer { padding: 16px 34px 22px; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; display: flex; justify-content: space-between; gap: 12px; max-width: 1160px; width: 100%; margin: 0 auto; }

/* Personal workspace */
.card-kicker { margin: 0 0 3px; color: var(--warm); font-size: 9px; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; }
.workspace-stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
.mini-stat { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 11px 13px; box-shadow: var(--shadow); }
.mini-stat span { display: block; color: var(--muted); font-size: 9px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.mini-stat strong { display: block; margin-top: 4px; font-size: 21px; font-weight: 620; letter-spacing: -0.02em; }
.mini-date { font-size: 12px !important; font-weight: 500 !important; color: var(--ink-soft); }
.workspace-grid { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); gap: 14px; margin-bottom: 14px; align-items: stretch; }
.workspace-card { padding: 17px 18px; margin-bottom: 14px; }
.workspace-grid .workspace-card { margin-bottom: 0; }
.workspace-card .card-head { margin-bottom: 12px; }
.workspace-card .card-head h2 { font-size: 14px; }
.workspace-card .card-head .count { align-self: flex-start; }
.inline-form { display: flex; gap: 7px; align-items: center; }
.inline-form input { flex: 1; }
.inline-form .primary-button { flex-shrink: 0; }
.course-list { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.course-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; border: 1px solid var(--line); border-radius: 7px; padding: 8px 9px; background: var(--surface-soft); }
.course-row-main { min-width: 0; }
.course-row-main strong { display: block; font-size: 11.5px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.course-row-main span { color: var(--muted); font-size: 9.5px; }
.course-row .delete-button { flex-shrink: 0; }
.dropzone { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 112px; margin-top: 10px; padding: 12px; border: 1px dashed var(--line-strong); border-radius: 8px; background: var(--surface-soft); color: var(--muted); text-align: center; cursor: pointer; transition: border-color 120ms ease, background 120ms ease; }
.dropzone:hover, .dropzone.is-dragging { border-color: var(--accent); background: var(--accent-soft); }
.dropzone strong { color: var(--ink-soft); font-size: 12px; }
.dropzone span { font-size: 11px; }
.dropzone small { color: var(--muted); font-size: 9.5px; line-height: 1.4; }
.selected-files { margin-top: 5px; color: var(--accent); font-size: 10.5px; font-weight: 600; }
.upload-foot { margin-top: 10px; }
.workspace-table { width: 100%; border-collapse: collapse; font-size: 11px; }
.workspace-table th { text-align: left; padding: 8px 9px; color: var(--muted); font-size: 9px; letter-spacing: 0.07em; text-transform: uppercase; border-bottom: 1px solid var(--line); }
.workspace-table td { padding: 9px; border-bottom: 1px solid var(--line); color: var(--ink-soft); vertical-align: middle; }
.workspace-table tr:last-child td { border-bottom: 0; }
.workspace-table .file-name { max-width: 260px; display: inline-block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; color: var(--ink); }
.workspace-table .delete-button { border: 1px solid var(--line-strong); color: var(--danger); background: transparent; border-radius: 6px; padding: 4px 8px; font-size: 9.5px; }
.workspace-table .delete-button:hover { background: var(--danger-soft); }
.empty-note { color: var(--muted); font-size: 11px; line-height: 1.5; margin: 8px 0 0; }

@media (max-width: 980px) {
  .workspace-grid { grid-template-columns: 1fr; }
  .workspace-grid .workspace-card { margin-bottom: 0; }
}

@media (max-width: 700px) {
  .workspace-stats { grid-template-columns: 1fr 1fr; }
  .workspace-card { padding: 14px; }
  .inline-form { flex-direction: column; align-items: stretch; }
  .inline-form .primary-button { width: 100%; }
  .workspace-table .file-name { max-width: 140px; }
}

/* Admin denied */
.denied-page { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.denied-card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 28px; max-width: 420px; box-shadow: var(--shadow); }
.denied-card .kicker { margin: 0 0 5px; color: var(--warm); font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; font-weight: 700; }
.denied-card h1 { margin: 0; font-size: 22px; }
.denied-card p { color: var(--muted); font-size: 12.5px; }

@media (max-width: 980px) {
  .app-sidebar { width: 190px; flex-basis: 190px; }
  .tutor-layout { grid-template-columns: 1fr; }
  .references-card { position: static; }
  .content { padding: 26px 22px 48px; }
}

@media (max-width: 700px) {
  .app-shell { flex-direction: column; }
  .app-sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; padding: 10px 14px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { margin: 0; padding: 0; }
  .brand-name { font-size: 14px; }
  .side-nav { flex-direction: row; margin-left: auto; }
  .side-link { width: auto; padding: 6px 8px; font-size: 12px; }
  .nav-glyph { display: none; }
  .sidebar-note { display: none; }
  .topbar { padding: 0 16px; height: 48px; }
  .content { padding: 22px 16px 40px; }
  .page-heading h1 { font-size: 24px; }
  .segmented { width: 100%; }
  .segment { flex: 1; }
  .card { border-radius: 8px; }
  .session-card { padding: 16px; }
  .form-foot { flex-direction: column; align-items: stretch; gap: 10px; }
  .form-foot .primary-button { width: 100%; }
  .field-row { flex-direction: column; align-items: stretch; }
  .field-compact { flex-basis: auto; }
  .exam-config-grid { grid-template-columns: 1fr 1fr; }
  .answer-foot { flex-direction: column; align-items: stretch; }
  .answer-foot .primary-button { width: 100%; }
  .exam-cover, .exam-instructions, .exam-format, .exam-questions { padding-left: 16px; padding-right: 16px; }
  .footer { flex-direction: column; padding: 14px 16px 20px; gap: 4px; }
}
