@font-face {
  font-family: "Press Start 2P";
  src: url("../fonts/press-start-2p.woff2") format("woff2");
  font-display: swap;
}
@font-face {
  font-family: "VT323";
  src: url("../fonts/vt323.woff2") format("woff2");
  font-display: swap;
}

:root {
  --ink: #15102a;
  --ink-2: #231a42;
  --ink-3: #3a2d63;
  --cream: #fff4d6;
  --muted: #cfc3e6;
  --yellow: #ffd23f;
  --yellow-dark: #c98a12;
  --coral: #ff5d73;
  --mint: #4ff0c8;
  --pixel: "Press Start 2P", ui-monospace, Menlo, Consolas, monospace;
  --body: "VT323", ui-monospace, Menlo, Consolas, monospace;
  --hud-h: 60px;
  --notice-h: 44px;
  --top-h: calc(var(--hud-h) + var(--notice-h));
}

*, *::before, *::after { box-sizing: border-box; }

html { background: var(--ink); -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--ink);
  color: var(--cream);
  font: 400 1.5rem/1.25 var(--body);
  overflow-x: hidden;
}

h1, h2, h3, p, ul, ol, dl, dd { margin: 0; padding: 0; }
ul, ol { list-style: none; }
a { color: inherit; }
button { font: inherit; color: inherit; }

:focus-visible { outline: 3px solid var(--mint); outline-offset: 3px; }

html:not(.js) .js-only { display: none !important; }

.skip {
  position: fixed; left: 12px; top: -80px; z-index: 100;
  padding: 12px 16px; background: var(--yellow); color: var(--ink);
  font-family: var(--pixel); font-size: .625rem;
}
.skip:focus { top: 12px; }

#world {
  position: fixed; inset: 0 0 auto 0; z-index: 0;
  display: block; width: 100%;
  height: 100vh; height: 100lvh;
  image-rendering: pixelated;
  background: #2b1b54;
}

/* ---------- HUD ---------- */
.hud {
  position: fixed; inset: 0 0 auto 0; z-index: 30;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px;
  height: var(--hud-h);
  padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  background: var(--ink);
  border-bottom: 4px solid var(--ink-3);
  font-family: var(--pixel); font-size: .625rem;
}
.hud-logo {
  position: absolute; left: 16px; top: 50%; transform: translateY(-50%);
  color: var(--yellow); font-size: 1.125rem; text-decoration: none;
  text-shadow: 2px 2px 0 var(--coral);
}
.hud-stats { display: flex; align-items: center; gap: 20px; padding-left: 96px; }
.stat { display: inline-flex; align-items: center; gap: 8px; }
.stat i { font-style: normal; color: var(--muted); }
.stat b { font-weight: 400; font-variant-numeric: tabular-nums; }
.coin-ico {
  width: 12px; height: 12px; background: var(--yellow);
  box-shadow: inset -3px -3px 0 var(--yellow-dark);
}
.combo { min-width: 36px; color: var(--coral); }
.combo.bump { animation: bump .25s steps(3); }

.hud-map ol { position: relative; display: flex; gap: 34px; }
.hud-map ol::before, .hud-map ol::after {
  content: ""; position: absolute; left: 14px; right: 14px; top: 12px; height: 4px;
  background: var(--ink-3);
}
.hud-map ol::after {
  right: auto; width: calc((100% - 28px) * var(--p, 0));
  background: var(--yellow);
}
.hud-map li { position: relative; z-index: 1; }
.hud-map a { position: relative; display: block; text-decoration: none; }
.hud-map span {
  display: grid; place-items: center; width: 28px; height: 28px;
  background: var(--ink-2); border: 3px solid var(--ink-3); color: var(--muted);
}
.hud-map em {
  position: absolute; left: 50%; top: 36px; transform: translateX(-50%);
  padding: 6px 8px; background: var(--ink); color: var(--cream);
  font-style: normal; white-space: nowrap; opacity: 0; pointer-events: none;
}
.hud-map a:hover em, .hud-map a:focus-visible em { opacity: 1; }
.hud-map a.done span { background: var(--yellow); border-color: var(--yellow-dark); color: var(--ink); }

.hud-actions { display: flex; justify-content: flex-end; gap: 8px; }
.hud-btn {
  display: inline-flex; align-items: center; min-height: 36px; padding: 0 12px;
  background: var(--ink-2); border: 3px solid var(--ink-3); border-radius: 0;
  font-family: var(--pixel); font-size: .5625rem; text-decoration: none; cursor: pointer;
}
.hud-btn:hover { border-color: var(--muted); }
.hud-btn[aria-pressed="true"] { border-color: var(--mint); color: var(--mint); }
.hud-cta { background: var(--yellow); border-color: var(--yellow-dark); color: var(--ink); }
.hud-cta:hover { border-color: var(--cream); }

/* ---------- Maintenance notice ---------- */
.notice {
  position: fixed; inset: var(--hud-h) 0 auto 0; z-index: 29;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 2px 20px;
  min-height: var(--notice-h); padding: 4px 16px 10px;
  background:
    repeating-linear-gradient(135deg, var(--ink) 0 10px, var(--yellow) 10px 20px) left bottom / 100% 6px no-repeat,
    var(--yellow);
  color: var(--ink); text-align: center; line-height: 1.1;
}
.notice strong { font: 400 .625rem/1.4 var(--pixel); text-transform: uppercase; }
.notice a { font-weight: 400; text-underline-offset: 3px; overflow-wrap: anywhere; }
.notice :focus-visible { outline-color: var(--ink); outline-offset: 1px; }

.maint {
  max-width: 560px; margin: 22px auto 0; padding: 14px 16px;
  background: var(--ink); border: 4px solid var(--coral);
  box-shadow: 6px 6px 0 rgba(10, 6, 24, .55);
}
.maint h2 {
  margin: 0 0 8px; color: var(--coral);
  font: 400 clamp(.6875rem, 1.8vw, .875rem)/1.6 var(--pixel);
}
.maint a, .card-final p a { color: var(--mint); text-underline-offset: 3px; overflow-wrap: anywhere; }

/* ---------- Layout ---------- */
main { position: relative; z-index: 2; }

.title {
  min-height: 150vh;
  padding: calc(var(--top-h) + 3vh) 16px 0;
  text-align: center;
}
.title-inner { position: sticky; top: calc(var(--top-h) + 3vh); max-width: 860px; margin: 0 auto; }

.logo {
  display: flex; justify-content: center; gap: .08em; margin: 22px 0 20px;
  font-family: var(--pixel); font-weight: 400;
  font-size: clamp(4rem, 15vw, 9rem); line-height: 1;
  color: var(--yellow);
  text-shadow: .06em .06em 0 var(--coral), .12em .12em 0 var(--ink);
}
.logo span { display: inline-block; }
.js .logo span { animation: float 2.4s steps(6) infinite; }
.js .logo span:nth-child(2) { animation-delay: -.8s; }
.js .logo span:nth-child(3) { animation-delay: -1.6s; }
.tagline {
  display: block; max-width: 22em; margin: 0 auto;
  font-family: var(--pixel); font-weight: 400;
  font-size: clamp(.8125rem, 2.2vw, 1.25rem); line-height: 1.7;
  color: var(--cream); text-shadow: 3px 3px 0 var(--ink);
}

.btn {
  display: inline-block; padding: 18px 26px;
  background: var(--yellow); color: var(--ink);
  border: 4px solid var(--ink);
  box-shadow: inset -4px -4px 0 var(--yellow-dark), inset 4px 4px 0 #ffe88f, 0 6px 0 var(--ink);
  font-family: var(--pixel); font-size: .8125rem; line-height: 1.3;
  text-decoration: none; text-transform: uppercase; cursor: pointer;
}
.btn:hover { background: #ffdf6b; transform: translateY(-2px); box-shadow: inset -4px -4px 0 var(--yellow-dark), inset 4px 4px 0 #fff0ad, 0 8px 0 var(--ink); }
.btn:active { transform: translateY(6px); box-shadow: inset -4px -4px 0 var(--yellow-dark), inset 4px 4px 0 #ffe88f, 0 0 0 var(--ink); }
.btn-start { margin-top: 30px; }
.js .btn-start { animation: blink 1.3s steps(2) infinite; }
.js .btn-start:hover, .js .btn-start:focus-visible { animation: none; }

.controls {
  margin-top: 26px; color: var(--cream); font-size: 1.375rem;
  text-shadow: 2px 2px 0 var(--ink);
}
kbd {
  display: inline-block; padding: 0 7px; background: var(--ink); color: var(--yellow);
  border: 2px solid var(--ink-3); font: inherit; text-shadow: none;
}
.controls-touch { display: none; }
@media (hover: none) and (pointer: coarse) {
  .controls-keys { display: none; }
  .controls-touch { display: block; }
}

/* ---------- Level cards ---------- */
.level {
  min-height: 240vh;
  padding: 70vh max(16px, 6vw) 0;
  outline: none;
}
.level-final { min-height: 220vh; }

.card {
  position: sticky; top: calc(var(--top-h) + 28px);
  width: min(100%, 580px); margin-left: auto; padding: 0 26px 28px;
  background: var(--ink);
  border: 4px solid var(--cream);
  box-shadow: 0 0 0 4px var(--ink), 10px 10px 0 4px rgba(10, 6, 24, .55);
}
.js .card { opacity: 0; transform: translateY(28px) scale(.96); }
.js .card.on { animation: pop .42s steps(6) forwards; }

.card-bar {
  display: flex; justify-content: space-between; gap: 12px;
  margin: 0 -26px 22px; padding: 11px 14px;
  background: var(--cream); color: var(--ink);
  font-family: var(--pixel); font-size: .5625rem;
}
.card h2 {
  margin-bottom: 16px;
  font-family: var(--pixel); font-weight: 400;
  font-size: clamp(1.0625rem, 2.2vw, 1.375rem); line-height: 1.5;
  color: var(--yellow); text-wrap: balance;
}
.card p { color: var(--cream); }
.card h3 {
  margin-bottom: 7px; font-family: var(--pixel); font-weight: 400;
  font-size: .6875rem; line-height: 1.5; color: var(--mint);
}
.quest { margin-top: 16px; padding: 10px 14px; background: var(--ink-2); border-left: 4px solid var(--coral); }
.quest b { font-weight: 400; color: var(--coral); }

.powers { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.powers li { padding: 14px; background: var(--ink-2); border: 3px solid var(--ink-3); }
.powers li:hover { border-color: var(--mint); }
.powers li:hover svg { animation: bump .3s steps(3); }
.powers svg { display: block; width: 32px; height: 32px; margin-bottom: 10px; }
.powers p { font-size: 1.3125rem; line-height: 1.15; }

.route { counter-reset: s; display: grid; gap: 14px; }
.route li {
  counter-increment: s; position: relative; min-height: 52px; padding-left: 66px;
}
.route li::before {
  content: counter(s); position: absolute; left: 0; top: 0;
  display: grid; place-items: center; width: 48px; height: 48px;
  background: var(--coral); color: var(--ink); border: 3px solid var(--cream);
  font-family: var(--pixel); font-size: .875rem;
}
.route li:not(:last-child)::after {
  content: ""; position: absolute; left: 21px; top: 48px; bottom: -14px; width: 6px;
  background: repeating-linear-gradient(var(--cream) 0 6px, transparent 6px 12px);
}

.card-final .btn { margin-top: 22px; }

.results { margin-top: 26px; padding-top: 20px; border-top: 4px dashed var(--ink-3); }
.results dl { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.results div { padding: 10px 6px; background: var(--ink-2); text-align: center; }
.results dt { color: var(--muted); font-size: 1.125rem; }
.results dd { font-family: var(--pixel); font-size: .75rem; color: var(--yellow); margin-top: 6px; overflow-wrap: anywhere; }
.btn-text {
  margin-top: 14px; padding: 8px 0; background: none; border: 0; cursor: pointer;
  color: var(--mint); font-size: 1.375rem; text-decoration: underline; text-underline-offset: 4px;
}

.foot {
  position: relative; z-index: 2; padding: 16px; text-align: center;
  background: var(--ink); color: var(--muted); font-size: 1.25rem;
}

/* ---------- Banner, toasts, jump ---------- */
.banner {
  position: fixed; left: 0; right: 0; bottom: 27vh; z-index: 20;
  padding: 18px 16px; text-align: center; pointer-events: none;
  background: var(--ink); border-block: 4px solid var(--yellow);
  opacity: 0; visibility: hidden;
}
.banner small { display: block; margin-bottom: 10px; font: .625rem var(--pixel); color: var(--mint); }
.banner strong { font: 400 clamp(1rem, 3.4vw, 2rem)/1.3 var(--pixel); color: var(--yellow); }
.banner.play { animation: sweep 1.9s steps(14) forwards; }

.toasts {
  position: fixed; left: 16px; bottom: 16px; z-index: 40;
  display: grid; gap: 8px; pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 12px; max-width: min(340px, calc(100vw - 32px));
  padding: 10px 14px; background: var(--ink); border: 3px solid var(--yellow);
  animation: toast 3.4s steps(10) forwards;
}
.toast::before {
  content: ""; flex: none; width: 20px; height: 20px; background: var(--yellow);
  box-shadow: inset -4px -4px 0 var(--yellow-dark);
}
.toast small { display: block; font: .5rem var(--pixel); color: var(--mint); margin-bottom: 5px; }
.toast b { font-weight: 400; font-size: 1.375rem; line-height: 1; }

.jump {
  position: fixed; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 25;
  display: none; width: 76px; height: 76px;
  background: var(--coral); color: var(--ink);
  border: 4px solid var(--ink); border-radius: 0;
  box-shadow: inset -4px -4px 0 #b92f49, inset 4px 4px 0 #ff9aa8;
  font-family: var(--pixel); font-size: .5625rem;
  touch-action: manipulation; -webkit-user-select: none; user-select: none;
}
.jump:active { transform: translateY(3px); }
@media (hover: none) and (pointer: coarse) {
  .jump { display: block; }
  .foot { padding-right: 104px; text-align: left; }
}

/* ---------- Boot screen ---------- */
.boot {
  position: fixed; inset: 0; z-index: 90;
  display: grid; place-content: center; gap: 18px; justify-items: center;
  background: var(--ink); font-family: var(--pixel); font-size: .6875rem; color: var(--cream);
}
.boot i { display: block; width: 220px; height: 16px; padding: 2px; border: 3px solid var(--cream); }
.boot i::after { content: ""; display: block; height: 100%; background: var(--yellow); animation: load .7s steps(10) forwards; }
.boot.out { animation: bootout .25s steps(4) forwards; }

/* ---------- Motion ---------- */
@keyframes float { 50% { transform: translateY(-.1em); } }
@keyframes blink { 50% { background: #fff0ad; } }
@keyframes bump { 50% { transform: translateY(-5px) scale(1.2); } }
@keyframes pop {
  0% { opacity: 0; transform: translateY(28px) scale(.96); }
  65% { opacity: 1; transform: translateY(-5px) scale(1.01); }
  100% { opacity: 1; transform: none; }
}
@keyframes sweep {
  0% { opacity: 1; visibility: visible; transform: translateX(-100%); }
  15%, 82% { opacity: 1; visibility: visible; transform: none; }
  100% { opacity: 1; visibility: hidden; transform: translateX(100%); }
}
@keyframes toast {
  0% { opacity: 0; transform: translateY(16px); }
  8%, 88% { opacity: 1; transform: none; }
  100% { opacity: 0; transform: translateY(8px); }
}
@keyframes load { from { width: 0; } to { width: 100%; } }
@keyframes bootout { to { opacity: 0; visibility: hidden; } }

/* ---------- Responsive ---------- */
@media (max-width: 1080px) {
  .hud { grid-template-columns: auto 1fr auto; }
  .hud-stats { padding-left: 84px; }
  .hud-map { display: none; }
}
@media (max-width: 899px), (max-height: 719px) {
  .card { position: relative; top: auto; margin-inline: auto; }
  .level { min-height: 0; padding-top: 85vh; padding-bottom: 85vh; }
  /* Keep the final card on screen at the finish line, where the results appear. */
  .level-final { padding-bottom: 16vh; }
  .title-inner { position: static; }
}
@media (max-width: 620px) {
  :root { --hud-h: 54px; --notice-h: 58px; }
  .notice { flex-direction: column; flex-wrap: nowrap; padding-inline: 8px; font-size: clamp(1.125rem, 5.6vw, 1.4375rem); }
  body { font-size: 1.4375rem; }
  .hud { gap: 8px; padding-inline: 12px; }
  .hud-logo { left: 12px; font-size: .9375rem; }
  .hud-stats { gap: 10px; padding-left: 62px; }
  .stat:first-child i { display: none; }
  .combo { display: none; }
  .hud-btn { min-height: 34px; padding: 0 8px; font-size: .5rem; }
  .sound-label { font-size: 0; }
  .sound-label::before { content: "SFX"; font-size: .5rem; }
  .card { padding: 0 16px 20px; }
  .card-bar { margin: 0 -16px 18px; }
  .powers { grid-template-columns: 1fr; }
  .powers li { display: grid; grid-template-columns: 32px 1fr; column-gap: 12px; }
  .powers svg { grid-row: span 2; margin: 0; }
  .btn { padding: 16px 18px; font-size: .75rem; }
  .results dl { grid-template-columns: 1fr 1fr; }
  .toasts { bottom: 104px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
  .js .btn-start, .js .logo span { animation: none; }
}
