:root {
  --bg: #151515; --side: #0f0f0f; --panel: #212121; --line: #2e2e2e; --hover: #262626;
  --text: #ececec; --muted: #9b9b9b; --accent: #10a37f; --danger: #e5484d;
  --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);
  font: 16px/1.6 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }

#app { display: flex; height: 100dvh; }
#side { width: 260px; background: var(--side); display: flex; flex-direction: column; padding: 10px; gap: 6px; flex: none; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.brand img { width: 26px; height: 26px; border-radius: 7px; }
.new-chat { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; }
.new-chat:hover, .chat-row:hover, .chat-row.on { background: var(--hover); }
#chats { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; margin-top: 8px; }
.chat-row { display: flex; align-items: center; border-radius: 10px; }
.chat-open { flex: 1; text-align: left; padding: 9px 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14.5px; }
.chat-del { padding: 8px; color: var(--muted); opacity: 0; }
.chat-row:hover .chat-del, .chat-row.on .chat-del, .chat-del.armed { opacity: 1; }
.chat-del.armed { color: var(--danger); }
.chat-del svg { width: 17px; height: 17px; }
.side-foot { color: var(--muted); font-size: 12.5px; padding: 8px 12px; }
#scrim { display: none; }

main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.top { display: flex; align-items: center; gap: 8px; padding: 10px 14px; min-height: 52px; }
.top h1 { flex: 1; margin: 0; font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon { padding: 8px; border-radius: 10px; display: grid; place-items: center; }
.icon:hover { background: var(--hover); }
.only-mobile { display: none; }

#thread { flex: 1; overflow-y: auto; padding: 8px 16px 24px; }
#messages, .empty { max-width: 760px; margin: 0 auto; }
.empty { text-align: center; padding-top: 18vh; }
.empty h2 { font-size: 28px; font-weight: 600; margin: 0 0 8px; }
.empty p { color: var(--muted); margin: 0; }
.msg { margin: 18px 0; }
.msg.user { display: flex; justify-content: flex-end; }
.bubble { background: var(--panel); padding: 10px 16px; border-radius: 20px; max-width: 80%; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.voice.user .bubble::before, .msg.voice.assistant .md::before { content: "voice"; display: block; font-size: 11px; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md pre { position: relative; background: #0d0d0d; border: 1px solid var(--line); border-radius: 12px; padding: 14px; overflow-x: auto; font-size: 14px; line-height: 1.5; }
.md code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .92em; }
.md :not(pre) > code { background: var(--panel); padding: 2px 6px; border-radius: 6px; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 10px; }
.md a { color: #7ab7ff; }
.md blockquote { margin: 0; padding-left: 14px; border-left: 3px solid var(--line); color: var(--muted); }
.copy-code { position: absolute; top: 8px; right: 8px; font-size: 12px; padding: 3px 9px; border-radius: 7px; background: var(--panel); color: var(--muted); }
.actions { display: flex; gap: 4px; margin-top: 6px; }
.actions button { font-size: 13px; color: var(--muted); padding: 4px 9px; border-radius: 8px; }
.actions button:hover { background: var(--hover); color: var(--text); }
.thinking { margin-bottom: 10px; color: var(--muted); font-size: 14.5px; }
.thinking summary { cursor: pointer; list-style: none; display: inline-flex; gap: 6px; align-items: center; }
.thinking summary::after { content: "›"; transition: transform .15s; }
.thinking[open] summary::after { transform: rotate(90deg); }
.thinking-body { white-space: pre-wrap; border-left: 2px solid var(--line); padding: 4px 0 4px 12px; margin-top: 6px; max-height: 320px; overflow-y: auto; }
.dots { display: inline-flex; gap: 4px; padding: 8px 0; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .2s; } .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

#composer { padding: 0 16px calc(10px + var(--safe-b)); }
.box { max-width: 760px; margin: 0 auto; background: var(--panel); border: 1px solid var(--line); border-radius: 26px; padding: 10px 10px 8px 16px; }
#input { width: 100%; resize: none; background: none; border: 0; outline: 0; color: var(--text); font: inherit; max-height: 200px; padding: 4px 0; }
.row { display: flex; align-items: center; gap: 6px; }
.grow { flex: 1; }
.pill { display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); font-size: 14px; }
.pill svg { width: 17px; height: 17px; }
.pill[aria-pressed="true"] { color: #8fd9c3; border-color: #1f6e58; background: #10a37f22; }
.round { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--text); color: #111; }
.round.ghost { background: var(--hover); color: var(--text); }
#send { display: none; }
body.typed #send, body.busy #send { display: grid; }
body.typed #voice, body.busy #voice { display: none; }
#send .i-stop { display: none; fill: currentColor; stroke: none; }
body.busy #send .i-send { display: none; } body.busy #send .i-stop { display: block; }
.fine { text-align: center; color: var(--muted); font-size: 12px; margin: 8px 0 0; }

.toast { position: fixed; left: 50%; bottom: calc(110px + var(--safe-b)); transform: translateX(-50%); background: #333; padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 50; max-width: 90vw; }

/* voice mode */
#voice-ui { position: fixed; inset: 0; z-index: 40; background: #000; display: flex; flex-direction: column; align-items: center; padding: max(24px, env(safe-area-inset-top)) 20px calc(28px + var(--safe-b)); }
.v-status { color: var(--muted); font-size: 15px; height: 24px; }
.v-space { margin-top: 12px; }
  background: radial-gradient(circle at 35% 30%, #e9f6ff 0%, #8cc8ff 28%, #2f7cf6 62%, #173a9a 100%);
  box-shadow: 0 0 80px #2f7cf655; transform: scale(calc(1 + var(--lv) * .22)); transition: transform .08s linear, filter .3s; }
.wave-wrap { flex: 1; display: grid; place-items: center; width: 100%; }
.wave { width: 100%; height: min(36vh, 260px); }
.v-lines { width: 100%; max-width: 560px; min-height: 120px; display: flex; flex-direction: column; justify-content: flex-end; gap: 8px; margin-bottom: 24px; }
.v-lines p { margin: 0; font-size: 16px; line-height: 1.45; }
.v-lines p.user { color: var(--muted); text-align: right; }
.v-controls { display: flex; gap: 28px; }
.v-btn { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; background: #262626; }
.v-btn svg { width: 26px; height: 26px; }
.v-btn.end { background: #3a1416; color: #ff8a8d; }
.v-btn .i-mic-off { display: none; }
.v-btn[aria-pressed="true"] { background: #ececec; color: #111; }
.v-btn[aria-pressed="true"] .i-mic { display: none; } .v-btn[aria-pressed="true"] .i-mic-off { display: block; }

@media (max-width: 800px) {
  .only-mobile { display: grid; }
  #side { position: fixed; inset: 0 auto 0 0; z-index: 30; width: 82vw; max-width: 320px; transform: translateX(-100%); transition: transform .2s; }
  body.side-open #side { transform: none; }
  body.side-open #scrim { display: block; position: fixed; inset: 0; z-index: 20; background: #0009; }
  .chat-del { opacity: 1; }
  .bubble { max-width: 88%; }
  #thread { padding: 4px 14px 18px; }
  #composer { padding: 0 10px calc(8px + var(--safe-b)); }
}
.tools { color: var(--muted); font-size: 13px; margin-bottom: 6px; }

/* Work / Personal switch: two Hermes profiles, own chats and memory */
.space { display: flex; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 3px; gap: 2px; flex: none; }
.space button { padding: 5px 12px; border-radius: 999px; font-size: 13.5px; color: var(--muted); }
.space button[aria-pressed="true"] { background: var(--text); color: #111; }
body[data-space="personal"] .space button[aria-pressed="true"] { background: #c9a2ff; }

/* who is signed in, the owner's voice */
.side-foot { display: flex; flex-direction: column; gap: 4px; }
.foot-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.foot-btn { font-size: 12.5px; color: var(--muted); padding: 4px 6px; border-radius: 8px; text-align: left; }
.foot-btn:hover { background: var(--hover); color: var(--text); }
.foot-btn b { color: var(--text); font-weight: 600; }
.sheet { position: fixed; inset: 0; z-index: 45; background: #000a; display: grid; place-items: end center; }
.sheet-box { width: min(520px, 100%); max-height: 80dvh; overflow-y: auto; background: var(--panel); border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + var(--safe-b)); }
@media (min-width: 801px) { .sheet { place-items: center; } .sheet-box { border-radius: 18px; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h3 { margin: 0; font-size: 17px; }
.sheet-box .fine { text-align: left; margin: 4px 0 12px; }
.voice-row { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); }
.voice-row > div { flex: 1; display: flex; flex-direction: column; }
.voice-row span { color: var(--muted); font-size: 13px; }
.voice-row .pill[aria-pressed="true"] { color: #111; background: var(--text); border-color: var(--text); }
/* sign in */
.login { position: fixed; inset: 0; z-index: 60; background: var(--bg); display: grid; place-items: center; padding: 20px; }
.login-box { width: min(340px, 100%); display: flex; flex-direction: column; gap: 10px; text-align: center; }
.login-box img { width: 56px; height: 56px; border-radius: 14px; margin: 0 auto; }
.login-box h2 { margin: 4px 0 10px; font-size: 22px; }
.login-box input { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; color: var(--text); font: inherit; }
.login-box button { background: var(--text); color: #111; border-radius: 12px; padding: 12px; font-weight: 600; }
.login-err { color: #ff8a8d; min-height: 1.2em; margin: 0; font-size: 14px; }
.login-or { color: var(--muted); font-size: 13px; margin: 0; }
