  :root {
    --bg: #0d1117;
    --bg-soft: #11161d;
    --panel: #161b22;
    --panel-2: #1c2230;
    --line: #2d333b99;
    --ink: #e6edf3;
    --ink-dim: #9eb1c2;
    /* #778494 failed WCAG AA (4.17:1 on panel-2) at the 10-12px sizes it is used;
       #93a1b0 measures 6.03:1 on the worst surface. */
    --muted: #93a1b0;
    --gold: #58a6ff;
    --gold-soft: #58a6ff1c;
    --violet: #8b5cf6;
    --red: #e5484d;
    --r: 12px;
    --r-sm: 8px;
    --shadow: 0 8px 28px rgba(0,0,0,.35);
    /* Spacing scale (0.25rem grid): one rhythm for the whole sidebar. */
    --sp-1: .25rem; --sp-2: .5rem; --sp-3: .75rem; --sp-4: 1rem;
    /* Type scale: 5 steps instead of a dozen ad-hoc sizes. */
    --fs-2xs: .66rem; --fs-xs: .76rem; --fs-sm: .85rem; --fs-md: .95rem; --fs-lg: 1rem;
    --red-soft: #e5484d1c;
    --line-strong: #3d4756;
    /* Theme tokens (Footer-Picker, :root = "Dunkel"): surfaces + the formerly
       hardcoded pastel foregrounds. Translucent accent/status TINTS stay literal
       on purpose, they read fine over every theme's surfaces. */
    --btn-ink: #081424;               /* text on solid accent buttons */
    --bg-grad: #152030;               /* body radial-gradient highlight */
    --scroll-thumb: #2d333b;
    --head-bg: #11161d66;             /* translucent chat header (blur backdrop) */
    --bubble-1: #1b2940; --bubble-2: #18233a; --bubble-line: #58a6ff22;
    --code-bg: #00000055; --pre-bg: #0a0e14;
    --bar-track: #ffffff1a;           /* budget bar track */
    --accent-tint: #58a6ff33; --accent-ring: #58a6ff55; /* avatar border / active-item ring */
    --ok: #3fb950; --warn: #d29922;   /* status foregrounds (chips, previews, bars) */
    --info-ink: #9ec5fe; --red-ink: #f3a3a5; --violet-ink: #c4b5fd; /* pastel-on-tint text */
  }
  /* "Hell": neutral light UI, same accent family as the dark default. */
  [data-theme="light"] {
    --bg: #eef1f5; --bg-soft: #f7f9fb; --panel: #ffffff; --panel-2: #e9edf2;
    --line: #cdd5dd; --line-strong: #9fadbb;
    --ink: #1f2328; --ink-dim: #46535e; --muted: #57606a;
    --gold: #0b63ce; --gold-soft: #0b63ce14;
    --violet: #6d28d9; --red: #c5303a; --red-soft: #c5303a14;
    --shadow: 0 8px 28px rgba(31,35,40,.14);
    --btn-ink: #ffffff; --bg-grad: #dfe7f1; --scroll-thumb: #c3ccd6; --head-bg: #f7f9fbcc;
    --bubble-1: #dbe7f8; --bubble-2: #e4edfa; --bubble-line: #0b63ce2b;
    --code-bg: #afb8c12e; --pre-bg: #f2f4f7; --bar-track: #00000014;
    --accent-tint: #0b63ce29; --accent-ring: #0b63ce59;
    /* ok measured on the worst surface (35% green tint of the active fog segment):
       #1a7f37 hit only 2.98:1 there, #0d5423 clears 5.3:1. */
    --ok: #0d5423; --warn: #9a6700;
    --info-ink: #0b63ce; --red-ink: #c5303a; --violet-ink: #6d28d9;
  }
  /* "DSA": Pergament, Tinte und das tiefe Regelwerk-Rot als Akzent. */
  [data-theme="dsa"] {
    --bg: #eadfc4; --bg-soft: #f3ead3; --panel: #f7efdc; --panel-2: #e6d9ba;
    --line: #a9946866; --line-strong: #8f7c54;
    --ink: #2f2517; --ink-dim: #594930; --muted: #6a5a3e;
    --gold: #8e1f1f; --gold-soft: #8e1f1f14;
    --violet: #5b21b6; --red: #b3261e; --red-soft: #b3261e14;
    --shadow: 0 8px 28px rgba(74,52,17,.2);
    --btn-ink: #f7efdc; --bg-grad: #f4ead1; --scroll-thumb: #bda87c; --head-bg: #f3ead3b3;
    --bubble-1: #e8dab5; --bubble-2: #eee1c3; --bubble-line: #8e1f1f26;
    --code-bg: #8f7c5426; --pre-bg: #efe4c9; --bar-track: #00000014;
    --accent-tint: #8e1f1f29; --accent-ring: #8e1f1f52;
    /* ok measured on the worst surface (35% green tint of the active fog segment):
       #33691e hit only 3.46:1 there, #224511 clears 5.7:1. */
    --ok: #224511; --warn: #7a5c10;
    --info-ink: #1d5c9e; --red-ink: #a4262c; --violet-ink: #5b21b6;
  }
  * { box-sizing: border-box; }
  html, body { height: 100%; }
  body {
    margin: 0; background: radial-gradient(1200px 700px at 70% -10%, var(--bg-grad) 0%, var(--bg) 55%);
    color: var(--ink); font: 15px/1.55 ui-sans-serif, system-ui, "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
  }
  ::-webkit-scrollbar { width: 10px; height: 10px; }
  ::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
  ::-webkit-scrollbar-track { background: transparent; }

  button {
    font: inherit; border: 0; border-radius: 9px; padding: .5rem .9rem; cursor: pointer;
    background: var(--gold); color: var(--btn-ink); font-weight: 650; letter-spacing: .01em;
    transition: filter .15s, transform .05s;
  }
  button:hover { filter: brightness(1.08); }
  button:active { transform: translateY(1px); }
  button.ghost { background: transparent; color: var(--ink-dim); border: 1px solid var(--line); font-weight: 500; }
  button.ghost:hover { color: var(--ink); border-color: var(--line-strong); }
  button.ghost.danger { color: var(--red); border-color: var(--red-soft); }
  button.ghost.danger:hover { color: var(--red); border-color: var(--red); background: var(--red-soft); }
  button.danger { background: transparent; color: var(--red); border: 1px solid transparent; padding: .25rem .45rem; }
  button:disabled { opacity: .45; cursor: default; }
  /* Neutral square icon-button: the one vocabulary for row/header glyph actions.
     Replaces the old danger-misuse + inline color styles. .danger only tints on hover. */
  .iconbtn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 1.75rem; height: 1.75rem; flex: none; padding: 0;
    border: 1px solid transparent; border-radius: var(--r-sm);
    background: transparent; color: var(--muted); font-weight: 500;
    font-size: var(--fs-sm); line-height: 1; cursor: pointer;
    transition: background .12s, color .12s, border-color .12s;
  }
  .iconbtn:hover { background: var(--panel); color: var(--ink); }
  .iconbtn:active { transform: translateY(1px); }
  .iconbtn.danger:hover { background: var(--red-soft); color: var(--red); }
  .iconbtn:disabled { opacity: .4; cursor: default; }
  .iconbtn:disabled:hover { background: transparent; color: var(--muted); }
  input, select, textarea {
    font: inherit; color: var(--ink); background: var(--bg-soft);
    border: 1px solid var(--line); border-radius: 9px; padding: .5rem .65rem; width: 100%;
    transition: border-color .15s;
  }
  input:focus, select:focus, textarea:focus { outline: none; border-color: var(--gold); }
  /* Sichtbarer Fokusring nur bei Tastatur-Navigation (modern, barrierearm). */
  button:focus-visible, summary:focus-visible, a:focus-visible, .item:focus-visible {
    outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 8px;
  }
  /* Game rows are real <button>s now (keyboard-navigable primary nav): undo the
     global gold-button styling so they render exactly like the old .item divs. */
  button.item {
    width: 100%; text-align: left; background: none; border: 0;
    font: inherit; font-weight: inherit; letter-spacing: normal;
  }
  button.item:hover { filter: none; }
  select { width: auto; }
  a { color: var(--gold); }

  /* ---------- Login ---------- */
  #login {
    height: 100%; display: none; align-items: center; justify-content: center; flex-direction: column; gap: 1.4rem;
  }
  #login .card {
    background: linear-gradient(180deg, var(--panel) 0%, var(--bg-soft) 100%);
    border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow);
    padding: 2.6rem 3rem; text-align: center; max-width: 420px;
  }
  #login h1 { margin: .2rem 0 .4rem; font-size: 1.6rem; color: var(--gold); font-weight: 700; }
  #login p { color: var(--ink-dim); margin: 0 0 1.6rem; }
  .sigil { font-size: 2.4rem; }

  /* ---------- Shell ---------- */
  #shell { height: 100%; display: none; }
  #shell.on, #login.on { display: flex; }
  aside {
    width: 300px; flex-shrink: 0; display: flex; flex-direction: column;
    background: var(--bg-soft); border-right: 1px solid var(--line);
    position: relative;
  }
  /* Drag handle to resize the sidebar (desktop only) */
  .side-resizer {
    position: absolute; top: 0; right: -3px; bottom: 0; width: 7px;
    cursor: col-resize; z-index: 11; touch-action: none;
  }
  .side-resizer::after {
    content: ''; position: absolute; top: 0; bottom: 0; left: 3px; width: 1px;
    background: transparent; transition: background .15s;
  }
  .side-resizer:hover::after, body.side-resizing .side-resizer::after { background: var(--gold); }
  body.side-resizing { cursor: col-resize; user-select: none; }
  .brand {
    padding: .7rem 1rem .6rem; font-weight: 750; font-size: 1rem; color: var(--gold);
    display: flex; align-items: center; gap: .55rem; border-bottom: 1px solid var(--line);
  }
  .side-scroll { flex: 1; overflow-y: auto; padding: var(--sp-3); display: flex; flex-direction: column; gap: var(--sp-1); }
  /* Collapsible section: native <details>. Header hosts chevron + title + count + add. */
  .side-sec { margin: 0; }
  .sec-head {
    display: flex; align-items: center; gap: var(--sp-2); list-style: none;
    margin: 0; padding: var(--sp-2); border-radius: var(--r-sm);
    font-size: var(--fs-md); font-weight: 650; letter-spacing: .01em;
    color: var(--ink-dim); cursor: pointer; user-select: none;
  }
  .sec-head::-webkit-details-marker { display: none; }
  .sec-head:hover { color: var(--ink); background: var(--panel); }
  .sec-head .chev { flex: none; font-size: 1.05rem; color: var(--ink-dim); transition: transform .15s, color .12s; }
  .sec-head:hover .chev { color: var(--ink); }
  details.side-sec:not([open]) > .sec-head .chev { transform: rotate(-90deg); }
  .sec-head .sec-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sec-head .count {
    flex: none; font-size: var(--fs-2xs); font-weight: 600; color: var(--muted);
    background: var(--panel-2); border: 1px solid var(--line);
    border-radius: 99px; padding: .02rem .42rem; letter-spacing: 0; text-transform: none;
  }
  .sec-head .add {
    flex: none; width: 1.5rem; height: 1.5rem; padding: 0; border: 0; border-radius: var(--r-sm);
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--gold-soft); color: var(--gold); font-size: 1.1rem; font-weight: 700;
    line-height: 1; cursor: pointer; transition: transform .2s, filter .12s;
  }
  .sec-head .add:hover { filter: brightness(1.18); }
  .side-sec.adding > .sec-head .add { transform: rotate(45deg); }
  .sec-body { padding: var(--sp-1) 0 var(--sp-2); }
  .row-actions { display: flex; align-items: center; gap: var(--sp-1); flex: none; }
  .item {
    display: flex; align-items: center; gap: var(--sp-2); padding: .4rem var(--sp-2); border-radius: var(--r-sm);
    cursor: pointer; color: var(--ink-dim); transition: background .12s, color .12s; user-select: none;
  }
  .item:hover { background: var(--panel); color: var(--ink); }
  .item.active { background: var(--gold-soft); color: var(--ink); box-shadow: inset 0 0 0 1px var(--accent-ring); }
  .item .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  /* Chat-Eintraege einzeilig: Titel links (flext mit Ellipsis), Badges + Aktionen
     rechts. min-width:0 am Titel ist Pflicht, sonst greift die Ellipsis im Flex nicht. */
  .item.chat-item { flex-direction: row; align-items: center; gap: var(--sp-2); position: relative; }
  .item.chat-item .t { flex: 1; min-width: 0; display: flex; align-items: center; gap: .4rem; }
  .item.chat-item .t .tt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  /* Live-Indikator: rotierender Ring, nur sichtbar wenn der Chat gerade eine
     Anfrage laeuft (.item.running). Nimmt sonst keinen Platz ein. */
  .run-ind { display: none; flex: none; width: 12px; height: 12px; border-radius: 50%;
    border: 2px solid var(--gold); border-right-color: transparent; animation: run-spin .7s linear infinite; }
  .item.running .run-ind { display: inline-block; }
  @keyframes run-spin { to { transform: rotate(360deg); } }
  .item.chat-item .meta { display: flex; align-items: center; flex: none; gap: var(--sp-1); }
  .item.chat-item .meta .spacer { display: none; }
  .item.chat-item .meta button { flex-shrink: 0; }
  /* Transfer-chat popover: a real member picker, replaces the numbered prompt(). */
  .row-backdrop { position: fixed; inset: 0; z-index: 39; }
  .row-pop {
    position: absolute; right: 0; top: calc(100% + 2px); z-index: 40; min-width: 12rem;
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-sm);
    box-shadow: var(--shadow); padding: var(--sp-1); display: flex; flex-direction: column; gap: 1px;
  }
  .row-pop-head { font-size: var(--fs-2xs); color: var(--muted); text-transform: uppercase;
    letter-spacing: .06em; padding: var(--sp-1) var(--sp-2); }
  .row-pop button { text-align: left; background: transparent; border: 0; color: var(--ink-dim);
    padding: var(--sp-1) var(--sp-2); border-radius: 6px; font-size: var(--fs-xs); font-weight: 500; cursor: pointer; }
  .row-pop button:hover { background: var(--panel-2); color: var(--ink); }
  .row-pop-empty { font-size: var(--fs-xs); color: var(--muted); padding: var(--sp-1) var(--sp-2); }
  .badge {
    font-size: var(--fs-2xs); font-weight: 650; padding: .12rem .42rem; border-radius: 99px;
    border: 1px solid var(--line); color: var(--muted); letter-spacing: .03em; flex-shrink: 0;
    cursor: default; user-select: none;
  }
  .badge.sl, .badge.master { color: var(--red-ink); border-color: var(--red-soft); background: var(--red-soft); }
  .badge.shared { color: var(--info-ink); border-color: #4d7fe566; background: #4d7fe514; }
  /* Chat-header visibility toggle: a real button, not a clickable badge. */
  .vis-toggle {
    display: inline-flex; align-items: center; gap: .3rem; flex: none;
    font-size: var(--fs-2xs); font-weight: 650; padding: .16rem .55rem; border-radius: 99px;
    background: transparent; border: 1px solid var(--line); color: var(--ink-dim); cursor: pointer;
    transition: color .12s, border-color .12s;
  }
  .vis-toggle:hover:not(:disabled) { color: var(--ink); border-color: var(--line-strong); }
  .vis-toggle:disabled { opacity: .6; cursor: default; }
  /* Inline add/config form: standalone card, opened by the section header's + button. */
  .form { display: flex; flex-direction: column; gap: var(--sp-2); padding: var(--sp-3);
    margin-top: var(--sp-1); background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--r-sm); }
  .form .row { display: flex; gap: var(--sp-2); }
  .form .row > * { flex: 1; }
  .form label { font-size: var(--fs-xs); color: var(--muted); margin-top: var(--sp-1); }
  .form-empty { font-size: var(--fs-xs); color: var(--muted); line-height: 1.45; padding: var(--sp-1) 0; }
  /* Nebel-Schwelle slider (Settings): direction is confusing as a bare number. */
  .tau-row { display: flex; align-items: center; gap: var(--sp-2); }
  .tau-row input[type=range] { flex: 1; width: auto; accent-color: var(--gold); }
  .tau-end { font-size: var(--fs-2xs); color: var(--muted); flex: none; }
  .tau-read { font-size: var(--fs-2xs); color: var(--ink-dim); line-height: 1.45; }
  /* Wartung/Gefahrenzone: separate expensive+destructive actions from routine save. */
  .danger-zone { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2);
    margin-top: var(--sp-2); padding-top: var(--sp-2); border-top: 1px solid var(--line); }
  .danger-zone .dz-label { flex: 1 0 100%; font-size: var(--fs-2xs); color: var(--muted);
    text-transform: uppercase; letter-spacing: .05em; }
  .date-hint { font-size: var(--fs-2xs); color: var(--ink-dim); line-height: 1.45;
    background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--r-sm); padding: .4rem .55rem; }

  .member { display: flex; align-items: center; gap: var(--sp-2); padding: .4rem var(--sp-2); border-radius: var(--r-sm); }
  .member:hover { background: var(--panel); }
  .member .nm { flex: 1; min-width: 0; font-size: var(--fs-sm); color: var(--ink-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .member select { font-size: var(--fs-xs); padding: .18rem .3rem; border-radius: var(--r-sm); width: auto; flex: none; }
  .member .crown { color: var(--gold); font-size: var(--fs-sm); flex: none; }

  .side-bottom { border-top: 1px solid var(--line); }
  /* The identity row IS the collapse toggle: always visible at the bottom, a clear
     chevron shows state. Collapsed -> only this account chip remains. */
  .foot-head {
    width: 100%; display: flex; align-items: center; gap: var(--sp-2); text-align: left;
    padding: var(--sp-2) var(--sp-3); background: transparent; border: 0; cursor: pointer;
    color: var(--ink-dim); transition: background .12s;
  }
  .foot-head:hover { background: var(--panel); }
  .foot-head .who { flex: 1; min-width: 0; }
  .foot-head .who .n { font-size: var(--fs-sm); color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .foot-head .who .r { font-size: var(--fs-2xs); color: var(--muted); }
  .foot-head .chev { flex: none; color: var(--ink-dim); font-size: 1.05rem; transition: transform .15s, color .12s; }
  .foot-head:hover .chev { color: var(--ink); }
  .side-bottom.collapsed .foot-head .chev { transform: rotate(-90deg); }
  .side-bottom.collapsed .foot-body { display: none; }
  .foot-body { display: flex; flex-direction: column; gap: var(--sp-2); padding: 0 var(--sp-3) var(--sp-3); }
  .side-actions { display: flex; flex-direction: row; gap: var(--sp-2); }
  .side-actions > * { flex: 1; }
  .side-actions > a { display: block; text-decoration: none; }
  .side-actions .ghost { width: 100%; }
  .avatar {
    width: 32px; height: 32px; border-radius: 50%; background: var(--gold-soft); color: var(--gold);
    display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: var(--fs-sm); flex: none;
    border: 1px solid var(--accent-tint);
  }
  /* Theme picker row in the account footer */
  .theme-row { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-xs); color: var(--muted); }
  .theme-row select { flex: 1; width: auto; font-size: var(--fs-xs); padding: .25rem .4rem; }
  .buildinfo { font-size: var(--fs-2xs); color: var(--muted); opacity: .75; padding: 0; }
  /* Doku is a real button now, not a fine-print text link. */
  .doku-link {
    display: inline-flex; align-items: center; gap: .35rem; align-self: flex-start;
    margin: var(--sp-1) 0 0; padding: var(--sp-1) var(--sp-2);
    font-size: var(--fs-xs); color: var(--ink-dim); background: transparent;
    border: 1px solid var(--line); border-radius: var(--r-sm); text-decoration: none;
    transition: color .12s, border-color .12s;
  }
  .doku-link:hover { color: var(--ink); border-color: var(--line-strong); }

  /* ---------- Chat ---------- */
  main { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
  .jump-latest {
    position: absolute; right: 1.6rem; bottom: 5.2rem; z-index: 6;
    display: inline-flex; align-items: center; gap: .35rem;
    font-size: .8rem; font-weight: 600; padding: .45rem .8rem; border-radius: 999px;
    background: var(--gold); color: var(--btn-ink); box-shadow: var(--shadow);
  }
  .chat-head {
    display: flex; align-items: center; gap: .7rem; padding: .7rem 1.2rem;
    border-bottom: 1px solid var(--line); background: var(--head-bg); backdrop-filter: blur(6px);
  }
  .chat-head .title { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .chat-head .spacer { flex: 1; }
  .chat-head .total { font-size: .76rem; color: var(--muted); white-space: nowrap; }
  #messages { flex: 1; overflow-y: auto; padding: 1.4rem 1.6rem 1rem; display: flex; flex-direction: column; gap: 1.05rem; }
  .empty {
    margin: auto; text-align: center; color: var(--muted);
  }
  .empty .sigil { opacity: .5; margin-bottom: .6rem; }
  .empty .fog-note { margin-top: .6rem; font-size: .8rem; }
  .empty .examples { display: flex; flex-direction: column; gap: .4rem; margin-top: .9rem; align-items: center; }
  .msg { display: flex; flex-direction: column; max-width: 128ch; }
  .msg.user { align-self: flex-end; align-items: flex-end; max-width: 96ch; }
  .bubble {
    padding: .7rem 1rem; border-radius: 14px; box-shadow: 0 2px 10px rgba(0,0,0,.18);
    overflow-wrap: break-word;
  }
  .msg.user .bubble { background: linear-gradient(180deg, var(--bubble-1), var(--bubble-2)); border: 1px solid var(--bubble-line); white-space: pre-wrap; }
  .msg.assistant .bubble { background: var(--panel); border: 1px solid var(--line); }
  .md p { margin: .45em 0; } .md p:first-child { margin-top: 0; } .md p:last-child { margin-bottom: 0; }
  .md h1,.md h2,.md h3,.md h4 { margin: .8em 0 .35em; color: var(--gold); line-height: 1.25; }
  .md h1{font-size:1.2em}.md h2{font-size:1.12em}.md h3{font-size:1.04em}.md h4{font-size:1em}
  .md ul,.md ol { margin: .4em 0; padding-left: 1.4em; }
  .md li { margin: .18em 0; }
  .md code { background: var(--code-bg); border: 1px solid var(--line); border-radius: 5px; padding: .08em .35em; font-size: .88em; }
  .md pre { background: var(--pre-bg); border: 1px solid var(--line); border-radius: 9px; padding: .7rem .9rem; overflow-x: auto; }
  .md pre code { background: none; border: 0; padding: 0; }
  .md blockquote { margin: .5em 0; padding: .15em .9em; border-left: 3px solid var(--gold); color: var(--ink-dim); background: #d4a9480d; border-radius: 0 8px 8px 0; }
  .md table { border-collapse: collapse; margin: .5em 0; font-size: .92em; }
  .md th, .md td { border: 1px solid var(--line); padding: .3em .6em; }
  .md th { background: var(--panel-2); color: var(--gold); }
  .md hr { border: 0; border-top: 1px solid var(--line); margin: .8em 0; }
  .md a { color: var(--gold); }

  .toolnote { font-size: .76rem; color: var(--muted); padding: .15rem .2rem; font-style: italic; }
  .toolnote::before { content: "🔎 "; font-style: normal; }
  /* Pre-first-delta pending state: reuses the sidebar run-spin ring inline. */
  .bubble.pending { color: var(--muted); font-style: italic; }
  .bubble.pending .run-ind { display: inline-block; vertical-align: -1px; }
  .retry-btn { margin-top: .45rem; }

  /* Inline-Zitate: [N]-Chips im Text; Klick klappt Passage + Download direkt darunter auf. */
  sup.cref { cursor: pointer; font-weight: 750; font-size: .72em; margin: 0 .12em; user-select: none; }
  sup.cref.vault { color: var(--violet-ink); }
  sup.cref.pdf { color: var(--red-ink); }
  sup.cref:hover { text-decoration: underline; }
  .cref-panel { margin: .5rem 0; border-radius: 10px; padding: .5rem .7rem; font-size: .8rem; }
  .cref-panel.vault { background: #8b5cf614; border: 1px solid #8b5cf655; }
  .cref-panel.pdf { background: #e5484d12; border: 1px solid #e5484d55; }
  .cref-head { display: flex; gap: .55rem; align-items: center; flex-wrap: wrap; }
  .cref-label { font-weight: 620; text-decoration: none; }
  .cref-panel.vault .cref-label { color: var(--violet-ink); }
  .cref-panel.pdf .cref-label { color: var(--red-ink); }
  .cref-label:hover { text-decoration: underline; }
  .cref-page { font-size: .7rem; color: var(--muted); text-decoration: none; border: 1px solid var(--line); padding: .06rem .4rem; border-radius: 99px; }
  .cref-page:hover { color: var(--ink); }
  .cref-close { margin-left: auto; cursor: pointer; color: var(--muted); border: 0; background: none; font-size: .85rem; padding: 0 .2rem; }
  .cref-body { white-space: pre-wrap; margin-top: .45rem; font-size: .78rem; color: var(--ink); max-height: 300px; overflow: auto; padding: .5rem .6rem; background: var(--code-bg); border-radius: 8px; }
  .cost { font-size: .72rem; color: var(--ink-dim); } /* money-critical: above the muted tier */
  .msg-foot { display: flex; align-items: center; gap: .6rem; margin-top: .45rem; min-height: 1.3rem; }
  .copy-actions { margin-left: auto; display: flex; gap: .1rem; opacity: .7; transition: opacity .15s; }
  .msg.assistant:hover .copy-actions, .copy-actions:focus-within { opacity: 1; }
  .copy-ico { background: none; border: 0; padding: .25rem; color: var(--muted); cursor: pointer; display: inline-flex; align-items: center; }
  .copy-ico:hover { color: var(--ink); }
  .copy-ico svg { height: 15px; width: auto; display: block; }
  .copy-lbl { font-size: .62rem; margin-left: .18rem; }

  .budget { padding: var(--sp-1) 0; }
  .budget-head { display: flex; justify-content: space-between; align-items: baseline; font-size: var(--fs-xs); color: var(--muted); }
  .budget-head #budgetPct { font-weight: 600; color: var(--ink); }
  .budget-bar { height: 6px; border-radius: 99px; background: var(--bar-track); overflow: hidden; margin-top: .3rem; }
  .budget-bar i { display: block; height: 100%; width: 0; border-radius: 99px; background: var(--ok); transition: width .35s ease, background .35s ease; }
  .budget-bar i.warn { background: var(--warn); }
  .budget-bar i.over { background: var(--red); }
  .budget-sub { font-size: .66rem; color: var(--ink-dim); margin-top: .25rem; } /* money-critical */

  .idx-status { font-size: .72rem; color: var(--ink-dim); line-height: 1.5; padding: .2rem 0; }
  button.ghost.sm { padding: .3rem .5rem; font-size: .78rem; }
  .browse-ov { position: fixed; inset: 0; background: #000a; display: flex; align-items: center; justify-content: center; z-index: 50; }
  .browse-box { width: min(560px, 92vw); max-height: 80vh; display: flex; flex-direction: column;
    background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
  .browse-head { display: flex; align-items: center; gap: .6rem; padding: .7rem .9rem; border-bottom: 1px solid var(--line); }
  .browse-head .browse-path { flex: 1; font-size: .72rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .browse-list { overflow: auto; padding: .5rem; display: flex; flex-direction: column; gap: .2rem; }
  .browse-dir { text-align: left; background: var(--panel-2); border: 1px solid var(--line); color: var(--ink); border-radius: 8px; padding: .45rem .6rem; font-size: .82rem; }
  .browse-dir:hover { border-color: var(--gold); }
  .browse-empty, .browse-err { color: var(--muted); font-size: .78rem; padding: .5rem; }
  .browse-foot { display: flex; justify-content: space-between; gap: .5rem; padding: .7rem .9rem; border-top: 1px solid var(--line); }

  .composer { display: flex; gap: .6rem; padding: .85rem 1.2rem 1.1rem; border-top: 1px solid var(--line); }
  .composer textarea {
    flex: 1; resize: none; height: 52px; border-radius: 12px; padding: .8rem .95rem; background: var(--panel);
  }
  .composer .send-stack { display: flex; flex-direction: column; gap: .35rem; justify-content: stretch; }
  .composer .send-stack select { font-size: .72rem; padding: .25rem .4rem; border-radius: 8px; width: 100%; }
  .composer button { border-radius: 10px; padding: .45rem 1.3rem; }
  .chat-head .back-home { padding: .3rem .6rem; font-size: var(--fs-xs); flex: none; }
  /* Inline-editable chat title: button looks like the title, hover hints editability. */
  .chat-head button.title-edit {
    background: none; border: 0; color: var(--ink); font: inherit; font-weight: 650;
    padding: .12rem .4rem; margin-left: -.4rem; cursor: text; border-radius: 6px; max-width: 60ch;
  }
  .chat-head button.title-edit:hover { background: var(--panel-2); }
  .chat-head .title-input {
    font: inherit; font-weight: 650; color: var(--ink); background: var(--bg-soft);
    border: 1px solid var(--gold); border-radius: 6px; padding: .12rem .4rem;
    width: auto; flex: 0 1 40ch; min-width: 10rem;
  }

  /* ---------- Runden-Home (Projekt-Startseite) ---------- */
  .rhome { flex: 1; display: flex; flex-direction: column; min-width: 0; }
  .rh-scroll {
    flex: 1; overflow-y: auto; padding: 1.6rem 1.8rem 2rem;
    display: flex; flex-direction: column; gap: 1.4rem;
    width: 100%; max-width: 980px; margin: 0 auto;
  }
  .rh-head { display: flex; align-items: center; gap: .7rem; }
  .rh-title { margin: 0; font-size: 1.5rem; font-weight: 750; color: var(--ink); }
  .rh-framing { color: var(--ink-dim); font-size: var(--fs-md); line-height: 1.6; display: flex; flex-direction: column; gap: .7rem; }
  .rh-framing p { margin: 0; }
  .rh-fognote { font-size: var(--fs-sm); color: var(--ink-dim); background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--r-sm); padding: .7rem .9rem; }
  .rh-starter {
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
    box-shadow: 0 2px 10px rgba(0,0,0,.18); padding: .9rem;
    display: flex; flex-direction: column; gap: .7rem;
  }
  .rh-input { resize: none; height: 76px; border-radius: var(--r-sm); padding: .8rem .95rem; background: var(--bg-soft); font-size: var(--fs-md); }
  .rh-starter-foot { display: flex; align-items: flex-end; justify-content: space-between; gap: .7rem; flex-wrap: wrap; }
  .rh-opts { display: flex; gap: .9rem; flex-wrap: wrap; }
  .rh-opts label { display: inline-flex; flex-direction: column; gap: .2rem; font-size: var(--fs-2xs); color: var(--muted); }
  .rh-opts select { width: auto; font-size: var(--fs-xs); padding: .3rem .4rem; }
  .rh-starter-foot > button { border-radius: 10px; padding: .5rem 1.4rem; }
  .rh-h2 { margin: 0 0 .6rem; font-size: var(--fs-md); font-weight: 650; color: var(--ink-dim); }
  .rh-chats { display: flex; flex-direction: column; gap: .3rem; }
  .rh-chats .item.chat-item { background: var(--panel); border: 1px solid var(--line); }
  .rh-chats .item.chat-item:hover { background: var(--panel-2); }
  .rh-cards { display: flex; flex-direction: column; gap: 1rem; }
  .rh-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 1rem; display: flex; flex-direction: column; gap: .5rem; align-items: flex-start; }
  .rh-card-h { font-weight: 650; color: var(--ink); }
  .rh-card-sub { margin: 0; color: var(--ink-dim); font-size: var(--fs-sm); }
  .rh-sub { color: var(--muted); font-size: var(--fs-sm); margin-top: .25rem; }
  .rh-social { color: var(--ink-dim); }
  /* Reused sidebar Sections (Members/DateBar/Settings) rehosted as home cards. */
  .rhome .side-sec { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 0 .5rem .3rem; }
  .rhome .side-sec > .sec-head { font-size: var(--fs-md); color: var(--ink); padding: .7rem .5rem; }
  .rhome .side-sec > .sec-head .count { color: var(--muted); }
  @media (max-width: 760px) {
    .rh-scroll { padding: 1.1rem 1rem 1.6rem; }
    .rh-title { font-size: 1.25rem; }
  }

  #backdrop { display: none; }
  .close-side { display: none; }
  @media (max-width: 760px) {
    aside { position: fixed; z-index: 10; height: 100%; width: 300px !important; transform: translateX(-100%); transition: transform .2s; }
    aside.open { transform: none; box-shadow: var(--shadow); }
    .side-resizer { display: none; }
    .burger { display: inline-flex !important; }
    .close-side { display: inline-flex; margin-left: auto; }
    #backdrop.on { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 9; }
  }
  /* Fog-Modal-Mobilregeln leben in einem EIGENEN Media-Block am DATEIENDE:
     Media-Queries erhoehen die Spezifitaet nicht, ein frueher Block wuerde von
     den spaeteren Fog-Basisregeln ueberschrieben (Kaskaden-Reihenfolge). */
  /* Touch targets: 28px glyphs are fine for mouse, too small for fingers. 36px is
     the max that still fits 3 actions + badges in the 300px drawer (44px would
     crush the title ellipsis). */
  @media (pointer: coarse) {
    .iconbtn { width: 2.25rem; height: 2.25rem; }
    .item.chat-item .meta, .row-actions { gap: var(--sp-2); }
  }
  /* Copy buttons: hover-reveal has no equivalent on touch, keep them fully
     visible there and grow the ~23px tap target to ~41px without shifting the
     .msg-foot line height. */
  @media (hover: none), (pointer: coarse) {
    .copy-actions { opacity: 1; }
    .copy-ico { padding: .55rem; margin: -.3rem 0; }
  }
  .burger { display: none; }

  /* Quellen & Nebel modal */
  #fogModal { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 20;
    display: flex; align-items: center; justify-content: center; }
  .fog-box { background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
    width: min(1080px, 96vw); height: 90vh; display: flex; flex-direction: column; box-shadow: var(--shadow); }
  .fog-head { display: flex; flex-direction: column; align-items: stretch; gap: .5rem; padding: .7rem 1rem; border-bottom: 1px solid var(--line); }
  .fog-head-top { display: flex; align-items: center; gap: .6rem; }
  .fog-head-top b { font-size: 1rem; }
  .fog-legend { margin-left: auto; font-size: var(--fs-xs); color: var(--ink-dim); }
  .fog-legend b { color: var(--ink); font-weight: 650; }
  .fog-taubar { display: flex; align-items: center; gap: .55rem; background: var(--panel-2);
    border: 1px solid var(--line); border-radius: var(--r-sm); padding: .4rem .7rem; }
  .fog-taubar label { font-size: var(--fs-xs); color: var(--muted); flex: none; font-weight: 600; }
  .fog-taubar input[type=range] { flex: 1; width: auto; accent-color: var(--gold); }
  .fog-tau-min, .fog-tau-max { font-size: var(--fs-2xs); color: var(--muted); flex: none; }
  .fog-tauval { font-size: var(--fs-xs); color: var(--ink); flex: none; min-width: 8.5rem; text-align: right; font-variant-numeric: tabular-nums; }
  .fog-help > summary { cursor: pointer; color: var(--gold); font-size: var(--fs-xs); list-style: none; width: max-content; }
  .fog-help > summary::-webkit-details-marker { display: none; }
  .fog-help > summary::before { content: 'ℹ '; }
  .fog-help p { margin: .45rem 0 0; font-size: var(--fs-xs); color: var(--ink-dim); line-height: 1.5; }
  .fog-help p b { color: var(--ink); }
  .fog-search { padding: .6rem 1rem 0; }
  .fog-search input { width: 100%; font-size: .8rem; }
  /* ONE scroll container for categories + tree. Two separate flex scroll panels
     starved the tree (flex:1 = basis 0) to a sliver once the category list grew;
     on mobile only the cats panel was usable. Cats scroll away with the content. */
  .fog-scroll { flex: 1; min-height: 0; overflow-y: auto; }
  /* overflow-x safety net: category rows have no scroll container of their own,
     without this their Sperre/Nebel/Frei segment can clip unreachably off-screen. */
  .fog-cats { padding: .6rem 1rem .65rem; border-bottom: 1px solid var(--line); overflow-x: auto; }
  .fog-cats .fog-cats-hd { font-size: .66rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: .4rem; }
  .fog-catrow { display: flex; gap: .55rem; align-items: center; padding: .18rem 0; font-size: .82rem; }
  .fog-catrow .nm { flex: 1; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .fog-catrow .fog-count { flex: none; }
  .fog-catchip { font-size: var(--fs-2xs); border: 1px solid var(--line); border-radius: 999px; padding: .03rem .45rem; color: var(--muted); flex: none; white-space: nowrap; }
  .fog-catchip.free { color: var(--ok); border-color: #1f6f4366; }
  .fog-catchip.lock { color: var(--red-ink); border-color: #e5484d55; }
  /* Spoiler-Vorschlag: strukturierte Liste (Checkbox | Seite | Score | Gründe) */
  .fog-spoiler { width: 100%; margin-top: .35rem; padding-top: .5rem; border-top: 1px dashed var(--line); display: flex; flex-direction: column; gap: .45rem; }
  .fog-sp-head { display: flex; align-items: center; gap: .7rem; flex-wrap: wrap; }
  .fog-sp-head label { font-size: .66rem; color: var(--muted); display: inline-flex; align-items: center; gap: .25rem; }
  .fog-sp-note { font-size: .68rem; color: var(--muted); }
  .fog-sp-list { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--panel-2); }
  .fog-sp-item { display: grid; grid-template-columns: 1.1rem 4.6rem 3.4rem 1fr auto; gap: .55rem; align-items: center;
    padding: .34rem .6rem; font-size: .72rem; border-top: 1px solid var(--line); cursor: pointer; }
  .fog-sp-list > .fog-sp-item:first-child { border-top: 0; }
  .fog-sp-item:hover { background: var(--panel); }
  .fog-sp-item .pg { font-weight: 700; color: var(--ink); white-space: nowrap; }
  .fog-sp-bar { height: .42rem; border-radius: 999px; background: var(--line); overflow: hidden; }
  .fog-sp-bar > i { display: block; height: 100%; background: var(--red); }
  .fog-sp-item .rs { color: var(--muted); line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .fog-sp-item .sp-view { font-size: .62rem; padding: .14rem .55rem; flex: none; }
  .fog-sp-prev { border-top: 1px solid var(--line); background: var(--panel); padding: .45rem .65rem; max-height: 12rem; overflow: auto; }
  .fog-sp-prev .pgh { color: var(--gold); font-weight: 700; font-size: .66rem; margin: .35rem 0 .15rem; }
  .fog-sp-prev .pgh:first-child { margin-top: 0; }
  .fog-sp-prev .txt { font-size: .7rem; color: var(--ink-dim); white-space: pre-wrap; line-height: 1.3; }
  .fog-sp-foot { display: flex; justify-content: space-between; align-items: center; gap: .6rem; }
  .fog-tree { padding: .55rem 1rem .8rem; }
  .fog-open { width: 100%; margin-top: var(--sp-2); background: var(--panel-2); color: var(--ink-dim);
    border: 1px solid var(--line); font-weight: 600; }
  .fog-open:hover { color: var(--ink); border-color: var(--line-strong); filter: none; }
  .fog-folder summary { cursor: pointer; padding: .32rem 0; display: flex; align-items: center; gap: .5rem; font-weight: 600; font-size: .85rem; }
  .fog-folder summary::-webkit-details-marker { display: none; }
  .fog-folder > summary::before { content: '📁'; flex: none; }
  .fog-folder[open] > summary::before { content: '📂'; }
  .fog-ico { flex: none; }
  .fog-count { font-size: .68rem; color: var(--muted); font-weight: 400; }
  .fog-bulk { margin-left: auto; }
  .fog-bookwrap { padding-left: 1.1rem; }
  .fog-book { display: flex; gap: .55rem; align-items: center; padding: .22rem 0; font-size: .8rem; color: var(--ink-dim); }
  .fog-book .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .fog-book:hover .nm { color: var(--ink); }
  /* Player result badge (👤): the resolved book-level state a player will get. */
  .fog-result { font-size: var(--fs-2xs); font-weight: 650; border-radius: 999px; padding: .08rem .5rem;
    flex: none; white-space: nowrap; border: 1px solid; }
  .fog-result.st-free { color: var(--ok); border-color: #1f6f4366; background: #1f6f431f; }
  .fog-result.st-lock { color: var(--red-ink); border-color: #e5484d55; background: #e5484d1f; }
  .fog-result.st-fog { color: var(--info-ink); border-color: #58a6ff55; background: #58a6ff1f; }
  .fog-via { font-size: var(--fs-2xs); color: var(--muted); flex: none; white-space: nowrap; }
  .fog-warnchip { font-size: var(--fs-2xs); color: var(--warn); border: 1px solid #d6a52a66; background: #d6a52a14;
    border-radius: 999px; padding: .03rem .45rem; flex: none; white-space: nowrap; cursor: help; }
  .fog-datechip { font-size: var(--fs-2xs); color: var(--warn); flex: none; white-space: nowrap; cursor: help; }
  .fog-seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; flex: none; }
  .fog-seg button { font-size: .78rem; padding: .28rem .7rem; border: 0; border-radius: 0; background: transparent; color: var(--muted); cursor: pointer; font-weight: 600; }
  .fog-seg button:hover:not(.on) { background: var(--panel); color: var(--ink); }
  .fog-seg button.on.st-fog { background: #58a6ff33; color: var(--info-ink); }
  .fog-seg button.on.st-free { background: #1f6f4359; color: var(--ok); }
  .fog-seg button.on.st-lock { background: #e5484d40; color: var(--red-ink); }
  .fog-pgbtn { font-size: .72rem; padding: .2rem .55rem; flex: none; }
  .fog-pgs { font-size: .66rem; color: var(--muted); flex: none; }
  .fog-mi { font-size: var(--fs-2xs); border: 1px solid #d6a52a66; color: var(--warn); background: #d6a52a14; border-radius: 999px; padding: .03rem .45rem; flex: none; white-space: nowrap; cursor: help; }
  .fog-pages { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; padding: .25rem 0 .5rem 1.6rem; }
  .fog-chip { font-size: .66rem; border: 1px solid var(--line); border-radius: 999px; padding: .1rem .5rem; display: inline-flex; align-items: center; gap: .3rem; }
  .fog-chip.rev { color: var(--ok); border-color: #1f6f4366; }
  .fog-chip.hid { color: var(--red-ink); border-color: #e5484d55; }
  .fog-chip.fg { color: var(--ink-dim); border-color: var(--line); }
  .fog-chip button { background: none; border: 0; color: inherit; padding: 0; font-size: .66rem; cursor: pointer; }
  .fog-pgadd { display: flex; gap: .35rem; width: 100%; }
  .fog-pgadd input { flex: 1; font-size: .72rem; padding: .25rem .5rem; }
  .fog-pgadd select, .fog-pgadd button { font-size: .68rem; }
  .fog-preview { width: 100%; font-size: .66rem; min-height: .9rem; }
  .fog-preview.ok { color: var(--ok); }
  .fog-preview.bad { color: var(--red-ink); }
  .fog-preview.warn { color: var(--warn); }
  .fog-foot { display: flex; justify-content: flex-end; gap: .5rem; padding: .7rem 1rem; border-top: 1px solid var(--line); }

  /* Ingame-Datum (always visible per selected game) */
  .datebar { display: flex; flex-direction: column; gap: var(--sp-2); padding: 0; }
  .date-status { font-weight: 650; color: var(--gold); font-size: var(--fs-md); }
  .date-sub { font-size: var(--fs-xs); color: var(--muted); }
  .date-pill { font-size: .66rem; color: var(--warn); border: 1px solid #d2992255; background: #d2992212;
    border-radius: 999px; padding: .12rem .5rem; align-self: flex-start; }
  .date-edit { display: flex; gap: .3rem; }
  .date-edit select { flex: 1; font-size: .76rem; padding: .25rem .3rem; border-radius: 7px; min-width: 0; }
  .date-edit input { width: 4.2rem; flex: none; font-size: .76rem; padding: .25rem .3rem; border-radius: 7px; }
  .date-btns { display: flex; gap: .35rem; }
  .date-btns button { font-size: .74rem; padding: .3rem .5rem; }

  /* Per-book Spoiler/Datum meta in the fog modal */
  .fog-metabtn { font-size: .72rem; padding: .2rem .55rem; flex: none; }
  .fog-metabtn.on { background: #e5484d22; color: var(--red-ink); border-color: #e5484d55; }
  .fog-meta { display: flex; flex-wrap: wrap; gap: .45rem; align-items: center; padding: .3rem 0 .55rem 1.6rem; font-size: .72rem; color: var(--ink-dim); }
  .fog-meta label { display: inline-flex; align-items: center; gap: .3rem; }
  .fog-meta select { font-size: .68rem; padding: .15rem .3rem; width: auto; }
  .fog-meta input { width: 3.6rem; font-size: .68rem; padding: .15rem .3rem; }
  .fog-meta .sep { color: var(--muted); }

  #app { height: 100%; }

  /* Fog-Modal am Handy: Vollbild (dvh statt 90vh gegen die iOS-Chrome-Leiste),
     Buchzeilen umbruchfähig (Name eigene Zeile, Segment rechts darunter),
     Bedienelemente auf ~40px Touch-Höhe. MUSS nach allen Fog-Basisregeln stehen,
     sonst gewinnen die späteren gleich-spezifischen Basis-Deklarationen. */
  @media (max-width: 760px) {
    .fog-box { width: 100vw; height: 100dvh; border-radius: 0; border: 0; }
    .fog-legend { display: none; } /* the always-open legend text; the details help stays */
    .fog-tau-min, .fog-tau-max { display: none; }
    .fog-tauval { min-width: 0; }
    .fog-book, .fog-catrow, .fog-folder summary { flex-wrap: wrap; row-gap: .3rem; }
    .fog-book .nm, .fog-catrow .nm { flex: 1 1 100%; white-space: normal; }
    .fog-seg { margin-left: auto; }
    .fog-seg button, .fog-pgbtn, .fog-metabtn { font-size: .72rem; padding: .55rem .7rem; }
  }
