/* Jarvis PWA — dark, quiet, and readable on a phone at arm's length. */

:root {
  --bg: #07090c;
  --panel: #0d1117;
  --line: #1b232e;
  --text: #dfe6ee;
  --dim: #7d8b9c;
  --accent: #35d6c4;
  --accent-dim: #17605a;
  --user: #1a2836;
  --warn: #f0b849;
  --bad: #ef6b73;
  --radius: 14px;
  /* Real pixels the browser chrome is eating (iOS notch, home bar). */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 ui-sans-serif, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* Stop iOS rubber-banding the whole app while scrolling the log. */
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: grid;
  grid-template-rows: auto 1fr auto;
  /* dvh, not vh: iOS Safari's toolbar changes the viewport height. */
  height: 100dvh;
}

/* ------------------------------------------------------------------ header */

#bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(var(--safe-top) + 10px) 14px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

#bar h1 {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  letter-spacing: .02em;
}

#stateLabel {
  margin-left: auto;
  font-size: 12px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  text-transform: lowercase;
}

.dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--dim);
  flex: none;
  transition: background .2s, box-shadow .2s;
}
.dot[data-state="idle"]      { background: var(--accent-dim); }
.dot[data-state="listening"] { background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.dot[data-state="thinking"]  { background: var(--warn); animation: pulse 1.1s ease-in-out infinite; }
.dot[data-state="speaking"]  { background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.dot[data-state="offline"]   { background: var(--bad); }

@keyframes pulse { 50% { opacity: .3; } }

.icon {
  background: none;
  border: 1px solid var(--line);
  color: var(--dim);
  border-radius: 9px;
  width: 32px; height: 30px;
  font-size: 14px;
  cursor: pointer;
  flex: none;
}
.icon:hover { color: var(--text); border-color: var(--accent-dim); }
.icon[aria-pressed="true"] { color: var(--accent); border-color: var(--accent-dim); }

/* -------------------------------------------------------------------- main */

main {
  position: relative;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
}

#face {
  width: 100%;
  height: 132px;
  display: block;
  border-bottom: 1px solid var(--line);
  background: #05070a;
}

/* Full-screen face: the visualizer takes the whole app. */
body.faceOnly #face { height: auto; grid-row: 1 / -1; }
body.faceOnly #log,
body.faceOnly #composer form { display: none; }

#log {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 14px 14px 4px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  max-width: 78%;
  padding: 9px 13px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  animation: rise .18s ease-out;
}
@keyframes rise { from { opacity: 0; transform: translateY(4px); } }

.msg.user  { align-self: flex-end; background: var(--user); border-bottom-right-radius: 4px; }
.msg.agent { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.agent.live { border-color: var(--accent-dim); }

.msg.tool {
  align-self: flex-start;
  background: none;
  border: 1px dashed var(--line);
  color: var(--dim);
  font-size: 12.5px;
  padding: 4px 10px;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
}

.msg.err { align-self: center; background: #2a1416; border: 1px solid var(--bad); color: #ffc9cc; font-size: 13.5px; }

#banner {
  position: absolute;
  left: 12px; right: 12px; bottom: 10px;
  padding: 10px 13px;
  border-radius: 11px;
  background: #241c07;
  border: 1px solid var(--warn);
  color: #ffe2a6;
  font-size: 13px;
}
#banner[hidden] { display: none; }

/* ---------------------------------------------------------------- composer */

#composer {
  border-top: 1px solid var(--line);
  background: var(--panel);
  padding: 10px 12px calc(var(--safe-bottom) + 10px);
  display: grid;
  gap: 9px;
}

.talk {
  width: 100%;
  padding: 15px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  background: #10202a;
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  /* Holding the button must not select text or fire a context menu. */
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.talk:active,
.talk.hot { background: var(--accent); color: #04231f; border-color: var(--accent); }
.talk[disabled] { opacity: .45; cursor: not-allowed; }
.talkIcon { font-size: 18px; }

#form { display: flex; gap: 8px; }

#input {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  /* 16px minimum or iOS Safari zooms the page on focus. */
  font-size: 16px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
#input:focus { outline: none; border-color: var(--accent-dim); }

#send {
  flex: none;
  width: 46px;
  font-size: 18px;
  color: #04231f;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
}
#send:disabled { opacity: .4; cursor: not-allowed; }

.stop {
  padding: 11px;
  font-size: 14px;
  font-weight: 600;
  color: #ffd2d5;
  background: #2a1416;
  border: 1px solid var(--bad);
  border-radius: var(--radius);
  cursor: pointer;
}
.stop[hidden] { display: none; }

/* Desktop gets a centred column rather than a stretched phone layout. */
@media (min-width: 760px) {
  main, #composer { max-width: 860px; width: 100%; margin-inline: auto; }
  #bar { max-width: 860px; width: 100%; margin-inline: auto; }
  #face { height: 168px; }
  .msg { max-width: 68%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ------------------------------------------------------------ login gate */

#login {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}
#login[hidden] { display: none; }

#loginForm {
  width: 100%;
  max-width: 320px;
  display: grid;
  gap: 12px;
  text-align: center;
}
#loginForm h2 { margin: 0; font-size: 22px; letter-spacing: .04em; }
#loginMsg { margin: 0; font-size: 13.5px; color: var(--dim); min-height: 2.6em; }
#loginMsg.bad { color: #ffc9cc; }

#password {
  padding: 13px 14px;
  font-size: 16px;             /* 16px or iOS zooms on focus */
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  text-align: center;
}
#password:focus { outline: none; border-color: var(--accent-dim); }

#loginForm button {
  padding: 13px;
  font-size: 15px;
  font-weight: 600;
  color: #04231f;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
}
#loginForm button:disabled { opacity: .5; cursor: wait; }
