:root {
  --bg: #15121c;
  --panel: #1c1826;
  --panel-2: #241f31;
  --line: #2f293f;
  --text: #ece7f3;
  --muted: #9a92ad;
  --gold: #e8b86d;
  --gold-ink: #2a1d08;
  --danger: #e2727f;
  --story: Georgia, 'Iowan Old Style', 'Palatino Linotype', serif;
  --ui: system-ui, 'Segoe UI', Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 var(--ui); overflow: hidden; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; border-radius: 8px; }
h1, h2, h3, h4, p { margin: 0; }
.muted { color: var(--muted); font-weight: 400; }
.error { color: var(--danger); }
.logo { color: var(--gold); }
code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }

input, textarea, select {
  width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--gold); }
textarea { resize: vertical; }
label, .label { display: block; font-size: 13px; color: var(--muted); margin-top: 12px; }
label > input, label > textarea, label > select { margin-top: 4px; color: var(--text); font-size: 15px; }

.primary { background: var(--gold); color: var(--gold-ink); font-weight: 600; padding: 8px 16px; }
.primary:hover { filter: brightness(1.08); }
.ghost { border: 1px solid var(--line); padding: 7px 12px; color: var(--text); text-decoration: none; }
.ghost:hover { border-color: var(--muted); }
.danger { color: var(--danger); border: 1px solid transparent; padding: 7px 12px; }
.danger:hover { border-color: var(--danger); }
.link { color: var(--muted); text-decoration: underline; padding: 0; font-size: 13px; }
.icon { width: 38px; height: 38px; font-size: 18px; display: inline-grid; place-items: center; flex: none; color: var(--muted); }
.icon:hover { background: var(--panel-2); color: var(--text); }
.icon.small { width: 26px; height: 26px; font-size: 13px; }

/* ── Anmeldung ── */
#login { height: 100%; display: grid; place-items: center; padding: 16px; background: radial-gradient(ellipse at 50% 20%, #2a2140, var(--bg) 70%); }
.login-card { width: min(360px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; text-align: center; }
.login-card .logo { font-size: 34px; }
.login-card h1 { font: 600 26px var(--story); letter-spacing: .5px; }
.login-card label { text-align: left; }
.login-card .primary { width: 100%; margin-top: 18px; padding: 10px; }
.login-card .error { margin-top: 10px; font-size: 14px; }

/* ── Aufbau ── */
#app { height: 100%; display: grid; grid-template-columns: 270px 1fr; }
#side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.brand { font: 600 19px var(--story); padding: 16px 16px 8px; letter-spacing: .5px; }
#side section { padding: 8px; min-height: 0; display: flex; flex-direction: column; }
#side section.grow { flex: 1; }
#side h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); padding: 4px 8px; display: flex; align-items: center; justify-content: space-between; }
#side h2 .icon { width: 26px; height: 26px; font-size: 15px; }
#side ul { list-style: none; margin: 0; padding: 0; overflow-y: auto; }
#side li { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; cursor: pointer; }
#side li:hover { background: var(--panel-2); }
#side li.active { background: var(--panel-2); box-shadow: inset 3px 0 var(--gold); }
#side li .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#side li .icon { visibility: hidden; }
#side li:hover .icon { visibility: visible; }
#side li.hint { color: var(--muted); font-size: 13px; cursor: default; }
#side footer { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#online { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 13px; }
.dot::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #6fd38a; margin-right: 5px; }
#shade { display: none; }

main { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100%; isolation: isolate; }
#backdrop { position: absolute; inset: 0; z-index: -1; background-size: cover; background-position: center; opacity: 0; transition: opacity .6s; }
#backdrop.on { opacity: .3; }
#backdrop::after { content: ''; position: absolute; inset: 0; background: linear-gradient(to bottom, rgba(21, 18, 28, .55), rgba(21, 18, 28, .9)); }

#scene { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: rgba(28, 24, 38, .8); backdrop-filter: blur(8px); }
.scene-text { flex: 1; min-width: 0; }
#storyName { font: 600 17px var(--story); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#sceneLine { font-size: 13px; color: var(--gold); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#sceneLine:empty { display: none; }
#menuBtn { display: none; }

/* ── Verlauf ── */
#log { flex: 1; overflow-y: auto; padding: 16px max(16px, calc((100% - 820px) / 2)); display: flex; flex-direction: column; gap: 10px; scroll-behavior: smooth; }
#log > * { flex: none; }
.empty { margin: auto; text-align: center; }
.empty .logo { font-size: 40px; }
.empty p:first-of-type { font: 20px var(--story); }
.day { align-self: center; font-size: 12px; color: var(--muted); padding: 2px 12px; border: 1px solid var(--line); border-radius: 99px; background: var(--bg); margin: 6px 0; }

.msg { position: relative; }
.msg.new { animation: rise .25s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.msg .tools { display: inline-flex; opacity: 0; transition: opacity .15s; }
.msg:hover .tools, .msg:focus-within .tools { opacity: 1; }
.time { font-size: 12px; color: var(--muted); }
.text { overflow-wrap: anywhere; }
.text em { color: #cfc6e2; }
.aside { color: var(--muted); font-size: .92em; }
.badge { font-size: 10px; font-weight: 700; letter-spacing: .5px; color: var(--gold); border: 1px solid var(--gold); border-radius: 4px; padding: 0 4px; }
.pic { display: block; max-width: min(100%, 420px); max-height: 420px; border-radius: 10px; margin-top: 6px; cursor: zoom-in; }

.avatar { --s: 46px; width: var(--s); height: var(--s); border-radius: 50%; flex: none; display: inline-grid; place-items: center; overflow: hidden; background: color-mix(in srgb, var(--c) 30%, var(--panel-2)); color: var(--c); font-weight: 700; font-size: calc(var(--s) * .45); box-shadow: 0 0 0 2px var(--c); }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.small { --s: 28px; box-shadow: 0 0 0 1.5px var(--c); }
.avatar.tiny { --s: 22px; box-shadow: none; }
.avatar.big { --s: 96px; border-radius: 16px; box-shadow: none; border: 1px dashed var(--line); color: var(--muted); font-size: 13px; font-weight: 400; background: var(--bg); }

.say { display: flex; gap: 12px; align-items: flex-start; }
.say .avatar-wrap { cursor: zoom-in; margin-top: 2px; }
.say .bubble { min-width: 0; background: rgba(36, 31, 49, .85); border: 1px solid var(--line); border-left: 3px solid var(--c); border-radius: 4px 14px 14px 14px; padding: 8px 14px 10px; }
.say .meta { display: flex; align-items: center; gap: 8px; min-height: 26px; }
.say .who { font-weight: 700; color: var(--c); }
.say .mood { font-size: 12px; color: var(--muted); font-style: italic; }
.say .text { font: 16px/1.6 var(--story); }

.narr { align-self: center; max-width: 640px; width: 100%; text-align: center; padding: 10px 18px; }
.narr .text { font: italic 17px/1.7 var(--story); color: #e2d8c6; }
.narr .text em { color: inherit; font-style: normal; }
.narr::before, .narr::after { content: '✦'; display: block; color: var(--gold); opacity: .6; font-size: 11px; }
.narr .pic { margin: 8px auto 0; }
.narr .meta { display: inline-flex; align-items: center; gap: 8px; min-height: 26px; margin-top: 2px; }

.ooc { align-self: flex-start; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; font-size: 13px; color: var(--muted); padding: 3px 12px; border: 1px dashed var(--line); border-radius: 99px; max-width: 100%; }
.ooc .who { font-weight: 600; }
.ooc .pic { max-height: 160px; }

.dice { align-self: center; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 6px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.dice .total { font: 700 22px var(--story); color: var(--gold); min-width: 30px; text-align: center; }

.scene-card { border-radius: 14px; overflow: hidden; background: var(--panel-2) center/cover; border: 1px solid var(--line); margin: 6px 0; }
.scene-card .scene-inner { padding: 18px 20px; }
.scene-card.has-img .scene-inner { padding-top: 150px; background: linear-gradient(to bottom, transparent, rgba(15, 12, 22, .92) 75%); cursor: zoom-in; }
.scene-card .eyebrow { font-size: 11px; letter-spacing: 2px; text-transform: uppercase; color: var(--gold); }
.scene-card h4 { font: 600 22px var(--story); }
.scene-card .text { font: 15px/1.6 var(--story); color: #d8d0e6; margin-top: 4px; }
.scene-card .tools { position: absolute; top: 8px; right: 8px; background: rgba(15, 12, 22, .7); border-radius: 8px; }

.editor { margin-top: 6px; text-align: left; }
.rowbtn { display: flex; gap: 8px; margin-top: 8px; }
.editor .rowbtn { justify-content: flex-end; }

#typing { height: 22px; padding: 0 max(16px, calc((100% - 820px) / 2)); font-size: 13px; color: var(--muted); font-style: italic; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Schreibfeld ── */
#composer { position: relative; border-top: 1px solid var(--line); background: rgba(28, 24, 38, .9); backdrop-filter: blur(8px); padding: 8px max(12px, calc((100% - 844px) / 2)) max(10px, env(safe-area-inset-bottom)); }
#speakers, #moods { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: thin; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 12px 3px 4px; border-radius: 99px; border: 1px solid var(--line); white-space: nowrap; color: var(--muted); flex: none; min-height: 30px; }
.chip .glyph { width: 22px; text-align: center; }
.chip:hover { border-color: var(--muted); }
.chip.active { border-color: var(--c); color: var(--text); background: color-mix(in srgb, var(--c) 18%, transparent); }
.mood-pick { display: inline-flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px 6px; border-radius: 10px; font-size: 11px; color: var(--muted); flex: none; border: 1px solid transparent; }
.mood-pick:hover { background: var(--panel-2); }
.mood-pick.active { border-color: var(--gold); color: var(--text); }
.mood-pick .avatar { --s: 38px; }
#composer .row { display: flex; align-items: flex-end; gap: 4px; }
#text { flex: 1; resize: none; min-height: 42px; max-height: 180px; font: 16px/1.5 var(--story); padding: 8px 12px; border-radius: 12px; }
.send { width: 42px; height: 40px; padding: 0; font-size: 16px; border-radius: 12px; flex: none; }
#kiBtn.busy { animation: pulse 1s infinite alternate; color: var(--gold); }
@keyframes pulse { to { opacity: .35; } }
#attachPreview { display: flex; align-items: flex-start; gap: 4px; padding-bottom: 6px; }
#attachPreview img { height: 70px; border-radius: 8px; }
#dicePop { position: absolute; bottom: calc(100% + 6px); left: max(12px, calc((100% - 844px) / 2)); display: flex; flex-wrap: wrap; align-items: center; gap: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px; box-shadow: 0 8px 30px rgba(0, 0, 0, .5); max-width: calc(100% - 24px); }
#dicePop .muted { font-size: 12px; width: 100%; }

/* ── Fenster ── */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 16px; padding: 22px; width: min(480px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); }
dialog::backdrop { background: rgba(8, 6, 12, .7); backdrop-filter: blur(3px); }
dialog h3 { font: 600 20px var(--story); margin-bottom: 4px; }
dialog menu { display: flex; align-items: center; gap: 8px; padding: 0; margin: 20px 0 0; }
.spacer { flex: 1; }
#askInput { margin-top: 12px; }
.char-head { display: flex; gap: 16px; align-items: flex-start; margin-top: 8px; }
.char-head .fields { flex: 1; }
.char-head label:first-child { margin-top: 0; }
label.inline { display: flex; align-items: center; gap: 10px; }
label.inline input { width: 54px; height: 34px; padding: 2px; margin: 0; }
#charAvatar { cursor: pointer; }
#charMoods { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px; margin: 6px 0 8px; }
.mood-row { display: flex; align-items: center; gap: 6px; }
.mood-row img { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; cursor: zoom-in; flex: none; }
.mood-row input { padding: 5px 8px; font-size: 14px; }
.scene-preview { height: 130px; border-radius: 10px; border: 1px dashed var(--line); background: var(--bg) center/cover; display: grid; place-items: center; color: var(--muted); margin-top: 4px; }

#lightbox { position: fixed; inset: 0; z-index: 50; background: rgba(8, 6, 12, .92); display: grid; place-items: center; cursor: zoom-out; padding: 16px; }
#lightbox img { max-width: 100%; max-height: calc(100dvh - 32px); border-radius: 10px; }
#toast { position: fixed; z-index: 60; left: 50%; bottom: 110px; transform: translateX(-50%); background: #3a2230; border: 1px solid var(--danger); color: var(--text); padding: 10px 16px; border-radius: 10px; max-width: calc(100vw - 32px); box-shadow: 0 8px 30px rgba(0, 0, 0, .5); }

/* ── Handy ── */
@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; }
  #side { position: fixed; z-index: 30; inset: 0 auto 0 0; width: min(290px, 85vw); transform: translateX(-100%); transition: transform .2s; }
  body.menu #side { transform: none; }
  body.menu #shade { display: block; position: fixed; inset: 0; z-index: 20; background: rgba(8, 6, 12, .6); }
  #menuBtn { display: inline-grid; }
  #side li .icon { visibility: visible; }
  .msg .tools { opacity: .6; }
  .avatar { --s: 38px; }
  .say { gap: 8px; }
  .say .bubble { padding: 6px 10px 8px; }
  #sceneEdit { padding: 7px 9px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
