/* LANTERN — deep-purple, candlelit dark theme (the default look). */
:root {
  --bg: #0e0a17;
  --panel: #191224;
  --panel-2: #241a35;
  --border: #302647;
  --text: #ece8f6;
  --muted: #9f96bb;
  --accent: #9a6cf5;
  --accent-2: #7a5cf0;
  --user: #5a4a95;
  --user-text: #f3eeff;
  --ai: #1d1630;
  --danger: #e5577a;
  --gold: #e8b06a;              /* candle-flame warmth for small touches */
  --radius: 14px;
  --brand-font: "Cinzel", Georgia, "Times New Roman", serif;
  --title-font: Georgia, "Times New Roman", serif;
  /* Scrim laid over a scene-background image so chat text stays readable. */
  --bg-scrim: rgba(14, 10, 23, .70);
}

/* Light theme — a parchment take on the same violet (data-theme="light"). */
:root[data-theme="light"] {
  --bg: #f3f0fa;
  --panel: #ffffff;
  --panel-2: #ece7f6;
  --border: #d9d1ea;
  --text: #241c33;
  --muted: #6a6286;
  --accent: #7a52e0;
  --accent-2: #6a4de0;
  --user: #e3d9fb;
  --user-text: #241c33;
  --ai: #ece7f6;
  --danger: #d23a63;
  --gold: #b9842f;
  --bg-scrim: rgba(243, 240, 250, .82);
}

/* "Auto" (no explicit data-theme) follows the OS: light palette when the OS
   prefers light; otherwise the base :root (dark) applies. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]):not([data-theme="light"]) {
    --bg: #f3f0fa;
    --panel: #ffffff;
    --panel-2: #ece7f6;
    --border: #d9d1ea;
    --text: #241c33;
    --muted: #6a6286;
    --accent: #7a52e0;
    --accent-2: #6a4de0;
    --user: #e3d9fb;
    --user-text: #241c33;
    --ai: #ece7f6;
    --danger: #d23a63;
    --gold: #b9842f;
    --bg-scrim: rgba(243, 240, 250, .82);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
}

.hidden { display: none !important; }

/* Story search + character auto-generate row */
.story-search {
  width: 100%; margin: 0 0 8px; padding: 6px 10px;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; font-size: 13px;
}
.gen-row { display: flex; gap: 8px; margin: 0 0 12px; }
.gen-row input {
  flex: 1; padding: 8px 10px; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
}
.gen-row button { white-space: nowrap; }

/* Story tag-filter bar (sidebar) */
.tag-bar { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 8px; }
.tag-chip {
  padding: 3px 10px; font-size: 12px; line-height: 1.4; border-radius: 20px;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--border);
}
.tag-chip:hover { border-color: var(--accent); color: var(--text); }
.tag-chip.active { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border-color: transparent; }

#app { display: grid; grid-template-columns: 300px 1fr; height: 100vh; }

/* ---------- Banner ---------- */
.banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 50;
  background: #4a2330; color: #ffd9e2; padding: 10px 16px;
  text-align: center; font-size: 14px; border-bottom: 1px solid var(--danger);
}
.banner code { background: rgba(0,0,0,.3); padding: 1px 6px; border-radius: 5px; }
.banner a { color: #fff; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  z-index: 200; background: #3a2230; color: #ffd9e2; border: 1px solid var(--danger);
  padding: 10px 18px; border-radius: 10px; font-size: 14px; max-width: 80vw;
  box-shadow: 0 6px 24px rgba(0,0,0,.4);
}

/* ---------- Sidebar ---------- */
#sidebar {
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px; gap: 10px; overflow-y: auto;
}
.brand { font-size: 18px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.section-label {
  font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
  margin-top: 8px; display: flex; align-items: center; justify-content: space-between;
}
.section-label span { display: flex; gap: 4px; }
.list { display: flex; flex-direction: column; gap: 4px; }

.list-item {
  display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: 9px;
  cursor: pointer; border: 1px solid transparent; color: var(--text);
}
.list-item:hover { background: var(--panel-2); }
.list-item.active { background: var(--panel-2); border-color: var(--accent); }
.list-item .emoji { font-size: 18px; flex: none; }
.list-item .meta { overflow: hidden; }
.list-item .title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .act { margin-left: auto; flex: none; opacity: 0; background: none; border: none; color: var(--muted); cursor: pointer; font-size: 14px; padding: 2px 4px; }
.list-item:hover .act { opacity: 1; }
.list-item .act:hover { color: var(--accent); }
.list-item .act.del:hover { color: var(--danger); }
/* A pinned item keeps its star lit even when the row isn't hovered. */
.list-item .act.pin.on { opacity: 1; color: var(--accent); }

.sidebar-footer { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.4; }

/* ---------- Fields ---------- */
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.field > span { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.field em { font-style: normal; opacity: .7; }
.field code { background: var(--panel-2); padding: 0 4px; border-radius: 4px; }
.row { display: flex; gap: 10px; }
select, input[type="text"], input[type="number"], textarea {
  width: 100%; background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font: inherit; font-size: 14px;
}
textarea { resize: vertical; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.token-badge { margin-left: auto; font-size: 12px; color: var(--muted); }
.token-badge.warn { color: var(--danger); }

details { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; }
details summary { cursor: pointer; color: var(--muted); font-size: 13px; }
details[open] { padding-bottom: 12px; }
details > .field, details > .row { margin-top: 10px; }

/* ---------- Buttons ---------- */
button { cursor: pointer; font: inherit; border-radius: 8px; border: 1px solid var(--border); padding: 8px 14px; background: var(--panel-2); color: var(--text); }
button:hover { border-color: var(--accent); }
button.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: none; color: #fff; font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.ghost { background: transparent; }
button.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
button.danger:hover { background: var(--danger); color: #fff; }
button.mini { padding: 2px 9px; font-size: 15px; line-height: 1; }
button:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Chat ---------- */
#chat-pane { display: flex; flex-direction: column; min-width: 0; }
#chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--panel); gap: 12px;
}
#chat-title { display: flex; align-items: center; gap: 10px; font-size: 17px; font-weight: 600; min-width: 0; }
#chat-title #active-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#active-avatar { font-size: 22px; }
.header-actions { display: flex; align-items: center; gap: 8px; flex: none; flex-wrap: wrap; justify-content: flex-end; }
.ctx-meter { font-size: 12px; color: var(--muted); background: var(--panel-2); padding: 4px 8px; border-radius: 6px; }
.ctx-meter.warn { color: #ffd9a0; }
.ctx-meter.over { color: var(--danger); }

.messages { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 14px; }
/* Scene background: a cover image (with a themed scrim composited on top, set
   inline in JS) fixed behind the scrolling messages. */
.messages.has-bg { background-size: cover; background-position: center; background-repeat: no-repeat; }

/* ---------- Home hub (dashboard landing) ---------- */
.hub { flex: 1; overflow-y: auto; padding: 28px 28px 40px; }
.hub-hero {
  background: var(--panel);
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 22%, var(--panel)), var(--panel));
  border: 1px solid var(--border); border-radius: 16px; padding: 26px 28px 22px; margin-bottom: 24px;
}
.hub-title { font-size: 28px; font-weight: 800; }
.hub-sub { color: var(--muted); margin-top: 4px; }
.hub-stats { display: flex; flex-wrap: wrap; gap: 26px; margin: 18px 0 20px; }
.hub-stats .stat { display: flex; flex-direction: column; }
.hub-stats .stat b { font-size: 22px; font-weight: 800; color: var(--accent); }
.hub-stats .stat span { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.hub-cta { display: flex; flex-wrap: wrap; gap: 10px; }
.hub-section { margin-bottom: 26px; }
.hub-h { display: flex; align-items: center; justify-content: space-between; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 12px; }
.hub-link { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 13px; padding: 2px 4px; }
.hub-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.hub-card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px; cursor: pointer; transition: transform .1s, border-color .1s; min-height: 92px; display: flex; flex-direction: column; gap: 4px; }
.hub-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.hub-card.pinned { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }
.hub-card .hc-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hub-card .hc-sub { font-size: 12px; color: var(--muted); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.hub-card .hc-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: auto; }
.hub-card .chip { font-size: 11px; color: var(--muted); background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 0 6px; }
.char-card .hc-av { font-size: 30px; margin-bottom: 2px; }
.char-card .hc-av img.av { width: 44px; height: 44px; border-radius: 10px; }
.add-card { align-items: center; justify-content: center; text-align: center; border-style: dashed; color: var(--muted); }
.add-card:hover { color: var(--accent); }
.add-card .hc-add { font-size: 30px; line-height: 1; }

.msg { max-width: 820px; width: fit-content; display: flex; gap: 12px; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg .who { font-size: 20px; flex: none; margin-top: 2px; }
.msg .col { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.msg .bubble { padding: 12px 16px; border-radius: var(--radius); line-height: 1.55; white-space: pre-wrap; word-wrap: break-word; }
.msg.user .bubble { background: var(--user); border-top-right-radius: 4px; }
.msg.ai .bubble { background: var(--ai); border: 1px solid var(--border); border-top-left-radius: 4px; }
.bubble em { color: var(--accent); font-style: italic; opacity: .95; }
.bubble .thought { color: var(--muted); font-style: italic; opacity: .72; }
.bubble.editing { outline: 2px solid var(--accent); }
.cursor::after { content: "▋"; animation: blink 1s steps(2) infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }

.msg-controls { display: flex; align-items: center; gap: 2px; opacity: 0; transition: opacity .12s; font-size: 13px; }
.msg:hover .msg-controls { opacity: 1; }
.msg.user .msg-controls { justify-content: flex-end; }
.msg-controls button { background: none; border: none; color: var(--muted); padding: 2px 6px; border-radius: 6px; }
.msg-controls button:hover { color: var(--accent); background: var(--panel-2); }
.swipe-nav { display: inline-flex; align-items: center; gap: 2px; color: var(--muted); }
.swipe-nav .count { font-size: 12px; min-width: 30px; text-align: center; }

/* Guided-regenerate inline note box (appears under a reply) */
.guide-row { display: flex; gap: 6px; margin-top: 6px; align-items: center; }
.guide-row .guide-input { flex: 1; font-size: 13px; padding: 6px 10px; }
.guide-row button { padding: 6px 12px; font-size: 13px; }

.empty-state { margin: auto; text-align: center; color: var(--muted); max-width: 400px; }
.empty-state .big { font-size: 56px; }
.empty-state h2 { color: var(--text); margin: 8px 0; }
.empty-state button { margin: 14px auto 6px; }
.empty-state kbd { background: var(--panel-2); border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px; font-size: 12px; }

#chat-header { flex-wrap: wrap; }

.msg .speaker { font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 2px; }

.group-bar { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 20px 0; background: var(--panel); }
.group-chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border: 1px solid var(--border); border-radius: 20px; cursor: pointer; font-size: 13px; background: var(--panel-2); }
.group-chip:hover { border-color: var(--accent); }
.group-chip img.av { width: 20px; height: 20px; border-radius: 50%; }
.group-pick { display: flex; flex-direction: column; gap: 6px; max-height: 50vh; overflow-y: auto; }
.group-pick label { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 9px; cursor: pointer; }
.group-pick label:hover { background: var(--panel-2); }
.group-pick input { width: auto; }
.group-pick .em { font-size: 20px; }
.group-pick img.av { width: 26px; height: 26px; }

.an-bar { padding: 8px 20px 0; background: var(--panel); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Relationship badge (lives in the author's-note bar) */
.rel-badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border: 1px solid var(--border); border-radius: 20px; background: var(--bg); color: var(--text); font-size: 13px; cursor: pointer; flex: 0 0 auto; max-width: 260px; }
.rel-badge:hover { border-color: var(--accent); }
.rel-badge .rel-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }
.rel-badge .rel-bar { width: 52px; height: 6px; border-radius: 3px; background: var(--panel-2); overflow: hidden; flex: none; }
.rel-badge .rel-fill { display: block; height: 100%; background: var(--accent); }
.rel-badge .rel-bar.cold .rel-fill { background: var(--accent-2); }
.rel-badge .rel-bar.warm .rel-fill { background: linear-gradient(90deg, var(--accent), var(--danger)); }
#rel-band { font-style: normal; opacity: .8; }
#rel-reason:empty { display: none; }
.an-bar input { background: var(--bg); border-color: var(--border); font-size: 13px; flex: 1; }
.an-bar select { width: auto; flex: 0 0 auto; background: var(--bg); font-size: 13px; }

.composer { display: flex; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--panel); }
.composer textarea { flex: 1; max-height: 160px; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal-card { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 24px; width: 580px; max-width: 100%; max-height: 92vh; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-card.wide { width: 760px; }
.modal-card h3 { margin: 0 0 4px; }
.modal-actions { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.modal-actions .spacer { flex: 1; }

/* ---------- Avatars ---------- */
img.av { width: 30px; height: 30px; border-radius: 8px; object-fit: cover; display: block; }
.msg .who img.av { width: 34px; height: 34px; }
.list-item .emoji img.av { width: 26px; height: 26px; border-radius: 6px; }
#active-avatar img.av, .header-actions img.av { width: 26px; height: 26px; }
.avatar-edit { display: flex; align-items: center; gap: 14px; }
.avatar-preview { width: 64px; height: 64px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; font-size: 34px; overflow: hidden; flex: none; }
.avatar-preview img { width: 100%; height: 100%; object-fit: cover; }
.avatar-actions { display: flex; flex-direction: column; gap: 6px; }

/* ---------- Scene background editor (settings drawer) ---------- */
.bg-edit { display: flex; align-items: center; gap: 14px; }
.bg-preview {
  width: 160px; height: 90px; border-radius: 10px; background: var(--panel-2);
  border: 1px solid var(--border); display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 12px; overflow: hidden; flex: none;
}
.bg-preview img { width: 100%; height: 100%; object-fit: cover; }
.bg-actions { display: flex; flex-direction: column; gap: 6px; }

/* ---------- Memories ---------- */
.mem-section { display: flex; flex-direction: column; gap: 8px; }
.mem-head { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-top: 4px; }
.mem-list { display: flex; flex-direction: column; gap: 6px; max-height: 30vh; overflow-y: auto; }
.mem-row { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 9px; background: var(--panel-2); }
.mem-row.pinned { border-color: var(--accent); }
.mem-text { flex: 1; min-width: 0; line-height: 1.4; }
.mem-edit { flex: 1; }
.mem-auto { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); border: 1px solid var(--border); border-radius: 6px; padding: 1px 5px; flex: none; }
.mem-acts { display: flex; gap: 2px; flex: none; margin-left: auto; }
.mem-acts .act { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 14px; padding: 2px 5px; border-radius: 6px; }
.mem-acts .act:hover { color: var(--accent); background: var(--panel); }
.mem-acts .act.del:hover { color: var(--danger); }
.mem-acts .act.pin.on { color: var(--accent); }

/* ---------- Objectives ---------- */
.obj-status { background: none; border: none; cursor: pointer; font-size: 16px; padding: 0 2px; flex: none; line-height: 1; }
.mem-row.obj-done .obj-text { text-decoration: line-through; opacity: .7; }
.mem-row.obj-failed .obj-text { text-decoration: line-through; opacity: .55; color: var(--danger); }
.mem-row.obj-done { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }

/* ---------- Greeting chooser ---------- */
.greet-option { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 8px; cursor: pointer; line-height: 1.5; }
.greet-option:hover { border-color: var(--accent); background: var(--panel-2); }
.greet-option .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 4px; }

/* ---------- Lorebook entries ---------- */
.lore-entry { border: 1px solid var(--border); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.lore-entry .lore-head { display: flex; gap: 8px; align-items: center; }
.lore-entry .lore-head input { flex: 1; }
.lore-entry .opts { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; font-size: 12px; color: var(--muted); }
.lore-entry label.inline { display: flex; align-items: center; gap: 5px; }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  /* Stack the sidebar above the chat instead of overlaying it (no toggle needed). */
  #app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  #sidebar { max-height: 42vh; border-right: none; border-bottom: 1px solid var(--border); }
  .msg { max-width: 100%; }
}

/* ======================= LANTERN look ======================= */
body {
  background:
    radial-gradient(1100px 560px at 82% -12%, rgba(154,108,245,.10), transparent 62%),
    radial-gradient(820px 460px at -8% 112%, rgba(154,108,245,.08), transparent 60%),
    var(--bg);
}
/* Narrower desktop sidebar — but only above the mobile breakpoint, so this
   doesn't re-introduce two columns and override the stacked layout at ≤820px. */
@media (min-width: 821px) { #app { grid-template-columns: 264px 1fr; } }

/* Brand + sidebar */
.brand { gap: 10px; font-family: var(--brand-font); font-weight: 700; letter-spacing: .14em; margin-bottom: 4px; }
.brand-logo { display: inline-flex; width: 26px; height: 26px; color: var(--accent); filter: drop-shadow(0 0 7px rgba(154,108,245,.55)); }
.brand-logo svg { width: 100%; height: 100%; }
.brand-name { font-size: 17px; }
#sidebar { background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 7%, var(--panel)), var(--panel)); }

/* AI status chip */
.ai-status { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 11px; background: var(--panel-2); margin-bottom: 8px; }
.ai-status .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.ai-status.online .dot { background: #54d08a; box-shadow: 0 0 9px rgba(84,208,138,.75); }
.ai-status.offline .dot { background: var(--danger); }
.ai-status-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.ai-status-text b { font-size: 13px; }
.ai-status-text span { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Serif headings */
.modal-card h3, .empty-state h2 { font-family: var(--title-font); }

/* ---- Hub ---- */
.hub { padding: 0 0 40px; }
.hub-hero {
  position: relative; overflow: hidden; text-align: center;
  border: none; border-bottom: 1px solid var(--border); border-radius: 0;
  margin: 0 0 26px; padding: 56px 28px 40px;
  background:
    radial-gradient(760px 300px at 50% -36%, rgba(154,108,245,.30), transparent 70%),
    linear-gradient(180deg, color-mix(in srgb, var(--accent) 13%, var(--panel)), var(--bg));
}
.hub-title { font-family: var(--brand-font); font-weight: 700; letter-spacing: .2em; font-size: 46px; text-shadow: 0 0 26px rgba(154,108,245,.5); }
.hub-sub { font-family: var(--title-font); font-style: italic; font-size: 17px; margin-top: 8px; }
.hub-stats { justify-content: center; gap: 42px; margin: 24px 0 0; }
.hub-stats .stat { flex-direction: row; align-items: center; gap: 8px; }
.hub-stats .stat .si { font-size: 17px; filter: grayscale(.15); }
.hub-stats .stat b { font-size: 24px; color: var(--text); }
.hub-stats .stat span:last-child { font-size: 13px; text-transform: none; letter-spacing: 0; color: var(--muted); }
.hub > .hub-section { padding: 0 28px; }
.hub-h { font-family: var(--title-font); font-size: 22px; text-transform: none; letter-spacing: 0; color: var(--text); margin-bottom: 14px; }
.hub-link { color: var(--accent); font-weight: 600; }
.hub-grid { grid-template-columns: repeat(auto-fill, minmax(234px, 1fr)); gap: 16px; }

/* Story cards with scene art */
.story-card { position: relative; overflow: hidden; min-height: 196px; padding: 0; justify-content: flex-end; gap: 0; }
.story-card .sc-art { position: absolute; inset: 0; background-size: cover; background-position: center; }
.story-card .sc-art::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, transparent 18%, rgba(10,7,18,.5) 52%, rgba(10,7,18,.94)); }
.story-card .sc-body { position: relative; padding: 14px; display: flex; flex-direction: column; gap: 6px; }
.story-card .hc-title { font-family: var(--title-font); font-size: 17px; white-space: normal; color: #f3eeff; }
.story-card .sc-meta { font-size: 12px; color: #d2c9ea; display: flex; align-items: center; gap: 12px; }
.story-card .sc-continue { align-self: flex-start; margin-top: 6px; padding: 6px 14px; font-size: 13px; }

/* Character tiles */
.char-card { align-items: center; text-align: center; padding: 18px 14px; gap: 2px; }
.char-card .hc-av { margin: 0 auto 10px; font-size: 42px; }
.char-card .hc-av, .char-card .hc-av img.av { width: 84px; height: 84px; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.char-card .hc-av img.av { object-fit: cover; box-shadow: 0 0 0 2px var(--accent), 0 0 18px rgba(154,108,245,.4); }
.char-card .hc-title { font-family: var(--title-font); font-size: 18px; white-space: normal; }
.char-card .hc-sub { -webkit-line-clamp: 2; }
.add-card { align-items: center; justify-content: center; border-style: dashed; }
.add-card .hc-add { width: 54px; height: 54px; border-radius: 50%; background: color-mix(in srgb, var(--accent) 20%, transparent); color: var(--accent); display: flex; align-items: center; justify-content: center; font-size: 28px; margin: 4px auto 8px; }

/* Chat header */
.header-actions .ghost { border-radius: 10px; }
#chat-title { align-items: center; }
.chat-title-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
#active-name { font-family: var(--title-font); font-size: 19px; }
.active-sub { font-size: 12px; color: var(--muted); font-style: italic; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 42ch; }

/* Chat bubbles */
.msg .bubble { border-radius: 16px; }
.msg.user .bubble { background: var(--user); color: var(--user-text); border-top-right-radius: 5px; border: none; }
.msg.ai .bubble { background: var(--ai); border: 1px solid var(--border); border-top-left-radius: 5px; }
.msg.ai .bubble em { color: #c9b6ff; }
.msg .who img.av { box-shadow: 0 0 0 2px var(--accent); border-radius: 50%; }

/* Composer */
.composer { padding: 14px 20px 18px; }
.composer textarea { background: var(--panel-2); border: 1px solid var(--border); border-radius: 14px; }
#send-btn { border-radius: 12px; }

/* Hub hero banner image */
.hub-hero.has-img { background-size: cover; background-position: center; }
.hub-hero.has-img .hub-title, .hub-hero.has-img .hub-sub,
.hub-hero.has-img .hub-stats .stat b, .hub-hero.has-img .hub-stats .stat span:last-child { color: #fff; }
.hero-edit { position: absolute; top: 12px; right: 14px; background: rgba(0,0,0,.4); border: 1px solid var(--border); color: #fff; border-radius: 10px; padding: 4px 9px; font-size: 14px; opacity: .5; cursor: pointer; }
.hero-edit:hover { opacity: 1; border-color: var(--accent); }

/* Accounts (Phase 1 M1): login/signup overlay + sidebar account bar */
.auth-overlay { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(900px 520px at 50% -10%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 70%), var(--bg); padding: 20px; }
.auth-overlay.hidden { display: none; }
.auth-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 18px; padding: 28px 24px; box-shadow: 0 24px 60px rgba(0,0,0,.5); }
.auth-brand { font-family: var(--brand-font, Georgia); letter-spacing: .18em; font-size: 20px; text-align: center; color: var(--gold); }
.auth-card h2 { margin: 0 0 4px; font-family: var(--title-font, Georgia); font-weight: 600; font-size: 20px; text-align: center; }
.auth-card input[type=text], .auth-card input[type=password] { width: 100%; padding: 11px 13px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text); font-size: 15px; box-sizing: border-box; }
.auth-age { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin-top: 8px; }
.auth-age input { width: auto; }
#auth-signup-only { display: flex; flex-direction: column; gap: 12px; }
.auth-error { color: #ff8a8a; font-size: 13px; min-height: 16px; text-align: center; }
.auth-submit { padding: 11px; border-radius: 12px; border: none; background: var(--accent); color: #fff; font-size: 15px; font-weight: 600; cursor: pointer; }
.auth-submit:hover { filter: brightness(1.08); }
.auth-toggle { text-align: center; font-size: 13px; color: var(--muted); text-decoration: none; }
.auth-toggle:hover { color: var(--accent); }
.account-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 0 12px; padding: 6px 10px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; font-size: 12px; }
.account-bar.hidden { display: none; }
.account-who { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-actions { display: flex; gap: 4px; flex: 0 0 auto; }

/* Admin dashboard (Phase 1 M2) */
.admin-section { margin-bottom: 18px; }
.admin-sec-head { display: flex; align-items: center; justify-content: space-between; }
.admin-section h4 { margin: 0 0 8px; font-size: 14px; color: var(--muted); }
.admin-list { display: flex; flex-direction: column; gap: 6px; max-height: 240px; overflow-y: auto; }
.admin-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; }
.admin-row.suspended { opacity: .6; }
.admin-row-main b { font-size: 14px; }
.admin-row-sub { color: var(--muted); font-size: 12px; }
.admin-row-acts { display: flex; gap: 4px; flex: 0 0 auto; }
.tag { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; padding: 1px 6px; border-radius: 6px;
  background: color-mix(in srgb, var(--accent) 25%, transparent); color: var(--accent); }
.tag.warn { background: color-mix(in srgb, #e8706a 28%, transparent); color: #ff9a92; }
.admin-peek { margin-top: 4px; padding: 10px 12px; background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; }
.admin-peek-head { display: flex; align-items: center; justify-content: space-between; font-weight: 600; margin-bottom: 6px; }
.admin-peek-list { margin: 6px 0 0; padding-left: 18px; font-size: 13px; }
