/* J.A.R.V.I.S — neo interface
   Palette tokens mirror jarvis/theme.py; --primary/--accent/--dim are re-written
   by the render loop on every state cross-fade, so the DOM chrome grades with
   the canvas instead of drifting out of step with it. */

:root {
  --backdrop: #03070f;
  --panel: #050c17;
  --grid: #0b1b2b;

  --primary: #00e5ff;
  --accent: #b7f6ff;
  --dim: #0b5b72;

  --ink: #dbe9f4;
  --ink-soft: #7f97ad;
  --ink-faint: #4a5f74;

  --ok: #00ffb3;
  --warn: #ffb020;
  --bad: #ff3b5c;

  --edge: color-mix(in srgb, var(--primary) 26%, transparent);
  --edge-soft: color-mix(in srgb, var(--primary) 12%, transparent);
  --glass: color-mix(in srgb, var(--panel) 82%, transparent);

  --s-1: 0.25rem;
  --s-2: 0.5rem;
  --s-3: 0.75rem;
  --s-4: 1rem;
  --s-5: 1.5rem;
  --s-6: 2rem;

  --r-1: 2px;
  --r-2: 4px;
  --r-3: 10px;

  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Mono", Consolas, "Liberation Mono", monospace;
  --fade: 420ms cubic-bezier(.22, .61, .36, 1);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--backdrop);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

body::after {                       /* vignette + faint interlace over everything */
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 40;
  background:
    repeating-linear-gradient(to bottom, rgba(255,255,255,.018) 0 1px, transparent 1px 3px),
    radial-gradient(120% 90% at 50% 45%, transparent 42%, rgba(0,0,0,.72) 100%);
  mix-blend-mode: soft-light;
}

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

#hud {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
}

/* ---------------------------------------------------------------- layout */

.frame {
  position: relative;
  z-index: 10;
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(200px, 260px) 1fr minmax(200px, 260px);
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "top    top    top"
    "left   stage  right"
    "bottom bottom bottom";
  gap: var(--s-4);
  padding: var(--s-4) clamp(var(--s-3), 2vw, var(--s-6));
  pointer-events: none;
}

/* Grid items default to min-width:auto, so the console's min-content width
   would widen the whole track and push the top bar off-screen on a phone. */
.frame > * { pointer-events: auto; min-width: 0; }

/* --------------------------------------------------------------- chrome */

.bar--top    { grid-area: top; }
.bar--bottom { grid-area: bottom; }

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
}

.mark {
  display: flex;
  align-items: baseline;
  flex: 1 1 auto;
  min-width: 0;
  gap: var(--s-3);
  letter-spacing: .34em;
  font-size: 13px;
  text-transform: uppercase;
}
.mark__glyph {
  align-self: center;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 12px var(--primary), 0 0 26px color-mix(in srgb, var(--primary) 55%, transparent);
  transition: background var(--fade), box-shadow var(--fade);
}
.mark__text {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: clip;
  color: var(--accent);
  text-shadow: 0 0 18px color-mix(in srgb, var(--primary) 45%, transparent);
}
.mark__rev  { color: var(--ink-faint); letter-spacing: .18em; font-size: 10px; }

.state {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  margin: 0;
  padding: var(--s-1) var(--s-3);
  border: 1px solid var(--edge);
  border-radius: var(--r-1);
  background: var(--glass);
  backdrop-filter: blur(6px);
  font-size: 11px;
  letter-spacing: .22em;
  color: var(--accent);
  transition: border-color var(--fade), color var(--fade);
}
.state__dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 10px var(--primary);
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: .35; transform: scale(.8); } }

.clock {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  font-variant-numeric: tabular-nums;
}
.clock time { font-size: 15px; letter-spacing: .12em; color: var(--accent); }
.clock span { font-size: 10px; letter-spacing: .2em; color: var(--ink-faint); text-transform: uppercase; }

/* --------------------------------------------------------------- panels */

.panel {
  align-self: start;
  max-height: 100%;
  overflow: hidden auto;
  scrollbar-width: thin;
  scrollbar-color: var(--dim) transparent;
  padding: var(--s-3) var(--s-4) var(--s-4);
  border: 1px solid var(--edge-soft);
  border-radius: var(--r-2);
  background: linear-gradient(180deg, var(--glass), color-mix(in srgb, var(--backdrop) 88%, transparent));
  backdrop-filter: blur(8px);
  transition: border-color var(--fade);
}
.panel--left  { grid-area: left; }
.panel--right { grid-area: right; }

.panel::before {                    /* corner tick, top-left */
  content: "";
  display: block;
  width: 26px; height: 1px;
  margin-bottom: var(--s-3);
  background: var(--primary);
  box-shadow: 0 0 10px var(--primary);
  transition: background var(--fade);
}

.panel__title {
  margin: var(--s-4) 0 var(--s-2);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .3em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.panel__title:first-of-type { margin-top: 0; }

.panel__note {
  margin: var(--s-2) 0 0;
  font-size: 10px;
  line-height: 1.6;
  color: var(--ink-faint);
}

.rows { list-style: none; margin: 0; padding: 0; }
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-2);
  padding: 5px 0;
  border-bottom: 1px dashed color-mix(in srgb, var(--grid) 90%, transparent);
  font-size: 11px;
}
.row:last-child { border-bottom: 0; }
.row__k { color: var(--ink-soft); letter-spacing: .08em; }
.row__v {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  text-align: right;
  transition: color var(--fade);
}

/* Status is carried by a glyph as well as colour, so it survives greyscale. */
.row__v[data-status]::before {
  content: "◇ ";
  color: var(--ink-faint);
}
.row__v[data-status="ok"]   { color: var(--ok);   }
.row__v[data-status="ok"]::before   { content: "◆ "; color: var(--ok); }
.row__v[data-status="warn"] { color: var(--warn); }
.row__v[data-status="warn"]::before { content: "▲ "; color: var(--warn); }
.row__v[data-status="bad"]  { color: var(--bad);  }
.row__v[data-status="bad"]::before  { content: "✕ "; color: var(--bad); }
.row__v[data-status="off"]  { color: var(--ink-faint); }

.hints { list-style: none; margin: 0; padding: 0; font-size: 10.5px; color: var(--ink-soft); }
.hints li { padding: 4px 0; border-bottom: 1px dashed color-mix(in srgb, var(--grid) 90%, transparent); }
.hints li:last-child { border-bottom: 0; }
.hints b { color: var(--accent); font-weight: 500; }

.segmented { display: flex; gap: 2px; }
.segmented button {
  flex: 1;
  padding: 6px 2px;
  border: 1px solid var(--edge-soft);
  border-radius: var(--r-1);
  background: transparent;
  color: var(--ink-soft);
  font: inherit;
  font-size: 10px;
  letter-spacing: .1em;
  cursor: pointer;
  transition: color 160ms, border-color 160ms, background 160ms;
}
.segmented button:hover { color: var(--accent); border-color: var(--edge); }
.segmented button[aria-checked="true"] {
  color: var(--backdrop);
  background: var(--primary);
  border-color: var(--primary);
}

.meter {
  position: relative;
  height: 6px;
  border: 1px solid var(--edge-soft);
  border-radius: var(--r-1);
  overflow: hidden;
  background: color-mix(in srgb, var(--grid) 60%, transparent);
}
.meter__fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--dim), var(--primary));
  box-shadow: 0 0 12px color-mix(in srgb, var(--primary) 70%, transparent);
  transition: width 80ms linear, background var(--fade);
}
.meter__peak {
  position: absolute;
  top: 0; bottom: 0;
  width: 2px;
  left: 0;
  background: var(--accent);
  transition: left 220ms ease-out;
}

/* ------------------------------------------------------------ transcript */

.stage {
  grid-area: stage;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  min-height: 0;
  padding-bottom: var(--s-2);
  pointer-events: none;
}

.transcript {
  pointer-events: auto;
  width: min(720px, 100%);
  max-height: 38%;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--dim) transparent;
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  padding-right: var(--s-2);
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 12%);
          mask-image: linear-gradient(to bottom, transparent, #000 12%);
}

.line {
  --line-tint: var(--primary);
  max-width: 92%;
  padding: var(--s-2) var(--s-3);
  border-left: 2px solid var(--line-tint);
  border-radius: 0 var(--r-2) var(--r-2) 0;
  /* The ring renders behind the log, so each line carries its own ground —
     legibility over a moving background is not negotiable. */
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--line-tint) 14%, transparent), transparent 70%),
    color-mix(in srgb, var(--backdrop) 86%, transparent);
  backdrop-filter: blur(3px);
  animation: line-in 320ms cubic-bezier(.22,.61,.36,1) both;
}
.line--you {
  --line-tint: var(--ink-soft);
  align-self: flex-end;
  text-align: right;
  border-left: 0;
  border-right: 2px solid var(--line-tint);
  border-radius: var(--r-2) 0 0 var(--r-2);
  background:
    linear-gradient(270deg, color-mix(in srgb, var(--ink-soft) 16%, transparent), transparent 70%),
    color-mix(in srgb, var(--backdrop) 82%, transparent);
}
.line--sys { --line-tint: var(--warn); }
.line--err { --line-tint: var(--bad); }

.line__who {
  display: block;
  font-size: 9px;
  letter-spacing: .28em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 3px;
}
.line__body { font-size: 13px; color: var(--ink); white-space: pre-wrap; overflow-wrap: anywhere; }
.line--you .line__body { color: var(--ink-soft); }

.line__body::after {                /* caret while a reply is still streaming */
  content: "";
  display: none;
  width: 7px; height: 1em;
  margin-left: 2px;
  vertical-align: -2px;
  background: var(--primary);
  animation: blink 900ms steps(2, start) infinite;
}
.line[data-streaming="true"] .line__body::after { display: inline-block; }

@keyframes blink { 50% { opacity: 0; } }
@keyframes line-in { from { opacity: 0; transform: translateY(8px); } }

/* --------------------------------------------------------------- console */

.console {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  width: min(900px, 100%);
  max-width: 100%;
  margin: 0 auto;
  padding: var(--s-2);
  border: 1px solid var(--edge);
  border-radius: var(--r-3);
  background: var(--glass);
  backdrop-filter: blur(10px);
  box-shadow: 0 0 40px -12px color-mix(in srgb, var(--primary) 60%, transparent);
  transition: border-color var(--fade), box-shadow var(--fade);
}

.field { flex: 1; display: flex; min-width: 0; }
.field input {
  flex: 1;
  min-width: 0;
  padding: var(--s-2) var(--s-3);
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  letter-spacing: .04em;
}
.field input::placeholder { color: var(--ink-faint); }
.field input:focus { outline: none; }
.console:focus-within { border-color: var(--primary); }

.key {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-3);
  border: 1px solid var(--edge);
  border-radius: var(--r-2);
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-size: 11px;
  letter-spacing: .16em;
  text-transform: uppercase;
  cursor: pointer;
  white-space: nowrap;
  transition: background 160ms, color 160ms, border-color 160ms;
}
.key:hover { background: color-mix(in srgb, var(--primary) 14%, transparent); }
.key--send { background: color-mix(in srgb, var(--primary) 16%, transparent); }
.key--mic[aria-pressed="true"] {
  color: var(--backdrop);
  background: var(--primary);
  border-color: var(--primary);
  box-shadow: 0 0 22px -4px var(--primary);
}
.key--ghost { color: var(--ink-soft); border-color: var(--edge-soft); }
.key--ghost[aria-pressed="false"] { color: var(--ink-faint); text-decoration: line-through; }
.key[disabled] { opacity: .4; cursor: not-allowed; }

:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ------------------------------------------------------------------ boot */

.boot {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  background: radial-gradient(80% 60% at 50% 50%, #04101c, var(--backdrop) 70%);
  transition: opacity 700ms ease, visibility 700ms;
}
.boot[hidden-soft] { opacity: 0; visibility: hidden; pointer-events: none; }

.boot__inner { width: min(560px, 88vw); }
.boot__log {
  margin: 0 0 var(--s-5);
  font-size: 12px;
  line-height: 1.9;
  color: var(--ink-soft);
  white-space: pre-wrap;
  min-height: 15em;
}
.boot__log b { color: var(--primary); font-weight: 500; }
.boot__log i { color: var(--ok); font-style: normal; }

.boot__go {
  display: block;
  width: 100%;
  padding: var(--s-3);
  border: 1px solid var(--primary);
  border-radius: var(--r-2);
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  color: var(--accent);
  font: inherit;
  font-size: 12px;
  letter-spacing: .34em;
  text-transform: uppercase;
  cursor: pointer;
  animation: line-in 400ms both;
}
.boot__go:hover { background: color-mix(in srgb, var(--primary) 24%, transparent); }

/* ----------------------------------------------------------- responsive */

@media (max-width: 1080px) {
  .frame {
    grid-template-columns: 1fr;
    grid-template-areas: "top" "stage" "bottom";
    gap: var(--s-3);
  }
  .panel { display: none; }
  .transcript { max-height: min(52%, 420px); width: 100%; }
  .stage { padding-bottom: 0; }
}

@media (max-width: 560px) {
  html, body { font-size: 13px; }
  .mark__rev, .clock span { display: none; }
  .mark { letter-spacing: .16em; font-size: 10px; min-width: 0; }
  .mark__text { overflow: hidden; text-overflow: ellipsis; }
  .clock time { font-size: 12px; letter-spacing: .06em; }
  .state { flex: 0 0 auto; padding: 2px var(--s-2); font-size: 9px; letter-spacing: .14em; }
  .bar--top { gap: var(--s-2); }
  .frame { padding-inline: var(--s-2); }
  .key__text { display: none; }
  .key--send, .key--mic { padding: var(--s-2); }
  .key--ghost .key__text { display: inline; font-size: 9px; }
  .console { border-radius: var(--r-2); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
