:root {
  --bg-dark: #0e0a16;
  --panel-bg: #1c1528;
  --panel-mid: #281e3a;
  --border-gold: #e6b83a;
  --border-gold-dark: #7a5214;
  --pepto: #ff7cc8;
  --pepto-deep: #c4368a;
  --toxic: #7cf052;
  --toxic-dark: #257a2e;
  --crimson: #e83b4b;
  --text: #f6f2ff;
  --muted: #b2a6cc;
}

* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-dark);
  color: var(--text);
  font-family: 'Press Start 2P', 'Courier New', monospace;
  image-rendering: pixelated;
}

img, canvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#game-root {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: #0b0812;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}

/* Gothic Stepped Pixel Box Frame */
.pixel-panel {
  background: linear-gradient(180deg, #271d3a 0%, #161022 100%);
  border: 3px solid var(--border-gold);
  box-shadow:
    0 0 0 3px #120c1c,
    inset 0 0 0 3px #422e14,
    0 12px 32px rgba(0, 0, 0, 0.8);
}

.pixel-btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 12px;
  letter-spacing: 0.5px;
  color: #fff;
  background: linear-gradient(180deg, #4f3a75 0%, #2e2049 100%);
  border: 3px solid var(--border-gold);
  box-shadow: 0 4px 0 #140c1f, inset 0 2px 0 rgba(255,255,255,0.22);
  padding: 10px 18px;
  cursor: pointer;
  text-transform: uppercase;
  text-shadow: 2px 2px 0 #12091b;
  transition: transform 0.06s, filter 0.1s;
}
.pixel-btn:hover {
  filter: brightness(1.18);
  transform: translateY(-1px);
}
.pixel-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #140c1f;
}
.pixel-btn.primary {
  background: linear-gradient(180deg, #d9366a 0%, #8e1940 100%);
  border-color: #ffe374;
  font-size: 15px;
  padding: 14px 28px;
}
.pixel-btn.toxic {
  background: linear-gradient(180deg, #3ea832 0%, #1d611c 100%);
  border-color: #a4ff70;
}
.pixel-btn.small {
  font-size: 10px;
  padding: 7px 12px;
}
.pixel-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: grayscale(0.7);
}

/* ==================== TITLE & MENU OVERLAY ==================== */
.screen-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 20;
}
.hidden {
  display: none !important;
}

#title-screen {
  background-color: #0d0816;
  background-image:
    radial-gradient(ellipse at center, rgba(16, 10, 28, 0.25) 0%, rgba(8, 5, 14, 0.88) 100%),
    url('assets/title-bg.png');
  background-size: cover;
  background-position: center;
  padding: 10px 14px;
  overflow-y: auto;
  justify-content: center;
}

.title-banner {
  text-align: center;
  margin-top: 4px;
  margin-bottom: 10px;
}
.title-main {
  font-size: clamp(20px, 3.4vw, 40px);
  line-height: 1.2;
  margin: 0;
  color: #ffe46e;
  text-shadow:
    0 4px 0 #7a2d12,
    0 7px 0 #1c0814,
    0 0 26px rgba(124, 240, 82, 0.55);
  letter-spacing: 2px;
}
.title-main .drip {
  color: #88f754;
  text-shadow:
    0 4px 0 #1c5e20,
    0 7px 0 #0c1c10,
    0 0 22px rgba(136, 247, 84, 0.7);
}
.title-sub {
  font-size: 9.5px;
  color: var(--pepto);
  margin-top: 5px;
  text-shadow: 2px 2px 0 #16091f;
  letter-spacing: 1.5px;
}

.menu-grid {
  display: grid;
  grid-template-columns: 1.25fr 0.95fr;
  gap: 12px;
  width: min(1000px, 96vw);
  margin-bottom: 10px;
}

@media (max-width: 820px) {
  .menu-grid { grid-template-columns: 1fr; }
}

.menu-box {
  padding: 11px 12px;
}
.menu-box h3 {
  margin: 0 0 8px 0;
  font-size: 10.5px;
  color: #ffe46e;
  text-shadow: 2px 2px 0 #0d0816;
  border-bottom: 2px solid #4c366b;
  padding-bottom: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.char-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.char-list.five-col {
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}
@media (max-width: 900px) {
  .char-list.five-col { grid-template-columns: repeat(3, 1fr); }
}

.char-card {
  background: rgba(18, 12, 29, 0.92);
  border: 3px solid #4b396b;
  padding: 5px;
  cursor: pointer;
  text-align: center;
  transition: transform 0.08s, border-color 0.1s;
}
.char-card.locked {
  opacity: 0.72;
  border-color: #36294d;
}
.char-card.locked img.portrait {
  filter: grayscale(0.85) brightness(0.55);
}
.portrait-wrap {
  position: relative;
}
.lock-badge {
  position: absolute;
  inset: auto 2px 8px 2px;
  background: rgba(12, 8, 22, 0.9);
  border: 1px solid #ffe46e;
  color: #ffe46e;
  font-size: 7px;
  padding: 2px 3px;
}
.char-card:hover {
  border-color: var(--pepto);
  transform: translateY(-2px);
}
.char-card.selected {
  border-color: #ffe46e;
  background: linear-gradient(180deg, #372352 0%, #1d132e 100%);
  box-shadow: 0 0 16px rgba(255, 228, 110, 0.35);
}
.char-card img.portrait {
  width: 100%;
  max-height: 98px;
  aspect-ratio: 1 / 1;
  border: 2px solid #2b1f40;
  display: block;
  margin: 0 auto 5px auto;
  object-fit: cover;
}
.char-card .cname {
  font-size: 8px;
  color: #fff;
  margin-bottom: 3px;
}
.char-card .ctitle {
  font-size: 6.5px;
  color: var(--pepto);
  margin-bottom: 4px;
}
.char-card .cbonus {
  font-size: 6.2px;
  line-height: 1.4;
  color: var(--toxic);
}

.relic-section {
  margin-top: 8px;
  padding-top: 7px;
  border-top: 2px solid #3c2b59;
}
.relic-header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 7px;
  color: #ffe46e;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.relic-row {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}
.relic-pill {
  font-family: 'Press Start 2P', monospace;
  font-size: 6.5px;
  color: #e4dbf5;
  background: #140e22;
  border: 2px solid #4a3769;
  padding: 4px 6px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}
.relic-pill:hover { border-color: #8ef6ff; }
.relic-pill.selected {
  border-color: #ffe46e;
  background: #36214f;
  color: #ffe46e;
}
.relic-pill.locked {
  opacity: 0.52;
}

.stage-card.locked {
  opacity: 0.68;
}
.mod-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-top: 8px;
}
.mod-toggle {
  font-family: 'Press Start 2P', monospace;
  font-size: 7px;
  color: #cfc4e6;
  background: #140d21;
  border: 2px solid #4a3769;
  padding: 7px 6px;
  cursor: pointer;
}
.mod-toggle.active {
  border-color: #ff6262;
  background: linear-gradient(180deg, #5e1d2f 0%, #2d0e1a 100%);
  color: #ffe46e;
  box-shadow: 0 0 12px rgba(255, 98, 98, 0.35);
}

.char-detail-bar {
  margin-top: 8px;
  padding: 7px 9px;
  background: rgba(12, 8, 20, 0.85);
  border: 2px solid #3c2b59;
  font-size: 8px;
  line-height: 1.5;
  color: #dcd2f0;
  display: flex;
  align-items: center;
  gap: 10px;
}
.char-detail-bar .quote {
  color: #ffe46e;
  font-style: italic;
}

.stage-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.stage-card {
  background: rgba(18, 12, 29, 0.92);
  border: 3px solid #4b396b;
  padding: 8px 10px;
  cursor: pointer;
  transition: border-color 0.1s;
}
.stage-card:hover { border-color: var(--pepto); }
.stage-card.selected {
  border-color: var(--toxic);
  background: linear-gradient(90deg, #253b2c 0%, #19132b 100%);
  box-shadow: 0 0 14px rgba(124, 240, 82, 0.25);
}
.stage-card .sname {
  font-size: 10px;
  color: #fff;
  margin-bottom: 4px;
}
.stage-card .ssub {
  font-size: 8px;
  color: #ffe46e;
  margin-bottom: 5px;
}
.stage-card .sdesc {
  font-size: 7.5px;
  color: var(--muted);
  line-height: 1.5;
}

.menu-actions {
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 10px;
}
.gold-pill {
  background: rgba(16, 11, 24, 0.92);
  border: 2px solid var(--border-gold);
  padding: 8px 14px;
  font-size: 11px;
  color: #ffe46e;
  display: flex;
  align-items: center;
  gap: 8px;
}
.controls-hint {
  font-size: 8px;
  color: #c8bddf;
  background: rgba(12, 8, 22, 0.8);
  padding: 6px 12px;
  border: 1px solid #3c2c58;
  text-align: center;
}

/* ==================== POWERUP SHOP MODAL ==================== */
#shop-modal {
  background: rgba(8, 5, 14, 0.88);
  z-index: 30;
  padding: 16px;
}
.shop-box {
  width: min(820px, 95vw);
  max-height: 90vh;
  overflow-y: auto;
  padding: 18px;
}
.shop-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  border-bottom: 2px solid #4c366b;
  padding-bottom: 10px;
}
.shop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.shop-item {
  background: #140e21;
  border: 2px solid #4a3769;
  padding: 10px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.shop-item .pips {
  display: flex;
  gap: 4px;
}
.shop-item .pip {
  width: 10px;
  height: 10px;
  background: #2b2042;
  border: 1px solid #69528f;
}
.shop-item .pip.on {
  background: #88f754;
  border-color: #d8ffba;
}

/* ==================== IN-GAME HUD (Authentic VS Layout) ==================== */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

.xp-bar-wrap {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 20px;
  background: #120c1d;
  border-bottom: 3px solid #ffe46e;
  box-shadow: 0 3px 8px rgba(0,0,0,0.7);
}
#xp-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #2784e8 0%, #5ce8ff 65%, #ffffff 100%);
  transition: width 0.1s linear;
}
#level-badge {
  position: absolute;
  right: 10px;
  top: 3px;
  font-size: 10px;
  color: #fff;
  text-shadow: 2px 2px 0 #000;
}

.hud-top-row {
  position: absolute;
  top: 26px;
  left: 10px;
  right: 10px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.slots-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.slot-row {
  display: flex;
  gap: 4px;
}
.inv-slot {
  width: 34px;
  height: 34px;
  background: rgba(16, 11, 26, 0.85);
  border: 2px solid #59447a;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.inv-slot.evolved {
  border-color: #ffe46e;
  box-shadow: 0 0 8px rgba(255, 228, 110, 0.65);
  background: rgba(58, 34, 16, 0.9);
}
.inv-slot canvas {
  width: 26px;
  height: 26px;
}
.inv-slot .lv {
  position: absolute;
  right: 1px;
  bottom: 1px;
  font-size: 7px;
  color: #ffe46e;
  background: rgba(0, 0, 0, 0.8);
  padding: 1px 2px;
}

.hud-center {
  text-align: center;
}
#hud-timer {
  font-size: 20px;
  color: #fff;
  text-shadow: 3px 3px 0 #12081b, 0 0 12px rgba(255, 124, 200, 0.45);
}
#hud-wave-label {
  font-size: 8px;
  color: var(--pepto);
  margin-top: 4px;
  text-shadow: 2px 2px 0 #000;
}

.hud-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}
.hud-stats-line {
  display: flex;
  gap: 12px;
  font-size: 10px;
  background: rgba(14, 9, 22, 0.78);
  padding: 5px 10px;
  border: 2px solid #483566;
  text-shadow: 2px 2px 0 #000;
}
.hud-controls {
  display: flex;
  gap: 6px;
  pointer-events: auto;
}

/* Boss HP Bar */
#boss-bar-wrap {
  position: absolute;
  top: 86px;
  left: 50%;
  transform: translateX(-50%);
  width: min(460px, 82vw);
  text-align: center;
}
#boss-name {
  font-size: 10px;
  color: #ff6262;
  text-shadow: 2px 2px 0 #000;
  margin-bottom: 4px;
}
.boss-hp-outer {
  height: 14px;
  background: #1a0b12;
  border: 2px solid #ffe46e;
}
#boss-hp-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #a81024 0%, #ff4538 100%);
}

#banner-toast {
  position: absolute;
  top: 130px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 8, 28, 0.92);
  border: 3px solid #ff5252;
  color: #ffe46e;
  padding: 10px 20px;
  font-size: 12px;
  text-align: center;
  text-shadow: 2px 2px 0 #000;
  box-shadow: 0 0 24px rgba(255, 50, 70, 0.55);
  z-index: 15;
}

/* ==================== LEVEL UP MODAL ==================== */
#levelup-modal, #chest-modal, #pause-modal, #gameover-modal {
  background: rgba(8, 5, 16, 0.82);
  z-index: 25;
  padding: 16px;
}

.levelup-box {
  width: min(560px, 94vw);
  padding: 18px;
}
.levelup-title {
  text-align: center;
  font-size: 18px;
  color: #ffe46e;
  margin: 0 0 6px 0;
  text-shadow: 3px 3px 0 #1b0b26;
}
.levelup-sub {
  text-align: center;
  font-size: 9px;
  color: var(--pepto);
  margin-bottom: 14px;
}

.upgrade-choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.upgrade-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: linear-gradient(90deg, #271d3d 0%, #171026 100%);
  border: 3px solid #6e5696;
  padding: 12px;
  cursor: pointer;
  text-align: left;
  transition: transform 0.08s, border-color 0.1s;
}
.upgrade-card:hover {
  border-color: #ffe46e;
  transform: translateX(4px);
  background: linear-gradient(90deg, #3c2961 0%, #201536 100%);
}
.upgrade-card.evo-card {
  border-color: #ffe46e;
  background: linear-gradient(90deg, #4f2c12 0%, #241326 100%);
  box-shadow: 0 0 18px rgba(255, 210, 60, 0.4);
}
.upgrade-icon-box {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  background: #120b1f;
  border: 2px solid #967cc4;
  display: flex;
  align-items: center;
  justify-content: center;
}
.upgrade-icon-box canvas {
  width: 38px;
  height: 38px;
}
.upgrade-meta {
  flex: 1;
}
.upgrade-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.upgrade-name {
  font-size: 11px;
  color: #fff;
}
.upgrade-tag {
  font-size: 9px;
  padding: 3px 6px;
  background: #234d28;
  color: #9cff7a;
  border: 1px solid #76e35b;
}
.upgrade-tag.new {
  background: #611d49;
  color: #ff99d6;
  border-color: #ff7cc8;
}
.upgrade-tag.evo {
  background: #70490b;
  color: #fff08a;
  border-color: #ffe46e;
}
.upgrade-desc {
  font-size: 8.5px;
  line-height: 1.55;
  color: #d6cbe8;
}
.upgrade-hint {
  margin-top: 5px;
  font-size: 7.5px;
  color: #ffe46e;
}

/* ==================== CHEST MODAL ==================== */
.chest-box {
  width: min(520px, 94vw);
  padding: 20px;
  text-align: center;
}
.chest-rays {
  display: flex;
  justify-content: center;
  margin: 12px 0;
}
.chest-rewards {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 14px 0;
  text-align: left;
}
.chest-reward-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #140d21;
  border: 2px solid var(--border-gold);
  padding: 8px 10px;
  font-size: 9.5px;
  animation: popIn 0.25s ease-out both;
}
@keyframes popIn {
  from { transform: scale(0.8); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* ==================== PAUSE & GAMEOVER ==================== */
.summary-box {
  width: min(600px, 94vw);
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px;
  text-align: center;
}
.summary-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 14px 0;
}
.stat-tile {
  background: #130d21;
  border: 2px solid #483566;
  padding: 10px 6px;
}
.stat-tile .val {
  font-size: 13px;
  color: #ffe46e;
  margin-bottom: 4px;
}
.stat-tile .lbl {
  font-size: 7.5px;
  color: var(--muted);
}
.dmg-table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0 18px 0;
  font-size: 8.5px;
  text-align: left;
}
.dmg-table th, .dmg-table td {
  padding: 6px 8px;
  border-bottom: 1px solid #35274d;
}
.dmg-table th {
  color: var(--pepto);
}
.evo-chart {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  margin: 12px 0 16px 0;
  text-align: left;
  font-size: 7.5px;
}
.evo-pair {
  background: #130d21;
  border: 1px solid #3c2c58;
  padding: 6px 8px;
  color: #d6cbe8;
}
.evo-pair b { color: #ffe46e; }

/* ==================== URGENCY METER (BOTTOM HUD) ==================== */
#urg-wrap {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  width: min(440px, 82vw);
  background: rgba(14, 9, 24, 0.86);
  border: 2px solid #59447a;
  padding: 6px 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.75);
}
.urg-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 8.5px;
  margin-bottom: 5px;
  text-shadow: 2px 2px 0 #000;
}
.urg-left {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #f6f2ff;
}
.urg-left b { color: #ffe46e; }
#urg-state { color: #88f754; }

.urg-bar-outer {
  position: relative;
  height: 14px;
  background: #181024;
  border: 2px solid #12091c;
  box-shadow: inset 0 0 0 1px #4c386e;
  overflow: hidden;
}
#urg-fill {
  height: 100%;
  width: 0%;
  background: repeating-linear-gradient(90deg, #7cf052 0 12px, #4eb832 12px 15px);
  transition: width 0.1s linear;
}
.urg-mark {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 70%;
  width: 2px;
  background: #ffe46e;
  box-shadow: 0 0 4px #000;
}

#urg-wrap.mid { border-color: #e6b83a; }
#urg-wrap.mid #urg-state { color: #ffe46e; }
#urg-wrap.mid #urg-fill {
  background: repeating-linear-gradient(90deg, #ffe46e 0 12px, #d19c26 12px 15px);
}

#urg-wrap.cramp {
  border-color: #f08a30;
  animation: urgShake 0.22s steps(2) infinite;
}
#urg-wrap.cramp #urg-state { color: #ff9e4a; }
#urg-wrap.cramp #urg-fill {
  background: repeating-linear-gradient(90deg, #d67628 0 12px, #8c4814 12px 15px);
}

#urg-wrap.imminent {
  border-color: #ff3b3b;
  box-shadow: 0 0 18px rgba(255, 59, 59, 0.7);
  animation: urgShake 0.12s steps(2) infinite;
}
#urg-wrap.imminent #urg-state { color: #ff5252; }
#urg-wrap.imminent #urg-fill {
  background: repeating-linear-gradient(90deg, #e83b3b 0 10px, #7a3614 10px 14px);
}

#urg-wrap.shame { border-color: #a6642e; }
#urg-wrap.shame #urg-state { color: #d98e4c; }

@keyframes urgShake {
  0% { transform: translateX(calc(-50% - 2px)); }
  100% { transform: translateX(calc(-50% + 2px)); }
}

/* ==================== UNLOCKS, LEVELUP FOOTER & 4-COL SUMMARY ==================== */
#unlocks-modal {
  background: rgba(8, 5, 14, 0.88);
  z-index: 30;
  padding: 16px;
}
.ach-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 8px;
}
.ach-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #140d21;
  border: 2px solid #3f2f5c;
  padding: 8px 10px;
}
.ach-row.done {
  border-color: #7cf052;
  background: linear-gradient(90deg, #1b3622 0%, #140d21 100%);
}
.ach-info { flex: 1; }
.ach-top {
  display: flex;
  justify-content: space-between;
  font-size: 8.5px;
  margin-bottom: 4px;
}
.ach-desc {
  font-size: 7px;
  color: #cfc4e6;
  line-height: 1.45;
}

.levelup-footer {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 12px;
}

.summary-stats.four-col {
  grid-template-columns: repeat(4, 1fr);
}
@media (max-width: 560px) {
  .summary-stats.four-col { grid-template-columns: repeat(2, 1fr); }
}

.end-unlocks {
  margin-top: 10px;
  padding: 8px 10px;
  background: #233b1e;
  border: 2px solid #88f754;
  color: #ffe46e;
  font-size: 8px;
  line-height: 1.5;
}
