:root {
  --bg: #04060b;
  --panel: rgba(10, 14, 23, 0.74);
  --panel-solid: #0b101b;
  --line: rgba(255, 176, 72, 0.22);
  --line-strong: rgba(255, 176, 72, 0.5);
  --gold: #ffbe55;
  --orange: #ff8a1f;
  --text: #f4ece0;
  --muted: #9b917f;
  --user: rgba(255, 170, 60, 0.12);
  --danger: #ff6a4d;
  --ok: #7dffb1;
  --radius: 16px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--font);
  overflow: hidden; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { opacity: .55; cursor: default; }

.grid-bg {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 45%, rgba(255, 120, 20, 0.10), transparent 60%),
    radial-gradient(ellipse at 50% 120%, rgba(40, 70, 120, 0.25), transparent 60%),
    linear-gradient(rgba(255, 180, 80, 0.035) 1px, transparent 1px) 0 0 / 48px 48px,
    linear-gradient(90deg, rgba(255, 180, 80, 0.035) 1px, transparent 1px) 0 0 / 48px 48px,
    var(--bg);
}
.grid-bg::after {
  content: ""; position: absolute; inset: 0;
  background: repeating-linear-gradient(0deg, rgba(255,255,255,0.018) 0 1px, transparent 1px 3px);
  -webkit-mask-image: radial-gradient(ellipse at center, #000 30%, transparent 80%);
  mask-image: radial-gradient(ellipse at center, #000 30%, transparent 80%);
}
#core { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 1; pointer-events: none; }

.hud {
  position: fixed; inset: 0; z-index: 2; display: grid;
  grid-template-columns: 1fr minmax(300px, 360px);
  grid-template-rows: auto 1fr auto;
  grid-template-areas: "top top" "stage chat" "dock chat";
  transition: filter .3s;
}
body.locked .hud { filter: blur(8px) brightness(.6); pointer-events: none; }

/* ---------- top bar ---------- */
.top {
  grid-area: top; display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 14px) calc(env(safe-area-inset-right) + 18px) 8px calc(env(safe-area-inset-left) + 20px);
}
.brand { display: flex; align-items: baseline; gap: 16px; }
.logo {
  font-weight: 600; letter-spacing: .38em; color: var(--gold); font-size: 15px;
  text-shadow: 0 0 12px rgba(255, 150, 40, .65), 0 0 28px rgba(255, 110, 0, .35);
}
.logo.big { font-size: 22px; text-align: center; margin-bottom: 22px; }
.status-wrap { display: inline-flex; align-items: center; gap: 8px; font: 11px/1 var(--mono); letter-spacing: .18em; text-transform: uppercase; color: var(--muted); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 10px var(--gold); }
body[data-mode="listening"] .dot { background: #ffe08a; animation: pulse 1.1s ease-in-out infinite; }
body[data-mode="thinking"] .dot { background: var(--orange); animation: pulse .5s ease-in-out infinite; }
body[data-mode="speaking"] .dot { background: #fff1c9; box-shadow: 0 0 14px #ffcf6b; }
body[data-mode="offline"] .dot { background: #555; box-shadow: none; }
@keyframes pulse { 50% { opacity: .25; transform: scale(.7); } }

.top-actions { position: relative; display: flex; gap: 8px; }
.icon-btn {
  width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px;
  background: rgba(255, 180, 80, .06); border: 1px solid var(--line); color: var(--gold);
}
.icon-btn svg { width: 20px; height: 20px; fill: currentColor; }
.icon-btn.small { width: 32px; height: 32px; border-radius: 10px; }
.icon-btn:hover { border-color: var(--line-strong); background: rgba(255, 180, 80, .12); }
#chatToggle, #chatClose { display: none; }
.menu {
  position: absolute; right: 0; top: 48px; min-width: 220px; padding: 6px; z-index: 20;
  background: var(--panel-solid); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 40px rgba(0,0,0,.6);
}
.menu button { display: block; width: 100%; text-align: left; padding: 10px 12px; border: 0; background: none; border-radius: 8px; }
.menu button:hover { background: rgba(255, 180, 80, .1); }
.menu-info { padding: 8px 12px 6px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); margin-top: 4px; }

/* ---------- stage + caption ---------- */
.stage { grid-area: stage; position: relative; min-height: 0; }
.caption {
  position: absolute; left: 50%; bottom: 4%; transform: translateX(-50%); width: min(86%, 640px);
  text-align: center; color: #f7dcb0; font-size: 16px; min-height: 1.5em;
  text-shadow: 0 0 18px rgba(0,0,0,.9), 0 0 8px rgba(255,140,30,.35);
}
.caption[data-who="user"] { color: var(--text); font-style: italic; }

/* ---------- chat ---------- */
.chat {
  grid-area: chat; display: flex; flex-direction: column; min-height: 0;
  margin: 4px calc(env(safe-area-inset-right) + 16px) calc(env(safe-area-inset-bottom) + 16px) 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  backdrop-filter: blur(14px) saturate(1.2); -webkit-backdrop-filter: blur(14px) saturate(1.2);
  box-shadow: 0 0 0 1px rgba(0,0,0,.4), 0 20px 60px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,200,120,.06);
}
.chat-head {
  display: flex; justify-content: space-between; align-items: center; padding: 12px 14px 10px;
  font: 11px/1 var(--mono); letter-spacing: .2em; text-transform: uppercase; color: var(--muted);
  border-bottom: 1px solid var(--line);
}
.messages { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; }
.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-thumb { background: rgba(255,180,80,.2); border-radius: 3px; }
.msg { max-width: 92%; font-size: 14px; }
.msg .body { padding: 9px 12px; border-radius: 12px; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; }
.msg.user .body { background: var(--user); border: 1px solid rgba(255, 170, 60, .3); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; }
.msg.assistant .body { background: rgba(255,255,255,.035); border: 1px solid rgba(255,255,255,.06); border-bottom-left-radius: 4px; }
.msg.assistant .body:empty::after { content: "▍"; color: var(--gold); animation: pulse 1s infinite; }
.msg.system { align-self: center; max-width: 100%; }
.msg.system .body { color: var(--muted); font-size: 12px; text-align: center; padding: 2px 8px; }
.msg pre { background: rgba(0,0,0,.4); padding: 8px; border-radius: 8px; overflow-x: auto; font: 12px/1.4 var(--mono); white-space: pre; }
.msg code { font: 12.5px var(--mono); background: rgba(0,0,0,.3); padding: 1px 4px; border-radius: 4px; }
.msg a { color: var(--gold); }
.tool-chip {
  display: inline-block; margin: 0 4px 4px 0; padding: 2px 8px; border-radius: 999px; font: 11px var(--mono);
  color: var(--gold); background: rgba(255, 180, 80, .08); border: 1px solid var(--line);
}
.note { font-size: 12px; color: var(--muted); padding: 4px 4px 0; }
.error { font-size: 12.5px; color: var(--danger); padding: 4px 4px 0; }
.approval {
  border: 1px solid rgba(255, 106, 77, .55); background: rgba(255, 90, 31, .08); border-radius: 12px;
  padding: 10px 12px; font-size: 13.5px; display: grid; gap: 8px;
}
.approval-title { color: #ffb08f; font-weight: 600; }
.approval pre { margin: 0; background: rgba(0,0,0,.45); padding: 8px; border-radius: 8px; font: 12px/1.4 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }
.approval-actions { display: flex; gap: 8px; color: var(--muted); }
.btn { border: 1px solid var(--line); background: rgba(255,255,255,.04); border-radius: 10px; padding: 8px 12px; }
.btn.approve { border-color: rgba(125,255,177,.45); color: var(--ok); }
.btn.deny { border-color: rgba(255,106,77,.5); color: var(--danger); }
.btn.primary {
  width: 100%; margin-top: 18px; padding: 12px; font-weight: 600; color: #1a0f00; border: 0;
  background: linear-gradient(135deg, #ffd27a, var(--orange)); box-shadow: 0 0 24px rgba(255, 140, 30, .35);
}
.composer { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.composer input {
  flex: 1; min-width: 0; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: rgba(0,0,0,.35); color: var(--text); font: 16px var(--font); outline: none;
}
.composer input:focus { border-color: var(--line-strong); box-shadow: 0 0 0 3px rgba(255,170,60,.12); }
.composer button { width: 42px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255,180,80,.1); color: var(--gold); display: grid; place-items: center; }
.composer svg { width: 18px; height: 18px; }

/* ---------- dock / talk button ---------- */
.dock { grid-area: dock; display: flex; justify-content: center; padding: 6px 16px calc(env(safe-area-inset-bottom) + 22px); }
.talk {
  position: relative; display: inline-flex; align-items: center; gap: 12px; height: 60px; padding: 0 30px 0 24px;
  border-radius: 999px; border: 1px solid rgba(255, 190, 90, .55); color: #ffe2ad; font-weight: 600; letter-spacing: .04em;
  background: linear-gradient(180deg, rgba(255,160,50,.20), rgba(255,110,10,.10)), rgba(8,10,16,.75);
  box-shadow: 0 0 30px rgba(255, 130, 20, .30), inset 0 1px 0 rgba(255,220,160,.25);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); transition: transform .15s, box-shadow .2s;
}
.talk svg { width: 22px; height: 22px; }
.talk:hover { box-shadow: 0 0 44px rgba(255, 130, 20, .45), inset 0 1px 0 rgba(255,220,160,.3); }
.talk:active { transform: scale(.97); }
.talk .ring { position: absolute; inset: -6px; border-radius: inherit; border: 1px solid transparent; pointer-events: none; }
.talk.active { color: #fff; border-color: rgba(255, 110, 70, .8); background: linear-gradient(180deg, rgba(255,90,40,.35), rgba(200,40,10,.2)), rgba(8,10,16,.8); }
.talk.active .ring { border-color: rgba(255,120,60,.6); animation: ring 1.6s ease-out infinite; }
@keyframes ring { from { opacity: 1; transform: scale(1); } to { opacity: 0; transform: scale(1.18); } }

/* ---------- auth ---------- */
.auth { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; padding: 16px; background: rgba(2,3,6,.55); }
.auth-card {
  width: min(380px, 100%); padding: 28px 24px; border-radius: 18px; background: var(--panel); border: 1px solid var(--line);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); box-shadow: 0 30px 80px rgba(0,0,0,.6);
}
.auth-card label { display: block; margin: 14px 0 6px; font: 11px var(--mono); letter-spacing: .15em; text-transform: uppercase; color: var(--muted); }
.auth-card input:not([hidden]) {
  width: 100%; padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: rgba(0,0,0,.4);
  color: var(--text); font: 16px var(--font); outline: none;
}
.auth-card input:focus { border-color: var(--line-strong); }
.hint { color: var(--muted); font-size: 13.5px; margin: 0 0 6px; }
[hidden] { display: none !important; }

/* ---------- mobile ---------- */
@media (max-width: 760px) {
  .hud { grid-template-columns: 1fr; grid-template-areas: "top" "stage" "dock"; }
  #chatToggle, #chatClose { display: grid; }
  .brand { gap: 6px; flex-direction: column; align-items: flex-start; }
  .logo { font-size: 14px; }
  .chat {
    position: fixed; left: 0; right: 0; bottom: 0; height: min(60dvh, 560px); margin: 0; z-index: 10;
    border-radius: 20px 20px 0 0; border-bottom: 0; padding-bottom: env(safe-area-inset-bottom);
    background: rgba(8, 11, 19, .94); transform: translateY(105%); transition: transform .28s cubic-bezier(.2,.8,.2,1);
  }
  body.chat-open .chat { transform: none; }
  .caption { bottom: 2%; font-size: 15px; }
  .talk { height: 58px; }
}
@media (prefers-reduced-motion: reduce) {
  .talk.active .ring, .dot { animation: none !important; }
}

/* ---------- tabs, approvals, notes ---------- */
.tabs { display: flex; gap: 4px; }
.tab {
  border: 1px solid transparent; background: none; color: var(--muted); padding: 6px 10px; border-radius: 8px;
  font: 11px/1 var(--mono); letter-spacing: .14em; text-transform: uppercase;
}
.tab.active { color: var(--gold); border-color: var(--line); background: rgba(255,180,80,.08); }
.badge {
  display: inline-grid; place-items: center; min-width: 17px; height: 17px; padding: 0 4px; margin-left: 4px; border-radius: 9px;
  background: var(--danger); color: #fff; font: 600 10px/1 var(--font); letter-spacing: 0;
}
#chatToggle.alert { border-color: var(--danger); color: #ffb08f; box-shadow: 0 0 14px rgba(255,106,77,.45); }
.outbox-item, .note-card {
  position: relative; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: grid; gap: 6px;
  background: rgba(255,255,255,.03); font-size: 13.5px;
}
.outbox-item.pending { border-color: rgba(255,106,77,.6); background: rgba(255,90,31,.07); }
.outbox-head { display: flex; justify-content: space-between; gap: 8px; }
.outbox-type { color: var(--gold); font-weight: 600; }
.outbox-time { color: var(--muted); font: 11px var(--mono); }
.outbox-meta { white-space: pre-line; color: var(--muted); font-size: 12.5px; }
.outbox-body, .note-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font: 13px/1.45 var(--font); background: rgba(0,0,0,.3); padding: 8px; border-radius: 8px; max-height: 260px; overflow-y: auto; }
.note-text { background: none; padding: 0; max-height: none; }
.note-title { font-weight: 600; padding-right: 30px; }
.note-card .del { position: absolute; top: 6px; right: 6px; font-size: 16px; }
.section-title { font: 11px var(--mono); letter-spacing: .18em; text-transform: uppercase; color: var(--muted); margin-top: 4px; }
.task { display: flex; align-items: center; gap: 10px; padding: 6px 2px; border-bottom: 1px solid rgba(255,255,255,.05); font-size: 14px; }
.task .due { margin-left: auto; color: var(--muted); font: 11px var(--mono); white-space: nowrap; }
.check { width: 20px; height: 20px; flex: none; border-radius: 6px; border: 1.5px solid var(--line-strong); background: none; }
.check:hover { background: rgba(125,255,177,.15); border-color: var(--ok); }
.auth-card.wide { width: min(460px, 100%); }
.auth-card input[type=url] { margin-top: 4px; font-size: 13px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.auth-card.scroll { max-height: calc(100dvh - 32px); overflow-y: auto; }
.steps { margin: 8px 0 0; padding-left: 20px; display: grid; gap: 12px; font-size: 14px; color: var(--text); }
.steps li::marker { color: var(--gold); font-weight: 600; }
.steps .btn.primary { margin-top: 8px; }
.steps a { color: var(--gold); }
