:root {
  --bg: #f4efe6;
  --paper: rgba(255, 252, 247, 0.94);
  --paper-strong: #fffdf9;
  --paper-soft: rgba(251, 247, 239, 0.88);
  --ink: #1d2630;
  --muted: #5d6876;
  --border: rgba(46, 62, 82, 0.12);
  --shadow: 0 16px 36px rgba(78, 62, 38, 0.12);
  --shadow-soft: 0 8px 18px rgba(78, 62, 38, 0.08);
  --primary: #0f5d55;
  --primary-deep: #0a4943;
  --accent: #b35c2e;
  --accent-soft: rgba(179, 92, 46, 0.12);
  --success: #216b46;
  --warning: #9a5a14;
  --danger: #8c2f2f;
  --stage-active: #203f82;
  --stage-active-soft: rgba(32, 63, 130, 0.12);
  --radius-xl: 28px;
  --radius-lg: 24px;
  --radius-md: 18px;
  --radius-sm: 12px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(179, 92, 46, 0.12), transparent 28%),
    radial-gradient(circle at top right, rgba(15, 93, 85, 0.14), transparent 25%),
    linear-gradient(180deg, #fbf7ef 0%, var(--bg) 40%, #f1ebdf 100%);
}

body.reference-modal-open {
  overflow: hidden;
}

body.tutorial-tour-open {
  overscroll-behavior: contain;
}

a {
  color: var(--primary);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

code,
pre {
  font-family: "IBM Plex Sans", "SFMono-Regular", Consolas, monospace;
}

.page-shell {
  width: min(1600px, calc(100vw - 40px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.app-header {
  padding: 26px 30px 30px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 30px;
  background:
    linear-gradient(135deg, rgba(14, 36, 56, 0.93), rgba(23, 53, 49, 0.88)),
    linear-gradient(180deg, rgba(255, 255, 255, 0.12), transparent);
  box-shadow: var(--shadow);
  color: #f7f3ea;
}

.app-header-row,
.session-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.app-header-row {
  align-items: flex-start;
}

.eyebrow,
.panel-label,
.rubric-item-id {
  margin: 0;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 0.72rem;
  font-weight: 700;
}

.eyebrow {
  color: rgba(255, 219, 186, 0.92);
}

.app-header h1 {
  margin: 10px 0 0;
  font-family: "Source Serif 4", Georgia, serif;
  font-size: clamp(2.2rem, 4vw, 3.4rem);
  line-height: 1;
}

.session-controls {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.session-identity {
  margin: 0;
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #f7f3ea;
  font-size: 0.92rem;
  font-weight: 600;
}

.app-main {
  margin-top: 24px;
}

.view-panel {
  padding: 24px;
  border-radius: var(--radius-xl);
  background: var(--paper);
  border: 1px solid rgba(255, 255, 255, 0.45);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.panel-intro,
.topic-toolbar,
.topic-card-top,
.stage-panel-top,
.article-card-header,
.evaluation-card-header,
.comparison-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.panel-intro h2,
.topic-header-card h2,
.study-brief-card h3,
.article-card h3,
.evaluation-card h4,
.comparison-card h4,
.stage-panel h4 {
  margin: 8px 0 0;
  font-family: "Source Serif 4", Georgia, serif;
  line-height: 1.1;
}

.status-text,
.stage-summary,
.topic-card-copy,
.study-brief-copy p,
.study-brief-note,
.article-subtitle,
.evaluation-card-note,
.rubric-item-description,
.selected-scale-text,
.stage-copy,
.placeholder-text,
.error-text,
.completion-note {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.topic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 18px;
  margin-top: 22px;
}

.auth-panel {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 520px;
}

.auth-card,
.profile-card,
.consent-card {
  width: min(560px, 100%);
  padding: 32px;
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.99), rgba(252, 248, 241, 0.98));
  border: 1px solid var(--border);
  box-shadow: var(--shadow-soft);
}

.consent-panel {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 520px;
}

.profile-panel {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 520px;
}

.profile-card {
  width: min(640px, 100%);
}

.consent-card {
  width: min(920px, 100%);
}

.auth-card h2,
.profile-card h2,
.consent-card h2 {
  margin: 10px 0 12px;
  font-family: "Source Serif 4", Georgia, serif;
  font-size: clamp(2rem, 4vw, 2.5rem);
  line-height: 1.05;
}

.auth-copy {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.auth-form {
  display: grid;
  gap: 16px;
  margin-top: 24px;
}

.profile-form {
  display: grid;
  gap: 16px;
  margin-top: 24px;
}

.auth-field {
  display: grid;
  gap: 8px;
  font-weight: 600;
  color: var(--ink);
}

.auth-field input,
.auth-field select {
  min-height: 48px;
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(46, 62, 82, 0.14);
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
}

.auth-field input:disabled {
  background: rgba(240, 236, 229, 0.96);
  color: var(--muted);
}

.auth-field select:disabled {
  background: rgba(240, 236, 229, 0.96);
  color: var(--muted);
}

.auth-field select {
  appearance: none;
}

#auth-status {
  margin-top: 16px;
}

#profile-status {
  margin-top: 16px;
}

.profile-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.consent-copy-shell {
  margin-top: 24px;
  max-height: min(56vh, 620px);
  overflow: auto;
  padding: 22px 24px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(46, 62, 82, 0.12);
  background: rgba(255, 255, 255, 0.78);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65);
}

.consent-copy h2,
.consent-copy h3 {
  margin: 0 0 12px;
  font-family: "Source Serif 4", Georgia, serif;
  line-height: 1.15;
}

.consent-copy h2 + p,
.consent-copy h3 + p {
  margin-top: 0;
}

.consent-copy p,
.consent-copy li {
  margin: 0;
  color: var(--ink);
  line-height: 1.7;
}

.consent-copy p + p,
.consent-copy p + ul,
.consent-copy ul + p,
.consent-copy h2,
.consent-copy h3 {
  margin-top: 14px;
}

.consent-copy ul {
  margin: 0;
  padding-left: 22px;
}

.consent-status {
  margin-top: 16px;
}

.consent-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.topic-card,
.empty-state-card,
.topic-header-card,
.study-brief-card,
.stage-panel,
.article-card,
.evaluation-card,
.comparison-card {
  border-radius: var(--radius-lg);
  background: var(--paper-strong);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-soft);
}

.topic-card {
  padding: 20px;
  display: flex;
  flex-direction: column;
  min-height: 238px;
}

.admin-topic-options {
  margin-top: auto;
}

.admin-topic-options-label {
  margin: 18px 0 10px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
}

.admin-topic-options-grid {
  display: grid;
  gap: 10px;
}

.topic-scope-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(46, 62, 82, 0.12);
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
  text-align: left;
}

.topic-scope-label {
  font-weight: 700;
}

.topic-scope-status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(30, 43, 58, 0.06);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}

.topic-scope-button-complete .topic-scope-status {
  background: rgba(33, 107, 70, 0.12);
  color: var(--success);
}

.topic-scope-button-started .topic-scope-status {
  background: rgba(32, 63, 130, 0.12);
  color: var(--stage-active);
}

.topic-scope-button-clean .topic-scope-status {
  background: rgba(179, 92, 46, 0.12);
  color: var(--accent);
}

.topic-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.meta-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(30, 43, 58, 0.08);
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 600;
}

.meta-chip-success {
  background: rgba(33, 107, 70, 0.12);
  color: var(--success);
}

.meta-chip-warning {
  background: rgba(154, 90, 20, 0.14);
  color: var(--warning);
}

.topic-card h3 {
  margin: 22px 0 12px;
  font-size: 1.55rem;
}

.topic-card-button,
.secondary-button,
.primary-button,
.home-button {
  border-radius: 999px;
  border: none;
  transition: transform 160ms ease, box-shadow 160ms ease, background-color 160ms ease;
}

.topic-card-button {
  margin-top: auto;
  align-self: flex-start;
  padding: 12px 18px;
  background: linear-gradient(135deg, var(--accent), #cb7b4d);
  color: #fffaf3;
  font-weight: 700;
  box-shadow: 0 12px 24px rgba(179, 92, 46, 0.24);
}

.secondary-button {
  padding: 10px 16px;
  background: rgba(30, 43, 58, 0.08);
  color: var(--ink);
  font-weight: 600;
}

#view-consent-button,
#logout-button {
  background: rgba(255, 255, 255, 0.14);
  color: #f7f3ea;
  border: 1px solid rgba(255, 255, 255, 0.18);
}

#view-consent-button:hover,
#view-consent-button:focus,
#logout-button:hover,
#logout-button:focus {
  background: rgba(255, 255, 255, 0.22);
  color: #fffaf3;
}

.home-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 56px;
  min-height: 44px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid rgba(46, 62, 82, 0.12);
  color: var(--ink);
  font-weight: 700;
  box-shadow: var(--shadow-soft);
}

.home-button-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.01em;
}

.primary-button {
  padding: 11px 18px;
  background: linear-gradient(135deg, var(--primary), #1d766d);
  color: #f8fbfa;
  font-weight: 700;
  box-shadow: 0 12px 24px rgba(15, 93, 85, 0.22);
}

.topic-card-button:hover,
.topic-scope-button:hover,
.secondary-button:hover,
.primary-button:hover,
.home-button:hover,
.topic-card-button:focus,
.topic-scope-button:focus,
.secondary-button:focus,
.primary-button:focus,
.home-button:focus {
  transform: translateY(-1px);
}

.topic-toolbar {
  align-items: center;
  margin-bottom: 14px;
}

.topic-toolbar .status-text {
  margin-left: auto;
  text-align: right;
}

.topic-header-card,
.study-brief-card,
.stage-panel {
  padding: 22px 24px;
}

.study-brief-card {
  margin-top: 18px;
  background:
    linear-gradient(135deg, rgba(15, 93, 85, 0.05), rgba(49, 89, 166, 0.04)),
    var(--paper-strong);
}

.study-brief-copy {
  max-width: 1080px;
}

.study-brief-copy p + p {
  margin-top: 10px;
}

.study-brief-highlight {
  display: inline;
  font-weight: 700;
  color: var(--ink);
  background: linear-gradient(180deg, transparent 54%, rgba(179, 92, 46, 0.18) 54%);
}

.study-brief-quote {
  position: relative;
  padding-left: 24px;
}

.study-brief-quote::before {
  content: ">";
  position: absolute;
  left: 0;
  top: 0;
  color: var(--warning);
  font-weight: 700;
}

.study-brief-note {
  color: var(--warning);
}

.flowchart {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.flow-step {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding: 16px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(46, 62, 82, 0.1);
  background: rgba(255, 255, 255, 0.76);
  text-align: left;
  color: var(--ink);
  transition: transform 160ms ease, border-color 160ms ease, box-shadow 160ms ease;
}

.flow-step:hover,
.flow-step:focus {
  transform: translateY(-1px);
}

.flow-step-status {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 1;
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: rgba(179, 92, 46, 0.92);
  box-shadow: 0 0 0 4px rgba(179, 92, 46, 0.12);
}

.flow-step-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  min-height: 34px;
  border-radius: 999px;
  background: rgba(30, 43, 58, 0.08);
  font-size: 0.86rem;
  font-weight: 700;
}

.flow-step-title,
.preference-option-label {
  font-weight: 700;
}

.flow-step-copy,
.preference-option-copy {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

.flow-step.started {
  border-color: rgba(32, 63, 130, 0.22);
  background: linear-gradient(135deg, rgba(32, 63, 130, 0.12), rgba(15, 93, 85, 0.08));
  box-shadow: inset 0 0 0 1px rgba(32, 63, 130, 0.08);
}

.flow-step.started .flow-step-number {
  background: rgba(32, 63, 130, 0.18);
  color: var(--stage-active);
}

.flow-step.completed {
  background: rgba(33, 107, 70, 0.08);
  border-color: rgba(33, 107, 70, 0.16);
}

.flow-step.completed .flow-step-number {
  background: rgba(33, 107, 70, 0.14);
  color: var(--success);
}

.flow-step.current {
  outline: 2px solid rgba(32, 63, 130, 0.22);
  outline-offset: 2px;
}

.stage-workspace {
  min-height: 240px;
  margin-top: 18px;
}

.stage-panel-top h4,
.comparison-card h4 {
  font-size: 1.4rem;
}

.stage-mini-metric {
  margin: 0;
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(15, 93, 85, 0.08);
  color: var(--primary);
  font-size: 0.84rem;
  font-weight: 700;
}

.article-card,
.evaluation-card {
  overflow: hidden;
}

.article-card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(255, 252, 247, 0.98));
}

.article-card-blind {
  border-top: 5px solid rgba(32, 63, 130, 0.7);
}

.article-card-reference {
  margin-top: 18px;
  border-top: 5px solid rgba(139, 58, 58, 0.65);
}

.article-review-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(320px, 0.95fr);
  gap: 18px;
  align-items: start;
  margin-top: 18px;
}

.article-reading-card {
  margin-top: 0;
  min-width: 0;
}

.article-card-header {
  padding: 20px 22px 18px;
  border-bottom: 1px solid var(--border);
}

.article-card h3 {
  font-size: 1.95rem;
}

.article-subtitle {
  max-width: 360px;
  font-size: 0.92rem;
}

.article-body {
  padding: 24px 24px 30px;
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 1.08rem;
  line-height: 1.78;
}

.article-body > :first-child {
  margin-top: 0;
}

.article-body > :last-child {
  margin-bottom: 0;
}

.article-body h1,
.article-body h2,
.article-body h3,
.article-body h4 {
  color: var(--ink);
  line-height: 1.2;
  margin-top: 1.7em;
  margin-bottom: 0.7em;
}

.article-body h1,
.article-body h2 {
  font-size: 1.7rem;
}

.article-body h3 {
  font-size: 1.38rem;
}

.article-body p,
.article-body li {
  color: #2e3743;
}

.article-body blockquote {
  margin: 1.4rem 0;
  padding: 0.1rem 0 0.1rem 1rem;
  border-left: 3px solid rgba(179, 92, 46, 0.45);
  color: #495564;
}

.article-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.2rem 0;
  font-size: 0.96rem;
  background: rgba(255, 255, 255, 0.72);
  overflow: hidden;
  border-radius: 14px;
}

.article-body th,
.article-body td {
  padding: 10px 12px;
  border: 1px solid rgba(46, 62, 82, 0.12);
  text-align: left;
}

.article-body th {
  background: rgba(15, 93, 85, 0.08);
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  font-weight: 600;
}

.article-body pre,
.evaluation-card pre {
  overflow: auto;
  padding: 14px;
  border-radius: var(--radius-sm);
  background: #f3efe6;
  border: 1px solid rgba(46, 62, 82, 0.12);
  font-size: 0.9rem;
}

.article-body code,
.evaluation-card code {
  background: rgba(49, 89, 166, 0.08);
  padding: 0.14rem 0.32rem;
  border-radius: 6px;
  font-size: 0.9rem;
}

.evaluation-card {
  padding: 18px;
  background:
    linear-gradient(180deg, rgba(255, 250, 243, 0.98), rgba(250, 245, 237, 0.98));
  margin-top: 0;
  min-width: 0;
  border-top: 5px solid rgba(15, 93, 85, 0.78);
  box-shadow: 0 18px 30px rgba(15, 93, 85, 0.1);
}

.score-progress {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(15, 93, 85, 0.08);
  color: var(--primary);
  font-size: 0.84rem;
  font-weight: 700;
  white-space: nowrap;
}

.rubric-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 16px;
}

.tutorial-overlay {
  position: fixed;
  inset: 0;
  z-index: 1200;
  pointer-events: none;
}

.tutorial-backdrop {
  position: absolute;
  inset: 0;
  background: transparent;
  pointer-events: auto;
}

.tutorial-spotlight {
  position: fixed;
  border-radius: 22px;
  box-shadow: 0 0 0 9999px rgba(17, 24, 39, 0.56);
  border: 2px solid rgba(255, 255, 255, 0.88);
  background: transparent;
  pointer-events: none;
  transition: left 180ms ease, top 180ms ease, width 180ms ease, height 180ms ease;
}

.tutorial-popover {
  position: fixed;
  width: min(360px, calc(100vw - 32px));
  border-radius: var(--radius-lg);
  border: 1px solid rgba(255, 255, 255, 0.32);
  background: linear-gradient(180deg, rgba(255, 252, 248, 0.98), rgba(248, 242, 233, 0.98));
  box-shadow: 0 28px 56px rgba(17, 24, 39, 0.32);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  pointer-events: auto;
}

.tutorial-popover-header,
.tutorial-popover-actions {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.tutorial-popover-header {
  align-items: center;
}

.tutorial-counter {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.tutorial-popover h2 {
  margin: 0;
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 1.45rem;
  line-height: 1.1;
}

.tutorial-copy {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.65;
}

.tutorial-popover-actions {
  justify-content: flex-end;
}

.tutorial-skip-button {
  flex: 0 0 auto;
}

.read-only-banner {
  margin-top: 18px;
  padding: 16px 18px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(32, 63, 130, 0.14);
  background: linear-gradient(135deg, rgba(32, 63, 130, 0.08), rgba(255, 255, 255, 0.94));
}

.read-only-banner-label,
.read-only-banner-copy {
  margin: 0;
}

.read-only-banner-label {
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--stage-active);
}

.read-only-banner-copy {
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.6;
}

.rubric-item {
  padding: 16px;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(46, 62, 82, 0.09);
}

.rubric-item h5 {
  margin: 6px 0 0;
  font-size: 1.06rem;
  line-height: 1.3;
}

.rubric-item-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.rubric-item-id {
  color: var(--accent);
}

.score-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.score-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  min-height: 42px;
  padding: 0 14px;
  border-radius: 999px;
  background: rgba(30, 43, 58, 0.06);
  border: 1px solid transparent;
  color: var(--ink);
  font-weight: 700;
  transition: all 140ms ease;
}

.score-pill:hover,
.score-pill:focus {
  border-color: rgba(15, 93, 85, 0.22);
  background: rgba(15, 93, 85, 0.08);
}

.score-pill.selected {
  background: linear-gradient(135deg, rgba(15, 93, 85, 0.16), rgba(49, 89, 166, 0.14));
  border-color: rgba(15, 93, 85, 0.26);
  color: var(--primary-deep);
  box-shadow: inset 0 0 0 1px rgba(15, 93, 85, 0.08);
}

.score-pill:disabled,
.score-pill.is-read-only {
  cursor: default;
  opacity: 0.9;
}

.citation-button {
  display: inline;
  padding: 0;
  border: none;
  background: none;
  color: var(--stage-active);
  font: inherit;
  font-weight: 700;
  text-decoration: underline;
  text-decoration-color: rgba(32, 63, 130, 0.28);
  text-underline-offset: 0.16em;
}

.citation-button:hover,
.citation-button:focus {
  color: #162f67;
}

.reference-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 16px;
}

.reference-modal[hidden] {
  display: none;
}

.reference-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(17, 24, 39, 0.58);
  backdrop-filter: blur(4px);
}

.reference-modal-dialog {
  position: relative;
  z-index: 1;
  width: min(860px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  min-width: 0;
  border-radius: var(--radius-lg);
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: linear-gradient(180deg, rgba(255, 253, 249, 0.98), rgba(249, 244, 236, 0.98));
  box-shadow: 0 28px 56px rgba(17, 24, 39, 0.24);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.reference-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px 18px;
  border-bottom: 1px solid var(--border);
}

.reference-modal-header h2 {
  margin: 0;
  font-family: "Source Serif 4", Georgia, serif;
  line-height: 1.1;
}

.reference-modal-close-button {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.8rem;
  line-height: 1;
  padding: 0 0.3rem;
}

.reference-modal-close-button:hover,
.reference-modal-close-button:focus {
  background: rgba(30, 43, 58, 0.08);
  color: var(--ink);
}

.reference-modal-body {
  padding: 20px 22px 24px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  min-height: 0;
  overscroll-behavior: contain;
}

.reference-modal-body pre,
.reference-modal-body code {
  max-width: 100%;
}

.reference-entry,
.reference-entry * {
  min-width: 0;
}

.reference-entry {
  width: 100%;
  max-width: 100%;
}

.reference-modal-body > * {
  flex-shrink: 0;
}

.reference-entry h3 {
  margin: 0 0 18px;
  font-family: "Source Serif 4", Georgia, serif;
  font-size: 1.4rem;
  line-height: 1.2;
}

.reference-entry p,
.reference-entry li,
.reference-entry a,
.reference-entry code,
.reference-entry pre,
.reference-entry h4 {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.reference-modal-body pre {
  white-space: pre-wrap;
}

.citation-section {
  margin-bottom: 18px;
}

.citation-heading {
  margin: 0 0 8px;
  font-size: 0.96rem;
  font-weight: 700;
  color: var(--ink);
}

.citation-description p:last-child,
.citation-links p,
.reference-external-url,
.reference-snippets {
  margin-bottom: 0;
}

.citation-query,
.citation-sql {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.5;
  white-space: pre-wrap;
  padding: 14px;
  border-radius: var(--radius-sm);
  background: #f3efe6;
  border: 1px solid rgba(46, 62, 82, 0.12);
}

.citation-query code,
.citation-sql code,
.citation-agent-response code {
  background: transparent;
  padding: 0;
  border-radius: 0;
}

.citation-description > :first-child {
  margin-top: 0;
}

.citation-description > :last-child {
  margin-bottom: 0;
}

.citation-description pre {
  margin: 0 0 14px;
  font-size: 0.88rem;
  line-height: 1.5;
  white-space: pre-wrap;
  padding: 14px;
  border-radius: var(--radius-sm);
  background: #f3efe6;
  border: 1px solid rgba(46, 62, 82, 0.12);
}

.citation-description :is(h3, h4) {
  margin: 16px 0 8px;
  font-size: 0.96rem;
  font-weight: 700;
  color: var(--ink);
}

.citation-description table {
  margin-top: 10px;
}

.citation-url-section {
  margin-bottom: 18px;
}

.reference-external-url {
  margin-top: 0;
}

.reference-snippets {
  margin-top: 0;
  padding-left: 18px;
}

.reference-url-missing {
  color: var(--danger);
  font-style: italic;
}

.reference-open-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--primary), #1d766d);
  color: #f8fbfa;
  font-weight: 700;
  text-decoration: none;
  box-shadow: 0 12px 24px rgba(15, 93, 85, 0.22);
  margin-bottom: 18px;
}

.reference-open-button:hover,
.reference-open-button:focus {
  transform: translateY(-1px);
}

.reference-modal-body table,
.reference-modal-body iframe,
.reference-modal-body img {
  max-width: 100%;
}

.reference-modal-body table {
  display: block;
  overflow-x: auto;
}

.scale-details {
  margin-top: 12px;
}

.scale-details summary {
  cursor: pointer;
  color: var(--primary);
  font-weight: 600;
}

.scale-details-body {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.scale-row {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 10px;
  align-items: start;
  color: var(--muted);
  font-size: 0.9rem;
}

.scale-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  border-radius: 999px;
  background: rgba(30, 43, 58, 0.06);
  color: var(--ink);
  font-weight: 700;
}

.preference-panel {
  margin-top: 18px;
}

.preference-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 320px));
  justify-content: start;
  gap: 16px;
  margin-top: 18px;
}

.comparison-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin-top: 18px;
}

.article-human-comparison {
  margin-top: 18px;
}

.comparison-card-inline {
  padding: 18px;
}

.preference-grid-compact {
  grid-template-columns: repeat(auto-fit, minmax(220px, 280px));
}

.notes-label-row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.completion-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: rgba(179, 92, 46, 0.92);
  box-shadow: 0 0 0 4px rgba(179, 92, 46, 0.12);
  flex: 0 0 auto;
}

.completion-dot.is-complete {
  opacity: 0;
  box-shadow: none;
}

.preference-option {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 124px;
  padding: 16px 18px 16px 52px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(46, 62, 82, 0.1);
  background: rgba(255, 255, 255, 0.82);
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

.preference-option input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.preference-option-marker {
  position: absolute;
  top: 18px;
  left: 18px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 2px solid rgba(46, 62, 82, 0.22);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.92);
}

.preference-option:hover,
.preference-option:focus-within {
  transform: translateY(-1px);
  border-color: rgba(32, 63, 130, 0.18);
  box-shadow: 0 10px 20px rgba(46, 62, 82, 0.08);
}

.preference-option.selected {
  border-color: rgba(32, 63, 130, 0.24);
  background: linear-gradient(135deg, rgba(32, 63, 130, 0.12), rgba(15, 93, 85, 0.08));
  box-shadow: inset 0 0 0 1px rgba(32, 63, 130, 0.08);
}

.preference-option.selected .preference-option-marker {
  border-color: rgba(32, 63, 130, 0.48);
  background: var(--stage-active);
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.94);
}

.preference-option.is-read-only {
  cursor: default;
}

.preference-option.is-read-only:hover,
.preference-option.is-read-only:focus-within {
  transform: none;
  box-shadow: none;
}

.preference-option-state {
  display: inline-flex;
  align-items: center;
  align-self: flex-start;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(30, 43, 58, 0.06);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.preference-option.selected .preference-option-state {
  background: rgba(32, 63, 130, 0.14);
  color: var(--stage-active);
}

.comparison-card {
  padding: 18px;
  background: linear-gradient(180deg, rgba(255, 252, 247, 0.98), rgba(248, 244, 237, 0.98));
}

.notes-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 18px;
  font-weight: 600;
}

.notes-field textarea {
  min-height: 132px;
  width: 100%;
  padding: 12px 14px;
  resize: vertical;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(46, 62, 82, 0.14);
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
}

.notes-field textarea[readonly] {
  background: rgba(244, 239, 230, 0.92);
  color: var(--muted);
}

.stage-navigation {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-top: 22px;
}

.nav-button {
  min-width: 148px;
}

.completion-note {
  margin-left: auto;
  max-width: 420px;
  text-align: right;
}

.empty-state-card {
  padding: 26px;
}

.empty-state-card h3 {
  margin: 0 0 10px;
}

.error-text {
  color: var(--danger);
}

.topic-card-button:focus,
.topic-scope-button:focus,
.secondary-button:focus,
.primary-button:focus,
.home-button:focus,
.auth-field input:focus,
.auth-field select:focus,
.flow-step:focus,
.stage-step:focus,
.notes-field textarea:focus {
  outline: 2px solid rgba(49, 89, 166, 0.28);
  outline-offset: 2px;
}

@media (max-width: 1180px) {
}

@media (max-width: 820px) {
  .page-shell {
    width: min(100vw - 20px, 100%);
    padding-top: 10px;
  }

  .view-panel,
  .app-header {
    padding: 18px;
    border-radius: 22px;
  }

  .app-header-row {
    flex-direction: column;
  }

  .session-controls {
    width: 100%;
    justify-content: flex-start;
  }

  .panel-intro,
  .topic-toolbar,
  .topic-card-top,
  .stage-panel-top,
  .article-card-header,
  .evaluation-card-header,
  .tutorial-popover-header,
  .tutorial-popover-actions,
  .reference-modal-header,
  .comparison-card-header,
  .stage-navigation {
    flex-direction: column;
  }

  .article-body {
    padding: 18px;
    font-size: 1rem;
  }

  .article-card h3 {
    font-size: 1.65rem;
  }

  .topic-grid,
  .flowchart,
  .article-review-layout,
  .preference-grid,
  .comparison-grid {
    grid-template-columns: 1fr;
  }

  .auth-card {
    padding: 24px;
  }

  .profile-card {
    padding: 24px;
  }

  .consent-card {
    padding: 24px;
  }

  .consent-copy-shell {
    padding: 18px;
  }

  .profile-actions,
  .consent-actions {
    flex-direction: column-reverse;
    align-items: stretch;
  }

  .completion-note {
    margin-left: 0;
    text-align: left;
  }
}
