:root {
  --bg: #0a0b10;
  --panel: rgba(18, 22, 31, 0.85);
  --line: #1c2230;
  --text: #e6e9ef;
  --muted: #8a93a6;
  --accent: #3ee6c1;
  --accent-2: #7c5cff;
  --hot: #ff4d6d;
  --gold: #ffd166;
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Code", Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ---------- Background: editor viewport grid + CRT scanlines ---------- */
.grid-bg {
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(ellipse at 50% -10%, rgba(124, 92, 255, 0.25), transparent 60%),
    radial-gradient(ellipse at 100% 100%, rgba(62, 230, 193, 0.10), transparent 50%),
    linear-gradient(var(--line) 1px, transparent 1px) 0 0 / 40px 40px,
    linear-gradient(90deg, var(--line) 1px, transparent 1px) 0 0 / 40px 40px;
  mask-image: linear-gradient(to bottom, rgba(0,0,0,1), rgba(0,0,0,0.2));
  -webkit-mask-image: linear-gradient(to bottom, rgba(0,0,0,1), rgba(0,0,0,0.2));
}
.scanlines {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgba(255,255,255,0.025) 0 1px, transparent 1px 3px);
  box-shadow: inset 0 0 160px rgba(0,0,0,0.7);
}

/* ---------- Floating pixel sprites ---------- */
.sprites { position: fixed; inset: 0; z-index: -1; pointer-events: none; }
.sprite {
  position: absolute;
  image-rendering: pixelated;
  opacity: 0.55;
  animation: float 7s ease-in-out infinite;
}
.s1 { width: 34px; top: 22%; left: 6%; }
.s2 { width: 48px; top: 64%; right: 7%; animation-delay: -2s; }
.s3 { width: 28px; top: 14%; right: 14%; animation-delay: -4s; animation-duration: 5s; }
.s4 { width: 40px; bottom: 12%; left: 10%; animation-delay: -1s; animation-duration: 9s; }
@keyframes float {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50%      { transform: translateY(-18px) rotate(4deg); }
}

/* ---------- Top HUD ---------- */
.hud {
  position: sticky;
  top: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 12px 24px;
  font-family: var(--mono);
  font-size: 0.8rem;
  letter-spacing: 0.1em;
  background: linear-gradient(to bottom, rgba(10,11,16,0.95), rgba(10,11,16,0.7));
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(6px);
}
.hud-left { display: flex; align-items: center; gap: 12px; }
.p1 {
  background: var(--accent);
  color: #04110d;
  font-weight: 800;
  padding: 1px 7px;
  border-radius: 2px;
}
.hearts { display: flex; gap: 5px; }
.hearts i {
  width: 14px; height: 12px;
  background: var(--hot);
  clip-path: polygon(0 20%, 20% 0, 45% 0, 50% 15%, 55% 0, 80% 0, 100% 20%, 100% 50%, 50% 100%, 0 50%);
  animation: beat 1.4s ease-in-out infinite;
}
.hearts i:nth-child(2) { animation-delay: 0.15s; }
.hearts i:nth-child(3) { animation-delay: 0.3s; }
@keyframes beat { 0%, 100% { transform: scale(1); } 15% { transform: scale(1.2); } }

.hud-mid { display: flex; align-items: center; gap: 10px; }
.lvl { color: var(--gold); }
.xp {
  width: 160px; height: 10px;
  border: 1px solid var(--muted);
  padding: 2px;
}
.xp-fill {
  height: 100%;
  width: 35%;
  background: repeating-linear-gradient(90deg, var(--accent) 0 6px, transparent 6px 8px);
  transform-origin: left;
  animation: xp 2.4s ease-out both;
}
@keyframes xp { from { transform: scaleX(0); } }
.hud-right { text-align: right; color: var(--muted); }
.score { color: var(--text); }

/* ---------- Main ---------- */
.wrap {
  flex: 1;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 10vh 24px 48px;
}

.boot {
  font-family: var(--mono);
  font-size: 0.9rem;
  color: var(--accent);
  margin-bottom: 1.25rem;
}
.prompt { color: var(--accent-2); margin-right: 0.4em; }
.dots::after { content: ""; animation: dots 1.6s steps(4, end) infinite; }
@keyframes dots {
  0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; }
}

/* Glitch headline */
.name {
  position: relative;
  font-size: clamp(2.4rem, 8vw, 4.75rem);
  font-weight: 900;
  letter-spacing: -0.02em;
  line-height: 1.05;
  text-transform: uppercase;
  color: var(--text);
  text-shadow: 0 0 24px rgba(62, 230, 193, 0.25);
}
.glitch::before,
.glitch::after {
  content: attr(data-text);
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}
.glitch::before {
  color: var(--hot);
  transform: translate(-2px, 0);
  mix-blend-mode: screen;
  animation: glitch-a 4s infinite steps(1);
}
.glitch::after {
  color: var(--accent);
  transform: translate(2px, 0);
  mix-blend-mode: screen;
  animation: glitch-b 4s infinite steps(1);
}
@keyframes glitch-a {
  0%, 88%, 100% { clip-path: inset(0 0 100% 0); }
  89% { clip-path: inset(10% 0 60% 0); transform: translate(-4px, -1px); }
  91% { clip-path: inset(55% 0 20% 0); transform: translate(3px, 1px); }
  93% { clip-path: inset(30% 0 45% 0); transform: translate(-2px, 0); }
}
@keyframes glitch-b {
  0%, 88%, 100% { clip-path: inset(0 0 100% 0); }
  90% { clip-path: inset(65% 0 10% 0); transform: translate(4px, 1px); }
  92% { clip-path: inset(20% 0 60% 0); transform: translate(-3px, -1px); }
  94% { clip-path: inset(40% 0 35% 0); transform: translate(2px, 0); }
}

.role {
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.95rem;
  color: var(--muted);
  margin-top: 0.7rem;
}
.sep { color: var(--accent-2); margin: 0 0.4em; }

.intro {
  margin-top: 1.75rem;
  font-size: 1.15rem;
  max-width: 60ch;
  color: #c9cfdb;
}
.intro strong { color: var(--text); font-weight: 600; }

/* ---------- HUD-style framed panels (corner brackets) ---------- */
.frame {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  --c: var(--accent);
  --s: 14px;
  background-image:
    linear-gradient(var(--c), var(--c)), linear-gradient(var(--c), var(--c)),
    linear-gradient(var(--c), var(--c)), linear-gradient(var(--c), var(--c)),
    linear-gradient(var(--c), var(--c)), linear-gradient(var(--c), var(--c)),
    linear-gradient(var(--c), var(--c)), linear-gradient(var(--c), var(--c));
  background-repeat: no-repeat;
  background-size:
    var(--s) 2px, 2px var(--s),
    var(--s) 2px, 2px var(--s),
    var(--s) 2px, 2px var(--s),
    var(--s) 2px, 2px var(--s);
  background-position:
    0 0, 0 0,
    100% 0, 100% 0,
    0 100%, 0 100%,
    100% 100%, 100% 100%;
  background-color: var(--panel);
}

.panels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
  margin-top: 2.75rem;
}
.panel { padding: 1.4rem 1.5rem; }
.panel-title {
  font-family: var(--mono);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--accent);
  margin-bottom: 1rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px dashed var(--line);
}

.sheet { display: grid; gap: 0.35rem; margin-bottom: 1.1rem; }
.sheet div { display: flex; justify-content: space-between; gap: 1rem; font-size: 0.95rem; }
.sheet dt { color: var(--muted); font-family: var(--mono); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; }
.sheet dd { font-weight: 600; text-align: right; }

.stats { list-style: none; display: grid; gap: 0.6rem; }
.stats li {
  display: grid;
  grid-template-columns: 110px 1fr;
  align-items: center;
  gap: 10px;
  font-family: var(--mono);
  font-size: 0.82rem;
}
.stat {
  display: block;
  height: 10px;
  background:
    repeating-linear-gradient(90deg, transparent 0 9px, var(--bg) 9px 11px),
    linear-gradient(90deg, var(--accent-2), var(--accent)) 0 0 / var(--v) 100% no-repeat,
    var(--line);
  border: 1px solid #2a3244;
  animation: statfill 1.6s ease-out both;
}
@keyframes statfill { from { background-size: auto, 0 100%, auto; } }

.quest-name { color: var(--gold); font-weight: 600; margin-bottom: 0.7rem; }
.objectives { list-style: none; display: grid; gap: 0.45rem; font-size: 0.95rem; }
.objectives li { position: relative; padding-left: 1.7rem; color: var(--muted); }
.objectives li::before {
  content: "";
  position: absolute;
  left: 0; top: 0.35em;
  width: 12px; height: 12px;
  border: 2px solid #3a4459;
}
.objectives li.done { color: #6f788b; text-decoration: line-through; }
.objectives li.done::before { background: var(--accent); border-color: var(--accent); }
.objectives li.active { color: var(--text); }
.objectives li.active::before { border-color: var(--gold); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { background: rgba(255, 209, 102, 0.5); } }
.quest-note { margin-top: 1rem; font-size: 0.85rem; color: var(--muted); font-style: italic; }

/* ---------- Code window ---------- */
.code-window { margin-top: 20px; --c: var(--accent-2); overflow: hidden; }
.code-bar {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(0,0,0,0.25);
}
.dot { width: 10px; height: 10px; border-radius: 50%; }
.dot.r { background: #ff5f57; } .dot.y { background: #febc2e; } .dot.g { background: #28c840; }
.file { margin-left: 10px; font-family: var(--mono); font-size: 0.78rem; color: var(--muted); }
.code-window pre {
  margin: 0;
  padding: 1.1rem 1.4rem 1.3rem;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 0.88rem;
  line-height: 1.65;
  color: #cfd6e4;
}
.c-kw { color: #c792ea; }
.c-ty { color: #82aaff; }
.c-fn { color: #3ee6c1; }
.c-st { color: #ffd166; }
.c-cm { color: #5c6680; font-style: italic; }
.caret {
  display: inline-block;
  width: 8px; height: 1.1em;
  margin-left: 4px;
  vertical-align: text-bottom;
  background: var(--accent);
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ---------- Press start ---------- */
.press-start {
  margin-top: 3rem;
  text-align: center;
  font-family: var(--mono);
  font-weight: 700;
  letter-spacing: 0.22em;
  font-size: 0.9rem;
  color: var(--gold);
  text-shadow: 0 0 12px rgba(255, 209, 102, 0.5);
  animation: blink 1.2s steps(1) infinite;
}

/* ---------- Footer ---------- */
.foot {
  text-align: center;
  padding: 24px;
  font-size: 0.78rem;
  color: var(--muted);
  font-family: var(--mono);
  border-top: 1px solid var(--line);
}
.ver { color: var(--accent-2); }

/* ---------- Responsive ---------- */
@media (max-width: 600px) {
  .hud { grid-template-columns: 1fr 1fr; padding: 10px 16px; }
  .hud-mid { display: none; }
  .sprite { opacity: 0.3; }
  .stats li { grid-template-columns: 95px 1fr; }
}

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