:root {
  --bg: #05060b;
  --bg-2: #0b0e1a;
  --text: rgba(255, 255, 255, 0.93);
  --text-dim: rgba(255, 255, 255, 0.55);
  --text-faint: rgba(255, 255, 255, 0.34);
  --glass: rgba(255, 255, 255, 0.07);
  --glass-strong: rgba(255, 255, 255, 0.12);
  --line: rgba(255, 255, 255, 0.09);
  --accent: #7c8cff;
  --live: #ff5a8a;
  --ok: #4fe0b0;
  --radius: 22px;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background:
    radial-gradient(120% 70% at 50% 20%, #10142b 0%, var(--bg) 60%),
    var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, sans-serif;
  overflow: hidden;
}
button, input { font: inherit; color: inherit; }

.app {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  grid-template-columns: minmax(0, 1fr);
  max-width: 640px;
  margin: 0 auto;
  padding: env(safe-area-inset-top) 16px calc(env(safe-area-inset-bottom) + 12px);
}

/* Top bar */
.top { display: flex; align-items: center; justify-content: space-between; height: 56px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: 0.02em; font-size: 18px; }
.brand-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); transition: background .3s, box-shadow .3s; }
.brand-dot.live { background: var(--live); box-shadow: 0 0 12px var(--live); }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: transparent; fill: var(--text-dim);
  display: grid; place-items: center; cursor: pointer;
}
.icon-btn:hover { background: var(--glass); }

/* Orb */
.stage { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 0; }
.orb-wrap {
  position: relative;
  width: min(72vw, 46dvh, 380px);
  aspect-ratio: 1;
  cursor: pointer;
  outline: none;
  border-radius: 50%;
  transition: transform .25s ease;
}
.orb-wrap:active { transform: scale(0.97); }
.orb-wrap:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.orb-glow, .orb-core { position: absolute; inset: 0; width: 100%; height: 100%; }
.orb-glow { filter: blur(26px) saturate(1.5); transform: scale(1.18); opacity: 0.9; }
.orb-core { filter: saturate(1.2); }

.status { margin-top: 10px; font-size: 17px; font-weight: 550; min-height: 1.45em; text-align: center; }
.substatus { color: var(--text-dim); font-size: 13.5px; min-height: 1.4em; text-align: center; }

/* Chat */
.chat {
  overflow-y: auto;
  max-height: 34dvh;
  padding: 18px 2px 8px;
  display: flex; flex-direction: column; gap: 10px;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 28px);
  mask-image: linear-gradient(to bottom, transparent 0, #000 28px);
  scrollbar-width: none;
}
.chat::-webkit-scrollbar { display: none; }
.msg { max-width: 86%; animation: rise .28s ease both; overflow-wrap: anywhere; }
.msg.user {
  align-self: flex-end; background: var(--glass-strong); padding: 9px 14px; border-radius: 18px 18px 6px 18px;
}
.msg.zbot { align-self: flex-start; padding: 2px 2px; font-size: 16.5px; }
.msg.zbot.proactive::before { content: "🔔 "; }
.msg.pending { color: var(--text-faint); }
.msg.tool {
  align-self: flex-start; font: 12.5px/1.3 ui-monospace, "Cascadia Code", Consolas, monospace;
  color: var(--text-faint); padding: 0 2px;
}
.msg.error { align-self: center; color: #ff8a8a; font-size: 13.5px; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Composer */
.composer {
  display: flex; align-items: center; gap: 8px;
  background: var(--glass); border: 1px solid var(--line);
  border-radius: 999px; padding: 6px 6px 6px 18px; margin-top: 8px;
}
.composer input { flex: 1; min-width: 0; background: transparent; border: 0; outline: none; padding: 8px 0; font-size: 16px; }
.composer input::placeholder { color: var(--text-faint); }
.round-btn {
  width: 42px; height: 42px; border-radius: 50%; border: 0; display: grid; place-items: center;
  cursor: pointer; flex: none; transition: background .2s, transform .15s, opacity .2s;
}
.round-btn:active { transform: scale(0.92); }
.send-btn { background: var(--glass-strong); }
.send-btn:disabled { opacity: 0.35; cursor: default; }
.mic-btn { background: linear-gradient(135deg, #6a7bff, #b06bff); color: white; }
.mic-btn .stop-icon { display: none; }
.mic-btn.live { background: var(--live); box-shadow: 0 0 0 6px rgba(255, 90, 138, 0.18); }
.mic-btn.live .mic-icon { display: none; }
.mic-btn.live .stop-icon { display: block; }

/* Sheet */
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); backdrop-filter: blur(2px); z-index: 10; }
.sheet {
  position: fixed; left: 50%; bottom: 0; transform: translateX(-50%);
  width: min(640px, 100%); max-height: 85dvh; overflow-y: auto; z-index: 11;
  background: var(--bg-2); border: 1px solid var(--line); border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 8px 16px calc(env(safe-area-inset-bottom) + 16px);
  animation: sheet-up .25s ease both;
}
@keyframes sheet-up { from { transform: translate(-50%, 30px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 6px auto 12px; }
.caps { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.cap { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: var(--glass); color: var(--text-dim); }
.cap.on { color: var(--ok); }
.sheet-item {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%;
  background: transparent; border: 0; border-top: 1px solid var(--line); padding: 14px 4px; text-align: left; cursor: pointer;
}
.sheet-item small { color: var(--text-faint); font-size: 13px; }
.sheet-item.toggle { flex-direction: row; justify-content: space-between; align-items: center; }
.sheet-item.toggle input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; margin-left: 12px; }
.toggle-text { display: flex; flex-direction: column; gap: 2px; }
.usage { padding: 6px 4px 12px; }
.usage-row { display: flex; justify-content: space-between; font-size: 15px; padding-top: 6px; }
.usage-row b { font-weight: 650; }
.usage-detail { color: var(--text-faint); font-size: 12.5px; }
.usage-note { color: var(--text-faint); font-size: 11.5px; margin-top: 8px; }
.memory-view { border-top: 1px solid var(--line); padding: 12px 4px; font-size: 14px; color: var(--text-dim); }
.memory-view h4 { margin: 10px 0 4px; color: var(--text); font-size: 13px; text-transform: uppercase; letter-spacing: .06em; }
.memory-view ul { margin: 0; padding-left: 18px; }

/* PIN */
.overlay { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: rgba(5, 6, 11, 0.92); padding: 16px; }
.pin-card { width: min(340px, 100%); display: flex; flex-direction: column; gap: 10px; text-align: center; }
.pin-title { font-size: 20px; font-weight: 650; }
.pin-sub { color: var(--text-dim); font-size: 14px; }
.pin-card input {
  margin-top: 8px; text-align: center; font-size: 22px; letter-spacing: .3em; padding: 12px;
  border-radius: 14px; border: 1px solid var(--line); background: var(--glass); outline: none;
}
.pin-card input:focus { border-color: var(--accent); }
.pin-go { padding: 12px; border-radius: 14px; border: 0; background: linear-gradient(135deg, #6a7bff, #b06bff); font-weight: 600; cursor: pointer; }
.pin-err { color: #ff8a8a; min-height: 1.4em; font-size: 14px; }

/* Toast */
.toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 64px); transform: translate(-50%, -12px);
  background: var(--bg-2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 14px;
  font-size: 14px; max-width: calc(100% - 32px); opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; z-index: 30;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-height: 760px) { .chat { max-height: 38dvh; } }
@media (prefers-reduced-motion: reduce) { .msg, .sheet { animation: none; } }

/* Who's talking */
.who { position: relative; margin-left: auto; margin-right: 4px; }
.who-chip {
  border: 1px solid var(--line); background: var(--glass); border-radius: 999px; padding: 6px 12px;
  font-size: 13px; color: var(--text-dim); cursor: pointer;
}
.who-chip b { color: var(--text); font-weight: 600; }
.who-pop {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 15; min-width: 170px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; padding: 6px; box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
.who-pop button { display: block; width: 100%; text-align: left; background: transparent; border: 0; padding: 9px 10px; border-radius: 10px; cursor: pointer; }
.who-pop button:hover, .who-pop button.on { background: var(--glass); }
.who-pop button.on::after { content: " ✓"; color: var(--ok); }

/* Now playing */
.now-playing {
  display: flex; align-items: center; gap: 10px; margin-top: 8px; padding: 8px 8px 8px 14px;
  border-radius: 999px; background: linear-gradient(90deg, rgba(255,120,92,.16), rgba(196,92,255,.16)); border: 1px solid var(--line);
}
.np-name { flex: 1; min-width: 0; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np-stop { border: 0; border-radius: 999px; padding: 6px 12px; background: var(--glass-strong); cursor: pointer; font-size: 13px; }
.np-bars { display: inline-flex; gap: 2px; align-items: flex-end; height: 14px; }
.np-bars i { width: 3px; background: #ff9a7a; border-radius: 1px; animation: np 1s ease-in-out infinite; }
.np-bars i:nth-child(2) { animation-delay: -.3s; } .np-bars i:nth-child(3) { animation-delay: -.6s; }
@keyframes np { 0%,100% { height: 4px; } 50% { height: 14px; } }

.push-topic { font: 14px ui-monospace, Consolas, monospace; background: var(--glass); padding: 8px 10px; border-radius: 10px; user-select: all; margin: 6px 0; word-break: break-all; }
.mini-btn { border: 1px solid var(--line); background: var(--glass); border-radius: 10px; padding: 8px 12px; cursor: pointer; margin: 4px 6px 4px 0; font-size: 14px; }
.mini-btn.primary { background: linear-gradient(135deg, #6a7bff, #b06bff); border: 0; }
.memory-view ol { margin: 0; padding-left: 18px; }

/* ---------- alarms ---------- */
.alarm-overlay {
  position: fixed; inset: 0; z-index: 15; display: flex; flex-direction: column; justify-content: space-between;
  padding: max(28px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom));
  background: radial-gradient(120% 60% at 50% 115%, rgba(255, 140, 70, 0.4), rgba(5, 6, 11, 0) 70%);
  text-align: center; animation: sunrise 2.4s ease-out;
}
@keyframes sunrise { from { opacity: 0; } to { opacity: 1; } }
.alarm-time { font-size: clamp(56px, 18vw, 96px); font-weight: 250; letter-spacing: -2px; line-height: 1; }
.alarm-label { font-size: 20px; color: var(--text-dim); margin-top: 6px; }
.alarm-station { font-size: 14px; color: var(--text-faint); margin-top: 6px; min-height: 1.4em; }
.alarm-actions { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; width: min(420px, 100%); margin: 0 auto; }
.alarm-btn { padding: 18px 12px; border-radius: 20px; border: 1px solid var(--line); background: var(--glass-strong); font-size: 18px; font-weight: 600; cursor: pointer; }
.alarm-btn.primary { border: 0; background: linear-gradient(135deg, #ff9a5a, #ff5f8f); color: #1a0d12; }
.alarm-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.alarm-row.off { opacity: 0.5; }
.alarm-row b { font-size: 20px; font-weight: 600; margin-right: 6px; }
.alarm-row small { display: block; color: var(--text-faint); font-size: 12px; }
.alarm-row input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); }
.alarm-form { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 6px; }
.alarm-form input, .alarm-form select { background: var(--glass); border: 1px solid var(--line); border-radius: 10px; padding: 8px; color: inherit; font: inherit; font-size: 14px; min-width: 0; }
.alarm-form input[type=time] { flex: 1 1 110px; }
.alarm-form input[type=text] { flex: 1 1 100%; }
.alarm-form select { flex: 1 1 110px; }
.alarm-form select option { background: #14151d; }
.bedside { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 8px; font-size: 14px; }
.bedside input { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
body.ringing .top, body.ringing .status, body.ringing .substatus, body.ringing .chat,
body.ringing .composer, body.ringing .now-playing { visibility: hidden; }

/* ---------- voice engine switch ---------- */
.sheet-item.engine { flex-direction: row; justify-content: space-between; align-items: center; gap: 12px; cursor: default; }
.seg { display: inline-flex; flex: none; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 8px 12px; font-size: 14px; cursor: pointer; color: var(--text-dim); }
.seg button.on { background: linear-gradient(135deg, #6a7bff, #b06bff); color: #fff; }
.msg.zbot.local::after { content: " ⚡"; opacity: 0.5; font-size: 12px; }
.brand-dot.ears { background: #3ddc97; box-shadow: 0 0 8px rgba(61, 220, 151, 0.6); }
