/* Scooby AI Live Playground. Colour = who owns the time: phone line (brown), LiveKit (blue),
   our worker (green), Gemini (orange). */
:root {
  --paper: #eef1ed; --panel: #fbfcfa; --ink: #17201c; --muted: #5d6963; --rule: #d3dad5;
  --c-phone: #8a6a34; --c-lk: #2f66d0; --c-worker: #0b8268; --c-ai: #c9681c; --c-ai-light: #e7a46b; --c-live: #c62828;
  --c-phone-soft: #efe4cf; --c-lk-soft: #dbe5f8; --c-worker-soft: #d2ece4; --c-ai-soft: #f6e0cc;
  --on-color: #ffffff; --changed: #b45309;
  --font-display: "Archivo", "Arial Narrow", system-ui, sans-serif;
  --font-body: "Source Sans 3", "Segoe UI", system-ui, sans-serif;
  --font-data: "JetBrains Mono", ui-monospace, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0f1412; --panel: #161d1a; --ink: #e3eae6; --muted: #98a59f; --rule: #2c3733;
    --c-phone: #cfa762; --c-lk: #77a0f2; --c-worker: #43c3a4; --c-ai: #f0a35a; --c-ai-light: #9c6a3c; --c-live: #f2867e;
    --c-phone-soft: #3a3020; --c-lk-soft: #1f2c47; --c-worker-soft: #163a31; --c-ai-soft: #45301c;
    --on-color: #0f1412; --changed: #f5b04c; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--font-body); font-size: 15px; line-height: 1.45; padding: 16px 16px 48px; }
.app { max-width: 1400px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
#liveView { display: flex; flex-direction: column; gap: 14px; }
[hidden] { display: none !important; }
h2, h3 { font-family: var(--font-display); margin: 0; }
p { margin: 0; }
.muted { color: var(--muted); }
.mono { font-family: var(--font-data); }
.views { display: flex; gap: 4px; background: var(--panel); border: 1px solid var(--rule); border-radius: 999px; padding: 4px; align-self: flex-start; }
.views button { font: 600 14px var(--font-body); border: 0; background: none; color: var(--muted); padding: 7px 16px; border-radius: 999px; cursor: pointer; }
.views button[aria-selected="true"] { background: var(--ink); color: var(--paper); }
.topbar { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end; background: var(--panel); border: 1px solid var(--rule); border-radius: 10px; padding: 12px 14px; }
.brand { font-family: var(--font-display); font-weight: 800; font-stretch: 78%; font-size: 24px; margin-right: 6px; align-self: center; }
.field { display: flex; flex-direction: column; gap: 2px; }
.field label { font-family: var(--font-data); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
input, select, textarea { font: inherit; color: var(--ink); background: var(--paper); border: 1px solid var(--rule); border-radius: 6px; padding: 7px 10px; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible { outline: 2px solid var(--c-lk); outline-offset: 1px; }
.seg2 { display: flex; border: 1px solid var(--rule); border-radius: 8px; overflow: hidden; align-self: flex-end; }
.seg2 button { font: 600 14px var(--font-body); border: 0; background: var(--panel); color: var(--muted); padding: 8px 12px; cursor: pointer; }
.seg2 button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.btn { font: 600 15px var(--font-body); border: 0; border-radius: 999px; padding: 9px 18px; cursor: pointer; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.call { background: var(--c-worker); color: var(--on-color); min-width: 110px; }
.btn.hang { background: var(--c-live); color: var(--on-color); min-width: 110px; }
.btn.ghost { background: var(--panel); color: var(--ink); border: 1px solid var(--rule); font-size: 14px; padding: 7px 14px; }
.btn.small { font-size: 13px; padding: 4px 10px; }
.status { display: inline-flex; align-items: center; gap: 8px; font-family: var(--font-data); font-size: 13px; margin-left: auto; align-self: center; }
.status i { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.status.live i { background: var(--c-live); box-shadow: 0 0 0 4px color-mix(in srgb, var(--c-live) 25%, transparent); animation: pulse 1.2s infinite; }
.status.ringing i { background: var(--c-phone); animation: pulse .6s infinite; }
@keyframes pulse { 50% { opacity: .4; } }
.error { background: color-mix(in srgb, var(--c-live) 12%, var(--panel)); border: 1px solid var(--c-live); color: var(--ink); border-radius: 8px; padding: 10px 14px; }
.grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(340px, 1fr); gap: 14px; align-items: start; }
.col { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.panel { background: var(--panel); border: 1px solid var(--rule); border-radius: 10px; padding: 14px; min-width: 0; }
.side { position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow-y: auto; }
.ph { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.ph h2 { font-size: 17px; font-weight: 700; }
.ph span { font-family: var(--font-data); font-size: 12px; color: var(--muted); }
.loopbox { overflow-x: auto; }
.loopbox svg { width: 100%; min-width: 620px; height: auto; display: block; }
.loopfoot { display: flex; flex-wrap: wrap; gap: 6px 18px; justify-content: space-between; font-size: 13px; margin-top: 6px; }
.check { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
svg text { font-family: var(--font-body); fill: var(--ink); }
.nd { cursor: pointer; }
.nd circle.b { stroke-width: 2; transition: stroke-width .15s; }
.nd:hover circle.b, .nd.sel circle.b { stroke-width: 5; }
.nd.on circle.b { stroke-width: 6; }
.nd:focus { outline: none; }
.nd:focus-visible circle.b { stroke-width: 6; }
.nl { font-family: var(--font-display); font-weight: 700; font-size: 16px; text-anchor: middle; }
.nt { font-family: var(--font-data); font-size: 13px; text-anchor: middle; fill: var(--muted); }
.nt.live { fill: var(--ink); font-weight: 600; }
.clock { font-family: var(--font-display); font-weight: 800; font-stretch: 75%; font-size: 60px; text-anchor: middle; font-variant-numeric: tabular-nums; }
.caption { font-size: 17px; text-anchor: middle; fill: var(--muted); }
.hist { display: flex; align-items: flex-end; gap: 4px; height: 130px; padding-top: 6px; border-bottom: 1px solid var(--rule); }
.hb { flex: 1; max-width: 46px; display: flex; flex-direction: column-reverse; border-radius: 3px 3px 0 0; overflow: hidden; min-width: 6px; position: relative; }
.hb > i { display: block; flex: none; }
.hb:hover { outline: 2px solid var(--ink); }
.hlab { display: flex; gap: 4px; font-family: var(--font-data); font-size: 10.5px; color: var(--muted); }
.hlab span { flex: 1; max-width: 46px; text-align: center; min-width: 6px; overflow: hidden; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; margin-top: 8px; }
.legend span { display: inline-flex; gap: 6px; align-items: center; }
.sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.tx { display: flex; flex-direction: column; gap: 10px; max-height: 420px; overflow-y: auto; }
.msg { display: grid; grid-template-columns: 64px 1fr; gap: 10px; }
.who { font-family: var(--font-data); font-size: 11px; color: var(--muted); padding-top: 3px; }
.bubble { padding: 8px 12px; border-radius: 8px; background: var(--paper); }
.msg.assistant .bubble { background: var(--c-ai-soft); }
.msg.note .bubble { background: none; border: 1px dashed var(--rule); color: var(--muted); font-size: 13px; padding: 4px 10px; }
.gapchip { display: inline-flex; gap: 6px; align-items: center; margin-top: 5px; font-family: var(--font-data); font-size: 11px; color: var(--muted); }
.mini { display: inline-flex; height: 8px; width: 120px; border-radius: 2px; overflow: hidden; background: var(--rule); }
.mini i { display: block; }
.evlog { margin-top: 12px; font-size: 13px; }
.evlog summary { cursor: pointer; color: var(--muted); }
.evlog ol { font-family: var(--font-data); font-size: 11.5px; max-height: 240px; overflow-y: auto; margin: 6px 0 0; padding-left: 0; list-style: none; }
.evlog li { padding: 1px 0; border-bottom: 1px dotted var(--rule); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--rule); margin-bottom: 12px; }
.tabs button { font: 600 14px var(--font-body); background: none; border: 0; padding: 8px 12px; color: var(--muted); cursor: pointer; border-bottom: 3px solid transparent; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }
.tabs .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--changed); margin-left: 5px; vertical-align: middle; }
.groups { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.groups button { font: 13px var(--font-body); border: 1px solid var(--rule); background: var(--paper); color: var(--ink); border-radius: 999px; padding: 4px 11px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.groups button[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.groups i { width: 9px; height: 9px; border-radius: 50%; }
.groups b { font-family: var(--font-data); font-size: 11px; color: var(--changed); }
.sethead { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.sethead i { width: 16px; height: 16px; border-radius: 50%; }
.sethead h3 { font-size: 20px; font-stretch: 85%; }
.setsub { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.setlist { display: flex; flex-direction: column; gap: 14px; }
.set { display: flex; flex-direction: column; gap: 4px; }
.set .row { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; font-weight: 600; align-items: baseline; }
.set .row b { font-family: var(--font-data); font-weight: 600; font-size: 13px; white-space: nowrap; }
.set.changed .row b { color: var(--changed); }
.set small { color: var(--muted); font-size: 12.5px; }
.set .base { font-family: var(--font-data); font-size: 11.5px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.set .base button { font: 11.5px var(--font-data); border: 0; background: none; color: var(--c-lk); cursor: pointer; padding: 0; text-decoration: underline; }
.set input[type=range] { width: 100%; padding: 0; accent-color: var(--ink); }
.set select, .set input[type=text] { width: 100%; }
.toggle { display: inline-flex; gap: 8px; align-items: center; cursor: pointer; }
.applies { font-family: var(--font-data); font-size: 11px; color: var(--muted); margin-top: 12px; border-top: 1px solid var(--rule); padding-top: 10px; }
.layers { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.layers button { font: 12.5px var(--font-body); border: 1px solid var(--rule); background: var(--paper); color: var(--ink); border-radius: 6px; padding: 4px 9px; cursor: pointer; max-width: 100%; text-align: left; }
.layers button[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.layers button.changed::after { content: " •"; color: var(--changed); font-weight: 700; }
.partHead { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 6px; font-size: 14px; flex-wrap: wrap; }
textarea { width: 100%; min-height: 340px; font-family: var(--font-data); font-size: 12.5px; line-height: 1.5; resize: vertical; }
#learnerJson { min-height: 420px; }
.pfoot { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 10px; font-size: 13px; }
/* history */
.hgrid { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 14px; align-items: start; }
.scrollx { overflow-x: auto; }
.calls { width: 100%; border-collapse: collapse; font-size: 14px; }
.calls th, .calls td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--rule); vertical-align: top; }
.calls th { font-family: var(--font-data); font-size: 10.5px; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.calls .r, .calls td.n { text-align: right; }
.calls tbody tr { cursor: pointer; }
.calls tbody tr:hover, .calls tbody tr.sel { background: var(--paper); }
.calls td.n { font-family: var(--font-data); white-space: nowrap; }
.chip { display: inline-block; font-family: var(--font-data); font-size: 11px; padding: 1px 7px; border-radius: 4px; margin: 2px 4px 0 0; background: var(--c-worker-soft); color: var(--c-worker); }
.chip.ai { background: var(--c-ai-soft); color: var(--c-ai); }
.chip.lk { background: var(--c-lk-soft); color: var(--c-lk); }
.chip.phone { background: var(--c-phone-soft); color: var(--c-phone); }
.chip.same { background: var(--paper); color: var(--muted); border: 1px solid var(--rule); }
.det { display: flex; flex-direction: column; gap: 16px; position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow-y: auto; }
.det h3 { font-size: 15px; margin: 0 0 6px; }
.kv { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--rule); border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; }
.kv div { background: var(--panel); padding: 10px 12px; }
.kv b { display: block; font-family: var(--font-display); font-weight: 800; font-stretch: 78%; font-size: 24px; font-variant-numeric: tabular-nums; }
.kv span { font-size: 12.5px; color: var(--muted); }
.diff { font-size: 13.5px; display: flex; flex-direction: column; gap: 4px; }
.diff div { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; border-bottom: 1px dashed var(--rule); padding-bottom: 4px; }
.diff s { color: var(--muted); font-family: var(--font-data); }
.diff b { font-family: var(--font-data); }
.wavebox { position: relative; }
.wavebox canvas { width: 100%; height: 110px; display: block; background: var(--paper); border-radius: 6px; cursor: pointer; }
audio { width: 100%; margin-top: 6px; }
.grade { border-left: 3px solid var(--c-worker); padding-left: 10px; font-size: 14px; }
.cmp { width: 100%; border-collapse: collapse; font-size: 14px; }
.cmp th, .cmp td { padding: 7px 8px; border-bottom: 1px solid var(--rule); text-align: left; }
.cmp td.v { font-family: var(--font-data); }
.cmp td.better { color: var(--c-worker); font-weight: 700; }
dialog { border: 1px solid var(--rule); border-radius: 10px; background: var(--panel); color: var(--ink); max-width: min(900px, 94vw); width: 100%; }
dialog pre { white-space: pre-wrap; font-family: var(--font-data); font-size: 12px; max-height: 70vh; overflow-y: auto; }
dialog::backdrop { background: rgba(0,0,0,.4); }
@media (max-width: 1000px) { .grid, .hgrid { grid-template-columns: 1fr; } .side, .det { position: static; max-height: none; } .status { margin-left: 0; } .kv { grid-template-columns: 1fr 1fr; } }
@media (prefers-reduced-motion: reduce) { .status i { animation: none !important; } }

/* Panels that scroll must not squash their children. */
.det > *, .side > *, .col > * { flex-shrink: 0; }

/* setup bar, presets, config history, export */
.setupbar { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; background: var(--panel); border: 1px solid var(--rule); border-radius: 10px; padding: 8px 14px; }
.setupbar .label { font-family: var(--font-data); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.setupchips { flex: 1; min-width: 0; }
.setupbtns { display: flex; flex-wrap: wrap; gap: 6px; }
.form { display: flex; flex-direction: column; gap: 12px; margin: 12px 0; }
.form label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 14px; }
.form textarea { min-height: 70px; font-family: var(--font-body); font-size: 14px; }
.cards { display: flex; flex-direction: column; gap: 10px; margin: 12px 0; max-height: 62vh; overflow-y: auto; }
.cardrow { border: 1px solid var(--rule); border-radius: 8px; padding: 10px 12px; display: grid; grid-template-columns: 1fr auto; gap: 6px 14px; align-items: start; }
.cardrow h4 { margin: 0; font-family: var(--font-display); font-size: 16px; }
.cardrow .meta { font-size: 12.5px; color: var(--muted); }
.cardrow .stats { font-family: var(--font-data); font-size: 12px; text-align: right; white-space: nowrap; }
.cardrow .acts { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; }
.cardrow .note { font-size: 13.5px; }
.badge { font-family: var(--font-data); font-size: 11px; background: var(--ink); color: var(--paper); border-radius: 4px; padding: 1px 6px; margin-left: 6px; }
textarea.md { min-height: 52vh; font-size: 12px; }
.modalfoot { display: flex; justify-content: flex-end; margin-top: 8px; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 8px 16px; border-radius: 999px; font-size: 14px; z-index: 10; }

/* header row: screens on the left, the setup on the right */
.header { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; justify-content: space-between; }
.setup { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; background: var(--panel); border: 1px solid var(--rule); border-radius: 999px; padding: 4px 6px 4px 14px; }
.setup label { font-family: var(--font-data); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.setup select { border: 0; background: var(--paper); border-radius: 999px; padding: 5px 10px; font-weight: 600; max-width: 230px; }
.setup .count { font: 600 12px var(--font-data); color: var(--changed); background: none; border: 0; cursor: pointer; padding: 2px 4px; }
.setup .count:hover { text-decoration: underline; }
.setup .divider { width: 1px; height: 20px; background: var(--rule); margin: 0 4px; }
.setup .btn.small { border: 0; background: none; }
.setup .btn.small:hover { background: var(--paper); }
