:root {
  --bg: #04060c;
  --bg-2: #0a0f1c;
  --glass: rgba(18, 26, 46, 0.55);
  --glass-2: rgba(28, 40, 68, 0.55);
  --line: rgba(120, 190, 255, 0.14);
  --line-strong: rgba(120, 220, 255, 0.35);
  --text: #e6f1ff;
  --muted: #7d8ca8;
  --cyan: #22d3ee;
  --violet: #8b5cf6;
  --magenta: #e879f9;
  --green: #34f5a8;
  --danger: #ff6b8a;
  --radius: 18px;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --state: var(--cyan);
}
body[data-state="listening"] { --state: var(--green); }
body[data-state="thinking"] { --state: var(--violet); }
body[data-state="speaking"] { --state: var(--magenta); }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
html { touch-action: manipulation; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  overflow: hidden;
  position: fixed; inset: 0;          /* kein Gummiband-Scrollen am iPhone */
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; user-select: none; -webkit-user-select: none; }
input, textarea, select { font: inherit; font-size: 16px; color: var(--text); } /* ≥16px: iPhone zoomt beim Tippen nicht */

/* ---------- Hintergrund ---------- */
.backdrop { position: fixed; inset: 0; z-index: -1; overflow: hidden; background: radial-gradient(120% 80% at 50% 0%, #0b1430 0%, var(--bg) 60%); }
.grid {
  position: absolute; inset: -50%;
  background-image: linear-gradient(var(--line) 1px, transparent 1px), linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 44px 44px;
  transform: perspective(600px) rotateX(60deg) translateY(20%);
  mask-image: radial-gradient(ellipse at 50% 30%, #000 10%, transparent 60%);
  -webkit-mask-image: radial-gradient(ellipse at 50% 30%, #000 10%, transparent 60%);
  opacity: .35;
}
.glow { position: absolute; border-radius: 50%; filter: blur(80px); opacity: .35; transition: background 1s; }
.g1 { width: 60vmax; height: 60vmax; left: -20vmax; top: -25vmax; background: var(--violet); opacity: .18; }
.g2 { width: 50vmax; height: 50vmax; right: -20vmax; bottom: -25vmax; background: var(--state); opacity: .12; }

.glass { background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(18px) saturate(140%); -webkit-backdrop-filter: blur(18px) saturate(140%); }

.brand { font-family: var(--mono); font-weight: 700; letter-spacing: .28em; font-size: 14px; color: var(--text); }
.brand span { color: var(--cyan); margin: 0 .15em; }
.brand.big { font-size: 22px; }

.btn { border: 1px solid var(--line); border-radius: 12px; padding: 10px 16px; background: var(--glass-2); font-weight: 600; letter-spacing: .02em; transition: border-color .2s, box-shadow .2s, transform .1s; }
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(135deg, rgba(34, 211, 238, .9), rgba(139, 92, 246, .9)); border-color: transparent; color: #fff; box-shadow: 0 0 24px rgba(34, 211, 238, .25); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { border-color: var(--line-strong); }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; }
.icon-btn { background: none; border: 0; padding: 8px; border-radius: 10px; display: grid; place-items: center; color: var(--muted); }
.icon-btn:hover { color: var(--text); background: rgba(255, 255, 255, .05); }
.error { color: var(--danger); min-height: 1.5em; margin: 0; font-size: 14px; }

/* ---------- Anmeldung ---------- */
.login { height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 360px; display: grid; gap: 14px; text-align: center; padding: 32px 24px; border-radius: 24px; }
.login-sub { margin: -8px 0 8px; color: var(--muted); font-size: 14px; }
.login-card input { padding: 14px 16px; border-radius: 12px; border: 1px solid var(--line); background: rgba(0, 0, 0, .3); outline: none; }
.login-card input:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(34, 211, 238, .15); }
.login-core { width: 96px; height: 96px; margin: 0 auto 6px; border-radius: 50%; position: relative;
  background: radial-gradient(circle at 35% 30%, #fff 0%, var(--cyan) 18%, var(--violet) 60%, transparent 72%);
  box-shadow: 0 0 60px rgba(34, 211, 238, .45); animation: breathe 3.5s ease-in-out infinite; }
.login-core span { position: absolute; inset: -10px; border-radius: 50%; border: 1px solid rgba(34, 211, 238, .5); animation: spin 8s linear infinite; border-top-color: transparent; border-bottom-color: transparent; }
@keyframes breathe { 50% { transform: scale(1.06); box-shadow: 0 0 90px rgba(139, 92, 246, .55); } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Layout ---------- */
.app { height: 100%; display: grid; grid-template-columns: 290px 1fr; }
.sidebar { display: flex; flex-direction: column; min-height: 0; border-width: 0 1px 0 0; border-radius: 0; }
.sidebar-head { padding: 16px; padding-top: max(16px, env(safe-area-inset-top)); display: grid; gap: 16px; }
.sidebar-foot { padding: 14px 16px; padding-bottom: max(14px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.conv-list { flex: 1; overflow-y: auto; padding: 0 10px; -webkit-overflow-scrolling: touch; }
.conv { display: flex; align-items: center; border-radius: 10px; border: 1px solid transparent; }
.conv button.open { flex: 1; text-align: left; background: none; border: 0; padding: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; color: #c5d3ea; }
.conv.active { border-color: var(--line-strong); background: rgba(34, 211, 238, .06); }
.conv:hover { background: rgba(255, 255, 255, .04); }
.conv .del { opacity: 0; }
.conv:hover .del, .conv.active .del { opacity: .6; }
.conv-group { font-family: var(--mono); font-size: 11px; color: var(--muted); padding: 14px 10px 6px; letter-spacing: .18em; text-transform: uppercase; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100%; }
.topbar { display: flex; align-items: center; gap: 8px; padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top)); }
#menuBtn { display: none; }
.top-title { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--state); box-shadow: 0 0 10px var(--state); flex: none; transition: background .4s, box-shadow .4s; }
.title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #c9d7ee; }

.auto-toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-family: var(--mono); font-size: 12px; letter-spacing: .2em; color: var(--muted); }
.auto-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.switch { width: 44px; height: 24px; border-radius: 12px; background: rgba(255, 255, 255, .08); border: 1px solid var(--line); position: relative; transition: background .25s, border-color .25s; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #9fb0cc; transition: transform .25s, background .25s, box-shadow .25s; }
.auto-toggle input:checked + .switch { background: rgba(52, 245, 168, .18); border-color: var(--green); }
.auto-toggle input:checked + .switch::after { transform: translateX(20px); background: var(--green); box-shadow: 0 0 12px var(--green); }
.auto-toggle input:checked ~ .auto-label { color: var(--green); }
.auto-toggle input:focus-visible + .switch { outline: 2px solid var(--cyan); outline-offset: 2px; }

/* ---------- Bühne mit Kern ---------- */
.stage { flex: none; display: flex; flex-direction: column; align-items: center; padding: 4px 16px 0; transition: flex .4s; }
.core { position: relative; width: min(64vw, 34vh, 300px); aspect-ratio: 1; border: 0; padding: 0; background: none; border-radius: 50%; transition: width .4s; }
.core canvas { position: absolute; inset: -18%; width: 136%; height: 136%; pointer-events: none; }
.core:focus-visible { outline: 2px solid var(--cyan); outline-offset: 6px; }
.readout { text-align: center; min-height: 64px; width: 100%; max-width: 720px; display: grid; justify-items: center; gap: 6px; margin-top: 2px; }
.status { font-family: var(--mono); font-size: 12px; letter-spacing: .32em; color: var(--state); text-shadow: 0 0 12px var(--state); transition: color .4s; }
.tool-chip { font-family: var(--mono); font-size: 11px; letter-spacing: .15em; text-transform: uppercase; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--violet); color: #d9ccff; background: rgba(139, 92, 246, .15); box-shadow: 0 0 16px rgba(139, 92, 246, .35); animation: chip 1.2s ease-in-out infinite; }
@keyframes chip { 50% { box-shadow: 0 0 4px rgba(139, 92, 246, .2); } }
.interim { font-size: 17px; color: #d7e6ff; opacity: .85; overflow-wrap: anywhere; padding: 0 8px; min-height: 1.5em; }

/* ---------- Nachrichten ---------- */
.messages { flex: 1; min-height: 0; overflow-y: auto; padding: 8px 16px 16px; display: flex; flex-direction: column; gap: 12px; -webkit-overflow-scrolling: touch;
  mask-image: linear-gradient(to bottom, transparent 0, #000 24px); -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 24px); }
.messages > * { width: 100%; max-width: 720px; margin-left: auto; margin-right: auto; }
.msg { display: flex; animation: rise .35s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.msg .bubble { padding: 12px 16px; border-radius: var(--radius); max-width: 86%; overflow-wrap: anywhere; position: relative; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: linear-gradient(135deg, rgba(34, 211, 238, .16), rgba(34, 211, 238, .06)); border: 1px solid rgba(34, 211, 238, .35); border-bottom-right-radius: 6px; }
.msg.assistant .bubble { background: var(--glass); border: 1px solid var(--line); border-bottom-left-radius: 6px; backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.msg.assistant .bubble::before { content: ""; position: absolute; left: -1px; top: 14px; bottom: 14px; width: 2px; border-radius: 2px; background: linear-gradient(var(--violet), var(--magenta)); box-shadow: 0 0 10px var(--violet); }
.msg.error .bubble { border-color: var(--danger); color: var(--danger); background: rgba(255, 107, 138, .06); }
.bubble p { margin: 0 0 .6em; } .bubble p:last-child { margin: 0; }
.bubble code { background: rgba(255, 255, 255, .08); padding: 1px 5px; border-radius: 6px; font-family: var(--mono); font-size: .9em; }
.bubble ul { margin: 0 0 .6em; padding-left: 1.2em; }
.bubble a { color: var(--cyan); }
.typing:empty::after, .typing > :last-child::after { content: "▍"; animation: blink 1s steps(1) infinite; color: var(--magenta); }
@keyframes blink { 50% { opacity: 0; } }

.empty { margin: auto; text-align: center; color: var(--muted); padding: 12px 8px 24px; }
.empty-big { font-size: 18px; color: var(--text); font-weight: 600; margin: 0 0 6px; }
.empty-small { margin: 0 auto; max-width: 420px; font-size: 14px; }

/* ---------- Eingabe ---------- */
.dock { display: flex; align-items: center; gap: 10px; padding: 8px 16px; padding-bottom: max(12px, env(safe-area-inset-bottom)); max-width: 752px; width: 100%; margin: 0 auto; }
.text-form { flex: 1; display: flex; align-items: center; border-radius: 999px; padding: 4px 4px 4px 18px; min-width: 0; transition: border-color .2s, box-shadow .2s; }
.text-form:focus-within { border-color: var(--line-strong); box-shadow: 0 0 0 3px rgba(34, 211, 238, .1); }
.text-form input { flex: 1; border: 0; background: none; outline: none; padding: 9px 0; min-width: 0; }
.text-form input::placeholder { color: var(--muted); }
.text-form .send { color: var(--cyan); }
.mic-btn { width: 52px; height: 52px; flex: none; border-radius: 50%; border: 1px solid var(--state); color: var(--state); background: rgba(0, 0, 0, .35);
  display: grid; place-items: center; box-shadow: 0 0 18px color-mix(in srgb, var(--state) 35%, transparent), inset 0 0 12px color-mix(in srgb, var(--state) 20%, transparent); transition: color .3s, border-color .3s, box-shadow .3s; }
.mic-btn:active { transform: scale(.94); }
.mic-btn svg { grid-area: 1 / 1; }
.mic-btn .i-stop { display: none; }
body[data-state="thinking"] .mic-btn .i-mic, body[data-state="speaking"] .mic-btn .i-mic { display: none; }
body[data-state="thinking"] .mic-btn .i-stop, body[data-state="speaking"] .mic-btn .i-stop { display: block; }

/* ---------- Auto-Modus: großer Kern, nur die letzte Antwort ---------- */
body.auto .stage { flex: 1; justify-content: center; }
body.auto .core { width: min(78vw, 48vh, 420px); }
body.auto .interim { font-size: 21px; }
body.auto .messages { flex: none; max-height: 30vh; }
body.auto .msg:not(:nth-last-child(-n+1)) { display: none; }
body.auto .empty { display: none; }
body.auto .text-form { display: none; }
body.auto .dock { justify-content: center; }
body.auto .mic-btn { width: 64px; height: 64px; }

/* ---------- Einstellungen ---------- */
.settings { border-radius: 22px; padding: 0; width: min(580px, calc(100vw - 24px)); max-height: calc(100dvh - 32px); color: var(--text); background: rgba(10, 15, 28, .92); overflow: auto; }
.settings::backdrop { background: rgba(2, 4, 10, .7); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.settings form { padding: 20px 22px 22px; display: grid; gap: 12px; }
.settings-head { display: flex; align-items: center; justify-content: space-between; }
.settings h2 { margin: 0; font-size: 20px; }
.section-label { font-family: var(--mono); font-size: 11px; letter-spacing: .22em; text-transform: uppercase; color: var(--cyan); margin-top: 10px; padding-bottom: 4px; border-bottom: 1px solid var(--line); }
.settings label { display: grid; gap: 6px; font-weight: 600; font-size: 14px; }
.settings small { font-weight: 400; color: var(--muted); }
.settings input[type=text], .settings textarea, .settings select { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: rgba(0, 0, 0, .35); font-weight: 400; outline: none; }
.settings input[type=text]:focus, .settings textarea:focus, .settings select:focus { border-color: var(--cyan); }
.settings input[type=range] { accent-color: var(--cyan); }
.settings textarea { resize: vertical; }
.settings .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.settings .row-inline { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.settings .check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.settings .check input { accent-color: var(--cyan); width: 18px; height: 18px; }
.hint { margin: 0; font-size: 13px; color: var(--muted); }
.meter-row { display: flex; align-items: center; gap: 12px; }
.meter { flex: 1; height: 12px; border-radius: 6px; background: rgba(255, 255, 255, .06); border: 1px solid var(--line); position: relative; overflow: hidden; }
.meter-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, var(--cyan), var(--green)); box-shadow: 0 0 12px var(--green); transition: width .06s linear; }
.meter-fill.hot { background: linear-gradient(90deg, var(--green), var(--magenta)); }
.meter-mark { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--magenta); box-shadow: 0 0 8px var(--magenta); left: 25%; }
.item-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.item-list li { display: flex; align-items: flex-start; gap: 8px; padding: 8px 10px; border-radius: 10px; background: rgba(255, 255, 255, .03); border: 1px solid var(--line); font-size: 14px; }
.item-list li .txt { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.item-list li .when { display: block; font-family: var(--mono); font-size: 11px; color: var(--cyan); letter-spacing: .05em; }
.item-list li.none { color: var(--muted); background: none; border-style: dashed; }
.item-list .icon-btn { padding: 2px 6px; }
.actions { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.spacer { flex: 1; }

/* ---------- Handy ---------- */
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  #menuBtn { display: grid; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(310px, 86vw); z-index: 20; transform: translateX(-102%); transition: transform .25s ease; background: rgba(8, 12, 24, .92); }
  .sidebar.open { transform: none; box-shadow: 0 0 60px rgba(0, 0, 0, .6); }
  .scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 10; }
  .settings .row { grid-template-columns: 1fr; }
  .msg .bubble { max-width: 92%; }
}
/* niedrige Bildschirme (Handy quer, Tastatur offen): Kern kleiner */
@media (max-height: 560px) {
  .core { width: min(40vw, 26vh, 200px); }
  .readout { min-height: 40px; }
}
@media (prefers-reduced-motion: reduce) {
  .login-core, .login-core span, .tool-chip, .msg { animation: none !important; }
}
