:root {
  --fg: rgba(255, 255, 255, 0.92);
  --dim: rgba(255, 255, 255, 0.5);
  --bg: rgba(8, 10, 16, 0.45);
  --accent: #ffcf6e;
  --font: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}
* { box-sizing: border-box; }
/* --app-h is set by main.js only in an iOS home-screen app spanning the whole screen: there WebKit's percentage/inset viewport
   under a translucent status bar is unreliable, so the page is sized to the screen itself. Everywhere else 100dvh tracks the
   visible viewport on rotate (100% is the fallback where dvh is unknown). */
html, body { margin: 0; height: 100%; height: var(--app-h, 100dvh); background: #000; overflow: hidden; }
/* Nothing on the page is meant to be selected or long-pressed (fingers catch text while dragging to look); the typed field opts back in. */
body { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
#typed-input { user-select: text; -webkit-user-select: text; }
/* JS also sets #view's width/height in px so the drawing buffer cannot drift from the CSS box on rotate. */
#view { position: fixed; top: 0; left: 0; width: 100%; height: 100%; height: var(--app-h, 100dvh); display: block; }

#hud { position: fixed; top: 0; left: 0; right: 0; height: 100%; height: var(--app-h, 100dvh); pointer-events: none; color: var(--fg); font-family: var(--font); }
#hud > * { pointer-events: none; }

#topbar { position: absolute; top: calc(18px + env(safe-area-inset-top, 0px)); left: 22px; right: 22px; display: flex; justify-content: space-between; align-items: center; font-family: var(--mono); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--dim); }
#topbar, #topbar #brand > span:first-of-type, #topbar #status-text, #topbar #people, #topbar #room, #topbar #count { transition: color .2s; }
#brand { display: flex; align-items: center; gap: 10px; }
#brand > span:first-of-type { color: var(--fg); letter-spacing: 0.28em; font-weight: 600; }
#brand > img { border-radius: 5px; box-shadow: 0 2px 8px rgba(0,0,0,.4); }
#avatar-btn { pointer-events: auto; width: 34px; height: 34px; flex: none; padding: 0; border-radius: 50%; border: 1px solid currentColor; background: transparent; overflow: hidden; cursor: pointer; position: relative; }
#avatar-face { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; }
#avatar-face img { width: 100%; height: 100%; object-fit: cover; display: block; }
#avatar-btn.generating::after { content: ''; position: absolute; inset: 0; border-radius: 50%; border: 2px solid transparent; border-top-color: var(--accent); animation: avatar-spin .8s linear infinite; }
@keyframes avatar-spin { to { transform: rotate(360deg); } }
#avatar-pane[hidden] { display: none; }
#avatar-pane { position: absolute; inset: 0; z-index: 6; display: flex; align-items: center; justify-content: center; background: rgba(6, 8, 14, 0.62); pointer-events: auto; padding: max(12px, env(safe-area-inset-top, 0px)) 12px max(12px, env(safe-area-inset-bottom, 0px)); }
#avatar-pane .card { width: min(420px, calc(100vw - 24px)); background: rgba(14, 17, 26, 0.96); border: 1px solid rgba(255,255,255,.12); border-radius: 16px; padding: 14px; box-shadow: 0 30px 80px rgba(0,0,0,.6); }
#avatar-stage { width: 100%; height: min(52vh, 440px); display: block; border-radius: 12px; background: radial-gradient(circle at 50% 38%, #323a4c, #12151c 72%); touch-action: none; cursor: grab; }
#avatar-stage:active { cursor: grabbing; }
#avatar-rec { margin-top: 12px; width: 100%; font: 15px var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: #1a1a1a; background: var(--accent); border: 0; border-radius: 8px; padding: 12px 16px; cursor: pointer; }
#avatar-rec:disabled { opacity: 0.55; cursor: default; }
#avatar-rec.active { background: #7fb2ff; }
@media (max-height: 520px) { #avatar-stage { height: 42vh; } #avatar-rec { padding: 8px 12px; } }
#status { display: flex; align-items: center; gap: 8px; margin-left: 14px; padding-left: 14px; border-left: 1px solid rgba(255,255,255,.18); }
/* main.js adds .light when the picture behind this bar is bright — white type vanishes on a noon sky. */
#topbar.light,
#topbar.light #status-text,
#topbar.light #people,
#topbar.light #count,
#topbar.light #room { color: rgba(0, 0, 0, 0.72); }
#topbar.light #brand > span:first-of-type { color: rgba(0, 0, 0, 0.92); }
#topbar.light #room:hover { color: rgba(0, 0, 0, 0.92); }
#topbar.light #status { border-left-color: rgba(0, 0, 0, 0.28); }
#status-dot { width: 9px; height: 9px; border-radius: 50%; background: #666; box-shadow: 0 0 0 0 rgba(255,255,255,0); transition: background .25s; }
#status-dot.idle { background: #7dd87d; }
#status-dot.listening { background: var(--accent); animation: pulse 1s infinite; }
#status-dot.thinking { background: #7fb2ff; animation: pulse .8s infinite; }
#status-dot.queued { background: #7fb2ff; animation: pulse .8s infinite; }
#status-dot.voice { background: #7fb2ff; animation: pulse 1s infinite; }
#status-dot.applying { background: #c58bff; animation: pulse .5s infinite; }
#status-dot.error { background: #ff6b6b; }
#status-dot.offline { background: #555; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(255,255,255,.45); } 100% { box-shadow: 0 0 0 10px rgba(255,255,255,0); } }
#badges { display: flex; gap: 14px; align-items: center; }
#mock-badge { color: #ffb347; border: 1px solid #ffb347; padding: 2px 6px; border-radius: 3px; }
#room { pointer-events: auto; cursor: pointer; color: var(--dim); }
#room:hover { color: var(--fg); }

#bottom { position: absolute; left: 0; right: 0; bottom: 26px; display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 0 24px; }
.line { max-width: 900px; text-align: center; text-shadow: 0 2px 12px rgba(0,0,0,.7); }   /* fades are eased per frame in hud.tick(): a CSS transition here stalls over the canvas on iOS */
#transcript { font-size: 22px; font-style: italic; color: var(--fg); min-height: 1.2em; }
#transcript.interim { color: var(--dim); }
#reply { font-size: 30px; color: var(--accent); min-height: 1.2em; }
#hint { font-family: var(--mono); font-size: 11px; letter-spacing: 0.06em; color: var(--dim); margin-top: 6px; }
#hint kbd { border: 1px solid rgba(255,255,255,.3); border-radius: 3px; padding: 0 5px; font-family: inherit; }

#typed { pointer-events: auto; width: min(720px, 90vw); }
#typed-input { width: 100%; padding: 12px 16px; font: 18px var(--font); color: var(--fg); background: var(--bg); border: 1px solid rgba(255,255,255,.25); border-radius: 8px; outline: none; backdrop-filter: blur(8px); }
#typed-input:focus { border-color: var(--accent); }

#listen-ring { position: absolute; left: 50%; top: 50%; width: 140px; height: 140px; margin: -70px 0 0 -70px; border-radius: 50%; border: 2px solid var(--accent); opacity: .9; animation: ring 1.2s ease-out infinite; }
#listen-ring.room { border-color: #7fb2ff; }
#listen-ring.room div { background: radial-gradient(circle, rgba(127,178,255,.5), transparent 70%); }
#stick { position: absolute; width: 92px; height: 92px; margin: -46px 0 0 -46px; border-radius: 50%; border: 1px solid rgba(255,255,255,.35); background: rgba(14, 17, 26, 0.35); pointer-events: none; }
#stick[hidden] { display: none; }
/* Portrait phones: a faint copy of the stick ring marks where the walk pad lives (placed by main.js just above the mic bar). */
#stickpad { position: absolute; width: 92px; height: 92px; border-radius: 50%; border: 1px solid rgba(255,255,255,.16); background: rgba(14, 17, 26, 0.16); pointer-events: none; }   /* opacity eased per frame by main.js while text is on screen; the walk zone stays live */
#stickpad[hidden] { display: none; }
#stick div { position: absolute; left: 26px; top: 26px; width: 40px; height: 40px; border-radius: 50%; background: rgba(255,255,255,.75); box-shadow: 0 2px 10px rgba(0,0,0,.4); }
#listen-ring div { position: absolute; inset: 30px; border-radius: 50%; background: radial-gradient(circle, rgba(255,207,110,.5), transparent 70%); }
@keyframes ring { 0% { transform: scale(.8); opacity: .9; } 100% { transform: scale(1.25); opacity: 0; } }

.fade { opacity: 0; }

/* first-visit welcome */
#welcome[hidden] { display: none; }
#welcome { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(6, 8, 14, 0.55); backdrop-filter: blur(6px); pointer-events: auto; overflow-y: auto; padding: max(12px, env(safe-area-inset-top, 0px)) 12px max(12px, env(safe-area-inset-bottom, 0px)); }
#welcome .card { width: min(560px, calc(100vw - 24px)); max-width: 100%; min-width: 0; max-height: 100%; overflow: auto; background: rgba(14, 17, 26, 0.92); border: 1px solid rgba(255,255,255,.12); border-radius: 16px; padding: 32px 34px 28px; text-align: center; box-shadow: 0 30px 80px rgba(0,0,0,.6); }
#welcome img { border-radius: 10px; margin-bottom: 10px; }
#welcome h1 { font-family: var(--font); font-weight: 400; font-size: 30px; line-height: 1.15; margin: 6px 0 14px; color: var(--fg); overflow-wrap: break-word; }
#welcome p { font-size: 17px; line-height: 1.5; color: rgba(255,255,255,.82); margin: 0 0 12px; overflow-wrap: break-word; }
#welcome .card > * { max-width: 100%; }
#welcome p.small { font-family: var(--mono); font-size: 12px; color: var(--dim); }
#welcome kbd { border: 1px solid rgba(255,255,255,.35); border-radius: 4px; padding: 1px 7px; font-family: var(--mono); font-size: 0.85em; }
#welcome .choices { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
#welcome button { font: 16px var(--mono); letter-spacing: 0.12em; text-transform: uppercase; color: #1a1a1a; background: var(--accent); border: 0; border-radius: 8px; padding: 12px 28px; cursor: pointer; width: 100%; }
#welcome button:hover { filter: brightness(1.08); }
#welcome button.secondary { background: transparent; color: var(--fg); border: 1px solid rgba(255,255,255,.28); }
#welcome button.secondary:hover { background: rgba(255,255,255,.08); filter: none; }

/* touch controls: shown on coarse-pointer devices (body.touch is set by main.js) */
body .touch { display: none; }   /* touch-only elements (descendants only — body itself carries the .touch class) */
body.touch .touch { display: block; }
body.touch .keys { display: none; }
#touchbar { position: absolute; left: 0; right: 0; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); justify-content: center; align-items: center; gap: 18px; pointer-events: none; }
body.touch #touchbar { display: flex; }
#touchbar button { pointer-events: auto; display: flex; align-items: center; justify-content: center; width: 56px; height: 56px; border-radius: 50%; border: 1px solid rgba(255,255,255,.22); background: rgba(14, 17, 26, 0.72); color: var(--fg); backdrop-filter: blur(8px); touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; box-shadow: 0 6px 20px rgba(0,0,0,.45); }
#touchbar button:active { background: rgba(255,255,255,.18); }
#touchbar button:disabled { opacity: .35; }
#touchbar #tb-mic { width: 84px; height: 84px; background: var(--accent); color: #1a1a1a; border-color: transparent; }
#touchbar #tb-mic.active { background: #ffe1a3; box-shadow: 0 0 0 10px rgba(255,207,110,.35), 0 6px 20px rgba(0,0,0,.5); transform: scale(1.06); }
#touchbar #tb-mic:disabled { background: rgba(14, 17, 26, 0.72); color: var(--dim); }
#touchbar #tb-voice { flex-direction: column; gap: 0; line-height: 1; }
#touchbar #tb-voice span { font-family: var(--mono); font-size: 9px; font-weight: 600; letter-spacing: 0.01em; }
#touchbar #tb-voice.active { background: #7fb2ff; color: #1a1a1a; border-color: transparent; box-shadow: 0 0 0 8px rgba(127,178,255,.35), 0 6px 20px rgba(0,0,0,.5); }
body.touch #bottom { bottom: calc(120px + env(safe-area-inset-bottom, 0px)); }   /* 18px above the tallest button: the 84px mic, in a row that sits 18px + inset up. The old 92px measured the 56px buttons and left the text under the mic. */
body.touch #typed { display: none; }   /* phones are voice-only; typed fallback is desktop */
body.touch #hint { display: none; }
/* Landscape phones: not enough height for a button row above the transcript — split the buttons to the
   corners (undo + mic left, sound right) and let the transcript sit between them. */
@media (orientation: landscape) and (max-height: 520px) {
  body.touch #touchbar { justify-content: flex-start; padding: 0 14px; gap: 12px; bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
  body.touch #tb-voice { margin-left: auto; }
  body.touch #touchbar button { width: 46px; height: 46px; }
  body.touch #touchbar #tb-mic { width: 62px; height: 62px; }
  body.touch #touchbar #tb-voice svg { width: 16px; height: 16px; }
  body.touch #touchbar #tb-voice span { font-size: 8px; }
  body.touch #bottom { bottom: calc(16px + env(safe-area-inset-bottom, 0px)); padding: 0 168px; gap: 6px; }
  body.touch #transcript { font-size: 15px; } body.touch #reply { font-size: 19px; }
  body.touch #welcome .card { padding: 14px 18px 12px; } body.touch #welcome img { display: none; } body.touch #welcome h1 { font-size: 20px; margin: 2px 0 6px; } body.touch #welcome p { font-size: 13px; margin-bottom: 6px; } body.touch #welcome button { padding: 8px 20px; margin-top: 2px; }
}
@media (max-width: 640px) {
  #topbar { top: calc(12px + env(safe-area-inset-top, 0px)); left: 14px; right: 14px; font-size: 10px; }
  #brand > span:first-of-type { display: none; }
  #count { display: none; }
  #transcript { font-size: 17px; } #reply { font-size: 22px; }
  #welcome img { display: none; }
  #welcome p.touch, #welcome p.keys { display: none; }
  #welcome .card { padding: 16px 14px 14px; overflow-x: hidden; }
  #welcome h1 { font-size: 20px; margin: 0 0 8px; }
  #welcome p { font-size: 14px; margin-bottom: 8px; }
  #welcome .choices { margin-top: 12px; gap: 8px; } #welcome button { padding: 11px 16px; }
}
