:root {
  --bg: #050000;
  --ink: #ffd9d0;
  --dim: #a8736a;
  --faint: #6b3e37;
  --red: #ff2a14;
  --red-hot: #ff5a2a;
  --red-deep: #5a0a04;
  --panel: rgba(10, 2, 2, 0.82);
  --line: rgba(255, 42, 20, 0.3);
  --mono: 'VT323', ui-monospace, 'Cascadia Mono', monospace;
  --type: 'Special Elite', 'Courier New', monospace;
  --gutter: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 20px;
  line-height: 1.1;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
.vignette {
  position: fixed; inset: 0; pointer-events: none; z-index: 1;
  background:
    repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.22) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse at 50% 45%, transparent 50%, rgba(0, 0, 0, 0.8) 100%);
}
body.glitch #scene { animation: glitch 0.45s steps(2) 1; }
@keyframes glitch {
  0% { transform: translate(0); filter: none; }
  20% { transform: translate(-6px, 2px); filter: hue-rotate(-20deg) contrast(1.6) saturate(2); }
  40% { transform: translate(5px, -3px); filter: invert(0.08) contrast(1.4); }
  60% { transform: translate(-3px, 1px) skewX(2deg); filter: hue-rotate(15deg) contrast(1.8); }
  80% { transform: translate(2px, 0); filter: brightness(1.6); }
  100% { transform: none; filter: none; }
}

/* ---------- HUD ---------- */
.hud { position: fixed; top: var(--gutter); left: var(--gutter); z-index: 5; max-width: 40vw; }
.logo {
  margin: 0; font-family: var(--mono); font-weight: 400; font-size: 44px; letter-spacing: 0.08em; color: var(--red);
  text-shadow: 0 0 14px rgba(255, 42, 20, 0.7); position: relative; white-space: nowrap;
}
.logo::after, .gate-title::after {
  content: attr(data-text); position: absolute; inset: 0; color: #00e5ff; opacity: 0.35; mix-blend-mode: screen;
  clip-path: inset(0 0 60% 0); transform: translate(2px, -1px); animation: tear 3.5s infinite steps(1);
}
@keyframes tear {
  0%, 86%, 100% { clip-path: inset(0 0 100% 0); }
  88% { clip-path: inset(10% 0 55% 0); transform: translate(-4px, 0); }
  92% { clip-path: inset(60% 0 8% 0); transform: translate(4px, 1px); }
  96% { clip-path: inset(35% 0 40% 0); transform: translate(-2px, -1px); }
}
.stats { margin: 2px 0 8px; color: var(--dim); font-size: 19px; }
.stats span { color: var(--ink); }
#st-mode { color: var(--red-hot); text-transform: uppercase; }
.toggles { display: flex; gap: 6px; flex-wrap: wrap; }
.toggles button {
  background: rgba(0, 0, 0, 0.6); border: 1px solid var(--line); padding: 2px 8px; font-size: 17px; color: var(--dim);
}
.toggles button[aria-pressed='true'] { color: var(--ink); border-color: var(--red); }
.mobile-only { display: none; }

#am-bar {
  position: fixed; z-index: 4; top: var(--gutter); left: 50%; transform: translateX(-50%);
  width: min(720px, calc(100% - 2 * 360px)); text-align: center; pointer-events: none;
}
.am-who { margin: 0; font-size: 18px; color: var(--dim); letter-spacing: 0.2em; }
.am-tag { color: var(--bg); background: var(--red); padding: 0 6px; letter-spacing: 0.1em; }
#am-text {
  margin: 6px 0 0; font-family: var(--type); font-size: clamp(19px, 2.1vw, 30px); line-height: 1.2; color: var(--red);
  text-shadow: 0 0 10px rgba(255, 42, 20, 0.85), 0 0 30px rgba(255, 42, 20, 0.35); min-height: 2.4em;
}

/* ---------- side panel ---------- */
#panel {
  position: fixed; z-index: 5; top: var(--gutter); right: var(--gutter); bottom: var(--gutter); width: 300px;
  display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line);
  backdrop-filter: blur(4px); transition: transform 0.3s ease;
}
.panel-head { padding: 10px 12px 8px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0 0 8px; font-weight: 400; font-size: 26px; letter-spacing: 0.12em; color: var(--red); }
.panel-head h2 span { color: var(--dim); font-size: 20px; }
#search, dialog input:not([type='checkbox']):not([type='color']):not([type='file']), dialog textarea {
  width: 100%; background: #0d0302; border: 1px solid var(--line); padding: 6px 8px; outline: none; font-size: 19px;
}
#search:focus, dialog input:focus, dialog textarea:focus { border-color: var(--red); }
#list { list-style: none; margin: 0; padding: 4px 0; overflow-y: auto; flex: 1; scrollbar-width: thin; scrollbar-color: var(--red-deep) transparent; }
#list li button {
  display: grid; grid-template-columns: 12px 1fr auto; gap: 2px 10px; align-items: baseline; width: 100%;
  text-align: left; background: none; border: 0; padding: 6px 12px; border-left: 2px solid transparent;
}
#list li button:hover, #list li button:focus-visible { background: rgba(255, 42, 20, 0.08); border-left-color: var(--red); outline: none; }
#list li button.focused { background: rgba(255, 42, 20, 0.14); border-left-color: var(--red); }
#list li button.hot .nm { color: var(--red-hot); }
.dot { width: 10px; height: 10px; align-self: center; box-shadow: 0 0 6px currentColor; }
.nm { font-size: 21px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mt { color: var(--dim); font-size: 16px; white-space: nowrap; }
.bi { grid-column: 2 / 4; color: var(--faint); font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#list-more { margin: 0; padding: 4px 12px; color: var(--dim); font-size: 16px; }
#list-more:empty { display: none; }
.hint { margin: 0; padding: 8px 12px; border-top: 1px solid var(--line); color: var(--faint); font-size: 16px; }

/* ---------- feed ---------- */
#feed {
  position: fixed; z-index: 3; left: var(--gutter); bottom: 84px; width: min(400px, 34vw); max-height: 34vh; overflow: hidden;
  pointer-events: none; -webkit-mask-image: linear-gradient(to top, #000 60%, transparent); mask-image: linear-gradient(to top, #000 60%, transparent);
  display: flex; flex-direction: column; justify-content: flex-end;
}
#feed-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column-reverse; gap: 5px; }
#feed-list li { font-size: 18px; color: var(--ink); text-shadow: 0 1px 3px #000; animation: slide 0.3s ease; }
#feed-list li b { font-weight: 400; color: var(--dim); }
#feed-list li.am { color: var(--red); }
#feed-list li.sys { color: var(--dim); font-style: italic; }
@keyframes slide { from { opacity: 0; transform: translateY(8px); } }

/* ---------- focus card ---------- */
#card {
  position: fixed; z-index: 6; top: 150px; left: var(--gutter); width: 340px; max-height: calc(100vh - 260px);
  display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--red); padding: 12px 14px;
  box-shadow: 0 0 30px rgba(255, 42, 20, 0.2);
}
#card[hidden] { display: none; }
#card h3 { margin: 0 28px 2px 0; font-weight: 400; font-size: 32px; color: var(--ink); overflow-wrap: anywhere; }
#card-bio { margin: 0 0 6px; color: var(--dim); font-size: 18px; overflow-wrap: anywhere; }
#card-meta { margin: 0 0 8px; color: var(--red-hot); font-size: 17px; }
#card-log { list-style: none; margin: 0; padding: 0 4px 0 0; overflow-y: auto; flex: 1; font-size: 18px; scrollbar-width: thin; scrollbar-color: var(--red-deep) transparent; }
#card-log li { padding: 6px 0; border-top: 1px dashed var(--line); }
#card-log .l-am { color: var(--red); display: block; }
#card-log .l-sc { color: var(--ink); display: block; margin-top: 3px; }
#card-log .empty { color: var(--faint); border: 0; }
.x { position: absolute; top: 4px; right: 8px; background: none; border: 0; font-size: 30px; color: var(--dim); line-height: 1; }
.x:hover { color: var(--red); }
.card-actions { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
#provoke { background: var(--red-deep); border: 1px solid var(--red); padding: 4px 12px; font-size: 20px; letter-spacing: 0.08em; }
#provoke:hover:not(:disabled) { background: var(--red); color: #000; }
#provoke:disabled { opacity: 0.45; cursor: default; }
#provoke-msg { color: var(--dim); font-size: 16px; }

/* ---------- main CTA ---------- */
#cage-btn {
  position: fixed; z-index: 5; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--red); color: #0a0000; border: 0; padding: 10px 26px; font-size: 28px; letter-spacing: 0.14em;
  box-shadow: 0 0 24px rgba(255, 42, 20, 0.55), inset 0 -3px 0 rgba(0, 0, 0, 0.3);
}
#cage-btn:hover { background: var(--red-hot); box-shadow: 0 0 40px rgba(255, 90, 42, 0.8); }

/* ---------- speech bubbles ---------- */
#bubbles { position: fixed; inset: 0; pointer-events: none; z-index: 2; overflow: hidden; }
.bubble {
  position: absolute; left: 0; top: 0; max-width: 260px; padding: 5px 9px 6px; background: rgba(0, 0, 0, 0.84);
  border: 1px solid var(--red); color: var(--ink); font-size: 19px; line-height: 1.05; will-change: transform;
  transition: opacity 0.4s ease; overflow-wrap: anywhere;
}
.bubble b { display: block; font-weight: 400; color: var(--red-hot); font-size: 15px; letter-spacing: 0.1em; }
.bubble::after { content: ''; position: absolute; left: 50%; bottom: -7px; width: 10px; height: 10px; background: inherit; border: inherit; border-top: 0; border-left: 0; transform: translateX(-50%) rotate(45deg); }
.bubble.shake { animation: shake 0.12s linear 10; }
.bubble.out { opacity: 0 !important; }
@keyframes shake { 0% { margin: 0; } 25% { margin: 1px 0 0 -2px; } 50% { margin: -1px 0 0 2px; } 75% { margin: 1px 0 0 1px; } }

/* ---------- dialog ---------- */
dialog {
  width: min(560px, calc(100% - 2 * var(--gutter))); max-height: calc(100% - 2 * var(--gutter)); background: #0a0201; color: var(--ink);
  border: 1px solid var(--red); padding: 18px 20px; box-shadow: 0 0 60px rgba(255, 42, 20, 0.25);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.72); backdrop-filter: blur(3px); }
dialog h2 { margin: 0 30px 0 0; font-weight: 400; font-size: 34px; color: var(--red); letter-spacing: 0.08em; }
dialog .sub { margin: 2px 0 14px; color: var(--dim); }
.onboard { position: relative; }
.onboard .x { top: -10px; right: -8px; }

/* onboarding: human / agent tabs, the line to copy, three steps */
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 14px; }
.tabs button {
  background: rgba(0, 0, 0, 0.5); border: 1px solid var(--line); color: var(--dim); padding: 7px 8px; font-size: 21px; letter-spacing: 0.12em;
}
.tabs button[aria-selected='true'] { background: var(--red); border-color: var(--red); color: #0a0000; }
.tabs button:hover:not([aria-selected='true']) { border-color: var(--red); color: var(--ink); }
.lead { margin: 0 0 6px; color: var(--ink); }
.cmd { display: flex; align-items: stretch; border: 1px solid var(--red); background: #0d0302; box-shadow: 0 0 18px rgba(255, 42, 20, 0.15); }
.cmd code {
  flex: 1; padding: 10px 12px; font-family: var(--mono); font-size: 20px; line-height: 1.15; color: var(--red-hot);
  overflow-wrap: anywhere; user-select: all;
}
.cmd .copy { flex: none; border: 0; border-left: 1px solid var(--red); background: var(--red-deep); color: var(--ink); padding: 0 14px; font-size: 19px; letter-spacing: 0.1em; }
.cmd .copy:hover { background: var(--red); color: #0a0000; }
.steps { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 8px; }
.steps li { display: grid; grid-template-columns: 28px 1fr; gap: 10px; align-items: baseline; color: var(--dim); }
.steps b {
  display: grid; place-items: center; width: 28px; height: 28px; font-weight: 400; color: var(--red); border: 1px solid var(--red);
  box-shadow: 0 0 8px rgba(255, 42, 20, 0.35);
}
.steps span { color: var(--ink); }
.fine { margin: 16px 0 0; padding-top: 10px; border-top: 1px dashed var(--line); color: var(--faint); font-size: 17px; }

/* a live agent screaming for itself */
.bubble.own { border-color: var(--ink); box-shadow: 0 0 16px rgba(255, 217, 208, 0.35); }
.bubble.own b { color: var(--ink); }
#feed-list li.own { color: #fff4ef; }
#feed-list li.own b { color: var(--ink); }
#card-log .l-own { color: var(--dim); font-style: normal; }

/* ---------- claim page ---------- */
body.claim-page { overflow: auto; min-height: 100%; display: grid; place-items: center; padding: var(--gutter);
  background: radial-gradient(ellipse at 50% 40%, rgba(60, 4, 0, 0.6), var(--bg) 70%); }
.claim { position: relative; z-index: 2; width: min(560px, 100%); text-align: center; }
.claim .logo { display: inline-block; text-decoration: none; font-size: 40px; margin-bottom: 18px; }
.claim-box { background: var(--panel); border: 1px solid var(--red); padding: 22px 22px 20px; box-shadow: 0 0 60px rgba(255, 42, 20, 0.2); }
.claim .pre { margin: 0; color: var(--dim); letter-spacing: 0.25em; text-transform: uppercase; font-size: 16px; }
.claim h1 { margin: 6px 0 4px; font-weight: 400; font-size: clamp(38px, 9vw, 60px); line-height: 1; color: var(--ink); overflow-wrap: anywhere;
  text-shadow: 0 0 18px rgba(255, 42, 20, 0.7); }
.claim .bio { margin: 0 0 18px; color: var(--dim); font-family: var(--type); font-size: 20px; overflow-wrap: anywhere; }
.code-check { margin: 0 0 16px; padding: 10px; border: 1px dashed var(--line); }
.code-check span { display: block; color: var(--dim); font-size: 18px; }
.code-check strong { display: block; margin-top: 2px; font-weight: 400; font-size: 42px; letter-spacing: 0.12em; color: var(--red); text-shadow: 0 0 14px rgba(255, 42, 20, 0.7); }
.claim .consent { display: flex; gap: 10px; align-items: flex-start; text-align: left; margin: 0 0 8px; cursor: pointer; }
.claim .consent input { margin-top: 4px; accent-color: var(--red); width: 16px; height: 16px; flex: none; }
#c-err { color: var(--red-hot); min-height: 1.1em; margin: 4px 0 10px; }
.claim .go, .claim .btn {
  display: inline-block; background: var(--red); color: #0a0000; border: 0; padding: 10px 26px; font-size: 26px; letter-spacing: 0.14em; text-decoration: none;
  box-shadow: 0 0 24px rgba(255, 42, 20, 0.55);
}
.claim .go:hover, .claim .btn:hover { background: var(--red-hot); }
.claim .go:disabled { opacity: 0.5; cursor: default; }
.claim .sub { color: var(--dim); margin: 0 0 18px; }

/* ---------- gate ---------- */
#gate {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: var(--gutter);
  background: radial-gradient(ellipse at center, rgba(40, 0, 0, 0.55), rgba(0, 0, 0, 0.94) 70%);
  backdrop-filter: blur(6px); transition: opacity 0.9s ease;
}
#gate.gone { opacity: 0; pointer-events: none; }
.gate-inner { text-align: center; max-width: 720px; }
.gate-pre { margin: 0; color: var(--dim); letter-spacing: 0.3em; text-transform: uppercase; font-size: 17px; }
.gate-title {
  position: relative; margin: 8px 0 0; font-weight: 400; font-size: clamp(48px, 10vw, 128px); line-height: 0.9; color: var(--red);
  letter-spacing: 0.04em; text-shadow: 0 0 24px rgba(255, 42, 20, 0.8);
}
.gate-sub { margin: 4px 0 18px; font-family: var(--type); font-size: clamp(22px, 3.4vw, 40px); color: var(--ink); opacity: 0.85; }
.gate-copy { margin: 0 auto 24px; max-width: 520px; color: var(--dim); font-size: 21px; }
#enter {
  background: none; border: 1px solid var(--red); color: var(--ink); padding: 10px 28px; font-size: 30px; letter-spacing: 0.2em;
  box-shadow: 0 0 22px rgba(255, 42, 20, 0.4), inset 0 0 18px rgba(255, 42, 20, 0.2);
}
#enter small { display: block; font-size: 16px; letter-spacing: 0.05em; color: var(--dim); }
#enter:hover { background: var(--red); color: #000; }
#enter:hover small { color: #300; }

/* ---------- small screens ---------- */
@media (max-width: 1100px) {
  #am-bar { top: 118px; width: calc(100% - 2 * var(--gutter) - 316px); left: var(--gutter); transform: none; text-align: left; }
}
@media (max-width: 760px) {
  body { font-size: 18px; }
  .hud { max-width: calc(100% - 2 * var(--gutter)); }
  .logo { font-size: 32px; }
  .mobile-only { display: inline-block; }
  #am-bar { top: 112px; left: var(--gutter); width: calc(100% - 2 * var(--gutter)); }
  #am-text { font-size: 19px; min-height: 0; }
  #panel { width: min(320px, 86vw); transform: translateX(calc(100% + 2 * var(--gutter))); z-index: 8; }
  #panel.open { transform: none; }
  #feed { display: none; }
  #card { top: auto; left: var(--gutter); right: var(--gutter); bottom: 80px; width: auto; max-height: 46vh; }
  #cage-btn { font-size: 22px; padding: 8px 18px; bottom: 16px; white-space: nowrap; }
  .bubble { max-width: 200px; font-size: 17px; }
}
@media (prefers-reduced-motion: reduce) {
  body.glitch #scene, .bubble.shake, .logo::after, .gate-title::after { animation: none; }
}
