:root {
  color-scheme: dark;
  --background: #000;
  --text: #39ff14;
  --secondary: rgba(57, 255, 20, 0.72);
  --muted: rgba(57, 255, 20, 0.58);
  --font-scale: 1;
  --camera-opacity: .35;
  --chrome-font: clamp(15px, 1.25vw, 21px);
  --footer-height: calc(3.4rem + env(safe-area-inset-bottom));
  --camera-bar-height: 0px;
  --current-space: 0px;
  font-family: "IBM Plex Mono", "JetBrains Mono", ui-monospace, monospace;
  background: var(--background);
  color: var(--text);
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--background);
}

body {
  --bottom-stack-height: calc(var(--footer-height) + var(--camera-bar-height) + var(--current-space));
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  padding: max(18px, env(safe-area-inset-top)) max(22px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(22px, env(safe-area-inset-left));
  font-size: clamp(28px, 2.8vw, 42px);
  line-height: 1.45;
}

body.camera-active { --camera-bar-height: 6.5rem; }
body:has(#current:not(.hidden)) { --current-space: 3.25rem; }

#camera-layer {
  position: fixed;
  z-index: 0;
  inset: 0;
  overflow: hidden;
  visibility: hidden;
  opacity: 0;
  background: #000;
  pointer-events: none;
}

body.camera-active #camera-layer { visibility: visible; }
body.camera-preview #camera-layer { opacity: 1; }

#camera-feed {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  opacity: var(--camera-opacity);
}

button, input, select { font: inherit; }

button, input, select, dialog {
  color: var(--text);
  background: #000;
  border: 1px solid var(--muted);
}

button { cursor: pointer; padding: .22em .42em; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--text); outline-offset: 3px; }
button:active { color: var(--text); }
button:disabled, button[aria-disabled="true"] { color: var(--muted); cursor: wait; }

@media (hover: hover) and (pointer: fine) {
  button:hover { outline: 2px solid var(--text); outline-offset: 3px; }
}

header {
  grid-row: 1;
  z-index: 2;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 1.5rem;
  align-items: center;
  padding-bottom: .8rem;
  font-size: var(--chrome-font);
  color: var(--secondary);
  background: #000;
  white-space: nowrap;
}

#clock { text-align: center; }
#status { text-align: right; }
#date, #header-actions { min-width: 0; }
#header-actions { display: flex; justify-content: flex-end; align-items: center; gap: .55rem; }
#inbox-button { position: relative; min-width: 44px; min-height: 44px; padding: 0 .2rem; font-size: var(--chrome-font); }
#inbox-dot {
  position: absolute;
  top: 4px;
  right: 3px;
  width: 9px;
  height: 9px;
  border: 1px solid #000;
  border-radius: 50%;
  background: #ff9f0a;
  box-shadow: 0 0 .45rem #ff9f0a;
}

#transcript {
  grid-row: 3;
  position: relative;
  z-index: 1;
  min-height: 0;
  overflow: auto;
  padding: .4rem 0 calc(var(--bottom-stack-height) + 1rem);
  font-size: calc(clamp(20px, 2.1vw, 30px) * var(--font-scale));
  line-height: 1.5;
  scroll-padding-block: .4rem calc(var(--bottom-stack-height) + 1rem);
  scrollbar-color: var(--muted) transparent;
  overscroll-behavior: contain;
}

body.camera-preview :is(header, #notice, #transcript, .bottom, #camera-controls, .bottom #current) {
  background: transparent;
  text-shadow: 0 1px 2px #000, 0 0 2px #000;
}
body.camera-preview :is(header, #transcript, .bottom, #camera-controls) button { background: transparent; }
body.camera-preview .bottom { box-shadow: none; }

#older-transcript {
  min-width: 44px;
  min-height: 44px;
  margin: 0 auto 1rem;
  font-size: var(--chrome-font);
}

.message { max-inline-size: 58ch; margin: 0 0 clamp(1.35rem, 3vh, 2rem); }
.message.user { margin-inline-start: auto; padding-inline-start: clamp(.5rem, 2vw, 1rem); text-align: right; }
.speaker {
  display: block;
  margin-bottom: .3rem;
  color: var(--secondary);
  font-size: clamp(12px, .62em, 15px);
  letter-spacing: .06em;
}
.message p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.message.in_progress p::after { content: "_"; color: var(--secondary); }
.word-reveal { animation: matrix-in 840ms steps(8, end) both; animation-delay: calc(var(--reveal-index) * 180ms); }
.message-fade { animation: message-fade 500ms ease-out both; }

.photo-message {
  display: grid;
  gap: .45rem;
  width: min(94%, 42rem);
  margin: .35rem 0 1.15em auto;
  padding: .5rem;
  background: #000;
  border: 1px solid var(--secondary);
  text-align: right;
}
.photo-message > .speaker { justify-self: end; }
.photo-message img { display: block; width: 100%; height: auto; max-height: min(62dvh, 42rem); object-fit: contain; background: #000; }
.photo-message figcaption { display: grid; gap: .35rem; justify-items: end; color: var(--secondary); font-size: .55em; overflow-wrap: anywhere; }
.photo-message .photo-actions { width: 100%; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .4rem; }
.photo-message .photo-actions > * {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  padding: .35em .55em;
  color: var(--text);
  background: #000;
  border: 1px solid var(--muted);
  font-size: var(--chrome-font);
  text-decoration: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.photo-message .photo-send { border-color: var(--text); }
.photo-message .photo-send[aria-disabled="true"]:not([aria-busy="true"]) { cursor: default; }
.photo-message .photo-actions > :active { background: rgba(57, 255, 20, .12); }
.photo-message .photo-actions > :focus-visible { outline: 2px solid var(--text); outline-offset: 3px; }

#notice {
  grid-row: 2;
  position: relative;
  z-index: 12;
  margin: 0;
  padding: .3rem 0 .65rem;
  max-inline-size: 52ch;
  justify-self: center;
  color: var(--secondary);
  background: #000;
  font-size: .55em;
  line-height: 1.4;
  text-align: center;
  pointer-events: none;
}
#notice:empty { display: none; }
body:is([data-status="LISTENING"], [data-status="THINKING"], [data-status="SPEAKING"]) #status { color: var(--text); }
#notice[role="alert"], body:is([data-status="ERROR"], [data-status="OFFLINE"]) #status { color: #ff9f0a; }
#settings-error { min-height: 1.5em; max-width: 58rem; margin: 0; color: var(--secondary); font-size: .55em; text-align: center; }

.bottom {
  position: fixed;
  z-index: 11;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  align-items: center;
  min-height: var(--footer-height);
  padding: .65rem max(22px, env(safe-area-inset-right)) max(.65rem, env(safe-area-inset-bottom)) max(22px, env(safe-area-inset-left));
  background: #000;
  border-top: 1px solid rgba(57, 255, 20, .34);
  box-shadow: 0 -1rem 2rem #000;
  pointer-events: none;
}
.bottom button { line-height: 1; pointer-events: auto; }
.bottom > button:not(#current) { flex: 1 1 0; width: 100%; min-width: 0; padding-inline: .25rem; text-align: center; }
.bottom #current {
  position: absolute;
  left: 50%;
  bottom: calc(100% + var(--camera-bar-height) + .5rem);
  max-width: calc(100vw - 2rem);
  min-height: 44px;
  padding-inline: .65rem;
  overflow: hidden;
  color: var(--text);
  background: #000;
  border: 1px solid var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
  transform: translateX(-50%);
}
.bottom .quiet { font-size: var(--chrome-font); }
.quiet { border: 0; color: var(--muted); font-size: .48em; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

#camera-controls {
  position: fixed;
  z-index: 10;
  right: 0;
  bottom: var(--footer-height);
  left: 0;
  height: var(--camera-bar-height);
  display: grid;
  grid-template-rows: auto minmax(44px, 1fr);
  gap: .35rem;
  padding: .45rem max(22px, env(safe-area-inset-right)) .5rem max(22px, env(safe-area-inset-left));
  visibility: hidden;
  opacity: 0;
  color: var(--secondary);
  background: #000;
  border-top: 1px solid var(--muted);
  pointer-events: none;
}
body.camera-active #camera-controls { visibility: visible; opacity: 1; pointer-events: auto; }
.camera-control-head { min-width: 0; display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; font-size: var(--chrome-font); }
.camera-control-head small { min-width: 0; color: var(--muted); font-size: max(10px, .65em); line-height: 1.25; text-align: right; }
.camera-control-actions { min-width: 0; display: grid; grid-template-columns: auto auto minmax(8rem, 1fr); gap: .65rem; align-items: center; }
.camera-control-actions button { min-width: 44px; min-height: 44px; font-size: var(--chrome-font); }
.camera-opacity-control { min-width: 0; display: grid; grid-template-columns: auto minmax(5rem, 1fr); gap: .65rem; align-items: center; font-size: var(--chrome-font); white-space: nowrap; }
.camera-opacity-control input { width: 100%; min-width: 0; min-height: 44px; margin: 0; padding: 0; accent-color: var(--text); }

#sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  width: min(34rem, 88vw);
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 1rem;
  padding: max(20px, env(safe-area-inset-top)) 24px max(20px, env(safe-area-inset-bottom));
  overflow: hidden;
  background: #000;
  border-right: 1px solid var(--muted);
  transform: translateX(-102%);
  visibility: hidden;
}

#sidebar.open { transform: translateX(0); visibility: visible; }
.sidebar-head { display: flex; justify-content: space-between; align-items: baseline; }
h1 { margin: 0; font-size: .75em; letter-spacing: .08em; }
#new-chat { justify-self: start; font-size: .62em; }
#chat-list { margin: 0; padding: 0; overflow: auto; list-style: none; }
#chat-list li { display: grid; grid-template-columns: 1fr auto; gap: .4rem; padding: .45rem 0; border-bottom: 1px solid rgba(57, 255, 20, .18); }
.chat-select { border: 0; padding: 0; text-align: left; font-size: .58em; }
.chat-select[aria-current="true"] { color: #fff; }
.chat-meta { display: block; color: var(--muted); font-size: .68em; }
.delete-chat { border: 0; align-self: start; color: var(--muted); font-size: .44em; }
.sidebar-actions { display: flex; flex-wrap: wrap; gap: .5rem; }

dialog {
  width: min(58rem, calc(100vw - 2rem));
  max-height: calc(100dvh - 2rem);
  padding: clamp(20px, 4vw, 48px);
  overflow: auto;
  overscroll-behavior: contain;
}
dialog::backdrop { background: rgba(0, 0, 0, .92); }
dialog form { display: grid; gap: 1rem; }
dialog label { display: grid; gap: .35rem; color: var(--secondary); font-size: .55em; }
dialog input, dialog select { width: 100%; padding: .55em; font-size: 1.15em; }
.dialog-shell { display: grid; gap: 1rem; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.dialog-head .quiet { min-width: 44px; min-height: 44px; }
.check-label { grid-template-columns: auto 1fr; align-items: center; }
.check-label input { width: 1.1em; height: 1.1em; }
.warning { margin: 0; color: var(--secondary); font-size: .47em; line-height: 1.55; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.dialog-actions button { font-size: .58em; }
#agent-error { min-height: 1.5em; margin: 0; color: #ff9f0a; font-size: .5em; }
#agent-list, #inbox-list { display: grid; gap: .65rem; margin: 0; padding: 0; list-style: none; }
.agent-card, .inbox-card { display: grid; gap: .45rem; padding: .75rem; border: 1px solid rgba(57, 255, 20, .3); font-size: .52em; }
.agent-card[data-state="error"] { border-color: #ff9f0a; }
.agent-card-head, .inbox-card-head { display: flex; justify-content: space-between; gap: .75rem; }
.agent-card-head > *, .inbox-card-head > * { min-width: 0; overflow-wrap: anywhere; }
.agent-card-actions, .inbox-card-actions { display: flex; flex-wrap: wrap; gap: .35rem; }
.agent-card button, .inbox-card button { min-height: 44px; font-size: .85em; }
.inbox-pager button { min-height: 44px; font-size: .48em; }
.agent-meta { color: var(--muted); font-size: .82em; overflow-wrap: anywhere; }
.agent-output { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.unread { border-color: var(--text); box-shadow: inset 3px 0 var(--text); }

@media (prefers-reduced-motion: no-preference) {
  #sidebar { transition: transform 120ms linear, visibility 0s 120ms; }
  #sidebar.open { transition-delay: 0s; }
  #camera-layer, #camera-controls { transition: opacity 120ms linear, visibility 120ms linear; }
  @keyframes matrix-in {
    from { opacity: 0; color: #fff; }
    55% { opacity: 1; color: #fff; text-shadow: 0 0 .45em var(--text); }
    to { opacity: 1; color: inherit; text-shadow: none; }
  }
  @keyframes message-fade { from { opacity: 0; } to { opacity: 1; } }
}

@media (max-width: 680px) {
  :root { --chrome-font: clamp(12px, 3.1vw, 14px); }
  button { min-height: 44px; }
  .delete-chat { min-width: 44px; }
  body { padding-inline: max(16px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-right)); }
  #transcript { font-size: calc(clamp(18px, 4.8vw, 21px) * var(--font-scale)); line-height: 1.52; }
  header { grid-template-columns: minmax(0, 1fr) auto; gap: .4rem; }
  #header-actions { gap: .25rem; }
  #clock { display: none; }
  #date, #status { overflow: hidden; text-overflow: ellipsis; }
  .bottom { padding-inline: max(14px, env(safe-area-inset-left)) max(14px, env(safe-area-inset-right)); }
  .bottom button { min-width: 0; min-height: 44px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #fullscreen { font-size: 0; }
  #fullscreen::after { content: "[ FULL ]"; font-size: var(--chrome-font); }
  :fullscreen #fullscreen::after { content: "[ EXIT ]"; }
  #camera-controls { padding-inline: max(14px, env(safe-area-inset-left)) max(14px, env(safe-area-inset-right)); }
  .camera-control-head { gap: .5rem; }
  .camera-control-head small { max-width: 58%; }
  .camera-control-actions { gap: .45rem; }
  .camera-opacity-control { gap: .4rem; }
  .photo-message .photo-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .photo-message .photo-actions > * { min-width: 0; justify-content: center; }
  .photo-message .photo-send { grid-column: 1 / -1; }
  #sidebar { width: 100%; padding-inline: max(16px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-right)); border-right: 0; }
  dialog {
    inset: max(.5rem, env(safe-area-inset-top)) max(.5rem, env(safe-area-inset-right)) max(.5rem, env(safe-area-inset-bottom)) max(.5rem, env(safe-area-inset-left));
    width: auto;
    max-width: none;
    max-height: calc(100dvh - max(.5rem, env(safe-area-inset-top)) - max(.5rem, env(safe-area-inset-bottom)));
    margin: 0;
    padding: 16px;
  }
  dialog input, dialog select { min-height: 44px; font-size: max(16px, 1.15em); }
}

@media (max-width: 360px) {
  body.camera-active { --camera-bar-height: 11.5rem; }
  .bottom .quiet, #fullscreen::after { font-size: 11px; }
  .bottom > button:not(#current) { padding-inline: .125rem; }
  .camera-control-head { align-items: start; }
  .camera-control-head small { max-width: 62%; }
  .camera-control-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .camera-control-actions button { width: 100%; }
  .camera-opacity-control { grid-column: 1 / -1; grid-template-columns: auto minmax(0, 1fr); }
}

@media (max-height: 420px) and (orientation: landscape) {
  body.camera-active { --camera-bar-height: 5.75rem; }
  #transcript { font-size: calc(clamp(16px, 2.6vw, 19px) * var(--font-scale)); }
  .message { margin-bottom: 1rem; }
  .camera-control-head small { display: none; }
  .camera-control-actions { grid-template-columns: auto auto minmax(8rem, 1fr); }
  .camera-opacity-control { grid-column: auto; }
}

@media (pointer: coarse) {
  :root { --footer-height: calc(3.4rem + max(.65rem, env(safe-area-inset-bottom))); }
  button { min-height: 44px; }
  .delete-chat { min-width: 44px; }
}
