:root {
  --bg-0: #060409;
  --bg-1: #100b1c;
  --purple: #9d4dff;
  --cyan: #4dd8ff;
  --amber: #ff9d2e;
  --yellow: #ffd23d;
  --green: #3dff8f;
  --red: #ff4d6d;
  --text: #e8e4f2;
  --dim: #8b83a8;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  background: radial-gradient(1200px 700px at 50% -10%, #241435 0%, var(--bg-1) 45%, var(--bg-0) 100%);
  color: var(--text);
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
}

#stage {
  position: relative;
  width: min(100vw - 20px, calc((100vh - 70px) * 3 / 2), 1080px);
  aspect-ratio: 3 / 2;
  border-radius: 14px;
  overflow: hidden;
  box-shadow:
    0 0 0 1px rgba(157, 77, 255, 0.25),
    0 0 40px rgba(157, 77, 255, 0.15),
    0 24px 80px rgba(0, 0, 0, 0.6);
  background: #0d0a16;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
}

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
  z-index: 5;
}

.hud-col { display: flex; flex-direction: column; gap: 6px; }
.hud-col.hud-right { align-items: flex-end; }

/* keep HUD clear of the 3-button topbar */
#hud .hud-col.hud-right { margin-right: 124px; }
.hud-mid { display: flex; flex-direction: column; align-items: center; gap: 6px; }

.hud-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 72px;
  padding: 3px 10px;
  border-radius: 8px;
  background: rgba(8, 6, 16, 0.55);
  border: 1px solid rgba(157, 77, 255, 0.2);
}

.hud-label {
  font-size: 9px;
  letter-spacing: 2px;
  color: var(--dim);
}

.hud-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--cyan);
  text-shadow: 0 0 10px rgba(77, 216, 255, 0.7);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.hud-lives-val { color: var(--red); text-shadow: 0 0 10px rgba(255, 77, 109, 0.7); }
.hud-gems-val { color: var(--cyan); }

.hud-hp {
  width: 110px;
  height: 10px;
  margin-top: 2px;
  border-radius: 5px;
  background: rgba(8, 6, 16, 0.7);
  border: 1px solid rgba(157, 77, 255, 0.25);
  overflow: hidden;
}

.hp-fill {
  height: 100%;
  width: 100%;
  border-radius: 4px;
  background: linear-gradient(90deg, #3dff8f, #a0ffb8);
  transition: width 0.15s ease;
}

.hud-combo {
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--yellow);
  text-shadow: 0 0 12px rgba(255, 210, 61, 0.9);
  animation: pulse 0.5s ease-in-out infinite alternate;
}

/* ---------- Boss bar ---------- */
#boss-bar {
  position: absolute;
  top: 64px;
  left: 24px;
  right: 24px;
  z-index: 5;
  pointer-events: none;
}

.boss-name {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 3px;
  color: var(--red);
  text-shadow: 0 0 8px rgba(255, 77, 109, 0.8);
  display: block;
  margin-bottom: 3px;
}

.boss-track {
  height: 7px;
  border-radius: 4px;
  background: rgba(8, 6, 16, 0.7);
  border: 1px solid rgba(255, 77, 109, 0.4);
  overflow: hidden;
}

.boss-fill {
  height: 100%;
  width: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, #ff2d55, #ff7a9d);
  box-shadow: 0 0 10px rgba(255, 45, 85, 0.8);
  transition: width 0.15s ease;
}

/* ---------- Top bar ---------- */
#topbar {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 8px;
  z-index: 6;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  text-decoration: none;
  border: 1px solid rgba(157, 77, 255, 0.3);
  background: rgba(8, 6, 16, 0.6);
  color: var(--cyan);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  transition: all 0.15s ease;
}

.icon-btn:hover {
  background: rgba(157, 77, 255, 0.2);
  box-shadow: 0 0 14px rgba(157, 77, 255, 0.4);
}

.icon-btn.muted { color: var(--dim); text-decoration: line-through; }

.back-link {
  color: var(--dim);
  font-size: 12px;
  letter-spacing: 1px;
  text-decoration: none;
  cursor: pointer;
}

.back-link:hover { color: var(--text); }

/* ---------- Overlays ---------- */
#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  background: rgba(5, 4, 12, 0.72);
  backdrop-filter: blur(4px);
}

#overlay.hidden { display: none; }

.screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
  padding: 24px;
  max-width: 460px;
  max-height: 100%;
  overflow-y: auto;
}

.screen.hidden { display: none; }

.logo {
  font-size: 54px;
  font-weight: 900;
  letter-spacing: 8px;
  line-height: 0.95;
  color: var(--purple);
  text-shadow:
    0 0 8px rgba(157, 77, 255, 0.9),
    0 0 30px rgba(157, 77, 255, 0.5);
}

.logo span {
  display: block;
  color: var(--amber);
  text-shadow:
    0 0 8px rgba(255, 157, 46, 0.9),
    0 0 30px rgba(255, 157, 46, 0.5);
}

.tagline { color: var(--dim); font-size: 14px; letter-spacing: 1px; }

.big {
  font-size: 36px;
  font-weight: 900;
  letter-spacing: 4px;
}

.over-title {
  color: var(--red);
  text-shadow: 0 0 12px rgba(255, 77, 109, 0.8);
}

.win-title {
  color: var(--green);
  text-shadow: 0 0 12px rgba(61, 255, 143, 0.8);
}

.shop-title {
  color: var(--amber);
  text-shadow: 0 0 12px rgba(255, 157, 46, 0.6);
  font-size: 30px;
}

.level-title {
  font-size: 42px;
  font-weight: 900;
  letter-spacing: 6px;
  color: var(--amber);
  text-shadow: 0 0 14px rgba(255, 157, 46, 0.7);
}

.level-name {
  font-size: 18px;
  letter-spacing: 3px;
  color: var(--text);
  text-transform: uppercase;
}

.final-score { font-size: 18px; color: var(--dim); }
.final-score span { color: var(--cyan); font-weight: 700; font-size: 22px; }

.new-record {
  color: var(--yellow);
  font-weight: 700;
  letter-spacing: 2px;
  animation: pulse 0.8s ease-in-out infinite alternate;
}

@keyframes pulse {
  from { opacity: 0.6; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1.03); }
}

/* ---------- Buttons ---------- */
.btn {
  padding: 12px 34px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--text);
  background: rgba(14, 10, 24, 0.8);
  border: 1px solid rgba(157, 77, 255, 0.4);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn:hover {
  border-color: var(--purple);
  box-shadow: 0 0 18px rgba(157, 77, 255, 0.4);
  transform: translateY(-1px);
}

.btn-primary {
  background: linear-gradient(135deg, rgba(157, 77, 255, 0.25), rgba(255, 157, 46, 0.18));
  border-color: var(--purple);
  color: #fff;
  box-shadow: 0 0 18px rgba(157, 77, 255, 0.25);
}

.btn-primary:hover { box-shadow: 0 0 28px rgba(157, 77, 255, 0.5); }

.btn-row { display: flex; gap: 12px; margin-top: 4px; }

/* ---------- Highscores ---------- */
.hs-wrap { width: 100%; max-width: 300px; }

.hs-title {
  font-size: 12px;
  letter-spacing: 3px;
  color: var(--dim);
  margin-bottom: 8px;
}

.hs-list {
  list-style: none;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.hs-list li {
  display: flex;
  justify-content: space-between;
  padding: 5px 12px;
  font-size: 14px;
  border-radius: 6px;
  background: rgba(14, 10, 24, 0.5);
  border: 1px solid rgba(157, 77, 255, 0.1);
  font-variant-numeric: tabular-nums;
}

.hs-list li .pos { color: var(--dim); margin-right: 10px; }
.hs-list li .ini { color: var(--amber); font-weight: 700; letter-spacing: 2px; }
.hs-list li .pts { color: var(--cyan); font-weight: 700; }
.hs-list li.empty { justify-content: center; color: var(--dim); }

/* ---------- Initials entry ---------- */
#hs-form, #win-form { display: flex; gap: 8px; }

#hs-input, #win-input {
  width: 84px;
  padding: 10px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 8px;
  text-align: center;
  text-transform: uppercase;
  color: var(--yellow);
  background: rgba(8, 6, 16, 0.8);
  border: 1px solid rgba(255, 210, 61, 0.4);
  border-radius: 10px;
  outline: none;
}

#hs-input:focus, #win-input:focus { box-shadow: 0 0 16px rgba(255, 210, 61, 0.35); }

.entry-label { color: var(--dim); font-size: 13px; letter-spacing: 1px; }

/* ---------- Shop ---------- */
.shop-floor {
  font-size: 14px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--dim);
}

.shop-gems {
  font-size: 16px;
  font-weight: 700;
  color: var(--cyan);
  text-shadow: 0 0 8px rgba(77, 216, 255, 0.5);
}

.shop-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  max-height: 44vh;
  overflow-y: auto;
  padding-right: 4px;
}

.shop-item {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  padding: 8px 14px;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: rgba(14, 10, 24, 0.6);
  border: 1px solid rgba(157, 77, 255, 0.2);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.shop-item:hover:not(.disabled) {
  border-color: var(--purple);
  box-shadow: 0 0 14px rgba(157, 77, 255, 0.35);
  transform: translateX(2px);
}

.shop-item.disabled { opacity: 0.45; cursor: default; }

.shop-icon {
  font-size: 20px;
  width: 30px;
  text-align: center;
  color: var(--amber);
  text-shadow: 0 0 8px rgba(255, 157, 46, 0.6);
}

.shop-mid {
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 2px;
}

.shop-name { font-weight: 700; letter-spacing: 1px; }
.shop-name em { font-style: normal; color: var(--dim); font-size: 11px; }
.shop-desc { color: var(--dim); font-size: 12px; }

.shop-cost {
  font-weight: 800;
  color: var(--cyan);
  letter-spacing: 1px;
  white-space: nowrap;
}

/* ---------- Misc ---------- */
.hint { color: var(--dim); font-size: 12px; letter-spacing: 1px; }

#footer {
  color: #4a4266;
  font-size: 11px;
  letter-spacing: 1px;
  text-align: center;
}

.hidden { display: none !important; }

@media (max-width: 700px) {
  .logo { font-size: 40px; letter-spacing: 5px; }
  .big { font-size: 28px; }
  .level-title { font-size: 32px; }
  .hud-value { font-size: 14px; }
  .hud-box { min-width: 58px; }
  #stage { width: min(100vw, calc((100vh - 60px) * 3 / 2)); border-radius: 0; }
}
