: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; }

/* ---------- 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)); }
#btn-pause { right: calc(16px + env(safe-area-inset-right, 0px)); top: calc(96px + env(safe-area-inset-top, 0px)); font-size: 16px; }

@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; }
}
