:root {
  --bg: #11141B; --panel: #1B2029; --line: #2C3340; --text: #EEF0EA; --muted: #AEB6C2;
  --accent: #FF8A3D; --accent-ink: #11141B; --cyan: #5CC8DB; --good: #5DD39E; --bad: #FF6B6B;
  --radius: 18px; --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
[hidden] { display: none !important; }
.screen { height: 100dvh; display: flex; flex-direction: column; }
.muted { color: var(--muted); }
.error { color: var(--bad); min-height: 1.4em; }
.mono { font-family: ui-monospace, "JetBrains Mono", Consolas, monospace; font-size: 22px; letter-spacing: 2px; text-align: center; }

/* pairing */
#pair { align-items: center; justify-content: center; padding: 24px; }
.pair-card { width: 100%; max-width: 380px; text-align: center; }
.logo { width: 72px; height: 72px; }
.pair-card h1 { font-size: 26px; margin: 12px 0 8px; }
#pair-form { display: flex; gap: 10px; margin-top: 20px; }
#pair-code { flex: 1; min-width: 0; background: var(--panel); border: 2px solid var(--line); border-radius: 14px; color: var(--text); font: 600 24px/1 ui-monospace, Consolas, monospace; letter-spacing: 4px; text-align: center; padding: 14px 8px; text-transform: uppercase; }
#pair-code:focus { outline: none; border-color: var(--accent); }
.primary { background: var(--accent); color: var(--accent-ink); font-weight: 650; border-radius: 14px; padding: 12px 20px; }

/* header */
.top { position: relative; display: flex; align-items: center; justify-content: space-between; padding: calc(10px + env(safe-area-inset-top, 0px)) 12px 10px 16px; border-bottom: 1px solid var(--line); }
.status { display: flex; align-items: center; gap: 12px; min-width: 0; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--bad); flex: none; box-shadow: 0 0 0 3px rgba(255,107,107,.18); }
.dot.on { background: var(--good); box-shadow: 0 0 0 3px rgba(93,211,158,.18); }
.status-text { min-width: 0; }
.game { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; color: var(--muted); flex: none; }
.icon-btn svg { width: 24px; height: 24px; fill: currentColor; }
.icon-btn.small { width: 28px; height: 28px; font-size: 20px; }
.icon-btn.active { color: var(--accent-ink); background: var(--cyan); }
.menu { position: absolute; right: 10px; top: calc(100% - 4px); z-index: 10; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 6px; min-width: 240px; max-height: calc(100dvh - 90px); overflow-y: auto; overscroll-behavior: contain; box-shadow: 0 12px 32px rgba(0,0,0,.45); }
.menu button { display: block; width: 100%; text-align: left; padding: 12px 14px; border-radius: 10px; }
.menu button:active, .menu button:hover { background: var(--line); }
.menu .danger { color: var(--bad); }

/* tabs */
.tabs { display: flex; padding: 6px 12px 0; gap: 4px; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; padding: 12px 8px 10px; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
#tab-feedback[aria-selected="true"] { border-bottom-color: var(--cyan); }
.badge { display: inline-block; min-width: 8px; height: 8px; border-radius: 4px; background: var(--cyan); vertical-align: middle; margin-left: 4px; }

/* conversation */
.log { flex: 1; overflow-y: auto; padding: 16px 14px 8px; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; }
/* Items keep their height: in a full column flex box, an overflow:hidden child (the controller picture) would otherwise shrink to nothing. */
.log > * { flex-shrink: 0; }
.msg { max-width: 86%; padding: 11px 14px; border-radius: var(--radius); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--line); border-bottom-right-radius: 6px; }
.msg.assistant { align-self: flex-start; background: var(--panel); border: 1.5px solid var(--accent); border-bottom-left-radius: 6px; position: relative; padding-right: 40px; }
.feedback .msg.assistant { border-color: var(--cyan); }
.msg .q { display: block; font-size: 13px; color: var(--muted); border-left: 3px solid var(--cyan); padding-left: 8px; margin-bottom: 6px; white-space: normal; }
.flag { position: absolute; right: 4px; top: 4px; width: 32px; height: 32px; display: grid; place-items: center; color: var(--muted); opacity: .7; border-radius: 8px; }
.flag svg { width: 16px; height: 16px; fill: currentColor; }
.speak { position: absolute; right: 4px; top: 38px; width: 32px; height: 32px; display: grid; place-items: center; color: var(--muted); opacity: .7; border-radius: 8px; }
.speak.top { top: 4px; }
.speak svg { width: 18px; height: 18px; fill: currentColor; }
.msg.assistant:has(.speak:not(.top)) { min-height: 74px; }
.notice { align-self: center; font-size: 13px; color: var(--muted); text-align: center; max-width: 92%; }
.notice a { color: var(--cyan); }
/* The live controller view (ctrlcard.js), pinned to the top of the Assistant chat: the view fits itself to whatever
   height it is given; the bar under it drags it taller or shorter, ⌃ folds it away. */
.cvdock { flex: none; position: relative; border-bottom: 1px solid var(--line); background: #0B0D12; font: 15px/1.35 system-ui, sans-serif; }
.feedback .cvdock { display: none; }
.cvdock .cvbox { position: relative; height: 34vh; min-height: 96px; }
.cvdock.folded .cvbox { display: none; }
.cvdock .cvbar { display: flex; align-items: center; gap: 6px; padding: 3px 8px 3px 14px; color: var(--muted); font-size: 12px; }
.cvdock .cvname { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cvdock .cvgrip { position: absolute; left: 0; right: 0; bottom: -7px; height: 14px; cursor: ns-resize; touch-action: none; z-index: 2; }
.cvdock .cvgrip::after { content: ''; position: absolute; left: 50%; top: 5px; width: 44px; height: 4px; margin-left: -22px; border-radius: 2px; background: var(--line); }
.cvgrow { border: 1px solid var(--line); background: transparent; color: var(--text); border-radius: 10px; min-width: 34px; height: 28px; padding: 0 8px; font-size: 15px; cursor: pointer; }
.cvgrow.cvstyle { font-size: 12px; font-weight: 600; color: var(--muted); }
.cvgrow[hidden] { display: none; }
/* The style picker: every style with what it is, the one in use ticked. */
.cvpick { position: fixed; z-index: 60; width: max-content; min-width: 220px; max-width: min(340px, calc(100vw - 16px)); max-height: min(72vh, 520px); overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 6px; box-shadow: 0 14px 36px rgba(0, 0, 0, .5); }
.cvpick button { display: grid; grid-template-columns: 18px 1fr; column-gap: 8px; width: 100%; text-align: left; padding: 10px 12px; border-radius: 10px; }
.cvpick button:hover, .cvpick button:active, .cvpick button:focus-visible { background: var(--line); outline: none; }
.cvpick .ck { grid-row: span 2; color: var(--accent); font-weight: 700; }
.cvpick .nm { font-weight: 600; }
.cvpick .ab { font-size: 13px; line-height: 1.3; color: var(--muted); }
.cvpick button[aria-checked="true"] .nm { color: var(--accent); }
/* The controller view full screen. */
#cv-full { width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; border-radius: 0; background: #0B0D12; font: 15px/1.35 system-ui, sans-serif; }
#cv-full .cvbox { position: absolute; inset: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); }
#cv-full .cvclose { position: absolute; top: max(6px, env(safe-area-inset-top)); right: max(6px, env(safe-area-inset-right)); z-index: 5; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: rgba(11,13,18,.85); color: var(--text); font-size: 24px; line-height: 1; cursor: pointer; }
.enter { animation: enter .35s cubic-bezier(.2,.8,.2,1) both; }
.msg.assistant.enter { animation: enter .35s cubic-bezier(.2,.8,.2,1) both, glow 1.2s ease-out .1s; }
@keyframes enter { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes glow { from { box-shadow: 0 0 0 4px rgba(255,138,61,.35); } to { box-shadow: 0 0 0 0 rgba(255,138,61,0); } }
@media (prefers-reduced-motion: reduce) { .enter, .msg.assistant.enter { animation: none; } }
/* At the top of the chat, never under the hold-to-talk button in the middle of the screen (Dan, 2026-10-27). */
.empty { margin: 12px auto auto; text-align: center; color: var(--muted); max-width: 320px; padding: 24px; }
.empty b { color: var(--text); display: block; font-size: 18px; margin-bottom: 6px; }

.activity { display: flex; align-items: center; gap: 10px; padding: 6px 16px; color: var(--muted); font-size: 14px; }
.activity.slow { color: var(--accent); }
.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.link { color: var(--cyan); padding: 6px 8px; margin-left: auto; }

.quote { display: flex; align-items: center; gap: 8px; margin: 0 12px; padding: 8px 10px; background: var(--panel); border-left: 3px solid var(--cyan); border-radius: 8px; font-size: 13px; color: var(--muted); }
.quote span { flex: 1; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* composer */
.composer { padding: 8px 10px calc(10px + var(--safe-b)); border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.chip { align-self: flex-start; font-size: 14px; padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.feedback .chip { display: none; }
.row { display: flex; align-items: flex-end; gap: 6px; }
.row.end { justify-content: flex-end; }
#input { flex: 1; min-width: 0; resize: none; max-height: 140px; background: var(--panel); color: var(--text); border: 1.5px solid var(--line); border-radius: 22px; padding: 11px 16px; font: inherit; }
#input:focus { outline: none; border-color: var(--muted); }
.count { font-size: 12px; color: var(--muted); text-align: right; padding: 0 12px; }
.count.full { color: #ff9a3c; }
.round { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; background: var(--panel); border: 1.5px solid var(--line); flex: none; }
.round svg { width: 22px; height: 22px; fill: currentColor; }
.round.accent { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
#mic-btn { touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
#mic-btn.listening { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 10px rgba(255,138,61,.15); } }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 18px; width: min(92vw, 380px); padding: 20px; }
dialog::backdrop { background: rgba(0,0,0,.55); }
dialog h2 { margin: 0 0 12px; font-size: 20px; }
dialog label { display: block; color: var(--muted); font-size: 14px; }
dialog input { display: block; width: 100%; margin-top: 6px; background: var(--bg); color: var(--text); border: 1.5px solid var(--line); border-radius: 12px; padding: 12px; font: inherit; }
dialog select { display: block; width: 100%; margin: 6px 0 14px; background: var(--bg); color: var(--text); border: 1.5px solid var(--line); border-radius: 12px; padding: 11px 10px; font: inherit; }
#audio-dialog [hidden] { display: none !important; }
#mic-btn.live-speaking { animation: none; opacity: .85; }

/* Hold to talk: a big, see-through red button over the middle of the chat. Audio is only sent while it's held. */
.ptt { position: fixed; left: 50%; top: var(--ptt-y, 50%); transform: translate(-50%, -50%); width: 148px; height: 148px; border-radius: 50%; z-index: 5;
  display: grid; place-items: center; align-content: center; gap: 4px; color: #fff; font: 600 13px/1.2 system-ui, sans-serif;
  background: rgba(220, 38, 38, .32); border: 3px solid rgba(255, 90, 90, .55); box-shadow: 0 6px 24px rgba(0, 0, 0, .25);
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
  transition: transform .12s ease, background .12s ease; }
.ptt svg { width: 40px; height: 40px; fill: currentColor; }
.ptt.held { background: rgba(220, 38, 38, .78); border-color: rgba(255, 140, 140, .9); transform: translate(-50%, -50%) scale(1.08); animation: pttpulse 1s ease-in-out infinite; }
.ptt.busy { opacity: .6; }
@keyframes pttpulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, .55); } 50% { box-shadow: 0 0 0 18px rgba(220, 38, 38, 0); } }
.ptt[hidden] { display: none; }
#invite-dialog .invite-code, #devices-dialog .invite-code { font-family: ui-monospace, "JetBrains Mono", Consolas, monospace; font-size: 26px; letter-spacing: 3px; text-align: center; margin: 8px 0; user-select: all; -webkit-user-select: all; }
#invite-dialog .invite-msg { white-space: pre-wrap; word-break: break-word; font: 13px/1.4 system-ui, sans-serif; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 10px; max-height: 30vh; overflow: auto; user-select: text; -webkit-user-select: text; }
#invite-dialog .invite-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 4px; }
#invite-dialog .invite-actions a { text-decoration: none; color: inherit; display: inline-flex; align-items: center; }
#invite-dialog .small { font-size: 12px; }
#invite-dialog [hidden] { display: none !important; }
.menu-note { padding: 10px 16px; font-size: 14px; color: var(--muted, #9aa3ad); }
.menu-note[hidden] { display: none; }
#mic-btn.live-connected { border-color: var(--accent); color: var(--accent); }
#testers-dialog { width: min(94vw, 460px); }
#testers-list { max-height: 60vh; overflow: auto; margin: 4px -4px 8px; }
.tester { border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; margin: 0 4px 8px; background: var(--bg); }
.tester-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.tester-name { font-weight: 600; overflow-wrap: anywhere; }
.tester-when { color: var(--muted); font-size: 12px; white-space: nowrap; }
.tester-when.new { color: var(--cyan); }
.tester table { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 13px; font-variant-numeric: tabular-nums; }
.tester th { color: var(--muted); font-weight: 400; text-align: right; padding: 2px 0 2px 8px; }
.tester th:first-child, .tester td:first-child { text-align: left; padding-left: 0; color: var(--muted); }
.tester td { text-align: right; padding: 2px 0 2px 8px; }
.tester .split { color: var(--muted); font-size: 12px; margin-top: 4px; }
.testers-total { display: flex; justify-content: space-between; font-size: 14px; margin: 0 4px 8px; }

/* License codes (owner) */
#codes-dialog { width: min(94vw, 460px); max-height: 90dvh; overflow: auto; }
#codes-dialog label { margin-bottom: 10px; }
#codes-dialog h3 { margin: 14px 0 6px; font-size: 16px; }
.code-row { border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; margin-bottom: 8px; background: var(--bg); font-size: 13px; }
.code-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.code-text { font-family: ui-monospace, "JetBrains Mono", Consolas, monospace; font-size: 15px; user-select: all; -webkit-user-select: all; overflow-wrap: anywhere; }
.code-row .muted { color: var(--muted); overflow-wrap: anywhere; }

/* Your devices (Add a device) */
.devices-list { display: flex; flex-direction: column; gap: 8px; margin: 8px 0 16px; }
.device-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; }
.device-row b { font-size: 13px; color: var(--muted); font-weight: 500; }
#devices-dialog h3 { margin: 4px 0 6px; font-size: 16px; }

.pair-qr { display: flex; justify-content: center; margin: 8px 0; }
.pair-qr img, .pair-qr canvas { background: #fff; padding: 8px; border-radius: 10px; }
