:root {
  --ink: #2b2118;
  --marble: #faf6ee;
  --marble-2: #efe7d8;
  --ketchup: #c8412f;
  --mustard: #f2b705;
  --gold: #c9a54a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #d8c7a6;
  color: var(--ink);
  font-family: 'Fredoka', system-ui, -apple-system, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button { font-family: inherit; }

#game {
  position: fixed;
  inset: 0;
  display: block;
  touch-action: none;
}
body.playing #game { cursor: none; }

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
  pointer-events: none;
  z-index: 5;
}
.stat {
  background: rgba(250, 246, 238, 0.9);
  border: 2px solid var(--ink);
  border-radius: 14px;
  padding: 4px 12px 6px;
  box-shadow: 0 3px 0 var(--ink);
  min-width: 76px;
  position: relative;
}
.stat-center { text-align: center; min-width: 60px; }
.hud-brand { padding: 6px 12px 3px; }
.hud-brand img { display: block; width: auto; height: 38px; margin: 0 auto 1px; }
.level-num { font-size: 14px; font-weight: 700; letter-spacing: 0; font-variant-numeric: tabular-nums; }
.stat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.7;
}
.stat-value { font-size: 24px; font-weight: 700; line-height: 1.05; font-variant-numeric: tabular-nums; }
.combo {
  position: absolute;
  left: 8px;
  top: 100%;
  margin-top: 6px;
  font-weight: 700;
  font-size: 14px;
  color: var(--ketchup);
  white-space: nowrap;
  text-shadow: 0 1px 0 #fff;
}
.hud-right { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.lives { font-size: 20px; line-height: 1.2; letter-spacing: 1px; min-height: 24px; }
.hud-buttons { display: flex; gap: 6px; pointer-events: auto; }
.icon-btn {
  width: 38px; height: 38px;
  border-radius: 12px;
  border: 2px solid var(--ink);
  background: var(--marble);
  box-shadow: 0 3px 0 var(--ink);
  font-size: 17px;
  cursor: pointer;
  padding: 0;
}
.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }

/* ---------- Level banner ---------- */
#banner {
  position: fixed;
  top: 30%;
  left: 0; right: 0;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  z-index: 4;
}
#banner h2 {
  margin: 0;
  font-family: 'Cinzel', Georgia, serif;
  font-weight: 900;
  font-size: clamp(36px, 9vw, 64px);
  color: var(--mustard);
  -webkit-text-stroke: 2px var(--ink);
  text-shadow: 0 4px 0 var(--ink);
}
#banner p {
  margin: 6px auto 0;
  display: inline-block;
  padding: 4px 14px;
  font-weight: 700;
  font-size: 18px;
  background: var(--marble);
  border: 2px solid var(--ink);
  border-radius: 999px;
}
#banner p:empty { display: none; }
#banner.show { animation: banner 2.2s ease forwards; }
@keyframes banner {
  0% { opacity: 0; transform: scale(0.6); }
  12% { opacity: 1; transform: scale(1.08); }
  20% { transform: scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-20px); }
}

/* ---------- Overlays ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  padding: 16px;
  overflow-y: auto;
  background: rgba(43, 33, 24, 0.42);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  z-index: 10;
}
.overlay[hidden] { display: none; }
.card {
  margin: auto;
  width: 100%;
  max-width: 580px;
  padding: 22px 20px 18px;
  text-align: center;
  background: var(--marble);
  border: 3px solid var(--ink);
  border-radius: 24px;
  box-shadow: 0 8px 0 var(--ink);
}
.card-small { max-width: 400px; }
.eyebrow {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #8a6d24;
}
.logo { margin: 8px 0 10px; }
.logo img {
  display: block;
  width: min(100%, 360px);
  height: auto;
  margin: 0 auto;
}
h2 {
  margin: 4px 0 8px;
  font-family: 'Cinzel', Georgia, serif;
  font-weight: 900;
  font-size: 26px;
  line-height: 1.15;
}
.tagline { margin: 0 0 12px; font-size: 17px; line-height: 1.35; }

.legend { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 18px; }
.legend-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px;
  background: var(--marble-2);
  border: 2px solid var(--ink);
  border-radius: 14px;
}
.legend-col canvas { width: 64px; height: 44px; }
.legend-col strong { font-size: 15px; line-height: 1.15; }
.legend-col small { font-size: 13px; line-height: 1.2; opacity: 0.75; }

.btn {
  font-size: 20px;
  font-weight: 700;
  color: #fff;
  background: var(--ketchup);
  border: 3px solid var(--ink);
  border-radius: 999px;
  padding: 11px 28px;
  box-shadow: 0 5px 0 var(--ink);
  cursor: pointer;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--ink); }
.btn.secondary { background: var(--marble); color: var(--ink); }
.btn-row { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; margin-top: 12px; }

.best-line { margin: 12px 0 0; font-weight: 600; }
.footnote { margin: 8px 0 0; font-size: 12px; opacity: 0.6; }

.final-score {
  font-size: 64px;
  font-weight: 700;
  line-height: 1;
  color: var(--ketchup);
  text-shadow: 0 3px 0 var(--ink);
  font-variant-numeric: tabular-nums;
}
.new-best {
  display: inline-block;
  margin: 8px 0 0;
  padding: 3px 12px;
  background: var(--mustard);
  border: 2px solid var(--ink);
  border-radius: 999px;
  font-weight: 700;
}
.new-best[hidden] { display: none; }
.rank { margin: 10px 0 2px; font-size: 17px; }
.final-stats { margin: 0; font-size: 14px; opacity: 0.75; }

@media (max-width: 480px) {
  .card { padding: 18px 12px 14px; }
  .tagline { font-size: 15px; }
  .legend { gap: 5px; }
  .legend-col canvas { width: 52px; height: 36px; }
  .legend-col strong { font-size: 13px; }
  .legend-col small { font-size: 12px; }
  .stat { min-width: 64px; padding: 3px 9px 5px; }
  .stat-value { font-size: 20px; }
  .hud-brand img { height: 30px; }
  .lives { font-size: 16px; }
}
