:root {
  --bg: #f6f5f2; --card: #ffffff; --fg: #1b1d21; --muted: #6b6f78; --line: #e3e1dc;
  --accent: #2f6fdb; --accent-fg: #fff; --hl: #fff2b8; --err: #c0392b; --ok: #2e9e5b; --warn: #b7791f;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a; --card: #1d2026; --fg: #e9eaee; --muted: #9298a3; --line: #2c3038;
    --accent: #6b9cff; --accent-fg: #0d1117; --hl: #3a3420; --err: #ff7b6b; --ok: #4cc785; --warn: #e0a84a;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--fg);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { padding: env(safe-area-inset-top) 0 0; }
h1 { font-size: 1.15rem; margin: 0; letter-spacing: .01em; flex: 1; white-space: nowrap; }
h1 .home { color: inherit; text-decoration: none; }
h2 { font-size: .85rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 1.5rem 0 .5rem; }
h3 { font-size: .95rem; margin: 1rem 0 .3rem; }
.muted { color: var(--muted); } .small { font-size: .8rem; } .grow { flex: 1; min-width: 0; }
.error { color: var(--err); margin: .5rem 0 0; }
button, input, textarea, select { font: inherit; color: inherit; }
button { background: var(--accent); color: var(--accent-fg); border: 0; border-radius: 10px; padding: .6rem 1.1rem;
  cursor: pointer; font-weight: 600; }
button.ghost { background: transparent; color: var(--fg); border: 1px solid var(--line); font-weight: 500; }
button.small { padding: .3rem .6rem; font-size: .85rem; }
button.big { width: 100%; padding: 1rem; font-size: 1.1rem; border-radius: 99px; }
button.danger { background: var(--err); color: #fff; }
button:disabled { opacity: .5; cursor: default; }
input, textarea, select { width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: .55rem .7rem; }
input[type=checkbox] { width: 1.3rem; height: 1.3rem; accent-color: var(--accent); flex: none; margin: 0; }
.row { display: flex; gap: .5rem; margin-top: .6rem; align-items: center; flex-wrap: wrap; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 1rem; }
.pill { font-size: .75rem; padding: .15rem .55rem; border-radius: 99px; border: 1px solid var(--line); color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 55vw; }
.pill.ok { color: var(--ok); border-color: currentColor; } .pill.down { color: var(--err); border-color: currentColor; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
button:focus-visible, select:focus-visible, input:focus-visible, summary:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; }

header { display: flex; gap: .6rem; align-items: center; padding: .9rem 1rem; max-width: 760px; margin: auto; }
main { padding: 0 1rem 3rem; max-width: 760px; margin: auto; }
.banner { max-width: 728px; margin: 0 auto .5rem; padding: .6rem .9rem; border-radius: 10px; background: var(--hl);
  font-size: .9rem; width: calc(100% - 2rem); }
.banner.err { color: var(--err); }

.screen { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.screen .card { width: min(360px, 100%); display: grid; gap: .7rem; }

/* --- setup --------------------------------------------------------------- */
.group { margin-bottom: .8rem; }
.group-title { font-size: .85rem; color: var(--muted); margin: 0 0 .35rem .2rem; overflow-wrap: anywhere; }
.agents { list-style: none; margin: 0; padding: 0; display: grid; gap: .4rem; }
.agent { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: .65rem .8rem;
  display: grid; grid-template-columns: auto 1fr; gap: .2rem .7rem; align-items: center; }
.agent.checked { border-color: var(--accent); }
.agent .name { font-weight: 600; overflow-wrap: anywhere; }
.agent .meta { grid-column: 2; font-size: .8rem; color: var(--muted); overflow-wrap: anywhere; }
.agent .alias { grid-column: 2; margin-top: .3rem; padding: .4rem .6rem; font-size: .9rem; }
.st { font-size: .75rem; padding: .05rem .45rem; border-radius: 99px; border: 1px solid currentColor; white-space: nowrap; }
.st-working { color: var(--muted); } .st-done { color: var(--ok); }
.st-waiting { color: var(--accent); } .st-permission { color: var(--warn); }

.settings { display: grid; gap: .7rem; }
.settings label { display: grid; gap: .25rem; font-size: .85rem; color: var(--muted); }
.settings .pair { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; align-items: end; }
.cheat { margin-top: 1.5rem; }
.cheat summary { cursor: pointer; font-weight: 600; }
.cheat-body table { border-collapse: collapse; width: 100%; font-size: .9rem; }
.cheat-body th { text-align: left; vertical-align: top; padding: .3rem .6rem .3rem 0; white-space: nowrap; }
.cheat-body td { padding: .3rem 0; }
.cheat-body ul { margin: .2rem 0; padding-left: 1.2rem; font-size: .92rem; }
.cheat-body li { margin: .15rem 0; }
.start-row { margin: 1.5rem 0 1rem; }

/* --- session ------------------------------------------------------------- */
.status { text-align: center; }
.state-label { font-size: 2.2rem; font-weight: 700; line-height: 1.15; letter-spacing: -.01em; }
.state-label.listening { color: var(--err); }
.state-label.confirming { color: var(--warn); }
.state-label.sending { color: var(--accent); }
#state-detail { min-height: 1.45em; }
.player { justify-content: center; }
.player #play { width: 3rem; padding: .5rem 0; }
#time { flex: 1 0 100%; order: 3; text-align: left; margin: 0; font-variant-numeric: tabular-nums; }
.mic-row { align-items: stretch; }
.mic-row > * { flex: 1 1 8rem; padding: .7rem .5rem; border-radius: 14px; font-size: 1.05rem; line-height: 1.2; }
.mic-row .hint { display: block; font-size: .75rem; font-weight: 400; opacity: .8; margin-top: .15rem; }
.mic-row .hint[hidden] { display: none; }
.mic::before { content: ""; display: inline-block; width: .7em; height: .7em; border-radius: 50%; background: currentColor;
  margin-right: .5em; vertical-align: -.02em; }
.mic[aria-pressed="true"], .mic-cmd[aria-pressed="true"] { background: var(--err); color: #fff; border-color: var(--err); }
.mic[aria-pressed="true"]::before { border-radius: 2px; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .mic[aria-pressed="true"]::before { animation: none; } }
#resume { margin-top: .8rem; }

.draft { margin-top: 1rem; border-color: var(--warn); }
#draft-text { font-size: 1.1rem; margin: .4rem 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }

.announcement .who { font-size: .85rem; color: var(--muted); margin-bottom: .4rem; }
/* command chips: one row per group, its small label on the left */
.chips { display: grid; gap: .45rem; }
.chip-group { display: grid; grid-template-columns: 5.2rem 1fr; gap: .35rem; align-items: start; }
.chip-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding-top: .4rem; }
.chip-row { display: flex; flex-wrap: wrap; gap: .35rem; min-width: 0; }

.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4 { font-size: 1.05rem; text-transform: none; letter-spacing: 0; color: var(--fg); margin: 1rem 0 .4rem; }
.md h1 { font-size: 1.2rem; }
.md p { margin: .5rem 0; }
.md ul, .md ol { padding-left: 1.3rem; margin: .4rem 0; }
.md code { font: .88em ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--bg); border-radius: 4px; padding: .05em .3em; }
.md pre { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: .6rem .7rem; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { margin: .5rem 0; padding-left: .8rem; border-left: 3px solid var(--line); color: var(--muted); }
.md .table { overflow-x: auto; margin: .5rem 0; }
.md table { border-collapse: collapse; font-size: .9rem; min-width: 100%; }
.md th, .md td { border: 1px solid var(--line); padding: .3rem .5rem; text-align: left; vertical-align: top; }
.md th { background: var(--bg); }
.md a { color: var(--accent); }

.followed { display: grid; gap: .5rem; }
.fcard { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: .7rem .9rem;
  display: flex; gap: .6rem; align-items: center; }
.fcard .name { font-weight: 600; overflow-wrap: anywhere; }
.fcard .meta { font-size: .8rem; color: var(--muted); overflow-wrap: anywhere; }
.fcard .del { background: none; color: var(--muted); padding: .3rem .5rem; font-size: 1.1rem; }

.history { list-style: none; padding: 0; margin: 0; display: grid; gap: .4rem; }
.history li { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: .5rem .8rem; font-size: .92rem; }
.history .meta { font-size: .75rem; color: var(--muted); }
.history .failed { color: var(--err); }

/* --- side panel ---------------------------------------------------------- */
.panel { position: fixed; inset: 0; background: #0006; z-index: 10; display: flex; justify-content: flex-end; }
.panel-inner { background: var(--bg); width: min(420px, 100%); height: 100%; overflow-y: auto;
  padding: calc(1rem + env(safe-area-inset-top)) 1rem calc(2rem + env(safe-area-inset-bottom)); box-shadow: -6px 0 24px #0003; }
.panel-head { margin-top: 0; }
.panel-head h2 { margin: 0; }

/* --- agent picker (dialog of the Agents chips) ------------------------------ */
.picker { border: 0; padding: 0; background: transparent; color: var(--fg); width: min(440px, calc(100% - 2rem));
  max-height: calc(100% - 2rem); margin: auto; }
.picker::backdrop { background: #0006; }
.picker-inner { background: var(--bg); border: 1px solid var(--line); border-radius: 14px; padding: 1rem;
  max-height: calc(100vh - 2rem); overflow-y: auto; box-shadow: 0 8px 32px #0004; }
.picker .agent { width: 100%; text-align: left; color: var(--fg); font-weight: 400; grid-template-columns: 1fr; }
.picker .agent:hover { border-color: var(--accent); }
.picker .agent .meta { grid-column: 1; }
/* without a working showModal(): an open element over its own backdrop (a tap outside closes) */
.picker.fallback[open] { position: fixed; inset: 0; z-index: 100; width: 100%; height: 100%; max-width: none; max-height: none;
  margin: 0; display: flex; align-items: center; justify-content: center; background: #0006; }
.picker.fallback .picker-inner { width: min(440px, calc(100% - 2rem)); }

/* build of the running script (and of the page, when they differ) */
.version { margin: 2rem 0 1rem; text-align: center; font-size: .75rem; color: var(--muted); }
