:root {
  --bg: #f6f5f1;
  --fg: #1d1b18;
  --muted: #6f695f;
  --card: #ffffff;
  --line: #e5e1d7;
  --accent: #d97757;
  --green: #30c45a;
  --red: #ff3b30;
  --ok: #2f9e5a;
  --warn: #c88a12;
  --chip: rgba(127, 127, 127, 0.14);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161512;
    --fg: #f1eee6;
    --muted: #a19b8f;
    --card: #211f1b;
    --line: #35322c;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); }
body { font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; }
[hidden] { display: none !important; }
h1 { font-size: 26px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0; }
code { background: var(--chip); padding: 1px 6px; border-radius: 6px; font-size: 0.9em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.grow { flex: 1; min-width: 0; }
.error { color: var(--red); min-height: 1.4em; }

.view { min-height: 100%; padding: calc(var(--safe-top) + 16px) 16px calc(var(--safe-bottom) + 24px); max-width: 640px; margin: 0 auto; }
.top { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.top h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); color: var(--fg); font-size: 22px; line-height: 1; flex: none; }
.btn { flex: 1; min-height: 48px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); color: var(--fg); font: 600 16px/1 inherit; padding: 0 16px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--red); }
.row { display: flex; gap: 10px; margin: 16px 0; }
.sticky-actions { position: sticky; bottom: calc(var(--safe-bottom) + 8px); background: linear-gradient(transparent, var(--bg) 30%); padding-top: 16px; margin-bottom: 0; }

.conn { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); margin-top: 2px; }
.conn .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.conn.ok .dot { background: var(--ok); }
.conn.bad .dot { background: var(--red); }

.seg { display: flex; background: var(--chip); border-radius: 12px; padding: 3px; margin-bottom: 12px; }
.seg button { flex: 1; border: 0; background: transparent; color: var(--fg); font: 600 14px/1 inherit; padding: 10px 6px; border-radius: 10px; }
.seg button.on { background: var(--card); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.panel { margin-bottom: 8px; }
.field { display: block; margin: 12px 0; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
select, input[type="search"], input[inputmode], textarea {
  width: 100%; font: 16px/1.4 inherit; color: var(--fg); background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px;
  -webkit-appearance: none; appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 12px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 32px; }
textarea { resize: vertical; }
.toggle { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.toggle input { width: 22px; height: 22px; accent-color: var(--accent); }

.list { list-style: none; margin: 8px 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin: 8px 0; }
.list li.sel { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent); }
.list .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .s { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .more { border: 0; background: transparent; color: var(--muted); font-size: 24px; padding: 0 4px; }
.list .empty { justify-content: center; color: var(--muted); border-style: dashed; }
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 99px; background: var(--chip); color: var(--muted); vertical-align: 1px; margin-left: 4px; }
.badge.live { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.badge.busy { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.st { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--chip); flex: none; font-size: 15px; }
.section-title { margin: 20px 0 4px; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; }
.spacer { height: 160px; }

.dock { position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px calc(var(--safe-bottom) + 16px); display: flex; flex-direction: column; align-items: center; gap: 8px;
  background: linear-gradient(transparent, var(--bg) 35%); }
.dock-target { font-size: 13px; color: var(--muted); max-width: 90%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.call-btn { width: 76px; height: 76px; border-radius: 50%; border: 0; background: var(--green); color: #fff; display: grid; place-items: center;
  box-shadow: 0 8px 24px color-mix(in srgb, var(--green) 45%, transparent); }
.call-btn:active { transform: scale(0.95); }

/* ---- call screen ---- */
.call { position: fixed; inset: 0; max-width: none; background: radial-gradient(120% 80% at 50% 0%, #2b2620 0%, #0d0c0a 70%); color: #f4f0e8;
  display: flex; flex-direction: column; align-items: center; padding-bottom: calc(var(--safe-bottom) + 28px); user-select: none; -webkit-user-select: none; touch-action: none; }
.call-head { text-align: center; margin-top: 28px; }
.call-name { font-size: 32px; font-weight: 300; }
.call-target { font-size: 14px; color: #b9b2a5; margin-top: 4px; max-width: 80vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.call-status { font-size: 15px; color: #d8d1c4; margin-top: 8px; font-variant-numeric: tabular-nums; }
.avatar-wrap { --lvl: 0; position: relative; width: 180px; height: 180px; margin: 36px 0 20px; display: grid; place-items: center; }
.avatar { width: 120px; height: 120px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; position: relative; z-index: 2;
  box-shadow: 0 0 calc(10px + var(--lvl) * 40px) color-mix(in srgb, var(--accent) 60%, transparent); transition: box-shadow 0.1s; }
.ring { position: absolute; inset: 30px; border-radius: 50%; border: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); opacity: 0; }
.call.active .ring { animation: ring 2.4s infinite ease-out; }
.call.active .r2 { animation-delay: 0.8s; }
.call.active .r3 { animation-delay: 1.6s; }
.call.muted .ring { animation: none; }
@keyframes ring { 0% { transform: scale(1); opacity: 0.8; } 100% { transform: scale(1.9); opacity: 0; } }
.transcript { flex: 1; width: 100%; max-width: 560px; overflow-y: auto; padding: 0 24px; font-size: 19px; line-height: 1.45; text-align: center; color: #f4f0e8; }
.transcript .interim { color: #9d968a; }
.transcript .hint { color: #8a8478; font-size: 16px; }
.call-controls { display: flex; gap: 48px; margin: 16px 0 24px; }
.ctl { position: relative; width: 72px; height: 72px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, 0.14); color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.ctl .ctl-ic { font-size: 22px; line-height: 1; }
.ctl .ctl-l { font-size: 11px; }
.ctl.on { background: #f4f0e8; color: #111; }
.hangup { position: relative; width: 84px; height: 84px; border-radius: 50%; border: 0; background: var(--red); color: #fff; display: grid; place-items: center; }
.hold-ring { position: absolute; inset: -6px; width: calc(100% + 12px); height: calc(100% + 12px); transform: rotate(-90deg); pointer-events: none; }
.hold-ring circle { fill: none; stroke: #fff; stroke-width: 4; stroke-dasharray: 296; stroke-dashoffset: 296; }
[data-hold].holding .hold-ring circle { transition: stroke-dashoffset var(--hold, 450ms) linear; stroke-dashoffset: 0; }
[data-hold].holding { transform: scale(0.94); }
.hold-hint { font-size: 12px; color: #8a8478; margin-top: 10px; }

/* ---- job + session ---- */
.status-chip { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; padding: 6px 12px; border-radius: 99px; background: var(--chip); margin-bottom: 12px; }
.status-chip.running::before { content: ""; width: 10px; height: 10px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin 0.8s linear infinite; }
.status-chip.done { color: var(--ok); background: color-mix(in srgb, var(--ok) 15%, transparent); }
.status-chip.error { color: var(--red); background: color-mix(in srgb, var(--red) 12%, transparent); }
@keyframes spin { to { transform: rotate(360deg); } }
.bubble { border-radius: 18px; padding: 10px 14px; margin: 8px 0; white-space: pre-wrap; word-wrap: break-word; }
.bubble.me { background: var(--accent); color: #fff; margin-left: 15%; border-bottom-right-radius: 6px; }
.bubble.them { background: var(--card); border: 1px solid var(--line); margin-right: 8%; border-bottom-left-radius: 6px; white-space: normal; }
.bubble .tools { font-size: 12px; color: var(--muted); margin-top: 6px; }
.activity { list-style: none; padding: 0; margin: 12px 0; font-size: 14px; color: var(--muted); }
.activity li { padding: 4px 0 4px 22px; position: relative; overflow-wrap: anywhere; }
.activity li::before { content: "•"; position: absolute; left: 6px; }
.activity li.tool::before { content: "⚙"; left: 2px; }
.result { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; overflow-wrap: anywhere; }
.result pre, .bubble pre { background: var(--chip); padding: 10px; border-radius: 10px; overflow-x: auto; font-size: 13px; white-space: pre; }
.result p, .bubble p { margin: 0.4em 0; }
.result ul, .bubble ul { padding-left: 20px; margin: 0.4em 0; }
.messages { padding-bottom: 8px; }

.pair { text-align: center; padding-top: 12vh; }
.pair .logo { font-size: 56px; }
.pair form { display: flex; flex-direction: column; gap: 12px; margin: 24px auto 0; max-width: 320px; }
.pair input { text-align: center; font: 600 28px/1 ui-monospace, Menlo, monospace; letter-spacing: 8px; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--safe-bottom) + 120px); background: #1d1b18; color: #fff; padding: 10px 16px; border-radius: 12px;
  font-size: 14px; max-width: calc(100% - 32px); z-index: 50; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3); }

.hint-card { display: flex; flex-direction: column; gap: 2px; text-decoration: none; color: var(--fg); background: color-mix(in srgb, var(--accent) 14%, var(--card));
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); border-radius: 14px; padding: 12px 14px; margin-bottom: 12px; font-size: 14px; }
.hint-card span { color: var(--muted); }
