:root {
  --bg: #15183a;
  --ink: #fff8ec;
  --dim: #b9bde0;
  --accent: #ff8c3a;
  --accent-ink: #2b1d14;
  --panel: rgba(18, 20, 48, 0.82);
  --font: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --px: 2;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

.wrap {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.screen {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
}

.frame {
  position: relative;
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  outline: none;
}

/* ---------- HUD ---------- */
.hud {
  position: absolute;
  inset: 0 0 auto 0;
  display: flex;
  align-items: flex-start;
  gap: clamp(8px, 3%, 28px);
  padding: 6px 10px;
  font-size: clamp(10px, calc(var(--px) * 5px), 18px);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.45);
  pointer-events: none;
}
.hud[hidden] { display: none; }
.hud span { display: flex; flex-direction: column; line-height: 1.1; }
.hud small {
  font-size: 0.62em;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.8;
}
.hud b { font-weight: 700; letter-spacing: 0.04em; font-variant-numeric: tabular-nums; }

.hud-btn {
  pointer-events: auto;
  border: 0;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.28);
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  width: 28px;
  height: 28px;
  cursor: pointer;
}
.hud-btn:hover { background: rgba(0, 0, 0, 0.45); }
#pause-btn { margin-left: auto; }
.mute { position: absolute; right: 10px; bottom: 8px; z-index: 2; }
body:not([data-state="title"]) .mute { bottom: auto; top: 6px; right: 44px; }

/* ---------- overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px;
  text-align: center;
  background: rgba(10, 12, 32, 0.55);
}
.overlay[hidden] { display: none; }
.overlay.title { background: linear-gradient(rgba(10, 12, 32, 0.15), rgba(10, 12, 32, 0.6)); }
.overlay.intro { background: #0b0d22; }
.overlay h1, .overlay h2, .overlay p { margin: 0; }

.logo {
  font-size: clamp(36px, calc(var(--px) * 22px), 96px);
  font-weight: 800;
  letter-spacing: 0.06em;
  line-height: 1;
  color: var(--ink);
  text-shadow: 0 4px 0 #2b1d14, 0 8px 0 rgba(0, 0, 0, 0.25);
}
.logo span { color: var(--accent); }

.overlay h2 {
  font-size: clamp(22px, calc(var(--px) * 11px), 44px);
  letter-spacing: 0.04em;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.4);
}
.tag { color: var(--ink); max-width: 34ch; font-size: 14px; text-shadow: 0 1px 0 rgba(0, 0, 0, 0.5); }
.world { color: var(--accent); letter-spacing: 0.2em; text-transform: uppercase; font-size: 13px; }
.lives, .score { font-size: 16px; }
.best { color: var(--dim); font-size: 12px; letter-spacing: 0.08em; }
.best b, .score b { color: var(--ink); font-variant-numeric: tabular-nums; }

.pip {
  display: inline-block;
  width: 14px;
  height: 14px;
  vertical-align: -2px;
  border-radius: 3px;
  background: linear-gradient(#e9fbff 0 0) 3px 3px / 8px 5px no-repeat, var(--accent);
  box-shadow: 0 0 0 2px #2b1d14;
}

.buttons { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 4px; }
.overlay button {
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 9px 16px;
  border-radius: 8px;
  border: 2px solid var(--ink);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}
.overlay button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); box-shadow: 0 3px 0 #a14e14; }
.overlay button:hover { filter: brightness(1.08); }
.overlay button:focus-visible { outline: 3px solid #ffe14d; outline-offset: 2px; }

.keys { color: var(--dim); font-size: 11px; line-height: 2; }
kbd {
  display: inline-block;
  min-width: 18px;
  padding: 0 4px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.14);
  color: var(--ink);
  font: inherit;
  margin: 0 1px;
}
body.touch .keys { display: none; }

/* ---------- touch controls ---------- */
.pad { display: none; }
body.touch .pad {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 12px 18px 18px;
  flex: 0 0 auto;
}
/* landscape phones: the controls float over the game */
@media (orientation: landscape) {
  body.touch .pad {
    position: absolute;
    inset: auto 0 0 0;
    padding: 0 max(18px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
    pointer-events: none;
  }
  body.touch .pad > * { pointer-events: auto; opacity: 0.75; }
}
body[data-state="title"] .pad, body[data-state="over"] .pad, body[data-state="win"] .pad { visibility: hidden; }

.dpad {
  display: flex;
  width: 148px;
  height: 72px;
  border-radius: 36px;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.22);
  touch-action: none;
}
.dpad span {
  flex: 1;
  display: grid;
  place-items: center;
  font-size: 22px;
  color: var(--ink);
  pointer-events: none;
}
.ab { display: flex; gap: 14px; align-items: flex-end; }
.ab button {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.25);
  font: inherit;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.1);
  touch-action: none;
}
.ab .btn-a { width: 78px; height: 78px; background: var(--accent); border-color: var(--accent); color: var(--accent-ink); margin-bottom: 14px; }
.ab button:active { filter: brightness(1.2); }

.noscript { position: fixed; inset: 0; display: grid; place-items: center; margin: 0; }
