/* Web-client layout.
   face.css owns the character; this owns the chrome around it — sign-in,
   transcript and composer — and reshapes the stage for a phone in the hand
   rather than a 5-inch panel on a wall. */

body { overscroll-behavior: none; }

/* The Pi kiosk is face-only. Here the face shares the screen, so it shrinks
   and moves off centre to leave room for the conversation. */
.stage {
  justify-content: flex-start;
  padding: calc(env(safe-area-inset-top) + 46px) 0
           calc(env(safe-area-inset-bottom) + 8px);
  gap: 0;
}
.stage[hidden] { display: none; }

.head {
  width: min(58vw, 30vh * 1.55);
  flex: 0 0 auto;
  margin-top: clamp(4px, 2vh, 22px);
}

/* ── Sign in ─────────────────────────────────────────────────────────── */
.gate {
  position: fixed; inset: 0; z-index: 40;
  display: grid; place-items: center;
  padding: 24px;
  background: radial-gradient(120% 90% at 50% 38%, var(--bg-1) 0%, var(--bg-0) 62%);
}
body[data-view="in"] .gate { display: none; }
/* Until the session check returns, show neither the gate nor the app —
   flashing a login box at an already-signed-in user looks broken. */
body[data-view="checking"] .gate { visibility: hidden; }

.gate-card { width: min(340px, 100%); text-align: center; }

.gate-mark {
  margin: 0 0 6px;
  font-size: clamp(30px, 9vw, 42px);
  font-weight: 300;
  letter-spacing: .34em;
  text-indent: .34em;          /* letter-spacing pads the right; recentre it */
  color: var(--accent);
  text-shadow: 0 0 34px color-mix(in srgb, var(--accent) 45%, transparent);
}
.gate-sub { margin: 0 0 26px; color: var(--muted); font-size: 13px; }

.gate form { display: flex; flex-direction: column; gap: 10px; }

.gate input, .composer input {
  width: 100%;
  padding: 13px 16px;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  background: rgba(6, 12, 20, .78);
  color: var(--ink);
  font: inherit;
  font-size: 16px;             /* below 16px makes iOS Safari zoom on focus */
  outline: none;
  transition: border-color 200ms ease, box-shadow 200ms ease;
}
.gate input:focus, .composer input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}

.gate button {
  padding: 13px 16px;
  border: 0; border-radius: 12px;
  background: var(--accent); color: #04222c;
  font: inherit; font-size: 15px; font-weight: 600;
  cursor: pointer;
  transition: opacity 180ms ease;
}
.gate button:disabled { opacity: .55; cursor: default; }

.gate-error {
  margin: 14px 0 0; min-height: 18px;
  color: #e79a5c; font-size: 13px;
}

/* ── Top bar ─────────────────────────────────────────────────────────── */
.topbar {
  position: absolute; z-index: 5;
  top: calc(env(safe-area-inset-top) + 10px); left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px;
  font-size: 11px; letter-spacing: .12em; text-transform: uppercase;
}

.link { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); }
.link::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: currentColor;
}
.link[data-ok="true"]    { color: #4fd48a; }
.link[data-ok="false"]   { color: #e7685c; }
.link[data-ok="pending"] { color: var(--muted); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.ghost {
  background: none; border: 0; padding: 4px 2px;
  color: var(--muted); font: inherit; font-size: 11px;
  letter-spacing: .12em; text-transform: uppercase; cursor: pointer;
}
.ghost:hover { color: var(--ink); }

/* ── Transcript ──────────────────────────────────────────────────────── */
.transcript {
  flex: 1 1 auto;
  width: min(680px, 92vw);
  margin: clamp(6px, 2vh, 16px) auto 0;
  padding: 0 2px 6px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex; flex-direction: column; gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--accent) 30%, transparent) transparent;
}
.transcript::-webkit-scrollbar { width: 4px; }
.transcript::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--accent) 30%, transparent); border-radius: 4px;
}

.turn {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 15px; line-height: 1.5;
  white-space: pre-wrap; overflow-wrap: anywhere;
  animation: rise 260ms cubic-bezier(.22,.9,.3,1);
}
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

.turn[data-who="me"] {
  align-self: flex-end;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 26%, transparent);
  color: var(--ink);
}
.turn[data-who="jarvis"] {
  align-self: flex-start;
  background: rgba(9, 17, 27, .82);
  border: 1px solid rgba(90, 130, 155, .2);
  color: var(--ink);
}
.turn[data-who="error"] {
  align-self: stretch; max-width: 100%;
  background: rgba(60, 26, 16, .5);
  border: 1px solid rgba(231, 154, 92, .35);
  color: #e79a5c; font-size: 14px;
}

/* A display instruction the browser cannot render natively still shows its
   text form — degrade, never drop. */
.turn .payload {
  display: block; margin-top: 8px;
  padding: 8px 10px; border-radius: 8px;
  background: rgba(0, 0, 0, .28);
  color: var(--muted);
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 12.5px; line-height: 1.45;
  overflow-x: auto;
}

.turn .tools {
  display: block; margin-top: 6px;
  color: var(--muted); font-size: 11px;
  letter-spacing: .08em; text-transform: uppercase;
}

/* ── Composer ────────────────────────────────────────────────────────── */
.composer {
  flex: 0 0 auto;
  width: min(680px, 92vw);
  margin: 8px auto 0;
  display: flex; gap: 10px; align-items: center;
}
.composer input { flex: 1 1 auto; border-radius: 999px; }
.composer input:disabled { opacity: .5; }

.mic {
  flex: 0 0 auto;
  width: 48px; height: 48px;
  display: grid; place-items: center;
  border-radius: 50%;
  border: 1px solid color-mix(in srgb, var(--accent) 34%, transparent);
  background: rgba(6, 12, 20, .78);
  color: var(--accent);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;          /* a hold must not scroll or select */
  user-select: none;
  transition: background 160ms ease, transform 120ms ease, border-color 160ms ease;
}
.mic svg { width: 22px; height: 22px; fill: currentColor; }
.mic:disabled { opacity: .4; cursor: default; }

.mic[data-recording="true"] {
  background: #e7685c; border-color: #e7685c; color: #fff;
  transform: scale(1.06);
  animation: mic-pulse 1.1s ease-in-out infinite;
}
@keyframes mic-pulse {
  50% { box-shadow: 0 0 0 10px rgba(231, 104, 92, .14); }
}

/* ── Responsive ──────────────────────────────────────────────────────── */

/* Phone landscape: almost no vertical room, so the face goes beside the
   conversation instead of above it. */
@media (max-height: 460px) and (orientation: landscape) {
  .stage {
    display: grid;
    grid-template-columns: minmax(0, 34%) minmax(0, 1fr);
    grid-template-rows: 1fr auto;
    align-items: center;
    column-gap: 14px;
    padding-top: calc(env(safe-area-inset-top) + 34px);
  }
  .head { grid-row: 1 / span 2; width: min(30vw, 46vh * 1.55); margin: 0 auto; }
  .plate { display: none; }
  .transcript { grid-column: 2; width: 100%; margin: 0; }
  .composer  { grid-column: 2; width: 100%; }
}

/* Desktop: the face can breathe again. */
@media (min-width: 900px) and (min-height: 620px) {
  .head { width: min(30vw, 26vh * 1.55); }
  .transcript { font-size: 15.5px; }
}

@media (prefers-reduced-motion: reduce) {
  .head { animation: none; }
  .turn { animation: none; }
  .mic[data-recording="true"] { animation: none; }
}
