/* ============================================================
   Saint & Scholar — Illuminated Academic Interface
   Typography: Cormorant Garamond + Source Sans 3
   Palette: Ivory / Indigo / Aged Gold
   ============================================================ */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ========== DESIGN TOKENS ========== */

:root {
  /* Surface */
  --bg-base: #F4F0E8;
  --bg-surface: #FAF8F3;
  --bg-elevated: #FFFFFF;
  --bg-sunken: #ECE8DE;
  --bg-wash: #F8F5EE;

  /* Text */
  --ink-primary: #1A1A2E;
  --ink-secondary: #4A4A5A;
  --ink-tertiary: #8A8A96;
  --ink-ghost: #B8B8C0;
  --ink-inverse: #FAF8F3;

  /* Accent — Aged Gold */
  --gold: #C4A265;
  --gold-light: #D4B87A;
  --gold-dark: #A68945;
  --gold-wash: rgba(196, 162, 101, 0.1);
  --gold-glow: rgba(196, 162, 101, 0.25);

  /* Accent — Deep Indigo */
  --indigo: #2D2B55;
  --indigo-light: #3E3B70;
  --indigo-wash: rgba(45, 43, 85, 0.06);

  /* Status */
  --status-ok: #3D7C5F;
  --status-warn: #B8860B;
  --status-bad: #A63D40;

  /* Borders */
  --rule: #DCD6C8;
  --rule-strong: #C4BFB0;
  --rule-faint: #E8E3D8;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(26, 26, 46, 0.06), 0 1px 2px rgba(26, 26, 46, 0.04);
  --shadow-md: 0 4px 12px rgba(26, 26, 46, 0.07), 0 2px 4px rgba(26, 26, 46, 0.04);
  --shadow-lg: 0 12px 32px rgba(26, 26, 46, 0.1), 0 4px 8px rgba(26, 26, 46, 0.04);
  --shadow-glow: 0 0 0 3px var(--gold-wash), 0 4px 16px rgba(196, 162, 101, 0.12);
  --shadow-inset: inset 0 1px 3px rgba(26, 26, 46, 0.06);

  /* Radii */
  --r-sm: 4px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-xl: 16px;
  --r-pill: 100px;

  /* Transitions */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --dur-fast: 150ms;
  --dur-med: 250ms;
  --dur-slow: 400ms;

  /* Figure accent colors */
  --fig-buddha: #E8A735;
  --fig-aurelius: #8B2E2E;
  --fig-rumi: #1B6B5A;
  --fig-solomon: #5B3A8C;
  --fig-laotzu: #059669;
}

/* ========== DARK MODE ========== */

[data-theme="dark"] {
  --bg-base: #0E0E18;
  --bg-surface: #151520;
  --bg-elevated: #1C1C2B;
  --bg-sunken: #0A0A12;
  --bg-wash: #181825;

  --ink-primary: #E8E4DC;
  --ink-secondary: #A8A4A0;
  --ink-tertiary: #706C68;
  --ink-ghost: #4A4844;
  --ink-inverse: #0E0E18;

  --gold: #D4B87A;
  --gold-light: #E0C88E;
  --gold-dark: #C4A265;
  --gold-wash: rgba(212, 184, 122, 0.1);
  --gold-glow: rgba(212, 184, 122, 0.2);

  --indigo: #8B88B8;
  --indigo-light: #A09DC8;
  --indigo-wash: rgba(139, 136, 184, 0.08);

  --status-ok: #5DA87A;
  --status-warn: #D4A84B;
  --status-bad: #C85A5D;

  --rule: #2A2A3A;
  --rule-strong: #3A3A4E;
  --rule-faint: #1E1E2E;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 0 3px var(--gold-wash), 0 4px 16px rgba(212, 184, 122, 0.08);
  --shadow-inset: inset 0 1px 3px rgba(0, 0, 0, 0.2);

  --fig-buddha: #E8A735;
  --fig-aurelius: #C85A5D;
  --fig-rumi: #3DA88A;
  --fig-solomon: #9B7AC8;
  --fig-laotzu: #34D399;
}

/* ========== BASE ========== */

html, body {
  height: 100%;
  font-family: 'Cormorant Garamond', 'Georgia', serif;
  font-size: 16px;
  line-height: 1.7;
  color: var(--ink-primary);
  background: var(--bg-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'liga', 'calt', 'kern';
  transition: background-color var(--dur-med) var(--ease-out),
              color var(--dur-med) var(--ease-out);
}

/* Subtle grain texture */
.grain-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  opacity: 0.025;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
  background-repeat: repeat;
  background-size: 256px 256px;
}

[data-theme="dark"] .grain-overlay {
  opacity: 0.04;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 100%;
}

/* ========== HEADER ========== */

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.75rem;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--rule-faint);
  flex-shrink: 0;
  transition: background-color var(--dur-med) var(--ease-out),
              border-color var(--dur-med) var(--ease-out);
  position: relative;
}

/* Subtle gold underline accent */
.app-header::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 1.75rem;
  right: 1.75rem;
  height: 1px;
  background: linear-gradient(90deg, transparent 0%, var(--gold) 50%, transparent 100%);
  opacity: 0.2;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  color: var(--gold);
  flex-shrink: 0;
}

.brand-icon {
  width: 100%;
  height: 100%;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.brand-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--ink-primary);
  letter-spacing: 0.02em;
  line-height: 1.2;
}

.brand-amp {
  color: var(--gold);
  font-style: italic;
  font-weight: 400;
}

.brand-tagline {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.6875rem;
  font-weight: 400;
  color: var(--ink-tertiary);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: 1.2;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-divider {
  width: 1px;
  height: 20px;
  background: var(--rule);
}

.status-section {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.health-badge {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  transition: background-color var(--dur-med) ease;
}

.health-badge.status-ok { background: var(--status-ok); box-shadow: 0 0 6px rgba(61, 124, 95, 0.4); }
.health-badge.status-warn { background: var(--status-warn); box-shadow: 0 0 6px rgba(184, 134, 11, 0.4); }
.health-badge.status-bad { background: var(--status-bad); box-shadow: 0 0 6px rgba(166, 61, 64, 0.4); }

.request-id {
  font-family: 'Source Sans 3', monospace;
  font-size: 0.6875rem;
  color: var(--ink-ghost);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  color: var(--ink-tertiary);
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease-out);
  font-size: 0.875rem;
  position: relative;
  overflow: hidden;
}

.theme-toggle:hover {
  border-color: var(--gold);
  color: var(--gold);
  background: var(--gold-wash);
}

.theme-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--dur-med) var(--ease-spring);
}

.theme-toggle:hover .theme-icon {
  transform: rotate(15deg);
}

.new-chat-button {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.875rem;
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  color: var(--ink-secondary);
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease-out);
  letter-spacing: 0.01em;
}

.new-chat-button:hover {
  border-color: var(--gold);
  color: var(--gold);
  background: var(--gold-wash);
}

.new-chat-button:active {
  transform: scale(0.97);
}

.new-chat-button svg {
  flex-shrink: 0;
  opacity: 0.6;
}

/* ========== CHARACTER BAR ========== */

.character-bar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--rule-faint);
  padding: 0.75rem 0 0.875rem;
  flex-shrink: 0;
  overflow: visible;
  transition: background-color var(--dur-med) var(--ease-out),
              border-color var(--dur-med) var(--ease-out);
}

.character-bar-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1.75rem;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 1rem;
}

.character-bar-label {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-ghost);
  white-space: nowrap;
  flex-shrink: 0;
}

.figure-grid {
  display: grid;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.5rem;
  overflow: visible;
}

.figure-card {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0.625rem 0.375rem 0.375rem;
  background: var(--bg-elevated);
  border: 1px solid var(--rule-faint);
  border-radius: var(--r-lg);
  cursor: pointer;
  transition: all var(--dur-med) var(--ease-out);
  white-space: nowrap;
  position: relative;
  min-width: 0;
  width: 100%;
}

.figure-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 10px;
  bottom: 10px;
  width: 2.5px;
  border-radius: 0 2px 2px 0;
  background: var(--ink-ghost);
  opacity: 0;
  transition: opacity var(--dur-med) var(--ease-out);
}

.figure-card:hover {
  border-color: var(--rule-strong);
  box-shadow: var(--shadow-sm);
}

.figure-card:hover::before {
  opacity: 0.5;
}

/* Figure-specific accent colors on the left bar */
.figure-card[data-figure="buddha"]::before { background: var(--fig-buddha); }
.figure-card[data-figure="aurelius"]::before { background: var(--fig-aurelius); }
.figure-card[data-figure="rumi"]::before { background: var(--fig-rumi); }
.figure-card[data-figure="solomon"]::before { background: var(--fig-solomon); }
.figure-card[data-figure="laotzu"]::before { background: var(--fig-laotzu); }

.figure-card.active {
  background: var(--gold-wash);
  border-color: var(--gold);
  box-shadow: 0 0 0 2px var(--gold-wash);
}

.figure-card.active::before {
  opacity: 1;
}

.figure-card.active .figure-name {
  color: var(--ink-primary);
}

.figure-card.active .figure-meta {
  color: var(--ink-secondary);
}

.figure-card.active .figure-avatar {
  transform: scale(1.05);
}

.figure-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--r-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  position: relative;
  transition: all var(--dur-med) var(--ease-out);
  image-rendering: auto;
  background: var(--bg-wash);
  flex-shrink: 0;
  overflow: hidden;
}

.figure-avatar svg {
  width: 100%;
  height: 100%;
}

.figure-text {
  display: flex;
  flex-direction: column;
  gap: 0.0625rem;
  min-width: 0;
}

.figure-name {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-primary);
  letter-spacing: 0.01em;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.figure-meta {
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.7rem;
  font-weight: 400;
  font-style: italic;
  color: var(--ink-tertiary);
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ========== CHAT CONTAINER ========== */

.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-width: 820px;
  margin: 0 auto;
  width: 100%;
}

.chat-wrapper {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 2rem 2rem;
  scrollbar-gutter: stable;
}

/* ========== WELCOME STATE ========== */

.welcome-state {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 380px;
  animation: welcome-enter 0.8s var(--ease-out) both;
}

@keyframes welcome-enter {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.welcome-content {
  text-align: center;
  max-width: 560px;
  padding: 0 1rem;
}

.welcome-ornament {
  display: flex;
  justify-content: center;
  margin-bottom: 1.5rem;
  color: var(--gold);
  opacity: 0.5;
  animation: welcome-enter 0.8s var(--ease-out) 0.1s both;
}

.welcome-ornament svg {
  width: 88px;
  height: 30px;
}

.welcome-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.875rem;
  font-weight: 500;
  margin-bottom: 0.625rem;
  color: var(--ink-primary);
  letter-spacing: 0.01em;
  line-height: 1.25;
  animation: welcome-enter 0.8s var(--ease-out) 0.15s both;
}

.welcome-subtitle {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.0625rem;
  font-weight: 400;
  color: var(--ink-secondary);
  margin-bottom: 2rem;
  line-height: 1.7;
  max-width: 500px;
  margin-left: auto;
  margin-right: auto;
  animation: welcome-enter 0.8s var(--ease-out) 0.2s both;
}

.sample-prompts {
  animation: welcome-enter 0.8s var(--ease-out) 0.3s both;
}

.sample-prompts-label {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--ink-ghost);
  margin-bottom: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.prompt-chips {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  align-items: stretch;
  text-align: left;
}

.prompt-chip {
  padding: 0.75rem 1.125rem;
  background: var(--bg-elevated);
  border: 1px solid var(--rule-faint);
  border-radius: var(--r-lg);
  color: var(--ink-secondary);
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.9375rem;
  font-weight: 400;
  cursor: pointer;
  transition: all var(--dur-med) var(--ease-out);
  line-height: 1.55;
  position: relative;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.prompt-chip::after {
  content: '';
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 24 24' fill='none' stroke='%23C4A265' stroke-width='2' stroke-linecap='round' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M5 12h14M12 5l7 7-7 7'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
  opacity: 0;
  transition: opacity var(--dur-fast) ease, transform var(--dur-med) var(--ease-out);
}

.prompt-chip:hover {
  border-color: var(--gold);
  color: var(--ink-primary);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
  padding-right: 2.5rem;
}

.prompt-chip:hover::after {
  opacity: 0.7;
}

.prompt-chip:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

.empty-figure-state {
  text-align: center;
  color: var(--ink-tertiary);
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.8125rem;
}

/* ========== CHAT MESSAGES ========== */

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.message {
  display: flex;
  gap: 0.875rem;
  animation: msg-enter 0.5s var(--ease-out) both;
  padding: 1.125rem 0;
  position: relative;
}

.message + .message {
  border-top: 1px solid var(--rule-faint);
}

@keyframes msg-enter {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--r-md);
  background: var(--bg-wash);
  border: 1px solid var(--rule);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  image-rendering: auto;
  transition: all var(--dur-fast) ease;
}

.message-avatar svg {
  width: 100%;
  height: 100%;
}

.message.user .message-avatar {
  background: var(--indigo);
  border-color: var(--indigo);
  color: var(--ink-inverse);
}

[data-theme="dark"] .message.user .message-avatar {
  background: var(--indigo-light);
  border-color: var(--indigo-light);
}

.message.assistant .message-avatar {
  background: var(--bg-elevated);
  border-color: var(--rule);
}

.message-content {
  flex: 1;
  min-width: 0;
}

.message-header {
  display: flex;
  align-items: baseline;
  gap: 0.625rem;
  margin-bottom: 0.375rem;
  min-width: 0;
}

.message-author {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--ink-primary);
  letter-spacing: 0.01em;
}

.message-time {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.6875rem;
  color: var(--ink-ghost);
  font-variant-numeric: tabular-nums;
}

.message-body {
  font-family: 'Cormorant Garamond', serif;
  color: var(--ink-primary);
  line-height: 1.75;
  font-size: 1.0625rem;
  font-weight: 400;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.message-body p {
  margin-bottom: 0.875rem;
}

.message-body p:last-child {
  margin-bottom: 0;
}

.message-body ul,
.message-body ol {
  margin: 0.75rem 0;
  padding-left: 1.5rem;
}

.message-body li {
  margin-bottom: 0.375rem;
  line-height: 1.65;
}

.message-body blockquote {
  border-left: 2px solid var(--gold);
  padding: 0.75rem 1rem;
  margin: 1rem 0;
  color: var(--ink-secondary);
  font-style: italic;
  background: var(--gold-wash);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  transition: background-color var(--dur-med) var(--ease-out);
}

.message-body h1,
.message-body h2,
.message-body h3,
.message-body h4 {
  font-family: 'Source Sans 3', sans-serif;
  line-height: 1.25;
  letter-spacing: 0.01em;
  margin: 1rem 0 0.625rem;
}

.message-body h1 {
  font-size: 1.4rem;
  font-weight: 650;
}

.message-body h2 {
  font-size: 1.25rem;
  font-weight: 640;
}

.message-body h3 {
  font-size: 1.1rem;
  font-weight: 620;
}

.message-body h4 {
  font-size: 1rem;
  font-weight: 620;
}

.message-body h1:first-child,
.message-body h2:first-child,
.message-body h3:first-child,
.message-body h4:first-child {
  margin-top: 0;
}

.message-body pre {
  margin: 0.875rem 0;
  background: var(--bg-sunken);
  border: 1px solid var(--rule-faint);
  border-radius: var(--r-md);
  padding: 0.75rem 0.875rem;
  overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.825rem;
  line-height: 1.55;
}

.message-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.86em;
  background: var(--indigo-wash);
  border: 1px solid var(--rule-faint);
  border-radius: var(--r-sm);
  padding: 0.06rem 0.3rem;
}

.message-body pre code {
  background: transparent;
  border: none;
  padding: 0;
  font-size: inherit;
}

.message-body a {
  color: var(--gold-dark);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.message-body a:hover {
  color: var(--gold);
}

/* ========== CITATIONS ========== */

.citation-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.0625rem 0.375rem;
  background: var(--gold-wash);
  border: 1px solid var(--rule);
  border-radius: var(--r-sm);
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.6875rem;
  color: var(--ink-secondary);
  text-decoration: none;
  transition: all var(--dur-fast) ease;
  margin: 0 0.125rem;
  vertical-align: middle;
}

.citation-inline:hover {
  background: var(--gold-glow);
  border-color: var(--gold);
  color: var(--ink-primary);
}

.message-citations {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--rule-faint);
}

/* Collapsible citation panel */
.citations-panel {
  border: 1px solid var(--rule-faint);
  border-radius: var(--r-lg);
  overflow: hidden;
  transition: border-color var(--dur-fast) ease;
}

.citations-panel[open] {
  border-color: var(--rule);
}

.citations-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 0.875rem;
  background: var(--bg-wash);
  cursor: pointer;
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ink-secondary);
  letter-spacing: 0.02em;
  list-style: none;
  user-select: none;
  transition: all var(--dur-fast) ease;
}

.citations-toggle::-webkit-details-marker {
  display: none;
}

.citations-toggle:hover {
  background: var(--bg-sunken);
  color: var(--ink-primary);
}

.citations-toggle-icon {
  flex-shrink: 0;
  opacity: 0.6;
}

.citations-count {
  margin-left: auto;
  background: var(--gold-wash);
  color: var(--gold-dark);
  font-size: 0.625rem;
  font-weight: 700;
  padding: 0.125rem 0.5rem;
  border-radius: var(--r-pill);
  line-height: 1.4;
}

.citations-panel > :not(summary) {
  padding: 0.625rem 0.875rem;
}

.citations-section {
  margin-bottom: 0.875rem;
}

.citations-section-spaced {
  margin-top: 0.75rem;
}

.citations-section:last-child {
  margin-bottom: 0;
}

.citations-label {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-ghost);
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.citations-label svg {
  opacity: 0.5;
}

.citations-list {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.citation-item {
  padding: 0.625rem 0.75rem;
  background: var(--bg-wash);
  border: 1px solid var(--rule-faint);
  border-radius: var(--r-md);
  font-size: 0.8125rem;
  transition: all var(--dur-fast) ease;
}

.citation-item:hover {
  border-color: var(--rule);
  background: var(--bg-sunken);
  box-shadow: var(--shadow-sm);
}

.citation-title {
  font-family: 'Cormorant Garamond', serif;
  font-weight: 600;
  color: var(--ink-primary);
  margin-bottom: 0.125rem;
  line-height: 1.4;
  font-size: 0.875rem;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.citation-authors {
  font-family: 'Source Sans 3', sans-serif;
  color: var(--ink-secondary);
  font-size: 0.6875rem;
  font-weight: 500;
  line-height: 1.4;
  margin-bottom: 0.125rem;
}

.citation-meta {
  font-family: 'Source Sans 3', sans-serif;
  color: var(--ink-tertiary);
  font-size: 0.6875rem;
  line-height: 1.4;
  margin-bottom: 0.25rem;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.citation-score {
  height: 3px;
  background: var(--rule-faint);
  border-radius: 2px;
  margin: 0.375rem 0;
  overflow: hidden;
}

.citation-score-bar {
  height: 100%;
}

.citation-score-meter {
  height: 100%;
  background: var(--gold);
  border-radius: 2px;
  transition: width var(--dur-med) var(--ease-out);
  width: 0;
}

.citation-score-meter.pct-0 { width: 0%; }
.citation-score-meter.pct-5 { width: 5%; }
.citation-score-meter.pct-10 { width: 10%; }
.citation-score-meter.pct-15 { width: 15%; }
.citation-score-meter.pct-20 { width: 20%; }
.citation-score-meter.pct-25 { width: 25%; }
.citation-score-meter.pct-30 { width: 30%; }
.citation-score-meter.pct-35 { width: 35%; }
.citation-score-meter.pct-40 { width: 40%; }
.citation-score-meter.pct-45 { width: 45%; }
.citation-score-meter.pct-50 { width: 50%; }
.citation-score-meter.pct-55 { width: 55%; }
.citation-score-meter.pct-60 { width: 60%; }
.citation-score-meter.pct-65 { width: 65%; }
.citation-score-meter.pct-70 { width: 70%; }
.citation-score-meter.pct-75 { width: 75%; }
.citation-score-meter.pct-80 { width: 80%; }
.citation-score-meter.pct-85 { width: 85%; }
.citation-score-meter.pct-90 { width: 90%; }
.citation-score-meter.pct-95 { width: 95%; }
.citation-score-meter.pct-100 { width: 100%; }

.citation-preview {
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.8125rem;
  font-style: italic;
  color: var(--ink-tertiary);
  line-height: 1.5;
  margin: 0.375rem 0;
  padding-left: 0.5rem;
  border-left: 2px solid var(--rule-faint);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.citation-link {
  font-family: 'Source Sans 3', sans-serif;
  color: var(--gold-dark);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.6875rem;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  transition: color var(--dur-fast) ease;
  letter-spacing: 0.02em;
}

.citation-link:hover {
  color: var(--gold);
  text-decoration: underline;
}

/* ========== LOADING STATE ========== */

.message.loading .message-body {
  display: flex;
  gap: 0.375rem;
  padding: 0.625rem 0;
  align-items: center;
}

.loading-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gold);
  animation: loading-pulse 1.4s infinite ease-in-out;
}

.loading-dot:nth-child(1) { animation-delay: -0.32s; }
.loading-dot:nth-child(2) { animation-delay: -0.16s; }
.loading-dot:nth-child(3) { animation-delay: 0s; }

@keyframes loading-pulse {
  0%, 80%, 100% {
    transform: scale(0.6);
    opacity: 0.3;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* ========== INPUT AREA ========== */

.input-area {
  flex-shrink: 0;
  padding: 0.875rem 1.5rem 1.25rem;
  background: transparent;
  border-top: none;
  transition: background-color var(--dur-med) var(--ease-out);
  position: relative;
}

/* Fade-out effect at bottom of chat */
.input-area::before {
  content: '';
  position: absolute;
  top: -24px;
  left: 0;
  right: 0;
  height: 24px;
  background: linear-gradient(to top, var(--bg-base), transparent);
  pointer-events: none;
}

.input-form {
  max-width: 100%;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  background: var(--bg-elevated);
  border: 1px solid var(--rule-faint);
  border-radius: var(--r-xl);
  padding: 0.5rem 0.875rem;
  transition: all var(--dur-med) var(--ease-out);
  box-shadow: var(--shadow-sm);
  position: relative;
}

.input-wrapper:hover {
  border-color: var(--rule-strong);
  box-shadow: var(--shadow-md);
}

.input-wrapper:focus-within {
  border-color: var(--gold);
  box-shadow: var(--shadow-glow);
}

.input-wrapper textarea {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-family: 'Cormorant Garamond', serif;
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.6;
  color: var(--ink-primary);
  background: transparent;
  max-height: 180px;
  overflow-y: auto;
  transition: color var(--dur-med) var(--ease-out);
  padding: 0.125rem 0;
}

.input-wrapper textarea::placeholder {
  color: var(--ink-ghost);
  font-style: italic;
}

.input-wrapper textarea:focus-visible {
  outline: none;
}

.input-actions {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  flex-shrink: 0;
}

.char-counter {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.5625rem;
  font-weight: 500;
  color: var(--ink-ghost);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  opacity: 0.7;
}

.send-button {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--indigo);
  border: none;
  color: var(--ink-inverse);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--dur-med) var(--ease-out);
  flex-shrink: 0;
  position: relative;
}

[data-theme="dark"] .send-button {
  background: var(--gold-dark);
  color: var(--bg-base);
}

.send-button:hover:not(:disabled) {
  background: var(--gold-dark);
  transform: scale(1.06);
  box-shadow: 0 2px 10px var(--gold-glow);
}

[data-theme="dark"] .send-button:hover:not(:disabled) {
  background: var(--gold);
}

.send-button:active:not(:disabled) {
  transform: scale(0.96);
}

.send-button:disabled {
  opacity: 0.25;
  cursor: not-allowed;
  background: var(--ink-ghost);
}

.send-button svg {
  transition: transform var(--dur-fast) var(--ease-out);
}

.send-button:hover:not(:disabled) svg {
  transform: translateX(1px);
}

.input-hint {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.625rem;
  color: var(--ink-ghost);
  text-align: center;
  margin-top: 0.375rem;
  letter-spacing: 0.02em;
  opacity: 0.8;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.error-banner {
  margin-top: 0.75rem;
  padding: 0.625rem 0.875rem;
  background: rgba(166, 61, 64, 0.06);
  border: 1px solid rgba(166, 61, 64, 0.2);
  border-radius: var(--r-md);
  color: var(--status-bad);
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1.5;
}

[data-theme="dark"] .error-banner {
  background: rgba(200, 90, 93, 0.1);
  border-color: rgba(200, 90, 93, 0.25);
  color: #E8847F;
}

/* ========== UTILITIES ========== */

.hidden {
  display: none !important;
}

.meta-strip {
  padding: 0.5rem 1rem;
  background: var(--bg-sunken);
  border-top: 1px solid var(--rule-faint);
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.6875rem;
  color: var(--ink-ghost);
  text-align: center;
}

/* ========== INFO TOGGLE BUTTON ========== */

.info-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  color: var(--ink-tertiary);
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease-out);
}

.info-toggle:hover {
  border-color: var(--gold);
  color: var(--gold);
  background: var(--gold-wash);
}

/* ========== INFO DRAWER + OVERLAY ========== */

.info-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 900;
  opacity: 0;
  transition: opacity var(--dur-med) var(--ease-out);
  pointer-events: none;
}

.info-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.info-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 340px;
  max-width: 100%;
  background: var(--bg-surface);
  border-left: 1px solid var(--rule);
  z-index: 910;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--dur-slow) var(--ease-out);
  box-shadow: var(--shadow-lg);
}

.info-drawer.open {
  transform: translateX(0);
}

.info-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--rule-faint);
  flex-shrink: 0;
}

.info-drawer-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--ink-primary);
}

.info-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: transparent;
  border: 1px solid var(--rule-faint);
  border-radius: var(--r-md);
  color: var(--ink-tertiary);
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease-out);
}

.info-close:hover {
  border-color: var(--rule-strong);
  color: var(--ink-primary);
  background: var(--bg-wash);
}

.info-drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
}

.info-section {
  margin-bottom: 1.75rem;
}

.info-section:last-child {
  margin-bottom: 0;
}

.info-section h3 {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gold-dark);
  margin-bottom: 0.5rem;
}

.info-section p {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1rem;
  line-height: 1.7;
  color: var(--ink-secondary);
}

.info-section ol {
  padding-left: 1.25rem;
  margin: 0;
}

.info-section li {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1rem;
  line-height: 1.7;
  color: var(--ink-secondary);
  margin-bottom: 0.5rem;
}

.info-section li strong {
  color: var(--ink-primary);
}

/* ========== CONFIRMATION DIALOG ========== */

body.modal-open {
  overflow: hidden;
}

.dialog-overlay {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at top, rgba(196, 162, 101, 0.12), transparent 42%),
    rgba(16, 14, 22, 0.56);
  backdrop-filter: blur(10px);
  z-index: 920;
  opacity: 0;
  transition: opacity var(--dur-med) var(--ease-out);
  pointer-events: none;
}

.dialog-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}

.confirmation-dialog {
  position: fixed;
  inset: 0;
  z-index: 930;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition:
    opacity var(--dur-med) var(--ease-out),
    transform var(--dur-med) var(--ease-out);
}

.confirmation-dialog.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.confirmation-dialog-shell {
  width: min(100%, 32rem);
  background:
    linear-gradient(180deg, rgba(196, 162, 101, 0.08), transparent 26%),
    var(--bg-surface);
  border: 1px solid var(--rule);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.confirmation-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1rem 0;
}

.confirmation-dialog-eyebrow {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold-dark);
}

.confirmation-dialog-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  background: transparent;
  border: 1px solid var(--rule-faint);
  border-radius: var(--r-md);
  color: var(--ink-tertiary);
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease-out);
}

.confirmation-dialog-close:hover {
  border-color: var(--rule-strong);
  background: var(--bg-wash);
  color: var(--ink-primary);
}

.confirmation-dialog-body {
  padding: 0.5rem 1.5rem 0;
}

.confirmation-dialog-title {
  font-family: 'Cormorant Garamond', serif;
  font-size: clamp(1.6rem, 2.4vw, 2rem);
  font-weight: 600;
  line-height: 1.1;
  color: var(--ink-primary);
}

.confirmation-dialog-copy {
  margin-top: 0.75rem;
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.05rem;
  line-height: 1.65;
  color: var(--ink-secondary);
}

.confirmation-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1.5rem;
}

.dialog-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.75rem;
  padding: 0.7rem 1rem;
  border-radius: var(--r-md);
  border: 1px solid var(--rule);
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease-out);
}

.dialog-button-secondary {
  background: transparent;
  color: var(--ink-secondary);
}

.dialog-button-secondary:hover {
  background: var(--bg-wash);
  border-color: var(--rule-strong);
  color: var(--ink-primary);
}

.dialog-button-primary {
  background: var(--indigo);
  border-color: var(--indigo);
  color: var(--ink-inverse);
  box-shadow: 0 10px 24px rgba(45, 43, 85, 0.18);
}

.dialog-button-primary:hover {
  background: var(--indigo-light);
  border-color: var(--indigo-light);
  transform: translateY(-1px);
}

.dialog-button-primary:active,
.dialog-button-secondary:active,
.confirmation-dialog-close:active {
  transform: scale(0.98);
}

/* ========== SCROLLBAR ========== */

.chat-wrapper::-webkit-scrollbar,
.input-wrapper textarea::-webkit-scrollbar {
  width: 5px;
}

.chat-wrapper::-webkit-scrollbar-track,
.input-wrapper textarea::-webkit-scrollbar-track {
  background: transparent;
}

.chat-wrapper::-webkit-scrollbar-thumb,
.input-wrapper textarea::-webkit-scrollbar-thumb {
  background: var(--rule);
  border-radius: 3px;
}

.chat-wrapper::-webkit-scrollbar-thumb:hover,
.input-wrapper textarea::-webkit-scrollbar-thumb:hover {
  background: var(--rule-strong);
}

/* ========== SAFE AREAS ========== */

@supports (padding: env(safe-area-inset-top)) {
  .app-header {
    padding-top: calc(0.75rem + env(safe-area-inset-top));
    padding-left: calc(1.75rem + env(safe-area-inset-left));
    padding-right: calc(1.75rem + env(safe-area-inset-right));
  }
  .input-area {
    padding-bottom: calc(1.25rem + env(safe-area-inset-bottom));
    padding-left: calc(1.5rem + env(safe-area-inset-left));
    padding-right: calc(1.5rem + env(safe-area-inset-right));
  }
}

/* ========== RESPONSIVE ========== */

@media (max-width: 980px) {
  .app-header {
    padding: 0.75rem 1rem;
    flex-wrap: wrap;
  }

  .brand-mark {
    width: 28px;
    height: 28px;
  }

  .brand-title {
    font-size: 1.125rem;
  }

  .brand-tagline {
    font-size: 0.625rem;
  }

  .header-actions {
    gap: 0.5rem;
  }

  .header-divider {
    display: none;
  }

  .new-chat-button span {
    display: none;
  }

  .new-chat-button {
    padding: 0.4rem;
    width: 36px;
    height: 36px;
    justify-content: center;
  }

  .theme-toggle {
    width: 36px;
    height: 36px;
  }

  .character-bar-inner {
    display: flex;
    padding: 0 1rem;
    gap: 0.75rem;
  }

  .character-bar-label {
    display: none;
  }

  .figure-grid {
    display: flex;
    width: auto;
    max-width: none;
    gap: 0.5rem;
    padding-bottom: 0.25rem;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
  }

  .figure-grid::-webkit-scrollbar {
    display: none;
  }

  .figure-card {
    padding: 0.375rem 0.625rem 0.375rem 0.375rem;
    scroll-snap-align: start;
    flex-shrink: 0;
  }

  .figure-avatar {
    width: 32px;
    height: 32px;
  }

  .figure-name {
    font-size: 0.75rem;
  }

  .figure-meta {
    display: none;
  }

  .figure-text {
    gap: 0;
  }

  .chat-wrapper {
    padding: 1.5rem 1rem;
  }

  .input-area {
    padding: 0.75rem 1rem 1rem;
  }

  .welcome-state {
    min-height: 280px;
  }

  .welcome-title {
    font-size: 1.5rem;
  }

  .welcome-subtitle {
    font-size: 0.9375rem;
    margin-bottom: 1.5rem;
  }

  .message {
    gap: 0.625rem;
  }

  .message-avatar {
    width: 32px;
    height: 32px;
  }

  /* Citation metadata stacks vertically */
  .citation-meta {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    font-size: 0.625rem;
  }
}

@media (max-width: 480px) {
  .app-header {
    padding: 0.625rem 0.75rem;
  }

  .brand-section {
    gap: 0.5rem;
  }

  .brand-title {
    font-size: 1rem;
  }

  .brand-tagline {
    display: none;
  }

  .request-id {
    display: inline-block;
    max-width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
  }

  .character-bar {
    padding: 0.5rem 0 0.625rem;
  }

  .character-bar-inner {
    display: flex;
    padding: 0 0.75rem;
  }

  /* Keep the selected voice identifiable without restoring the full desktop card */
  .figure-grid {
    gap: 0.375rem;
  }

  .figure-card {
    padding: 0.375rem 0.5rem 0.375rem 0.375rem;
    border-radius: var(--r-md);
    max-width: min(46vw, 9rem);
  }

  .figure-text {
    display: flex;
    min-width: 0;
  }

  .figure-avatar {
    width: 34px;
    height: 34px;
  }

  .figure-name {
    max-width: 100%;
    font-size: 0.7rem;
  }

  .figure-meta {
    display: none;
  }

  .figure-card.active {
    box-shadow: 0 0 0 2px var(--gold-wash);
  }

  /* Chat messages: tighter on mobile */
  .chat-wrapper {
    padding: 1rem 0.75rem;
  }

  .message {
    gap: 0.5rem;
    padding: 0.875rem 0;
  }

  .message-header {
    flex-wrap: wrap;
  }

  .message-avatar {
    width: 28px;
    height: 28px;
  }

  .message-body {
    font-size: 1rem;
  }

  /* Input area: full-bleed feel */
  .input-area {
    padding: 0.625rem 0.5rem 0.875rem;
  }

  .input-wrapper {
    padding: 0.5rem 0.75rem;
    border-radius: var(--r-lg);
  }

  .send-button {
    width: 36px;
    height: 36px;
  }

  /* Welcome state: compact */
  .welcome-state {
    min-height: 220px;
  }

  .welcome-ornament {
    margin-bottom: 1rem;
  }

  .welcome-title {
    font-size: 1.25rem;
  }

  .welcome-subtitle {
    font-size: 0.875rem;
    margin-bottom: 1.25rem;
  }

  .prompt-chip {
    padding: 0.75rem 0.875rem;
    font-size: 0.875rem;
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  /* Citations: compact */
  .citation-title {
    font-size: 0.8125rem;
  }

  .citation-authors,
  .citation-meta {
    font-size: 0.625rem;
  }

  .citations-panel > :not(summary) {
    padding: 0.5rem 0.625rem;
  }

  /* Info drawer: full-width on mobile */
  .info-drawer {
    width: 100%;
  }

  .confirmation-dialog {
    padding: 1rem;
    align-items: end;
  }

  .confirmation-dialog-shell {
    width: 100%;
    border-radius: 18px 18px 0 0;
  }

  .confirmation-dialog-body {
    padding-left: 1.125rem;
    padding-right: 1.125rem;
  }

  .confirmation-dialog-actions {
    flex-direction: column-reverse;
    padding: 1.125rem;
  }

  .dialog-button {
    width: 100%;
  }

  .info-toggle {
    width: 36px;
    height: 36px;
  }
}

/* ========== ACCESSIBILITY ========== */

/* Focus indicators for keyboard navigation */
:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

button:focus-visible,
a:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* Respect reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
