:root {
  --ink: #2b1a0e;
  --bone: #fff6e3;
  --amber: #ffb238;
  --red: #e8473c;
  --panel: rgba(43, 26, 14, 0.86);
  --display: 'Luckiest Guy', 'Trebuchet MS', 'Arial Black', system-ui, sans-serif;
  --body: system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  color-scheme: dark;
  height: 100%;
  overflow: hidden;
  background: #1b120b;
  color: var(--bone);
  font-family: var(--display);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#game { position: fixed; inset: 0; }
#game canvas { display: block; }
.hidden { display: none !important; }

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  inset: 0 0 auto 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) 12px max(16px, env(safe-area-inset-left, 0px));
  pointer-events: none;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.6);
  z-index: 4;
}
#hearts { font-size: 30px; line-height: 1; color: var(--red); letter-spacing: 2px; }
#hearts .empty { color: rgba(0, 0, 0, 0.45); }
#lives { font-size: 16px; margin-top: 4px; }
.hud-center { flex: 1; max-width: 380px; text-align: center; }
#level-name { font-size: 18px; letter-spacing: 1px; }
.feast { display: flex; align-items: center; gap: 8px; margin-top: 4px; font-size: 15px; }
.feast-bar {
  flex: 1;
  height: 16px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.45);
  border: 2px solid var(--bone);
  overflow: hidden;
}
#feast-fill { height: 100%; width: 0; background: linear-gradient(90deg, #d9682a, #ffb238); transition: width 0.25s; }
.feast.full #feast-fill { background: linear-gradient(90deg, #ffe066, #fff7c2); }
.feast.full .feast-label { color: #ffe066; }
.hud-right { text-align: right; }
#score { font-size: 30px; color: var(--amber); line-height: 1; }
#timer { font-size: 16px; margin-top: 4px; }

#boss {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  width: min(420px, 80vw);
  text-align: center;
  pointer-events: none;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.6);
  z-index: 4;
}
.boss-name { font-size: 20px; margin-bottom: 4px; color: #e9b8ff; }
#boss .bar { height: 14px; border: 2px solid var(--bone); border-radius: 8px; background: rgba(0, 0, 0, 0.45); overflow: hidden; }
#boss-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #8e44ad, #e056fd); transition: width 0.2s; }

#toast {
  position: fixed;
  top: 22%;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  padding: 0 16px;
  text-align: center;
  font-size: clamp(20px, 4.2vw, 34px);
  line-height: 1.2;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.65);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
  z-index: 4;
}
#toast.show { opacity: 1; }
#toast small { display: block; font-size: 0.55em; margin-top: 6px; font-family: var(--body); font-weight: 700; }

#popups { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 3; }
.popup {
  position: absolute;
  left: 0;
  top: 0;
  font-size: 20px;
  color: var(--amber);
  text-shadow: 0 2px 0 #000;
  white-space: nowrap;
  will-change: transform, opacity;
}
.popup.good { color: #9dff7a; }
.popup.heart { color: #ff8a80; }

/* ---------- Screens ---------- */
.screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: radial-gradient(ellipse at center, rgba(20, 10, 4, 0.25), rgba(20, 10, 4, 0.78));
  overflow-y: auto;
}
.panel {
  width: 100%;
  max-width: 560px;
  margin: auto;
  padding: 24px 28px;
  text-align: center;
  background: var(--panel);
  border: 3px solid var(--amber);
  border-radius: 18px;
  box-shadow: 0 10px 0 rgba(0, 0, 0, 0.35);
}
.logo {
  font-size: clamp(56px, 14vw, 104px);
  line-height: 0.9;
  color: var(--amber);
  letter-spacing: 3px;
  text-shadow: 0 6px 0 #7a3e12, 0 12px 20px rgba(0, 0, 0, 0.6);
}
.subtitle { font-size: clamp(18px, 4.5vw, 28px); margin: 8px 0 16px; }
.blurb { font-family: var(--body); font-size: 15px; line-height: 1.5; margin: 0 auto 16px; max-width: 420px; color: #f3e3c3; }
.controls {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 14px;
  max-width: 380px;
  margin: 0 auto 18px;
  font-family: var(--body);
  font-size: 14px;
  text-align: left;
  color: #f3e3c3;
}
.controls b { color: var(--bone); white-space: nowrap; }
h2 { font-size: clamp(30px, 7vw, 46px); margin: 0 0 10px; color: var(--amber); font-weight: normal; text-shadow: 0 4px 0 #7a3e12; }
.tally { max-width: 320px; margin: 0 auto 18px; font-family: var(--body); font-size: 16px; }
.tally div { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px dashed rgba(255, 246, 227, 0.2); }
.tally div.total { border: 0; font-weight: 800; color: var(--amber); font-size: 18px; padding-top: 8px; }
.btn {
  font-family: var(--display);
  font-size: 24px;
  color: var(--ink);
  background: var(--amber);
  border: none;
  border-radius: 12px;
  padding: 10px 30px;
  box-shadow: 0 5px 0 #a1601a;
  cursor: pointer;
}
.btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #a1601a; }
.btn:focus-visible { outline: 3px solid var(--bone); outline-offset: 3px; }
.hint { font-family: var(--body); font-size: 13px; opacity: 0.75; margin-top: 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; align-items: center; }
.btn-secondary {
  font-family: var(--display);
  font-size: 18px;
  color: var(--bone);
  background: transparent;
  border: 2px solid var(--amber);
  border-radius: 12px;
  padding: 9px 20px;
  cursor: pointer;
}
.btn-secondary:hover { background: rgba(255, 178, 56, 0.15); }
.btn-secondary:focus-visible, .sbtn:focus-visible, .hud-btn:focus-visible { outline: 3px solid var(--bone); outline-offset: 2px; }
.hud-buttons { display: flex; gap: 6px; justify-content: flex-end; margin-top: 6px; }
.hud-btn.off { opacity: 0.45; text-decoration: line-through; }
.hud-btn {
  pointer-events: auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid var(--bone);
  background: rgba(0, 0, 0, 0.35);
  color: var(--bone);
  font-family: var(--display);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.hud-btn:hover { background: rgba(255, 178, 56, 0.45); }
.help-section { font-size: 18px; color: var(--amber); margin: 14px 0 6px; text-align: left; max-width: 420px; margin-inline: auto; }
.help-list { font-family: var(--body); font-size: 14px; line-height: 1.5; text-align: left; max-width: 420px; margin: 0 auto 6px; padding-left: 20px; color: #f3e3c3; display: grid; gap: 4px; }
.help-list b { color: var(--bone); }
#screen .panel h2 + .help-section { margin-top: 4px; }
.share { margin: 16px auto 0; max-width: 420px; display: grid; gap: 8px; justify-items: center; }
.share-label { font-size: 15px; color: var(--amber); }
.share-buttons { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.sbtn {
  font-family: var(--body);
  font-weight: 700;
  font-size: 13px;
  color: var(--bone);
  background: rgba(255, 246, 227, 0.08);
  border: 1px solid rgba(255, 246, 227, 0.35);
  border-radius: 999px;
  padding: 6px 14px;
  cursor: pointer;
  text-decoration: none;
}
.sbtn:hover { background: rgba(255, 178, 56, 0.25); }
.share-fallback { width: 100%; font-family: var(--body); font-size: 16px; /* 16px stops iOS zooming in on focus */ color: var(--ink); background: var(--bone); border: 0; border-radius: 8px; padding: 8px; resize: none; }
.credits { font-family: var(--body); font-size: 11px; opacity: 0.55; margin-top: 10px; line-height: 1.4; }

/* ---------- Touch controls ---------- */
#touch { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#stick-zone { position: absolute; left: 0; bottom: 0; width: 50%; height: 65%; pointer-events: auto; touch-action: none; }
#stick-base {
  position: absolute;
  left: 90px;
  top: calc(100% - 100px);
  width: 110px;
  height: 110px;
  margin: -55px 0 0 -55px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.5);
  background: rgba(0, 0, 0, 0.2);
  opacity: 0.6;
}
#stick-base.active { opacity: 1; }
#stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 50px;
  height: 50px;
  margin: -25px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.65);
}
.tbtn {
  position: absolute;
  pointer-events: auto;
  touch-action: none;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.6);
  background: rgba(0, 0, 0, 0.3);
  color: #fff;
  font-family: var(--display);
  font-size: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.tbtn.on { background: rgba(255, 178, 56, 0.6); }
#btn-jump { right: calc(22px + env(safe-area-inset-right, 0px)); bottom: calc(36px + env(safe-area-inset-bottom, 0px)); width: 92px; height: 92px; }
#btn-club { right: calc(126px + env(safe-area-inset-right, 0px)); bottom: calc(26px + env(safe-area-inset-bottom, 0px)); width: 78px; height: 78px; }
.small-btn { width: 50px; height: 50px; font-size: 20px; }
#btn-cl { right: calc(92px + env(safe-area-inset-right, 0px)); bottom: calc(150px + env(safe-area-inset-bottom, 0px)); }
#btn-cr { right: calc(30px + env(safe-area-inset-right, 0px)); bottom: calc(150px + env(safe-area-inset-bottom, 0px)); }

@media (max-width: 640px) {
  #hud { padding-top: calc(10px + env(safe-area-inset-top, 0px)); gap: 8px; }
  #hearts { font-size: 22px; }
  #lives, #timer { font-size: 13px; }
  #score { font-size: 22px; }
  #level-name { font-size: 14px; }
  .feast { font-size: 12px; gap: 5px; }
  .feast-label { display: none; }
  .panel { padding: 20px 18px; }
  .hud-btn { width: 30px; height: 30px; font-size: 16px; }
}

/* ---------- HUD extras ---------- */
#hud { background: linear-gradient(to bottom, rgba(0, 0, 0, 0.32), rgba(0, 0, 0, 0)); padding-bottom: 26px; }
.feast.bump .feast-bar { animation: bump 0.3s ease-out; }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.06, 1.35); } 100% { transform: scale(1); } }
.track { position: relative; height: 4px; margin: 10px 6px 0; border-radius: 2px; background: rgba(255, 246, 227, 0.3); }
#track-dot { position: absolute; top: 50%; left: 0; width: 12px; height: 12px; margin: -6px 0 0 -6px; border-radius: 50%; background: var(--amber); border: 2px solid var(--ink); transition: left 0.2s linear; }
.track-gate { position: absolute; right: -5px; top: 50%; width: 10px; height: 12px; margin-top: -8px; border: 2px solid var(--bone); border-bottom: 0; border-radius: 5px 5px 0 0; }

#flash { position: fixed; inset: 0; pointer-events: none; z-index: 3; opacity: 0; background: radial-gradient(ellipse at center, rgba(232, 71, 60, 0) 45%, rgba(232, 71, 60, 0.7) 100%); }
#flash.on { animation: flash 0.5s ease-out; }
@keyframes flash { 0% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- Menus ---------- */
.panel { animation: pop 0.22s ease-out; }
@keyframes pop { from { transform: translateY(10px) scale(0.97); opacity: 0; } to { transform: none; opacity: 1; } }
.eyebrow { font-size: 15px; letter-spacing: 2px; text-transform: uppercase; color: var(--amber); margin-bottom: 6px; }
.menu { display: grid; gap: 10px; max-width: 260px; margin: 0 auto; }
.menu .btn, .menu .btn-secondary { width: 100%; }
.stars { color: var(--amber); letter-spacing: 2px; font-family: var(--body); }
.stars.big { font-size: 44px; line-height: 1; margin: 2px 0 8px; text-shadow: 0 3px 0 #7a3e12; }

/* Hero select: small panel at the bottom so the 3D hero stays visible */
.screen.bottom { align-items: flex-end; background: linear-gradient(to top, rgba(20, 10, 4, 0.75), rgba(20, 10, 4, 0) 55%); padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
.screen.bottom .panel { max-width: 460px; padding: 16px 20px 18px; margin: 0 auto; animation: none; }
.hero-pick { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.hero-info { flex: 1; min-width: 0; }
.hero-name { font-size: clamp(34px, 9vw, 46px); line-height: 1; color: var(--amber); text-shadow: 0 4px 0 #7a3e12; }
.hero-label { font-size: 17px; margin-top: 4px; }
.hero-blurb { font-family: var(--body); font-size: 14px; color: #f3e3c3; margin-top: 2px; }
.arrow {
  flex: none;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 2px solid var(--amber);
  background: rgba(255, 178, 56, 0.12);
  color: var(--amber);
  font-size: 34px;
  line-height: 1;
  padding: 0 0 6px;
  cursor: pointer;
}
.arrow:hover { background: rgba(255, 178, 56, 0.3); }
.arrow:focus-visible, .level-card:focus-visible { outline: 3px solid var(--bone); outline-offset: 2px; }
.dots { display: flex; gap: 8px; justify-content: center; margin: 10px 0 14px; }
.dots span { width: 9px; height: 9px; border-radius: 50%; background: rgba(255, 246, 227, 0.3); }
.dots span.on { background: var(--amber); }

/* Level select */
.levels { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin: 0 0 18px; }
.level-card {
  display: grid;
  gap: 4px;
  justify-items: center;
  padding: 12px 8px 10px;
  border-radius: 14px;
  border: 2px solid rgba(255, 246, 227, 0.25);
  border-top: 6px solid var(--c);
  background: rgba(255, 246, 227, 0.06);
  color: var(--bone);
  font-family: var(--display);
  cursor: pointer;
}
.level-card:hover:not(.locked) { background: rgba(255, 246, 227, 0.14); }
.level-card.selected { border-color: var(--amber); border-top-color: var(--c); background: rgba(255, 178, 56, 0.16); box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3); }
.level-card.locked { opacity: 0.45; cursor: default; }
.lv-num { font-size: 26px; line-height: 1; color: var(--c); }
.level-card.locked .lv-num { font-size: 18px; }
.lv-name { font-size: 15px; }
.level-card .stars { font-size: 15px; }
.level-card.locked .stars { font-size: 12px; color: var(--bone); letter-spacing: 0; }

@media (max-width: 640px) {
  .levels { grid-template-columns: repeat(2, 1fr); }
  .track { margin-top: 8px; }
  .stars.big { font-size: 36px; }
}
@media (prefers-reduced-motion: reduce) {
  .panel, .feast.bump .feast-bar, #flash.on { animation: none; }
}

/* ---------- No accidental zoom on phones ---------- */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
#game canvas { touch-action: none; }
.screen { touch-action: pan-y; overscroll-behavior: contain; }
button, a, .hud-btn, .level-card, .sbtn { touch-action: manipulation; }
#touch .tbtn, #stick-zone { touch-action: none; }

/* ---------- Developer credit ---------- */
.studio { margin: 2px 0 16px; }
.studio-by { display: block; font-family: var(--body); font-size: 13px; letter-spacing: 2px; text-transform: uppercase; color: #f3e3c3; }
.studio-name {
  display: block;
  margin-top: 2px;
  font-family: var(--display);
  font-weight: normal;
  font-size: clamp(30px, 8vw, 44px);
  line-height: 1.1;
  letter-spacing: 2px;
  color: var(--amber);
  text-shadow: 0 3px 0 #7a3e12;
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
