:root {
  --bg: #0f1022;
  --bg-2: #171a3a;
  --text: #f4f5fc;
  --muted: #a6a8d0;
  --accent: #e0564c;
  --accent-2: #b0263f;
  --accent-glow: rgba(224, 86, 76, 0.55);
  --ok: #46c07d;
  --warn: #e6ad48;
  --err: #ec5b52;

  --glass-bg: rgba(255, 255, 255, 0.07);
  --glass-brd: rgba(255, 255, 255, 0.14);
  --glass-hi: rgba(255, 255, 255, 0.22);
  --blur: 22px;
  --radius: 22px;

  --amp: 0; /* 0..1, aus der Lautstärke (per Skript gesetzt) */
  font-size: 16px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Roboto Condensed", "Helvetica Neue", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.muted {
  color: var(--muted);
}
.error {
  color: var(--err);
  font-size: 0.9rem;
  margin: 4px 0 0;
}
[hidden] {
  display: none !important;
}

/* ── Hintergrund: bewegte Farbverläufe ──────────────────── */
.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  background: radial-gradient(120% 80% at 50% -10%, #24264f 0%, var(--bg) 55%);
}

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.55;
  will-change: transform;
}

.blob.b1 {
  width: 60vmax;
  height: 60vmax;
  left: -20vmax;
  top: -18vmax;
  background: radial-gradient(circle, #e0564c, transparent 60%);
  animation: drift1 22s ease-in-out infinite;
}
.blob.b2 {
  width: 55vmax;
  height: 55vmax;
  right: -22vmax;
  top: 10vmax;
  background: radial-gradient(circle, #5b2bd6, transparent 60%);
  animation: drift2 27s ease-in-out infinite;
}
.blob.b3 {
  width: 50vmax;
  height: 50vmax;
  left: 10vmax;
  bottom: -26vmax;
  background: radial-gradient(circle, #2b6bd6, transparent 60%);
  animation: drift3 24s ease-in-out infinite;
}

.grain {
  position: absolute;
  inset: -50%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.35'/%3E%3C/svg%3E");
  opacity: 0.03;
  mix-blend-mode: overlay;
}

@keyframes drift1 {
  0%, 100% { transform: translate3d(0, 0, 0) scale(1); }
  50% { transform: translate3d(6vmax, 4vmax, 0) scale(1.08); }
}
@keyframes drift2 {
  0%, 100% { transform: translate3d(0, 0, 0) scale(1); }
  50% { transform: translate3d(-5vmax, 6vmax, 0) scale(1.1); }
}
@keyframes drift3 {
  0%, 100% { transform: translate3d(0, 0, 0) scale(1); }
  50% { transform: translate3d(4vmax, -5vmax, 0) scale(1.06); }
}

/* ── Glas ──────────────────────────────────────────────── */
.glass {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(160%);
  backdrop-filter: blur(var(--blur)) saturate(160%);
  border: 1px solid var(--glass-brd);
  box-shadow:
    inset 0 1px 0 var(--glass-hi),
    inset 0 -12px 30px rgba(0, 0, 0, 0.18),
    0 18px 40px -18px rgba(0, 0, 0, 0.55);
}

/* ── Anmeldung ─────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 20;
}

.card {
  width: min(380px, 100%);
  border-radius: var(--radius);
  padding: 30px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: rise 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.card h1 {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: 0.5px;
}

input,
select,
button {
  font: inherit;
}

input[type="password"] {
  padding: 15px 16px;
  border-radius: 14px;
  border: 1px solid var(--glass-brd);
  background: rgba(0, 0, 0, 0.22);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
input[type="password"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-glow);
}

button {
  cursor: pointer;
  border: 0;
  border-radius: 14px;
}

.btn-primary {
  padding: 15px 16px;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.3px;
  box-shadow: 0 10px 24px -8px var(--accent-glow);
  transition: transform 0.08s ease, box-shadow 0.2s ease;
}
.btn-primary:active {
  transform: scale(0.98);
}

/* ── Aufbau der App ────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 620px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 10px) 14px
    calc(env(safe-area-inset-bottom) + 14px);
  gap: 12px;
}

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-radius: 999px;
  animation: rise 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.brand {
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  font-size: 0.95rem;
}

.cost {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--glass-brd);
  color: var(--text);
  font-weight: 600;
  font-size: 0.78rem;
  padding: 8px 13px;
  border-radius: 999px;
  transition: transform 0.08s ease;
}
.cost:active {
  transform: scale(0.96);
}

/* ── Gesprächsverlauf ──────────────────────────────────── */
.transcript {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  justify-content: flex-start; /* Inhalt wächst von oben nach unten */
  gap: 9px;
  padding: 4px 2px;
  mask-image: linear-gradient(to bottom, transparent, #000 16px, #000 calc(100% - 8px), transparent);
}

.msg {
  max-width: 84%;
  padding: 10px 15px;
  border-radius: 18px;
  line-height: 1.38;
  word-break: break-word;
  animation: fadein 0.28s ease both;
  font-size: 0.98rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Blinkender Cursor an der Zeile, die gerade geschrieben wird */
.msg.streaming .msg-text::after {
  content: "▌";
  margin-left: 1px;
  opacity: 0.55;
  animation: blink 1s step-end infinite;
}

.msg-label {
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  opacity: 0.65;
}

.msg-text {
  white-space: pre-wrap;
}

.msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  color: #fff;
  border-bottom-right-radius: 6px;
  box-shadow: 0 10px 22px -12px var(--accent-glow);
}

.msg.ai {
  align-self: flex-start;
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  border: 1px solid var(--glass-brd);
  border-bottom-left-radius: 6px;
}

.msg.sys {
  align-self: center;
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
  max-width: 92%;
}
.msg.sys.welcome {
  margin-top: 4px;
}

/* ── Notiz-Karte ───────────────────────────────────────── */
.note-card {
  border-radius: var(--radius);
  padding: 14px 16px;
  animation: rise 0.35s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.note-card-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 0.95rem;
}

.note-card-head .dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--warn);
  box-shadow: 0 0 12px currentColor;
  color: var(--warn);
}
.note-card.saved .dot {
  background: var(--ok);
  color: var(--ok);
}
.note-card.failed .dot {
  background: var(--err);
  color: var(--err);
}

.note-body {
  font-size: 0.88rem;
  color: var(--muted);
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 12px;
}
.note-body b {
  color: var(--text);
  font-weight: 600;
}

.note-status {
  margin-top: 9px;
  font-size: 0.84rem;
}

/* ── Steuerleiste unten ────────────────────────────────── */
.dock {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.status-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 32px;
}

.status {
  font-size: 0.9rem;
  color: var(--muted);
  transition: color 0.25s;
}

.pill-btn {
  flex-shrink: 0;
  border: 1px solid var(--glass-brd);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.08s ease;
}
.pill-btn:active {
  transform: scale(0.95);
}
.status[data-tone="listen"] { color: var(--ok); }
.status[data-tone="speak"] { color: var(--accent); }
.status[data-tone="error"] { color: var(--err); }

/* ── Segmentierte Umschalter ───────────────────────────── */
.switches {
  width: 100%;
  display: flex;
  gap: 8px;
}

.seg {
  position: relative;
  flex: 1;
  display: flex;
  padding: 3px;
  border-radius: 999px;
  isolation: isolate;
}
#mode-seg {
  flex: 1.7;
}

.seg button {
  position: relative;
  z-index: 1;
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 8px 4px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.2s ease;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.seg button.on {
  color: #fff;
}

.seg-thumb {
  position: absolute;
  z-index: 0;
  top: 3px;
  bottom: 3px;
  left: 3px;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  box-shadow: 0 6px 16px -8px var(--accent-glow);
  transition: left 0.28s cubic-bezier(0.3, 0.9, 0.3, 1),
    width 0.28s cubic-bezier(0.3, 0.9, 0.3, 1);
}

/* Eigene Nachricht ist antippbar (bearbeiten) */
.msg.editable {
  cursor: text;
}
.msg.editable:active {
  filter: brightness(1.08);
}

/* ── Ein-/Ausgabe-Leiste (schreiben + Mikrofon) ────────── */
.input-bar {
  width: 100%;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 6px 6px 6px 16px;
  border-radius: 26px;
}

.input-bar textarea {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.98rem;
  line-height: 1.35;
  resize: none;
  outline: none;
  max-height: 120px;
  padding: 10px 0;
}
.input-bar textarea::placeholder {
  color: var(--muted);
}
.input-bar textarea:disabled {
  opacity: 0.5;
}

.icon-btn {
  flex-shrink: 0;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 0;
  color: #fff;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.2s ease, box-shadow 0.2s ease;
  touch-action: none;
}
.icon-btn:active {
  transform: scale(0.92);
}
.icon-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.icon-btn.send {
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  box-shadow: 0 8px 20px -8px var(--accent-glow);
}
.icon-btn.send svg {
  transform: rotate(0deg);
}

/* Mikrofon: aus = dezent, an = grün + pulsiert mit der Lautstärke */
.icon-btn.mic {
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid var(--glass-brd);
  color: var(--muted);
}
.icon-btn.mic.on {
  background: linear-gradient(135deg, #3ec27e, #1f7d59);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 0 0 4px rgba(70, 192, 125, calc(0.12 + var(--amp) * 0.35)),
    0 8px 22px -6px rgba(70, 192, 125, 0.55);
  transform: scale(calc(1 + var(--amp) * 0.08));
}
.icon-btn.mic.held {
  background: linear-gradient(135deg, #3ec27e, #1f7d59);
  color: #fff;
  border-color: transparent;
}

.hint {
  margin: 2px 8px 0;
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
  opacity: 0.8;
}

/* ── Animationen ───────────────────────────────────────── */
@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadein {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes blink {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .blob,
  .msg,
  .card,
  .bar,
  .note-card {
    animation: none !important;
  }
  .icon-btn.mic.on {
    transform: none;
  }
  * {
    transition-duration: 0.01ms !important;
  }
}
