:root {
  --bg: #020203;
  --text: #ecedf1;
  --muted: #8a8d98;
  --faint: #4a4d57;
  --line: rgba(255, 255, 255, 0.08);
  --glass: rgba(255, 255, 255, 0.04);
  --danger: #ff6b81;
  --accent: #b9e6ff;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* No blue tap flash on Android/WebView, and no text selection when long-pressing controls */
* { -webkit-tap-highlight-color: transparent; }
button { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
button:focus:not(:focus-visible) { outline: none; }
html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font: 300 16px/1.5 Inter, system-ui, sans-serif;
  letter-spacing: -0.01em;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }

/* Soft falloff so particles fade into the dark edges */
.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(2, 2, 3, 0.85) 100%);
}

/* ---------- Header ---------- */
header {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px 32px;
  z-index: 2;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 500;
  font-size: 14px;
  letter-spacing: 0.32em;
  text-transform: uppercase;
}
.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--faint);
  transition: background 0.4s var(--ease), box-shadow 0.4s var(--ease);
}
body:not([data-state="idle"]) .dot { background: var(--accent); box-shadow: 0 0 12px var(--accent); }
body[data-state="connecting"] .dot { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }

.header-right { display: flex; align-items: center; gap: 16px; }
.sound {
  width: 32px; height: 32px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.2s var(--ease), background 0.2s var(--ease);
}
.sound:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }
.sound:focus-visible { outline: 2px solid var(--accent); }
.sound svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.sound .i-off, .sound.off .i-on { display: none; }
.sound.off .i-off { display: block; }

.clock { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; letter-spacing: 0.08em; }

/* Invisible hit area over the sphere */
.wake {
  position: fixed;
  top: 50%; left: 50%;
  aspect-ratio: 1;
  transform: translate(-50%, -58%);
  width: min(48vmin, 380px);
  border-radius: 50%;
  border: 0;
  background: transparent;
  cursor: pointer;
  z-index: 1;
}
.wake:disabled { cursor: default; }
.wake:focus-visible { outline: 1px solid var(--line); outline-offset: 8px; }

/* ---------- HUD ---------- */
.hud {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 0 16px 48px;
  z-index: 2;
  pointer-events: none;
}
.hud > * { pointer-events: auto; }

.status {
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--muted);
  transition: color 0.3s var(--ease);
}
body[data-state="speaking"] .status,
body[data-state="listening"] .status { color: var(--text); }

.caption {
  max-width: 640px;
  min-height: 3em;
  text-align: center;
  font-size: 20px;
  line-height: 1.5;
  color: var(--text);
  text-wrap: balance;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.error { color: var(--danger); font-size: 14px; text-align: center; max-width: 520px; }
.error:empty { display: none; }

.controls { display: flex; gap: 16px; }
.ctl {
  width: 56px; height: 56px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  color: var(--text);
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 8px 24px rgba(0, 0, 0, 0.4);
  transition: transform 0.2s var(--ease), background 0.2s var(--ease), border-color 0.2s var(--ease);
}
.ctl:hover { transform: translateY(-2px); background: rgba(255, 255, 255, 0.08); }
.ctl:active { transform: scale(0.96); }
.ctl:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.ctl svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.ctl .i-off { display: none; }
.ctl.muted { color: var(--danger); border-color: rgba(255, 107, 129, 0.35); }
.ctl.muted .i-mic { display: none; }
.ctl.muted .i-off { display: block; }
.ctl.end:hover { color: var(--danger); border-color: rgba(255, 107, 129, 0.35); }

/* ---------- Memory panel ---------- */
.log-toggle {
  position: fixed;
  right: 32px;
  bottom: 48px;
  z-index: 3;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--glass);
  backdrop-filter: blur(16px);
  color: var(--muted);
  font: 400 12px Inter, sans-serif;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  transition: color 0.2s var(--ease);
}
.log-toggle:hover, .log-toggle[aria-expanded="true"] { color: var(--text); }

.panel {
  position: fixed;
  top: 80px; right: 24px; bottom: 104px;
  width: 360px;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(10, 10, 12, 0.6);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  z-index: 3;
  opacity: 0;
  transform: translateX(16px);
  pointer-events: none;
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
  font-size: 14px;
  overflow: hidden;
}
.panel.open { opacity: 1; transform: none; pointer-events: auto; }

.tabs { display: flex; gap: 4px; padding: 8px; border-bottom: 1px solid var(--line); }
.tab {
  flex: 1;
  padding: 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font: 400 12px Inter, sans-serif;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.2s var(--ease), color 0.2s var(--ease);
}
.tab:hover { color: var(--text); }
.tab.active { background: rgba(255, 255, 255, 0.07); color: var(--text); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.pane { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.pane:empty::before, .empty { color: var(--faint); }
.log:empty::before { content: "Your conversation will appear here."; }
.who { font-size: 11px; font-weight: 500; letter-spacing: 0.16em; color: var(--muted); margin-bottom: 4px; }
.msg.user .who { color: var(--accent); }

.section-label { font-size: 11px; font-weight: 500; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); }

.fact {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
}
.fact-body { flex: 1; }
.fact .tag { font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--faint); margin-top: 4px; }
.del {
  flex: none;
  width: 24px; height: 24px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--faint);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  transition: color 0.2s var(--ease), background 0.2s var(--ease);
}
.del:hover { color: var(--danger); background: rgba(255, 107, 129, 0.1); }
.del:focus-visible { outline: 2px solid var(--accent); }

.conv { border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.03); }
.conv summary { list-style: none; cursor: pointer; padding: 12px; display: flex; gap: 12px; align-items: flex-start; }
.conv summary::-webkit-details-marker { display: none; }
.conv-title { font-weight: 400; color: var(--text); }
.conv-meta { font-size: 12px; color: var(--faint); margin: 4px 0; }
.conv-summary { color: var(--muted); font-size: 13px; }
.conv-lines { padding: 0 12px 12px; display: flex; flex-direction: column; gap: 12px; border-top: 1px solid var(--line); padding-top: 12px; }

/* ---------- Opening animation ---------- */
.boot {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -58%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  z-index: 4;
  pointer-events: none;
  transition: opacity 0.6s var(--ease), filter 0.6s var(--ease);
}
.boot.done { opacity: 0; filter: blur(6px); }
.boot-word {
  font-size: 32px;
  font-weight: 300;
  letter-spacing: 0.6em;
  margin-right: -0.6em; /* letter-spacing adds trailing space: keep the word optically centred */
  min-height: 1.2em;
  text-shadow: 0 0 24px rgba(185, 230, 255, 0.5);
}
.caret {
  display: inline-block;
  width: 2px; height: 0.9em;
  margin-left: 4px;
  vertical-align: -0.1em;
  background: var(--accent);
  animation: blink 0.8s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.boot-line { width: 160px; height: 1px; background: var(--line); overflow: hidden; }
.boot-line span {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  transform-origin: left;
  animation: load 2.2s var(--ease) forwards;
}
@keyframes load { from { transform: scaleX(0); } to { transform: scaleX(1); } }
.boot-sub { font-size: 11px; letter-spacing: 0.4em; text-transform: uppercase; color: var(--muted); }

/* Chrome fades in once the sphere has assembled */
header, .hud, .log-toggle { transition: opacity 0.8s var(--ease) 0.15s, transform 0.8s var(--ease) 0.15s; }
body.booting header, body.booting .hud, body.booting .log-toggle { opacity: 0; transform: translateY(8px); }
body.booting .wake { pointer-events: none; }

/* ---------- Floating result cards ---------- */
.cards {
  position: fixed;
  top: 50%;
  right: clamp(24px, calc(50% - 540px), 50%);
  transform: translateY(-58%);
  width: 300px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 2;
  pointer-events: none;
  transition: right 0.4s var(--ease);
}
body.panel-open .cards { right: 408px; }

.card {
  pointer-events: auto;
  touch-action: pan-y;
  cursor: pointer;
  animation: card-in 0.6s var(--ease) both;
  -webkit-user-select: none;
  user-select: none;
}
.card.leaving { animation: card-out 0.4s var(--ease) forwards; }
@keyframes card-in {
  from { opacity: 0; transform: translateX(-32px) scale(0.92); filter: blur(8px); }
  to { opacity: 1; transform: none; filter: none; }
}
@keyframes card-out { to { opacity: 0; transform: translateX(24px) scale(0.96); filter: blur(6px); } }

.card-inner {
  padding: 16px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(14, 16, 22, 0.55);
  backdrop-filter: blur(24px) saturate(140%);
  -webkit-backdrop-filter: blur(24px) saturate(140%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 12px 32px rgba(0, 0, 0, 0.45);
  animation: card-float 3s ease-in-out infinite alternate;
}
@keyframes card-float { from { transform: translateY(-4px); } to { transform: translateY(4px); } }

.card-head { display: flex; align-items: center; gap: 12px; }
.card-icon, .wx-icon, .gauge-bolt {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.card-icon { width: 20px; height: 20px; flex: none; color: var(--accent); }
.card-title { flex: 1; font-size: 14px; font-weight: 500; letter-spacing: 0.02em; }
.card-meta { font-size: 12px; color: var(--muted); }
.card-detail { margin-top: 8px; font-size: 14px; color: var(--muted); line-height: 1.45; }
.card-detail.strong { color: var(--text); }
.card-sub { margin-top: 4px; font-size: 12px; color: var(--muted); letter-spacing: 0.04em; }
.card-row { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 12px; font-size: 12px; color: var(--muted); letter-spacing: 0.04em; }
.card-list { list-style: none; margin-top: 12px; display: flex; flex-direction: column; gap: 8px; font-size: 14px; }
.card-list li { padding-left: 16px; position: relative; line-height: 1.4; }
.card-list li::before {
  content: "";
  position: absolute;
  left: 2px; top: 0.55em;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
}

/* weather */
.wx-main { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.wx-temp { font-size: 48px; font-weight: 200; line-height: 1; letter-spacing: -0.02em; }
.wx-icon { width: 44px; height: 44px; color: var(--accent); filter: drop-shadow(0 0 10px rgba(185, 230, 255, 0.45)); }
.wx-cond { margin-top: 8px; font-size: 14px; color: var(--muted); }

/* mac */
.mac-main { display: flex; align-items: center; gap: 16px; margin-top: 12px; }
.gauge { position: relative; width: 64px; height: 64px; flex: none; }
.ring { width: 64px; height: 64px; transform: rotate(-90deg); }
.ring-track, .ring-value { fill: none; stroke-width: 4; }
.ring-track { stroke: rgba(255, 255, 255, 0.08); }
.ring-value {
  stroke: var(--accent);
  stroke-linecap: round;
  filter: drop-shadow(0 0 4px var(--accent));
  transition: stroke-dashoffset 1.2s var(--ease) 0.2s;
}
.ring-value.low { stroke: var(--danger); filter: drop-shadow(0 0 4px var(--danger)); }
.gauge-label { position: absolute; inset: 0; display: grid; place-items: center; font-size: 14px; font-weight: 500; }
.gauge-bolt { position: absolute; right: -4px; top: -4px; width: 16px; height: 16px; color: #ffcf7a; fill: #ffcf7a; }
.mac-line { font-size: 14px; }
.mac-sub { margin-top: 4px; font-size: 12px; color: var(--muted); }

/* music equaliser */
.eq { display: flex; align-items: flex-end; gap: 3px; height: 14px; }
.eq span { width: 3px; height: 100%; background: var(--accent); border-radius: 2px; animation: eq 0.9s ease-in-out infinite alternate; }
.eq span:nth-child(2) { animation-delay: -0.3s; }
.eq span:nth-child(3) { animation-delay: -0.6s; }
@keyframes eq { from { transform: scaleY(0.25); } to { transform: scaleY(1); } }
.eq span { transform-origin: bottom; }

/* compact action chip */
.card-action .card-inner { padding: 12px 16px; }

/* confirm / warning */
.card-confirm .card-inner { border-color: rgba(255, 207, 122, 0.45); box-shadow: 0 0 24px rgba(255, 207, 122, 0.15), 0 12px 32px rgba(0, 0, 0, 0.45); }
.card-confirm .card-icon { color: #ffcf7a; }
.card-confirm .card-detail { color: var(--text); }
.card-warning .card-inner { border-color: rgba(255, 107, 129, 0.4); }
.card-warning .card-icon { color: var(--danger); }

.hidden { display: none !important; }

@media (max-width: 640px) {
  header { padding: 16px; }
  .hud { padding-bottom: 32px; }
  .caption { font-size: 16px; }
  .log-toggle { right: 16px; top: 64px; bottom: auto; }
  .panel { left: 16px; right: 16px; width: auto; top: 104px; bottom: 160px; }
  .cards { top: 72px; left: 16px; right: 16px; width: auto; transform: none; gap: 8px; }
  body.panel-open .cards { right: 16px; }
  .card-inner { padding: 12px 16px; }
  .wx-temp { font-size: 36px; }
  .boot-word { font-size: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  .card-inner { animation: none !important; }
  .boot { display: none; }
  * { transition-duration: 0.01ms !important; animation: none !important; }
}
