:root {
  --rarity-common: #c9c9c9;
  --rarity-uncommon: #4ade80;
  --rarity-rare: #60a5fa;
  --rarity-epic: #c084fc;
  --rarity-legendary: #fb923c;
  --rarity-set: #e63946;
  --hp: #e0453f;
  --mp: #3f8fe0;
  --sp: #e0c33f;
  --panel-bg: #14181f;
  --panel-border: #30384a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: #0a0c10;
  color: #e8e8ea;
  font-family: 'Trebuchet MS', 'Segoe UI', sans-serif;
  overflow: hidden;
  user-select: none;
}

.screen {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

.hidden { display: none !important; }

/* ===== class select ===== */
#screen-select {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, #1b1f2b 0%, #06070a 100%);
  padding: 16px;
}
.title-block { text-align: center; margin-bottom: 24px; }
.title-block h1 {
  font-size: clamp(32px, 8vw, 64px);
  letter-spacing: 6px;
  margin: 0;
  color: #f0c869;
  text-shadow: 0 0 20px rgba(240, 200, 105, 0.4);
}
.subtitle { color: #9aa0b0; margin: 4px 0 0; }

.name-row { display: flex; align-items: center; gap: 8px; margin-bottom: 20px; }
.name-row label { font-size: 13px; color: #aab0c0; }
.name-row input {
  background: #1a1d26;
  border: 1px solid #3a3f50;
  border-radius: 6px;
  color: #e8e8ea;
  padding: 7px 10px;
  font-size: 14px;
  width: 160px;
}

.class-cards {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 920px;
}
.class-card {
  background: var(--panel-bg);
  border: 2px solid var(--panel-border);
  border-radius: 12px;
  padding: 20px;
  width: 320px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}
.class-card:hover { transform: translateY(-4px); }
.class-card.selected { border-color: #f0c869; box-shadow: 0 0 24px rgba(240,200,105,0.25); }
.class-card h2 { margin: 8px 0 4px; }
.class-card p { color: #aab0c0; font-size: 14px; min-height: 60px; }
.class-card ul { font-size: 13px; color: #cfd4e0; padding-left: 18px; margin: 8px 0 0; }
.class-icon { width: 72px; height: 72px; border-radius: 50%; margin: 0 auto; position: relative; }
.melee-icon { background: radial-gradient(circle, #8a3b2a, #4a1d14); box-shadow: 0 0 18px rgba(200,80,40,0.4); }
.ranged-icon { background: radial-gradient(circle, #2a6a3b, #123a1d); box-shadow: 0 0 18px rgba(60,180,100,0.4); }

#btn-start {
  margin-top: 28px;
  padding: 14px 40px;
  font-size: 18px;
  background: #f0c869;
  color: #1a1206;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: bold;
  letter-spacing: 1px;
}
#btn-start:disabled { background: #3a3d45; color: #777; cursor: not-allowed; }

/* ===== loading ===== */
#screen-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #06070a;
}
.loading-box { text-align: center; width: 420px; }
.progress-outer {
  width: 100%;
  height: 18px;
  background: #1a1d26;
  border: 1px solid var(--panel-border);
  border-radius: 9px;
  overflow: hidden;
  margin: 16px 0;
}
.progress-inner {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #f0c869, #e08a3f);
  transition: width 0.1s linear;
}
#loading-label { color: #9aa0b0; font-size: 14px; }

/* ===== game screen ===== */
#screen-game { background: #000; }
#game-canvas { display: block; width: 100%; height: 100%; image-rendering: pixelated; }

#hud-top-left {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: rgba(10,12,16,0.55);
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.08);
}
.bar-row { display: flex; align-items: center; gap: 6px; }
.bar-label { width: 20px; font-size: 11px; font-weight: bold; color: #cfd4e0; }
.bar { position: relative; width: 170px; height: 14px; background: #1a1d26; border-radius: 4px; overflow: hidden; border: 1px solid rgba(255,255,255,0.1); }
.bar-fill { height: 100%; width: 100%; transition: width 0.15s ease-out; }
.bar-hp .bar-fill { background: linear-gradient(90deg, #a52a24, var(--hp)); }
.bar-mp .bar-fill { background: linear-gradient(90deg, #2a5ba5, var(--mp)); }
.bar-sp .bar-fill { background: linear-gradient(90deg, #a58d2a, var(--sp)); }
.bar-text { position: absolute; inset: 0; text-align: center; font-size: 10px; line-height: 14px; color: #fff; text-shadow: 0 1px 2px #000; }

#hud-level {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(10,12,16,0.55);
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.08);
}

#hud-gold {
  position: absolute;
  top: 60px;
  right: 14px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(10,12,16,0.55);
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.08);
  font-size: 13px;
  font-weight: bold;
  color: #f0c869;
}
.gold-coin { width: 14px; height: 14px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #ffe066, #b8860b); display: inline-block; border: 1px solid #fff3cf; }

#mob-info {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  background: rgba(10,12,16,0.75);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 8px;
  padding: 8px 14px;
  text-align: center;
  min-width: 220px;
  pointer-events: none;
}
#mob-info-name { font-size: 13px; font-weight: bold; margin-bottom: 5px; }
.mob-hp-bar { width: 220px; height: 14px; margin: 0 auto; }
#level-circle {
  width: 32px; height: 32px; border-radius: 50%;
  background: radial-gradient(circle, #f0c869, #a8762b);
  color: #1a1206; font-weight: bold;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  border: 2px solid #fff3cf;
}
#level-circle.ascended { box-shadow: 0 0 10px 2px #ffe066; border-color: #ffe066; }
.xp-outer { width: 140px; height: 8px; background: #1a1d26; border-radius: 4px; overflow: hidden; }
.xp-inner { height: 100%; width: 0%; background: #f0c869; transition: width 0.2s; }

#hotbar {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  gap: 10px;
}
.hotbar-slot {
  position: relative;
  width: 54px; height: 54px;
  background: rgba(10,12,16,0.7);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
}
.hotbar-key { position: absolute; top: 2px; left: 4px; font-size: 10px; color: #aab0c0; }
.hotbar-count { position: absolute; bottom: 2px; right: 4px; font-size: 11px; font-weight: bold; color: #fff; text-shadow: 0 1px 2px #000; }
.hotbar-icon { width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; }
.hotbar-icon svg { width: 100%; height: 100%; }

#corner-buttons {
  position: absolute;
  bottom: 16px;
  right: 16px;
  z-index: 10;
  display: flex;
  gap: 8px;
}
#btn-inventory-toggle, #btn-pause-toggle {
  width: 48px; height: 48px;
  font-size: 22px;
  background: rgba(10,12,16,0.7);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  cursor: pointer;
  color: #e8e8ea;
}

.cooldown-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: bold;
  color: #fff;
  background: rgba(0,0,0,0.55);
  border-radius: 8px;
  pointer-events: none;
}
.cooldown-text:empty { display: none; }

#screen-paused {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(5,6,9,0.78);
  display: flex;
  align-items: center;
  justify-content: center;
}
.pause-box {
  text-align: center;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 28px 36px;
}
.pause-box h2 { margin: 0 0 10px; color: #f0c869; letter-spacing: 2px; }
.pause-box p { margin: 4px 0; color: #aab0c0; font-size: 13px; }
#btn-resume {
  margin-top: 16px;
  padding: 10px 28px;
  font-size: 15px;
  background: #f0c869;
  color: #1a1206;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-weight: bold;
}

#fx-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 8;
  overflow: hidden;
}
.float-text {
  position: absolute;
  font-weight: bold;
  font-size: 14px;
  color: #fff;
  text-shadow: 0 1px 3px #000;
  animation: floatUp 0.9s ease-out forwards;
  pointer-events: none;
}
.float-text.dmg { color: #ff6b5e; }
.float-text.dmg-fire { color: #ff8a4a; }
.float-text.dmg-cold { color: #7ecbff; }
.float-text.dmg-poison { color: #9fe06a; }
.float-text.heal { color: #6effa0; }
.float-text.xp { color: #f0c869; font-size: 12px; }
@keyframes floatUp {
  from { transform: translateY(0); opacity: 1; }
  to { transform: translateY(-40px); opacity: 0; }
}

#toast {
  position: absolute;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 22, 30, 0.92);
  border: 1px solid rgba(255,255,255,0.15);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 20;
  transition: opacity 0.3s;
}

/* ===== inventory panel ===== */
#panel-inventory {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: min(760px, 92vw);
  max-height: 85vh;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
.panel-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--panel-border);
}
.panel-header h2 { margin: 0; font-size: 18px; }
#btn-close-inventory {
  background: none; border: none; color: #e8e8ea; font-size: 18px; cursor: pointer;
}
.panel-body,
.settings-body,
.skilltree-body {
  scrollbar-width: thin;
  scrollbar-color: #3a3f50 #14181f;
}
.panel-body::-webkit-scrollbar,
.settings-body::-webkit-scrollbar,
.skilltree-body::-webkit-scrollbar { width: 10px; }
.panel-body::-webkit-scrollbar-track,
.settings-body::-webkit-scrollbar-track,
.skilltree-body::-webkit-scrollbar-track { background: #14181f; }
.panel-body::-webkit-scrollbar-thumb,
.settings-body::-webkit-scrollbar-thumb,
.skilltree-body::-webkit-scrollbar-thumb { background: #3a3f50; border-radius: 5px; }
.panel-body::-webkit-scrollbar-thumb:hover,
.settings-body::-webkit-scrollbar-thumb:hover,
.skilltree-body::-webkit-scrollbar-thumb:hover { background: #4a5168; }

/* themed native form controls — otherwise browsers render these as plain
   white/square OS widgets that clash with the dark panels */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: #1a1d26;
  border-radius: 3px;
  border: 1px solid #3a3f50;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #f0c869;
  border: 2px solid #1a1206;
  cursor: pointer;
  margin-top: -1px;
}
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #f0c869;
  border: 2px solid #1a1206;
  cursor: pointer;
}
input[type="range"]::-moz-range-track { background: #1a1d26; border-radius: 3px; height: 6px; }

input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px; height: 18px;
  background: #1a1d26;
  border: 1px solid #3a3f50;
  border-radius: 4px;
  cursor: pointer;
  position: relative;
}
input[type="checkbox"]:checked { background: #f0c869; border-color: #f0c869; }
input[type="checkbox"]:checked::after {
  content: "✓";
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; color: #1a1206; font-weight: bold;
}

.panel-body { display: flex; gap: 20px; padding: 16px; overflow-y: auto; }
.equip-column { flex: 0 0 240px; }
.equip-grid {
  display: grid;
  grid-template-columns: repeat(3, 68px);
  grid-template-rows: repeat(4, 68px);
  grid-template-areas:
    ".       head    amulet"
    "weapon1 chest   weapon2"
    "gloves  belt    ring1"
    ".       ring2   .";
  gap: 8px;
  justify-content: center;
}
.equip-slot {
  background: #1a1d26;
  border: 1px dashed #3a3f50;
  border-radius: 8px;
  position: relative;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.equip-slot.filled { border-style: solid; }
.equip-slot.drag-over { border-color: #f0c869; background: #262b38; }
.slot-label { position: absolute; bottom: 2px; font-size: 9px; color: #6a7080; }
.equip-slot .item-icon { width: 40px; height: 40px; }
#stat-summary {
  margin-top: 16px;
  font-size: 13px;
  color: #cfd4e0;
  line-height: 1.6;
  background: #10131a;
  border-radius: 8px;
  padding: 10px;
}
.inventory-column { flex: 1; min-width: 300px; }
.inventory-column h3 { margin: 0 0 8px; font-size: 14px; color: #9aa0b0; }
.inventory-column h3 .hint { font-weight: normal; color: #5a6072; font-size: 11px; }
#trash-bin {
  margin-top: 10px;
  padding: 10px;
  text-align: center;
  font-size: 12px;
  color: #9aa0b0;
  border: 1px dashed #3a3f50;
  border-radius: 8px;
  background: #1a1d26;
}
#trash-bin.drag-over { border-color: #ff6b5e; background: #2a1a1a; color: #ff6b5e; }
.inventory-grid {
  display: grid;
  grid-template-columns: repeat(6, 50px);
  gap: 6px;
}
.inv-slot {
  width: 50px; height: 50px;
  background: #1a1d26;
  border: 1px solid #2a2f3c;
  border-radius: 6px;
  position: relative;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.inv-slot.drag-over { border-color: #f0c869; background: #262b38; }
.inv-slot .item-icon { width: 36px; height: 36px; }
.inv-slot .inv-count { position: absolute; bottom: 1px; right: 3px; font-size: 10px; font-weight: bold; color: #fff; text-shadow: 0 1px 2px #000; }

.item-icon {
  border-radius: 6px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
}
.item-icon svg { width: 72%; height: 72%; }
.item-icon.dragging { opacity: 0.35; }

#panel-settings {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: min(460px, 92vw);
  max-height: 85vh;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
#btn-close-settings {
  background: none; border: none; color: #e8e8ea; font-size: 18px; cursor: pointer;
}
.settings-body { padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.settings-row { display: flex; align-items: center; gap: 10px; }
.settings-row label { flex: 0 0 150px; font-size: 13px; color: #cfd4e0; }
.settings-row input[type="range"] { flex: 1; }
.settings-row select {
  flex: 1;
  background: #1a1d26;
  color: #e8e8ea;
  border: 1px solid #3a3f50;
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 13px;
}
.settings-val { width: 44px; text-align: right; font-size: 12px; color: #aab0c0; }
.settings-note { font-size: 11px; color: #6a7080; line-height: 1.5; margin: 0; }
.settings-row-check label { flex: 1 1 auto; }
.settings-row-check input[type="checkbox"] { flex: 0 0 auto; width: 18px; height: 18px; }
#btn-settings-reset {
  align-self: flex-start;
  padding: 8px 16px;
  background: #2a2f3c;
  color: #e8e8ea;
  border: 1px solid #3a3f50;
  border-radius: 6px;
  cursor: pointer;
}

#screen-flash {
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  opacity: 0;
  background: transparent;
}
#screen-flash.flash {
  animation: rareFlash 0.6s ease-out;
}
@keyframes rareFlash {
  0% { opacity: 0.55; }
  100% { opacity: 0; }
}

#panel-skilltree {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: min(420px, 92vw);
  max-height: 85vh;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
#panel-skilltree .panel-header .hint { font-size: 12px; color: #f0c869; font-weight: normal; margin-left: 6px; }
#btn-close-skilltree { background: none; border: none; color: #e8e8ea; font-size: 18px; cursor: pointer; }
.skilltree-body { padding: 12px 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.attr-section {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}
.attr-btn {
  background: #1a1d26;
  border: 1px solid #3a3f50;
  border-radius: 8px;
  padding: 8px;
  color: #e8e8ea;
  cursor: pointer;
  text-align: left;
}
.attr-btn:hover:not(:disabled) { border-color: #f0c869; background: #232820; }
.attr-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.attr-label { font-size: 13px; font-weight: bold; color: #f0c869; }
.attr-desc { font-size: 11px; color: #9aa0b0; margin-top: 2px; }
.attr-spent { font-size: 10px; color: #6a7080; margin-top: 2px; }
.skilltree-divider {
  font-size: 11px;
  color: #6a7080;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin: 8px 0 4px;
  border-top: 1px solid #2a2f3c;
  padding-top: 8px;
}
.talent-node {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid #2a2f3c;
  background: #1a1d26;
}
.talent-node.allocated { border-color: #f0c869; background: #262215; }
.talent-node.available { cursor: pointer; border-color: #4ade80; }
.talent-node.available:hover { background: #1f2a1f; }
.talent-node.locked { opacity: 0.4; }
.talent-node .talent-level { width: 26px; height: 26px; border-radius: 50%; background: #2a2f3c; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: bold; flex: none; }
.talent-node.allocated .talent-level { background: #f0c869; color: #1a1206; }
.talent-node .talent-info { flex: 1; }
.talent-node .talent-name { font-size: 13px; font-weight: bold; }
.talent-node .talent-desc { font-size: 11px; color: #9aa0b0; }

#vendor-prompt {
  position: absolute;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  background: rgba(10,12,16,0.75);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 13px;
}
#panel-vendor {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: min(820px, 94vw);
  max-height: 85vh;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
#vendor-gold { color: #f0c869; font-weight: normal; font-size: 13px; margin-left: 8px; }
#btn-close-vendor { background: none; border: none; color: #e8e8ea; font-size: 18px; cursor: pointer; }
.vendor-column { flex: 1; min-width: 280px; }
.vendor-column h3 { margin: 0 0 8px; font-size: 14px; color: #9aa0b0; }
.vendor-list { display: flex; flex-direction: column; gap: 6px; max-height: 60vh; overflow-y: auto; }
.vendor-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid #2a2f3c;
  background: #1a1d26;
}
.vendor-item .item-icon { width: 36px; height: 36px; flex: none; }
.vendor-item .vendor-item-info { flex: 1; font-size: 12px; }
.vendor-item .vendor-item-name { font-weight: bold; }
.vendor-item .vendor-price { font-size: 12px; color: #f0c869; white-space: nowrap; }
.vendor-item button {
  background: #2a2f3c;
  color: #e8e8ea;
  border: 1px solid #3a3f50;
  border-radius: 6px;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 12px;
}
.vendor-item button:disabled { opacity: 0.4; cursor: not-allowed; }
.vendor-sell-cell { position: relative; }
.vendor-sell-cell .vendor-sell-price {
  position: absolute; bottom: -2px; left: 0; right: 0;
  text-align: center; font-size: 9px; color: #f0c869;
  background: rgba(0,0,0,0.6);
}

#tooltip {
  position: absolute;
  z-index: 100;
  background: #0d0f14;
  border: 1px solid #3a3f50;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  max-width: 240px;
  pointer-events: none;
  line-height: 1.5;
}
#tooltip .tt-name { font-weight: bold; font-size: 13px; margin-bottom: 2px; }
#tooltip .tt-rarity { font-size: 11px; margin-bottom: 6px; text-transform: uppercase; letter-spacing: 1px; }
#tooltip .tt-stat { color: #9effb0; }
.tt-fire { color: #ff8a4a; }
.tt-cold { color: #7ecbff; }
.tt-poison { color: #9fe06a; }
.tt-better { color: #6effa0; }
.tt-worse { color: #ff6b5e; }
.tt-setbonus { color: var(--rarity-set); font-size: 11px; margin-top: 4px; }

@media (max-width: 640px) {
  .bar { width: 120px; }
  #hud-level { right: 8px; }
  .class-card { width: 100%; max-width: 360px; }
}
