/* ===========================================================================
   MATRI — Agent T · DATA RAIN / GLITCH entry portal (p6)
   Palette: fresh cyan + lime on near-black. Technical mono. Terminal key line.
   Strict-CSP: no inline styles; JS drives dynamic values via CSSOM/classList.
   Rebuilt fully responsive: fluid terminal card, viewport-fit glyph rain,
   gate reachable at 390x844 (portrait), 844x390 (landscape), and desktop.
   =========================================================================== */

:root {
  /* near-black substrate */
  --void:   #05070a;
  --void-2: #070b0f;
  --panel:  rgba(9, 14, 19, 0.72);
  --panel-solid: #090e13;

  /* signal colors */
  --cyan:   #2de2c6;   /* primary head glyph, focus, prompt */
  --cyan-hi:#7cffe9;
  --lime:   #c6ff4a;   /* accent surge / run button */
  --lime-hi:#e7ff9c;

  /* glitch RGB-split channels */
  --glitch-a: #ff2e6e; /* magenta-red */
  --glitch-b: #21d4ee; /* cyan-blue   */

  /* ink */
  --ink:    #d7e6e6;   /* body text — ~13:1 on --void */
  --ink-dim:#8aa2a3;   /* ~6.5:1 on --void */
  --ink-fnt:#5c7375;   /* faint labels — used only at >=14px on dark */
  --hair:   rgba(45, 226, 198, 0.16);
  --hair-2: rgba(45, 226, 198, 0.08);

  --mono: ui-monospace, "Cascadia Code", "JetBrains Mono", "SF Mono", "Roboto Mono", Menlo, Consolas, monospace;

  --r: 12px;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  min-height: 100svh;
  background: var(--void);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  display: grid;
  place-items: center;
  padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(20px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  /* Only the horizontal axis is clamped — vertical can scroll so the gate is
     always reachable when a short landscape viewport can't fit the card. */
  overflow-x: hidden;
  overflow-y: auto;
}

/* ---- skip link ---- */
.skip {
  position: fixed; left: 12px; top: -60px; z-index: 40;
  background: var(--panel-solid); color: var(--cyan);
  border: 1px solid var(--cyan); border-radius: 8px;
  padding: 10px 14px; font-size: 13px; text-decoration: none;
  transition: top .18s var(--ease);
}
.skip:focus { top: 12px; }

/* ---- backdrop layers ---- */
.rain {
  position: fixed; inset: 0; width: 100%; height: 100%;
  z-index: 0; display: block;
  background: radial-gradient(120% 120% at 50% 8%, #08111a 0%, var(--void) 62%);
}

/* ---- gesture-tech showcase overlay (8 demos render here, behind the card) ---- */
.fx {
  position: fixed; inset: 0; z-index: 2;
  pointer-events: none; overflow: hidden;
}
.fx__canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%; display: block;
}
.fx-label {
  position: fixed; z-index: 5;
  left: 50%; top: max(12px, env(safe-area-inset-top));
  transform: translateX(-50%);
  margin: 0; pointer-events: none;
  max-width: calc(100vw - 24px);
  padding: 6px 14px;
  font-size: 10.5px; letter-spacing: .2em; text-transform: uppercase;
  color: var(--cyan);
  background: rgba(5, 7, 10, .74);
  border: 1px solid var(--hair);
  border-radius: 999px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  opacity: 0; transition: opacity .3s var(--ease);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.fx-label.show { opacity: 1; }

/* click-and-hold demo: stacked translucent columns, additively phosphor-glowing */
.layerfx { position: absolute; inset: 0; }
.layerfx__col {
  position: absolute; top: -20%; height: 140%;
  mix-blend-mode: screen;
  background: linear-gradient(180deg,
    transparent 0%,
    rgba(45, 226, 198, .42) 38%,
    rgba(198, 255, 74, .40) 60%,
    transparent 100%);
  filter: blur(1px);
  opacity: .85;
  animation: layerdrift 2.6s var(--ease) infinite alternate;
  animation-delay: calc(var(--i, 0) * -0.34s);
}
@keyframes layerdrift {
  from { transform: translateY(-14%) scaleY(.82); }
  to   { transform: translateY(14%)  scaleY(1.16); }
}

.grain {
  position: fixed; inset: 0; z-index: 3; pointer-events: none;
  opacity: .05; mix-blend-mode: screen;
  background-image:
    repeating-linear-gradient(0deg, transparent 0 2px, rgba(45,226,198,.5) 2px 3px);
  background-size: 100% 3px;
}
.vignette {
  position: fixed; inset: 0; z-index: 4; pointer-events: none;
  background:
    radial-gradient(130% 100% at 50% 46%, transparent 40%, rgba(3,5,7,.62) 78%, rgba(3,5,7,.92) 100%);
}

/* ---- shell / centered terminal ---- */
.stage {
  position: relative; z-index: 6;
  width: min(560px, 100%);
  min-width: 0;            /* grid item: allow shrink to area, no min-content overflow */
  max-width: 100%;
  display: flex; justify-content: center;
}

.term {
  position: relative;
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--hair);
  border-radius: var(--r);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  box-shadow:
    0 0 0 1px rgba(0,0,0,.4),
    0 30px 80px -30px rgba(0,0,0,.9),
    0 0 60px -20px rgba(45,226,198,.22);
  overflow: hidden;
  opacity: 0;
  transform: translateY(10px) scale(.99);
  animation: term-in .7s var(--ease) .05s forwards;
}
@keyframes term-in { to { opacity: 1; transform: none; } }

/* denied: chromatic-aberration shake (bounded, no >3/s strobe) */
.term.is-deny { animation: deny-shake .5s var(--ease) both; }
@keyframes deny-shake {
  0%, 100% { transform: translateX(0); box-shadow: 0 0 0 1px rgba(0,0,0,.4), 0 30px 80px -30px rgba(0,0,0,.9), 0 0 60px -20px rgba(45,226,198,.22); }
  10% { transform: translateX(-7px); box-shadow: 6px 0 0 -2px var(--glitch-a), -6px 0 0 -2px var(--glitch-b), 0 30px 80px -30px rgba(0,0,0,.9); }
  30% { transform: translateX(6px); }
  50% { transform: translateX(-4px); box-shadow: 4px 0 0 -2px var(--glitch-a), -4px 0 0 -2px var(--glitch-b), 0 30px 80px -30px rgba(0,0,0,.9); }
  70% { transform: translateX(3px); }
  85% { transform: translateX(-1px); }
}

/* ---- title bar ---- */
.term__bar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--hair-2);
  background: linear-gradient(180deg, rgba(45,226,198,.05), transparent);
}
.term__dots { display: inline-flex; gap: 7px; flex: none; }
.term__dots .dot { width: 11px; height: 11px; }
.term__dots .dot:nth-child(1) { color: #ff5f57; }
.term__dots .dot:nth-child(2) { color: #f7c94b; }
.term__dots .dot:nth-child(3) { color: var(--cyan); }
.term__dots .dot circle { fill: currentColor; opacity: .9; }
.term__title {
  font-size: 12.5px; letter-spacing: .04em; color: var(--ink-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  min-width: 0;
}
.term__link {
  margin-left: auto; display: inline-flex; align-items: center; gap: 6px;
  color: var(--cyan); font-size: 11.5px; letter-spacing: .08em;
  opacity: .85; flex: none;
}
.term__link .lock { width: 14px; height: 14px; }

/* ---- body ---- */
.term__body { padding: 30px clamp(20px, 5vw, 34px) 26px; }

.brand {
  position: relative;
  margin: 0 0 20px;
  font-size: 13px; font-weight: 700; letter-spacing: .42em;
  color: var(--cyan);
  text-indent: .42em;
}
.brand::before {
  content: "// ";
  color: var(--ink-fnt); letter-spacing: normal; text-indent: 0; font-weight: 400;
}

.head {
  position: relative;
  margin: 0 0 14px;
  font-size: clamp(23px, 6vw, 33px);
  font-weight: 650;
  line-height: 1.12;
  letter-spacing: -0.015em;
  color: var(--ink);
}
/* RGB-split glitch layers on the headline (data-text mirror) */
.head::before, .head::after {
  content: attr(data-text);
  position: absolute; inset: 0;
  pointer-events: none;
  opacity: 0;
  clip-path: inset(0 0 0 0);
}
.head::before { color: var(--glitch-a); }
.head::after  { color: var(--glitch-b); }
.term.is-glitch .head::before { animation: split-a .42s steps(2) both; }
.term.is-glitch .head::after  { animation: split-b .42s steps(2) both; }
@keyframes split-a {
  0% { opacity: 0; transform: translate(0,0); }
  20% { opacity: .9; transform: translate(-3px,-1px); clip-path: inset(0 0 62% 0); }
  45% { transform: translate(2px,1px); clip-path: inset(58% 0 8% 0); }
  70% { transform: translate(-2px,0); clip-path: inset(20% 0 46% 0); }
  100% { opacity: 0; transform: translate(0,0); }
}
@keyframes split-b {
  0% { opacity: 0; transform: translate(0,0); }
  25% { opacity: .9; transform: translate(3px,1px); clip-path: inset(72% 0 0 0); }
  50% { transform: translate(-2px,-1px); clip-path: inset(10% 0 70% 0); }
  75% { transform: translate(2px,0); clip-path: inset(40% 0 30% 0); }
  100% { opacity: 0; transform: translate(0,0); }
}

.sub {
  margin: 0 0 26px;
  max-width: 46ch;
  font-size: 13.5px; line-height: 1.6;
  color: var(--ink-dim);
}

/* ---- the terminal key line ---- */
.key { margin: 0; }
.key__label {
  display: block;
  font-size: 11.5px; letter-spacing: .18em; text-transform: uppercase;
  color: var(--ink-fnt);
  margin-bottom: 9px;
}

.prompt {
  display: flex; align-items: center; flex-wrap: wrap; gap: 10px;
  padding: 12px 12px 12px 14px;
  background: rgba(3, 6, 9, .66);
  border: 1px solid var(--hair);
  border-radius: 10px;
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease), background .2s var(--ease);
}
.prompt:focus-within {
  border-color: var(--cyan);
  background: rgba(3, 6, 9, .82);
  box-shadow: 0 0 0 3px rgba(45,226,198,.22), 0 0 26px -8px rgba(45,226,198,.5);
}
.prompt__ps1 {
  flex: none;
  color: var(--cyan); font-size: 13.5px; letter-spacing: .01em;
  opacity: .92; user-select: none;
}
/* field flexes to fill and can shrink below content — the key overflow fix:
   the input width is now bounded by the container, never grown past it. */
.prompt__field { position: relative; flex: 1 1 120px; display: flex; align-items: center; min-width: 0; }
.prompt__input {
  flex: 1 1 auto; width: 100%; min-width: 0;
  appearance: none; background: transparent; border: 0; outline: none;
  color: var(--ink); font: inherit; font-size: 15px;
  letter-spacing: .12em;
  caret-color: var(--cyan);
  padding: 2px 0;
}
.prompt__input::placeholder { color: var(--ink-fnt); letter-spacing: normal; }
.prompt__input:-webkit-autofill { -webkit-text-fill-color: var(--ink); transition: background-color 9999s; }

/* run button */
.run {
  flex: none; margin-left: auto;
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 14px;
  font: inherit; font-size: 13px; font-weight: 700; letter-spacing: .06em;
  color: var(--void);
  background: var(--lime);
  border: 0; border-radius: 8px;
  cursor: pointer;
  transition: transform .15s var(--ease), filter .15s var(--ease), opacity .2s, background .2s;
}
.run__ico { width: 17px; height: 17px; }
.run:hover:not(:disabled) { filter: brightness(1.08); transform: translateY(-1px); }
.run:active:not(:disabled) { transform: translateY(0) scale(.98); }
.run:disabled { background: #1b2a2a; color: var(--ink-fnt); cursor: progress; }

/* ---- verdict (aria-live) ---- */
.verdict {
  min-height: 1.3em; margin: 14px 2px 0;
  font-size: 13px; letter-spacing: .01em; color: var(--ink-dim);
  transition: color .2s;
}
.verdict:not(:empty)::before { content: "> "; color: var(--ink-fnt); }
.verdict.is-work { color: var(--cyan); }
.verdict.is-deny { color: var(--glitch-a); }
.verdict.is-wait { color: var(--lime); }

/* ---- meta / footer key line ---- */
.meta {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
  margin-top: 24px; padding-top: 16px;
  border-top: 1px solid var(--hair-2);
  font-size: 11.5px; letter-spacing: .04em; color: var(--ink-fnt);
}
.meta__cell { white-space: nowrap; }
.meta__sep { opacity: .6; }
.meta__ver { margin-left: auto; color: var(--ink-dim); }
#status.is-live { color: var(--cyan); }

/* ---- gesture signal caption ---- */
.gestures {
  display: flex; flex-wrap: wrap; align-items: center; gap: 7px 10px;
  margin: 14px 2px 0;
  font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--ink-fnt);
}
.gestures__k {
  padding: 3px 8px;
  border: 1px solid var(--hair);
  border-radius: 999px;
  color: var(--ink-dim);
}
.gestures__t { color: var(--ink-fnt); letter-spacing: .08em; }

/* ---- focus-visible ring everywhere ---- */
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; border-radius: 4px; }
.run:focus-visible { outline-offset: 3px; }
.prompt__input:focus-visible { outline: none; }

/* ===========================================================================
   THE CROSSING — channel opens: scene warps, panel dissolves into the stream
   =========================================================================== */
html.crossing .term {
  animation: cross-out 1.4s var(--ease) forwards;
}
@keyframes cross-out {
  0%   { opacity: 1; transform: none; filter: none; }
  14%  { transform: translateX(-4px); box-shadow: 8px 0 0 -3px var(--glitch-a), -8px 0 0 -3px var(--glitch-b); }
  28%  { transform: translateX(5px); }
  44%  { transform: translateX(-2px) scale(1.004); }
  60%  { opacity: 1; transform: scale(1.02); filter: brightness(1.25) blur(.4px); }
  100% { opacity: 0; transform: scale(1.12); filter: brightness(2) blur(6px); }
}
html.crossing .vignette { animation: cross-fade 1.4s var(--ease) forwards; }
@keyframes cross-fade { to { background: radial-gradient(130% 100% at 50% 46%, rgba(45,226,198,.14) 0%, transparent 55%, rgba(3,5,7,.6) 100%); } }

/* ===========================================================================
   RESPONSIVE — portrait phones
   =========================================================================== */
@media (max-width: 480px) {
  body { padding: 16px 14px max(16px, env(safe-area-inset-bottom)); }
  .term__body { padding: 24px 18px 20px; }
  .term__title { font-size: 11.5px; }
  .brand { letter-spacing: .34em; }
  .run { padding: 9px 12px; }
}
@media (max-width: 360px) {
  .prompt__ps1 { font-size: 12px; }
  .brand { letter-spacing: .28em; }
}

/* ===========================================================================
   RESPONSIVE — short / landscape viewports (e.g. 844x390)
   Compact the card so the gate stays fully on-screen; body still scrolls
   as a last resort so the run button is never unreachable.
   =========================================================================== */
@media (max-height: 560px) {
  body { padding: 12px 16px; place-items: center; }
  .term__bar { padding: 8px 14px; }
  .term__body { padding: 16px clamp(16px, 4vw, 28px) 14px; }
  .brand { margin-bottom: 10px; }
  .head { font-size: clamp(19px, 4.4vh, 25px); margin-bottom: 8px; }
  .sub { margin-bottom: 14px; font-size: 12.5px; line-height: 1.5; }
  .key__label { margin-bottom: 6px; }
  .verdict { margin-top: 10px; min-height: 1.1em; }
  .meta { margin-top: 12px; padding-top: 10px; }
  .gestures { margin-top: 10px; }
}
/* very short landscape: hide the descriptive paragraph to guarantee fit */
@media (max-height: 430px) and (orientation: landscape) {
  .sub { display: none; }
  .gestures { display: none; }
  .term__body { padding: 14px 20px 12px; }
  .head { font-size: clamp(18px, 5.6vw, 23px); }
}

/* ===========================================================================
   REDUCED MOTION — pause every heavy animation to a still, quiet frame
   =========================================================================== */
@media (prefers-reduced-motion: reduce) {
  .term { opacity: 1; transform: none; animation: none; }
  .term.is-deny { animation: none; }
  .term.is-glitch .head::before, .term.is-glitch .head::after { animation: none; opacity: 0; }
  html.crossing .term { animation: none; opacity: .25; transition: opacity .3s; }
  html.crossing .vignette { animation: none; }
  .layerfx__col { animation: none; }
  .skip { transition: none; }
  .grain { display: none; }
}

/* exit veil: the LAST painted frame before leaving must match the app's dark canvas (#0b0d12) so the
   browser never shows a bright frame between documents — photosensitivity mandate, applies to every exit */
.exit-veil{ position:fixed; inset:0; z-index:2147483000; background:#0b0d12; opacity:0; pointer-events:none; transition:opacity .3s ease; }
.exit-veil.is-on{ opacity:1; }
@media (prefers-reduced-motion: reduce){ .exit-veil{ transition:none; } }
