@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&family=Source+Serif+4:ital,opsz,wght@0,8..60,400;0,8..60,500;1,8..60,400&display=swap");

:root {
  color-scheme: dark;
  --bg-base: #0f0d0b;
  --bg-surface: #161310;
  --bg-surface-2: #1e1a16;
  --bg-elevated: #26211c;
  --bg-overlay: rgba(15, 13, 11, 0.72);
  --text-primary: #ece3d4;
  --text-secondary: #a39685;
  --text-tertiary: #6b5e50;
  --text-on-accent: #0f0d0b;
  --accent: #c8a572;
  --accent-hover: #d6b582;
  --accent-muted: #8a7253;
  --accent-glow: rgba(200, 165, 114, 0.15);
  --destructive: #b8523c;
  --border: #2a2520;
  --border-strong: #3a332c;
  --divider: rgba(236, 227, 212, 0.06);
  --ooc-bg: #1b1a1f;
  --ooc-accent: #7e8fa1;
  --rumor-text: #8a7253;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --font-serif: "Source Serif 4", Lora, Georgia, serif;
  --font-sans: Inter, -apple-system, BlinkMacSystemFont, "Helvetica Neue", sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", ui-monospace, Menlo, monospace;
}

* { box-sizing: border-box; }
html, body, #app { min-height: 100%; height: 100%; }
html {
  touch-action: pan-x pan-y;
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  background: #080706;
  color: var(--text-primary);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}
button, input, textarea, select { font: inherit; }
button {
  border: 0;
  background: none;
  color: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
input, textarea, select {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg-surface-2);
  color: var(--text-primary);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  outline: none;
  user-select: text;
  -webkit-user-select: text;
  -webkit-touch-callout: default;
}
textarea { resize: vertical; min-height: 96px; line-height: 1.5; }
input:focus, textarea:focus, select:focus { border-color: var(--accent-muted); }
label { display: grid; gap: 8px; color: var(--text-secondary); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
.text-field { gap: 8px; }
.field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.field-tool,
.composer-tool {
  width: auto;
  min-width: max-content;
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  background: var(--bg-surface);
  font: 11px/14px var(--font-sans);
  text-transform: none;
  letter-spacing: 0;
}
.field-tool:active,
.composer-tool:active { background: var(--bg-elevated); }
.field-meta {
  color: var(--text-tertiary);
  font: 11px/16px var(--font-mono);
  text-transform: none;
  letter-spacing: 0;
}
.long-text {
  min-height: 180px;
  max-height: 34dvh;
  overflow-y: auto;
  resize: none;
  font: 14px/21px var(--font-serif);
}

.mobile-shell {
  width: 100vw;
  height: 100dvh;
  min-height: 0;
  margin: 0 auto;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(200, 165, 114, 0.055), transparent 42%),
    var(--bg-base);
  position: relative;
  overflow: hidden;
  border-inline: 1px solid rgba(236, 227, 212, 0.03);
}
@media (min-width: 700px) {
  .mobile-shell {
    width: 390px;
  }
}
.grain {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.035;
  mix-blend-mode: screen;
  background-image:
    radial-gradient(circle at 21% 13%, #fff 0.4px, transparent 0.8px),
    radial-gradient(circle at 67% 41%, #fff 0.4px, transparent 0.8px),
    radial-gradient(circle at 89% 78%, #fff 0.4px, transparent 0.8px),
    radial-gradient(circle at 33% 88%, #fff 0.4px, transparent 0.8px);
  background-size: 140px 140px, 180px 180px, 220px 220px, 160px 160px;
  z-index: 1;
}
.mobile-shell > :not(.grain):not(.overlay-root):not(.text-editor-overlay) { position: relative; z-index: 2; }

.app-header, .chat-header {
  min-height: 58px;
  padding: max(10px, env(safe-area-inset-top)) 14px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--divider);
  background: rgba(15, 13, 11, 0.84);
  backdrop-filter: blur(18px);
}
.app-title {
  font-family: var(--font-serif);
  font-size: 20px;
  font-weight: 500;
  line-height: 22px;
}
.app-subtitle, .chat-title span {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--text-tertiary);
  font: 11px/16px var(--font-mono);
}
.icon-button {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--text-secondary);
  background: var(--bg-surface-2);
}
.header-actions { display: flex; align-items: center; gap: 8px; }
.icon-button.accent {
  background: var(--accent);
  color: var(--text-on-accent);
  font-size: 22px;
  font-weight: 800;
}
.icon-button.ghost { background: transparent; font-size: 26px; }
.text-button {
  color: var(--accent);
  font-size: 15px;
  padding: 8px 0;
}
.header-spacer { width: 64px; }

.screen-body {
  height: calc(100dvh - 58px);
  overflow: auto;
  padding: 18px 16px 110px;
  scrollbar-width: none;
}
.screen-body::-webkit-scrollbar, .messages::-webkit-scrollbar, .sheet-body::-webkit-scrollbar { display: none; }
.section-title {
  margin: 0 0 12px;
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 16px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.section-head .section-title { margin-bottom: 12px; }
.section-head .text-button { margin-top: -8px; }

.session-stack { display: grid; gap: 8px; }
.story-card {
  width: 100%;
  text-align: left;
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: rgba(22, 19, 16, 0.9);
  position: relative;
  overflow: hidden;
}
.story-card:active, .template-card:active, .mini-entity:active { transform: scale(0.995); }
.weaving {
  position: absolute;
  inset: 10px auto 10px 0;
  width: 2px;
  background: var(--accent);
  opacity: .65;
}
.story-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.story-head strong {
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 500;
}
.story-head span, .story-meta {
  color: var(--text-tertiary);
  font: 11px/16px var(--font-mono);
}
.story-card p {
  margin: 0;
  color: var(--text-secondary);
  font-family: var(--font-serif);
  font-size: 15px;
  line-height: 23px;
}
.story-meta { display: flex; gap: 12px; flex-wrap: wrap; }
.chronicles {
  margin-top: 28px;
  color: var(--text-tertiary);
  text-align: center;
  font-family: var(--font-serif);
  font-size: 12px;
  font-style: italic;
}
.bottom-main {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--divider);
  background: linear-gradient(to top, var(--bg-base) 70%, rgba(15, 13, 11, 0));
  z-index: 10;
}
.main-button, .secondary-button, .danger-button {
  width: 100%;
  min-height: 50px;
  border-radius: var(--radius-md);
  font-size: 16px;
  font-weight: 700;
}
.main-button { background: linear-gradient(180deg, var(--accent-hover), var(--accent)); color: var(--text-on-accent); }
.secondary-button { border: 1px solid var(--border-strong); color: var(--text-primary); }
.danger-button { background: var(--destructive); color: #fff1eb; }

.empty-state {
  min-height: 55dvh;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  text-align: center;
}
.book-glyph {
  color: var(--accent-muted);
  font-family: var(--font-serif);
  font-size: 54px;
}
.empty-state h2 { margin: 0; font-size: 18px; }
.empty-state p, .muted { margin: 0; color: var(--text-tertiary); font-size: 13px; line-height: 20px; }

.login-screen { display: grid; place-items: center; padding: 24px; }
.login-panel { width: 100%; display: grid; gap: 18px; text-align: center; }
.brand-mark {
  width: 66px;
  height: 66px;
  margin: 0 auto;
  display: grid;
  place-items: center;
  border: 1px solid var(--accent-muted);
  border-radius: 50%;
  color: var(--accent);
  font: italic 42px/1 var(--font-serif);
}
.login-panel h1 { margin: 0; font: italic 34px/1 var(--font-serif); }
.login-panel p { margin: 6px 0 0; color: var(--text-tertiary); font: italic 13px/18px var(--font-serif); }
.inline-error { color: #ffd9cf; background: rgba(184, 82, 60, .18); border: 1px solid rgba(184, 82, 60, .35); border-radius: var(--radius-md); padding: 12px; }

.create-form { display: grid; gap: 22px; }
.template-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.template-card {
  min-height: 104px;
  text-align: left;
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
}
.template-card.active {
  border-color: var(--accent-muted);
  background: var(--bg-elevated);
  box-shadow: 0 0 0 1px var(--accent-muted), 0 0 24px var(--accent-glow);
}
.template-card span { color: var(--accent); font: 24px/1 var(--font-serif); }
.template-card strong { font-size: 14px; text-transform: none; letter-spacing: 0; }
.template-card em { color: var(--text-tertiary); font: italic 12px/17px var(--font-serif); }
.grid2 { display: grid; gap: 12px; }

.chat-screen { display: block; }
.chat-layout {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}
.chat-header { min-height: 60px; }
.chat-title {
  min-width: 0;
  flex: 1;
  display: grid;
  justify-items: center;
  gap: 1px;
}
.chat-title strong {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 16px;
  font-weight: 600;
}
.pulse-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1400ms ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: .4; transform: scale(1.5); } }

.messages {
  min-height: 0;
  overflow: auto;
  padding: 10px 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  scrollbar-width: none;
}
.message { animation: fadeup 180ms ease-out; }
@keyframes fadeup { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.message.user {
  max-width: 86%;
  align-self: flex-end;
  display: grid;
  justify-items: end;
  gap: 5px;
}
.user-bubble {
  background: var(--bg-surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md) var(--radius-md) 4px var(--radius-md);
  padding: 12px 14px;
  color: var(--text-primary);
  font-size: 15px;
  line-height: 22px;
}
.message.user.ooc .user-bubble, .message.assistant.ooc .assistant-text { background: var(--ooc-bg); }
.msg-time { color: var(--text-tertiary); font: 10px/14px var(--font-mono); }
.ooc-badge {
  width: max-content;
  color: var(--ooc-accent);
  border: 1px solid rgba(126, 143, 161, .28);
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 10px;
  letter-spacing: .08em;
}
.message.assistant { display: grid; gap: 10px; }
.assistant-rule { width: 38px; height: 1px; background: var(--divider); }
.assistant-text {
  white-space: pre-wrap;
  color: var(--text-primary);
  font-family: var(--font-serif);
  font-size: 17px;
  line-height: 29px;
}
.assistant-text p { margin: 0 0 12px; }
.assistant-text em { color: var(--text-secondary); }
.msg-actions {
  display: flex;
  gap: 4px;
  margin-top: 10px;
  opacity: .7;
}
.action-icon {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: var(--text-tertiary);
}
.action-icon:hover,
.action-icon:focus-visible {
  color: var(--text-secondary);
  background: var(--bg-surface);
}
.action-icon:active { background: var(--bg-surface-2); }
.action-icon svg { display: block; }
.small {
  min-width: 28px;
  min-height: 28px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  font-size: 13px;
}
.tool-chip-list {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.tool-chip {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid var(--divider);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font: 12px/16px var(--font-mono);
  letter-spacing: 0.01em;
}
.tool-chip svg { color: var(--accent-muted); flex: 0 0 auto; }
.tool-chip-button {
  color: var(--text-tertiary);
  border-color: var(--border);
}
.tool-chip-button:hover,
.tool-chip-button:focus-visible {
  color: var(--text-secondary);
  border-color: var(--border-strong);
}

.chat-bottom {
  position: relative;
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  transition: background 200ms ease;
}
.chat-bottom.ooc-on,
.chat-bottom:has(.composer.ooc-on) {
  background: var(--ooc-bg);
}
.composer-meta {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 34px;
  padding: 0 2px 8px 44px;
  color: var(--text-tertiary);
  font: 11px/16px var(--font-mono);
}
.chat-bottom:focus-within .composer-meta,
.chat-bottom.has-draft .composer-meta {
  display: flex;
}
.composer-meta span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.composer {
  min-height: 40px;
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) 36px;
  align-items: end;
  gap: 8px;
}
.composer textarea {
  width: 100%;
  height: 40px;
  min-height: 40px;
  max-height: 38dvh;
  border: 0;
  background: transparent;
  border-radius: 0;
  padding: 10px 12px;
  resize: none;
  overflow-y: auto;
  color: var(--text-primary);
  font: 15px/20px var(--font-sans);
}
.composer textarea:focus {
  background: rgba(236, 227, 212, 0.02);
  border-radius: var(--radius-sm);
}
.composer textarea::placeholder { color: var(--text-tertiary); opacity: 1; }
.ooc-toggle {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  padding: 0;
  gap: 0;
  text-transform: none;
  letter-spacing: 0;
}
.ooc-toggle:active { background: var(--bg-surface-2); }
.ooc-toggle input { display: none; }
.ooc-toggle span {
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  color: var(--text-tertiary);
}
.ooc-toggle span svg { display: block; }
.ooc-toggle input:checked + span { color: var(--accent); }
.send-button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  align-self: center;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: var(--text-on-accent);
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
  box-shadow: 0 0 0 1px rgba(200,165,114,0.25), 0 0 20px var(--accent-glow);
}
.send-button:disabled {
  background: var(--bg-surface-2);
  color: var(--text-tertiary);
  box-shadow: none;
}
.world-fab {
  position: absolute;
  right: 16px;
  bottom: calc(64px + env(safe-area-inset-bottom));
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  color: var(--text-secondary);
  z-index: 5;
}
.world-fab.extracting { box-shadow: 0 0 28px var(--accent-glow); }
.chat-bottom:focus-within .world-fab,
.chat-bottom.has-draft .world-fab {
  display: none;
}
.text-editor-overlay {
  position: absolute;
  inset: 0;
  z-index: 80;
  display: grid;
  background: rgba(8, 7, 6, 0.94);
  backdrop-filter: blur(18px);
}
.text-editor-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--bg-base);
}
.text-editor-header {
  min-height: 58px;
  padding: max(10px, env(safe-area-inset-top)) 12px 10px;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 13, 11, 0.9);
}
.text-editor-header div {
  min-width: 0;
  display: grid;
  gap: 2px;
  text-align: center;
}
.text-editor-header strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
}
.text-editor-header span {
  color: var(--text-tertiary);
  font: 11px/15px var(--font-mono);
}
.text-editor-close {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--text-secondary);
}
.text-editor-done {
  min-height: 36px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-weight: 600;
}
.text-editor-input {
  min-height: 0;
  height: 100%;
  width: 100%;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 18px 16px;
  resize: none;
  overflow: auto;
  color: var(--text-primary);
  font: 16px/24px var(--font-serif);
}
.text-editor-footer {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
}
.vellum-cursor {
  display: inline-block;
  width: .55em;
  height: 1em;
  background: var(--accent);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 800ms steps(1, end) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.overlay-root {
  position: absolute;
  inset: 0;
  z-index: 30;
  pointer-events: none;
}
.overlay-root .sheet-backdrop,
.overlay-root .world-sheet {
  pointer-events: auto;
}
.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: var(--bg-overlay);
  z-index: 20;
  animation: backdropIn 180ms ease-out;
}
.world-sheet {
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 100%;
  height: min(78dvh, 720px);
  min-height: min(60dvh, 560px);
  z-index: 21;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  border: 1px solid var(--border);
  border-bottom: 0;
  background: var(--bg-surface);
  box-shadow: 0 -20px 60px rgba(0, 0, 0, .42);
  transform: translateX(-50%);
  animation: sheetIn 260ms cubic-bezier(.16,.84,.44,1);
}
@keyframes backdropIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheetIn { from { transform: translateX(-50%) translateY(100%); } to { transform: translateX(-50%) translateY(0); } }
.sheet-top {
  height: 34px;
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: center;
  padding: 8px 12px 2px;
}
.sheet-handle {
  width: 40px;
  height: 4px;
  margin: 0 auto;
  border-radius: 99px;
  background: var(--border-strong);
  padding: 0;
}
.sheet-close {
  width: 34px;
  height: 34px;
  justify-self: end;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--text-secondary);
  font-size: 22px;
  line-height: 1;
}
.sheet-close:active { background: var(--bg-surface-2); }
.sheet-tabs {
  display: flex;
  gap: 4px;
  padding: 4px 16px 0;
  border-bottom: 1px solid var(--divider);
}
.sheet-tabs button {
  min-height: 46px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  font-size: 15px;
}
.sheet-tabs button.active {
  color: var(--text-primary);
  border-color: var(--accent);
  font-weight: 600;
}
.sheet-body {
  min-height: 0;
  overflow: auto;
  padding: 16px 16px calc(32px + env(safe-area-inset-bottom));
  scrollbar-width: none;
}
.world-section {
  display: grid;
  gap: 10px;
  margin-bottom: 24px;
}
.world-section:last-child { margin-bottom: 0; }
.world-card, .entity-row, .timeline-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface-2);
  padding: 14px;
}
.scene-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}
.scene-head strong {
  min-width: max-content;
  font-family: var(--font-serif);
  font-size: 17px;
  line-height: 24px;
  font-weight: 500;
}
.scene-head span {
  min-width: 0;
  color: var(--text-tertiary);
  font: 11px/16px var(--font-mono);
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.world-card p, .timeline-item p { color: var(--text-secondary); margin: 8px 0; font-size: 13px; }
.world-card em, .timeline-item em { color: var(--text-secondary); font: italic 14px/22px var(--font-serif); }
.entity-rail {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  margin-inline: -16px;
  padding: 0 16px 4px;
  scrollbar-width: none;
}
.entity-rail::-webkit-scrollbar, .entity-filter-rail::-webkit-scrollbar { display: none; }
.mini-entity {
  flex: 0 0 140px;
  width: 140px;
  height: 132px;
  display: grid;
  align-content: start;
  gap: 7px;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface-2);
  padding: 12px;
  overflow: hidden;
}
.mini-entity strong {
  min-width: 0;
  overflow-wrap: anywhere;
  font-family: var(--font-serif);
  font-size: 15px;
  line-height: 20px;
  font-weight: 500;
}
.mini-entity span { color: var(--text-secondary); font-size: 12px; }
.mini-entity em {
  color: var(--accent-muted);
  font: italic 12px/17px var(--font-serif);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.fact-line, .rumor, .event-line {
  color: var(--text-secondary);
  font: 14px/22px var(--font-serif);
}
.fact-line span { color: var(--accent); margin-right: 8px; }
.rumor { color: var(--rumor-text); font-style: italic; }
.entities-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.entity-filter-rail {
  min-height: 32px;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  overflow-y: hidden;
  margin-inline: -16px;
  padding: 0 16px 2px;
  scrollbar-width: none;
}
.entity-filter-chip {
  flex: 0 0 auto;
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  border-radius: 999px;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  background: transparent;
  font: 13px/16px var(--font-sans);
  white-space: nowrap;
}
.entity-filter-chip.active {
  color: var(--accent);
  border-color: var(--accent-muted);
  background: var(--accent-glow);
}
.entity-filter-chip:focus-visible {
  outline: 1px solid var(--accent-muted);
  outline-offset: 2px;
}
.search-box {
  height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface-2);
  color: var(--text-tertiary);
}
.search-box svg {
  flex: 0 0 auto;
  color: var(--text-tertiary);
}
.search-box input {
  min-width: 0;
  height: 100%;
  border: 0;
  background: transparent;
  padding: 0;
  border-radius: 0;
  color: var(--text-primary);
  font: 14px/20px var(--font-sans);
}
.search-box input::placeholder {
  color: var(--text-tertiary);
  opacity: 1;
}
.entity-list-row {
  width: 100%;
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 4px;
  text-align: left;
  border-bottom: 1px solid var(--divider);
}
.entity-list-row[hidden] { display: none; }
.entity-list-row:active { background: var(--bg-surface-2); }
.entity-list-row span {
  min-width: 0;
  display: grid;
  gap: 3px;
}
.entity-list-row strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-serif);
  font-size: 16px;
  font-weight: 500;
}
.entity-list-row em {
  color: var(--text-secondary);
  font-size: 13px;
  font-style: normal;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.entity-list-row b {
  flex: 0 0 auto;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-tertiary);
  font: 10px/14px var(--font-mono);
  text-transform: uppercase;
  letter-spacing: .08em;
}
.entity-list, .timeline-list, .settings-form { display: grid; gap: 10px; }
.entity-row summary, .timeline-item summary {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
}
.entity-row strong { font-family: var(--font-serif); font-size: 16px; font-weight: 500; }
.entity-row span, .timeline-item span { color: var(--text-tertiary); font-size: 12px; }
.fact-kv {
  display: grid;
  grid-template-columns: minmax(90px, .8fr) minmax(0, 1fr);
  gap: 10px;
  padding-top: 10px;
  color: var(--text-secondary);
  font-size: 12px;
}
.fact-kv b { color: var(--text-primary); font-weight: 500; }
.danger-link { color: #e58c77; padding: 10px 0 0; text-align: left; }
.settings-form textarea { min-height: 220px; font-family: var(--font-serif); }
.timeline-list {
  position: relative;
  gap: 16px;
  padding-left: 16px;
}
.timeline-list::before {
  content: "";
  position: absolute;
  left: 23px;
  top: 4px;
  bottom: 16px;
  width: 1px;
  background: var(--border);
}
.timeline-node {
  display: flex;
  gap: 14px;
  text-align: left;
  position: relative;
}
.timeline-node i {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  margin-top: 4px;
  border-radius: 50%;
  border: 1.5px solid var(--text-tertiary);
  background: var(--bg-surface);
  z-index: 1;
}
.timeline-node i.current {
  border: 0;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}
.timeline-node span {
  min-width: 0;
  display: grid;
  gap: 3px;
  padding-bottom: 4px;
}
.timeline-node strong {
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 500;
}
.timeline-node b {
  justify-self: start;
  color: var(--text-tertiary);
  font: 11px/16px var(--font-mono);
}
.timeline-node em {
  color: var(--text-tertiary);
  font: italic 13px/20px var(--font-serif);
}

@media (min-width: 760px) {
  body {
    display: grid;
    place-items: center;
    min-height: 100dvh;
    background:
      radial-gradient(circle at 50% 8%, rgba(200, 165, 114, .06), transparent 34%),
      #070605;
  }
  .mobile-shell {
    height: min(920px, 100dvh);
    border-radius: 28px;
    border: 1px solid rgba(236, 227, 212, 0.06);
    box-shadow: 0 32px 120px rgba(0, 0, 0, .55);
  }
}
