:root {
  --bg: #050a06;
  --panel: rgba(6, 16, 9, 0.74);
  --line: rgba(140, 255, 74, 0.16);
  --text: #eef5ea;
  --dim: #7fa58a;
  --accent: #8cff4a;
  --yellow: #ffe04a;
  --mag: #ff5ea8;
  --cyan: #35d8ff;
  --rainbow: linear-gradient(90deg, #ff5ea8, #ff8a29, #ffe04a, #8cff4a, #35d8ff, #4a8cff, #a46bff);
  --font: "JetBrains Mono", ui-monospace, Menlo, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: 12px;
}

#video { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
#gl, #overlay { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }
#overlay { pointer-events: none; }

/* ---------- TD chrome ---------- */
#titlebar {
  position: fixed; top: 0; left: 0; right: 0; height: 28px;
  display: flex; align-items: center; gap: 14px; padding: 0 12px;
  background: linear-gradient(#1b1b22, #121218); border-bottom: 1px solid #000;
  font-size: 11px; color: var(--dim); z-index: 5;
}
#titlebar .dots { display: flex; gap: 6px; }
#titlebar .dots i { width: 10px; height: 10px; border-radius: 50%; background: #ff5f57; display: block; }
#titlebar .dots i:nth-child(2) { background: #febc2e; }
#titlebar .dots i:nth-child(3) { background: #28c840; }
#titlebar .path b { color: var(--text); font-weight: 500; }
#titlebar .stats { margin-left: auto; display: flex; gap: 16px; }
#titlebar .stats b { color: var(--accent); font-weight: 500; }

#network {
  position: fixed; left: 12px; top: 44px; z-index: 4;
  display: flex; flex-direction: column; align-items: flex-start;
  padding: 10px; background: var(--panel); border: 1px solid var(--line);
  backdrop-filter: blur(6px);
}
.op {
  font-size: 11px; padding: 5px 8px; min-width: 150px;
  background: #23232c; border: 1px solid #3a3a48; border-left: 3px solid #6b6bff;
}
.op em { font-style: normal; color: var(--dim); font-size: 9px; margin-right: 6px; }
.op[data-k="hand"] { border-left-color: var(--yellow); }
.op[data-k="fb"] { border-left-color: var(--mag); }
.op.hot { border-left-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.op.pulse { animation: pulse 0.35s ease-out; }
@keyframes pulse { from { background: var(--accent); color: #000; } to { background: #23232c; } }
.wire { width: 2px; height: 10px; margin-left: 20px; background: linear-gradient(var(--accent), transparent); background-size: 100% 6px; animation: flow 0.6s linear infinite; }
@keyframes flow { to { background-position: 0 6px; } }
.params { margin-top: 10px; font-size: 10px; color: var(--dim); display: grid; grid-template-columns: 1fr 1fr; gap: 2px 14px; }
.params b { color: var(--text); font-weight: 500; }

#legend {
  position: fixed; right: 12px; top: 44px; z-index: 4; width: 230px;
  padding: 10px 12px; background: var(--panel); border: 1px solid var(--line);
  font-size: 11px; line-height: 1.75; color: var(--dim); backdrop-filter: blur(6px);
}
#legend h3 { margin: 0 0 2px; font-size: 10px; color: var(--yellow); font-weight: 500; letter-spacing: 0.08em; }
#legend h3:not(:first-child) { margin-top: 8px; }
#legend span { display: inline-block; min-width: 52px; color: var(--text); }

#fxbar {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 4;
  display: flex; gap: 4px; padding: 4px; background: var(--panel); border: 1px solid var(--line);
  backdrop-filter: blur(6px); max-width: calc(100vw - 32px); overflow-x: auto;
}
#fxbar button {
  font: inherit; font-size: 11px; color: var(--dim); background: transparent;
  border: 1px solid transparent; padding: 7px 10px; cursor: pointer; white-space: nowrap;
}
#fxbar button i { font-style: normal; opacity: 0.5; margin-right: 6px; }
#fxbar button:hover { color: var(--text); border-color: var(--line); }
#fxbar button.on { color: #000; background: var(--c, var(--accent)); }

#toggles { position: fixed; right: 12px; bottom: 16px; z-index: 4; display: flex; flex-direction: column; gap: 4px; }
#toggles button {
  font: inherit; font-size: 11px; color: var(--dim); background: var(--panel); border: 1px solid var(--line);
  padding: 7px 12px; cursor: pointer; text-align: left; backdrop-filter: blur(6px);
}
#toggles button.on { color: var(--accent); border-color: var(--accent); }
#toggles button.shoot { color: #000; background: var(--mag); border-color: var(--mag); }
#toggles button.shoot:hover { background: var(--rainbow); }
#toggles button b { color: var(--yellow); font-weight: 500; }

#flash { position: fixed; inset: 0; background: linear-gradient(160deg, #fff 40%, #ffd1e6 70%, #c9f4ff); opacity: 0; pointer-events: none; z-index: 6; }
#flash.go { animation: flash 0.45s ease-out; }
@keyframes flash { from { opacity: 0.9; } to { opacity: 0; } }

/* ---------- strip tray ---------- */
#tray {
  position: fixed; top: 0; right: 0; bottom: 0; width: 300px; z-index: 7;
  background: rgba(8, 8, 12, 0.94); border-left: 1px solid var(--line);
  display: flex; flex-direction: column; transition: transform 0.35s cubic-bezier(.2,.8,.2,1);
}
#tray.hidden { transform: translateX(105%); }
#tray header { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; color: var(--yellow); border-bottom: 1px solid var(--line); }
#tray header button { font: inherit; background: none; border: 0; color: var(--dim); cursor: pointer; font-size: 14px; }
#strips { overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 16px; }
#strips .strip { display: flex; flex-direction: column; gap: 6px; animation: develop 1.2s ease-out; }
@keyframes develop { from { filter: brightness(3) saturate(0) blur(4px); transform: translateY(-20px); } to { filter: none; transform: none; } }
#strips img { width: 100%; display: block; border: 1px solid var(--line); }
#strips a { color: var(--accent); text-decoration: none; font-size: 11px; }
#strips .empty { color: var(--dim); }

/* ---------- intro / loader ---------- */
#intro { position: fixed; inset: 0; z-index: 10; background: #000; display: grid; place-items: center; }
#intro-fx { position: absolute; inset: 0; width: 100%; height: 100%; }
#intro::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(0,0,0,0.35) 0 1px, transparent 1px 3px);
}
#intro .load { position: relative; z-index: 1; width: min(560px, calc(100vw - 32px)); text-align: left; mix-blend-mode: difference; }
#intro .bar { height: 2px; background: rgba(255,255,255,0.15); margin-top: 18px; overflow: hidden; }
#intro .bar i { display: block; height: 100%; background: #fff; transform-origin: left; transform: scaleX(0); }
#intro .meta { display: flex; justify-content: space-between; margin-top: 10px; font-size: 11px; letter-spacing: 0.3em; color: #fff; }
#intro .meta b { font-weight: 800; font-size: 13px; }
#intro.err .meta { color: #ff5f7a; mix-blend-mode: normal; }
#intro .prompt { margin-top: 18px; font-size: 11px; letter-spacing: 0.3em; color: #fff; animation: blink 1s step-end infinite; }
#intro.started .prompt { visibility: hidden; }
@keyframes blink { 50% { opacity: 0; } }
#intro.exit { animation: introOut 0.65s steps(6) forwards; }
@keyframes introOut {
  0% { filter: none; transform: none; }
  30% { filter: invert(1) hue-rotate(90deg); transform: translateX(-14px) skewX(-6deg); }
  60% { filter: saturate(6) contrast(3); transform: translateX(20px) scaleY(1.04); clip-path: inset(10% 0 30% 0); }
  100% { opacity: 0; transform: scaleY(0.02); clip-path: inset(48% 0 48% 0); }
}
#intro.gone { opacity: 0; pointer-events: none; }
.glitch {
  position: relative; margin: 0; font-size: clamp(40px, 10vw, 96px); font-weight: 800; letter-spacing: -0.05em; line-height: 0.9;
  color: #fff;
}
.glitch::before, .glitch::after { content: attr(data-text); position: absolute; inset: 0; overflow: hidden; }
.glitch::before { color: #45f0ff; transform: translate(-3px, 0); mix-blend-mode: screen; animation: g1 2.4s infinite steps(1); }
.glitch::after { color: #ff3fd8; transform: translate(3px, 0); mix-blend-mode: screen; animation: g2 1.9s infinite steps(1); }
@keyframes g1 {
  0% { clip-path: inset(10% 0 70% 0); } 20% { clip-path: inset(60% 0 10% 0); transform: translate(-8px,0); }
  40% { clip-path: inset(40% 0 40% 0); } 60% { clip-path: inset(80% 0 2% 0); transform: translate(5px,0); }
  80% { clip-path: inset(5% 0 85% 0); } 100% { clip-path: inset(50% 0 30% 0); }
}
@keyframes g2 {
  0% { clip-path: inset(70% 0 5% 0); } 25% { clip-path: inset(20% 0 60% 0); transform: translate(9px,0); }
  50% { clip-path: inset(45% 0 35% 0); } 75% { clip-path: inset(2% 0 90% 0); transform: translate(-4px,0); }
  100% { clip-path: inset(85% 0 0 0); }
}

@media (max-width: 760px) {
  #network, #legend { display: none; }
  #titlebar .path { display: none; }
  #fxbar { bottom: 70px; }
  #toggles { flex-direction: row; left: 12px; right: 12px; justify-content: center; flex-wrap: wrap; }
}
