/* ==============================
   DUNGEON MERCHANT - Dark Fantasy Idle Game
   ============================== */

:root {
  --bg-deep: #07060b;
  --bg: #0d0b14;
  --bg-surface: #14111f;
  --bg-card: #1a1628;
  --bg-card-hover: #211d30;
  --border: #2a2440;
  --border-glow: #3d2f6e;
  --text: #e8e4f0;
  --text-dim: #8a7fa0;
  --text-faint: #5c5470;
  --gold: #f0c040;
  --gold-dim: rgba(240, 192, 64, 0.12);
  --gold-glow: rgba(240, 192, 64, 0.3);
  --accent: #c06ef0;
  --accent-dim: rgba(192, 110, 240, 0.1);
  --red: #e84057;
  --red-dim: rgba(232, 64, 87, 0.12);
  --green: #40d870;
  --green-dim: rgba(64, 216, 112, 0.12);
  --blue: #4088e8;
  --blue-dim: rgba(64, 136, 232, 0.12);
  --tier1: #a0a0a0;
  --tier2: #40a0e8;
  --tier3: #e8a040;
  --tier4: #c06ef0;
}

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

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

body {
  font-family: 'Crimson Text', Georgia, serif;
  background: var(--bg-deep);
  color: var(--text);
  line-height: 1.5;
}

h1, h2, h3, h4, h5, h6 {
  font-family: 'Cinzel', 'Times New Roman', serif;
  line-height: 1.2;
  letter-spacing: 0.03em;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-glow); }

/* ===== LOADING SCREEN ===== */
#loading-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--bg-deep);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.6s ease;
}

#loading-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}

.loading-content {
  text-align: center;
}

.loading-title {
  font-size: 2.8rem;
  color: var(--gold);
  text-shadow: 0 0 30px rgba(240, 192, 64, 0.3);
  margin-bottom: 8px;
}

.loading-subtitle {
  color: var(--text-dim);
  font-size: 1.1rem;
  margin-bottom: 24px;
}

.loading-bar {
  width: 200px;
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto;
  overflow: hidden;
}

.loading-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--gold), var(--accent));
  border-radius: 2px;
  animation: load-fill 1.5s ease forwards;
}

@keyframes load-fill {
  0% { width: 0%; }
  60% { width: 80%; }
  100% { width: 100%; }
}

/* ===== TOP BAR ===== */
#top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 10;
}

#top-bar::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-glow), transparent);
}

.game-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.game-title .title-icon {
  font-size: 1.4rem;
}

.game-title h1 {
  font-size: 1.2rem;
  color: var(--gold);
  font-weight: 700;
  text-shadow: 0 0 20px rgba(240, 192, 64, 0.2);
}

.resources {
  display: flex;
  gap: 20px;
}

.resource {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.resource-icon { font-size: 1.1rem; }
.resource-value {
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--gold);
  min-width: 40px;
}
.resource-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* ===== TAB NAV ===== */
#tab-nav {
  display: flex;
  gap: 2px;
  padding: 0 24px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.tab {
  flex: 1;
  padding: 12px 16px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: 'Cinzel', serif;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  border-bottom: 2px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.tab:hover {
  color: var(--text);
  background: var(--bg-surface);
}

.tab.active {
  color: var(--gold);
  border-bottom-color: var(--gold);
  background: var(--bg-surface);
}

.tab-icon { font-size: 1rem; }

/* ===== MAIN PANELS ===== */
#game-main {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  background: var(--bg-deep);
  min-height: 0;
}

#game-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.panel { display: none; }
.panel.active { display: block; animation: fade-in 0.25s ease; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.panel-header h2 {
  font-size: 1.3rem;
  color: var(--text);
}

/* ===== CARD GRID ===== */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
}

/* ===== ADVENTURER CARDS ===== */
.adventurer-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}

.adventurer-card:hover {
  border-color: var(--border-glow);
  background: var(--bg-card-hover);
}

.adventurer-card.status-dungeon {
  border-color: rgba(64, 136, 232, 0.4);
}

.adventurer-card.status-dead {
  border-color: rgba(232, 64, 87, 0.4);
  opacity: 0.75;
}

.adv-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.adv-name {
  font-family: 'Cinzel', serif;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.adv-status {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 3px 8px;
  border-radius: 4px;
}

.adv-status.idle { background: var(--green-dim); color: var(--green); }
.adv-status.dungeon { background: var(--blue-dim); color: var(--blue); }
.adv-status.dead { background: var(--red-dim); color: var(--red); }

.adv-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.adv-stat {
  text-align: center;
  padding: 6px;
  background: var(--bg);
  border-radius: 6px;
}

.adv-stat-value {
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
}

.adv-stat-label {
  font-size: 0.65rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.adv-equipment {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.equip-slot {
  flex: 1;
  padding: 6px 10px;
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: 6px;
  font-size: 0.8rem;
  color: var(--text-dim);
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}

.equip-slot:hover {
  border-color: var(--gold);
  color: var(--text);
}

.equip-slot.equipped {
  border-style: solid;
  border-color: var(--accent);
  color: var(--accent);
}

.adv-progress {
  margin-bottom: 12px;
}

.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--bg);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}

.progress-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s ease;
}

.progress-fill.dungeon-progress {
  background: linear-gradient(90deg, var(--blue), var(--accent));
}

.progress-fill.respawn-progress {
  background: linear-gradient(90deg, var(--red), var(--gold));
}

.progress-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 4px;
  text-align: center;
}

.adv-actions {
  display: flex;
  gap: 8px;
}

/* ===== HP BAR ===== */
.hp-bar-container {
  margin-bottom: 10px;
}

.hp-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-bottom: 3px;
  display: flex;
  justify-content: space-between;
}

.hp-bar {
  width: 100%;
  height: 4px;
  background: var(--bg);
  border-radius: 2px;
  overflow: hidden;
}

.hp-fill {
  height: 100%;
  background: var(--green);
  border-radius: 2px;
  transition: width 0.3s;
}

.hp-fill.low { background: var(--red); }
.hp-fill.medium { background: var(--gold); }

/* ===== DUNGEON CARDS ===== */
.dungeon-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  transition: all 0.2s;
  position: relative;
}

.dungeon-card:hover {
  border-color: var(--border-glow);
  background: var(--bg-card-hover);
}

.dungeon-card.locked {
  opacity: 0.4;
  pointer-events: none;
}

.dungeon-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}

.dungeon-name {
  font-family: 'Cinzel', serif;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}

.dungeon-level {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--accent-dim);
  color: var(--accent);
}

.dungeon-desc {
  font-size: 0.85rem;
  color: var(--text-dim);
  font-style: italic;
  margin-bottom: 12px;
}

.dungeon-info {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.dungeon-info-item {
  text-align: center;
  padding: 6px;
  background: var(--bg);
  border-radius: 6px;
}

.dungeon-info-value {
  font-weight: 700;
  font-size: 0.9rem;
}

.dungeon-info-label {
  font-size: 0.6rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.dungeon-loot {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.loot-tag {
  font-size: 0.75rem;
  padding: 3px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-dim);
}

.danger-low { color: var(--green); }
.danger-med { color: var(--gold); }
.danger-high { color: var(--red); }

.lock-overlay {
  position: absolute;
  inset: 0;
  background: rgba(7, 6, 11, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
}

.lock-text {
  font-family: 'Cinzel', serif;
  font-size: 0.85rem;
  color: var(--text-dim);
  text-align: center;
  padding: 12px;
}

/* ===== CRAFTING ===== */
.materials-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  padding: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.material-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--bg);
  border-radius: 6px;
  font-size: 0.85rem;
}

.material-icon { font-size: 1rem; }
.material-count {
  font-family: 'Cinzel', serif;
  font-weight: 700;
  color: var(--gold);
}
.material-name {
  color: var(--text-dim);
  font-size: 0.75rem;
}

.recipe-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  transition: all 0.2s;
}

.recipe-card:hover {
  border-color: var(--border-glow);
}

.recipe-card.can-craft {
  border-color: var(--gold);
  box-shadow: 0 0 15px rgba(240, 192, 64, 0.08);
}

.recipe-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 6px;
}

.recipe-name {
  font-family: 'Cinzel', serif;
  font-size: 1rem;
  font-weight: 700;
}

.recipe-type {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 3px 8px;
  border-radius: 4px;
}

.recipe-type.weapon { background: var(--red-dim); color: var(--red); }
.recipe-type.armor { background: var(--blue-dim); color: var(--blue); }

.recipe-desc {
  font-size: 0.8rem;
  color: var(--text-dim);
  font-style: italic;
  margin-bottom: 10px;
}

.recipe-stats {
  display: flex;
  gap: 12px;
  margin-bottom: 10px;
}

.recipe-stat {
  font-size: 0.8rem;
  color: var(--text);
}

.recipe-stat .label { color: var(--text-dim); }

.recipe-materials {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.req-mat {
  font-size: 0.75rem;
  padding: 3px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.req-mat.has { color: var(--green); border-color: rgba(64, 216, 112, 0.3); }
.req-mat.needs { color: var(--red); border-color: rgba(232, 64, 87, 0.3); }

.tier-badge {
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 2px 6px;
  border-radius: 3px;
  text-transform: uppercase;
}

.tier-1 { color: var(--tier1); background: rgba(160,160,160,0.1); }
.tier-2 { color: var(--tier2); background: rgba(64,160,232,0.1); }
.tier-3 { color: var(--tier3); background: rgba(232,160,64,0.1); }
.tier-4 { color: var(--tier4); background: rgba(192,110,240,0.1); }

/* ===== INVENTORY ===== */
.inventory-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  transition: all 0.2s;
}

.inventory-item:hover {
  border-color: var(--border-glow);
}

.inv-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.inv-name {
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 1rem;
}

.inv-stats {
  display: flex;
  gap: 12px;
  margin-bottom: 10px;
  font-size: 0.85rem;
}

.inv-qty {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-dim);
  font-size: 1rem;
  font-style: italic;
}

/* ===== BUTTONS ===== */
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-family: 'Cinzel', serif;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.5px;
}

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

.btn-gold {
  background: linear-gradient(135deg, var(--gold), #d4a030);
  color: #1a1200;
  box-shadow: 0 2px 10px rgba(240, 192, 64, 0.2);
}

.btn-gold:hover:not(:disabled) {
  box-shadow: 0 4px 20px rgba(240, 192, 64, 0.35);
  transform: translateY(-1px);
}

.btn-accent {
  background: linear-gradient(135deg, var(--accent), #9040c0);
  color: #fff;
  box-shadow: 0 2px 10px rgba(192, 110, 240, 0.2);
}

.btn-accent:hover:not(:disabled) {
  box-shadow: 0 4px 20px rgba(192, 110, 240, 0.35);
  transform: translateY(-1px);
}

.btn-muted {
  background: var(--bg-surface);
  color: var(--text-dim);
  border: 1px solid var(--border);
}

.btn-muted:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--text-dim);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.72rem;
}

.btn-full {
  width: 100%;
}

.cost {
  opacity: 0.7;
  font-weight: 400;
}

/* ===== EVENT LOG ===== */
#event-log {
  padding: 8px 24px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  max-height: 80px;
  overflow-y: auto;
}

#log-entries {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.log-entry {
  font-size: 0.78rem;
  color: var(--text-dim);
  padding: 2px 0;
  animation: log-fade 0.3s ease;
}

.log-entry.loot { color: var(--gold); }
.log-entry.death { color: var(--red); }
.log-entry.craft { color: var(--accent); }
.log-entry.unlock { color: var(--green); }

@keyframes log-fade {
  from { opacity: 0; transform: translateX(-10px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ===== STATS BAR ===== */
#stats-bar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 8px 24px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  font-size: 0.72rem;
  color: var(--text-dim);
}

#stats-bar strong {
  color: var(--text);
  font-family: 'Cinzel', serif;
}

.auto-save {
  margin-left: auto;
  opacity: 0.6;
}

.auto-save.saving {
  opacity: 1;
  color: var(--gold);
}

/* ===== MODALS ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal.hidden { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(7, 6, 11, 0.85);
}

.modal-content {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border-glow);
  border-radius: 12px;
  padding: 28px;
  max-width: 480px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-content h2 {
  font-size: 1.2rem;
  color: var(--gold);
  margin-bottom: 12px;
}

.modal-content p {
  color: var(--text-dim);
  margin-bottom: 16px;
  font-size: 0.9rem;
}

.dungeon-option {
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.dungeon-option:hover {
  border-color: var(--gold);
  background: var(--bg-surface);
}

.dungeon-option .do-name {
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 4px;
}

.dungeon-option .do-info {
  font-size: 0.75rem;
  color: var(--text-dim);
  display: flex;
  gap: 12px;
}

.equip-option {
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.equip-option:hover {
  border-color: var(--accent);
}

.equip-option .eo-name {
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 2px;
}

.equip-option .eo-stats {
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* ===== OFFLINE MODAL ===== */
#offline-events {
  max-height: 300px;
  overflow-y: auto;
  margin-bottom: 16px;
}

.offline-event {
  padding: 6px 0;
  font-size: 0.85rem;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
}

.offline-event:last-child { border: none; }

/* ===== ANIMATIONS ===== */
@keyframes gold-pulse {
  0% { text-shadow: 0 0 10px rgba(240, 192, 64, 0.3); }
  50% { text-shadow: 0 0 20px rgba(240, 192, 64, 0.6); }
  100% { text-shadow: 0 0 10px rgba(240, 192, 64, 0.3); }
}

.gold-gained {
  animation: gold-pulse 0.5s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-4px); }
  40% { transform: translateX(4px); }
  60% { transform: translateX(-2px); }
  80% { transform: translateX(2px); }
}

.shake { animation: shake 0.4s ease; }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  #top-bar { padding: 10px 16px; }
  .game-title h1 { font-size: 1rem; }
  .resources { gap: 10px; }
  .resource { padding: 4px 10px; }
  .resource-label { display: none; }
  #tab-nav { padding: 0 8px; }
  .tab { font-size: 0.75rem; padding: 10px 8px; }
  .tab-icon { display: none; }
  #game-main { padding: 16px; }
  .card-grid { grid-template-columns: 1fr; }
  .panel-header { flex-direction: column; align-items: flex-start; gap: 8px; }
  #event-log { padding: 6px 16px; }
  #stats-bar { padding: 6px 16px; gap: 12px; font-size: 0.65rem; }
}
