:root {
  --bg: #070b16;
  --bg2: #0d1430;
  --card: rgba(20, 28, 56, 0.72);
  --card-solid: #131b38;
  --line: rgba(140, 170, 255, 0.22);
  --text: #eaf0ff;
  --muted: #aab6d4;
  --accent: #7ce0ff;
  --accent-2: #8f8cff;
  --on-accent: #04101f;
  --ok: #7dffb0;
  --bad: #ff9aa8;
  --warn: #ffd37a;
  --focus: #ffffff;
  --radius: 18px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f3f6fd;
    --bg2: #e4eaf9;
    --card: rgba(255, 255, 255, 0.82);
    --card-solid: #ffffff;
    --line: rgba(30, 50, 120, 0.2);
    --text: #0d1630;
    --muted: #46547a;
    --accent: #0a58c9;
    --accent-2: #5a4fe0;
    --on-accent: #ffffff;
    --ok: #0b6b3a;
    --bad: #a3122b;
    --warn: #7a4b00;
    --focus: #0d1630;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font: 17px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.backdrop {
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(60vmax 40vmax at 85% -10%, rgba(143, 140, 255, 0.28), transparent 60%),
    radial-gradient(50vmax 40vmax at -10% 105%, rgba(124, 224, 255, 0.2), transparent 60%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%);
}
main { max-width: 780px; margin: 0 auto; padding: 16px; }

.sr-only {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
.skip {
  position: absolute; left: 12px; top: -80px; z-index: 50; padding: 10px 14px; border-radius: 10px;
  background: var(--accent); color: var(--on-accent); font-weight: 700; text-decoration: none;
}
.skip:focus { top: 12px; }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; border-radius: 8px; }

h1, h2, h3 { line-height: 1.2; margin: 0 0 12px; }
h1 { font-size: clamp(2.2rem, 8vw, 3.2rem); letter-spacing: 0.02em; }
h2 { font-size: 1.5rem; }
.h3, h3 { font-size: 1.15rem; }
h2:focus { outline: none; }

/* ---------- Orb ---------- */
.orb { position: relative; flex: none; --s: 52px; width: var(--s); height: var(--s); }
.orb-xl { --s: 150px; margin: 8px auto 4px; }
.orb-sm { --s: 44px; }
.orb .core {
  position: absolute; inset: 0; border-radius: 50%;
  background: radial-gradient(circle at 34% 28%, #fff 0, #bdf3ff 9%, #5fd4ff 30%, #6f6dff 64%, #1b1850 100%);
  box-shadow: 0 0 calc(var(--s) * 0.35) calc(var(--s) * 0.04) rgba(111, 109, 255, 0.55),
              inset calc(var(--s) * -0.08) calc(var(--s) * -0.1) calc(var(--s) * 0.2) rgba(0, 0, 40, 0.55);
  animation: float 6s ease-in-out infinite;
}
.orb .ring {
  position: absolute; inset: -16%; border-radius: 50%;
  border: 2px solid rgba(124, 224, 255, 0.55);
  transform: rotate(-18deg) scaleY(0.3);
  animation: spin 9s linear infinite;
}
.orb[data-state="listening"] .core { animation: breathe 1.1s ease-in-out infinite; box-shadow: 0 0 calc(var(--s) * 0.6) calc(var(--s) * 0.12) rgba(125, 255, 176, 0.55); }
.orb[data-state="thinking"] .ring { animation-duration: 1.6s; border-color: rgba(255, 211, 122, 0.8); }
.orb[data-state="speaking"] .core { animation: breathe 0.7s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-4%); } }
@keyframes breathe { 50% { transform: scale(1.09); } }
@keyframes spin { to { transform: rotate(342deg) scaleY(0.3); } }

/* ---------- Auth ---------- */
.auth { padding-top: 8px; }
.auth-hero { text-align: center; padding: 18px 0 8px; }
.tagline { color: var(--muted); margin: 0 auto; max-width: 30ch; }
.auth-card { margin-top: 16px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin: 0 0 14px;
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
}

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 5px; border-radius: 14px; background: rgba(120, 140, 220, 0.14); margin: 8px 0 14px; }
.seg-btn { min-height: 46px; border: 0; border-radius: 10px; background: transparent; color: var(--text); font: inherit; font-weight: 600; cursor: pointer; }
.seg-btn[aria-pressed="true"] { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--on-accent); }

.form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field label { font-weight: 600; }
.field.check { grid-template-columns: auto 1fr; align-items: start; gap: 12px; }
.field.check input { width: 26px; height: 26px; margin: 2px 0 0; accent-color: var(--accent); }
input[type="text"], input[type="email"], input[type="password"], select {
  width: 100%; min-height: 48px; padding: 10px 14px; font: inherit; color: var(--text);
  background: rgba(8, 12, 30, 0.55); border: 1px solid var(--line); border-radius: 12px;
}
@media (prefers-color-scheme: light) { :root:not([data-theme="dark"]) input[type="text"], :root:not([data-theme="dark"]) input[type="email"], :root:not([data-theme="dark"]) input[type="password"], :root:not([data-theme="dark"]) select { background: #fff; } }
select option { color: #0d1630; background: #fff; }

.btn {
  min-height: 48px; padding: 10px 20px; border-radius: 14px; border: 1px solid var(--line);
  background: rgba(120, 140, 220, 0.16); color: var(--text); font: inherit; font-weight: 700; cursor: pointer;
}
.btn.primary { border: 0; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--on-accent); }
.btn.icon { width: 52px; padding: 0; display: grid; place-items: center; }
.btn[aria-pressed="true"] { background: var(--ok); color: #04210f; border-color: transparent; }
.btn:disabled { opacity: 0.6; cursor: progress; }
.link { background: none; border: 0; color: var(--accent); font: inherit; text-decoration: underline; min-height: 44px; cursor: pointer; justify-self: start; }
.hint { color: var(--muted); font-size: 0.93rem; margin: 6px 0; }
.msg { margin: 8px 0; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 154, 168, 0.12); color: var(--text); }
.msg.ok { background: rgba(125, 255, 176, 0.12); }
.msg::before { content: attr(data-prefix); font-weight: 700; margin-right: 6px; }

/* ---------- App shell ---------- */
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 6px 2px 10px; }
.brand { display: flex; align-items: center; gap: 14px; }
.brand-name { margin: 0; font-weight: 800; font-size: 1.25rem; letter-spacing: 0.02em; }
.ver { font-size: 0.72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); vertical-align: middle; }
.top-status { margin: 0; color: var(--muted); font-size: 0.9rem; }

.nav { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 12px; scroll-snap-type: x proximity; -webkit-overflow-scrolling: touch; }
.nav button {
  flex: none; min-height: 44px; padding: 8px 16px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); font: inherit; font-weight: 600; white-space: nowrap; cursor: pointer; scroll-snap-align: start;
}
.nav button[aria-current="page"] { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--on-accent); border-color: transparent; }

.panel { padding-top: 6px; }

/* ---------- Conversation ---------- */
.log {
  display: flex; flex-direction: column; gap: 12px; min-height: 220px; max-height: 52vh; overflow-y: auto;
  padding: 14px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--card);
}
.bubble { max-width: 92%; padding: 12px 16px; border-radius: 18px; overflow-wrap: anywhere; }
.bubble.user { align-self: flex-end; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--on-accent); border-bottom-right-radius: 6px; }
.bubble.darwin { align-self: flex-start; background: var(--card-solid); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.bubble .who { display: block; font-size: 0.8rem; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; opacity: 0.8; margin-bottom: 2px; }
.bubble details { margin-top: 8px; font-size: 0.92rem; color: var(--muted); }
.bubble summary { cursor: pointer; min-height: 32px; display: flex; align-items: center; font-weight: 600; }
.bubble dl { display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px; margin: 6px 0 0; }
.bubble dt { font-weight: 700; }
.bubble dd { margin: 0; overflow-wrap: anywhere; }
.empty-log { color: var(--muted); margin: auto; text-align: center; }

.chips { display: flex; flex-wrap: nowrap; gap: 8px; margin: 12px 0 4px; overflow-x: auto; padding-bottom: 6px; -webkit-overflow-scrolling: touch; }
.chip { flex: none; white-space: nowrap; min-height: 44px; padding: 8px 14px; border-radius: 999px; border: 1px dashed var(--line); background: transparent; color: var(--text); font: inherit; cursor: pointer; }
.composer { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; margin-top: 10px; align-items: center; }

/* ---------- Data views ---------- */
.dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.dl dt { font-weight: 700; color: var(--muted); }
.dl dd { margin: 0; overflow-wrap: anywhere; }
.meter { width: 100%; height: 14px; accent-color: var(--accent); }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.list { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.item { padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); }
.item h3 { margin-bottom: 6px; }
.tag { display: inline-block; font-size: 0.78rem; font-weight: 700; padding: 1px 9px; border-radius: 999px; border: 1px solid var(--line); margin-left: 6px; color: var(--muted); vertical-align: middle; }
.tag.good { color: var(--ok); }
.tag.bad { color: var(--bad); }
.tag.warn { color: var(--warn); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 14px; background: var(--card); }
table { border-collapse: collapse; width: 100%; font-size: 0.95rem; }
caption { text-align: left; padding: 12px 14px; font-weight: 700; }
th, td { text-align: left; padding: 10px 14px; border-top: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 700; white-space: nowrap; }
.tests-body { margin-top: 16px; }
.result { padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); }
.result q { display: block; color: var(--muted); margin-top: 6px; font-size: 0.93rem; quotes: none; }
.summary-line { font-size: 1.15rem; font-weight: 800; margin: 0 0 12px; }

.netbar { position: sticky; top: 0; z-index: 20; padding: 10px 16px; text-align: center; background: var(--warn); color: #1d1400; font-weight: 700; }

@media (max-width: 480px) {
  body { font-size: 16.5px; }
  .composer { grid-template-columns: 1fr auto; }
  .composer #say { grid-column: 1 / -1; }
  .composer .btn.primary { min-width: 0; }
  .dl { grid-template-columns: 1fr; gap: 0 0; }
  .dl dd { margin-bottom: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  .orb .core, .orb .ring { animation: none !important; }
  * { scroll-behavior: auto !important; transition: none !important; }
}
@media (forced-colors: active) {
  .btn.primary, .seg-btn[aria-pressed="true"], .nav button[aria-current="page"] { border: 2px solid CanvasText; }
}

/* ---------- missions & simulator ---------- */
.btn.small { min-height: 44px; padding: 8px 16px; }
.bubble .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.item h4 { margin: 12px 0 4px; font-size: 0.95rem; color: var(--muted); }
.steps { margin: 4px 0 0; padding-left: 1.3em; }
.plain { margin: 4px 0 0; padding-left: 1.1em; }
.mission .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.sim .row { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.sim .field { margin: 10px 0; }
.tag.bad { color: var(--bad); }
