:root {
  --bg:      #0a0705;
  --bg2:     #140d07;
  --ink:     #e8c9a0;
  --orange:  #ff9d2f;
  --orange-d:#f08a24;
  --leaf:    #6f9c4a;
  --glow:    #ff9d2f;
  --dim:     #7a5a38;
  --wire:    #3a2614;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  height: 100dvh;            /* track the *dynamic* viewport on mobile browsers */
  background: radial-gradient(120% 100% at 50% 0%, var(--bg2) 0%, var(--bg) 70%);
  color: var(--ink);
  font-family: "Share Tech Mono", monospace;
  overflow: hidden;
  cursor: crosshair;
  -webkit-text-size-adjust: 100%;
}

body { position: relative; }

/* ---------- CRT / atmosphere layers ---------- */
.scanlines, .vignette, .noise {
  position: fixed; inset: 0; pointer-events: none; z-index: 50;
}
.scanlines {
  background: repeating-linear-gradient(
    to bottom,
    rgba(0,0,0,0) 0px,
    rgba(0,0,0,0) 2px,
    rgba(0,0,0,0.28) 3px,
    rgba(0,0,0,0.28) 4px);
  mix-blend-mode: multiply;
  animation: roll 8s linear infinite;
}
@keyframes roll { from { background-position: 0 0; } to { background-position: 0 100px; } }

.vignette {
  background: radial-gradient(135% 115% at 50% 42%, rgba(0,0,0,0) 62%, rgba(0,0,0,0.8) 100%);
}
.noise {
  opacity: .045;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: jitter .4s steps(3) infinite;
}
@keyframes jitter {
  0% { transform: translate(0,0); } 33% { transform: translate(-2px,1px); }
  66% { transform: translate(1px,-2px); } 100% { transform: translate(0,0); }
}

#wires {
  position: fixed; inset: 0; z-index: 1; opacity: .42; pointer-events: none;
}

/* ---------- terminal frame ---------- */
.terminal {
  position: relative; z-index: 10;
  height: 100%;
  display: flex; flex-direction: column;
  padding: clamp(14px, 3vw, 34px);                              /* fallback */
  /* clear the notch / home indicator / rounded corners (viewport-fit=cover) */
  padding:
    max(clamp(14px, 3vw, 34px), env(safe-area-inset-top, 0px))
    max(clamp(14px, 3vw, 34px), env(safe-area-inset-right, 0px))
    max(clamp(14px, 3vw, 34px), env(safe-area-inset-bottom, 0px))
    max(clamp(14px, 3vw, 34px), env(safe-area-inset-left, 0px));
  max-width: 1100px; margin: 0 auto;
}

.bar {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 10px;
  font-size: clamp(10px, 1.4vw, 13px);
  letter-spacing: .12em; color: var(--dim);
  border-bottom: 1px solid var(--wire);
  padding-bottom: 8px;
}
.bar-left { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-right { color: var(--orange-d); white-space: nowrap; flex: none; }

.hero {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; gap: clamp(8px, 2vh, 18px);
  overflow: hidden;
}
.brand {
  display: flex; flex-direction: column; align-items: center;
  gap: clamp(6px, 1.6vh, 16px);
  flex: 0 1 auto; min-height: 0;
}

.orange-art {
  color: var(--orange);
  font-size: clamp(4px, min(1.3vw, 0.92vh), 10px);  /* scales to viewport height too */
  line-height: 1.0;
  letter-spacing: 0;
  text-shadow: 0 0 8px rgba(255,157,47,.5), 0 0 22px rgba(255,157,47,.25);
  filter: drop-shadow(0 6px 18px rgba(255,120,20,.18));
  animation: scanIn .9s steps(40, end) .45s backwards,
             flickerOn 1.0s linear .45s backwards,
             breathe 6s ease-in-out 1.7s infinite;
  user-select: none;
}
.orange-art .leaf {
  color: var(--leaf);
  text-shadow: 0 0 8px rgba(111,156,74,.55), 0 0 18px rgba(111,156,74,.3);
}
@keyframes breathe {
  0%,100% { transform: translateY(0) scale(1); opacity: .95; }
  50%     { transform: translateY(-6px) scale(1.015); opacity: 1; }
}

.wordmark {
  display: flex; flex-direction: column; align-items: center;
  gap: 2px; line-height: 1;
  animation: wmIn .72s steps(2, end) 1.25s backwards;
}
.wordmark .kanji {
  font-family: "Zen Kaku Gothic New", sans-serif;
  font-weight: 500;
  font-size: clamp(28px, min(6.5vw, 7vh), 60px);
  color: var(--orange);
  text-shadow: 0 0 14px rgba(255,157,47,.55), 0 0 40px rgba(255,120,20,.3);
}
.wordmark .latin {
  font-size: clamp(18px, min(4.6vw, 4.6vh), 40px);
  letter-spacing: .42em;
  text-indent: .42em;
  color: var(--ink);
  margin-top: 5px;
}
.wordmark .sub {
  font-size: clamp(9px, 1.6vw, 13px);
  letter-spacing: .55em; text-indent: .55em;
  color: var(--dim);
}

.tagline {
  min-height: 1.4em;
  font-size: clamp(11px, 1.8vw, 15px);
  letter-spacing: .14em;
  color: var(--leaf);
  text-shadow: 0 0 10px rgba(111,156,74,.35);
}
.tagline::after { content: ""; }

/* ---------- chat panel (bounded; transcript scrolls internally) ---------- */
.chat {
  width: min(660px, 94vw);
  flex: 0 1 auto; min-height: 0;
  display: flex; flex-direction: column; gap: 8px;
}

.transcript {
  flex: 1 1 auto;
  height: clamp(100px, 19vh, 190px);
  overflow-y: auto; overscroll-behavior: contain;
  text-align: left;
  font-size: clamp(11px, 1.55vw, 13px);
  line-height: 1.5;
  padding: 10px 12px;
  border: 1px solid var(--wire);
  background: rgba(16,10,6,.42);
  box-shadow: inset 0 0 30px rgba(0,0,0,.55);
  scrollbar-width: thin;
  scrollbar-color: var(--wire) transparent;
}
.transcript::-webkit-scrollbar { width: 7px; }
.transcript::-webkit-scrollbar-thumb { background: var(--wire); }
.transcript::-webkit-scrollbar-track { background: transparent; }

/* one exchange line: [tag] message */
.msg {
  display: flex; gap: 8px; align-items: baseline;
  margin: 0 0 5px; opacity: 0; animation: fadein .3s forwards;
  word-break: break-word;
}
.msg .tag {
  flex: 0 0 auto; min-width: 2.4em; text-align: right;
  font-size: .82em; letter-spacing: .08em; opacity: .9;
  user-select: none;
}
.msg .txt { flex: 1 1 auto; }
.msg.you .tag { color: var(--orange); }
.msg.you .txt { color: var(--ink); }
.msg.bot .tag { color: var(--leaf); }
.msg.bot .txt { color: #e7d6b6; text-shadow: 0 0 8px rgba(231,214,182,.12); }
.msg.sys .tag, .msg.sys .txt { color: var(--dim); }
.msg.err .tag { color: #d8643c; }
.msg.err .txt { color: #d8643c; }
.msg .caret { color: var(--leaf); animation: blink 1.05s steps(1) infinite; }
@keyframes fadein { to { opacity: 1; } }

/* ---------- prompt (input row, pinned under the transcript) ---------- */
.prompt {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--wire);
  background: rgba(20,13,7,.55);
  padding: 8px 14px;
  box-shadow: inset 0 0 24px rgba(0,0,0,.6), 0 0 0 1px rgba(255,157,47,.04);
}
.prompt:focus-within { border-color: var(--orange-d); box-shadow: inset 0 0 24px rgba(0,0,0,.6), 0 0 18px rgba(255,157,47,.12); }
.prompt-sym { color: var(--orange); }
#cmd {
  flex: 1; background: transparent; border: 0; outline: 0;
  color: var(--ink); font-family: inherit; font-size: 16px;  /* >=16px avoids iOS focus-zoom */
  letter-spacing: .08em; min-width: 0;
}
#cmd::placeholder { color: var(--dim); }
.cursor { color: var(--orange); animation: blink 1.05s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- footer ---------- */
.meta {
  display: flex; gap: 12px; justify-content: center; align-items: center;
  flex-wrap: wrap;
  font-size: clamp(9px, 1.3vw, 12px);
  letter-spacing: .16em; color: var(--dim);
  border-top: 1px solid var(--wire);
  padding-top: 10px;
}
.meta .dot { color: var(--wire); }
#node { color: var(--orange-d); }

/* glitch hook */
.glitch { animation: glitch .35s steps(2) 2; }
@keyframes glitch {
  0% { transform: translate(0,0); filter: hue-rotate(0); }
  25%{ transform: translate(-3px,1px); filter: hue-rotate(25deg); }
  50%{ transform: translate(2px,-2px); }
  75%{ transform: translate(-1px,2px); filter: hue-rotate(-20deg); }
  100%{ transform: translate(0,0); }
}

/* ---------- retro boot sequence ---------- */
#boot {
  position: fixed; inset: 0; z-index: 49; pointer-events: none;
  background: #000;
  animation: bootScreen .76s ease-out forwards;
}
#boot .crt-on {
  position: absolute; inset: 0; background: #ffe9c0;
  transform-origin: center center;
  box-shadow: 0 0 60px rgba(255,210,140,.9);
  animation: crtOn .76s cubic-bezier(.6,0,.2,1) forwards;
}
@keyframes bootScreen {            /* black masks the page, then clears to reveal it */
  0%, 52% { background: #000; }
  53%, 100% { background: transparent; }
}
@keyframes crtOn {                 /* dot -> horizontal line -> full flash -> fade */
  0%   { transform: scaleX(.015) scaleY(.003); opacity: 1; }
  18%  { transform: scaleX(1)    scaleY(.003); opacity: 1; }
  36%  { transform: scaleX(1)    scaleY(1);    opacity: 1; }
  52%  { transform: scaleX(1)    scaleY(1);    opacity: .9; }
  100% { transform: scaleX(1)    scaleY(1);    opacity: 0; }
}

/* logo rasters in top-to-bottom, with a power-on flicker */
@keyframes scanIn {
  0%   { clip-path: inset(0 0 100% 0); }
  100% { clip-path: inset(0 0 0 0); }
}
@keyframes flickerOn {
  0%   { opacity: .12; }
  20%  { opacity: .9; }
  28%  { opacity: .35; }
  40%  { opacity: 1; }
  55%  { opacity: .55; }
  70%  { opacity: 1; }
  82%  { opacity: .8; }
  100% { opacity: 1; }
}

/* wordmark slams in with a brief RGB-split glitch */
@keyframes wmIn {
  0%   { opacity: 0; transform: translateX(-7px) skewX(12deg); filter: blur(1.5px); }
  25%  { opacity: 1; transform: translateX(6px)  skewX(-9deg);
         text-shadow: -4px 0 #2fd4d4, 4px 0 #ff5630; }
  50%  { transform: translateX(-4px) skewX(5deg);
         text-shadow: 4px 0 #2fd4d4, -4px 0 #ff5630; }
  75%  { transform: translateX(2px)  skewX(-2deg); }
  100% { opacity: 1; transform: none; filter: none; }
}

/* the rest of the HUD powers in once the logo is up */
.bar      { animation: hudIn .55s ease-out 1.95s backwards; }
.tagline  { animation: hudIn .55s ease-out 2.10s backwards; }
.chat     { animation: hudIn .55s ease-out 2.30s backwards; }
.meta     { animation: hudIn .55s ease-out 2.45s backwards; }
#wires    { animation: wiresIn 1.3s ease-out 1.7s backwards; }
@keyframes hudIn   { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: none; } }
@keyframes wiresIn { from { opacity: 0; } to { opacity: .42; } }

@media (prefers-reduced-motion: reduce) {
  .scanlines, .noise, .orange-art, .cursor { animation: none; }
  #boot { display: none; }
  .orange-art, .wordmark, .bar, .tagline, .chat, .meta {
    animation: none !important; opacity: 1 !important;
    clip-path: none !important; transform: none !important;
  }
  #wires { animation: none !important; opacity: .42 !important; }
}

/* ───────── responsive: narrow / vertical mobile ───────── */
@media (max-width: 560px) {
  .terminal {
    padding: 12px 14px;                                         /* fallback */
    padding:
      max(12px, env(safe-area-inset-top, 0px))
      max(14px, env(safe-area-inset-right, 0px))
      max(12px, env(safe-area-inset-bottom, 0px))
      max(14px, env(safe-area-inset-left, 0px));
  }
  .bar { font-size: 10px; letter-spacing: .05em; gap: 8px; }
  .bar-verbose { display: none; }          /* drop "// CONNECTION ESTABLISHED" */
  .sec { display: none; }                  /* drop the :SS so the clock fits */
  .hero { gap: clamp(8px, 2.2vh, 16px); }
  .chat { width: 100%; }
  .orange-art { font-size: clamp(5px, min(2.3vw, 0.95vh), 10px); } /* use more width on phones */
  .transcript { font-size: 12px; line-height: 1.45; padding: 9px 10px; }
  .msg { gap: 7px; }
  .msg .tag { min-width: 1.8em; }
  .meta { gap: 5px 10px; font-size: 10px; letter-spacing: .06em; }
  .meta .dot { display: none; }            /* gaps replace the · separators when wrapping */
}

/* ───────── responsive: short viewports (small phones, landscape) ───────── */
@media (max-height: 680px) {
  .hero { gap: clamp(6px, 1.6vh, 12px); }
  .transcript { height: clamp(90px, 16vh, 150px); }
}
@media (max-height: 560px) {
  .tagline { display: none; }              /* reclaim a line when truly short */
  .transcript { height: clamp(78px, 26vh, 130px); }
}
