/* ============================================================
   ARCITECTS // genesis agent — blue pixel / CRT chat theme
   ============================================================ */

:root {
  --bg:        #060a14;
  --bg-soft:   #0a1120;
  --panel:     #0c1424;
  --panel-2:   #0e1830;
  --user:      #112a49;
  --fg:        #d7e6fb;
  --muted:     #6e83a6;
  --dim:       #33425e;
  --line:      #18263d;
  --accent:    #3ea0ff;
  --accent-lt: #7cc4ff;
  --accent-dk: #1c5fa6;
  --danger:    #ff6b6b;
  --px:        2px;
  --maxw:      640px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: "VT323", "Courier New", monospace;
  font-size: 21px;
  line-height: 1.3;
  letter-spacing: .3px;
  -webkit-font-smoothing: none;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  overscroll-behavior: none;
  display: flex;
  flex-direction: column;
  height: 100vh;                 /* fallback for old browsers */
  height: 100dvh;                /* dynamic viewport */
  height: var(--app-h, 100dvh);  /* visualViewport-aware (set in app.js) */
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ----------------------------------------------------- FX overlays */

.fx-grid, .fx-scan, .fx-vignette {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
}
.fx-grid {
  background-image:
    linear-gradient(to right, rgba(62,160,255,.05) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(62,160,255,.05) 1px, transparent 1px);
  background-size: 30px 30px;
  mask-image: radial-gradient(circle at 50% 30%, #000 0%, transparent 80%);
  -webkit-mask-image: radial-gradient(circle at 50% 30%, #000 0%, transparent 80%);
}
.fx-scan {
  background: repeating-linear-gradient(to bottom,
    rgba(0,0,0,0) 0 2px, rgba(0,0,0,.18) 3px 4px);
  opacity: .35; mix-blend-mode: multiply;
}
.fx-vignette {
  background: radial-gradient(circle at 50% 35%, transparent 42%, rgba(0,0,0,.6) 100%);
}

/* ----------------------------------------------------- top + footer bars */

.topbar, .footer {
  position: relative; z-index: 2;
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px;
  font-family: "Press Start 2P", monospace;
  font-size: 8px; letter-spacing: 1px; text-transform: uppercase;
  color: var(--muted);
  flex: none;
}
.topbar { border-bottom: var(--px) solid var(--line); }
.footer { border-top: var(--px) solid var(--line); color: var(--dim); }
.footer__seq { color: var(--muted); }
.topbar .dot { margin: 0 8px; color: var(--accent); }
.topbar__right { display: flex; align-items: center; gap: 8px; color: var(--accent); }
.led {
  width: 7px; height: 7px; flex: none;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  animation: pulse 1.5s steps(2) infinite;
}
.blink { animation: blink 1s steps(2) infinite; }

/* ----------------------------------------------------- chat shell */

.chat {
  position: relative; z-index: 1;
  flex: 1; min-height: 0;
  width: 100%; max-width: var(--maxw);
  margin: 0 auto;
  display: flex; flex-direction: column;
  border-left: var(--px) solid var(--line);
  border-right: var(--px) solid var(--line);
  background: linear-gradient(180deg, rgba(62,160,255,.03), transparent 30%);
}

/* agent header */
.chat__head {
  flex: none;
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: var(--px) solid var(--line);
  background: var(--bg-soft);
}
.agent { display: flex; align-items: center; gap: 11px; min-width: 0; }
.agent__avatar {
  flex: none;
  padding: 6px;
  border: var(--px) solid var(--line);
  background: var(--bg);
  box-shadow: 3px 3px 0 #000;
}
.mark__grid {
  display: grid;
  grid-template-columns: repeat(6, 5px);
  grid-template-rows: repeat(6, 5px);
  gap: 1px;
}
.mark__grid i { background: #16243d; }
.mark__grid i.on { background: var(--accent); box-shadow: 0 0 4px rgba(62,160,255,.8); }

.agent__id { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.agent__name {
  font-family: "Press Start 2P", monospace;
  font-size: 11px; letter-spacing: 1px; color: var(--fg);
}
.agent__status {
  display: flex; align-items: center; gap: 6px;
  font-size: 17px; color: var(--accent-lt);
}
.agent__sub { color: var(--muted); }

.stepbox {
  flex: none; text-align: right;
  display: flex; flex-direction: column; gap: 3px;
  font-family: "Press Start 2P", monospace;
}
.stepbox__n { font-size: 9px; color: var(--accent); }
.stepbox__name { font-size: 7px; letter-spacing: 1px; color: var(--muted); }

/* ----------------------------------------------------- message log */

.chat__log {
  flex: 1; min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 20px 14px 8px;
  display: flex; flex-direction: column; gap: 12px;
  scroll-behavior: smooth;
}
/* keep every message + the pass at natural height; the container scrolls
   instead of compressing children when the log overflows */
.chat__log > * { flex-shrink: 0; }
.chat__log::-webkit-scrollbar { width: 8px; }
.chat__log::-webkit-scrollbar-thumb { background: var(--line); }
.chat__log::-webkit-scrollbar-track { background: transparent; }

/* base message bubble */
.msg {
  max-width: 84%;
  padding: 10px 13px;
  font-size: 20px;
  line-height: 1.32;
  border: var(--px) solid var(--line);
  box-shadow: 3px 3px 0 #000;
  white-space: pre-wrap;
  word-break: break-word;
  animation: pop .18s steps(3);
}
.msg--agent {
  align-self: flex-start;
  background: var(--panel);
  border-left: var(--px) solid var(--accent);
  color: var(--fg);
}
.msg--user {
  align-self: flex-end;
  background: var(--user);
  border-right: var(--px) solid var(--accent-lt);
  color: var(--accent-lt);
  text-align: right;
}
.msg--system {
  align-self: center;
  background: transparent;
  border: 0; box-shadow: none;
  font-family: "Press Start 2P", monospace;
  font-size: 8px; letter-spacing: 1px;
  color: var(--dim);
  text-transform: uppercase;
  padding: 2px;
}
.msg--muted { color: var(--muted); font-style: normal; opacity: .9; }

/* typing indicator */
.typing {
  align-self: flex-start;
  display: inline-flex; gap: 5px;
  padding: 13px;
  background: var(--panel);
  border: var(--px) solid var(--line);
  border-left: var(--px) solid var(--accent);
  box-shadow: 3px 3px 0 #000;
}
.typing i {
  width: 7px; height: 7px; background: var(--accent);
  animation: typing 1s steps(2) infinite;
}
.typing i:nth-child(2){ animation-delay: .2s; }
.typing i:nth-child(3){ animation-delay: .4s; }

/* inline task action row */
.actionrow { align-self: flex-start; max-width: 84%; }

/* ----------------------------------------------------- buttons */

.btn {
  font-family: "Press Start 2P", monospace;
  font-size: 9px; letter-spacing: 1px; text-transform: uppercase;
  color: #04101f; background: var(--accent);
  border: var(--px) solid var(--accent-dk);
  padding: 11px 14px;
  cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  box-shadow: 3px 3px 0 #000;
  transition: transform .05s, box-shadow .05s, background .2s, color .2s;
  user-select: none;
  touch-action: manipulation;
  -webkit-touch-callout: none;
}
.btn:hover { transform: translate(-1px,-1px); box-shadow: 4px 4px 0 #000; }
.btn:active { transform: translate(2px,2px); box-shadow: 1px 1px 0 #000; }
.btn[disabled] { cursor: default; }

.btn--done {
  background: transparent; color: var(--accent-lt);
  border-color: var(--accent-dk); box-shadow: none;
}
.btn--done:hover { transform: none; box-shadow: none; }
.btn--ghost {
  background: transparent; color: var(--muted); border-color: var(--line);
}
.btn--ghost:hover { color: var(--fg); border-color: var(--muted); }

/* ----------------------------------------------------- input bar */

.chat__bar {
  flex: none;
  display: flex; align-items: stretch; gap: 0;
  padding: 10px 12px;
  border-top: var(--px) solid var(--line);
  background: var(--bg-soft);
}
.chat__prefix {
  display: flex; align-items: center; padding: 0 10px;
  font-family: "Press Start 2P", monospace; font-size: 11px;
  color: var(--accent);
  border: var(--px) solid var(--line); border-right: 0;
  background: var(--panel);
}
.chat__input {
  flex: 1; min-width: 0;
  border: var(--px) solid var(--line);
  background: var(--bg);
  color: var(--fg);
  font-family: "VT323", monospace; font-size: 22px; letter-spacing: 1px;
  padding: 12px 12px;
  outline: 0;
}
.chat__input::placeholder { color: var(--dim); }
.chat__input:disabled { color: var(--dim); background: #070c16; }
.chat__bar:focus-within .chat__prefix,
.chat__bar:focus-within .chat__input { border-color: var(--accent-dk); }

.chat__send {
  flex: none; margin-left: 10px;
  font-family: "Press Start 2P", monospace; font-size: 9px; letter-spacing: 1px;
  color: #04101f; background: var(--accent);
  border: var(--px) solid var(--accent-dk);
  padding: 0 16px; cursor: pointer;
  box-shadow: 3px 3px 0 #000;
  transition: transform .05s, box-shadow .05s, opacity .2s;
  touch-action: manipulation;
}
.chat__send:hover { transform: translate(-1px,-1px); box-shadow: 4px 4px 0 #000; }
.chat__send:active { transform: translate(2px,2px); box-shadow: 1px 1px 0 #000; }
.chat__send:disabled { opacity: .35; cursor: not-allowed; transform: none; box-shadow: 3px 3px 0 #000; }

.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }

/* ----------------------------------------------------- genesis pass card */

.pass {
  align-self: stretch;
  max-width: 100%;
  margin: 6px 0;
  border: var(--px) solid var(--accent-dk);
  background:
    linear-gradient(135deg, rgba(62,160,255,.14), transparent 40%),
    linear-gradient(315deg, rgba(124,196,255,.10), transparent 45%),
    var(--panel-2);
  box-shadow: 5px 5px 0 #000, 0 0 30px rgba(62,160,255,.18) inset;
  padding: 0;
  overflow: hidden;
  animation: pop .26s steps(4);
}
.pass__top {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px;
  border-bottom: var(--px) dashed var(--accent-dk);
  background: rgba(62,160,255,.06);
}
.pass__brand {
  font-family: "Press Start 2P", monospace; font-size: 9px; letter-spacing: 1px;
  color: var(--accent-lt);
}
.pass__chain {
  font-family: "Press Start 2P", monospace; font-size: 7px; letter-spacing: 1px;
  color: #04101f; background: var(--accent);
  padding: 5px 8px;
}
.pass__seat {
  text-align: center; padding: 18px 12px 8px;
}
.pass__seatlabel {
  font-family: "Press Start 2P", monospace; font-size: 7px; letter-spacing: 2px;
  color: var(--muted);
}
.pass__seatnum {
  font-family: "Press Start 2P", monospace; font-size: 30px; color: var(--fg);
  margin-top: 10px; text-shadow: 3px 3px 0 #000;
}
.pass__rows { padding: 6px 14px 12px; display: flex; flex-direction: column; gap: 8px; }
.pass__row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  font-size: 19px;
  border-bottom: var(--px) solid var(--line); padding-bottom: 7px;
}
.pass__row:last-child { border-bottom: 0; }
.pass__k {
  font-family: "Press Start 2P", monospace; font-size: 7px; letter-spacing: 1px;
  color: var(--muted);
}
.pass__v { color: var(--accent-lt); word-break: break-all; text-align: right; }
.pass__badges {
  display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px 14px;
}
.pass__badge {
  font-family: "Press Start 2P", monospace; font-size: 6px; letter-spacing: 1px;
  color: var(--accent-lt);
  border: var(--px) solid var(--accent-dk);
  background: rgba(62,160,255,.06);
  padding: 6px 7px;
}
.pass__foot { padding: 0 14px 14px; display: flex; gap: 10px; flex-wrap: wrap; }
.pass__foot .btn { flex: 1; }

/* ----------------------------------------------------- animations */

@keyframes blink  { 0%,49%{opacity:1} 50%,100%{opacity:0} }
@keyframes pulse  { 0%,49%{opacity:1} 50%,100%{opacity:.3} }
@keyframes typing { 0%,49%{opacity:1; transform:translateY(0)} 50%,100%{opacity:.25; transform:translateY(-2px)} }
@keyframes pop    { from{opacity:0; transform:translateY(6px)} to{opacity:1; transform:none} }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

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

/* touch devices: comfortable tap targets (≥44px) regardless of width */
@media (pointer: coarse) {
  .btn { min-height: 44px; }
  .chat__send { min-height: 46px; }
  .chat__input { min-height: 46px; }
}

@media (max-width: 480px) {
  body { font-size: 19px; }
  .chat { border-left: 0; border-right: 0; }
  .chat__log { padding: 16px 12px 6px; gap: 10px; }
  .msg { font-size: 18px; max-width: 88%; }
  .agent__name { font-size: 9px; }
  .agent__sub { display: none; }
  .stepbox__n { font-size: 8px; }
  .chat__input { font-size: 20px; }   /* keep ≥16px → no iOS focus-zoom */
  .pass__seatnum { font-size: 24px; }
}

@media (max-width: 380px) {
  body { font-size: 18px; }
  .topbar, .footer { font-size: 7px; padding: 10px 12px; }
  .chat__head { padding: 10px 11px; gap: 8px; }
  .agent { gap: 8px; }
  .agent__name { font-size: 8px; }
  .agent__status { font-size: 15px; }
  .stepbox__n { font-size: 7px; }
  .stepbox__name { font-size: 6px; }
  .msg { font-size: 17px; max-width: 90%; }
  .chat__prefix { font-size: 10px; padding: 0 8px; }
  .chat__send { padding: 0 12px; }
  .pass__brand { font-size: 8px; }
  .pass__seatnum { font-size: 22px; }
  .pass__row { font-size: 17px; }
}

@media (max-width: 330px) {
  .agent__status { display: none; }   /* free room on very small screens */
  .msg { font-size: 16px; }
  .pass__badge { font-size: 5px; }
}

/* short landscape phones: trim vertical chrome so the chat fits */
@media (max-height: 480px) and (orientation: landscape) {
  .topbar, .footer { padding: 7px 14px; }
  .chat__head { padding: 8px 12px; }
  .chat__log { padding-top: 10px; padding-bottom: 6px; }
}
