/* ==========================================================
   ELDORIA: FRACTURED REALMS — DARK FANTASY AAA THEME
   ========================================================== */

:root {
  /* Core palette — deep occult */
  --bg-0: #05030a;
  --bg-1: #0a0612;
  --bg-2: #0f0a1c;
  --bg-3: #17102a;
  --bg-4: #201538;
  --bg-5: #2c1d4a;

  --panel: linear-gradient(180deg, rgba(30,18,60,0.85) 0%, rgba(15,8,30,0.92) 100%);
  --panel-solid: #120824;
  --panel-elev: linear-gradient(180deg, rgba(44,29,74,0.9) 0%, rgba(23,14,44,0.96) 100%);

  --border: #3a2560;
  --border-soft: #28193f;
  --border-strong: #5a3a8c;
  --border-gold: #8a6d2e;

  /* Accent colors */
  --gold: #e9b963;
  --gold-2: #c89a3e;
  --gold-deep: #8a6520;
  --gold-glow: rgba(233,185,99,0.35);

  --primary: #a47dff;
  --primary-2: #7a4cf0;
  --primary-deep: #4a1fa8;
  --primary-glow: rgba(164,125,255,0.35);

  --blood: #d93a4b;
  --blood-2: #a61726;
  --ember: #ff8432;
  --mint: #3fd692;
  --cyan: #4cc4ff;
  --rose: #ff5f8a;

  /* Text */
  --text: #eae0ff;
  --text-muted: #a593cf;
  --text-dim: #6a578f;

  /* Rarity */
  --r-common: #b5b0c0;
  --r-uncommon: #5fd684;
  --r-rare: #4cc4ff;
  --r-epic: #c277ff;
  --r-legendary: #ffb347;
  --r-mythic: #ff5f8a;

  /* Typography */
  --font-title: 'Cinzel', 'Cormorant Garamond', serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-serif: 'Cormorant Garamond', serif;
  --font-mono: 'JetBrains Mono', 'Consolas', monospace;

  /* Shadows */
  --sh-sm: 0 2px 6px rgba(0,0,0,0.4);
  --sh-md: 0 6px 20px rgba(0,0,0,0.55);
  --sh-lg: 0 12px 40px rgba(0,0,0,0.65);
  --sh-glow-gold: 0 0 24px rgba(233,185,99,0.35);
  --sh-glow-primary: 0 0 24px rgba(164,125,255,0.4);
  --sh-inset: inset 0 1px 0 rgba(255,255,255,0.06), inset 0 0 0 1px rgba(0,0,0,0.3);

  /* Radii */
  --r-sm: 4px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-xl: 18px;

  /* Z indexes */
  --z-modal: 500;
  --z-toast: 1000;
  --z-tooltip: 1500;
}

/* ========== RESET ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { width: 100%; height: 100%; }
body {
  font-family: var(--font-body);
  color: var(--text);
  background: var(--bg-0);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  line-height: 1.45;
  -webkit-user-select: none;
  user-select: none;
}
button, input, select, textarea { font-family: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-1); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; border: 1px solid var(--bg-1); }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }
::selection { background: var(--primary-deep); color: #fff; }

/* ========== BACKDROP (world background) ========== */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(ellipse 60% 40% at 20% 10%, rgba(122,76,240,0.18), transparent 70%),
    radial-gradient(ellipse 50% 50% at 85% 85%, rgba(217,58,75,0.1), transparent 70%),
    radial-gradient(ellipse 70% 40% at 50% 50%, rgba(74,31,168,0.14), transparent 70%),
    linear-gradient(180deg, #060310 0%, #02010a 100%);
}

/* Race portrait helpers (image or FA fallback) */
.race-portrait-img {
  width: 100%;
  height: 100%;
  background-size: cover;
  background-position: center top;
  background-repeat: no-repeat;
  border-radius: inherit;
}
.race-portrait-fa {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.55em;
  color: var(--gold);
  border-radius: inherit;
}

/* Item image helper (image or FA fallback) */
.item-image {
  width: 100%;
  height: 100%;
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.6));
}
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image:
    radial-gradient(1px 1px at 25% 15%, rgba(255,255,255,0.5), transparent),
    radial-gradient(1px 1px at 70% 30%, rgba(255,255,255,0.4), transparent),
    radial-gradient(1px 1px at 40% 70%, rgba(255,255,255,0.45), transparent),
    radial-gradient(1px 1px at 90% 80%, rgba(255,255,255,0.35), transparent),
    radial-gradient(1px 1px at 15% 85%, rgba(255,255,255,0.4), transparent);
  opacity: 0.5;
  pointer-events: none;
}

/* ========== APP SHELL ========== */
#app {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ========== TYPOGRAPHY ========== */
.title { font-family: var(--font-title); font-weight: 700; letter-spacing: 0.04em; }
.title-hero {
  font-family: var(--font-title);
  font-weight: 900;
  font-size: clamp(28px, 5vw, 64px);
  letter-spacing: 0.15em;
  background: linear-gradient(180deg, #f0d78a 0%, #c89a3e 55%, #8a5e1f 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 30px rgba(233,185,99,0.2);
  text-transform: uppercase;
}
.subtitle-hero {
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 14px;
  color: var(--text-muted);
  letter-spacing: 0.3em;
  text-transform: uppercase;
}
h1, h2, h3, h4 { font-family: var(--font-title); font-weight: 700; letter-spacing: 0.02em; }
h1 { font-size: 24px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
h4 { font-size: 14px; }

/* ========== UTILITIES ========== */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.items-end { align-items: flex-end; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.gap-6 { gap: 24px; }
.wrap { flex-wrap: wrap; }
.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-left { text-align: left; }
.text-muted { color: var(--text-muted); }
.text-dim { color: var(--text-dim); }
.text-gold { color: var(--gold); }
.text-primary { color: var(--primary); }
.text-blood { color: var(--blood); }
.text-mint { color: var(--mint); }
.text-cyan { color: var(--cyan); }
.text-xs { font-size: 11px; }
.text-sm { font-size: 12px; }
.text-md { font-size: 14px; }
.text-lg { font-size: 16px; }
.text-xl { font-size: 20px; }
.text-2xl { font-size: 24px; }
.font-title { font-family: var(--font-title); }
.font-serif { font-family: var(--font-serif); }
.font-mono { font-family: var(--font-mono); }
.fw-400 { font-weight: 400; }
.fw-500 { font-weight: 500; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.fw-800 { font-weight: 800; }
.fw-900 { font-weight: 900; }
.uppercase { text-transform: uppercase; letter-spacing: 0.08em; }
.italic { font-style: italic; }
.w-full { width: 100%; }
.h-full { height: 100%; }
.mt-1 { margin-top: 4px; } .mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; } .mt-6 { margin-top: 24px; }
.mb-1 { margin-bottom: 4px; } .mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; } .mb-6 { margin-bottom: 24px; }
.p-2 { padding: 8px; } .p-3 { padding: 12px; } .p-4 { padding: 16px; } .p-6 { padding: 24px; }
.hidden { display: none !important; }
.pointer { cursor: pointer; }
.no-select { user-select: none; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.relative { position: relative; }

/* ========== RARITY HELPERS ========== */
.r-common { color: var(--r-common); }
.r-uncommon { color: var(--r-uncommon); }
.r-rare { color: var(--r-rare); }
.r-epic { color: var(--r-epic); }
.r-legendary { color: var(--r-legendary); text-shadow: 0 0 10px rgba(255,179,71,0.4); }
.r-mythic { color: var(--r-mythic); text-shadow: 0 0 14px rgba(255,95,138,0.5); }

.rb-common { border-color: #4a4654 !important; }
.rb-uncommon { border-color: var(--r-uncommon) !important; box-shadow: inset 0 0 10px rgba(95,214,132,0.1); }
.rb-rare { border-color: var(--r-rare) !important; box-shadow: inset 0 0 10px rgba(76,196,255,0.15); }
.rb-epic { border-color: var(--r-epic) !important; box-shadow: inset 0 0 12px rgba(194,119,255,0.2); }
.rb-legendary { border-color: var(--r-legendary) !important; box-shadow: inset 0 0 14px rgba(255,179,71,0.25), 0 0 12px rgba(255,179,71,0.15); }
.rb-mythic { border-color: var(--r-mythic) !important; box-shadow: inset 0 0 16px rgba(255,95,138,0.3), 0 0 16px rgba(255,95,138,0.2); }

/* ========== ORNAMENTAL BORDERS ========== */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-md), var(--sh-inset);
  position: relative;
}
.panel-gilded {
  background: var(--panel);
  border: 1px solid var(--border-gold);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-md), 0 0 0 1px rgba(0,0,0,0.4) inset, 0 0 30px rgba(233,185,99,0.08) inset;
  position: relative;
}
.panel-gilded::before, .panel-gilded::after {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  border: 2px solid var(--gold);
  pointer-events: none;
}
.panel-gilded::before { top: -1px; left: -1px; border-right: none; border-bottom: none; border-top-left-radius: var(--r-lg); }
.panel-gilded::after { bottom: -1px; right: -1px; border-left: none; border-top: none; border-bottom-right-radius: var(--r-lg); }

/* ========== BUTTONS ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--r-md);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.03em;
  transition: all 0.18s ease;
  border: 1px solid transparent;
  white-space: nowrap;
  line-height: 1;
  font-family: inherit;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; filter: grayscale(40%); }
.btn:not(:disabled):hover { transform: translateY(-1px); }
.btn:not(:disabled):active { transform: translateY(0); }
.btn i { font-size: 13px; }

.btn-primary {
  background: linear-gradient(180deg, #8d5dff 0%, #5a28d0 100%);
  color: #fff;
  border-color: #a47dff;
  box-shadow: 0 4px 14px rgba(122,76,240,0.35), inset 0 1px 0 rgba(255,255,255,0.18);
}
.btn-primary:hover { box-shadow: 0 8px 22px rgba(122,76,240,0.55), inset 0 1px 0 rgba(255,255,255,0.25); }

.btn-gold {
  background: linear-gradient(180deg, #f5cc6e 0%, #b37c1f 100%);
  color: #2a1a00;
  border-color: #f5cc6e;
  box-shadow: 0 4px 14px rgba(233,185,99,0.4), inset 0 1px 0 rgba(255,255,255,0.3);
  text-shadow: 0 1px 0 rgba(255,255,255,0.15);
}
.btn-gold:hover { box-shadow: 0 8px 22px rgba(233,185,99,0.6), inset 0 1px 0 rgba(255,255,255,0.4); }

.btn-danger {
  background: linear-gradient(180deg, #e85060 0%, #8a0e1c 100%);
  color: #fff;
  border-color: #ff6574;
  box-shadow: 0 4px 14px rgba(217,58,75,0.4), inset 0 1px 0 rgba(255,255,255,0.18);
}
.btn-danger:hover { box-shadow: 0 8px 22px rgba(217,58,75,0.6); }

.btn-ghost {
  background: rgba(255,255,255,0.04);
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:hover { background: rgba(255,255,255,0.07); border-color: var(--border-strong); }

.btn-mint {
  background: linear-gradient(180deg, #4ae59a 0%, #167a48 100%);
  color: #00200e;
  border-color: #5fd684;
  box-shadow: 0 4px 14px rgba(63,214,146,0.35);
}

.btn-block { width: 100%; }
.btn-sm { padding: 6px 10px; font-size: 11px; gap: 6px; }
.btn-lg { padding: 14px 26px; font-size: 15px; gap: 10px; }

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-md);
}

/* ========== FORM ========== */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label {
  font-size: 11px;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.15em;
  font-weight: 700;
  font-family: var(--font-title);
}
.input, .select, .textarea {
  width: 100%;
  padding: 11px 14px;
  background: rgba(5,3,10,0.7);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: var(--font-body);
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(233,185,99,0.15);
}
.input::placeholder { color: var(--text-dim); }

/* ========== BADGES ========== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  background: rgba(255,255,255,0.06);
  color: var(--text-muted);
  border: 1px solid rgba(255,255,255,0.08);
}
.badge-gold { background: rgba(233,185,99,0.15); color: var(--gold); border-color: rgba(233,185,99,0.35); }
.badge-primary { background: rgba(164,125,255,0.15); color: var(--primary); border-color: rgba(164,125,255,0.35); }
.badge-danger { background: rgba(217,58,75,0.15); color: var(--blood); border-color: rgba(217,58,75,0.35); }
.badge-mint { background: rgba(63,214,146,0.15); color: var(--mint); border-color: rgba(63,214,146,0.35); }
.badge-cyan { background: rgba(76,196,255,0.15); color: var(--cyan); border-color: rgba(76,196,255,0.35); }

/* ========== PROGRESS BARS ========== */
.bar {
  height: 12px;
  background: rgba(0,0,0,0.55);
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  border: 1px solid rgba(0,0,0,0.6);
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.5);
}
.bar-fill {
  height: 100%;
  transition: width 0.4s ease;
  position: relative;
}
.bar-fill::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.25) 0%, transparent 50%);
  pointer-events: none;
}
.bar-hp .bar-fill { background: linear-gradient(90deg, #8b1a28 0%, #e85060 50%, #ff9466 100%); }
.bar-mp .bar-fill { background: linear-gradient(90deg, #1a4a8b 0%, #4cc4ff 50%, #7aa9ff 100%); }
.bar-xp .bar-fill { background: linear-gradient(90deg, #3a8a2a 0%, #6fd44a 50%, #b3e66b 100%); }
.bar-sp .bar-fill { background: linear-gradient(90deg, #8a6520 0%, #e9b963 50%, #ffd980 100%); }
.bar-stamina .bar-fill { background: linear-gradient(90deg, #b8551c 0%, #ff8d33 50%, #ffc857 100%); box-shadow: 0 0 8px rgba(255,141,51,0.4); }
.bar-sm { height: 6px; }
.bar-md { height: 10px; }
.bar-lg { height: 16px; }
.bar-xl { height: 22px; }
.bar-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 11px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.9), 0 0 4px rgba(0,0,0,0.7);
  font-family: var(--font-title);
  letter-spacing: 0.05em;
}

/* ========== TOAST ========== */
#toast-host {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  background: linear-gradient(180deg, rgba(30,18,60,0.98), rgba(15,8,30,1));
  border: 1px solid var(--border-strong);
  border-left: 4px solid var(--primary);
  color: var(--text);
  border-radius: var(--r-md);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--sh-lg);
  animation: toastIn 0.3s ease;
  max-width: 340px;
  pointer-events: auto;
}
.toast i { font-size: 16px; }
.toast.success { border-left-color: var(--mint); }
.toast.success i { color: var(--mint); }
.toast.error { border-left-color: var(--blood); }
.toast.error i { color: var(--blood); }
.toast.gold { border-left-color: var(--gold); }
.toast.gold i { color: var(--gold); }
@keyframes toastIn { from { transform: translateX(120%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ========== MODAL ========== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at center, rgba(10,4,20,0.92) 0%, rgba(0,0,0,0.95) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: var(--z-modal);
  animation: fadeIn 0.25s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: linear-gradient(180deg, #1b0f38 0%, #0b0518 100%);
  border: 1px solid var(--border-gold);
  border-radius: var(--r-xl);
  padding: 28px;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--sh-lg), 0 0 50px rgba(233,185,99,0.1), var(--sh-inset);
  position: relative;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-title {
  font-family: var(--font-title);
  font-size: 22px;
  font-weight: 700;
  color: var(--gold);
  margin-bottom: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 10px;
}
.item-modal-img {
  display: inline-block;
  width: 48px;
  height: 48px;
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  filter: drop-shadow(0 2px 6px rgba(0,0,0,0.7));
  flex-shrink: 0;
}
.modal-body { color: var(--text); line-height: 1.55; }
.modal-actions { display: flex; gap: 10px; margin-top: 22px; }
.modal-actions .btn { flex: 1; }

/* ========== LOADER ========== */
.loader {
  width: 48px;
  height: 48px;
  margin: 60px auto;
  border: 3px solid var(--border-soft);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  position: relative;
}
.loader::before {
  content: "";
  position: absolute;
  inset: -6px;
  border: 2px solid var(--border-soft);
  border-bottom-color: var(--primary);
  border-radius: 50%;
  animation: spin 1.4s linear infinite reverse;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ========== RESPONSIVE ========== */
@media (max-width: 960px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}
