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

:root {
  --bg: #251c40;
  --panel: #322659;
  --line: #4d3d85;
  --text: #f4f1ff;
  --dim: #b4aad8;
  --w-agents: #b9a6ff;
  --w-agents-bg: #2a2054;
  --w-motion: #7fe8c5;
  --w-motion-bg: #123a2e;
  --w-image: #e8a6f0;
  --w-image-bg: #3a1f42;
  --w-platforms: #d4ff3f;
  --w-platforms-bg: #2e3a10;
  --gold: #d9ff4f;
  --bad: #ff6b8a;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Press Start 2P', monospace;
  min-height: 100vh;
  image-rendering: pixelated;
}

.scene { display: none; min-height: 100vh; }
.scene.active { display: flex; flex-direction: column; align-items: center; justify-content: center; }

.crt {
  text-align: center;
  padding: 48px 32px;
  border: 4px solid var(--line);
  background: var(--panel);
  box-shadow: 0 0 0 4px var(--bg), 0 0 0 8px var(--line);
  max-width: 640px;
}

h1.glitch { font-size: 42px; line-height: 1.4; color: var(--text); text-shadow: 3px 3px 0 #6b4fd8; }
.sub { margin-top: 20px; font-size: 11px; color: var(--dim); letter-spacing: 2px; }
.story { margin-top: 28px; font-size: 11px; line-height: 2; color: var(--dim); }
.hint { margin-top: 18px; font-size: 9px; color: var(--dim); }

.pixel-btn {
  font-family: inherit; font-size: 13px; cursor: pointer;
  background: var(--text); color: var(--bg);
  border: none; padding: 14px 24px; margin-top: 28px;
  box-shadow: 4px 4px 0 #6b4fd8;
  display: inline-block; text-decoration: none;
}
.pixel-btn:hover { transform: translate(-2px,-2px); box-shadow: 6px 6px 0 #6b4fd8; }
.pixel-btn:active { transform: translate(2px,2px); box-shadow: 1px 1px 0 #6b4fd8; }
.pixel-btn.big { font-size: 16px; padding: 18px 36px; animation: blink 1.4s steps(2) infinite; }
.pixel-btn.small { font-size: 10px; padding: 8px 14px; margin: 0; box-shadow: 3px 3px 0 var(--line); }
.gold-btn { background: var(--gold); box-shadow: 4px 4px 0 #5c6e14; }

@keyframes blink { 50% { opacity: 0.55; } }

.grid-head {
  width: 100%; max-width: 960px; display: flex; justify-content: space-between; align-items: center;
  padding: 24px 16px 8px;
}
.logo { font-size: 12px; color: var(--dim); }
.hud { font-size: 11px; color: var(--gold); }

.welcome { font-size: 13px; color: var(--gold); margin: 14px 0 4px; text-align: center; letter-spacing: 1px; line-height: 1.8; text-shadow: 2px 2px 0 #5c6e14; }
.name-input { letter-spacing: 2px; text-transform: none; }

.badges { display: flex; gap: 10px; margin: 8px 0 4px; min-height: 22px; }
.badge { font-size: 9px; padding: 5px 9px; border: 2px solid; }

.grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px;
  width: 100%; max-width: 960px; padding: 16px;
}

.tile {
  position: relative; cursor: pointer; text-align: left;
  border: 3px solid var(--line); background: var(--panel);
  padding: 16px 12px; min-height: 130px;
  display: flex; flex-direction: column; justify-content: space-between;
  font-family: inherit; color: var(--text);
  transition: transform 0.08s steps(2);
  box-shadow: 0 0 10px rgba(212,255,63,0.22), 0 0 3px rgba(212,255,63,0.35);
}
.tile:hover { transform: translateY(-3px); box-shadow: 0 0 16px rgba(212,255,63,0.45), 0 0 4px rgba(212,255,63,0.6); }
.tile .t-name { font-size: 10px; line-height: 1.7; }
.tile .t-meta { font-size: 8px; color: var(--dim); display: flex; gap: 8px; margin-top: 10px; }
.tile .t-stars { font-size: 9px; margin-top: 6px; height: 12px; }
.t-logo {
  position: absolute; right: 10px; top: 22px; width: 32px; height: 32px;
  object-fit: contain; image-rendering: pixelated;
}
.tile.off .t-logo { filter: grayscale(1) brightness(0.7); opacity: 0.55; }
.tile.lit .t-logo { filter: none; opacity: 1; }
.tile .t-name { padding-right: 40px; }

.tile.lit { background: var(--tile-bg); border-color: var(--tile-c); }
.tile.lit .t-name { color: var(--tile-c); }
.tile.lit::after { content: "ON AIR"; position: absolute; top: 6px; right: 6px; font-size: 7px; color: var(--tile-c); animation: blink 2s steps(2) infinite; }
.tile.off { opacity: 0.85; }
.tile.off::after { content: "static"; position: absolute; top: 6px; right: 6px; font-size: 7px; color: var(--dim); }

.grid-foot { font-size: 9px; color: var(--dim); padding: 10px 0 30px; }

.level-wrap { width: 100%; max-width: 720px; padding: 28px 16px 60px; }
#level-head { margin-top: 22px; }
#level-head .lv-world { font-size: 9px; letter-spacing: 1px; }
#level-head .lv-name { font-size: 18px; margin-top: 10px; line-height: 1.6; }
.operator {
  margin: 22px 0; padding: 14px 16px; font-size: 11px; line-height: 1.9; color: var(--gold);
  border-left: 4px solid var(--gold); background: var(--panel);
}
.operator::before { content: "OPERATOR // "; color: var(--dim); font-size: 9px; }

.stage { margin-top: 18px; }
.hidden { display: none !important; }

.video-facade {
  position: relative; cursor: pointer; margin: 0 auto;
  width: 300px; height: 533px; border: 3px solid var(--line); background: #000;
}
.video-facade img { width: 100%; height: 100%; object-fit: cover; opacity: 0.8; }
.video-facade .playbtn {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 40px; color: var(--text); text-shadow: 3px 3px 0 #000;
}
.video-facade .vf-label { position: absolute; bottom: 10px; left: 0; right: 0; text-align: center; font-size: 9px; color: var(--gold); text-shadow: 2px 2px 0 #000; }
#yt-frame { width: 300px; height: 533px; border: 3px solid var(--line); display: block; margin: 0 auto; }
.video-done { text-align: center; font-size: 10px; color: var(--w-platforms); margin-top: 12px; }
.skip-row { text-align: center; margin-top: 14px; }
.skip { font-size: 9px; color: var(--dim); cursor: pointer; background: none; border: none; font-family: inherit; text-decoration: underline; }

.quiz-q { font-size: 12px; line-height: 1.9; margin: 24px 0 16px; }
.quiz-answers { display: flex; flex-direction: column; gap: 10px; }
.quiz-a {
  font-family: inherit; font-size: 10px; line-height: 1.7; text-align: left; cursor: pointer;
  background: var(--panel); color: var(--text); border: 3px solid var(--line); padding: 12px 14px;
}
.quiz-a:hover { border-color: var(--dim); }
.quiz-a.correct { border-color: var(--w-platforms); color: var(--w-platforms); animation: flash 0.4s steps(3); }
.quiz-a.wrong { border-color: var(--bad); color: var(--bad); animation: shake 0.3s steps(4); }
@keyframes flash { 50% { background: #2e3a10; } }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
.quiz-progress { font-size: 9px; color: var(--dim); margin-top: 20px; }

.end-crt { max-width: 560px; }
.restored { font-size: 24px; color: var(--w-platforms); text-shadow: 3px 3px 0 #2e3a10; line-height: 1.5; }
.restored.gold { color: var(--gold); text-shadow: 3px 3px 0 #5c6e14; }
#end-stats { margin: 20px 0; font-size: 13px; line-height: 2.2; }
#end-stats .stars { font-size: 22px; color: var(--gold); letter-spacing: 6px; }
#end-cta { margin-top: 8px; }
#end-cta .create-btn { background: var(--gold); box-shadow: 4px 4px 0 #5c6e14; font-size: 12px; }
#end-cta .coupon { margin-top: 14px; font-size: 10px; color: var(--gold); border: 2px dashed var(--gold); padding: 10px; display: inline-block; }
#end-cta .no-aff { margin-top: 10px; font-size: 10px; color: var(--dim); line-height: 1.9; }

.overlay {
  position: fixed; inset: 0; background: rgba(4,4,10,0.92);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
#gate { background: var(--bg); z-index: 200; }
.gate-input {
  font-family: inherit; font-size: 14px; text-align: center; letter-spacing: 4px;
  background: var(--bg); color: var(--gold); border: 3px solid var(--line);
  padding: 12px; margin-top: 20px; width: 240px; text-transform: uppercase;
}
.gate-input:focus { outline: none; border-color: var(--gold); }

.scanlines {
  position: fixed; inset: 0; pointer-events: none; z-index: 100;
  background: repeating-linear-gradient(0deg, rgba(0,0,0,0.18) 0px, rgba(0,0,0,0.18) 1px, transparent 1px, transparent 4px);
}

body.shake { animation: bodyshake 0.3s steps(6); }
@keyframes bodyshake {
  20% { transform: translate(-6px, 2px); }
  40% { transform: translate(5px, -3px); }
  60% { transform: translate(-4px, -2px); }
  80% { transform: translate(3px, 2px); }
}

.tile { animation: bootin 0.3s steps(4) backwards; }
@keyframes bootin { from { opacity: 0; transform: translateY(10px); } }

.tile.off .t-name { animation: staticflicker 4s steps(2) infinite; }
@keyframes staticflicker {
  92% { opacity: 1; }
  94% { opacity: 0.4; }
  96% { opacity: 1; }
  98% { opacity: 0.6; }
}

.tile.lit { animation: none; }
.tile.just-lit { animation: lightup 0.9s steps(6); }
@keyframes lightup {
  0% { background: var(--panel); border-color: var(--tile-c); transform: scale(1); }
  30% { background: var(--tile-c); transform: scale(1.06); }
  60% { background: var(--tile-bg); transform: scale(0.98); }
  100% { transform: scale(1); }
}

.combo { min-height: 26px; margin-top: 14px; text-align: center; }
.combo.pop { color: var(--gold); font-size: 16px; animation: combopop 0.5s steps(4); }
@keyframes combopop { 0% { transform: scale(0.3); } 60% { transform: scale(1.3); } 100% { transform: scale(1); } }

#runner {
  display: block; margin: 0 auto; width: 100%; max-width: 640px;
  border: 3px solid var(--line); image-rendering: pixelated;
  touch-action: manipulation;
}
#runner.shake { animation: bodyshake 0.25s steps(5); }
.runner-hud {
  display: flex; justify-content: space-between; max-width: 640px; margin: 0 auto 8px;
  font-size: 11px; color: var(--gold);
}
.runner-help { text-align: center; font-size: 9px; color: var(--dim); margin-top: 12px; line-height: 1.8; }
.runner-fail { text-align: center; padding: 30px 0; }

.tip {
  display: inline-block; position: relative; z-index: 30;
  background: var(--gold); color: #241b4a;
  font-size: 9px; line-height: 1.6; padding: 8px 12px;
  border: 3px solid #241b4a; box-shadow: 3px 3px 0 #241b4a;
  animation: tipbounce 0.9s steps(2) infinite;
  white-space: nowrap;
}
@keyframes tipbounce { 50% { transform: translateY(-5px); } }
.tip-down::after, .tip-up::before {
  content: ""; position: absolute; left: 50%; margin-left: -7px;
  border-left: 7px solid transparent; border-right: 7px solid transparent;
}
.tip-down::after { top: 100%; border-top: 8px solid #241b4a; }
.tip-up::before { bottom: 100%; border-bottom: 8px solid #241b4a; }
.tip-row { text-align: center; margin: 10px 0; }
.tip-abs {
  position: absolute; top: -20px; left: 50%; transform: translateX(-50%);
  animation: tipbounceabs 0.9s steps(2) infinite;
}
@keyframes tipbounceabs { 50% { transform: translateX(-50%) translateY(-5px); } }
.grid-head { position: relative; }
.tip-allin { position: absolute; top: 54px; right: 90px; }

.scene.allin { background: #f4f0ff; color: #241b4a; }
.allin-wrap { width: 100%; max-width: 720px; padding: 32px 16px 48px; text-align: center; }
.enlight-title {
  font-size: 24px; color: #241b4a; margin-top: 24px; line-height: 1.5;
  text-shadow: 3px 3px 0 #d9ff4f;
}
.enlight-sub { font-size: 10px; color: #6a5fa0; line-height: 2; margin-top: 16px; }
.allin-stage { position: relative; height: 160px; margin: 10px 0 6px; overflow: hidden; }
#obd-sprite {
  position: absolute; bottom: 14px; left: -80px; width: 112px; height: auto;
  image-rendering: pixelated;
}
.allin-ground { position: absolute; bottom: 0; left: 0; right: 0; height: 10px; background: #ded4ff; }
.allin-row {
  display: flex; gap: 24px; justify-content: center; align-items: stretch;
  flex-wrap: wrap; margin: 18px 0 26px;
}
.qr-card {
  background: #ffffff; border: 4px solid #241b4a; padding: 14px;
  box-shadow: 6px 6px 0 #d9ff4f;
}
.qr-card img { width: 170px; height: 170px; image-rendering: pixelated; display: block; }
.qr-card p { font-size: 9px; color: #241b4a; margin-top: 10px; line-height: 1.8; }
.course-box {
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  padding: 14px 20px; border: 4px dashed #b9a6ff;
}
.course-kicker { font-size: 9px; color: #6a5fa0; letter-spacing: 2px; }
.course-title { font-size: 16px; color: #241b4a; margin: 12px 0 4px; line-height: 1.6; }
.allin-btn {
  background: #d9ff4f; color: #241b4a; font-size: 18px; padding: 18px 42px;
  box-shadow: 5px 5px 0 #241b4a; margin-top: 16px; cursor: default;
  animation: allinpulse 1.6s steps(2) infinite;
}
@keyframes allinpulse { 50% { box-shadow: 8px 8px 0 #241b4a; transform: translate(-2px,-2px); } }
.course-note { font-size: 8px; color: #6a5fa0; margin-top: 12px; }
.dark-btn { background: #241b4a; color: #f4f0ff; box-shadow: 3px 3px 0 #b9a6ff; }
.allin-badge { background: var(--gold); color: #241b4a; box-shadow: 3px 3px 0 #5c6e14; animation: blink 2s steps(2) infinite; }

@media (max-width: 760px) {
  .grid { grid-template-columns: repeat(2, 1fr); }
  h1.glitch { font-size: 26px; }
}

@media (prefers-reduced-motion: reduce) {
  .tile, .tip, .tip-abs, .pixel-btn.big, .allin-btn { animation: none !important; }
}
