/* JARVIS HUD und Orb. Wird nach style.css geladen und überschreibt nur Optik.
   Keine Webfonts, keine fremden Quellen: Systemschriften, alles lokal (CSP style-src 'self').
   Zustände über data-state am #jarvis-orb: idle | listening | thinking | speaking | error. */

:root {
  --bg: #05080d;
  --panel: rgba(10, 19, 29, .82);
  --panel-2: #0b1621;
  --line: #16314a;
  --text: #d7e6f2;
  --muted: #7f97ad;
  --accent: #4fc3f7;
  --hud-glow: rgba(79, 195, 247, .35);
  --hud-faint: rgba(79, 195, 247, .12);
  --hud-mono: ui-monospace, "SF Mono", "Cascadia Mono", "Segoe UI Mono", Consolas, "Roboto Mono", monospace;
}

body {
  background:
    radial-gradient(ellipse 90% 55% at 50% -5%, rgba(79, 195, 247, .13), transparent 70%),
    radial-gradient(ellipse 60% 40% at 50% 110%, rgba(21, 101, 192, .10), transparent 70%),
    linear-gradient(rgba(79, 195, 247, .035) 1px, transparent 1px) 0 0 / 34px 34px,
    linear-gradient(90deg, rgba(79, 195, 247, .035) 1px, transparent 1px) 0 0 / 34px 34px,
    var(--bg);
  background-attachment: fixed;
}

/* ---------------------------------------------------------------- Rahmen */

.topbar {
  background: rgba(4, 9, 15, .82);
  border-bottom: 1px solid rgba(79, 195, 247, .2);
  box-shadow: 0 1px 18px rgba(79, 195, 247, .06);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  padding-top: max(10px, env(safe-area-inset-top));
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}
.brand, .login h1 {
  font-family: var(--hud-mono);
  text-shadow: 0 0 12px var(--hud-glow);
}
.tab { font-family: var(--hud-mono); font-size: 13px; letter-spacing: .06em; }
.tab.active { border-color: rgba(79, 195, 247, .35); box-shadow: inset 0 -2px 0 var(--accent); }

.card { border-color: rgba(79, 195, 247, .18); box-shadow: 0 0 0 1px rgba(0, 0, 0, .3), 0 10px 30px rgba(0, 0, 0, .35); }

/* ---------------------------------------------------------------- HUD-Kopf */

.hud {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 4px 0 14px;
}
.hud-head {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}
.hud-head p { margin: 0; }
.hud-greeting {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--text);
}
.hud-meta {
  font-family: var(--hud-mono);
  font-size: 12px;
  color: var(--muted);
  letter-spacing: .08em;
}
.hud-meta time { color: var(--accent); font-size: 14px; margin-right: 8px; }
.hud-status {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-family: var(--hud-mono);
  font-size: 11px;
  letter-spacing: .08em;
  color: var(--muted);
  text-transform: uppercase;
}
.hud-item { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.hud-key { color: rgba(79, 195, 247, .65); }
#hud-model { color: var(--text); text-transform: none; letter-spacing: .02em; }
.hud-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warn);
  box-shadow: 0 0 6px currentColor;
  color: var(--warn);
}
.hud-conn[data-level="ok"] .hud-dot { background: var(--ok); color: var(--ok); }
.hud-conn[data-level="bad"] .hud-dot { background: var(--bad); color: var(--bad); }
.hud-conn[data-level="bad"] .hud-conn-text { color: var(--bad); }

.orb-wrap {
  --orb-size: 172px;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* Ringe ragen bis 26 % über den Orb hinaus, Abstand wächst mit der Größe mit */
  gap: calc(var(--orb-size) * .3);
  padding: calc(var(--orb-size) * .3) 0 4px;
}
.orb-label {
  font-family: var(--hud-mono);
  font-size: 12px;
  letter-spacing: .32em;
  text-transform: uppercase;
  color: rgba(var(--orb-rgb, 79, 195, 247), .9);
  padding-left: .32em; /* Ausgleich für letter-spacing, damit mittig */
}

.hud-briefing {
  font-family: var(--hud-mono);
  font-size: 12px;
  letter-spacing: .2em;
  text-transform: uppercase;
  background: rgba(79, 195, 247, .08);
  color: var(--accent);
  border: 1px solid rgba(79, 195, 247, .45);
  border-radius: 0;
  clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
  min-height: 40px;
  padding: 8px 20px;
  touch-action: manipulation;
  transition: background .2s, box-shadow .2s;
}
.hud-briefing:hover { background: rgba(79, 195, 247, .18); }
.hud-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.hud-autobrief { font-size: 12px; }
#tab-chat.hud-compact .hud-autobrief,
#tab-chat:has(#messages > *) .hud-autobrief { display: none; }

/* ---------------------------------------------------------------- Orb */

.orb {
  --orb-rgb: 79, 195, 247;
  --orb-rgb2: 21, 101, 192;
  position: relative;
  flex: none;
  width: var(--orb-size);
  height: var(--orb-size);
  border-radius: 50%;
  /* Grundkörper, sichtbar auch ohne orb.js */
  background: radial-gradient(circle at 36% 32%, #fff 0, rgba(var(--orb-rgb), .95) 16%, rgba(var(--orb-rgb2), .85) 52%, #041220 80%);
  box-shadow: 0 0 calc(var(--orb-size) * .3) rgba(var(--orb-rgb), .35);
  transition: width .45s ease, height .45s ease;
}
.orb[data-built] { background: none; box-shadow: none; }
/* Farben je Zustand */
.orb[data-state="listening"] { --orb-rgb: 0, 229, 255;  --orb-rgb2: 0, 131, 196; }
.orb[data-state="thinking"]  { --orb-rgb: 255, 189, 89; --orb-rgb2: 184, 104, 14; }
.orb[data-state="speaking"]  { --orb-rgb: 100, 255, 218; --orb-rgb2: 0, 145, 140; }
.orb[data-state="error"]     { --orb-rgb: 255, 92, 92;  --orb-rgb2: 140, 18, 32; }
/* Label übernimmt die Orb-Farbe über das gemeinsame Elternelement */
.orb-wrap:has(.orb[data-state="listening"]) { --orb-rgb: 0, 229, 255; }
.orb-wrap:has(.orb[data-state="thinking"])  { --orb-rgb: 255, 189, 89; }
.orb-wrap:has(.orb[data-state="speaking"])  { --orb-rgb: 100, 255, 218; }
.orb-wrap:has(.orb[data-state="error"])     { --orb-rgb: 255, 92, 92; }

.orb > span {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
}
.orb-halo {
  inset: -38%;
  background: radial-gradient(closest-side, rgba(var(--orb-rgb), .30), rgba(var(--orb-rgb), .08) 55%, transparent 100%);
  animation: orb-breathe 5s ease-in-out infinite;
}
.orb-ticks {
  inset: -16%;
  background: repeating-conic-gradient(rgba(var(--orb-rgb), .6) 0 1.2deg, transparent 1.2deg 7.5deg);
  -webkit-mask: radial-gradient(closest-side, transparent 88%, #000 89%, #000 99%, transparent 100%);
  mask: radial-gradient(closest-side, transparent 88%, #000 89%, #000 99%, transparent 100%);
  opacity: .7;
  animation: orb-spin 70s linear infinite;
}
.orb-arc { border: 2px solid transparent; }
.orb-arc.a1 {
  inset: -7%;
  border-top-color: rgba(var(--orb-rgb), .95);
  border-right-color: rgba(var(--orb-rgb), .3);
  filter: drop-shadow(0 0 4px rgba(var(--orb-rgb), .8));
  animation: orb-spin 14s linear infinite;
}
.orb-arc.a2 {
  inset: -26%;
  border-width: 1px;
  border-bottom-color: rgba(var(--orb-rgb), .7);
  border-left-color: rgba(var(--orb-rgb), .18);
  animation: orb-spin 24s linear infinite reverse;
}
.orb-wave {
  inset: 2%;
  border: 1.5px solid rgba(var(--orb-rgb), .7);
  opacity: 0;
}
.orb-core {
  inset: 4%;
  overflow: hidden;
  background:
    radial-gradient(circle at 36% 30%, rgba(255, 255, 255, .95) 0, rgba(255, 255, 255, 0) 22%),
    radial-gradient(circle at 50% 50%, rgba(var(--orb-rgb), .95) 0, rgba(var(--orb-rgb2), .9) 48%, #03101c 86%);
  box-shadow:
    0 0 calc(var(--orb-size) * .18) rgba(var(--orb-rgb), .55),
    inset 0 0 calc(var(--orb-size) * .12) rgba(255, 255, 255, .12),
    inset calc(var(--orb-size) * -.05) calc(var(--orb-size) * -.07) calc(var(--orb-size) * .14) rgba(0, 0, 0, .5);
  animation: orb-core-breathe 5s ease-in-out infinite;
  transition: box-shadow .5s ease;
}
/* Energieschlieren im Kern */
.orb-core::before {
  content: "";
  position: absolute;
  inset: -20%;
  background: conic-gradient(from 0deg, transparent 0 18%, rgba(255, 255, 255, .22) 24%, transparent 32% 58%, rgba(var(--orb-rgb), .45) 66%, transparent 76%);
  mix-blend-mode: screen;
  animation: orb-spin 12s linear infinite;
}
.orb-core::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(var(--orb-rgb), .5);
}

/* Zuhören: Wellen laufen nach außen */
.orb[data-state="listening"] .orb-wave { animation: orb-ripple 1.8s ease-out infinite; }
.orb[data-state="listening"] .orb-wave.w2 { animation-delay: .9s; }
.orb[data-state="listening"] .orb-arc.a1 { animation-duration: 6s; }
.orb[data-state="listening"] .orb-core { animation: none; transform: scale(1.03); }
.orb[data-state="listening"] .orb-halo { animation-duration: 1.8s; }

/* Denken: Bögen drehen schnell, Kern pulsiert */
.orb[data-state="thinking"] .orb-arc.a1 { animation-duration: 1.1s; }
.orb[data-state="thinking"] .orb-arc.a2 { animation-duration: 1.8s; border-style: dashed; }
.orb[data-state="thinking"] .orb-ticks { animation-duration: 9s; }
.orb[data-state="thinking"] .orb-core { animation: orb-core-pulse .9s ease-in-out infinite; }
.orb[data-state="thinking"] .orb-core::before { animation-duration: 2s; }

/* Sprechen: unruhiger Kern wie eine Stimme, schnelle Wellen */
.orb[data-state="speaking"] .orb-core { animation: orb-talk .62s ease-in-out infinite; }
.orb[data-state="speaking"] .orb-wave { animation: orb-ripple 1.1s ease-out infinite; }
.orb[data-state="speaking"] .orb-wave.w2 { animation-delay: .55s; }
.orb[data-state="speaking"] .orb-halo { animation: orb-breathe .62s ease-in-out infinite; }
.orb[data-state="speaking"] .orb-arc.a1 { animation-duration: 4s; }

/* Fehler: kurzes Flackern, danach ruhig rot */
.orb[data-state="error"] .orb-arc,
.orb[data-state="error"] .orb-ticks,
.orb[data-state="error"] .orb-core::before { animation-play-state: paused; }
.orb[data-state="error"] .orb-core { animation: orb-flicker .5s steps(2, end) 3; }
.orb[data-state="error"] .orb-halo { animation: none; }
.orb[data-state="error"] .orb-arc.a2 { border-style: dashed; }

@keyframes orb-spin { to { transform: rotate(360deg); } }
@keyframes orb-breathe {
  0%, 100% { opacity: .75; transform: scale(.97); }
  50% { opacity: 1; transform: scale(1.03); }
}
@keyframes orb-core-breathe {
  0%, 100% { transform: scale(.985); }
  50% { transform: scale(1.015); }
}
@keyframes orb-core-pulse {
  0%, 100% { transform: scale(.96); filter: brightness(.95); }
  50% { transform: scale(1.03); filter: brightness(1.2); }
}
@keyframes orb-talk {
  0% { transform: scale(1); }
  20% { transform: scale(1.06); }
  35% { transform: scale(.99); }
  55% { transform: scale(1.08); }
  75% { transform: scale(1.01); }
  100% { transform: scale(1); }
}
@keyframes orb-ripple {
  0% { opacity: .75; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.65); }
}
@keyframes orb-flicker {
  0% { opacity: 1; }
  50% { opacity: .45; }
  100% { opacity: 1; }
}

/* ---------------------------------------------------------------- Chatverlauf */

.messages { gap: 12px; padding-top: 4px; }
.msg { line-height: 1.55; }
.msg.user {
  background: rgba(79, 195, 247, .11);
  border: 1px solid rgba(79, 195, 247, .3);
  border-radius: 12px 2px 12px 12px;
}
.msg.assistant {
  background: rgba(9, 19, 29, .85);
  border: 1px solid rgba(79, 195, 247, .16);
  border-left: 2px solid var(--accent);
  border-radius: 2px 12px 12px 12px;
  box-shadow: 0 0 22px rgba(79, 195, 247, .05);
}
.msg .hint { font-family: var(--hud-mono); font-size: 11px; letter-spacing: .04em; }
.msg.system { font-family: var(--hud-mono); font-size: 12px; }

.composer {
  border-top: 1px solid rgba(79, 195, 247, .18);
  padding-bottom: env(safe-area-inset-bottom);
}
.composer textarea {
  background: rgba(6, 14, 22, .9);
  border-color: rgba(79, 195, 247, .22);
}
.composer textarea:focus { box-shadow: 0 0 0 3px rgba(79, 195, 247, .12); }

/* ---------------------------------------------------------------- Kompakt (Verlauf vorhanden) */

#tab-chat.hud-compact .hud,
#tab-chat:has(#messages > *) .hud {
  flex-direction: row;
  align-items: center;
  gap: 16px;
  padding: 0 0 10px;
  border-bottom: 1px solid rgba(79, 195, 247, .1);
  margin-bottom: 10px;
}
#tab-chat.hud-compact .orb-wrap,
#tab-chat:has(#messages > *) .orb-wrap { order: -1; padding: 6px; gap: 0; }
#tab-chat.hud-compact .orb-wrap,
#tab-chat:has(#messages > *) .orb-wrap { --orb-size: 64px; }
#tab-chat.hud-compact .orb-label,
#tab-chat:has(#messages > *) .orb-label {
  position: absolute;
  width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
#tab-chat.hud-compact .orb-ticks,
#tab-chat:has(#messages > *) .orb-ticks,
#tab-chat.hud-compact .orb-arc.a2,
#tab-chat:has(#messages > *) .orb-arc.a2 { display: none; }
#tab-chat.hud-compact .hud-head,
#tab-chat:has(#messages > *) .hud-head { flex: 1; min-width: 0; flex-direction: column; align-items: flex-start; gap: 4px; }
#tab-chat.hud-compact .hud-greeting,
#tab-chat:has(#messages > *) .hud-greeting { font-size: 16px; }

/* ---------------------------------------------------------------- Telefon */

@media (max-width: 600px) {
  .topbar {
    padding-left: max(10px, env(safe-area-inset-left));
    padding-right: max(10px, env(safe-area-inset-right));
  }
  .hud { gap: 6px; padding-bottom: 8px; }
  .hud-head { flex-direction: column; align-items: center; text-align: center; gap: 6px; }
  .hud-status { justify-content: center; gap: 10px; }
  .hud-greeting { font-size: 18px; }
  .orb-wrap { --orb-size: 128px; }
  /* iOS zoomt sonst beim Fokus in Felder unter 16 px */
  textarea, input, select { font-size: 16px; }

  #tab-chat.hud-compact .orb-wrap,
  #tab-chat:has(#messages > *) .orb-wrap { --orb-size: 46px; }
  #tab-chat.hud-compact .hud,
  #tab-chat:has(#messages > *) .hud { gap: 10px; }
  #tab-chat.hud-compact .hud-head,
  #tab-chat:has(#messages > *) .hud-head { text-align: left; }
  #tab-chat.hud-compact .hud-meta #hud-date,
  #tab-chat:has(#messages > *) .hud-meta #hud-date { display: none; }
  #tab-chat.hud-compact .hud-status,
  #tab-chat:has(#messages > *) .hud-status { justify-content: flex-start; font-size: 10px; }
  #tab-chat.hud-compact .hud-briefing,
  #tab-chat:has(#messages > *) .hud-briefing { padding: 8px 12px; letter-spacing: .12em; }
}

/* Sehr niedrige Bildschirme (Telefon quer): Orb klein halten */
@media (max-height: 520px) {
  .orb-wrap { --orb-size: 72px; }
}

/* ---------------------------------------------------------------- Ruhige Variante */

@media (prefers-reduced-motion: reduce) {
  .orb, .orb *, .orb *::before, .hud-briefing {
    animation: none !important;
    transition: none !important;
  }
  /* Zustände bleiben ohne Bewegung unterscheidbar: Farbe, Text, feste Ringe. */
  .orb-arc.a1 { transform: rotate(-30deg); }
  .orb-arc.a2 { transform: rotate(20deg); }
  .orb[data-state="listening"] .orb-wave.w1 { opacity: .55; transform: scale(1.18); }
  .orb[data-state="speaking"] .orb-wave.w1 { opacity: .5; transform: scale(1.14); }
  .orb[data-state="speaking"] .orb-wave.w2 { opacity: .25; transform: scale(1.32); }
  .orb[data-state="thinking"] .orb-arc.a1 { transform: rotate(60deg); }
}
