/* ============================================================
   Crusaders of Crypto — Pi Network Edition
   Retro dark-fantasy pixel theme
   ============================================================ */

:root {
  --bg-deep:    #0d0a14;
  --bg-stone:   #1a1426;
  --bg-panel:   #241b36;
  --bg-card:    #2e2344;
  --border-stone: #4a3b66;
  --gold:       #f2c94c;
  --gold-dark:  #b8901f;
  --rupee:      #34d399;
  --blood:      #e0455a;
  --mana:       #7f9cf5;
  --pi:         #8a3ffc;
  --pi-light:   #b07df7;
  --text:       #e8e2f4;
  --text-dim:   #9b8fb5;
  --font-pixel: 'Press Start 2P', monospace;
  --font-body:  'VT323', monospace;
}

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

html, body {
  height: 100%;
  background: var(--bg-deep);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 20px;
  -webkit-font-smoothing: none;
  overscroll-behavior: none;
}

#app { max-width: 560px; margin: 0 auto; min-height: 100dvh; position: relative; }

/* ---------- screens ---------- */
.screen { display: none; min-height: 100dvh; flex-direction: column; }
.screen.active { display: flex; }

/* ---------- buttons ---------- */
.btn {
  font-family: var(--font-pixel);
  font-size: 11px;
  color: var(--text);
  background: var(--bg-card);
  border: 3px solid var(--border-stone);
  border-radius: 6px;
  padding: 12px 16px;
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 1px;
  transition: transform .06s, filter .15s;
  touch-action: manipulation;
}
.btn:active { transform: translateY(2px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-gold  { background: linear-gradient(180deg, var(--gold), var(--gold-dark)); color: #241b00; border-color: #7c6011; }
.btn-pi    { background: linear-gradient(180deg, var(--pi-light), var(--pi)); color: #fff; border-color: #5b21b6; }
.btn-blood { background: linear-gradient(180deg, #f47187, var(--blood)); color: #2d060d; border-color: #8f1f30; }
.btn-stone { background: var(--bg-card); }
.btn-big   { font-size: 14px; padding: 18px 24px; }
.btn-small { font-size: 9px; padding: 8px 10px; }

/* ---------- title screen ---------- */
#screen-title {
  align-items: center; justify-content: center;
  background:
    radial-gradient(ellipse at 50% 20%, #2c1f4d 0%, transparent 55%),
    repeating-linear-gradient(0deg, #131020 0 42px, #171126 42px 44px),
    var(--bg-deep);
}
.title-wrap { text-align: center; padding: 24px; position: relative; width: 100%; }
.pixel-logo {
  image-rendering: pixelated;
  width: 96px; height: 96px;
  margin-bottom: 10px;
  filter: drop-shadow(0 6px 12px rgba(138, 63, 252, .4));
}
.game-logo { font-family: var(--font-pixel); line-height: 1.5; margin-bottom: 18px; }
.logo-line1 {
  display: block; font-size: clamp(16px, 5vw, 26px); color: var(--pi-light);
  text-shadow: 0 3px 0 #3c1a78, 0 6px 14px rgba(138, 63, 252, .45);
  letter-spacing: 6px;
}
.logo-line2 {
  display: block; font-size: clamp(26px, 8vw, 42px); color: var(--gold);
  text-shadow: 0 4px 0 #6b4e00, 0 8px 18px rgba(242, 201, 76, .35);
}
.tagline { color: var(--text-dim); font-size: 22px; margin-bottom: 34px; }
.title-buttons { display: flex; flex-direction: column; gap: 14px; align-items: center; }
.title-buttons .btn { width: min(320px, 80vw); }
.title-status { margin-top: 16px; color: var(--rupee); min-height: 24px; font-size: 18px; }
.version-tag { margin-top: 26px; color: var(--text-dim); opacity: .6; font-size: 16px; }
.title-torch {
  position: absolute; top: -10px; width: 22px; height: 34px; border-radius: 40% 40% 30% 30%;
  background: radial-gradient(circle at 50% 30%, #ffe08a 0 30%, #ff9d2e 55%, #d43d0c 100%);
  animation: flicker 480ms infinite alternate; filter: blur(.4px);
}
.title-torch.left  { left: 8%; }
.title-torch.right { right: 8%; }
@keyframes flicker {
  from { transform: scale(1) rotate(-2deg); opacity: .92; }
  to   { transform: scale(1.12) rotate(2deg); opacity: 1; }
}

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 14px;
  background: var(--bg-stone);
  border-bottom: 3px solid var(--border-stone);
  position: sticky; top: 0; z-index: 5;
}
.player-chip { display: flex; align-items: center; gap: 10px; }
.player-name { font-family: var(--font-pixel); font-size: 11px; color: var(--gold); }
.rupee-chip { font-size: 20px; color: var(--rupee); white-space: nowrap; }
.sub-title { font-family: var(--font-pixel); font-size: 12px; color: var(--gold); text-align: center; flex: 1; }

/* ---------- main menu ---------- */
#screen-menu { background: var(--bg-deep); }
.menu-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  padding: 16px; flex: 1; align-content: start;
}
.menu-card {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: linear-gradient(180deg, var(--bg-card), var(--bg-panel));
  border: 3px solid var(--border-stone); border-radius: 10px;
  padding: 18px 10px; cursor: pointer; color: var(--text);
  font-family: var(--font-body);
  transition: border-color .15s, transform .06s;
}
.menu-card:active { transform: scale(.97); }
.menu-card:hover { border-color: var(--gold); }
.menu-emoji { font-size: 34px; }
.menu-title { font-family: var(--font-pixel); font-size: 11px; color: var(--gold); }
.menu-sub { color: var(--text-dim); font-size: 16px; text-align: center; line-height: 1.15; }
.menu-footer { padding: 10px 16px 18px; color: var(--text-dim); font-size: 16px; text-align: center; }

/* ---------- sub screens ---------- */
.sub-content { padding: 14px; flex: 1; overflow-y: auto; }
.card-list { display: flex; flex-direction: column; gap: 10px; }
.item-card {
  display: flex; gap: 12px; align-items: center;
  background: var(--bg-panel); border: 2px solid var(--border-stone);
  border-radius: 8px; padding: 10px 12px;
}
.item-card .ic-emoji { font-size: 30px; width: 42px; text-align: center; flex-shrink: 0; }
.item-card .ic-body { flex: 1; min-width: 0; }
.item-card .ic-name { font-family: var(--font-pixel); font-size: 10px; margin-bottom: 4px; }
.item-card .ic-desc { color: var(--text-dim); font-size: 17px; line-height: 1.2; }
.item-card .ic-actions { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.price-tag { color: var(--rupee); font-size: 18px; white-space: nowrap; }
.price-tag.pi { color: var(--pi-light); }

.rarity-common    { color: #cbd5e1; }
.rarity-uncommon  { color: #4ade80; }
.rarity-rare      { color: #60a5fa; }
.rarity-epic      { color: #c084fc; }
.rarity-legendary { color: var(--gold); }

.section-head {
  font-family: var(--font-pixel); font-size: 11px; color: var(--pi-light);
  margin: 18px 0 10px; letter-spacing: 1px;
}
.section-head:first-child { margin-top: 0; }

/* hero picker */
.hero-card { border-width: 3px; }
.hero-card.selected { border-color: var(--gold); box-shadow: 0 0 14px rgba(242, 201, 76, .25); }
.stat-pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.stat-pill {
  font-size: 15px; background: var(--bg-stone); border: 1px solid var(--border-stone);
  padding: 2px 8px; border-radius: 20px; color: var(--text-dim);
}
.stat-pill b { color: var(--text); }

/* equipment grid */
.equip-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 10px 0; }
.equip-slot {
  aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--bg-panel); border: 2px dashed var(--border-stone); border-radius: 8px;
  font-size: 24px; cursor: pointer; gap: 2px;
}
.equip-slot.filled { border-style: solid; border-color: var(--gold-dark); }
.equip-slot .slot-label { font-size: 12px; color: var(--text-dim); }
.slot-icon { width: 24px; height: 24px; image-rendering: pixelated; opacity: .75; object-fit: contain; }

/* ---------- dungeon crawler ---------- */
#screen-dungeon { background: #151019; }
.crawl-wrap {
  position: relative; flex: 1; display: flex; flex-direction: column;
  height: 100dvh; overflow: hidden; touch-action: none;
}
#crawl-canvas {
  position: absolute; inset: 0; width: 100%; height: 100%;
  image-rendering: pixelated;
  background: #151019;
}

.crawl-hud {
  position: absolute; top: 10px; left: 10px; right: 10px; z-index: 4;
  display: flex; align-items: center; gap: 8px; pointer-events: none;
}
.hud-heart { font-size: 26px; filter: drop-shadow(0 2px 2px #000); }
.hud-heart img { width: 30px; height: 28px; image-rendering: pixelated; display: block; }
.pedia-icon { width: 42px; height: 42px; image-rendering: pixelated; object-fit: contain; }
.crawl-hpbar {
  position: relative; width: min(40vw, 178px); height: 18px;
  border: 2px solid #0d0a14; border-radius: 3px;
  background: #3a0a12; overflow: hidden;
  box-shadow: 0 2px 4px rgba(0,0,0,.6), inset 0 0 0 1px #6b4a2a;
}
.crawl-hpfill {
  height: 100%; width: 100%;
  background: url('../assets/sprites/hpbar_fill.png') repeat-x, linear-gradient(180deg, #ff4d5e, #c11226);
  background-size: auto 100%;
  image-rendering: pixelated;
  transition: width .25s;
}
.rupee-icon { width: 18px; height: 18px; image-rendering: pixelated; vertical-align: -3px; }
.crawl-hpbar span {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 12px; color: #fff; text-shadow: 0 1px 2px #000; font-family: var(--font-pixel); font-size: 8px;
}
.crawl-floor { font-family: var(--font-pixel); font-size: 11px; color: var(--gold); text-shadow: 0 2px 2px #000; margin-left: auto; }
.crawl-hud .rupee-chip { text-shadow: 0 2px 2px #000; }

.crawl-status {
  position: absolute; top: 40px; left: 12px; z-index: 4;
  font-size: 15px; color: var(--text); text-shadow: 0 1px 2px #000; pointer-events: none;
}

.crawl-side {
  position: absolute; right: 10px; bottom: 24%; z-index: 4;
  display: flex; flex-direction: column; gap: 10px;
}
.side-btn {
  width: 48px; height: 48px; font-size: 20px; cursor: pointer;
  background: url('../assets/sprites/btn_wood.png') no-repeat center / 100% 100%,
              linear-gradient(180deg, #7c5a34, #55381c);
  image-rendering: pixelated;
  border: none; border-radius: 6px;
  filter: drop-shadow(0 3px 4px rgba(0,0,0,.5));
  transition: transform .06s;
}
.side-btn:active { transform: scale(.92); }

.crawl-log {
  position: absolute; left: 10px; bottom: calc(24% + 4px); z-index: 3;
  max-width: 62vw; font-size: 15px; line-height: 1.25;
  text-shadow: 0 1px 2px #000, 0 0 4px #000; pointer-events: none;
}
.crawl-log p { margin: 0 0 2px; }
.log-hero { color: #7ce8a8; }
.log-foe  { color: #ff8a97; }
.log-gold { color: var(--gold); }
.log-sys  { color: #c9bfdd; }
.log-crit { color: var(--gold); font-weight: bold; }

/* full log overlay panel (original "COMBAT LOG" window) */
.log-overlay {
  max-height: 50dvh; overflow-y: auto; font-size: 17px; line-height: 1.3;
  background: rgba(10, 8, 16, .92); border: 2px solid var(--border-stone);
  border-radius: 6px; padding: 10px;
}

/* D-pad (original cross-shaped pad, bottom center) */
.dpad {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: calc(12px + env(safe-area-inset-bottom));
  display: grid; z-index: 4;
  grid-template-areas: ". up ." "left wait right" ". down .";
  gap: 0;
  background: url('../assets/sprites/dpad.png') no-repeat center / contain;
  image-rendering: pixelated;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,.55));
  padding: 2px;
}
.dpad-btn {
  width: 56px; height: 56px; font-size: 20px; color: transparent; cursor: pointer;
  background: transparent; border: none;
  touch-action: none; user-select: none;
}
.dpad-btn:active { background: radial-gradient(circle, rgba(255,220,150,.28) 0%, transparent 70%); }
.dpad-btn:active { transform: scale(.92); filter: brightness(1.2); }
.dpad-up { grid-area: up; } .dpad-left { grid-area: left; }
.dpad-right { grid-area: right; } .dpad-down { grid-area: down; }
.dpad-wait { grid-area: wait; font-size: 14px; opacity: .8; }

@media (min-width: 700px) {
  .dpad { opacity: .45; }
  .dpad:hover { opacity: 1; }
}

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(6, 4, 12, .82);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 18px;
}
.modal-backdrop.hidden { display: none; }
.modal {
  width: min(440px, 100%); max-height: 84dvh; overflow-y: auto;
  background: var(--bg-panel); border: 3px solid var(--gold-dark);
  border-radius: 12px; padding: 20px;
}
.modal h3 { font-family: var(--font-pixel); font-size: 13px; color: var(--gold); margin-bottom: 14px; text-align: center; }
.modal p { margin-bottom: 10px; line-height: 1.3; }
.modal .modal-actions { display: flex; gap: 10px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.modal .big-emoji { font-size: 56px; text-align: center; display: block; margin-bottom: 10px; }

/* ---------- toasts ---------- */
.toast-stack {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 90; width: min(420px, 92vw);
}
.toast {
  background: var(--bg-card); border: 2px solid var(--gold-dark); border-radius: 8px;
  padding: 10px 14px; font-size: 18px; text-align: center;
  animation: toastin .25s;
}
@keyframes toastin { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; } }

/* ---------- leaderboard ---------- */
.lb-tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.lb-tabs .btn { flex: 1; }
.lb-tabs .btn.active { border-color: var(--gold); color: var(--gold); }
.lb-row {
  display: flex; align-items: center; gap: 12px; padding: 8px 12px;
  background: var(--bg-panel); border: 2px solid var(--border-stone); border-radius: 8px;
}
.lb-rank { font-family: var(--font-pixel); font-size: 11px; color: var(--text-dim); width: 34px; }
.lb-row:nth-child(1) .lb-rank { color: var(--gold); }
.lb-row:nth-child(2) .lb-rank { color: #cbd5e1; }
.lb-row:nth-child(3) .lb-rank { color: #d97706; }
.lb-name { flex: 1; font-size: 20px; }
.lb-score { color: var(--rupee); font-size: 20px; }

/* ---------- misc ---------- */
.dim { color: var(--text-dim); }
.gold { color: var(--gold); }
.center { text-align: center; }
.mt { margin-top: 14px; }
.hr { border: none; border-top: 2px solid var(--border-stone); margin: 14px 0; }

@media (min-width: 561px) {
  #app { border-left: 3px solid var(--border-stone); border-right: 3px solid var(--border-stone); }
}
