/* Relic Raider — 16-Bit Subterranean Adventure Styles */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-deep: #120c08;
  --bg-panel: #1f1610;
  --bg-card: #1b130e;
  --border-gold: rgba(245, 158, 11, 0.34);
  --border-soft: rgba(214, 180, 130, 0.22);
  --text-main: #f8f1e4;
  --text-dim: #bba88d;
  --gold: #fbbf24;
  --amber: #f59e0b;
  --emerald: #34d399;
  --crimson: #f87171;
  --cyan: #38bdf8;
}

html, body {
  width: 100%;
  height: 100%;
  max-width: 100vw;
  overflow: hidden;
  background: var(--bg-deep);
  color: var(--text-main);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

.app-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100dvh;
  max-width: 100vw;
  overflow: hidden;
  background: radial-gradient(circle at 50% 20%, #2a1b12 0%, #120c08 75%);
}

/* HUD Bar */
.hud-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  background: linear-gradient(180deg, #271a11 0%, #1a110b 100%);
  border-bottom: 1px solid var(--border-gold);
  flex-shrink: 0;
  z-index: 20;
  max-width: 100vw;
  overflow: hidden;
}

.hud-group {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.hud-stats {
  flex-wrap: nowrap;
  overflow: hidden;
}

.hud-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 7px;
  background: rgba(12, 8, 5, 0.72);
  border: 1px solid var(--border-soft);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.02em;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.hud-hp { border-color: rgba(248, 113, 113, 0.4); color: #fecaca; }
.hud-bombs { border-color: rgba(251, 146, 60, 0.4); color: #fed7aa; }
.hud-ropes { border-color: rgba(217, 179, 122, 0.4); color: #fde68a; }
.hud-gold { border-color: rgba(251, 191, 36, 0.5); color: var(--gold); }
.hud-floor { border-color: rgba(56, 189, 248, 0.45); color: #bae6fd; }

.hud-ico { font-size: 13px; line-height: 1; }

.hud-gear {
  gap: 4px;
  flex-shrink: 1;
}

.gear-chip {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(52, 211, 153, 0.14);
  border: 1px solid rgba(52, 211, 153, 0.4);
  color: #a7f3d0;
  white-space: nowrap;
}

.hud-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 30px;
  padding: 0 10px;
  border-radius: 7px;
  border: 1px solid var(--border-gold);
  background: rgba(45, 30, 18, 0.9);
  color: var(--text-main);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.12s ease, background-color 0.12s ease, border-color 0.12s ease;
}

.hud-btn.icon-only {
  width: 30px;
  padding: 0;
  font-size: 14px;
}

.hud-btn:hover {
  background: rgba(74, 48, 25, 0.95);
  border-color: var(--gold);
  transform: translateY(-1px);
}

/* Main Stage & Canvas */
.stage-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #0d0906;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #120c08;
}

.banner-toast {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  padding: 7px 16px;
  border-radius: 999px;
  background: rgba(20, 12, 8, 0.92);
  border: 1.5px solid var(--gold);
  color: #fef3c7;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
  pointer-events: none;
  z-index: 15;
  white-space: nowrap;
  max-width: calc(100% - 20px);
  overflow: hidden;
  text-overflow: ellipsis;
}

.banner-toast.danger {
  border-color: var(--crimson);
  background: rgba(65, 14, 14, 0.94);
  color: #fee2e2;
}

.shop-prompt {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  padding: 7px 14px;
  border-radius: 10px;
  background: rgba(20, 14, 9, 0.94);
  border: 1.5px solid var(--gold);
  color: #fef3c7;
  font-size: 12.5px;
  font-weight: 700;
  z-index: 15;
  text-align: center;
  max-width: calc(100% - 24px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.55);
  pointer-events: none;
}

/* Footer */
.footer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 10px;
  padding-bottom: max(5px, env(safe-area-inset-bottom));
  background: #17100b;
  border-top: 1px solid var(--border-soft);
  font-size: 11.5px;
  color: var(--text-dim);
  flex-shrink: 0;
  z-index: 20;
  max-width: 100vw;
  overflow: hidden;
}

.footer-keys {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.footer-keys b { color: #fde68a; }

.footer-meta {
  white-space: nowrap;
  font-weight: 700;
  color: #fcd34d;
  flex-shrink: 0;
}

/* Touch Controls */
.touch-controls {
  display: none;
  position: absolute;
  inset: auto 0 6px 0;
  padding: 0 10px;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
  z-index: 18;
}

.touch-dpad, .touch-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  pointer-events: auto;
}

.touch-dpad-mid, .touch-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tbtn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  border: 1.5px solid rgba(251, 191, 36, 0.42);
  background: rgba(24, 15, 9, 0.78);
  color: #fff7ed;
  font-size: 16px;
  font-weight: 800;
  line-height: 1;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.tbtn span {
  font-size: 8.5px;
  letter-spacing: 0.04em;
  opacity: 0.85;
  margin-top: 2px;
}

.tbtn.active, .tbtn:active {
  background: rgba(245, 158, 11, 0.55);
  border-color: #fde68a;
  transform: scale(0.94);
}

.tbtn-jump {
  width: 58px;
  height: 52px;
  background: rgba(16, 185, 129, 0.34);
  border-color: rgba(52, 211, 153, 0.65);
}

.tbtn-whip {
  width: 58px;
  height: 52px;
  background: rgba(245, 158, 11, 0.34);
  border-color: rgba(251, 191, 36, 0.65);
}

.tbtn-bomb {
  width: 44px;
  height: 40px;
  background: rgba(239, 68, 68, 0.28);
  border-color: rgba(248, 113, 113, 0.55);
}

.tbtn-rope {
  width: 44px;
  height: 40px;
  background: rgba(217, 119, 6, 0.28);
}

.tbtn-act {
  width: 44px;
  height: 40px;
  background: rgba(56, 189, 248, 0.26);
  border-color: rgba(56, 189, 248, 0.55);
}

/* Fixed Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  background: rgba(8, 5, 3, 0.78);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  overflow-y: auto;
}

.hidden {
  display: none !important;
}

.card {
  width: 100%;
  max-width: 520px;
  max-height: min(90dvh, 720px);
  overflow-y: auto;
  background: linear-gradient(180deg, #251911 0%, #170f0a 100%);
  border: 1.5px solid var(--border-gold);
  border-radius: 16px;
  padding: 18px 18px 14px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.75);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ov-badge-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.ov-pill {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(245, 158, 11, 0.16);
  border: 1px solid rgba(251, 191, 36, 0.45);
  color: #fde68a;
}

.ov-streak-pill {
  background: rgba(52, 211, 153, 0.14);
  border-color: rgba(52, 211, 153, 0.42);
  color: #6ee7b7;
}

.ov-title {
  font-size: clamp(24px, 5vw, 34px);
  font-weight: 900;
  letter-spacing: 0.05em;
  text-align: center;
  color: var(--gold);
  text-shadow: 0 3px 0 #451a03, 0 0 18px rgba(251, 191, 36, 0.25);
}

.ov-subtitle {
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-dim);
  text-align: center;
}

.challenge-banner {
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(56, 189, 248, 0.15);
  border: 1px solid rgba(56, 189, 248, 0.45);
  color: #e0f2fe;
  font-size: 12.5px;
  font-weight: 700;
  text-align: center;
}

.ov-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.stat-box {
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(12, 8, 5, 0.66);
  border: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-lbl {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
}

.stat-box strong {
  font-size: 17px;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

.ov-cause {
  font-size: 12.5px;
  font-weight: 700;
  text-align: center;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(248, 113, 113, 0.14);
  border: 1px solid rgba(248, 113, 113, 0.35);
  color: #fecaca;
}

.ov-cause.victory {
  background: rgba(52, 211, 153, 0.16);
  border-color: rgba(52, 211, 153, 0.45);
  color: #a7f3d0;
}

.ov-cliffhanger {
  font-size: 12px;
  line-height: 1.35;
  padding: 7px 10px;
  border-radius: 9px;
  background: rgba(251, 191, 36, 0.1);
  border: 1px dashed rgba(251, 191, 36, 0.38);
  color: #fde68a;
  text-align: center;
}

.lb-submit-row {
  display: flex;
  gap: 8px;
}

.lb-submit-row input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 9px;
  border: 1px solid var(--border-gold);
  background: rgba(10, 7, 4, 0.85);
  color: var(--text-main);
  font-size: 13px;
  font-weight: 700;
}

.lb-submit-msg {
  font-size: 12px;
  text-align: center;
  color: var(--emerald);
  font-weight: 700;
}

.share-preview {
  padding: 8px 10px;
  border-radius: 9px;
  background: rgba(10, 7, 4, 0.85);
  border: 1px solid var(--border-soft);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  line-height: 1.4;
  color: #f3e8d2;
  white-space: pre-wrap;
  word-break: break-word;
}

.ov-btn-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.ov-btn-row-sub {
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 13.5px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease;
  white-space: nowrap;
}

.btn:hover { transform: translateY(-1px); filter: brightness(1.08); }
.btn:active { transform: translateY(0); }

.btn-primary {
  background: linear-gradient(180deg, #f59e0b 0%, #d97706 100%);
  color: #1c1005;
  border-color: #fde68a;
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.3);
}

.btn-emerald {
  background: linear-gradient(180deg, #10b981 0%, #059669 100%);
  color: #052e16;
  border-color: #6ee7b7;
}

.btn-amber {
  background: rgba(245, 158, 11, 0.2);
  color: #fde68a;
  border-color: rgba(251, 191, 36, 0.5);
}

.btn-ghost {
  background: rgba(41, 28, 18, 0.85);
  color: var(--text-main);
  border-color: var(--border-soft);
}

.ov-controls-tip {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 12px;
  font-size: 11px;
  color: var(--text-dim);
  padding-top: 2px;
}

.ov-controls-tip b { color: #fde68a; }

/* Camp & Leaderboard Modals */
.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.modal-head h2 {
  font-size: 18px;
  color: var(--gold);
}

.modal-sub {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

.btn-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border-soft);
  background: rgba(45, 30, 18, 0.9);
  color: var(--text-main);
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  flex-shrink: 0;
}

.camp-rp-badge {
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(251, 191, 36, 0.18);
  border: 1px solid var(--gold);
  color: var(--gold);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.camp-tabs {
  display: flex;
  gap: 6px;
}

.camp-tab {
  flex: 1;
  padding: 7px 8px;
  border-radius: 8px;
  border: 1px solid var(--border-soft);
  background: rgba(20, 13, 8, 0.8);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.camp-tab.active {
  background: rgba(245, 158, 11, 0.22);
  border-color: var(--gold);
  color: #fef3c7;
}

.camp-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 320px;
  overflow-y: auto;
}

.camp-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 11px;
  border-radius: 10px;
  background: rgba(12, 8, 5, 0.72);
  border: 1px solid var(--border-soft);
}

.camp-item-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.camp-item-name {
  font-size: 13.5px;
  font-weight: 800;
  color: var(--text-main);
}

.camp-item-desc {
  font-size: 11.5px;
  color: var(--text-dim);
}

.camp-buy-btn {
  padding: 6px 11px;
  border-radius: 8px;
  border: 1px solid var(--border-gold);
  background: rgba(245, 158, 11, 0.2);
  color: #fde68a;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.camp-buy-btn.equipped {
  background: rgba(16, 185, 129, 0.22);
  border-color: var(--emerald);
  color: #6ee7b7;
}

.camp-buy-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 4px;
}

.camp-note {
  font-size: 12px;
  color: var(--text-dim);
}

.lb-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 300px;
  overflow-y: auto;
}

.lb-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 8px;
  background: rgba(12, 8, 5, 0.72);
  border: 1px solid var(--border-soft);
  font-size: 13px;
}

.lb-rank { font-weight: 900; color: var(--gold); width: 24px; }
.lb-name { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-floor { font-size: 11.5px; color: #7dd3fc; font-weight: 700; }
.lb-score { font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; }
.lb-empty { text-align: center; padding: 20px 10px; color: var(--text-dim); font-size: 13px; }

/* Responsive Mobile Layout (390x844, 0px horizontal overflow) */
@media (max-width: 760px), (hover: none) and (pointer: coarse) {
  .touch-controls {
    display: flex;
  }
  .shop-prompt {
    bottom: 116px;
  }
  .footer-keys {
    display: none;
  }
}

@media (max-width: 600px) {
  .hud-bar {
    padding: 5px 6px;
    gap: 4px;
  }
  .hud-stats {
    gap: 4px;
  }
  .hud-pill {
    padding: 2px 5px;
    font-size: 11px;
    gap: 2px;
  }
  .hud-ico {
    font-size: 11px;
  }
  .hud-gear {
    display: none;
  }
  .hud-btn {
    height: 26px;
    width: 26px;
    padding: 0;
    font-size: 13px;
  }
  .hud-btn .btn-lbl {
    display: none;
  }
  .hud-btn.icon-only {
    width: 26px;
  }
  .card {
    padding: 14px 13px 12px;
    gap: 8px;
  }
  .ov-btn-row {
    grid-template-columns: 1fr;
  }
  .tbtn {
    width: 42px;
    height: 42px;
    font-size: 15px;
  }
  .tbtn-jump, .tbtn-whip {
    width: 54px;
    height: 48px;
  }
  .tbtn-bomb, .tbtn-rope, .tbtn-act {
    width: 42px;
    height: 38px;
  }
}
