:root {
  --red: #d61e26;
  --red-deep: #4a0a0e;
  --gold: #ffcf4a;
  --gold-deep: #7a4300;
  --blue: #1846b8;
  --leaf: #8fd18a;
  --dust: #b4593a;
  --ink: #fff7ea;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --display: "Arial Black", "Helvetica Neue", system-ui, -apple-system, Roboto, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: #12060a;
  color: var(--ink);
  font-family: system-ui, -apple-system, Roboto, "Segoe UI", sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: fixed;
  inset: 0;
  margin: 0 auto;
  max-width: calc(100dvh * 0.62);
  overflow: hidden;
  background: var(--dust);
}

canvas#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.hidden { display: none !important; }

button {
  font: inherit;
  color: inherit;
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
}

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; }

.hud-top {
  position: absolute;
  top: calc(var(--safe-top) + 8px);
  left: 10px;
  right: 10px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  text-shadow: 0 2px 0 rgba(0, 0, 0, .55), 0 0 10px rgba(0, 0, 0, .35);
}

.hud-left { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.hud-center { text-align: center; }
.hud-right { display: flex; justify-content: flex-end; }

.score { font-family: var(--display); font-weight: 900; font-size: 30px; line-height: 1; letter-spacing: 1px; }
.meters { font-family: var(--display); font-size: 12px; letter-spacing: 2px; color: var(--gold); opacity: .95; }

.army { display: flex; align-items: center; gap: 6px; font-family: var(--display); font-size: 20px; line-height: 1; }
.army.low { color: #ff6b6b; animation: low 0.5s steps(2) infinite; }
.koala-icon {
  position: relative;
  width: 17px; height: 15px; border-radius: 50%;
  background: linear-gradient(#968979 0 34%, #e3262f 34% 52%, #968979 52%);
  box-shadow: 0 1px 0 rgba(0, 0, 0, .5);
}
.koala-icon::before, .koala-icon::after {
  content: "";
  position: absolute;
  top: -4px;
  width: 9px; height: 9px; border-radius: 50%;
  background: radial-gradient(#f2e9dc 0 35%, #968979 40%);
}
.koala-icon::before { left: -5px; }
.koala-icon::after { right: -5px; }
.mult {
  font-family: var(--display);
  font-size: 12px;
  color: var(--gold);
  background: rgba(74, 10, 14, .75);
  border-radius: 8px;
  padding: 1px 6px;
  text-shadow: none;
}
.mult:empty { display: none; }

.icon-btn {
  pointer-events: auto;
  width: 40px; height: 40px;
  border-radius: 12px;
  background: rgba(74, 10, 14, .7);
  border: 2px solid rgba(255, 255, 255, .25);
  font-size: 14px;
  font-weight: 900;
}

.wave {
  position: absolute;
  top: calc(var(--safe-top) + 64px);
  left: 50%;
  transform: translateX(-50%);
  width: 58%;
  display: flex;
  align-items: center;
  gap: 6px;
}
.wave-label { font-family: var(--display); font-size: 11px; color: #8fb6ff; text-shadow: 0 1px 0 #000; }
.wave-bar {
  flex: 1;
  height: 10px;
  border-radius: 6px;
  background: rgba(0, 0, 0, .45);
  border: 1.5px solid rgba(255, 255, 255, .35);
  overflow: hidden;
}
.wave-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #12348a, #2f6bff 70%, #b9d0ff);
  box-shadow: 0 0 10px #2f6bff;
  transform-origin: left center;
  transition: transform .2s linear;
}
@keyframes low { 50% { opacity: .35; } }

.stampede-btn {
  pointer-events: auto;
  position: absolute;
  right: 14px;
  bottom: calc(var(--safe-bottom) + 18px);
  width: 82px; height: 82px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff1b8, #ffcf4a 35%, #e0631c 75%, #8a1a0c);
  box-shadow: 0 6px 0 #4a0a0e, 0 10px 24px rgba(0, 0, 0, .45);
  color: #4a0a0e;
  display: grid;
  place-items: center;
  transition: transform .08s, filter .2s;
}
.stampede-btn:active { transform: translateY(3px) scale(.97); }
.stampede-btn.empty { filter: grayscale(.85) brightness(.75); }
.stampede-btn.ready { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 6px 0 #4a0a0e, 0 0 0 8px rgba(255, 207, 74, .4), 0 10px 24px rgba(0, 0, 0, .45); } }
.stampede-word { font-family: var(--display); font-size: 10.5px; line-height: 1.1; text-align: center; }
.stampede-count {
  position: absolute; top: -17px; left: -17px;
  min-width: 26px; height: 26px; border-radius: 13px;
  background: var(--blue); color: #fff;
  font-family: var(--display); font-size: 14px;
  display: grid; place-items: center;
  border: 2px solid #fff;
}
.stampede-ring { position: absolute; inset: -6px; width: calc(100% + 12px); height: calc(100% + 12px); transform: rotate(-90deg); }
.stampede-ring circle { fill: none; stroke: rgba(0, 0, 0, .25); stroke-width: 5; }
.stampede-ring .progress { stroke: var(--leaf); stroke-linecap: round; stroke-dasharray: 289; stroke-dashoffset: 289; transition: stroke-dashoffset .2s; }

/* ---------- Screens ---------- */
.screen { position: absolute; inset: 0; }

.title-screen {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  background: radial-gradient(120% 60% at 50% 100%, #5a0c10, #2a0608 70%);
}
.hero {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: calc(100% - 262px);
  min-height: 55%;
  background: url("assets/hero.webp") center top / cover no-repeat;
  -webkit-mask-image: linear-gradient(#000 72%, transparent);
  mask-image: linear-gradient(#000 72%, transparent);
  transform-origin: center top;
  animation: drift 14s ease-in-out infinite alternate;
}
@keyframes drift { from { transform: scale(1.02); } to { transform: scale(1.08); } }
.title-shade {
  position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(74, 10, 14, .45) 0%, rgba(74, 10, 14, 0) 16%);
}
.title-content {
  position: relative;
  padding: 0 22px calc(var(--safe-bottom) + 22px);
  text-align: center;
}
/* The poster carries the painted logo; the heading stays for screen readers. */
.logo.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.logo {
  margin: 0;
  font-family: var(--display);
  font-weight: 900;
  line-height: .9;
  display: flex; flex-direction: column;
  transform: rotate(-3deg) skewX(-6deg);
}
.logo span {
  display: block;
  color: #ff2a33;
  -webkit-text-stroke: 2px #3a0006;
  text-shadow: 0 4px 0 #3a0006, 0 8px 0 #1a0204, 0 0 30px rgba(255, 42, 51, .55);
}
.logo span:first-child { font-size: clamp(54px, 18vw, 86px); letter-spacing: 4px; }
.logo span:last-child { font-size: clamp(48px, 16vw, 76px); color: #fff; -webkit-text-stroke-color: var(--red-deep); }
.tagline {
  display: inline-block;
  margin: 18px 0 16px;
  padding: 6px 14px;
  font-family: var(--display);
  font-size: clamp(14px, 4.6vw, 20px);
  letter-spacing: 2px;
  background: var(--blue);
  color: #fff;
  transform: rotate(-2deg);
  box-shadow: 0 4px 0 #081d52;
}
.play-btn {
  display: block;
  width: 100%;
  max-width: 320px;
  margin: 0 auto;
  padding: 16px 0;
  border-radius: 16px;
  font-family: var(--display);
  font-size: 26px;
  letter-spacing: 3px;
  color: #fff;
  background: linear-gradient(180deg, #ff4a50, var(--red) 55%, #8a0a10);
  box-shadow: 0 6px 0 #4a0006, 0 10px 26px rgba(0, 0, 0, .5), inset 0 2px 0 rgba(255, 255, 255, .35);
  text-shadow: 0 2px 0 rgba(0, 0, 0, .4);
}
.play-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #4a0006; }
.ghost-btn {
  display: block;
  margin: 12px auto 0;
  padding: 10px 18px;
  background: transparent;
  font-weight: 800;
  letter-spacing: 1px;
  opacity: .8;
}
.best { margin: 12px 0 6px; font-weight: 700; color: var(--gold); min-height: 1em; }
.how {
  text-align: left;
  font-size: 14px;
  line-height: 1.4;
  background: rgba(255, 255, 255, .07);
  border-radius: 12px;
  padding: 8px 12px;
  max-width: 360px;
  margin: 0 auto;
}
.how summary { font-weight: 800; cursor: pointer; text-align: center; }
.how ul { margin: 8px 0 4px; padding-left: 18px; }
.how li { margin-bottom: 5px; }
.blue { color: #8fb6ff; }
.gold { color: var(--gold); }
.leaf { color: var(--leaf); }
.mute { position: absolute; top: calc(var(--safe-top) + 10px); right: 10px; font-size: 18px; }
.switch-game {
  position: absolute;
  top: calc(var(--safe-top) + 10px);
  left: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 40px;
  padding: 0 10px 0 8px;
  border-radius: 12px;
  font-family: var(--display);
  font-size: 10.5px;
  line-height: 1.05;
  letter-spacing: .5px;
  color: #fff;
  text-decoration: none;
  text-shadow: 0 1px 0 rgba(0, 0, 0, .4);
  background: linear-gradient(180deg, #2f6bff, var(--blue) 60%, #12348a);
  border: 2px solid rgba(255, 255, 255, .3);
  box-shadow: 0 4px 0 #081d52, 0 6px 14px rgba(0, 0, 0, .4);
}
.switch-icon { font-size: 16px; }
.switch-game:active { transform: translateY(3px); box-shadow: 0 1px 0 #081d52; }

.panel-screen {
  display: grid;
  place-items: center;
  background: rgba(30, 6, 8, .72);
  backdrop-filter: blur(3px);
  padding: 20px;
}
.over-hero {
  position: absolute; inset: 0;
  background: url("assets/hero.webp") center 30% / cover no-repeat;
  opacity: .35;
  filter: saturate(1.3);
}
.panel {
  position: relative;
  width: 100%;
  max-width: 360px;
  text-align: center;
  background: linear-gradient(180deg, rgba(184, 24, 32, .95), rgba(74, 10, 14, .97));
  border: 3px solid rgba(255, 255, 255, .2);
  border-radius: 22px;
  padding: 22px 18px 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .6);
}
.panel h2 {
  margin: 0 0 14px;
  font-family: var(--display);
  font-size: 28px;
  line-height: 1;
  color: #fff;
  text-shadow: 0 3px 0 var(--blue);
}
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.stats div { background: rgba(0, 0, 0, .25); border-radius: 10px; padding: 7px 4px; }
.stats span { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; opacity: .75; }
.stats b { font-family: var(--display); font-size: 20px; }
.stats div:first-child b { color: var(--gold); }
.quote { font-style: italic; opacity: .85; margin: 4px 0 14px; font-size: 14px; }
.quote b { color: var(--gold); font-style: normal; }
.new-best { display: block; color: var(--gold); font-size: 14px; letter-spacing: 2px; margin-top: 6px; text-shadow: none; }

.rotate {
  display: none;
  position: fixed; inset: 0;
  background: var(--red-deep);
  place-items: center;
  text-align: center;
  font-family: var(--display);
  font-size: 22px;
  z-index: 10;
}
@media (orientation: landscape) and (max-height: 520px) {
  .rotate { display: grid; }
}
