:root {
  color-scheme: dark;
  --bg: #0f1012; --panel: #15171b; --raise: #1b1e23; --line: #26292e; --line2: #33373e;
  --ink: #e6e8eb; --mute: #8b9099; --faint: #5d626b; --acc: #46d8c4; --acc-ink: #06211d; --bad: #d86a7c;
  --r: 10px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; overflow: hidden; }
#app { height: 100dvh; display: flex; flex-direction: column; }

/* ---- top bar ---- */
.bar { display: flex; align-items: center; gap: 14px; height: 48px; padding: 0 16px; border-bottom: 1px solid var(--line); flex: none; }
.brand { font-weight: 600; letter-spacing: -.01em; font-size: 15px; }
.brand span { color: var(--mute); font-weight: 400; margin-left: 4px; }
.grow { flex: 1; }
.conn { display: flex; align-items: center; gap: 8px; color: var(--mute); font-size: 13px; white-space: nowrap; }
#dot { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
#dot.on { background: var(--acc); box-shadow: 0 0 0 3px rgba(70, 216, 196, .14); }
#dot.denied { background: var(--bad); }

/* ---- controls ---- */
button, input, select { font: inherit; color: var(--ink); }
button { background: var(--raise); border: 1px solid var(--line); border-radius: 8px; padding: 6px 11px; cursor: pointer; transition: background .12s, border-color .12s, color .12s; }
button:hover { border-color: var(--line2); background: #20242a; }
button:active { background: #252a31; }
button:disabled { opacity: .45; cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible { outline: 2px solid var(--acc); outline-offset: 1px; }
button.primary { background: var(--acc); border-color: var(--acc); color: var(--acc-ink); font-weight: 600; }
button.primary:hover { background: #5fe0cf; }
button[aria-pressed="true"] { border-color: rgba(70, 216, 196, .5); color: var(--acc); }
input[type=text], input[type=password], select { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; min-width: 0; width: 100%; }
input::placeholder { color: var(--faint); }
input[type=range] { accent-color: var(--acc); flex: 1; min-width: 0; }
input[type=checkbox] { accent-color: var(--acc); margin: 0 8px 0 0; }
kbd { font: 11px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--mute); border: 1px solid var(--line2); border-radius: 4px; padding: 1px 5px; margin-left: 8px; }
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 9px; padding: 2px; gap: 2px; }
.seg button { border: 0; background: transparent; color: var(--mute); padding: 4px 12px; border-radius: 7px; }
.seg button:hover { color: var(--ink); background: transparent; }
.seg button.on { background: var(--raise); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line2); }
.seg.wide { display: flex; } .seg.wide button { flex: 1; padding: 6px 4px; }

/* ---- layout ---- */
main { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 348px; }
#stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: var(--bg); }
#view3d, #direct { position: absolute; inset: 0; }
#view3d canvas { display: block; outline: none; }
#direct { display: none; align-items: center; justify-content: center; padding: 56px 28px 84px; }
[data-view="direct"] #direct { display: flex; } [data-view="direct"] #view3d { visibility: hidden; }
[data-view="direct"] .cube-only { display: none !important; }
.screenframe { flex: none; width: 320px; height: 240px; background: #050505; border-radius: 22px; border: 1px solid var(--line);
  box-shadow: 0 0 0 7px #0b0c0e, 0 0 0 8px var(--line), 0 30px 80px rgba(0, 0, 0, .5); overflow: hidden; cursor: pointer; touch-action: none; }
.screenframe canvas { width: 100%; height: 100%; display: block; }

.pill { position: absolute; left: 16px; top: 14px; display: flex; align-items: center; gap: 8px; padding: 5px 11px 5px 9px; border-radius: 999px;
  background: rgba(21, 23, 27, .82); border: 1px solid var(--line); color: var(--mute); font-size: 12.5px; backdrop-filter: blur(8px); pointer-events: none; }
.pill i { width: 7px; height: 7px; border-radius: 50%; background: var(--faint); }
.pill[data-state="waiting"] i, .pill[data-state="ready"] i { background: var(--mute); }
.pill[data-state="listening"] { color: var(--ink); border-color: rgba(70, 216, 196, .45); }
.pill[data-state="listening"] i { background: var(--acc); animation: pulse 1s infinite; }
.pill[data-state="thinking"] i { background: var(--acc); opacity: .55; animation: pulse 1.6s infinite; }
.pill[data-state="speaking"] { color: var(--ink); } .pill[data-state="speaking"] i { background: var(--acc); }
.pill[data-state="error"] i { background: var(--bad); }
@keyframes pulse { 50% { transform: scale(1.7); opacity: .35; } }
#caption { position: absolute; left: 50%; bottom: 46px; transform: translateX(-50%); max-width: min(680px, 86%); text-align: center; font-size: 16px; line-height: 1.4;
  color: var(--ink); text-shadow: 0 1px 12px rgba(0, 0, 0, .9); opacity: 0; transition: opacity .3s; pointer-events: none; }
#caption.on { opacity: 1; }
.tools { position: absolute; right: 14px; top: 12px; display: flex; gap: 6px; }
.tools button { background: rgba(21, 23, 27, .82); backdrop-filter: blur(8px); font-size: 12.5px; padding: 5px 10px; color: var(--mute); }
.tools button:hover { color: var(--ink); }
.hint { position: absolute; left: 0; right: 0; bottom: 14px; text-align: center; color: var(--faint); font-size: 12px; pointer-events: none; padding: 0 16px; }
.nogl { position: absolute; inset: auto 20px 20px 20px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); color: var(--mute); }

/* ---- side panel ---- */
#panel { border-left: 1px solid var(--line); background: var(--bg); overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; scrollbar-width: thin; scrollbar-color: var(--line2) transparent; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; }
h2, summary { margin: 0 0 10px; font-size: 11px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--mute); display: flex; align-items: center; justify-content: space-between; }
h2 .state { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--faint); font-size: 12px; }
h2 .state.on { color: var(--acc); } h2 .state.bad { color: var(--bad); }
summary { margin: 0; cursor: pointer; list-style: none; } summary::after { content: "show"; text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--faint); }
details[open] summary { margin-bottom: 10px; } details[open] summary::after { content: "hide"; }
.row { display: flex; gap: 6px; align-items: center; } .row.slim { margin: 10px 0 8px; gap: 10px; }
.mute { color: var(--mute); font-size: 13px; } .num { font-variant-numeric: tabular-nums; min-width: 36px; text-align: right; }
.url { margin: 8px 0 0; font: 11.5px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--faint); overflow-wrap: anywhere; }
.msg { margin: 10px 0 0; font-size: 12.5px; color: var(--bad); line-height: 1.4; }
.check { display: flex; align-items: center; font-size: 13.5px; cursor: pointer; } .check span { color: var(--faint); margin-left: 8px; font-size: 12px; }

.convo { max-height: 210px; min-height: 44px; overflow-y: auto; display: flex; flex-direction: column; gap: 7px; margin-bottom: 10px; scrollbar-width: thin; scrollbar-color: var(--line2) transparent; }
.convo p { margin: 0; font-size: 13.5px; line-height: 1.4; display: grid; grid-template-columns: 30px 1fr; gap: 6px; }
.convo p b { font-weight: 500; font-size: 11.5px; color: var(--faint); padding-top: 2px; }
.convo p.pip b { color: var(--acc); } .convo p.you span { color: var(--mute); }
.convo p.note, .convo p.empty { display: block; color: var(--faint); font-size: 12.5px; }

.talk { width: 100%; margin-top: 10px; padding: 12px; font-size: 14.5px; font-weight: 500; touch-action: none; user-select: none; -webkit-user-select: none; }
.talk.live { background: var(--acc); border-color: var(--acc); color: var(--acc-ink); }
.talk.live kbd { color: var(--acc-ink); border-color: rgba(6, 33, 29, .35); }
.meter { position: relative; height: 4px; border-radius: 2px; background: var(--line); margin-top: 10px; overflow: hidden; }
.meter > div { height: 100%; width: 0; background: var(--mute); border-radius: 2px; }
.meter.live > div { background: var(--acc); }
.meter > i { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--faint); left: 0; }

.preview { position: relative; margin-top: 10px; border-radius: 8px; overflow: hidden; background: #050505; aspect-ratio: 4 / 3; border: 1px solid var(--line); }
.preview video, .preview img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: none; }
.preview[data-src="webcam"] video, .preview[data-src="image"] img { display: block; }
.preview span { position: absolute; left: 8px; bottom: 7px; font-size: 11px; color: #cfd3d8; background: rgba(8, 9, 10, .65); padding: 2px 7px; border-radius: 999px; }
.preview::after { content: ""; position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.preview.flash::after { animation: flash .45s ease-out; }
@keyframes flash { 0% { opacity: .85; } 100% { opacity: 0; } }

.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; } .grid button { padding: 6px 2px; font-size: 12.5px; }
.imu { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 12px 0 0; font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }
.imu dt { color: var(--faint); } .imu dd { margin: 0; text-align: right; color: var(--mute); white-space: pre; }
#log { font: 11.5px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; max-height: 220px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--mute); }

/* ---- phone: stage on top, controls in a sheet ---- */
@media (max-width: 820px) {
  main { grid-template-columns: 1fr; grid-template-rows: minmax(250px, 44dvh) minmax(0, 1fr); }
  #panel { border-left: 0; border-top: 1px solid var(--line); border-radius: 16px 16px 0 0; margin-top: -14px; position: relative; z-index: 2; padding: 14px 12px calc(16px + env(safe-area-inset-bottom)); }
  #panel::before { content: ""; flex: none; width: 36px; height: 4px; border-radius: 2px; background: var(--line2); margin: -4px auto 0; }
  .bar { padding: 0 12px; gap: 10px; height: 44px; } .brand span { display: none; }
  .hint { display: none; } .tools { top: 48px; left: 12px; right: 12px; justify-content: flex-end; flex-wrap: wrap; }
  #caption { bottom: 26px; font-size: 14.5px; } #direct { padding: 50px 16px 34px; }
  .convo { max-height: 150px; }
  input[type=text], input[type=password], select { font-size: 16px; }   /* stops iOS zooming on focus */
}
@media (pointer: coarse) { kbd { display: none; } }

/* ---- a console game in an emulator, over the stage ---- */
.screenframe { position: relative; }
#gameHost { position: absolute; inset: 0; z-index: 5; background: #000; cursor: default; }
#gameHost iframe { width: 100%; height: 100%; border: 0; display: block; }
#gameHost button { position: absolute; top: 8px; right: 8px; width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line);
  background: rgba(10, 11, 13, .8); color: #cfd3d8; font-size: 18px; line-height: 1; cursor: pointer; }
#gameHost button:hover { color: #fff; }
#gameHost .keys { position: absolute; left: 0; right: 0; top: 8px; margin: auto; width: max-content; max-width: calc(100% - 96px); padding: 5px 10px; border-radius: 999px;
  background: rgba(10, 11, 13, .82); color: #cfd3d8; font-size: 11.5px; pointer-events: none; transition: opacity .6s; text-align: center; }
#gameHost.quiet .keys { opacity: 0; }

/* ---- ?full=1: only Pip, filling the screen (a phone on a stand, a spare monitor) ---- */
#fullInfo, #fullDock, #fullSign, #fullChat { display: none; }
html.full header.bar, html.full #panel, html.full .pill, html.full #stage > :not(#direct):not(#gameHost):not(#fullInfo):not(#fullDock):not(#fullSign):not(#fullChat):not(#world) { display: none !important; }
/* Just Pip: the face, what state it is in, the last exchange, and a place to type. Everything in one centred column. */
html.full #direct { flex-direction: column; justify-content: flex-start; padding: 0; }
html.full #fullInfo { display: flex; flex-direction: column; align-items: center; gap: 8px; position: absolute; left: 50%; transform: translateX(-50%); width: min(640px, calc(100% - 32px)); text-align: center; z-index: 6; transition: opacity .5s; }
#fullState { display: inline-flex; align-items: center; gap: 8px; padding: 5px 13px 5px 11px; border-radius: 999px; border: 1px solid var(--line); color: var(--mute); font-size: 13px; background: rgba(21, 23, 27, .7); transition: border-color .2s, color .2s; }
#fullState i { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
#fullState[data-state="ready"] i, #fullState[data-state="waiting"] i { background: var(--mute); }
#fullState[data-state="listening"] { color: var(--ink); border-color: var(--acc); } #fullState[data-state="listening"] i { background: var(--acc); animation: pulse 1s infinite; }
#fullState[data-state="thinking"] { color: var(--ink); } #fullState[data-state="thinking"] i { background: var(--acc); opacity: .6; animation: pulse 1.6s infinite; }
#fullState[data-state="speaking"] { color: var(--ink); } #fullState[data-state="speaking"] i { background: var(--acc); }
#fullState[data-state="error"] i, #fullState[data-state="off"] i { background: var(--bad); }
#fullInfo p { margin: 0; max-width: 100%; overflow-wrap: anywhere; } #fullInfo p:empty { display: none; }
#fullYou { color: var(--mute); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
#fullYou::before { content: "You  "; color: var(--faint); font-size: 12px; letter-spacing: .04em; text-transform: uppercase; }
#fullPip { color: var(--ink); font-size: 17px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
#fullNote { color: var(--faint); font-size: 12.5px; }
html.full #fullDock { display: flex; flex-direction: column; align-items: center; gap: 8px; position: absolute; left: 50%; transform: translateX(-50%); bottom: max(14px, env(safe-area-inset-bottom)); width: min(600px, calc(100% - 24px)); z-index: 20; transition: opacity .5s; }
#fullBar { display: flex; align-items: center; gap: 6px; width: 100%; padding: 6px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line2); }
#fullBar:focus-within { border-color: rgba(70, 216, 196, .55); }
#fullBar input { flex: 1; min-width: 0; background: transparent; border: 0; outline: 0; color: var(--ink); font: inherit; font-size: 15px; padding: 8px 6px; }
#fullMic { flex: none; width: 38px; height: 38px; border-radius: 50%; border: 0; background: var(--raise); color: var(--ink); display: grid; place-items: center; cursor: pointer; touch-action: none; }
#fullMic:hover { background: var(--line2); } #fullMic.live { background: var(--acc); color: var(--acc-ink); box-shadow: 0 0 0 calc(2px + var(--lvl, 0) * 12px) rgba(70, 216, 196, .25); }
#fullSend { flex: none; padding: 9px 16px; border-radius: 999px; border: 0; background: var(--acc); color: var(--acc-ink); font: inherit; font-weight: 600; cursor: pointer; }
#fullLinks { display: flex; gap: 18px; font-size: 12.5px; } #fullLinks a, #fullLinks button { color: var(--faint); text-decoration: none; background: none; border: 0; padding: 0; font: inherit; cursor: pointer; }
#fullLinks a:hover, #fullLinks button:hover { color: var(--ink); }
html.full.idle #fullDock { opacity: .28; } html.full.idle #fullInfo { opacity: .55; }
html.full.gaming #fullInfo { display: none; }
html.full #faceHost { cursor: pointer; flex: none; }
@media (max-width: 600px) { #fullPip { font-size: 15.5px; } #fullLinks { display: none; } }
html.full #fullSign:not([hidden]) { display: flex; flex-direction: column; gap: 10px; align-items: center; text-align: center; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 21;
  width: min(340px, calc(100% - 32px)); padding: 22px; border-radius: 14px; background: rgba(21, 23, 27, .96); border: 1px solid var(--line); color: var(--mute); font-size: 13.5px; }
#fullSign b { color: var(--ink); font-size: 15.5px; font-weight: 600; }
#fullSign .go { display: block; width: 100%; padding: 10px; border-radius: 9px; background: var(--acc); color: var(--acc-ink); font-weight: 600; text-decoration: none; }
#fullSign div { display: flex; gap: 8px; width: 100%; }
#fullSign input { flex: 1; min-width: 0; padding: 9px 10px; border-radius: 9px; border: 1px solid var(--line2); background: var(--raise); color: var(--ink); font: inherit; }
#fullSign button { padding: 9px 12px; border-radius: 9px; border: 1px solid var(--line2); background: var(--raise); color: var(--ink); font: inherit; cursor: pointer; }
html.full main { grid-template-columns: 1fr; }
html.full body, html.full #stage { background: var(--pipbg, #050505); }      /* the room around the face is the face's own background: no letterbox */
html.full, html.full body { overflow: hidden; overscroll-behavior: none; }
html.full #direct { padding: 0; }
html.full .screenframe { border: 0; border-radius: 0; box-shadow: none; }

/* ---- which body the simulator imitates ---- */
#bodySel { flex: none; width: auto; background: var(--raise); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; font: inherit; font-size: 13px; }
.small { font-size: 12.5px; margin: 0; line-height: 1.5; }
#app:not([data-body="phone"]) .phone-only, #app:not([data-body="cube"]) .smallspk-only, [data-body="computer"] .battery-only { display: none !important; }
#app:not([data-body="cube"]) #viewSeg { display: none; }
[data-body="phone"] .screenframe { box-sizing: content-box; border: 9px solid #1d2026; border-radius: 34px; background: var(--pipbg, #050505); overflow: hidden; }
[data-body="phone"] #gameHost { border-radius: 24px; }
[data-body="computer"] .screenframe { border: 10px solid #1d2026; border-bottom-width: 22px; border-radius: 10px; box-sizing: content-box; background: var(--pipbg, #050505); }
html.full .screenframe { border: 0 !important; border-radius: 0 !important; }
html.full #stage { grid-row: 1 / -1; } html.full main { grid-template-rows: 1fr !important; }

/* ---- Pip on a desk-sized screen: a conversation, with Pip beside it ---- */
#fullMic .slash { display: none; } #fullMic.muted { color: var(--faint); } #fullMic.muted .slash { display: inline; stroke: var(--bad); }
html.full.desk:not(.gaming) #fullChat { display: block; position: absolute; z-index: 6; }
html.full.desk #fullYou, html.full.desk #fullPip { display: none; }
html.full.desk.idle #fullDock { opacity: 1; } html.full.desk.idle #fullInfo { opacity: 1; }
html.full.desk:not(.gaming) #faceHost { transition: width .45s ease, height .45s ease, margin-top .45s ease; }
html.full.desk #fullInfo { transition: top .45s ease; } html.full.desk #fullDock { transition: bottom .45s ease; }
html.full.desk:not(.talked) #fullChat { display: none; }
html.full.desk #fullNote { display: none; }
#fullChat { -webkit-mask-image: linear-gradient(transparent, #000 26px); mask-image: linear-gradient(transparent, #000 26px); }
#fullChat .convo { max-height: none; height: 100%; margin: 0; gap: 14px; padding: 26px 4px 8px; justify-content: flex-start; scrollbar-width: none; }
#fullChat .convo p { display: block; font-size: 15.5px; line-height: 1.5; max-width: 88%; }
#fullChat .convo p b { display: none; }
#fullChat .convo p.you { align-self: flex-end; background: var(--raise); border: 1px solid var(--line); padding: 8px 14px; border-radius: 16px 16px 4px 16px; } #fullChat .convo p.you span { color: var(--ink); }
#fullChat .convo p.pip { align-self: flex-start; color: var(--ink); padding-left: 14px; border-left: 2px solid var(--acc); }
#fullChat .convo p.note { align-self: center; font-size: 12.5px; color: var(--faint); text-align: center; }
#fullChat .convo p.empty { margin: auto; font-size: 15px; color: var(--faint); text-align: center; max-width: 320px; }
#fullChat .convo p:first-child { margin-top: auto; }

@media (pointer: coarse) { #gameHost button { width: 44px; height: 44px; font-size: 24px; } }

/* ---- Pip on wheels, in its own little world (desk-sized screens) ---- */
#world { display: none; }
html.full.rover.desk:not(.gaming) #world { display: block; position: absolute; inset: 0; z-index: 0; cursor: pointer; }
html.full.rover.desk:not(.gaming) #direct { visibility: hidden; pointer-events: none; }
html.full.rover.desk body, html.full.rover.desk #stage { background: #0d0e10; }
html.full.rover.desk.talked:not(.gaming) #world::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 56%; pointer-events: none;
  background: linear-gradient(rgba(13, 14, 16, 0), rgba(13, 14, 16, .93) 22%, #0d0e10 40%); }
html.full.rover.desk #fullState { background: rgba(21, 23, 27, .88); }
#fullLinks [hidden] { display: none; }
