/* REALM UNBOUND — Celestial Dark Theme */
@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@400;700;900&family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --bg-deep: #0a0a14;
  --bg-dark: #0f0f1e;
  --bg-panel: #141428;
  --bg-panel-light: #1a1a35;
  --border: #2a2a4a;
  --border-glow: #4a3a8a;
  --text-primary: #e8e6f0;
  --text-secondary: #9896b0;
  --text-dim: #686680;
  --accent-indigo: #6366f1;
  --accent-purple: #8b5cf6;
  --accent-silver: #c0c0e0;
  --accent-gold: #fbbf24;
  --accent-cyan: #22d3ee;
  --hp-red: #ef4444;
  --hp-red-dark: #991b1b;
  --mp-blue: #3b82f6;
  --mp-blue-dark: #1e3a5f;
  --xp-green: #22c55e;
  --rarity-common: #9ca3af;
  --rarity-uncommon: #22c55e;
  --rarity-rare: #3b82f6;
  --rarity-epic: #a855f7;
  --rarity-legendary: #f59e0b;
  --rarity-mythic: #ef4444;
  --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.15);
  --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.4);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Inter', sans-serif;
  background: var(--bg-deep);
  color: var(--text-primary);
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-dark); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-indigo); }

/* Stars background */
.stars-bg {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(1px 1px at 20% 30%, rgba(255,255,255,0.3), transparent),
    radial-gradient(1px 1px at 40% 70%, rgba(255,255,255,0.2), transparent),
    radial-gradient(1px 1px at 60% 20%, rgba(255,255,255,0.3), transparent),
    radial-gradient(1px 1px at 80% 50%, rgba(255,255,255,0.15), transparent),
    radial-gradient(1px 1px at 10% 80%, rgba(255,255,255,0.2), transparent),
    radial-gradient(1px 1px at 90% 10%, rgba(255,255,255,0.25), transparent),
    radial-gradient(1px 1px at 50% 90%, rgba(255,255,255,0.2), transparent),
    radial-gradient(1px 1px at 30% 50%, rgba(255,255,255,0.15), transparent),
    radial-gradient(1px 1px at 70% 40%, rgba(255,255,255,0.3), transparent),
    radial-gradient(1px 1px at 15% 60%, rgba(255,255,255,0.2), transparent);
  animation: twinkle 8s ease-in-out infinite alternate;
}

@keyframes twinkle {
  0% { opacity: 0.6; }
  100% { opacity: 1; }
}

/* Main layout */
#app {
  position: relative; z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  min-width: 800px;
}

/* Main content row */
#main-row {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* Header */
#header {
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--bg-dark), var(--bg-panel));
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  height: 50px;
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

#header h1 {
  font-family: 'Cinzel', serif;
  font-size: 18px;
  font-weight: 900;
  background: linear-gradient(135deg, var(--accent-indigo), var(--accent-purple), var(--accent-silver));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  letter-spacing: 3px;
}

#header .mode-badge {
  font-size: 11px; padding: 3px 10px; border-radius: 12px;
  background: rgba(34, 197, 94, 0.15); color: var(--xp-green);
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.header-right { display: flex; gap: 10px; align-items: center; }
.header-btn {
  background: var(--bg-panel-light); border: 1px solid var(--border);
  color: var(--text-secondary); padding: 5px 12px; border-radius: 6px;
  cursor: pointer; font-size: 12px; transition: all 0.2s;
}
.header-btn:hover { border-color: var(--accent-indigo); color: var(--text-primary); }

/* Left panel — Character */
#character-panel {
  background: var(--bg-dark);
  overflow-y: auto;
  padding: 12px;
  width: 260px;
  min-width: 260px;
  max-width: 260px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100%;
}

.panel-title {
  font-family: 'Cinzel', serif;
  font-size: 11px; font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 2px; text-transform: uppercase;
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

/* Character avatar */
.char-avatar {
  width: 100%; aspect-ratio: 1;
  border-radius: 12px;
  border: 2px solid var(--border-glow);
  margin-bottom: 12px;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 40%, rgba(99,102,241,0.15), transparent 70%);
  overflow: hidden;
  position: relative;
}

.char-avatar canvas {
  width: 100%; height: 100%;
}

.char-name {
  font-family: 'Cinzel', serif;
  font-size: 16px; font-weight: 700;
  text-align: center;
  color: var(--accent-silver);
  margin-bottom: 2px;
}

.char-race-class {
  font-size: 11px; text-align: center;
  color: var(--text-dim); margin-bottom: 12px;
}

/* Bars */
.bar-container { margin-bottom: 8px; }
.bar-label {
  display: flex; justify-content: space-between;
  font-size: 11px; margin-bottom: 3px;
}
.bar-label span:first-child { color: var(--text-secondary); }
.bar-label span:last-child { color: var(--text-primary); font-weight: 600; }

.bar-track {
  height: 8px; border-radius: 4px;
  background: rgba(0,0,0,0.4);
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.05);
}

.bar-fill {
  height: 100%; border-radius: 4px;
  transition: width 0.5s ease;
  position: relative;
}

.bar-fill::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent 60%, rgba(255,255,255,0.2));
  border-radius: 4px;
}

.bar-hp .bar-fill { background: linear-gradient(90deg, var(--hp-red-dark), var(--hp-red)); }
.bar-mp .bar-fill { background: linear-gradient(90deg, var(--mp-blue-dark), var(--mp-blue)); }
.bar-xp .bar-fill { background: linear-gradient(90deg, #166534, var(--xp-green)); }

/* Stats grid */
.stats-grid {
  display: grid; grid-template-columns: 1fr 1fr 1fr;
  gap: 6px; margin-top: 12px;
}

.stat-box {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 4px;
  text-align: center;
}

.stat-box .stat-name {
  font-size: 9px; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 1px;
}

.stat-box .stat-value {
  font-size: 18px; font-weight: 700;
  color: var(--accent-indigo);
  margin-top: 2px;
}

.stat-box .stat-mod {
  font-size: 10px; color: var(--xp-green);
}

/* Center — Scene & Narrative */
#scene-panel {
  background: var(--bg-dark);
  display: flex; flex-direction: column;
  overflow: hidden;
  flex: 1;
  min-width: 0;
}

#scene-image {
  width: 100%; height: 180px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  position: relative; overflow: hidden;
  flex-shrink: 0;
}

#scene-image canvas {
  width: 100%; height: 100%;
}

.scene-overlay {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: linear-gradient(transparent, rgba(10,10,20,0.9));
  padding: 20px 15px 10px;
}

.scene-location {
  font-family: 'Cinzel', serif;
  font-size: 13px; font-weight: 700;
  color: var(--accent-silver);
  letter-spacing: 1px;
}

.scene-time {
  font-size: 10px; color: var(--text-dim);
}

/* Narrative area */
#narrative {
  flex: 1; overflow-y: auto;
  padding: 15px;
  display: flex; flex-direction: column;
  gap: 10px;
}

.narrative-entry {
  padding: 10px 12px;
  border-radius: 8px;
  border-left: 3px solid var(--border);
  background: var(--bg-panel);
  font-size: 13px;
  line-height: 1.6;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.narrative-entry.dm {
  border-left-color: var(--accent-indigo);
  background: linear-gradient(135deg, rgba(99,102,241,0.05), var(--bg-panel));
}

.narrative-entry.action {
  border-left-color: var(--accent-gold);
  background: linear-gradient(135deg, rgba(251,191,36,0.05), var(--bg-panel));
}

.narrative-entry.combat {
  border-left-color: var(--hp-red);
  background: linear-gradient(135deg, rgba(239,68,68,0.05), var(--bg-panel));
}

.narrative-entry.system {
  border-left-color: var(--xp-green);
  background: linear-gradient(135deg, rgba(34,197,94,0.05), var(--bg-panel));
  font-size: 11px;
}

.narrative-entry .entry-icon {
  font-size: 14px; margin-right: 6px;
}

/* Action bar */
#action-bar {
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  padding: 8px 12px;
  display: flex; gap: 8px; align-items: center;
  flex-shrink: 0;
}

#action-input {
  flex: 1;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: 'Inter', sans-serif;
  outline: none;
  transition: border-color 0.2s;
}

#action-input:focus { border-color: var(--accent-indigo); }
#action-input::placeholder { color: var(--text-dim); }

.action-btn {
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-panel-light);
  color: var(--text-primary);
  font-size: 12px; font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.action-btn:hover {
  border-color: var(--accent-indigo);
  background: rgba(99,102,241,0.15);
}

.action-btn.primary {
  background: linear-gradient(135deg, var(--accent-indigo), var(--accent-purple));
  border-color: transparent;
}

.action-btn.primary:hover {
  box-shadow: 0 0 15px rgba(99,102,241,0.3);
}

.quick-actions {
  display: flex; gap: 4px; flex-wrap: wrap;
  padding: 4px 12px;
  background: var(--bg-dark);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  max-height: 48px;
  overflow-y: auto;
}

.quick-btn {
  padding: 4px 10px; border-radius: 12px;
  background: var(--bg-panel-light);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 11px; cursor: pointer;
  transition: all 0.2s;
}

.quick-btn:hover {
  border-color: var(--accent-indigo);
  color: var(--text-primary);
}

/* Right panel — Tabs */
#right-panel {
  background: var(--bg-dark);
  display: flex; flex-direction: column;
  overflow: hidden;
  width: 280px;
  min-width: 280px;
  max-width: 280px;
  border-left: 1px solid var(--border);
  flex-shrink: 0;
  height: 100%;
}

.tab-bar {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
  flex-shrink: 0;
}

.tab-btn {
  flex: 1;
  padding: 10px 8px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-dim);
  font-size: 11px; font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.tab-btn:hover { color: var(--text-secondary); }
.tab-btn.active {
  color: var(--accent-indigo);
  border-bottom-color: var(--accent-indigo);
}
.tab-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: none;
  min-height: 0;
  max-height: 100%;
}

.tab-content.active { display: block; }

/* Inventory */
.inv-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.inv-slot {
  aspect-ratio: 1;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  position: relative;
  font-size: 20px;
}

.inv-slot:hover {
  border-color: var(--accent-indigo);
  transform: scale(1.05);
}

.inv-slot.rarity-common { border-color: var(--rarity-common); }
.inv-slot.rarity-uncommon { border-color: var(--rarity-uncommon); box-shadow: 0 0 8px rgba(34,197,94,0.2); }
.inv-slot.rarity-rare { border-color: var(--rarity-rare); box-shadow: 0 0 8px rgba(59,130,246,0.2); }
.inv-slot.rarity-epic { border-color: var(--rarity-epic); box-shadow: 0 0 10px rgba(168,85,247,0.2); }
.inv-slot.rarity-legendary { border-color: var(--rarity-legendary); box-shadow: 0 0 12px rgba(245,158,11,0.3); }
.inv-slot.rarity-mythic { border-color: var(--rarity-mythic); box-shadow: 0 0 15px rgba(239,68,68,0.3); }

.inv-slot .item-count {
  position: absolute; bottom: 2px; right: 4px;
  font-size: 9px; color: var(--text-dim);
}

/* Quest log */
.quest-item {
  padding: 10px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.quest-item:hover { border-color: var(--accent-indigo); }
.quest-item.completed { opacity: 0.5; }

.quest-name {
  font-size: 12px; font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.quest-difficulty {
  font-size: 10px; padding: 2px 6px; border-radius: 4px;
  display: inline-block; margin-bottom: 4px;
}

.diff-easy { background: rgba(34,197,94,0.15); color: var(--xp-green); }
.diff-medium { background: rgba(251,191,36,0.15); color: var(--accent-gold); }
.diff-hard { background: rgba(239,68,68,0.15); color: var(--hp-red); }

.quest-desc {
  font-size: 11px; color: var(--text-secondary);
  line-height: 1.4;
}

/* Combat overlay */
#combat-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 100;
  background: rgba(10,10,20,0.95);
  flex-direction: column;
  align-items: center; justify-content: center;
}

#combat-overlay.active { display: flex; }

.combat-title {
  font-family: 'Cinzel', serif;
  font-size: 24px; font-weight: 900;
  color: var(--hp-red);
  letter-spacing: 4px;
  margin-bottom: 20px;
  text-shadow: 0 0 20px rgba(239,68,68,0.5);
}

.combat-arena {
  display: flex; gap: 40px;
  align-items: center;
  margin-bottom: 20px;
}

.combatant {
  text-align: center;
  padding: 20px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  min-width: 160px;
}

.combatant.enemy { border-color: var(--hp-red); }
.combatant.player { border-color: var(--accent-indigo); }

.combatant-name {
  font-family: 'Cinzel', serif;
  font-size: 14px; font-weight: 700;
  margin-bottom: 8px;
}

.combatant-hp-bar {
  width: 100%; height: 6px;
  background: rgba(0,0,0,0.4);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 6px;
}

.combatant-hp-fill {
  height: 100%;
  background: var(--hp-red);
  border-radius: 3px;
  transition: width 0.5s ease;
}

.combat-vs {
  font-size: 28px; font-weight: 900;
  color: var(--accent-gold);
  text-shadow: 0 0 15px rgba(251,191,36,0.5);
}

.combat-actions {
  display: flex; gap: 8px; flex-wrap: wrap;
  justify-content: center;
  max-width: 500px;
}

.combat-log {
  max-width: 500px; max-height: 120px;
  overflow-y: auto;
  margin-top: 15px;
  padding: 10px;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 11px;
  line-height: 1.6;
}

/* Tooltip */
.tooltip {
  display: none;
  position: fixed;
  background: var(--bg-panel);
  border: 1px solid var(--border-glow);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 11px;
  max-width: 220px;
  z-index: 200;
  pointer-events: none;
  box-shadow: var(--shadow-card);
}

.tooltip.visible { display: block; }
.tooltip-name { font-weight: 700; margin-bottom: 4px; }
.tooltip-rarity { font-size: 10px; margin-bottom: 6px; }
.tooltip-desc { color: var(--text-secondary); line-height: 1.4; }

/* Notifications */
#notifications {
  position: fixed; top: 60px; right: 20px;
  z-index: 300;
  display: flex; flex-direction: column;
  gap: 6px;
}

.notification {
  padding: 10px 16px;
  background: var(--bg-panel);
  border: 1px solid var(--border-glow);
  border-radius: 8px;
  font-size: 12px;
  animation: slideIn 0.3s ease, fadeOut 0.3s ease 3s forwards;
  box-shadow: var(--shadow-card);
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes fadeOut {
  to { opacity: 0; transform: translateX(50px); }
}

/* Loading */
.loading-overlay {
  position: fixed; inset: 0;
  background: rgba(10,10,20,0.8);
  display: flex; align-items: center; justify-content: center;
  z-index: 500;
}

.loading-spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent-indigo);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Responsive */
@media (max-width: 900px) {
  #main-row {
    flex-direction: column;
  }
  #character-panel, #right-panel {
    display: none;
  }
  #scene-image {
    height: 120px;
  }
}
