/* Crypt Crawler — 16-Bit Dark-Fantasy Roguelike UI */
:root {
  --bg: #0b0a10;
  --panel: #15131f;
  --panel-hi: #1f1b2e;
  --border: #332c48;
  --border-gold: #b8893a;
  --text: #f3ede0;
  --muted: #a69bb8;
  --gold: #f5c25b;
  --crimson: #ef4444;
  --emerald: #34d399;
  --frost: #38bdf8;
  --violet: #c084fc;
  --amber: #f59e0b;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: radial-gradient(circle at 50% 0%, #1c162b 0%, #0b0a10 68%);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.app-shell {
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  padding: 6px 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-height: 100dvh;
}

/* Top HUD Bar */
.hud-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  background: linear-gradient(180deg, #1b1729, #12101c);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
}

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

.hud-title {
  margin: 0;
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0.06em;
  color: var(--gold);
  text-shadow: 0 2px 0 #000;
  white-space: nowrap;
}

.mode-pill {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.05em;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(245, 194, 91, 0.16);
  border: 1px solid rgba(245, 194, 91, 0.45);
  color: #fde68a;
  white-space: nowrap;
}

.mode-pill.daily {
  background: rgba(192, 132, 252, 0.2);
  border-color: rgba(192, 132, 252, 0.55);
  color: #e9d5ff;
}

.hud-stats {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.stat-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(11, 10, 16, 0.72);
  border: 1px solid rgba(166, 155, 184, 0.2);
  border-radius: 7px;
  padding: 3px 7px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.stat-chip.hp {
  border-color: rgba(239, 68, 68, 0.45);
  color: #fecaca;
}

.stat-chip.floor {
  border-color: rgba(56, 189, 248, 0.45);
  color: #bae6fd;
}

.stat-chip.gold {
  border-color: rgba(245, 194, 91, 0.45);
  color: #fde68a;
}

.stat-chip.soul {
  border-color: rgba(192, 132, 252, 0.45);
  color: #e9d5ff;
}

.hud-actions {
  display: flex;
  align-items: center;
  gap: 5px;
}

.icon-btn {
  background: #231e36;
  color: var(--text);
  border: 1px solid #3f375c;
  border-radius: 7px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
  white-space: nowrap;
}

.icon-btn:hover {
  border-color: var(--gold);
  background: #2d2645;
}

.icon-btn:active {
  transform: scale(0.96);
}

/* Challenge Banner */
.challenge-banner {
  background: linear-gradient(90deg, rgba(245, 158, 11, 0.18), rgba(192, 132, 252, 0.18));
  border: 1px solid rgba(245, 194, 91, 0.55);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 700;
  color: #fef3c7;
  text-align: center;
}

/* Main Stage */
.stage-wrap {
  position: relative;
  width: 100%;
  background: #07060b;
  border: 2px solid #352d4b;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.65), inset 0 0 28px rgba(0, 0, 0, 0.8);
}

#game-canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 10;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  cursor: pointer;
  touch-action: manipulation;
}

/* Boss HP Bar overlaid cleanly at top of canvas */
.boss-bar {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: min(88%, 420px);
  background: rgba(11, 9, 17, 0.88);
  border: 1px solid rgba(239, 68, 68, 0.7);
  border-radius: 8px;
  padding: 5px 9px;
  pointer-events: none;
  z-index: 5;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.6);
}

.boss-bar-head {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 800;
  color: #fca5a5;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.boss-track {
  height: 8px;
  background: #271520;
  border-radius: 999px;
  overflow: hidden;
}

.boss-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #b91c1c, #ef4444, #f59e0b);
  transition: width 0.16s ease;
}

/* Non-blocking Loot Compare Popup inside stage */
.loot-toast {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  width: min(94%, 460px);
  background: rgba(18, 15, 29, 0.96);
  border: 1.5px solid var(--gold);
  border-radius: 10px;
  padding: 9px 12px;
  z-index: 8;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.78);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.loot-toast-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.loot-name {
  font-size: 13px;
  font-weight: 800;
  color: var(--gold);
}

.loot-diff {
  font-size: 12px;
  font-weight: 800;
}

.loot-diff.pos {
  color: var(--emerald);
}

.loot-diff.neg {
  color: #fca5a5;
}

.loot-desc {
  font-size: 11.5px;
  color: var(--muted);
}

.loot-btns {
  display: flex;
  gap: 7px;
}

.loot-btns button {
  flex: 1;
  padding: 6px 8px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  border: 1px solid transparent;
}

.btn-equip {
  background: linear-gradient(180deg, #d97706, #b45309);
  color: #fff;
  border-color: #fbbf24 !important;
}

.btn-sell {
  background: #231e36;
  color: #e2e8f0;
  border-color: #473d66 !important;
}

/* Status & Relics Strip */
.sub-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  background: #13111d;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 5px 9px;
  font-size: 11.5px;
}

.equip-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  color: #ddd6fe;
  font-weight: 700;
}

.relic-row {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.relic-pill {
  background: rgba(192, 132, 252, 0.14);
  border: 1px solid rgba(192, 132, 252, 0.38);
  color: #f3e8ff;
  border-radius: 6px;
  padding: 2px 6px;
  font-size: 11px;
  font-weight: 700;
}

/* Compact 2-line Combat Log */
.combat-log {
  background: #0e0c16;
  border: 1px solid #2b243e;
  border-radius: 8px;
  padding: 5px 9px;
  min-height: 36px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  font-size: 11.5px;
  line-height: 1.28;
}

.log-line {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.log-line.latest {
  color: #f8fafc;
  font-weight: 700;
}

.log-line.prev {
  color: #9489aa;
}

/* Tactical Action Hotbar */
.action-dock {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.hotbar {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
}

.hot-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 7px 4px;
  background: linear-gradient(180deg, #211c33, #161324);
  border: 1px solid #3c3459;
  border-radius: 9px;
  color: var(--text);
  cursor: pointer;
  min-height: 52px;
  transition: transform 0.1s ease, border-color 0.12s ease, opacity 0.15s ease;
}

.hot-btn:hover:not(:disabled) {
  border-color: var(--gold);
  background: linear-gradient(180deg, #2b2442, #1c182d);
}

.hot-btn:active:not(:disabled) {
  transform: scale(0.95);
}

.hot-btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.hot-key {
  position: absolute;
  top: 3px;
  left: 5px;
  font-size: 9.5px;
  font-weight: 800;
  color: #9e93b8;
}

.hot-count {
  position: absolute;
  top: 3px;
  right: 5px;
  font-size: 10px;
  font-weight: 900;
  color: var(--gold);
}

.hot-icon {
  font-size: 16px;
  line-height: 1;
}

.hot-label {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.hot-btn.skill {
  border-color: rgba(245, 194, 91, 0.52);
}

/* Mobile D-Pad (shown on touch / narrow screens, plus optional toggle) */
.mobile-pad {
  display: none;
  grid-template-columns: repeat(3, 46px);
  grid-template-rows: repeat(3, 42px);
  gap: 5px;
  justify-content: center;
  align-items: center;
  margin: 2px auto 0;
}

.pad-btn {
  width: 46px;
  height: 42px;
  border-radius: 9px;
  border: 1px solid #453c66;
  background: linear-gradient(180deg, #27213d, #191529);
  color: #f8fafc;
  font-size: 17px;
  font-weight: 900;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}

.pad-btn:active {
  background: #3b315d;
  border-color: var(--gold);
  transform: scale(0.94);
}

.pad-btn.wait {
  font-size: 12px;
  color: var(--gold);
  border-color: rgba(245, 194, 91, 0.55);
}

.pad-spacer {
  visibility: hidden;
}

/* Overlays & Modals */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(6, 5, 11, 0.84);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}

.overlay.hidden {
  display: none !important;
}

.hidden {
  display: none !important;
}

.card {
  width: 100%;
  max-width: 500px;
  max-height: min(90dvh, 720px);
  overflow-y: auto;
  background: linear-gradient(180deg, #1b1629, #110e1a);
  border: 1.5px solid #483d68;
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 22px 54px rgba(0, 0, 0, 0.78);
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: center;
}

.card-badge {
  align-self: center;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: 999px;
  background: rgba(245, 194, 91, 0.16);
  border: 1px solid rgba(245, 194, 91, 0.5);
  color: #fde68a;
}

.card h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 900;
  color: var(--gold);
  letter-spacing: 0.04em;
  text-shadow: 0 2px 0 #000;
}

.card-sub {
  margin: 0;
  font-size: 12.5px;
  color: #cbbfe0;
  line-height: 1.4;
}

/* Hero Class Picker */
.hero-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
  text-align: left;
}

.hero-card {
  background: rgba(13, 11, 21, 0.85);
  border: 1.5px solid #383052;
  border-radius: 10px;
  padding: 8px;
  cursor: pointer;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 3px;
  transition: border-color 0.14s ease, transform 0.12s ease, background 0.14s ease;
}

.hero-card:hover {
  border-color: #7c6ca8;
}

.hero-card.selected {
  border-color: var(--gold);
  background: linear-gradient(180deg, rgba(245, 194, 91, 0.14), rgba(24, 19, 38, 0.95));
  box-shadow: 0 0 16px rgba(245, 194, 91, 0.2);
}

.hero-card-title {
  font-size: 12px;
  font-weight: 900;
  color: #fef3c7;
}

.hero-card-stats {
  font-size: 10px;
  font-weight: 700;
  color: #93c5fd;
}

.hero-card-perk {
  font-size: 10px;
  color: #b5a9cc;
  line-height: 1.25;
}

.cta-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-primary,
.btn-daily,
.btn-secondary {
  flex: 1;
  min-width: 120px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.03em;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: transform 0.12s ease, filter 0.12s ease;
}

.btn-primary {
  background: linear-gradient(180deg, #eab308, #b45309);
  color: #140f08;
  border-color: #fde68a;
}

.btn-daily {
  background: linear-gradient(180deg, #7c3aed, #4c1d95);
  color: #faf5ff;
  border-color: #c084fc;
}

.btn-secondary {
  background: #231e36;
  color: #e2e8f0;
  border-color: #4a406b;
}

.btn-primary:hover,
.btn-daily:hover,
.btn-secondary:hover {
  filter: brightness(1.08);
}

.btn-primary:active,
.btn-daily:active,
.btn-secondary:active {
  transform: scale(0.97);
}

.daily-note {
  font-size: 11.5px;
  color: #e9d5ff;
  background: rgba(124, 58, 237, 0.16);
  border: 1px solid rgba(192, 132, 252, 0.35);
  border-radius: 8px;
  padding: 6px 9px;
}

/* Post-Run Stats & Cliffhanger */
.ov-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  text-align: left;
}

.ov-stat-box {
  background: rgba(10, 9, 16, 0.78);
  border: 1px solid #342c4c;
  border-radius: 8px;
  padding: 6px 9px;
}

.ov-stat-label {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.ov-stat-val {
  font-size: 14px;
  font-weight: 900;
  color: #f8fafc;
}

.cliffhanger-box {
  background: linear-gradient(90deg, rgba(245, 194, 91, 0.14), rgba(56, 189, 248, 0.12));
  border: 1px solid rgba(245, 194, 91, 0.42);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 700;
  color: #fef3c7;
}

.share-preview {
  background: #0b0912;
  border: 1px solid #352e4f;
  border-radius: 8px;
  padding: 7px 9px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: #cbd5e1;
  text-align: left;
  white-space: pre-wrap;
  word-break: break-word;
}

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

.lb-submit-row input {
  flex: 1;
  min-width: 0;
  background: #0d0b14;
  border: 1px solid #483d68;
  border-radius: 8px;
  padding: 7px 9px;
  color: #fff;
  font-size: 12.5px;
  font-weight: 700;
}

/* Guild Upgrades List */
.guild-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  text-align: left;
}

.guild-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: rgba(11, 10, 18, 0.82);
  border: 1px solid #362e50;
  border-radius: 9px;
  padding: 8px 10px;
}

.guild-info {
  min-width: 0;
  flex: 1;
}

.guild-name {
  font-size: 13px;
  font-weight: 800;
  color: #fef3c7;
}

.guild-desc {
  font-size: 11px;
  color: var(--muted);
}

.guild-buy {
  background: linear-gradient(180deg, #7c3aed, #5b21b6);
  color: #fff;
  border: 1px solid #c084fc;
  border-radius: 7px;
  padding: 6px 10px;
  font-size: 11.5px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

.guild-buy:disabled {
  background: #231e36;
  border-color: #3a3254;
  color: #7c7296;
  cursor: not-allowed;
}

/* Leaderboard Table */
.lb-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  text-align: left;
}

.lb-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(12, 10, 20, 0.8);
  border: 1px solid #312a4a;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12.5px;
}

.lb-rank {
  font-weight: 900;
  color: var(--gold);
  width: 28px;
}

.lb-name {
  flex: 1;
  font-weight: 700;
  color: #f8fafc;
}

.lb-score {
  font-weight: 900;
  color: #fde68a;
}

/* Footer (Studio Bar docks cleanly here!) */
.footer-bar {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding: 4px 4px 2px;
  font-size: 11px;
  color: #8f84a8;
}

.controls-hint {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 720px) {
  .app-shell {
    padding: 6px 6px 8px;
    gap: 5px;
  }

  .hud-bar {
    padding: 5px 7px;
    gap: 5px;
  }

  .hud-title {
    font-size: 13.5px;
  }

  .stat-chip {
    font-size: 11px;
    padding: 2px 5px;
  }

  .icon-btn {
    padding: 4px 6px;
    font-size: 11px;
  }

  .hotbar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
  }

  .hot-btn {
    min-height: 46px;
    padding: 5px 3px;
  }

  .mobile-pad {
    display: grid;
  }

  .hero-grid {
    grid-template-columns: 1fr;
  }

  .controls-hint {
    display: none;
  }
}
