:root {
  --bg: #0f0d17;
  --surface: #1a1726;
  --surface-2: #242036;
  --text: #f1eef9;
  --muted: #a39cb8;
  --accent: #c58bff;
  --accent-2: #ff8fc7;
  --ok: #6fe3b4;
  --danger: #ff7a8a;
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); min-height: 1.2em; }
h1, h2, h3 { margin: 0; }
h2 { font-size: 22px; }
h3 { font-size: 15px; color: var(--muted); font-weight: 600; margin-bottom: 8px; text-transform: uppercase; letter-spacing: .06em; }

/* Orb */
.orb {
  width: 54px; height: 54px; border-radius: 50%; flex: none;
  background: radial-gradient(circle at 35% 30%, #fff8 0 8%, transparent 30%),
              conic-gradient(from 200deg, var(--accent), var(--accent-2), #7aa8ff, var(--accent));
  box-shadow: 0 0 24px #c58bff55;
  transition: transform .3s, box-shadow .3s;
}
.orb.small { width: 72px; height: 72px; margin: 0 auto 12px; }
.orb[data-state="listening"] { animation: pulse 1.1s ease-in-out infinite; box-shadow: 0 0 38px #ff8fc799; }
.orb[data-state="thinking"] { animation: spin 1.4s linear infinite; }
.orb[data-state="speaking"] { animation: talk .45s ease-in-out infinite alternate; }
.orb[data-state="wake"] { box-shadow: 0 0 0 3px #6fe3b455, 0 0 24px #6fe3b433; }
@keyframes pulse { 50% { transform: scale(1.12); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes talk { from { transform: scale(.96); } to { transform: scale(1.08); } }

/* Login */
.screen { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(360px, 100%); text-align: center; }
.login-card form { display: grid; gap: 12px; margin-top: 24px; }
input[type=password], input[type=text], input[type=search], select {
  width: 100%; padding: 14px 16px; border-radius: 14px; border: 1px solid #ffffff14;
  background: var(--surface); outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
.primary { padding: 14px 18px; border: 0; border-radius: 14px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #1a0f24; font-weight: 700; }
.pill { padding: 8px 14px; border-radius: 999px; border: 1px solid #ffffff1f; background: var(--surface-2); font-size: 14px; }
.pill[aria-pressed="true"] { border-color: var(--ok); color: var(--ok); }
.link { background: none; border: 0; color: var(--accent); padding: 8px 0; }
.link.danger { color: var(--danger); }

/* Layout */
#app { height: 100%; display: flex; flex-direction: column; }
.tab { display: none; flex: 1; overflow-y: auto; padding: 16px 16px calc(84px + var(--safe-b)); }
.tab.active { display: block; }
#tab-talk.active { display: flex; flex-direction: column; padding-bottom: calc(76px + var(--safe-b)); overflow: hidden; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 0 16px; }
.talk-head { display: flex; align-items: center; gap: 12px; padding: 4px 0 12px; }
.talk-head > div:not(.orb) { flex: 1; min-width: 0; }
.talk-head h1 { font-size: 20px; }
.talk-head p { margin: 2px 0 0; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Chat */
.chat { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 8px 0; }
.bubble { max-width: 85%; padding: 10px 14px; border-radius: var(--radius); white-space: pre-wrap; word-wrap: break-word; }
.bubble.user { align-self: flex-end; background: var(--surface-2); border-bottom-right-radius: 6px; }
.bubble.assistant { align-self: flex-start; background: linear-gradient(135deg, #2b1f42, #2a1d33); border-bottom-left-radius: 6px; }
.bubble.interim { opacity: .6; font-style: italic; }
.chips { align-self: flex-start; display: flex; flex-wrap: wrap; gap: 6px; margin-top: -4px; }
.chip { font-size: 12px; padding: 3px 9px; border-radius: 999px; background: #6fe3b41a; color: var(--ok); }
.empty { margin: auto; text-align: center; color: var(--muted); padding: 24px; }

.composer { display: flex; gap: 8px; align-items: center; padding-top: 8px; }
.composer input { flex: 1; min-width: 0; }
.mic, .send { flex: none; width: 50px; height: 50px; border-radius: 50%; border: 0; display: grid; place-items: center; }
.mic { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #1a0f24; }
.mic.live { animation: pulse 1s infinite; }
.send { background: var(--surface-2); }

/* Notes */
.search { margin-bottom: 14px; }
.cat { margin-bottom: 14px; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.cat > summary { list-style: none; padding: 14px 16px; display: flex; justify-content: space-between; font-weight: 600; cursor: pointer; }
.cat > summary::-webkit-details-marker { display: none; }
.note { padding: 12px 16px; border-top: 1px solid #ffffff0d; display: flex; gap: 12px; align-items: flex-start; }
.note.done .note-title { text-decoration: line-through; color: var(--muted); }
.note input[type=checkbox] { width: 22px; height: 22px; margin-top: 2px; accent-color: var(--accent); flex: none; }
.note-body { flex: 1; min-width: 0; }
.note-title { font-weight: 600; }
.note-content { color: var(--muted); font-size: 14px; margin-top: 2px; white-space: pre-wrap; }
.note-meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.prio-high { color: var(--accent-2); }
.del { background: none; border: 0; color: var(--muted); font-size: 18px; padding: 0 4px; }

/* Cards */
.card { background: var(--surface); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.profile { white-space: pre-wrap; margin: 0; }
.memories { list-style: none; padding: 0; margin: 0; }
.memories li { display: flex; gap: 8px; padding: 8px 0; border-top: 1px solid #ffffff0d; font-size: 15px; }
.memories li:first-child { border-top: 0; }
.memories .kind { font-size: 11px; text-transform: uppercase; color: var(--accent); min-width: 72px; padding-top: 3px; }
.memories span:nth-child(2) { flex: 1; }
.row { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; gap: 12px; }
.row input { width: 22px; height: 22px; accent-color: var(--accent); }
.stack { display: grid; gap: 6px; padding: 8px 0; color: var(--muted); font-size: 14px; }
.stack select, .stack input { color: var(--text); }
input[type=range] { accent-color: var(--accent); }
svg.chart text { fill: var(--muted); font-size: 10px; }

/* Tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex;
  padding: 6px 8px calc(6px + var(--safe-b)); background: #0f0d17ee; backdrop-filter: blur(12px);
  border-top: 1px solid #ffffff10;
}
.tabbar button { flex: 1; background: none; border: 0; color: var(--muted); display: grid; justify-items: center; gap: 2px; font-size: 12px; padding: 6px 0; }
.tabbar button span { font-size: 20px; filter: grayscale(1); opacity: .7; }
.tabbar button.active { color: var(--text); }
.tabbar button.active span { filter: none; opacity: 1; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%) translateY(20px);
  background: var(--surface-2); padding: 10px 16px; border-radius: 12px; opacity: 0; pointer-events: none;
  transition: .25s; max-width: calc(100% - 32px); text-align: center; font-size: 14px;
}
.toast.show { opacity: 1; transform: translateX(-50%); }
.primary:disabled { opacity: .4; }
