/* ==========================================================================
   Cave Quest - Dark Fantasy RPG Stylesheet
   ========================================================================== */

/* ---------- CSS Custom Properties ---------- */
:root {
  --bg-dark: #0a0a0f;
  --bg-panel: rgba(10, 10, 20, 0.92);
  --bg-panel-solid: #0e0e1a;
  --text-primary: #e0d5c0;
  --text-dim: #8a8070;
  --text-bright: #f5eedd;
  --accent-gold: #c4a35a;
  --accent-gold-bright: #e0c878;
  --accent-gold-dim: #8a7340;
  --hp-dark: #8b1a1a;
  --hp-light: #cc3333;
  --mp-dark: #1a3d8b;
  --mp-light: #3366cc;
  --xp-dark: #8b7a1a;
  --xp-light: #ccaa33;
  --sp-dark: #1a8b3d;
  --sp-light: #33cc66;
  --border-color: #333;
  --border-highlight: #555;
  --btn-bg: #2a2a3a;
  --btn-hover: #3a3a4a;
  --btn-active: #4a4a5a;
  --panel-radius: 6px;
  --slot-size: 56px;
  --transition-speed: 0.25s;
  --font-fantasy: 'MedievalSharp', serif;
  --font-ui: 'MedievalSharp', 'Segoe UI', serif;
}

/* ---------- Performance Stats ---------- */
#perf-stats {
  position: fixed;
  bottom: 4px;
  right: 4px;
  font-size: 0.65rem;
  color: rgba(255, 255, 255, 0.3);
  z-index: 5;
  pointer-events: none;
  font-family: monospace;
}

/* ---------- Reset & Base ---------- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-dark);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Scrollbar (dark theme) ---------- */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: rgba(10, 10, 20, 0.5);
}
::-webkit-scrollbar-thumb {
  background: #444;
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: #555;
}

/* ---------- Screen Management ---------- */
.screen {
  display: none;
}
.screen.active {
  display: block;
}

/* Panels and modals use hidden class */
.hidden {
  display: none !important;
}

/* ==========================================================================
   1. AUTH SCREEN
   ========================================================================== */
#auth-screen {
  position: fixed;
  inset: 0;
  display: none;
  justify-content: center;
  align-items: center;
  background:
    radial-gradient(ellipse at center, rgba(30, 20, 10, 0.6) 0%, var(--bg-dark) 70%),
    var(--bg-dark);
  z-index: 1000;
}
#auth-screen.active {
  display: flex;
}

.auth-container {
  width: 100%;
  max-width: 420px;
  padding: 40px 36px 36px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--panel-radius);
  text-align: center;
}

.game-title {
  font-family: var(--font-fantasy);
  font-size: 4rem;
  letter-spacing: 0.25em;
  color: var(--accent-gold);
  text-shadow:
    0 0 20px rgba(196, 163, 90, 0.4),
    0 0 60px rgba(196, 163, 90, 0.15),
    2px 2px 0 #1a1200;
  margin-bottom: 4px;
  user-select: none;
}

.game-subtitle {
  color: var(--text-dim);
  font-size: 0.95rem;
  margin-bottom: 28px;
  letter-spacing: 0.08em;
}

/* Auth Tabs */
.auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 24px;
  border-bottom: 2px solid var(--border-color);
}

.auth-tab {
  flex: 1;
  padding: 10px 0;
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: var(--font-ui);
  font-size: 1rem;
  cursor: pointer;
  transition: color var(--transition-speed), border-color var(--transition-speed);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
}
.auth-tab:hover {
  color: var(--text-primary);
}
.auth-tab.active {
  color: var(--accent-gold);
  border-bottom-color: var(--accent-gold);
}

/* Auth Forms */
.auth-form {
  display: none;
  flex-direction: column;
  gap: 16px;
}
.auth-form.active {
  display: flex;
}

.form-group {
  text-align: left;
}
.form-group label {
  display: block;
  margin-bottom: 6px;
  color: var(--text-dim);
  font-size: 0.85rem;
  letter-spacing: 0.04em;
}
.form-group input {
  width: 100%;
  padding: 10px 14px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 0.95rem;
  outline: none;
  transition: border-color var(--transition-speed);
}
.form-group input::placeholder {
  color: rgba(224, 213, 192, 0.3);
}
.form-group input:focus {
  border-color: var(--accent-gold-dim);
}

/* Auth Error */
.auth-error {
  margin-top: 14px;
  padding: 0;
  color: #cc4444;
  font-size: 0.85rem;
  min-height: 20px;
  transition: opacity var(--transition-speed);
}
.auth-error:empty {
  opacity: 0;
}

/* ==========================================================================
   BUTTONS
   ========================================================================== */
.btn {
  padding: 10px 24px;
  border: 1px solid var(--accent-gold-dim);
  border-radius: 4px;
  background: var(--btn-bg);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 1rem;
  cursor: pointer;
  transition:
    background var(--transition-speed),
    border-color var(--transition-speed),
    transform 0.1s;
  user-select: none;
}
.btn:hover {
  background: var(--btn-hover);
  border-color: var(--accent-gold);
}
.btn:active {
  background: var(--btn-active);
  transform: scale(0.97);
}
.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: linear-gradient(180deg, #3a3520 0%, #2a2510 100%);
  border-color: var(--accent-gold);
  color: var(--accent-gold-bright);
}
.btn-primary:hover {
  background: linear-gradient(180deg, #4a4530 0%, #3a3520 100%);
}

.btn-auth {
  width: 100%;
  padding: 12px;
  font-size: 1.05rem;
  letter-spacing: 0.06em;
  margin-top: 4px;
}

/* ==========================================================================
   2. CHARACTER CREATION SCREEN
   ========================================================================== */
#character-create-screen {
  position: fixed;
  inset: 0;
  display: none;
  justify-content: center;
  align-items: center;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(40, 30, 15, 0.5) 0%, var(--bg-dark) 65%),
    var(--bg-dark);
  z-index: 1000;
  overflow-y: auto;
  padding: 20px;
}
#character-create-screen.active {
  display: flex;
}

.create-container {
  width: 100%;
  max-width: 960px;
  text-align: center;
}

.create-title {
  font-family: var(--font-fantasy);
  font-size: 2.6rem;
  color: var(--accent-gold);
  text-shadow: 0 0 30px rgba(196, 163, 90, 0.3);
  margin-bottom: 4px;
}
.create-subtitle {
  color: var(--text-dim);
  font-size: 0.95rem;
  margin-bottom: 32px;
}

/* Race Cards */
.race-selection {
  display: flex;
  gap: 14px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 32px;
}

.race-card {
  width: 168px;
  padding: 20px 14px 16px;
  background: var(--bg-panel);
  border: 2px solid var(--border-color);
  border-radius: var(--panel-radius);
  cursor: pointer;
  transition:
    border-color var(--transition-speed),
    transform var(--transition-speed),
    box-shadow var(--transition-speed);
  text-align: center;
}
.race-card:hover {
  border-color: var(--accent-gold-dim);
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.race-card.selected {
  border-color: var(--accent-gold);
  box-shadow:
    0 0 16px rgba(196, 163, 90, 0.2),
    0 8px 24px rgba(0, 0, 0, 0.5);
  transform: translateY(-4px);
}

.race-icon {
  font-size: 2.6rem;
  margin-bottom: 8px;
  line-height: 1;
}

.race-name {
  font-family: var(--font-fantasy);
  font-size: 1.2rem;
  color: var(--accent-gold);
  margin-bottom: 6px;
}

.race-desc {
  font-size: 0.75rem;
  color: var(--text-dim);
  line-height: 1.35;
  margin-bottom: 12px;
  min-height: 36px;
}

/* Mini stat bars on race cards */
.race-stats {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.stat-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.7rem;
}
.stat-label {
  width: 28px;
  text-align: right;
  color: var(--text-dim);
  font-weight: 600;
  letter-spacing: 0.04em;
}
.stat-bar-mini {
  flex: 1;
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
  overflow: hidden;
}
.stat-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-gold-dim), var(--accent-gold));
  border-radius: 3px;
  transition: width 0.4s ease;
}
.stat-fill.str { background: linear-gradient(90deg, #8b2020, #cc4444); }
.stat-fill.spd { background: linear-gradient(90deg, #1a6b3a, #33cc66); }
.stat-fill.mag { background: linear-gradient(90deg, #3a1a8b, #7733cc); }
.stat-fill.sta { background: linear-gradient(90deg, #8b6b1a, #ccaa33); }
.stat-val {
  width: 16px;
  text-align: left;
  color: var(--text-dim);
}

/* Bottom area: name + button */
.create-bottom {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
}
.name-input-group {
  width: 260px;
}
.name-input-group input {
  width: 100%;
  padding: 10px 14px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 1rem;
  outline: none;
  transition: border-color var(--transition-speed);
}
.name-input-group input:focus {
  border-color: var(--accent-gold-dim);
}
.name-input-group input::placeholder {
  color: rgba(224, 213, 192, 0.3);
}

.btn-begin {
  padding: 10px 32px;
  font-size: 1.1rem;
  letter-spacing: 0.06em;
}

/* ==========================================================================
   3. GAME CONTAINER
   ========================================================================== */
#game-container {
  position: fixed;
  inset: 0;
  z-index: 1;
  background: #000;
}
#game-container canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

/* ==========================================================================
   4. HUD OVERLAY
   ========================================================================== */
#hud {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}
#hud > * {
  pointer-events: auto;
}

/* --- Top Left: Character Info + Bars --- */
#hud-top-left {
  position: absolute;
  top: 16px;
  left: 16px;
  width: 260px;
}

#hud-char-info {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 8px;
}
#hud-char-name {
  font-family: var(--font-fantasy);
  font-size: 1.2rem;
  color: var(--accent-gold);
}
#hud-char-level {
  font-size: 0.85rem;
  color: var(--text-dim);
}
.hud-race-badge {
  font-size: 0.7rem;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.06);
  padding: 1px 8px;
  border-radius: 3px;
  letter-spacing: 0.04em;
}

/* HUD Bars */
#hud-bars {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
}
.hud-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 18px;
}
.hud-bar-label {
  width: 22px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-align: right;
}
.hp-bar .hud-bar-label { color: var(--hp-light); }
.mp-bar .hud-bar-label { color: var(--mp-light); }
.stamina-bar .hud-bar-label { color: var(--sp-light); }
.xp-bar .hud-bar-label { color: var(--xp-light); }

.hud-bar-track {
  flex: 1;
  height: 10px;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 5px;
  overflow: hidden;
}

.hud-bar-fill {
  height: 100%;
  border-radius: 5px;
  transition: width 0.35s ease;
}
.hp-fill { background: linear-gradient(90deg, var(--hp-dark), var(--hp-light)); }
.mp-fill { background: linear-gradient(90deg, var(--mp-dark), var(--mp-light)); }
.stamina-fill { background: linear-gradient(90deg, var(--sp-dark), var(--sp-light)); }
.xp-fill { background: linear-gradient(90deg, var(--xp-dark), var(--xp-light)); }

.hud-bar-text {
  font-size: 0.7rem;
  color: var(--text-dim);
  min-width: 60px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Gold display */
#hud-gold {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
}
.gold-icon {
  font-size: 1rem;
}
#hud-gold-amount {
  color: var(--accent-gold);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* --- Zone Name --- */
#hud-zone {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
}
#hud-zone-name {
  font-family: var(--font-fantasy);
  font-size: 1.1rem;
  color: var(--text-primary);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
  letter-spacing: 0.08em;
  background: rgba(0, 0, 0, 0.35);
  padding: 4px 20px;
  border-radius: 4px;
}

/* ==========================================================================
   10. MINIMAP
   ========================================================================== */
#minimap {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 164px;
  height: 184px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--panel-radius);
  overflow: hidden;
}
#minimap-canvas {
  display: block;
  width: 160px;
  height: 160px;
  margin: 2px;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.4);
}
.minimap-label {
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-dim);
  padding: 2px 0;
  letter-spacing: 0.06em;
}

/* ==========================================================================
   11. TARGET INFO
   ========================================================================== */
#target-info {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  margin-top: 40px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--panel-radius);
  padding: 8px 20px 10px;
  text-align: center;
  min-width: 200px;
  transition: opacity var(--transition-speed);
}
#target-name {
  font-family: var(--font-fantasy);
  font-size: 1rem;
  color: var(--hp-light);
  margin-right: 8px;
}
#target-level {
  font-size: 0.75rem;
  color: var(--text-dim);
}
.target-hp-bar {
  width: 100%;
  height: 8px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 4px;
  margin-top: 6px;
  overflow: hidden;
}
.target-hp-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--hp-dark), var(--hp-light));
  border-radius: 4px;
  transition: width 0.25s ease;
}
.target-hp-text {
  font-size: 0.7rem;
  color: var(--text-dim);
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   12. COMBAT LOG
   ========================================================================== */
#combat-log {
  position: absolute;
  bottom: 90px;
  left: 16px;
  width: 320px;
  max-height: 120px;
  pointer-events: none;
}
#combat-log-messages {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
#combat-log-messages .log-entry {
  font-size: 0.78rem;
  color: var(--text-dim);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
  padding: 1px 0;
  opacity: 0.85;
  animation: logFadeIn 0.3s ease;
}
#combat-log-messages .log-entry.damage  { color: #cc5555; }
#combat-log-messages .log-entry.heal    { color: #55cc55; }
#combat-log-messages .log-entry.info    { color: #8899bb; }
#combat-log-messages .log-entry.loot    { color: var(--accent-gold); }

@keyframes logFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 0.85; transform: translateY(0); }
}

/* ==========================================================================
   7. SPELL BAR
   ========================================================================== */
#spell-bar {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  padding: 6px 10px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--panel-radius);
}

.spell-slot {
  width: var(--slot-size);
  height: 68px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 4px;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color var(--transition-speed);
  overflow: hidden;
}
.spell-slot:hover {
  border-color: var(--accent-gold-dim);
}

.spell-key {
  position: absolute;
  top: 2px;
  left: 4px;
  font-size: 0.6rem;
  color: var(--text-dim);
  font-weight: 700;
}
.spell-icon {
  font-size: 1.4rem;
  line-height: 1;
  margin-bottom: 2px;
}
.spell-name {
  font-size: 0.55rem;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.15;
  max-width: 100%;
  overflow: hidden;
}
.spell-cost {
  font-size: 0.55rem;
  color: var(--mp-light);
  margin-top: 1px;
}

/* Cooldown overlay */
.spell-cooldown-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  pointer-events: none;
  transform-origin: bottom;
  transform: scaleY(0);
}
.spell-slot.on-cooldown .spell-cooldown-overlay {
  transform: scaleY(1);
  animation: cooldownShrink var(--cd-duration, 2s) linear forwards;
}

@keyframes cooldownShrink {
  from { transform: scaleY(1); }
  to   { transform: scaleY(0); }
}

/* ==========================================================================
   5. INVENTORY PANEL
   ========================================================================== */
.panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--panel-radius);
  z-index: 100;
  animation: panelOpen 0.2s ease;
}

@keyframes panelOpen {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.95); }
  to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-color);
}
.panel-title {
  font-family: var(--font-fantasy);
  font-size: 1.3rem;
  color: var(--accent-gold);
  letter-spacing: 0.06em;
}
.panel-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  padding: 4px 8px;
  transition: color var(--transition-speed);
}
.panel-close:hover {
  color: var(--text-primary);
}

/* Inventory Layout */
#inventory-panel {
  width: 580px;
  max-width: 95vw;
}

.inventory-layout {
  display: flex;
  gap: 16px;
  padding: 16px 18px;
}

/* Inventory Grid */
.inventory-grid-section {
  flex: 1;
}
.inventory-grid {
  display: grid;
  grid-template-columns: repeat(6, var(--slot-size));
  grid-template-rows: repeat(5, var(--slot-size));
  gap: 4px;
}
.inv-slot {
  width: var(--slot-size);
  height: var(--slot-size);
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  cursor: pointer;
  transition: border-color var(--transition-speed), background var(--transition-speed);
  position: relative;
}
.inv-slot:hover {
  border-color: var(--accent-gold-dim);
  background: rgba(196, 163, 90, 0.06);
}
.inv-slot.has-item {
  border-color: rgba(255, 255, 255, 0.12);
}
.inv-slot .item-count {
  position: absolute;
  bottom: 1px;
  right: 3px;
  font-size: 0.6rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

/* Equipment Section */
.equipment-section {
  width: 140px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.equipment-title {
  font-family: var(--font-fantasy);
  font-size: 0.95rem;
  color: var(--accent-gold-dim);
  margin-bottom: 10px;
  letter-spacing: 0.04em;
}
.equipment-slots {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
}
.equip-slot {
  width: 60px;
  height: 60px;
  background: rgba(196, 163, 90, 0.04);
  border: 1px solid var(--accent-gold-dim);
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition-speed);
  position: relative;
}
.equip-slot:hover {
  background: rgba(196, 163, 90, 0.1);
}
.equip-label {
  font-size: 0.6rem;
  color: var(--accent-gold-dim);
  position: absolute;
  bottom: 2px;
  letter-spacing: 0.03em;
}

/* Inventory Stats */
.inventory-stats {
  padding: 10px 18px 16px;
  border-top: 1px solid var(--border-color);
}
.stats-title {
  font-family: var(--font-fantasy);
  font-size: 0.9rem;
  color: var(--accent-gold-dim);
  margin-bottom: 8px;
}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}
.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.stat-name {
  font-size: 0.7rem;
  color: var(--text-dim);
  letter-spacing: 0.06em;
  font-weight: 600;
}
.stat-value {
  font-size: 1rem;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   6. SHOP PANEL
   ========================================================================== */
#shop-panel {
  width: 560px;
  max-width: 95vw;
  max-height: 80vh;
}

.shop-gold {
  padding: 10px 18px;
  font-size: 0.95rem;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border-color);
}
#shop-gold-amount {
  color: var(--accent-gold);
  font-weight: 600;
}

.shop-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
}
.shop-column {
  padding: 12px 16px;
}
.shop-column:first-child {
  border-right: 1px solid var(--border-color);
}
.shop-column-title {
  font-family: var(--font-fantasy);
  font-size: 1rem;
  color: var(--accent-gold);
  margin-bottom: 10px;
  letter-spacing: 0.04em;
}

.shop-item-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 300px;
  overflow-y: auto;
}

.shop-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid transparent;
  border-radius: 3px;
  cursor: pointer;
  transition: border-color var(--transition-speed), background var(--transition-speed);
}
.shop-item:hover {
  border-color: var(--accent-gold-dim);
  background: rgba(196, 163, 90, 0.06);
}
.shop-item-icon {
  font-size: 1.3rem;
  width: 28px;
  text-align: center;
}
.shop-item-info {
  flex: 1;
}
.shop-item-name {
  font-size: 0.85rem;
  color: var(--text-primary);
}
.shop-item-detail {
  font-size: 0.7rem;
  color: var(--text-dim);
}
.shop-item-price {
  font-size: 0.85rem;
  color: var(--accent-gold);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.shop-item-btn {
  padding: 4px 12px;
  font-size: 0.75rem;
  border: 1px solid var(--accent-gold-dim);
  border-radius: 3px;
  background: var(--btn-bg);
  color: var(--text-primary);
  cursor: pointer;
  font-family: var(--font-ui);
  transition: background var(--transition-speed);
}
.shop-item-btn:hover {
  background: var(--btn-hover);
}

/* ==========================================================================
   8. LEVEL UP MODAL
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 500;
  animation: overlayFadeIn 0.3s ease;
}

@keyframes overlayFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal-content {
  background: var(--bg-panel-solid);
  border: 1px solid var(--border-color);
  border-radius: var(--panel-radius);
  padding: 32px 40px;
  text-align: center;
  animation: modalSlideIn 0.35s ease;
  max-width: 90vw;
}

@keyframes modalSlideIn {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.levelup-content {
  width: 360px;
}

.levelup-title {
  font-family: var(--font-fantasy);
  font-size: 2.4rem;
  color: var(--accent-gold);
  text-shadow: 0 0 30px rgba(196, 163, 90, 0.5);
  margin-bottom: 4px;
  animation: levelupGlow 1.5s ease-in-out infinite alternate;
}
@keyframes levelupGlow {
  from { text-shadow: 0 0 20px rgba(196, 163, 90, 0.3); }
  to   { text-shadow: 0 0 40px rgba(196, 163, 90, 0.6), 0 0 80px rgba(196, 163, 90, 0.2); }
}

.levelup-subtitle {
  color: var(--text-dim);
  font-size: 0.95rem;
  margin-bottom: 24px;
}
#levelup-new-level {
  color: var(--accent-gold-bright);
}

.levelup-stats {
  margin-bottom: 24px;
}
.levelup-points {
  font-size: 0.9rem;
  color: var(--accent-gold);
  margin-bottom: 14px;
  letter-spacing: 0.04em;
}
#levelup-points-remaining {
  font-size: 1.1rem;
  font-weight: 700;
}

.levelup-stat-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 6px 0;
}
.levelup-stat-row .stat-name {
  width: 36px;
  text-align: right;
  font-size: 0.85rem;
  color: var(--text-dim);
  font-weight: 600;
  letter-spacing: 0.06em;
}
.levelup-stat-row .stat-value {
  width: 28px;
  text-align: center;
  font-size: 1rem;
  color: var(--text-primary);
}
.stat-added {
  width: 28px;
  text-align: center;
  font-size: 0.9rem;
  color: var(--accent-gold);
  font-variant-numeric: tabular-nums;
}

.btn-stat-minus,
.btn-stat-plus {
  width: 28px;
  height: 28px;
  background: var(--btn-bg);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-speed), border-color var(--transition-speed);
  font-family: var(--font-ui);
  line-height: 1;
}
.btn-stat-minus:hover,
.btn-stat-plus:hover {
  background: var(--btn-hover);
  border-color: var(--accent-gold-dim);
}

/* ==========================================================================
   9. DEATH SCREEN
   ========================================================================== */
.death-content {
  width: 340px;
}
.death-title {
  font-family: var(--font-fantasy);
  font-size: 3rem;
  color: var(--hp-light);
  text-shadow: 0 0 30px rgba(204, 51, 51, 0.5);
  margin-bottom: 12px;
  letter-spacing: 0.08em;
}
.death-penalty {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-bottom: 24px;
}
.death-penalty strong {
  color: var(--hp-light);
}

/* ==========================================================================
   TOOLTIP (for item hover)
   ========================================================================== */
.tooltip {
  position: fixed;
  z-index: 600;
  background: var(--bg-panel-solid);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 8px 12px;
  pointer-events: none;
  font-size: 0.8rem;
  max-width: 200px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.6);
}
.tooltip-name {
  color: var(--accent-gold);
  font-family: var(--font-fantasy);
  margin-bottom: 4px;
}
.tooltip-desc {
  color: var(--text-dim);
  font-size: 0.72rem;
  line-height: 1.3;
}

/* ==========================================================================
   FLOATING TEXT (damage/heal numbers)
   ========================================================================== */
#floating-texts {
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
}
.floating-text {
  position: absolute;
  font-family: var(--font-fantasy);
  font-size: 1.2rem;
  font-weight: 700;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9), 0 0 8px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
  pointer-events: none;
  transform: translateX(-50%);
  transition: opacity 0.1s linear;
}

/* ==========================================================================
   SHOP HINT
   ========================================================================== */
#shop-hint {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-panel);
  border: 1px solid var(--accent-gold-dim);
  border-radius: var(--panel-radius);
  padding: 8px 20px;
  font-size: 0.9rem;
  color: var(--accent-gold);
  z-index: 20;
  text-align: center;
  letter-spacing: 0.04em;
  pointer-events: none;
}

/* ==========================================================================
   SHIELD INDICATOR
   ========================================================================== */
#shield-indicator {
  position: fixed;
  top: 140px;
  left: 16px;
  background: rgba(68, 68, 255, 0.2);
  border: 1px solid #4444ff;
  border-radius: var(--panel-radius);
  padding: 4px 12px;
  font-size: 0.8rem;
  color: #8888ff;
  z-index: 15;
  pointer-events: none;
}

/* ==========================================================================
   INVENTORY ITEM DISPLAY (JS-generated)
   ========================================================================== */
.inv-icon {
  font-size: 1.4rem;
  line-height: 1;
}
.inv-qty {
  position: absolute;
  bottom: 1px;
  right: 3px;
  font-size: 0.6rem;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}
.inv-equipped {
  position: absolute;
  top: 1px;
  right: 3px;
  font-size: 0.55rem;
  color: var(--accent-gold);
  font-weight: 700;
}

/* Equipment slot fills */
.equip-icon {
  font-size: 1.3rem;
  line-height: 1;
}
.equip-name {
  font-size: 0.55rem;
  text-align: center;
  line-height: 1.1;
  margin-top: 2px;
}
.equip-empty {
  font-size: 0.6rem;
  color: var(--accent-gold-dim);
}

/* Item action menu */
.item-actions-menu {
  position: absolute;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-panel-solid);
  border: 1px solid var(--border-color);
  border-radius: var(--panel-radius);
  padding: 12px 16px;
  z-index: 110;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 160px;
  text-align: center;
}
.item-action-header {
  font-family: var(--font-fantasy);
  font-size: 1rem;
  margin-bottom: 2px;
}
.item-action-desc {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.item-actions-menu button {
  padding: 6px 12px;
  background: var(--btn-bg);
  border: 1px solid var(--border-color);
  border-radius: 3px;
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background var(--transition-speed);
}
.item-actions-menu button:hover {
  background: var(--btn-hover);
  border-color: var(--accent-gold-dim);
}

/* ==========================================================================
   SHOP ITEM BUTTONS & STATES (JS-generated)
   ========================================================================== */
.shop-buy-btn, .shop-sell-btn {
  padding: 4px 12px;
  font-size: 0.75rem;
  border: 1px solid var(--accent-gold-dim);
  border-radius: 3px;
  background: var(--btn-bg);
  color: var(--text-primary);
  cursor: pointer;
  font-family: var(--font-ui);
  transition: background var(--transition-speed);
  white-space: nowrap;
}
.shop-buy-btn:hover, .shop-sell-btn:hover {
  background: var(--btn-hover);
}
.shop-buy-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.too-expensive {
  color: #cc4444 !important;
}
.level-locked {
  opacity: 0.5;
}
.shop-item-level {
  font-size: 0.7rem;
  color: var(--text-dim);
  white-space: nowrap;
}
.shop-item-qty {
  font-size: 0.75rem;
  color: var(--text-dim);
}
.shop-empty {
  font-size: 0.85rem;
  color: var(--text-dim);
  text-align: center;
  padding: 20px 0;
}

/* Spell bar states */
.spell-slot.on-cooldown {
  opacity: 0.6;
}
.spell-slot.no-mana {
  border-color: rgba(139, 26, 26, 0.4);
}
.spell-empty {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.15);
}

/* Stat line in inventory stats */
.stat-line {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  padding: 2px 0;
  color: var(--text-dim);
}
.stat-line span:last-child {
  color: var(--text-primary);
}

/* Level up hint text */
.levelup-hint {
  color: var(--text-dim);
  font-size: 0.85rem;
  margin-top: 16px;
}

/* ==========================================================================
   SHIFT LOCK - Crosshair & Indicator
   ========================================================================== */
#shiftlock-crosshair {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 20;
  pointer-events: none;
}
#shiftlock-crosshair.hidden {
  display: none;
}
.crosshair-dot {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 4px;
  height: 4px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 50%;
}
.crosshair-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 24px;
  height: 24px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 50%;
}
#shiftlock-indicator {
  position: fixed;
  bottom: 120px;
  right: 16px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: var(--panel-radius);
  padding: 4px 12px;
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.7);
  z-index: 15;
  pointer-events: none;
  letter-spacing: 0.5px;
}
#shiftlock-indicator.hidden {
  display: none;
}

/* ==========================================================================
   RESPONSIVE ADJUSTMENTS
   ========================================================================== */

/* Medium screens */
@media (max-width: 960px) {
  .race-selection {
    gap: 10px;
  }
  .race-card {
    width: 150px;
    padding: 16px 10px 14px;
  }
  #inventory-panel {
    width: 95vw;
  }
  .inventory-grid {
    grid-template-columns: repeat(6, 48px);
    grid-template-rows: repeat(5, 48px);
  }
  .inv-slot {
    width: 48px;
    height: 48px;
  }
}

/* Small screens */
@media (max-width: 680px) {
  .game-title {
    font-size: 2.8rem;
  }
  .auth-container {
    padding: 28px 24px 24px;
    max-width: 95vw;
  }
  .race-card {
    width: 140px;
    padding: 14px 8px 12px;
  }
  .race-desc {
    font-size: 0.68rem;
  }
  .create-title {
    font-size: 1.8rem;
  }

  #hud-top-left {
    width: 200px;
  }

  #combat-log {
    width: 240px;
    bottom: 80px;
  }

  #spell-bar {
    gap: 2px;
    padding: 4px 6px;
  }
  .spell-slot {
    width: 44px;
    height: 56px;
  }

  #minimap {
    width: 120px;
    height: 140px;
  }
  #minimap-canvas {
    width: 116px;
    height: 116px;
  }

  .shop-columns {
    grid-template-columns: 1fr;
  }
  .shop-column:first-child {
    border-right: none;
    border-bottom: 1px solid var(--border-color);
  }
  #shop-panel {
    max-height: 90vh;
    overflow-y: auto;
  }

  .inventory-layout {
    flex-direction: column;
    align-items: center;
  }
  .equipment-section {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
  }
  .equipment-slots {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
  }
  .equipment-title {
    width: 100%;
    text-align: center;
    margin-bottom: 6px;
  }
  .stats-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Very small screens */
@media (max-width: 420px) {
  .race-selection {
    flex-direction: column;
    align-items: center;
  }
  .race-card {
    width: 90%;
    max-width: 280px;
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-rows: auto auto;
    gap: 4px 12px;
    text-align: left;
    padding: 12px 16px;
  }
  .race-icon {
    grid-row: 1 / 3;
    align-self: center;
    font-size: 2rem;
  }
  .race-stats {
    grid-column: 1 / -1;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px 12px;
  }
  .stat-row {
    flex: 1;
    min-width: 100px;
  }
  .stat-bar-mini {
    display: none;
  }
  .spell-slot {
    width: 38px;
    height: 50px;
  }
}
