/* ========================================
   WITH BARE FEET — Shared Styles
   ======================================== */

:root {
  --bg-deep:    #0e0c13;
  --bg:         #131118;
  --bg-surface: #1a1722;
  --bg-raised:  #211e2b;
  --bg-glow:    #1e1b27;

  --text:       #d4cfe0;
  --text-soft:  #9e96b0;
  --text-faint: #7a7490;
  --text-ghost: #3a3550;

  --border:     #2a2638;
  --border-soft:#1f1c2a;

  --c0: #9090b0; --c0-bg: rgba(144,144,176,0.05);
  --c1: #d4a0bf; --c1-bg: rgba(212,160,191,0.06);
  --c2: #c47050; --c2-bg: rgba(196,112,80,0.06);
  --c3: #c4b88a; --c3-bg: rgba(196,184,138,0.04);
  --c4: #b090c0; --c4-bg: rgba(176,144,192,0.05);
  --c5: #70c0c0; --c5-bg: rgba(112,192,192,0.05);
  --c6: #c0a860; --c6-bg: rgba(192,168,96,0.05);
  --c7: #8ec4b0; --c7-bg: rgba(142,196,176,0.06);
  --c8: #c07070; --c8-bg: rgba(192,112,112,0.05);
  --c9: #7ba8d4; --c9-bg: rgba(123,168,212,0.06);
  --cx: #d4b060; --cx-bg: rgba(212,176,96,0.05);
  --system: #706a80;

  --accent: #b8a0d0;

  /* Inline formatting */
  --em-color:       #b0aac4;
  --strong-color:   #ebe4f0;
  --q-color:        #f0e8d8;
  --c0-q: #b0b0d0; --c0-em: #707090; --c0-strong: #b0b0e0;
  --c1-q: #e4b8d4; --c1-em: #a88898; --c1-strong: #ff9cd0;
  --c2-q: #e8b090; --c2-em: #906850; --c2-strong: #ff8050;
  --c3-q: #d8d0b4; --c3-em: #908868; --c3-strong: #f0e0a0;
  --c4-q: #d0a8e0; --c4-em: #8868a0; --c4-strong: #c090e0;
  --c5-q: #90e0e0; --c5-em: #508888; --c5-strong: #70d0d0;
  --c6-q: #e0c880; --c6-em: #887840; --c6-strong: #d0b850;
  --c7-q: #d4ffe8; --c7-em: #608878; --c7-strong: #80ffc0;
  --c8-q: #e09090; --c8-em: #885050; --c8-strong: #d07070;
  --c9-q: #a0c4e4; --c9-em: #7090a8; --c9-strong: #90c8ff;
  --bq-color:       #c8c0d8;
  --bq-border:      rgba(184,160,208,0.3);
  --system-bg:      rgba(112,106,128,0.06);
  --system-border:  rgba(112,106,128,0.12);
  --c3-border:rgba(196,184,138,0.15);
  --cx-border:rgba(212,176,96,0.1);

  /* Grain overlay */
  --grain-opacity:  0.025;

  --radius: 8px;

  /* Typography controls */
  --body-font: 'Lucida Grande', 'Lucida Sans Unicode', Verdana, Helvetica, sans-serif;
  --body-size: 17px;

  /* Topbar height (set by JS) */
  --topbar-h: 42px;

  /* Safe area for notch phones */
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

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

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  overflow-x: clip;
  max-width: 100vw;
}

body {
  font-family: var(--body-font);
  background: var(--bg-deep);
  color: var(--text);
  line-height: 1.8;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: clip;
  -webkit-font-smoothing: antialiased;
  -webkit-text-stroke: var(--text-weight, 0);
}

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

/* ===== PROGRESS BAR ===== */
.progress-track {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  z-index: 1000;
  background: transparent;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--c1) 0%, var(--c1) 15%, var(--c9) 40%, var(--c9) 60%, var(--c7) 85%, var(--c7) 100%);
  transition: width 0.15s ease-out;
  box-shadow: 0 0 12px rgba(184,160,208,0.4);
}

/* ===== TOP BAR ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  width: 100%;
  max-width: 100vw;
  padding: calc(10px + var(--sat)) 16px 10px;
  background: var(--bg-deep);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar-title {
  font-family: 'Playfair Display', serif;
  font-size: clamp(20px, 2.2vw, 30px);
  font-weight: 400;
  font-style: italic;
  color: var(--accent);
  letter-spacing: 0.5px;
  white-space: nowrap;
  opacity: 0.9;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 1;
  line-height: 1.2;
}

.topbar-arc {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  min-width: 0;
  flex: 1;
  padding-right: 8px;
  line-height: 1.2;
}
.topbar-arc-num {
  font-family: 'JetBrains Mono', monospace;
  font-size: clamp(9px, 1vw, 14px);
  color: var(--text-faint);
  letter-spacing: 2px;
}
.topbar-arc-name {
  font-family: 'Playfair Display', serif;
  font-size: clamp(12px, 1.2vw, 18px);
  font-style: italic;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.topbar-controls {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
}

/* ===== PILL BUTTONS ===== */
.pill {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-faint);
  font-family: 'Source Sans 3', 'Segoe UI', sans-serif;
  font-size: clamp(11px, 1.1vw, 16px);
  font-weight: 300;
  letter-spacing: 0.5px;
  padding: 5px 10px;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  white-space: nowrap;
}
.pill:active { transform: scale(0.95); }
.pill.active {
  background: var(--bg-raised);
  color: var(--text-soft);
  border-color: var(--text-faint);
}
.pill.off { opacity: 0.3; }

/* ===== SETTINGS DRAWER ===== */
.settings-toggle {
  appearance: none;
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: clamp(32px, 3vw, 42px);
  height: clamp(32px, 3vw, 42px);
  font-size: clamp(16px, 1.6vw, 24px);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-faint);
  font-size: 16px;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.2s;
}
.settings-toggle:active { transform: scale(0.9); }

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.6s ease;
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }

.drawer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 80vh;
  max-height: 80dvh;
  overflow-y: auto;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  padding: 20px 20px calc(20px + var(--sab));
  z-index: 201;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}
.drawer-backdrop.open .drawer { transform: translateY(0); }

.drawer-close {
  position: absolute;
  top: 12px;
  right: 16px;
  appearance: none;
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.2s;
}
.drawer-close:hover { color: var(--text-soft); }

.drawer-section {
  margin-bottom: 16px;
}
.drawer-label {
  font-family: 'Source Sans 3', 'Segoe UI', sans-serif;
  font-size: clamp(11px, 1.1vw, 15px);
  color: var(--text-soft);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.drawer-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ===== ARC SELECTOR ===== */
.arc-select-wrap {
  position: relative;
}
.arc-select {
  appearance: none;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-soft);
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  padding: 5px 24px 5px 10px;
  border-radius: 20px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.arc-select option {
  background: var(--bg-surface);
  color: var(--text);
}

/* ===== STORY CONTAINER ===== */
.story {
  max-width: clamp(640px, 50vw, 900px);
  margin: 0 auto;
  padding: 8px 18px 60px;
}

@media (min-width: 769px) {
  .story { padding: 20px 24px 60px; }
}

/* ===== ARC SEPARATOR ===== */
.arc-separator {
  border: none;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--text-ghost), transparent);
  margin: 40px 0 0;
}

/* ===== COVER IMAGE ===== */
.cover-image {
  padding: 0 0 16px;
  margin-top: -24px;
  text-align: center;
}
.cover-image img {
  width: 100%;
  max-width: 560px;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: var(--radius);
  box-shadow: 0 4px 24px rgba(0,0,0,0.4);
}

/* ===== ARC DIVIDER ===== */
.arc-divider {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 24px 0 36px;
}
.arc-divider::before,
.arc-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  align-self: flex-end;
  margin-bottom: 10px;
}
.arc-divider::before {
  background: linear-gradient(90deg, transparent, var(--text-faint));
}
.arc-divider::after {
  background: linear-gradient(90deg, var(--text-faint), transparent);
}

.beat-mark {
  color: var(--text-faint);
  font-size: 16px;
  letter-spacing: 4px;
}

.the-end {
  text-align: center;
  font-family: 'Playfair Display', serif;
  font-size: clamp(28px, 2.8vw, 40px);
  font-style: italic;
  color: var(--text);
  letter-spacing: 4px;
  margin: 80px 0 0;
}

.arc-title {
  text-align: center;
  font-family: 'Playfair Display', serif;
  font-size: clamp(14px, 1.4vw, 22px);
  font-style: italic;
  color: var(--text);
  letter-spacing: 2px;
}
.arc-number {
  display: block;
  font-family: 'JetBrains Mono', monospace;
  font-size: clamp(9px, 0.9vw, 13px);
  font-style: normal;
  letter-spacing: 4px;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 4px;
}

/* ===== MESSAGE ===== */
.message {
  margin-bottom: 28px;
  position: relative;
  padding-left: 3px;
}

/* Subtle left accent line per character */
.message::before {
  content: '';
  position: absolute;
  left: -6px;
  top: 6px;
  bottom: 6px;
  width: 2px;
  border-radius: 1px;
  opacity: 0.35;
}

.message.char-c0::before { background: var(--c0); }
.message.char-c1::before { background: var(--c1); }
.message.char-c2::before { background: var(--c2); }
.message.char-c3::before { background: var(--c3); }
.message.char-c4::before { background: var(--c4); }
.message.char-c5::before { background: var(--c5); }
.message.char-c6::before { background: var(--c6); }
.message.char-c7::before { background: var(--c7); }
.message.char-c8::before { background: var(--c8); }
.message.char-c9::before { background: var(--c9); }
.message.char-cx::before { background: var(--cx); }

/* type-narrator */
.message.type-narrator {
  text-align: center;
  margin-left: 20px;
  margin-right: 20px;
  padding: 14px 0;
  border-top: 1px solid var(--c3-border);
  border-bottom: 1px solid var(--c3-border);
}
.message.type-narrator::before { display: none; }
.message.type-narrator .msg-header {
  justify-content: center;
}
.message.type-narrator .msg-body {
  color: var(--c3);
  font-style: italic;
  font-size: var(--body-size);
}

/* ===== MESSAGE HEADER ===== */
.msg-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 5px;
}

.msg-name {
  font-family: 'JetBrains Mono', monospace;
  font-size: clamp(11px, 1vw, 15px);
  font-weight: 300;
  letter-spacing: 2px;
  text-transform: uppercase;
}
.msg-name.n-c0 { color: var(--c0); }
.msg-name.n-c1 { color: var(--c1); }
.msg-name.n-c2 { color: var(--c2); }
.msg-name.n-c3 { color: var(--c3); }
.msg-name.n-c4 { color: var(--c4); }
.msg-name.n-c5 { color: var(--c5); }
.msg-name.n-c6 { color: var(--c6); }
.msg-name.n-c7 { color: var(--c7); }
.msg-name.n-c8 { color: var(--c8); }
.msg-name.n-c9 { color: var(--c9); }
.msg-name.n-cx { color: var(--cx); }

.msg-index {
  font-family: 'JetBrains Mono', monospace;
  font-size: clamp(9px, 0.8vw, 12px);
  color: var(--text-faint);
  letter-spacing: 0.5px;
}

/* Sticky character names */
.message .msg-header {
  position: sticky;
  top: var(--topbar-h, 42px);
  z-index: 10;
  background: var(--bg-deep);
  padding: 4px 0 6px;
}

/* ===== MESSAGE CONTEXT MENU ===== */

/* Trigger — three ghost dots, nearly invisible until needed */

/* Dropdown — velvet surface, appears from nothing */
@keyframes ctxIn {
  from { opacity: 0; transform: scale(0.95) translateY(-4px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ===== MESSAGE BODY TEXT ===== */
.msg-body {
  font-size: var(--body-size);
  line-height: 1.85;
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.msg-body p { margin: 0 0 0.5em; }
.msg-body p:last-child { margin-bottom: 0; }
/* Action/narration — per-character, muted */
.msg-body em { font-style: italic; color: var(--em-color); }
.char-c0 em { color: var(--c0-em); }
.char-c1 em { color: var(--c1-em); }
.char-c2 em { color: var(--c2-em); }
.char-c4 em { color: var(--c4-em); }
.char-c5 em { color: var(--c5-em); }
.char-c6 em { color: var(--c6-em); }
.char-c7 em { color: var(--c7-em); }
.char-c8 em { color: var(--c8-em); }
.char-c9 em { color: var(--c9-em); }

.msg-body q { color: var(--q-color); quotes: none; }
.char-c0 q { color: var(--c0-q); }
.char-c1 q { color: var(--c1-q); }
.char-c2 q { color: var(--c2-q); }
.char-c4 q { color: var(--c4-q); }
.char-c5 q { color: var(--c5-q); }
.char-c6 q { color: var(--c6-q); }
.char-c7 q { color: var(--c7-q); }
.char-c8 q { color: var(--c8-q); }
.char-c9 q { color: var(--c9-q); }
.type-narrator q { color: var(--c3-q); }

.msg-body q em { color: inherit; }
.msg-body strong { font-weight: 600; color: var(--strong-color); }
.char-c0 strong { color: var(--c0-strong); }
.char-c1 strong { color: var(--c1-strong); }
.char-c2 strong { color: var(--c2-strong); }
.char-c4 strong { color: var(--c4-strong); }
.char-c5 strong { color: var(--c5-strong); }
.char-c6 strong { color: var(--c6-strong); }
.char-c7 strong { color: var(--c7-strong); }
.char-c8 strong { color: var(--c8-strong); }
.char-c9 strong { color: var(--c9-strong); }
.type-narrator strong { color: var(--c3-strong); }
.msg-body s { text-decoration: line-through; opacity: 0.5; }

/* No text colors mode */
.no-text-colors [class*="char-"] em,
.no-text-colors .type-narrator em,
.no-text-colors .msg-body em { color: #ffffff; }
.no-text-colors [class*="char-"] q,
.no-text-colors .type-narrator q,
.no-text-colors .msg-body q { color: #ffffff; }
.no-text-colors [class*="char-"] strong,
.no-text-colors .type-narrator strong,
.no-text-colors .msg-body strong { color: #ffffff; }
[data-theme="light"] .no-text-colors [class*="char-"] em,
[data-theme="light"] .no-text-colors .type-narrator em,
[data-theme="light"] .no-text-colors .msg-body em { color: #000000; }
[data-theme="light"] .no-text-colors [class*="char-"] q,
[data-theme="light"] .no-text-colors .type-narrator q,
[data-theme="light"] .no-text-colors .msg-body q { color: #000000; }
[data-theme="light"] .no-text-colors [class*="char-"] strong,
[data-theme="light"] .no-text-colors .type-narrator strong,
[data-theme="light"] .no-text-colors .msg-body strong { color: #000000; }

.msg-body blockquote {
  border-left: 2px solid var(--bq-border);
  padding-left: 14px;
  margin: 8px 0;
  color: var(--bq-color);
  font-style: italic;
}

.msg-body hr {
  border: none;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--text-ghost), transparent);
  margin: 28px 20px;
}

/* Regenerated messages */
.message.regen-replaced,
.message.regen-correction {
  opacity: 0.60;
  max-height: 48px;
  overflow: hidden;
  position: relative;
  cursor: pointer;
  transition: all 0.3s ease;
}
.message.regen-replaced::after,
.message.regen-correction::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 32px;
  background: linear-gradient(transparent, var(--bg-deep));
  pointer-events: none;
}
.regen-badge {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--text-faint);
  letter-spacing: 1px;
  margin-bottom: 4px;
  text-align: center;
}
.message.regen-replaced.expanded,
.message.regen-correction.expanded {
  max-height: none;
  overflow: visible;
  opacity: 0.75;
}
.message.regen-replaced.expanded::after,
.message.regen-correction.expanded::after {
  display: none;
}

/* ===== LOADING / ERROR ===== */
.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
  min-height: 80dvh;
  text-align: center;
  padding: 40px 20px;
}

.loading-title {
  font-family: 'Playfair Display', serif;
  font-size: 32px;
  font-style: italic;
  color: var(--accent);
  margin-bottom: 20px;
  opacity: 0;
  animation: loadFade 1.5s ease 0.2s forwards;
}

.loading-sub {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--text-faint);
  letter-spacing: 3px;
  text-transform: uppercase;
  opacity: 0;
  animation: loadFade 1.5s ease 0.6s forwards;
}

.loading-dots {
  margin-top: 24px;
  display: flex;
  gap: 6px;
  opacity: 0;
  animation: loadFade 1s ease 1s forwards;
}
.loading-dots span {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
  animation: dotPulse 1.4s ease-in-out infinite;
}
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes loadFade { to { opacity: 1; } }
@keyframes dotPulse {
  0%, 80%, 100% { opacity: 0.2; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1.2); }
}

.error-screen {
  text-align: center;
  padding: 100px 24px;
  color: #c07070;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  line-height: 1.8;
}

/* ===== DESKTOP ARC NAV (right rail) ===== */
.arc-rail {
  position: fixed;
  right: 24px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 50;
}

.arc-pip {
  appearance: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-ghost);
  border: none;
  padding: 0;
  cursor: pointer;
  transition: all 0.25s ease;
  position: relative;
}
.arc-pip:hover {
  background: var(--text-faint);
  transform: scale(2);
}
.arc-pip.active {
  background: var(--accent);
  transform: scale(2);
  box-shadow: 0 0 8px rgba(184,160,208,0.5);
}

/* Tooltip on hover */
.arc-pip::after {
  content: attr(data-tip);
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  white-space: nowrap;
  font-family: 'JetBrains Mono', monospace;
  font-size: 10px;
  color: var(--text-soft);
  background: var(--bg-surface);
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid var(--border);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.arc-pip:hover::after { opacity: 1; }

/* ===== EMOTION DISPLAY (fixed, crossfading) ===== */
/* Collapsed settings */
.collapsed { display: none !important; }

/* ===== ARC LIST (drawer) ===== */
.arc-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.arc-list .pill {
  text-align: left;
  width: 100%;
  font-size: 12px;
  color: var(--text-soft);
}
.arc-list-item { position: relative; }

[data-theme="light"] .arc-list .pill {
  border-color: var(--text-faint);
}

/* ===== FONT CONTROLS ===== */
.font-select {
  appearance: none;
  background: var(--bg-surface);
  border: 1px solid var(--text-faint);
  color: var(--text-soft);
  font-family: 'Source Sans 3', 'Segoe UI', sans-serif;
  font-size: clamp(12px, 1.1vw, 16px);
  padding: 5px 10px;
  border-radius: 20px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.font-select option {
  background: var(--bg-surface);
  color: var(--text);
}

.size-controls {
  display: flex;
  align-items: center;
  gap: 4px;
}
.size-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-surface);
  color: var(--text-soft);
  font-family: 'Source Sans 3', 'Segoe UI', sans-serif;
  font-size: clamp(14px, 1.3vw, 18px);
  width: clamp(26px, 2.5vw, 34px);
  height: 26px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.2s;
}
.size-btn:active { transform: scale(0.9); }
.size-label {
  font-family: 'Source Sans 3', 'Segoe UI', sans-serif;
  font-size: clamp(12px, 1.1vw, 16px);
  color: var(--text-soft);
  min-width: 28px;
  text-align: center;
}

/* ===== LIGHT THEME ===== */
[data-theme="light"] {
  --bg-deep:    #e4e0da;
  --bg:         #dedad4;
  --bg-surface: #d4d0ca;
  --bg-raised:  #cac6c0;
  --bg-glow:    #dcd8d2;

  --text:       #1a1624;
  --text-soft:  #403850;
  --text-faint: #908898;
  --text-ghost: #c4c0cc;

  --border:     #d4d0dc;
  --border-soft:#e0dce8;

  --c0: #606080; --c0-bg: rgba(96,96,128,0.06);
  --c1: #a05878; --c1-bg: rgba(160,88,120,0.07);
  --c2: #c06040; --c2-bg: rgba(192,96,64,0.07);
  --c3: #807040; --c3-bg: rgba(128,112,64,0.05);
  --c4: #8a6090; --c4-bg: rgba(138,96,144,0.06);
  --c5: #50a0a0; --c5-bg: rgba(80,160,160,0.06);
  --c6: #a08840; --c6-bg: rgba(160,136,64,0.06);
  --c7: #408868; --c7-bg: rgba(64,136,104,0.07);
  --c8: #905050; --c8-bg: rgba(144,80,80,0.06);
  --c9: #3070a8; --c9-bg: rgba(48,112,168,0.07);
  --cx: #907820; --cx-bg: rgba(144,120,32,0.06);
  --system: #686080;

  --accent: #6850a0;

  --em-color:       #7868a8;
  --strong-color:   #100c18;
  --q-color:        #6a5030;
  --c0-q: #7878a0; --c0-em: #505070; --c0-strong: #4040a0;
  --c1-q: #b84c7c; --c1-em: #704858; --c1-strong: #c02070;
  --c2-q: #e09070; --c2-em: #784030; --c2-strong: #d05030;
  --c3-q: #787028; --c3-em: #585020; --c3-strong: #806818;
  --c4-q: #a06898; --c4-em: #604060; --c4-strong: #8050a0;
  --c5-q: #308888; --c5-em: #206060; --c5-strong: #208080;
  --c6-q: #907828; --c6-em: #685818; --c6-strong: #907020;
  --c7-q: #10c870; --c7-em: #2a5040; --c7-strong: #008850;
  --c8-q: #a04040; --c8-em: #683030; --c8-strong: #903030;
  --c9-q: #3080d8; --c9-em: #304868; --c9-strong: #0850c0;
  --bq-color:       #686080;
  --bq-border:      rgba(100,80,160,0.3);
  --system-bg:      rgba(100,90,120,0.07);
  --system-border:  rgba(100,90,120,0.15);
  --c3-border:rgba(128,112,64,0.2);
  --cx-border:rgba(144,120,32,0.15);

  --grain-opacity:  0.015;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  :root { --topbar-h: 34px; }
  .arc-rail { display: none; }
  .topbar { padding: calc(8px + var(--sat)) 12px 8px; }
  .topbar-title { font-size: 17px; }
  .msg-body { line-height: 1.8; }
  .story { padding: 4px 14px 40px; }
}

@media (min-width: 769px) {
  .topbar-controls { gap: 8px; }
}

/* ===== SELECTION COLOR ===== */
::selection {
  background: rgba(184,160,208,0.3);
  color: #fff;
}
[data-theme="light"] ::selection {
  background: rgba(100,80,160,0.25);
  color: #000;
}

/* ===== SCROLLBAR (desktop) ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--text-ghost);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* ===== SEARCH ===== */

/* ===== WELCOME MODAL ===== */
.welcome-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg-deep);
  display: flex;
  align-items: center;
  justify-content: center;
}
.welcome-modal {
  max-width: 420px;
  width: 90%;
  padding: 40px 32px;
  text-align: center;
}
.welcome-title {
  font-family: 'Playfair Display', serif;
  font-size: clamp(32px, 3vw, 44px);
  font-style: italic;
  color: var(--text);
  letter-spacing: 2px;
  margin-bottom: 40px;
}
.welcome-section {
  margin-bottom: 28px;
}
.welcome-label {
  font-family: 'Source Sans 3', 'Segoe UI', sans-serif;
  font-size: clamp(14px, 1.3vw, 20px);
  color: var(--text-soft);
  margin-bottom: 10px;
}
.welcome-hint {
  font-family: 'Source Sans 3', 'Segoe UI', sans-serif;
  font-size: clamp(12px, 1.1vw, 16px);
  color: var(--text-faint);
  margin-top: -6px;
  margin-bottom: 10px;
}
.welcome-row {
  display: flex;
  gap: 8px;
  justify-content: center;
}
.welcome-pill {
  font-size: clamp(13px, 1.2vw, 18px);
  padding: clamp(8px, 0.8vw, 12px) clamp(20px, 2vw, 32px);
}
.welcome-footer {
  font-family: 'Source Sans 3', 'Segoe UI', sans-serif;
  font-size: clamp(12px, 1vw, 15px);
  color: var(--text-ghost);
  margin: 24px 0 20px;
}
.welcome-start {
  font-family: 'Source Sans 3', 'Segoe UI', sans-serif;
  font-size: clamp(15px, 1.4vw, 20px);
  padding: clamp(12px, 1vw, 16px) clamp(40px, 4vw, 60px);
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.2s;
}
.welcome-start:hover {
  background: var(--bg-glow);
}
