:root {
  --bg: #0a0503; --panel: #140a05; --ink: #f0d9bd; --muted: #a58b6b; --amber: #c98a4b; --amber-hi: #f0a85a;
  --danger: #d9534f; --ok: #6bbf7a; --warn: #e0a030; --line: rgba(201,138,75,.28);
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--ink); font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
body { overflow: hidden; overscroll-behavior: none; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
h1, h2, h3 { font-weight: 500; letter-spacing: .06em; margin: .2em 0; }
button, input, textarea, select { font: inherit; color: inherit; }
button { min-height: 48px; min-width: 48px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--amber); background: #22110a; touch-action: manipulation; cursor: pointer; }
button:active { background: #3a1d10; }
button:disabled { opacity: .45; cursor: not-allowed; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid var(--amber-hi); outline-offset: 2px; }
button.ghost { background: transparent; border-color: var(--line); }
button.big { min-height: 56px; font-size: 1.05em; width: 100%; max-width: 420px; }
input, textarea, select { background: #1b0e08; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; min-height: 48px; width: 100%; }

/* Full-page screens (wake, gate, off) */
.screen { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: calc(24px + var(--safe-t)) calc(24px + var(--safe-r)) calc(24px + var(--safe-b)) calc(24px + var(--safe-l)); text-align: center; background: var(--bg); z-index: 5; }
.screen form { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 420px; text-align: left; }
#signinBox { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 420px; align-items: center; }

/* App shell */
#app { position: fixed; inset: 0; display: flex; flex-direction: column; padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l); }
#topbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
#who { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#stopBtn, #faceStop { background: var(--danger); border-color: #ff8a85; color: #fff; font-weight: 700; letter-spacing: .08em; min-width: 72px; }
.pill { padding: 2px 10px; border-radius: 999px; border: 1px solid var(--warn); color: var(--warn); font-size: .8em; }
.banner { padding: 10px 14px; background: #2b1a05; border-bottom: 1px solid var(--warn); color: #ffd48a; }
.banner.error { background: #2c0e0d; border-color: var(--danger); color: #ffb3af; }

/* Phone portrait: face 38vh, transcript, bottom bar */
#layout { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#face { flex: 0 0 38vh; min-height: 200px; display: flex; flex-direction: column; border-bottom: 1px solid var(--line); }
#facehost { position: relative; flex: 1 1 auto; min-height: 0; overflow: hidden; background: #0a0503; }
#facehost canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#facehost .panel, #facehost #badge, #facehost #live { display: none; }
#faceState { margin: 0; padding: 2px 12px; font-size: .85em; }
#facebtns { display: flex; gap: 8px; padding: 4px 12px 8px; }
#chat { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#transcript { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; -webkit-overflow-scrolling: touch; }
.msg { max-width: 92%; padding: 10px 14px; border-radius: 16px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: #3a1d10; border: 1px solid var(--amber); }
.msg.bot { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); }
.msg.note { align-self: center; color: var(--muted); font-size: .85em; background: none; border: none; padding: 2px; text-align: center; }
.msg.note.untrusted { color: #ffd48a; border: 1px solid var(--warn); border-radius: 10px; padding: 6px 10px; }
.msg .retry { margin-left: 8px; min-height: 40px; }
#composer { display: flex; gap: 8px; align-items: flex-end; padding: 8px 12px calc(8px) 12px; border-top: 1px solid var(--line); background: var(--bg); }
#say { flex: 1; resize: none; max-height: 30vh; min-height: 52px; }
.mic { width: 64px; height: 64px; border-radius: 32px; }
.send { min-height: 64px; min-width: 76px; background: var(--amber); color: #1b0e08; font-weight: 700; border-color: var(--amber-hi); }

/* Tablet landscape: face left half, chat right */
@media (min-width: 768px) and (orientation: landscape) {
  #layout { flex-direction: row; }
  #face { flex: 0 0 50%; border-bottom: none; border-right: 1px solid var(--line); }
  #chat { flex: 1; }
}
/* Full-screen face */
#face.full { position: fixed; inset: 0; z-index: 4; background: var(--bg); border: none; padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l); }
#face.full #facebtns { justify-content: space-between; }
#faceStop { min-height: 56px; }
body.household { font-size: 20px; }
body.household #settingsBtn, body.household #who { display: none; }

/* Settings drawer: a bottom sheet on phones, a right drawer on tablets */
#drawer { position: fixed; z-index: 8; left: 0; right: 0; bottom: 0; max-height: 82vh; overflow: auto; background: #170b06; border-top: 2px solid var(--amber); border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + var(--safe-b)); display: flex; flex-direction: column; gap: 12px; }
@media (min-width: 768px) { #drawer { left: auto; top: 0; width: 380px; max-height: none; border-radius: 0; border-top: none; border-left: 2px solid var(--amber); } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; }
.drawer-actions { display: flex; flex-direction: column; gap: 10px; }
#info { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: .9em; }
#info dt { color: var(--muted); } #info dd { margin: 0; overflow-wrap: anywhere; }
#deviceList { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
#deviceList li { display: flex; align-items: center; gap: 8px; justify-content: space-between; padding: 8px 10px; border: 1px solid var(--line); border-radius: 12px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
.row { display: flex; align-items: center; gap: 10px; min-height: 48px; }
.row input { width: 24px; min-height: 24px; height: 24px; flex: none; }
#pasteBtn { min-width: 56px; }
.msg .copy { margin-left: 8px; min-height: 40px; }

/* Voice (stage 3a): a big thumb-reach mic, an always-visible mic state, a hard mute */
#voiceBar { display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.micstate { display: inline-flex; align-items: center; gap: 8px; padding: 4px 12px; border: 1px solid var(--line); border-radius: 999px; font-size: .9em; }
.micstate .dot { width: 12px; height: 12px; border-radius: 50%; background: #6a5a48; display: inline-block; }
.micstate[data-state="listening"] { border-color: var(--danger); color: #ffb3af; }
.micstate[data-state="listening"] .dot { background: var(--danger); box-shadow: 0 0 0 4px rgba(217,83,79,.3); }
.micstate[data-state="muted"] { border-color: var(--warn); color: var(--warn); }
.micstate[data-state="muted"] .dot { background: var(--warn); }
.micstate[data-state="denied"], .micstate[data-state="error"] { border-color: var(--danger); color: #ffb3af; }
#muteBtn[aria-pressed="true"] { background: #3a2a05; border-color: var(--warn); color: var(--warn); }
button.mic { width: 88px; height: 88px; border-radius: 44px; font-size: .8em; line-height: 1.1; padding: 0 6px; touch-action: none; user-select: none; -webkit-user-select: none; }
button.mic.listening { background: var(--danger); border-color: #ff8a85; color: #fff; }
button.mic:disabled { opacity: .45; }
@media (prefers-reduced-motion: no-preference) { button.mic.listening { animation: micpulse 1.4s ease-in-out infinite; } }
@keyframes micpulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(217,83,79,.55); } 50% { box-shadow: 0 0 0 14px rgba(217,83,79,0); } }
@media (min-width: 768px) and (orientation: landscape) { button.mic { width: 96px; height: 96px; } }
#composer { align-items: center; }

/* Cost panel and headline */
#costBody { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; font-size: .9em; }
#costBody .k { color: var(--muted); } #costBody .v { text-align: right; } #costBody .h { grid-column: 1 / -1; margin-top: 8px; color: var(--amber-hi); letter-spacing: .05em; }
#costBody .warn { grid-column: 1 / -1; padding: 8px 10px; border: 1px solid var(--danger); border-radius: 10px; color: #ffb3af; }
#costHeadline { border-color: var(--amber); color: var(--amber-hi); }
#costHeadline.over { border-color: var(--danger); color: #ffb3af; }

/* Models page */
#modelSlots { display: flex; flex-direction: column; gap: 10px; }
.slotrow { border: 1px solid var(--line); border-radius: 12px; padding: 10px; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; }
.slotrow h4 { grid-column: 1 / -1; margin: 0; font-weight: 500; letter-spacing: .05em; }
.slotrow label { font-size: .8em; color: var(--muted); display: block; }
.slotrow .full { grid-column: 1 / -1; }
.slotrow .cost { grid-column: 1 / -1; font-size: .8em; color: var(--muted); }
#slotChip { cursor: pointer; min-height: 32px; }
