:root {
  --bg: #13111c;
  --bg2: #1c1929;
  --bg3: #262238;
  --border: #363050;
  --text: #e8e4f5;
  --muted: #9b94b8;
  --accent: #a78bfa;
  --accent2: #7c5cf0;
  --ok: #4ade80;
  --warn: #fbbf24;
  --err: #f87171;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  display: flex;
  flex-direction: column;
  overscroll-behavior: none;
}
header {
  padding: 10px 14px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
header h1 { font-size: 17px; margin: 0; font-weight: 700; }
header h1 span { color: var(--accent); }
#provider-badge {
  margin-left: auto;
  font-size: 11px;
  color: var(--muted);
  background: var(--bg3);
  padding: 3px 8px;
  border-radius: 99px;
  white-space: nowrap;
}
main { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.tab-page { display: none; padding: 14px; max-width: 760px; margin: 0 auto; width: 100%; }
.tab-page.active { display: block; }
nav {
  display: flex;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  padding-bottom: env(safe-area-inset-bottom);
}
nav button {
  flex: 1;
  background: none;
  border: none;
  color: var(--muted);
  padding: 9px 0 7px;
  font-size: 10px;
  min-width: 0;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
nav button .ico { font-size: 19px; line-height: 1; }
nav button.active { color: var(--accent); }
h2 { font-size: 16px; margin: 4px 0 12px; }
h3 { font-size: 14px; margin: 18px 0 8px; color: var(--accent); }
label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 4px; font-weight: 600; }
label .hint { font-weight: 400; }
input[type=text], input[type=password], input[type=number], textarea, select {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
}
textarea { resize: vertical; min-height: 70px; }
textarea.tall { min-height: 120px; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent2); }
button.btn {
  background: var(--accent2);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 11px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
button.btn:disabled { opacity: 0.5; }
button.btn.secondary { background: var(--bg3); color: var(--text); border: 1px solid var(--border); }
button.btn.small { padding: 7px 12px; font-size: 12px; border-radius: 9px; }
button.btn.danger { background: none; border: 1px solid var(--err); color: var(--err); }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.row > * { flex: 1; min-width: 130px; }
.row > .no-grow { flex: 0; min-width: auto; }
.card-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 12px;
}
.muted { color: var(--muted); font-size: 12px; line-height: 1.5; }
/* Chat (Interview) */
#chat-log { display: flex; flex-direction: column; gap: 10px; padding-bottom: 8px; }
.msg { max-width: 88%; padding: 10px 13px; border-radius: 14px; white-space: pre-wrap; line-height: 1.45; font-size: 14px; }
.msg.user { align-self: flex-end; background: var(--accent2); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--bg3); border-bottom-left-radius: 4px; }
.msg.thinking { color: var(--muted); font-style: italic; }
#chat-input-row { display: flex; gap: 8px; margin-top: 10px; align-items: flex-end; }
#chat-input { flex: 1; min-height: 44px; max-height: 140px; }
#interview-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
/* Avatar */
#avatar-wrap { display: flex; gap: 14px; align-items: flex-start; }
#avatar-preview, #gen-image-preview {
  width: 130px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg3);
  display: block;
}
#gen-image-preview { width: 100%; max-width: 380px; margin-top: 10px; }
.list-item { background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; margin-bottom: 8px; }
.list-item textarea, .list-item input { background: var(--bg2); }
.list-item .li-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 4px; }
.list-item .li-head span { font-size: 12px; color: var(--muted); font-weight: 600; }
.status { font-size: 12px; margin-top: 8px; min-height: 16px; }
.status.ok { color: var(--ok); }
.status.err { color: var(--err); white-space: pre-wrap; }
.status.busy { color: var(--warn); }
details { margin-top: 12px; }
summary { cursor: pointer; color: var(--accent); font-size: 13px; font-weight: 600; padding: 6px 0; }
.spin { display: inline-block; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.pill-ok { color: var(--ok); }
.pill-missing { color: var(--err); }
a { color: var(--accent); }
footer-spacer { display: block; height: 30px; }
/* Story */
.msg.prose { white-space: normal; max-width: 96%; align-self: stretch; }
.msg.prose p { margin: 0 0 0.7em; }
.msg.prose p:last-child { margin-bottom: 0; }
.msg.prose em { color: var(--accent); }
.msg-actions { display: flex; gap: 6px; flex-wrap: wrap; align-self: flex-start; }
.msg-actions.right { align-self: flex-end; }
.msg-edit textarea { background: var(--bg2); }
.choice-btn {
  display: block; width: 100%; text-align: left;
  background: var(--bg3); border: 1px solid var(--accent2); color: var(--text);
  border-radius: var(--radius); padding: 10px 12px; font-size: 13px;
  cursor: pointer; margin-top: 8px; font-family: inherit; line-height: 1.4;
}
.continuity-box {
  background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; font-size: 12px; line-height: 1.5;
}
.continuity-box.ok { border-color: var(--ok); }
.continuity-box.bad { border-color: var(--warn); }
.continuity-box ul { margin: 6px 0; padding-left: 18px; }
#btn-story-stop { background: var(--err); }
#story-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
#story-title { font-weight: 700; font-size: 16px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#story-log { display: flex; flex-direction: column; gap: 10px; padding-bottom: 8px; margin-top: 10px; }
#story-input-row { display: flex; gap: 8px; margin-top: 10px; align-items: flex-end; }
#story-input { flex: 1; min-height: 44px; max-height: 140px; }
.story-meta { font-size: 11px; color: var(--muted); font-weight: 400; }
#story-mismatch { color: var(--warn); font-size: 12px; margin-bottom: 8px; }
.check-row label { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); font-weight: 400; margin: 10px 0 0; }
/* Arcs */
.arc-item { border-left: 3px solid var(--accent2); }
.arc-item.secret { border-left-color: var(--warn); }
.arc-hidden {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg3); border: 1px dashed var(--warn); border-radius: var(--radius);
  padding: 10px; margin-bottom: 8px; font-size: 13px;
}
/* Bibliotheken */
.lib-bar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.lib-bar select { flex: 1; min-width: 150px; }
/* Login */
#login-overlay {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
#login-box { width: min(340px, 90vw); }
#login-box h1 { font-size: 22px; text-align: center; margin-bottom: 18px; }
#login-box h1 span { color: var(--accent); }
[hidden] { display: none !important; }
