:root {
  --bg: #16130f;
  --panel: #211d18;
  --panel-2: #2b261f;
  --line: #3a332a;
  --text: #f1ebe2;
  --muted: #a89e90;
  --accent: #e0a458;
  --accent-ink: #1b1308;
  --danger: #e06c5a;
  --ok: #7fbf7f;
  --you: #2f3a44;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f2ec; --panel: #ffffff; --panel-2: #f0e9df; --line: #e0d6c8; --text: #231d16;
    --muted: #7a6f61; --accent: #b86e1f; --accent-ink: #ffffff; --you: #e3ebf2; color-scheme: light;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.45 var(--font); }
body { min-height: 100dvh; }
#app { max-width: 720px; margin: 0 auto; padding: max(12px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom)); }
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1 { font-size: 1.35rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 24px 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--danger); }

/* top bar */
.bar { display: flex; align-items: center; gap: 12px; min-height: 48px; margin-bottom: 12px; }
.bar h1 { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { background: none; border: 0; padding: 10px; margin: -10px; font-size: 1.3rem; line-height: 1; color: var(--text); border-radius: 10px; }
.text-btn { background: none; border: 0; color: var(--accent); padding: 8px 4px; }

/* buttons */
.btn { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 16px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* login */
.login { min-height: 80dvh; display: grid; place-content: center; gap: 14px; text-align: center; }
.login input { width: min(320px, 80vw); }

/* forms */
label.field { display: block; margin: 12px 0; }
label.field > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=url], select, textarea {
  width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
textarea { font-family: var(--mono); font-size: .9rem; line-height: 1.5; min-height: 220px; resize: vertical; }
textarea.short { min-height: 110px; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 420px) { .two { grid-template-columns: 1fr; } }

/* cards */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 12px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--text); }
.card:active { transform: scale(.98); }
.avatar { width: 88px; height: 88px; border-radius: 50%; object-fit: cover; background: var(--panel-2);
  display: grid; place-items: center; font-size: 2rem; font-weight: 700; color: var(--accent); border: 2px solid var(--line); flex: none; }
.avatar.sm { width: 40px; height: 40px; font-size: 1rem; }
.card .name { font-weight: 650; font-size: 1.05rem; }
.card .role { color: var(--muted); font-size: .85rem; }

/* lists */
.list { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list > * { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--line); color: var(--text); }
.list > *:first-child { border-top: 0; }
.list .grow { flex: 1; min-width: 0; }
.list > button { width: 100%; text-align: left; }
.list .sub { color: var(--muted); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chev { color: var(--muted); }
.pill { font-size: .75rem; padding: 2px 8px; border-radius: 99px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.pill.ok { color: var(--ok); } .pill.bad { color: var(--danger); }

/* talk view */
.talk { display: flex; flex-direction: column; min-height: calc(100dvh - 40px); }
.transcript { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 4px 0 16px; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: 16px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.you { align-self: flex-end; background: var(--you); border-bottom-right-radius: 4px; }
.msg.agent { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.tool, .msg.notice { align-self: flex-start; background: none; color: var(--muted); font-size: .85rem; padding: 0 4px; }
.msg.err { align-self: center; color: var(--danger); font-size: .9rem; }
.empty-hint { margin: auto; text-align: center; color: var(--muted); padding: 40px 16px; }
.dock { position: sticky; bottom: 0; padding: 12px 0 max(8px, env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%);
  display: flex; flex-direction: column; align-items: center; gap: 8px; }
.talk-btn { width: 68px; height: 68px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink);
  font-size: .62rem; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; box-shadow: 0 4px 16px rgb(0 0 0 / .3);
  display: grid; place-items: center; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.talk-btn .dot { display: block; width: 14px; height: 14px; border-radius: 50%; background: currentColor; margin: 0 auto 4px; }
.talk-btn.recording { background: var(--danger); color: #fff; animation: pulse 1.2s infinite; }
.talk-btn.recording .dot { border-radius: 4px; }
.talk-btn.listening { background: var(--panel-2); color: var(--ok); border: 2px solid var(--ok); animation: breathe 2.4s infinite; }
@keyframes breathe { 0%, 100% { box-shadow: 0 0 0 0 rgb(127 191 127 / .35); } 50% { box-shadow: 0 0 0 12px rgb(127 191 127 / 0); } }
.talk-btn { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.dock .modes { width: min(320px, 100%); }
.talk-btn.busy { background: var(--panel-2); color: var(--text); border: 2px solid var(--accent); }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgb(224 108 90 / .5); } 50% { box-shadow: 0 0 0 12px rgb(224 108 90 / 0); } }
.state { font-size: .85rem; color: var(--muted); min-height: 1.2em; }
.typebox { display: flex; gap: 8px; width: 100%; }
.typebox input { flex: 1; }

/* settings bits */
.modes { display: flex; gap: 4px; flex-wrap: wrap; }
.modes label { flex: 1; min-width: 64px; }
.modes input { position: absolute; opacity: 0; }
.modes span { display: block; text-align: center; padding: 8px 6px; border: 1px solid var(--line); border-radius: 8px; font-size: .85rem; background: var(--panel); }
.modes input:checked + span { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.modes input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.server { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin: 8px 0; }
.server .head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.tools { margin-top: 10px; display: grid; gap: 2px; max-height: 280px; overflow-y: auto; }
.tools label { display: flex; gap: 8px; align-items: baseline; font-size: .9rem; padding: 4px 0; }
.check { display: flex; gap: 10px; align-items: center; margin: 12px 0; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.portrait-row { display: flex; gap: 14px; align-items: center; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 10px; z-index: 10; max-width: calc(100vw - 32px); }
.savebar { position: sticky; bottom: 0; background: var(--bg); padding: 12px 0 max(8px, env(safe-area-inset-bottom)); display: flex; gap: 8px; }
.savebar .btn.primary { flex: 1; }
.btn.small { padding: 6px 12px; font-size: .85rem; }
.overlay { position: fixed; inset: 0; background: rgb(0 0 0 / .45); display: grid; place-items: center; padding: 16px; z-index: 20; }
.dialog { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; width: min(380px, 100%); }
#title { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
/* iOS Safari zooms into any field with text under 16px when it's tapped, and stays zoomed. */
@media (pointer: coarse) {
  input, select, textarea { font-size: 16px !important; }
}
