:root {
  --bg: #05080c;
  --panel: rgba(14, 24, 32, 0.72);
  --line: rgba(120, 220, 255, 0.16);
  --text: #d8f3ff;
  --muted: #6d8a98;
  --accent: #39d5ff;
  --armed: #7cffb2;
  --think: #b48cff;
  --speak: #39d5ff;
  --warn: #ffb347;
  --danger: #ff5c7a;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  background:
    radial-gradient(ellipse at 50% 18%, rgba(57, 213, 255, 0.10), transparent 60%),
    repeating-linear-gradient(0deg, transparent 0 3px, rgba(255, 255, 255, 0.012) 3px 4px),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.shell {
  max-width: 560px;
  min-height: 100%;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* ── Header ─────────────────────────────────────────── */
.bar { display: flex; align-items: center; gap: 10px; }
.brand { font: 600 15px/1 var(--mono); letter-spacing: 0.32em; flex: 1; }
.ver { color: var(--muted); font-size: 10px; letter-spacing: 0.1em; margin-left: 6px; vertical-align: super; }

.link {
  display: inline-flex; align-items: center; gap: 7px;
  font: 500 10px/1 var(--mono); letter-spacing: 0.18em; color: var(--muted);
  border: 1px solid var(--line); border-radius: 999px; padding: 6px 10px;
}
.link i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.link[data-state="online"] i { background: var(--armed); box-shadow: 0 0 8px var(--armed); }
.link[data-state="degraded"] i { background: var(--warn); box-shadow: 0 0 8px var(--warn); }
.link[data-state="offline"] i { background: var(--danger); }

.icon-btn {
  width: 34px; height: 34px; border-radius: 10px;
  border: 1px solid var(--line); background: transparent; color: var(--text);
  font-size: 16px; cursor: pointer;
}

/* ── Orb ────────────────────────────────────────────── */
.core { display: flex; flex-direction: column; align-items: center; padding-top: 12px; }

.orb {
  --c: var(--muted);
  position: relative; width: min(58vw, 230px); aspect-ratio: 1;
  border: 0; border-radius: 50%; background: transparent; cursor: pointer;
}
.orb[data-mode="standby"]  { --c: var(--accent); }
.orb[data-mode="armed"]    { --c: var(--armed); }
.orb[data-mode="thinking"] { --c: var(--think); }
.orb[data-mode="speaking"] { --c: var(--speak); }
.orb[data-mode="error"]    { --c: var(--danger); }

.ring, .nucleus { position: absolute; border-radius: 50%; inset: 0; margin: auto; }
.ring { border: 1px solid var(--c); opacity: 0.35; transition: border-color 0.4s, opacity 0.4s; }
.r1 { width: 100%; height: 100%; border-style: dashed; animation: spin 24s linear infinite; }
.r2 { width: 78%; height: 78%; border-width: 2px; border-color: transparent var(--c); animation: spin 9s linear infinite reverse; opacity: 0.6; }
.r3 { width: 56%; height: 56%; opacity: 0.5; }
.nucleus {
  width: 30%; height: 30%;
  background: radial-gradient(circle, var(--c) 0%, transparent 70%);
  box-shadow: 0 0 40px var(--c);
  opacity: 0.55; transition: background 0.4s, box-shadow 0.4s;
}

.orb[data-mode="offline"] .ring { animation-play-state: paused; }
.orb[data-mode="standby"] .nucleus { animation: breathe 3.6s ease-in-out infinite; }
.orb[data-mode="armed"] .nucleus { animation: breathe 0.9s ease-in-out infinite; opacity: 0.9; }
.orb[data-mode="armed"] .r3 { animation: ping 1.2s ease-out infinite; }
.orb[data-mode="thinking"] .r2 { animation-duration: 1.4s; }
.orb[data-mode="thinking"] .r1 { animation-duration: 6s; }
.orb[data-mode="speaking"] .nucleus { animation: pulse 0.45s ease-in-out infinite alternate; opacity: 0.9; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes breathe { 50% { transform: scale(1.18); opacity: 0.85; } }
@keyframes pulse { to { transform: scale(1.3); } }
@keyframes ping { from { transform: scale(1); opacity: 0.7; } to { transform: scale(1.7); opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .ring, .nucleus { animation: none !important; }
}

.mode { margin: 18px 0 4px; font: 600 13px/1.2 var(--mono); letter-spacing: 0.28em; text-align: center; }
.hint { margin: 0; color: var(--muted); font-size: 13px; text-align: center; min-height: 1.3em; }

/* ── Panel ──────────────────────────────────────────── */
.panel {
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.label { font: 500 10px/1 var(--mono); letter-spacing: 0.24em; color: var(--muted); margin-bottom: 8px; }
.transcript { margin: 0 0 18px; font: 15px/1.45 var(--mono); color: var(--armed); word-wrap: break-word; }
.answer { margin: 0; font-size: 17px; line-height: 1.55; white-space: pre-wrap; word-wrap: break-word; }
.answer.error { color: var(--danger); font-family: var(--mono); font-size: 14px; }
.answer:empty::before { content: "Awaiting query."; color: var(--muted); }

.sources { list-style: none; margin: 16px 0 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; }
.sources:empty { display: none; }
.sources li { counter-increment: src; min-width: 0; }
.sources a {
  display: flex; gap: 8px; align-items: baseline;
  color: var(--text); text-decoration: none; font-size: 13px;
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px;
  overflow: hidden;
}
.sources a::before { content: "[" counter(src) "]"; color: var(--accent); font-family: var(--mono); }
.sources a span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sources a small { color: var(--muted); margin-left: auto; flex-shrink: 0; font-family: var(--mono); }

/* ── Composer ───────────────────────────────────────── */
.composer { display: flex; gap: 8px; }
.composer input, .settings input[type="password"] {
  flex: 1; min-width: 0;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; font: 16px var(--sans); /* 16px stops iOS zoom-on-focus */
  outline: none;
}
.composer input:focus, .settings input:focus { border-color: var(--accent); }

button[type="submit"], .settings menu button {
  border: 1px solid var(--accent); background: rgba(57, 213, 255, 0.12); color: var(--accent);
  border-radius: 12px; padding: 0 16px; min-height: 44px;
  font: 600 12px var(--mono); letter-spacing: 0.2em; cursor: pointer;
}
.settings menu button.ghost { border-color: var(--line); background: transparent; color: var(--muted); }

/* ── Settings dialog ────────────────────────────────── */
.settings {
  width: min(92vw, 420px);
  background: #0b141b; color: var(--text);
  border: 1px solid var(--line); border-radius: 16px; padding: 20px;
}
.settings::backdrop { background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(4px); }
.settings h2 { margin: 0 0 16px; font: 600 13px var(--mono); letter-spacing: 0.28em; }
.settings label { display: grid; gap: 8px; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.settings label.check { display: flex; align-items: center; gap: 10px; color: var(--text); }
.settings .note { font: 12px var(--mono); color: var(--muted); word-break: break-all; }
.settings menu { display: flex; justify-content: flex-end; gap: 8px; margin: 16px 0 0; padding: 0; }
