:root {
  --bg: #02070d;
  --bg2: #06111c;
  --panel: rgba(8, 24, 38, .72);
  --panel-solid: #081826;
  --line: rgba(64, 200, 255, .16);
  --line-strong: rgba(64, 200, 255, .38);
  --text: #d8ecf7;
  --muted: #7b98ab;
  --accent: #3fd0ff;
  --accent-2: #8ef0ff;
  --glow: rgba(63, 208, 255, .45);
  --warn: #ffb547;
  --danger: #ff5d6c;
  --ok: #3ee39a;
  --user: rgba(63, 208, 255, .13);
  --radius: 14px;
  --font: "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Code", Consolas, "SF Mono", Menlo, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 15px/1.5 var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 700px at 30% 20%, rgba(20, 90, 140, .22), transparent 60%),
    radial-gradient(900px 600px at 90% 90%, rgba(10, 60, 100, .18), transparent 60%),
    var(--bg);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
body::before { /* feines HUD-Raster */
  content: "";
  position: fixed; inset: 0;
  background-image:
    linear-gradient(rgba(63, 208, 255, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(63, 208, 255, .035) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(circle at 40% 40%, #000 30%, transparent 85%);
  pointer-events: none;
}
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }
svg.i { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- Buttons & Formulare ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45em;
  padding: .55em 1.05em; border-radius: 10px; cursor: pointer;
  background: rgba(63, 208, 255, .08); border: 1px solid var(--line-strong); color: var(--text);
  transition: background .15s, border-color .15s, box-shadow .15s;
}
.btn:hover { background: rgba(63, 208, 255, .16); box-shadow: 0 0 14px rgba(63, 208, 255, .18); }
.btn.primary { background: linear-gradient(180deg, #34c3f2, #1690c4); border-color: transparent; color: #001522; font-weight: 600; }
.btn.primary:hover { box-shadow: 0 0 20px var(--glow); }
.btn.danger { border-color: rgba(255, 93, 108, .5); color: #ffc2c8; background: rgba(255, 93, 108, .08); }
.btn.small { padding: .3em .7em; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; cursor: pointer;
  background: transparent; border: 1px solid transparent; color: var(--muted);
}
.icon-btn:hover { color: var(--text); background: rgba(63, 208, 255, .08); border-color: var(--line); }
input[type=text], input[type=password], input[type=number], input[type=time], textarea, select {
  width: 100%; padding: .6em .8em; border-radius: 10px; outline: none;
  background: rgba(2, 10, 18, .7); border: 1px solid var(--line);
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(63, 208, 255, .12); }
label.field { display: grid; gap: .3em; font-size: 13px; color: var(--muted); }
label.check { display: inline-flex; align-items: center; gap: .5em; cursor: pointer; color: var(--muted); font-size: 14px; user-select: none; }
label.check input { accent-color: var(--accent); width: 16px; height: 16px; }

/* ---------- Anmeldung ---------- */
.login {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 20px; z-index: 50;
}
.login-card {
  width: min(400px, 100%); padding: 32px 28px; border-radius: 20px; text-align: center;
  background: var(--panel); border: 1px solid var(--line-strong); backdrop-filter: blur(14px);
  box-shadow: 0 0 60px rgba(0, 120, 180, .18);
}
.login-card .reactor { --size: 120px; margin: 0 auto 18px; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: .5em; font-weight: 600; padding-left: .5em; }
.login-card p { margin: 0 0 20px; color: var(--muted); font-size: 14px; }
.login-card form { display: grid; gap: 12px; text-align: left; }
.login-card .error { color: var(--danger); font-size: 14px; min-height: 1.2em; text-align: center; }

/* ---------- Layout ---------- */
.app { position: fixed; inset: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); grid-template-columns: minmax(0, 1fr); }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line); background: rgba(2, 8, 14, .6); backdrop-filter: blur(10px);
}
.brand { font-weight: 600; letter-spacing: .38em; font-size: 15px; display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.chips { display: flex; gap: 6px; margin-left: 8px; overflow: hidden; }
.chip {
  font-size: 12px; padding: 2px 9px; border-radius: 99px; border: 1px solid var(--line); color: var(--muted);
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #3a4b57; }
.chip.ok::before { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.chip.warn::before { background: var(--warn); }
.chip.off::before { background: var(--danger); }
.topbar .spacer { flex: 1; }

.control-bar {
  position: fixed; top: calc(60px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 20;
  display: flex; align-items: center; gap: 12px; padding: 8px 14px; border-radius: 12px; max-width: calc(100% - 24px);
  background: rgba(70, 10, 18, .92); border: 1px solid var(--danger); box-shadow: 0 0 30px rgba(255, 93, 108, .35);
  animation: rise .2s ease-out;
}
.control-bar span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.code-box { font: 600 28px/1.2 var(--mono); letter-spacing: .25em; color: var(--accent-2); text-align: center; padding: 10px;
  border: 1px dashed var(--line-strong); border-radius: 12px; }
.layout { display: grid; grid-template-columns: minmax(320px, 42%) minmax(0, 1fr); min-height: 0; min-width: 0; }
.layout > * { min-width: 0; }
.stage {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; padding: 24px; border-right: 1px solid var(--line); min-height: 0;
}
.chat { display: grid; grid-template-rows: minmax(0, 1fr) auto auto; min-height: 0; }
.attach-bar { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px clamp(10px, 3vw, 36px) 0; border-top: 1px solid var(--line); }
.file-chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding: 4px 10px; border-radius: 10px; font-size: 13px;
  background: rgba(63, 208, 255, .08); border: 1px solid var(--line-strong); color: var(--text); text-decoration: none;
}
.file-chip svg.i { width: 16px; height: 16px; color: var(--accent); }
.file-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip small { color: var(--muted); }
.file-chip button { background: none; border: none; color: var(--muted); cursor: pointer; padding: 0 0 0 4px; font-size: 15px; }
a.file-chip:hover { border-color: var(--accent); }
.msg .files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.msg.user .files { justify-content: flex-end; }

/* ---------- Arc-Reaktor ---------- */
.reactor { --size: min(34vh, 300px); position: relative; width: var(--size); height: var(--size); cursor: pointer; flex: none; }
.reactor canvas { position: absolute; inset: -18%; width: 136%; height: 136%; }
.reactor .ring { position: absolute; border-radius: 50%; inset: 0; }
.reactor .r1 {
  border: 2px solid transparent;
  background: conic-gradient(from 0deg, transparent 0 8%, var(--accent) 8% 22%, transparent 22% 33%, var(--accent) 33% 47%,
    transparent 47% 58%, var(--accent) 58% 72%, transparent 72% 83%, var(--accent) 83% 97%, transparent 97%) border-box;
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2px));
  opacity: .8; animation: spin 24s linear infinite;
}
.reactor .r2 {
  inset: 11%; border: 1px dashed rgba(63, 208, 255, .45); animation: spin 36s linear infinite reverse;
}
.reactor .r3 {
  inset: 22%;
  background: repeating-conic-gradient(from 0deg, rgba(63, 208, 255, .55) 0 2deg, transparent 2deg 10deg);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 10px), #000 calc(100% - 9px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 10px), #000 calc(100% - 9px));
  animation: spin 60s linear infinite;
}
.reactor .core {
  position: absolute; inset: 33%; border-radius: 50%;
  background: radial-gradient(circle, #e9fdff 0%, #8ef0ff 18%, #2cb8ea 42%, rgba(20, 120, 180, .35) 62%, transparent 72%);
  box-shadow: 0 0 40px var(--glow), 0 0 90px rgba(63, 208, 255, .25), inset 0 0 20px rgba(255, 255, 255, .5);
  animation: breathe 4s ease-in-out infinite;
}
.reactor[data-state=listening] .core { animation: breathe 1.2s ease-in-out infinite; }
.reactor[data-state=listening] .r1 { animation-duration: 8s; opacity: 1; }
.reactor[data-state=thinking] .r1 { animation-duration: 2.2s; }
.reactor[data-state=thinking] .r2 { animation-duration: 3.5s; }
.reactor[data-state=thinking] .r3 { animation-duration: 6s; }
.reactor[data-state=speaking] .core { animation: talk .45s ease-in-out infinite alternate; }
.reactor[data-state=error] .core { filter: hue-rotate(160deg) saturate(1.4); }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes breathe { 0%, 100% { transform: scale(.94); opacity: .9; } 50% { transform: scale(1.04); opacity: 1; } }
@keyframes talk { from { transform: scale(.95); } to { transform: scale(1.1); } }

.state-label { font-size: 13px; letter-spacing: .3em; text-transform: uppercase; color: var(--accent-2); min-height: 1.4em; text-align: center; }
.live { min-height: 2.8em; max-width: 90%; text-align: center; color: var(--muted); font-size: 15px; font-style: italic; }
.voice-controls { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px 18px; }
.mic-btn {
  width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; cursor: pointer;
  border: 1px solid var(--line-strong); background: radial-gradient(circle, rgba(63, 208, 255, .2), rgba(63, 208, 255, .04));
  color: var(--accent-2); transition: transform .12s, box-shadow .2s;
}
.mic-btn svg.i { width: 26px; height: 26px; }
.mic-btn:hover { box-shadow: 0 0 22px var(--glow); }
.mic-btn:active { transform: scale(.94); }
.mic-btn.active { background: radial-gradient(circle, rgba(255, 93, 108, .45), rgba(255, 93, 108, .08)); border-color: var(--danger); color: #fff; box-shadow: 0 0 26px rgba(255, 93, 108, .5); }
.quick { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 520px; }
.quick button {
  font-size: 13px; padding: .38em .9em; border-radius: 99px; cursor: pointer;
  background: rgba(63, 208, 255, .06); border: 1px solid var(--line); color: var(--muted);
}
.quick button:hover { color: var(--text); border-color: var(--line-strong); }

/* ---------- Chat ---------- */
.messages { overflow-y: auto; padding: 20px clamp(12px, 3vw, 36px) 12px; display: flex; flex-direction: column; gap: 14px; scroll-behavior: smooth; }
.empty { margin: auto; text-align: center; color: var(--muted); max-width: 380px; }
.empty h2 { color: var(--text); font-weight: 500; letter-spacing: .05em; }
.msg { display: flex; gap: 10px; max-width: min(820px, 100%); animation: rise .25s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.msg .avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: none; margin-top: 2px;
  background: radial-gradient(circle, #bdf6ff 0%, #2cb8ea 45%, #0b3953 72%); box-shadow: 0 0 12px var(--glow);
}
.msg .bubble {
  padding: 10px 14px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line);
  overflow-wrap: anywhere; min-width: 0;
}
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.user .bubble { background: var(--user); border-color: var(--line-strong); white-space: pre-wrap; }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 4px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.msg.user .meta { justify-content: flex-end; }
.bubble p { margin: 0 0 .6em; } .bubble p:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: .3em 0 .6em; padding-left: 1.3em; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 { font-size: 1em; margin: .6em 0 .3em; color: var(--accent-2); }
.bubble code { font-family: var(--mono); font-size: .9em; background: rgba(63, 208, 255, .1); padding: .1em .35em; border-radius: 5px; }
.bubble pre { background: rgba(0, 0, 0, .35); padding: 10px; border-radius: 8px; overflow-x: auto; }
.bubble pre code { background: none; padding: 0; }
.bubble table { border-collapse: collapse; margin: .4em 0; font-size: 14px; display: block; overflow-x: auto; }
.bubble th, .bubble td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; }
.bubble th { color: var(--accent-2); font-weight: 600; }
.bubble blockquote { margin: .4em 0; padding-left: 10px; border-left: 3px solid var(--line-strong); color: var(--muted); }
.tool-line { font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.tool-line span { padding: 1px 8px; border-radius: 99px; background: rgba(63, 208, 255, .07); border: 1px solid var(--line); }
.tool-line span.live::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; border: 2px solid var(--accent); border-right-color: transparent; animation: spin .8s linear infinite; vertical-align: -1px; }
.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); opacity: .4; animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 50% { opacity: 1; } }
.badge { font-size: 10.5px; padding: 0 6px; border-radius: 6px; border: 1px solid var(--line); color: var(--muted); letter-spacing: .03em; }

.card {
  align-self: stretch; max-width: min(820px, 100%); margin-left: 40px;
  border: 1px solid rgba(255, 181, 71, .45); background: rgba(40, 28, 8, .45); border-radius: var(--radius); padding: 12px 14px;
}
.card h4 { margin: 0 0 6px; color: var(--warn); font-size: 14px; display: flex; gap: 8px; align-items: center; }
.card pre { margin: 0 0 10px; white-space: pre-wrap; font: 14px/1.45 var(--font); color: var(--text); max-height: 280px; overflow: auto; }
.card .row { display: flex; gap: 8px; flex-wrap: wrap; }
.card.done { border-color: var(--line); background: var(--panel); opacity: .75; }
.card.secret { border-color: var(--line-strong); background: rgba(8, 40, 60, .5); }
.card.secret h4 { color: var(--accent-2); }
.card .row input { flex: 1; min-width: 180px; }

.composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 10px clamp(10px, 3vw, 36px) 14px;
  padding-bottom: max(14px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: rgba(2, 8, 14, .5);
}
.composer textarea { resize: none; max-height: 180px; min-height: 44px; line-height: 1.4; padding: .7em .9em; border-radius: 12px; }
.composer .send { width: 44px; height: 44px; border-radius: 12px; flex: none; }

/* ---------- Einstellungen ---------- */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(0, 4, 8, .6); backdrop-filter: blur(3px); z-index: 30; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(620px, 100%); z-index: 31; display: grid; grid-template-rows: auto auto 1fr;
  background: #040e17; border-left: 1px solid var(--line-strong); box-shadow: -20px 0 60px rgba(0, 0, 0, .5);
  padding-top: env(safe-area-inset-top);
}
.drawer header { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.drawer header h2 { margin: 0; font-size: 16px; letter-spacing: .2em; font-weight: 600; flex: 1; }
.tabs { display: flex; gap: 2px; padding: 8px 12px 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button {
  padding: 8px 12px; background: none; border: none; border-bottom: 2px solid transparent; color: var(--muted); cursor: pointer; white-space: nowrap;
}
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.pane { overflow-y: auto; padding: 18px; display: grid; gap: 18px; align-content: start; padding-bottom: max(18px, env(safe-area-inset-bottom)); }
.section { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 12px; background: rgba(8, 24, 38, .35); }
.section h3 { margin: 0; font-size: 14px; letter-spacing: .08em; color: var(--accent-2); font-weight: 600; }
.section p, .hint { margin: 0; color: var(--muted); font-size: 13px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.list { display: grid; gap: 6px; }
.list .item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; background: rgba(2, 10, 18, .6); border: 1px solid var(--line); }
.list .item .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.list .item small { color: var(--muted); display: block; }
.status-line { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.qr { background: #fff; padding: 12px; border-radius: 12px; width: 240px; max-width: 100%; justify-self: center; }
.qr img, .qr svg { display: block; width: 100%; height: auto; }
.copy { font-family: var(--mono); font-size: 12.5px; padding: 8px 10px; border-radius: 8px; background: rgba(0, 0, 0, .35); border: 1px solid var(--line); overflow-wrap: anywhere; cursor: copy; }
ol.steps { margin: 0; padding-left: 1.2em; color: var(--muted); font-size: 13px; display: grid; gap: 4px; }
ol.steps b { color: var(--text); font-weight: 600; }
details summary { cursor: pointer; color: var(--accent); font-size: 13px; }
.stat { display: flex; gap: 18px; flex-wrap: wrap; }
.stat div { font-size: 13px; color: var(--muted); }
.stat b { display: block; font-size: 20px; color: var(--text); font-weight: 600; }
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 60; padding: 10px 16px; border-radius: 12px;
  background: #0b2233; border: 1px solid var(--line-strong); box-shadow: 0 8px 30px rgba(0, 0, 0, .5); max-width: 90vw;
  animation: rise .2s ease-out;
}
.toast.error { border-color: var(--danger); }

/* ---------- Mobil ---------- */
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .stage {
    display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 8px 12px;
    grid-template-areas: "reactor label mic" "wake wake speak" "live live live" "quick quick quick";
    border-right: none; border-bottom: 1px solid var(--line); padding: 10px 12px;
  }
  .reactor { --size: 64px; grid-area: reactor; }
  .stage .state-label { grid-area: label; text-align: left; letter-spacing: .18em; font-size: 12px; }
  .voice-controls { display: contents; }
  #btn-mic { grid-area: mic; width: 52px; height: 52px; justify-self: end; }
  .voice-controls label:nth-of-type(1) { grid-area: wake; font-size: 13px; }
  .voice-controls label:nth-of-type(2) { grid-area: speak; font-size: 13px; justify-self: end; }
  .stage .live { grid-area: live; max-width: 100%; min-height: 0; font-size: 14px; text-align: left; }
  .stage .live:empty { display: none; }
  .quick { grid-area: quick; max-width: 100%; justify-content: flex-start; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
  .quick button { white-space: nowrap; }
  .chips { display: none; }
  .topbar { padding-left: 12px; padding-right: 8px; gap: 4px; }
  .messages { padding: 14px 10px 10px; }
  .msg .avatar { width: 24px; height: 24px; }
  .card { margin-left: 0; }
  .grid2 { grid-template-columns: 1fr; }
  .composer { padding-left: 8px; padding-right: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0s !important; animation-iteration-count: 1 !important; }
}
