:root {
  --bg: #07050c;
  --ink: #f2eefa;
  --dim: #9a94b4;
  --panel: rgba(18, 12, 30, 0.88);
  --edge: #3a2c58;
  --gold: #ffd84a;
  --red: #ff3b4a;
  --blue: #7cc8ff;
  --violet: #c684ff;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  overscroll-behavior: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Pixelify Sans", ui-monospace, monospace;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
#stage { position: fixed; inset: 0; display: grid; place-items: center; }
#screen { image-rendering: pixelated; image-rendering: crisp-edges; display: block; }

.hidden { display: none !important; }

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: radial-gradient(ellipse at center, rgba(10, 6, 20, 0.55), rgba(4, 2, 10, 0.9));
  text-align: center;
  padding: 16px;
}
#loading { background: var(--bg); }
h1 {
  font-size: clamp(36px, 7vw, 72px);
  margin: 0;
  letter-spacing: 4px;
  color: var(--gold);
  text-shadow: 0 4px 0 #6a2a08, 0 0 28px rgba(255, 160, 40, 0.45);
}
h2 { font-size: clamp(26px, 4vw, 40px); margin: 0; color: var(--gold); text-shadow: 0 3px 0 #6a2a08; letter-spacing: 2px; }
.sub { font-size: 20px; margin: 0; }
.dim { color: var(--dim); margin: 0; }
.small { font-size: 13px; }
.blue { color: var(--blue); }
.gold { color: var(--gold); }
.help { max-width: 560px; line-height: 1.5; font-size: 16px; }
.help p { margin: 6px 0; }
.credit { position: absolute; bottom: 12px; font-size: 13px; color: var(--dim); }
.credit a { color: var(--violet); }

.progress { width: min(320px, 80vw); height: 12px; border: 2px solid var(--edge); background: #120c1e; }
#loadfill { height: 100%; width: 0; background: linear-gradient(90deg, #f2561d, #ffd84a); }

.btn {
  font: inherit;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 2px;
  color: #1a0c04;
  background: var(--gold);
  border: none;
  padding: 10px 28px;
  box-shadow: 0 4px 0 #8a4a0c, 0 0 24px rgba(255, 200, 60, 0.35);
  cursor: pointer;
}
.btn:hover { filter: brightness(1.12); transform: translateY(-1px); }
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #8a4a0c; }
.btn.ghost { background: transparent; color: var(--dim); box-shadow: none; border: 2px solid var(--edge); font-size: 16px; }

/* HUD */
#hud { position: absolute; inset: 0; pointer-events: none; }
#xpbar { position: absolute; top: 0; left: 0; right: 0; height: 14px; background: #0c0818; border-bottom: 2px solid #241a3a; }
#xpfill { height: 100%; width: 0; background: linear-gradient(180deg, #7cc8ff, #1f56b8); transition: width 0.12s; }
#lvl { position: absolute; right: 8px; top: -1px; font-size: 13px; font-weight: 700; text-shadow: 0 1px 0 #000; }
#topline { position: absolute; top: calc(20px + env(safe-area-inset-top)); left: calc(12px + env(safe-area-inset-left)); right: calc(12px + env(safe-area-inset-right)); display: flex; justify-content: space-between; align-items: flex-start; }
#hp { position: relative; width: 180px; height: 16px; background: #2a0810; border: 2px solid #140c1c; }
#hpfill { height: 100%; background: linear-gradient(180deg, #ff6a74, #c01c2c); width: 100%; }
#hptext { position: absolute; inset: 0; font-size: 12px; text-align: center; line-height: 13px; text-shadow: 0 1px 0 #000; }
#timer { font-size: 28px; font-weight: 700; text-shadow: 0 2px 0 #000; }
#counters { display: flex; gap: 14px; font-size: 18px; text-shadow: 0 2px 0 #000; }
#coins { color: var(--gold); }
#slots { position: absolute; top: calc(46px + env(safe-area-inset-top)); left: calc(12px + env(safe-area-inset-left)); display: flex; flex-direction: column; gap: 4px; }
#wslots, #pslots { display: flex; gap: 4px; }
.slot { position: relative; width: 30px; height: 30px; background: var(--panel); border: 2px solid var(--edge); }
.slot canvas { width: 100%; height: 100%; image-rendering: pixelated; }
.slot b { position: absolute; right: 1px; bottom: -3px; font-size: 11px; text-shadow: 0 1px 0 #000, 0 0 3px #000; }
#pslots .slot { width: 24px; height: 24px; }
#bossbar { position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%); width: min(520px, 80vw); height: 16px; background: #1a0408; border: 2px solid #3a0a14; }
#bossfill { height: 100%; background: linear-gradient(180deg, #ff4a56, #8a1222); width: 100%; }
#bossname { position: absolute; top: -22px; left: 0; right: 0; text-align: center; font-size: 16px; color: #ff8a8e; text-shadow: 0 2px 0 #000; }
#banner {
  position: absolute; top: 22%; left: 0; right: 0; text-align: center;
  font-size: clamp(20px, 3.4vw, 34px); font-weight: 700; color: var(--gold);
  text-shadow: 0 3px 0 #000, 0 0 20px rgba(255, 120, 40, 0.6);
  opacity: 0; transition: opacity 0.25s; padding: 0 16px;
}
#banner.show { opacity: 1; }
#banner.danger { color: #ff6a74; }

/* level up */
#cards { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; max-width: 960px; }
.card {
  width: 200px; padding: 14px 12px 16px;
  background: var(--panel); border: 2px solid var(--edge);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  cursor: pointer; transition: transform 0.1s, border-color 0.1s;
  animation: rise 0.25s ease-out both;
}
.card:hover, .card.sel { transform: translateY(-4px); border-color: var(--gold); box-shadow: 0 0 22px rgba(255, 200, 60, 0.3); }
.card canvas { width: 72px; height: 72px; image-rendering: pixelated; }
.card .name { font-size: 20px; font-weight: 700; }
.card .tag { font-size: 13px; color: var(--violet); }
.card .tag.new { color: var(--gold); }
.card .text { font-size: 15px; color: #d8d2ea; min-height: 40px; }
.card .key { font-size: 12px; color: var(--dim); }
@keyframes rise { from { opacity: 0; transform: translateY(16px); } }

#pauseinfo, #endstats { font-size: 18px; line-height: 1.6; }
#endstats .row { display: flex; gap: 24px; justify-content: center; }

#stick { position: absolute; width: 110px; height: 110px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.25); background: rgba(255, 255, 255, 0.05); pointer-events: none; transform: translate(-50%, -50%); }
#knob { position: absolute; left: 50%; top: 50%; width: 44px; height: 44px; margin: -22px; border-radius: 50%; background: rgba(255, 216, 74, 0.5); }

@media (max-width: 640px) {
  #hp { width: 110px; }
  #timer { font-size: 22px; }
  #counters { font-size: 14px; gap: 8px; }
  .card { width: 150px; }
  .card canvas { width: 56px; height: 56px; }
}

/* touch vs desktop hints */
.mob { display: none; }
body.touch .mob { display: inline; }
body.touch p.mob { display: block; }
body.touch .desk { display: none; }

#pausebtn {
  pointer-events: auto; font: inherit; font-size: 14px; color: var(--ink);
  background: var(--panel); border: 2px solid var(--edge); width: 34px; height: 30px; cursor: pointer; padding: 0;
}
#counters { align-items: center; }

/* phones: portrait or small landscape */
@media (max-width: 640px), (max-height: 480px) {
  h1 { font-size: clamp(30px, 9vw, 48px); letter-spacing: 2px; }
  .sub { font-size: 16px; }
  .help { font-size: 14px; }
  #topline { top: calc(18px + env(safe-area-inset-top)); }
  #hp { width: 96px; height: 14px; }
  #hptext { font-size: 10px; line-height: 11px; }
  #timer { font-size: 20px; }
  #counters { font-size: 13px; gap: 8px; }
  #slots { top: calc(40px + env(safe-area-inset-top)); }
  .slot { width: 24px; height: 24px; }
  #pslots .slot { width: 20px; height: 20px; }
  #cards { flex-direction: column; gap: 8px; width: min(420px, 94vw); }
  .card { width: 100%; flex-direction: row; text-align: left; padding: 10px; gap: 10px; flex-wrap: wrap; }
  .card canvas { width: 52px; height: 52px; flex: none; }
  .card .name { font-size: 17px; }
  .card .text { font-size: 13px; min-height: 0; flex-basis: 100%; }
  .card .key { display: none; }
  #levelup { gap: 8px; justify-content: flex-start; padding-top: calc(24px + env(safe-area-inset-top)); overflow-y: auto; }
}
@media (max-height: 480px) and (orientation: landscape) {
  #cards { flex-direction: row; width: auto; max-width: 96vw; }
  .card { width: 30vw; flex-direction: column; text-align: center; }
  .card .text { flex-basis: auto; }
  .credit { display: none; }
}
