:root {
  --black: #14100D;
  --iron: #2B2420;
  --steel: #6E5C4A;
  --rust: #B8442A;
  --amber: #E8882C;
  --bone: #F6E7C9;
  --teal: #3E7A72;
  --hud-h: clamp(90px, 14.5vh, 126px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--black);
  color: var(--bone);
  font-family: "Archivo", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body { position: fixed; inset: 0; touch-action: none; }

#app { position: absolute; inset: 0; overflow: hidden; }
#game { position: absolute; inset: 0; }
#game canvas { display: block; image-rendering: auto !important; }

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

[hidden] { display: none !important; }

.fx-grain {
  position: absolute;
  inset: 0;
  z-index: 60;
  pointer-events: none;
  background-image: url("grain.png");
  background-repeat: repeat;
  background-size: 128px 128px;
  opacity: 0.085;
  mix-blend-mode: overlay;
}

.fx-vignette {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  background:
    radial-gradient(125% 92% at 50% 42%, rgba(20, 16, 13, 0) 46%, rgba(20, 16, 13, 0.42) 100%),
    linear-gradient(180deg, rgba(20, 16, 13, 0.22), rgba(20, 16, 13, 0) 20%);
}

/* ---------- HUD ---------- */

.hud {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--hud-h);
  padding: 0 8px calc(6px + env(safe-area-inset-bottom));
  z-index: 30;
  pointer-events: none;
}

.hud-plate {
  position: relative;
  height: 100%;
  display: flex;
  align-items: stretch;
  gap: 8px;
  padding: 7px 9px;
  background: var(--iron);
  border: 3px solid var(--black);
  box-shadow: inset 0 0 0 2px var(--steel), inset 0 -8px 0 rgba(20, 16, 13, 0.45);
  pointer-events: auto;
}

.rivet {
  position: absolute;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--steel);
  border: 2px solid var(--black);
  box-shadow: inset 1px 1px 0 #a08a70, inset -2px -2px 0 #14100d;
  pointer-events: none;
}
.rivet.r1 { left: 4px; top: 4px; }
.rivet.r2 { right: 4px; top: 4px; }
.rivet.r3 { left: 4px; bottom: 4px; }
.rivet.r4 { right: 4px; bottom: 4px; }

.hud-bust {
  flex: 0 0 auto;
  width: calc(var(--hud-h) * 0.72);
  max-width: 104px;
  background: #1b1612;
  border: 3px solid var(--black);
  box-shadow: inset 0 0 0 2px var(--steel);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  overflow: hidden;
  padding: 2px;
}
.hud-bust img { width: 116%; height: 116%; object-fit: contain; object-position: center bottom; margin-bottom: -6%; }

.hud-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.health-wrap { position: relative; overflow: hidden; }
.hud-topline {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: stretch;
  gap: 6px;
}
.hud-health { flex: 1 1 auto; min-height: 30px; }
.health-img { display: block; width: 100%; height: 100%; object-fit: fill; }

.upgrade-rack {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 3px 4px;
  background: #1b1612;
  border: 2px solid var(--black);
  box-shadow: inset 0 0 0 1px var(--steel);
  pointer-events: none;
}
.rack-slot {
  position: relative;
  width: clamp(17px, 4.35vw, 24px);
  height: min(100%, 30px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.rack-slot img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  opacity: 0.28;
  filter: grayscale(1) brightness(0.72);
}
.rack-slot.owned img { opacity: 1; filter: none; }
.rack-count {
  position: absolute;
  right: -3px;
  bottom: -3px;
  min-width: 10px;
  padding: 0 1px;
  background: var(--black);
  border: 1px solid var(--amber);
  color: var(--bone);
  font-family: "Martian Mono", monospace;
  font-weight: 700;
  font-size: 7px;
  line-height: 1.15;
  text-align: center;
}

.health-slots { position: absolute; inset: 0; }
.health-slots .slot {
  position: absolute;
  top: 23.3%;
  height: 51.3%;
  background: var(--black);
  border: 2px solid #0a0705;
  border-radius: 2px;
  opacity: 0;
  transition: opacity 40ms linear;
}
.health-slots .slot.empty { opacity: 0.92; }

.hud-row {
  flex: 0 0 auto;
  display: flex;
  align-items: stretch;
  gap: 6px;
  height: clamp(28px, 3.4vh, 36px);
}

.score-plate {
  position: relative;
  flex: 1 1 40%;
  min-width: 0;
  background: url("interface_kit_04_score_badge.webp") center / 100% 100% no-repeat;
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.5));
}
.score-star { display: none; }
.score-window {
  position: absolute;
  left: 19%;
  right: 3%;
  top: 19%;
  bottom: 17%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #221a15;
  border: 2px solid var(--black);
  color: var(--bone);
  font-family: "Martian Mono", monospace;
  font-weight: 700;
  font-size: clamp(10px, 2.5vw, 19px);
  letter-spacing: 0.06em;
  line-height: 1;
  padding-top: 1px;
}
.score-window::before {
  content: "";
  position: absolute;
  inset: 1px 1px auto 1px;
  height: 2px;
  background: rgba(246, 231, 201, 0.12);
}

.wave-plate {
  position: relative;
  flex: 0 0 clamp(58px, 18vw, 104px);
  background: url("interface_kit_05_wave_plate.webp") center / 100% 100% no-repeat;
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.5));
}
.wave-label { display: none; }
.wave-window {
  position: absolute;
  left: 31%;
  right: 31%;
  top: 43%;
  bottom: 9%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #2a1c15;
  border: 2px solid var(--black);
  color: var(--bone);
  font-family: "Martian Mono", monospace;
  font-weight: 700;
  font-size: clamp(12px, 2.9vw, 20px);
  line-height: 1;
}

.hud-spacer { flex: 1 1 auto; min-width: 0; }

.mini-plate {
  flex: 0 0 auto;
  min-width: 34px;
  padding: 0 5px;
  background: #221b16;
  border: 2px solid var(--black);
  box-shadow: inset 0 0 0 2px var(--steel);
  color: var(--bone);
  font-family: "Archivo", sans-serif;
  font-weight: 700;
  font-size: 9px;
  letter-spacing: 0.08em;
  pointer-events: auto;
}
.mini-plate:active { transform: translateY(1px); }
.mini-plate.off { color: var(--steel); }
.mini-plate.on { color: var(--amber); }
.pause-btn { width: 38px; padding: 3px; display: flex; align-items: center; justify-content: center; }
.pause-btn img { width: 100%; height: 100%; object-fit: contain; }

/* ---------- Boss bar ---------- */

.bossbar {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  width: min(600px, 92vw);
  z-index: 25;
  pointer-events: none;
}
.bossbar-plate {
  position: relative;
  padding: 5px 8px 6px;
  background: #211a15;
  border: 3px solid var(--black);
  box-shadow: inset 0 0 0 2px var(--steel);
}
.bossbar-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 3px;
  font-family: "Archivo", sans-serif;
  font-weight: 700;
  font-size: clamp(8px, 1.7vw, 11px);
  letter-spacing: 0.2em;
  color: var(--bone);
  text-shadow: 1px 1px 0 var(--black);
}
.bossbar-pct {
  font-family: "Martian Mono", monospace;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--amber);
}
.boss-meter { height: clamp(18px, 3.4vw, 26px); }
.boss-meter .health-slots .slot { border-width: 1px; }

/* ---------- Toast ---------- */

.toast {
  position: absolute;
  top: 19%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 35;
  text-align: center;
  pointer-events: none;
  width: max-content;
  max-width: 92vw;
}
.toast-kicker {
  font-family: "Archivo", sans-serif;
  font-weight: 700;
  font-size: clamp(9px, 1.8vw, 12px);
  letter-spacing: 0.32em;
  color: var(--amber);
  text-shadow: 2px 2px 0 var(--black);
}
.toast-title {
  font-family: "Bowlby One SC", sans-serif;
  font-size: clamp(30px, 8vw, 78px);
  line-height: 0.96;
  color: var(--bone);
  text-shadow: 4px 4px 0 var(--rust), 8px 8px 0 rgba(20, 16, 13, 0.7);
  -webkit-text-stroke: 2px var(--black);
}
.toast.show { animation: toast-pop 1.5s cubic-bezier(0.16, 1.24, 0.3, 1) both; }
@keyframes toast-pop {
  0% { opacity: 0; transform: translateX(-50%) translateY(18px) scale(0.86); }
  14% { opacity: 1; transform: translateX(-50%) translateY(0) scale(1.03); }
  22% { transform: translateX(-50%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) translateY(-14px) scale(0.99); }
}

/* ---------- Screens ---------- */

.screen {
  position: absolute;
  inset: 0;
  z-index: 45;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.soot { position: absolute; inset: 0; background: rgba(20, 16, 13, 0.84); z-index: -1; }

/* Title */
.title-screen {
  z-index: 26;
  justify-content: flex-start;
  padding: 2vh 14px calc(var(--hud-h) + 22px);
}
.title-scrim { position: absolute; inset: 0; background: rgba(20, 16, 13, 0.3); z-index: -1; }
.marquee {
  width: min(80vw, 760px);
  max-height: 29vh;
  object-fit: contain;
  filter: drop-shadow(6px 7px 0 rgba(10, 8, 6, 0.55));
  animation: marquee-in 700ms cubic-bezier(0.2, 1.3, 0.4, 1) both;
}
@keyframes marquee-in {
  from { opacity: 0; transform: translateY(-46px) scale(0.95); }
  to { opacity: 1; transform: none; }
}
.title-copy {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(5px, 1.2vh, 12px);
  margin-top: clamp(2px, 1.6vh, 18px);
  width: min(580px, 82vw);
  padding: 8px 14px 10px;
  background: rgba(20, 16, 13, 0.72);
  border: 2px solid var(--black);
  box-shadow: inset 0 0 0 2px rgba(110, 92, 74, 0.9);
}
.title-kicker {
  font-family: "Archivo", sans-serif;
  font-weight: 700;
  font-size: clamp(9px, 1.8vw, 13px);
  letter-spacing: 0.28em;
  color: var(--amber);
  text-align: center;
  text-shadow: 2px 2px 0 var(--black);
}
.arcade-btn {
  position: relative;
  width: clamp(94px, 20vw, 148px);
  aspect-ratio: 302 / 275;
  display: block;
  filter: drop-shadow(0 5px 0 rgba(8, 6, 4, 0.6));
  transition: transform 90ms ease;
}
.arcade-btn img { display: block; width: 100%; height: 100%; object-fit: contain; animation: cap-pulse 1.9s ease-in-out infinite; }
.arcade-btn span {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-bottom: 30%;
  font-family: "Bowlby One SC", sans-serif;
  font-size: clamp(15px, 3.2vw, 24px);
  color: #2B2420;
  text-shadow: 1px 1px 0 rgba(246, 231, 201, 0.35);
  pointer-events: none;
}
.arcade-btn:active { transform: translateY(3px) scale(0.98); }
.arcade-btn.small { width: clamp(80px, 16vw, 116px); }
.arcade-btn.small span { font-size: clamp(12px, 2.4vw, 17px); }
@keyframes cap-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.035); }
}
.title-best {
  font-family: "Archivo", sans-serif;
  font-weight: 600;
  font-size: clamp(9px, 1.7vw, 12px);
  letter-spacing: 0.2em;
  color: var(--steel);
  text-shadow: 1px 1px 0 var(--black);
}
.title-best b { font-family: "Martian Mono", monospace; color: var(--bone); letter-spacing: 0.04em; }
.title-controls {
  position: static;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 14px;
  max-width: min(680px, 84vw);
  margin-top: 2px;
  font-family: "Archivo", sans-serif;
  font-weight: 600;
  font-size: clamp(8px, 1.5vw, 11px);
  letter-spacing: 0.14em;
  color: #cdbca2;
  text-shadow: 1px 1px 0 var(--black);
  text-align: center;
}
.title-screen #startBtn {
  position: absolute;
  right: clamp(16px, 6vw, 74px);
  bottom: calc(var(--hud-h) + clamp(14px, 3vh, 30px));
  width: clamp(86px, 18vw, 132px);
  z-index: 2;
}
.title-controls b { color: var(--bone); }

/* Upgrade */
.upgrade-screen { z-index: 46; justify-content: center; padding: max(14px, 3vh) 14px; }
.upgrade-heading {
  font-family: "Bowlby One SC", sans-serif;
  font-size: clamp(26px, 5.4vw, 46px);
  line-height: 1;
  color: var(--bone);
  text-shadow: 4px 4px 0 var(--rust), 7px 7px 0 rgba(20, 16, 13, 0.7);
  -webkit-text-stroke: 1.5px var(--black);
  text-align: center;
}
.upgrade-sub {
  margin-top: 6px;
  font-family: "Archivo", sans-serif;
  font-weight: 700;
  font-size: clamp(9px, 1.8vw, 12px);
  letter-spacing: 0.3em;
  color: var(--amber);
  text-align: center;
}
.cards {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(7px, 1.6vw, 20px);
  width: min(940px, 94vw);
  margin-top: clamp(12px, 2.6vh, 28px);
}
.up-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: clamp(6px, 1.2vw, 12px);
  background: #241d18;
  border: 3px solid var(--black);
  box-shadow: inset 0 0 0 2px var(--steel), 0 4px 0 rgba(8, 6, 4, 0.55);
  animation: card-slap 520ms cubic-bezier(0.16, 1.2, 0.3, 1) both;
  text-align: center;
  touch-action: manipulation;
}
.up-card:nth-child(2) { animation-delay: 110ms; }
.up-card:nth-child(3) { animation-delay: 220ms; }
@keyframes card-slap {
  0% { opacity: 0; transform: translateY(-120px) rotate(-5deg) scale(1.06); }
  55% { opacity: 1; }
  100% { opacity: 1; transform: none; }
}
.up-card img { width: 100%; height: auto; max-height: clamp(58px, 13vh, 130px); object-fit: contain; filter: drop-shadow(0 3px 0 rgba(8, 6, 4, 0.6)); }
.up-text { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.up-name {
  font-family: "Bowlby One SC", sans-serif;
  font-size: clamp(10px, 1.55vw, 16px);
  line-height: 1.05;
  color: var(--bone);
  text-shadow: 2px 2px 0 var(--black);
}
.up-desc {
  font-family: "Archivo", sans-serif;
  font-weight: 700;
  font-size: clamp(7px, 1.05vw, 10px);
  letter-spacing: 0.1em;
  color: #d9b98f;
  line-height: 1.2;
}
.up-num {
  position: absolute;
  top: -10px;
  left: -10px;
  width: clamp(22px, 4.6vw, 32px);
  height: clamp(22px, 4.6vw, 32px);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--amber);
  border: 3px solid var(--black);
  box-shadow: inset 0 0 0 2px #f8c078;
  color: #2b1a0d;
  font-family: "Martian Mono", monospace;
  font-weight: 700;
  font-size: clamp(10px, 1.8vw, 14px);
}
.up-card:hover, .up-card:focus-visible {
  transform: translateY(-4px);
  box-shadow: inset 0 0 0 2px var(--amber), 0 7px 0 rgba(8, 6, 4, 0.55);
  outline: none;
}
.up-card.picked { animation: card-weld 260ms ease-out both; }
@keyframes card-weld {
  0% { transform: scale(1); filter: brightness(1); }
  40% { transform: scale(1.04); filter: brightness(2.2) saturate(0.4); }
  100% { transform: scale(0.98); filter: brightness(2.6); }
}
.upgrade-hint {
  position: relative;
  z-index: 1;
  margin-top: clamp(12px, 2.4vh, 26px);
  font-family: "Archivo", sans-serif;
  font-weight: 600;
  font-size: clamp(8px, 1.5vw, 11px);
  letter-spacing: 0.24em;
  color: var(--steel);
  text-align: center;
}

@media (max-width: 620px) {
  .cards { display: flex; flex-direction: column; gap: 9px; width: min(430px, 92vw); margin-top: 10px; }
  .up-card { flex-direction: row; align-items: center; gap: 12px; padding: 6px 10px; text-align: left; }
  .up-card img { width: 78px; max-height: 66px; flex: 0 0 auto; }
  .up-text { display: flex; flex-direction: column; gap: 3px; flex: 1 1 auto; min-width: 0; align-items: flex-start; }
  .up-name { font-size: clamp(14px, 4.2vw, 18px); }
  .up-desc { font-size: clamp(9px, 2.4vw, 11px); }
  .up-num { top: 50%; left: auto; right: 8px; transform: translateY(-50%); width: 24px; height: 24px; font-size: 11px; }
}

/* Pause */
.pause-screen { z-index: 47; }
.pause-title {
  font-family: "Bowlby One SC", sans-serif;
  font-size: clamp(38px, 9vw, 86px);
  color: var(--bone);
  text-shadow: 5px 5px 0 var(--rust), 9px 9px 0 rgba(20, 16, 13, 0.7);
  -webkit-text-stroke: 2px var(--black);
}
.pause-help {
  margin-top: 12px;
  font-family: "Archivo", sans-serif;
  font-weight: 600;
  font-size: clamp(8px, 1.45vw, 11px);
  letter-spacing: 0.13em;
  color: #cdbca2;
  text-align: center;
  text-shadow: 1px 1px 0 var(--black);
}
.pause-help b { color: var(--bone); }
.pause-sub {
  margin-top: 6px;
  font-family: "Archivo", sans-serif;
  font-weight: 700;
  font-size: clamp(9px, 1.8vw, 12px);
  letter-spacing: 0.3em;
  color: var(--amber);
}
.pause-actions { display: flex; align-items: center; gap: clamp(14px, 4vw, 34px); margin-top: clamp(18px, 4vh, 40px); }
.plate-btn {
  padding: 12px 20px;
  background: #241d18;
  border: 3px solid var(--black);
  box-shadow: inset 0 0 0 2px var(--steel), 0 3px 0 rgba(8, 6, 4, 0.55);
  color: var(--bone);
  font-family: "Archivo", sans-serif;
  font-weight: 700;
  font-size: clamp(10px, 1.9vw, 13px);
  letter-spacing: 0.18em;
}
.plate-btn:active { transform: translateY(2px); }

/* End */
.end-screen { z-index: 48; }
.end-kicker {
  font-family: "Archivo", sans-serif;
  font-weight: 700;
  font-size: clamp(10px, 2vw, 14px);
  letter-spacing: 0.34em;
  color: var(--amber);
  text-shadow: 2px 2px 0 var(--black);
}
.end-title {
  margin: 4px 0 0;
  font-family: "Bowlby One SC", sans-serif;
  font-weight: 400;
  font-size: clamp(44px, 11vw, 110px);
  line-height: 0.94;
  color: var(--bone);
  text-shadow: 6px 6px 0 var(--rust), 10px 10px 0 rgba(20, 16, 13, 0.7);
  -webkit-text-stroke: 2px var(--black);
  text-align: center;
}
.end-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: clamp(6px, 1.6vw, 16px);
  margin-top: clamp(12px, 2.6vh, 28px);
}
.end-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: clamp(88px, 22vw, 150px);
  padding: 8px 14px;
  background: #241d18;
  border: 3px solid var(--black);
  box-shadow: inset 0 0 0 2px var(--steel);
}
.end-stat span {
  font-family: "Archivo", sans-serif;
  font-weight: 700;
  font-size: clamp(8px, 1.5vw, 10px);
  letter-spacing: 0.24em;
  color: var(--amber);
}
.end-stat b {
  font-family: "Martian Mono", monospace;
  font-weight: 700;
  font-size: clamp(16px, 3.2vw, 26px);
  color: var(--bone);
  letter-spacing: 0.03em;
}
.end-best {
  margin: clamp(8px, 1.6vh, 16px) 0 0;
  font-family: "Archivo", sans-serif;
  font-weight: 600;
  font-size: clamp(8px, 1.5vw, 11px);
  letter-spacing: 0.18em;
  color: var(--steel);
  min-height: 1em;
}
.end-screen .arcade-btn { margin-top: clamp(12px, 2.6vh, 26px); }

/* Loading */
.loading {
  position: absolute;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--black);
  color: var(--amber);
  font-family: "Archivo", sans-serif;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 0.34em;
  transition: opacity 260ms linear;
}
.loading.gone { opacity: 0; pointer-events: none; }

/* Narrow adjustments */
@media (max-width: 560px) {
  .hud { padding: 0 5px calc(5px + env(safe-area-inset-bottom)); }
  .hud-plate { gap: 6px; padding: 6px 7px; }
  .hud-bust { width: calc(var(--hud-h) * 0.6); }
  .hud-row { height: clamp(26px, 3.6vh, 32px); }
  .score-window { font-size: clamp(10px, 3vw, 14px); }
  .wave-window { font-size: clamp(12px, 3.2vw, 15px); }
  .mini-plate { min-width: 31px; font-size: 8px; }
  .pause-btn { width: 32px; }
  .title-controls { gap: 4px 10px; }
  .marquee { width: min(88vw, 520px); max-height: 25vh; }
}

@media (max-height: 500px) and (orientation: landscape) {
  :root { --hud-h: 92px; }
  .title-screen { padding-top: 6px; }
  .marquee { max-height: 40vh; width: min(42vw, 400px); }
  .title-copy { margin-top: 2px; gap: 4px; width: min(62vw, 540px); }
  .title-screen #startBtn { right: 12px; width: clamp(80px, 14vw, 112px); }
  .title-controls { bottom: calc(var(--hud-h) + 4px); }
  .up-card img { max-height: 76px; }
  .end-title { font-size: clamp(38px, 9vh, 76px); }
}

@media (prefers-reduced-motion: reduce) {
  .arcade-btn img, .marquee { animation: none; }
  .up-card { animation-duration: 1ms; }
}
