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

/* Prevent iOS Safari from zooming on input focus */
input, button, textarea, select { touch-action: manipulation; }

body {
  background: #05080d;
  color: #e8e0cc;
  font-family: 'Courier New', Courier, monospace;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}

/* ── Login Screen ───────────────────────────── */
#login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, #0d1a0d 0%, #020408 100%);
  z-index: 100;
}
.login-box {
  background: rgba(5,12,5,0.95);
  border: 2px solid #3d6b22;
  border-radius: 4px;
  padding: 40px 48px;
  text-align: center;
  box-shadow: 0 0 60px rgba(60,150,30,0.12), inset 0 1px 0 rgba(255,255,255,0.05);
  min-width: 320px;
}
.login-title {
  font-size: 36px;
  font-weight: bold;
  color: #c8a856;
  letter-spacing: 6px;
  text-transform: uppercase;
  text-shadow: 0 0 20px rgba(200,168,86,0.4);
  margin-bottom: 6px;
}
.login-sub {
  font-size: 11px;
  color: #5a7a3a;
  letter-spacing: 4px;
  text-transform: uppercase;
  margin-bottom: 32px;
}
.login-label {
  font-size: 11px;
  color: #8ab060;
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 6px;
  text-align: left;
}
.login-input {
  width: 100%;
  background: #0a1508;
  border: 1px solid #3d6b22;
  border-radius: 2px;
  color: #e8e0cc;
  font-family: 'Courier New', monospace;
  font-size: 15px;
  padding: 10px 14px;
  outline: none;
  margin-bottom: 20px;
  transition: border-color 0.2s;
}
.login-input:focus { border-color: #7ab040; }
.login-btn {
  width: 100%;
  background: linear-gradient(180deg, #4a8c1c, #2d5a10);
  border: 1px solid #6aad28;
  border-radius: 2px;
  color: #e8f0d0;
  font-family: 'Courier New', monospace;
  font-size: 13px;
  font-weight: bold;
  letter-spacing: 3px;
  text-transform: uppercase;
  padding: 12px;
  cursor: pointer;
  transition: all 0.15s;
}
.login-btn:hover { background: linear-gradient(180deg, #5aab22, #3a7015); transform: translateY(-1px); }
.login-btn:active { transform: translateY(0); }
.login-hint  { font-size: 11px; color: #3d6b22; margin-top: 14px; }
.login-error { font-size: 12px; color: #ff6060; min-height: 18px; margin-top: 10px; letter-spacing: 1px; }
.wiki-link {
  display: block;
  margin-top: 18px;
  font-size: 11px;
  color: #5a7a3a;
  letter-spacing: 2px;
  text-decoration: none;
  text-transform: uppercase;
  transition: color 0.15s;
}
.wiki-link:hover { color: #8ab060; }

/* ── Game Wrapper ───────────────────────────── */
#app {
  display: none;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}
#game-container {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  /* Height leaves room for the chat panel (100px) + spell bar (~74px) + gap */
  height: calc(100% - 190px);
  /* Flex centering ensures the canvas stays centred even if Phaser produces
     a canvas that is slightly smaller than the container (e.g. pixel rounding). */
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
/* Let Phaser's Scale.RESIZE manager own the canvas dimensions entirely.
   Do NOT set width/height here — it conflicts with Phaser's inline style. */
#game-container canvas {
  display: block;
  /* Prevent flex from shrinking a correctly-sized canvas. */
  flex-shrink: 0;
}

/* ── Target Bar ─────────────────────────────── */
#target-bar {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(4,10,4,0.92);
  border: 1px solid #5a1515;
  border-radius: 3px;
  padding: 6px 12px;
  min-width: 160px;
  max-width: 220px;
  pointer-events: none;
  z-index: 10;
  text-align: center;
}
#target-name {
  font-size: 11px;
  color: #e8a888;
  letter-spacing: 1px;
  font-weight: bold;
  margin-bottom: 4px;
  text-transform: uppercase;
}
#target-hp-bar-bg {
  width: 100%;
  height: 8px;
  background: #1a0000;
  border: 1px solid #500;
  border-radius: 1px;
  overflow: hidden;
}
#target-hp-fill {
  height: 100%;
  background: #27ae60;
  transition: width 0.3s, background 0.3s;
}
#target-hp-text {
  font-size: 9px;
  color: #907070;
  margin-top: 2px;
}

#player-hp-widget {
  position: absolute;
  left: 50%;
  bottom: 178px;
  transform: translateX(-50%);
  width: 170px;
  padding: 7px 8px;
  background: rgba(4,10,4,0.9);
  border: 1px solid #2a4a18;
  border-radius: 4px;
  box-shadow: 0 8px 22px rgba(0,0,0,0.28);
  z-index: 10;
  pointer-events: none;
}

#player-hp-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
  font-size: 10px;
  color: #8fb56a;
  letter-spacing: 1px;
  text-transform: uppercase;
}

#player-hp-text {
  color: #e8e0cc;
  font-size: 11px;
  letter-spacing: 0;
  text-transform: none;
}

#player-hp-bar-bg {
  width: 100%;
  height: 10px;
  background: #1a0000;
  border: 1px solid #500;
  border-radius: 2px;
  overflow: hidden;
}

#player-hp-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #c0392b, #e74c3c);
  transition: width 0.3s;
}

/* ── HUD Overlays ───────────────────────────── */
#stats-hud {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 172px;
  pointer-events: all;
  z-index: 10;
}
.hud-action-stack {
  background: rgba(4,10,4,0.9);
  border: 1px solid #2a4a18;
  border-radius: 4px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}
.hud-action-stack {
  padding: 10px;
  gap: 6px;
  display: flex;
  flex-direction: column;
}
.hud-action-btn,
.logout-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  background: transparent;
  border: 1px solid #2f4938;
  border-radius: 2px;
  color: #d3c9af;
  font-family: 'Courier New', monospace;
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  padding: 5px 0;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.hud-action-btn {
  background: linear-gradient(180deg, rgba(30,50,24,0.95), rgba(12,24,12,0.95));
}
.hud-action-btn:hover {
  border-color: #6aad28;
  color: #e8f0d0;
}
.hud-hotkey-hint {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 15px;
  height: 15px;
  padding: 0 4px;
  border: 1px solid rgba(214, 233, 196, 0.3);
  border-radius: 999px;
  background: rgba(7, 14, 9, 0.9);
  color: #eef7d6;
  font-size: 9px;
  font-weight: bold;
  line-height: 1;
  letter-spacing: 0;
  box-shadow: 0 0 6px rgba(0,0,0,0.28);
}
.logout-btn {
  border-color: #5a1515;
  color: #c06060;
}
.logout-btn:hover { border-color: #aa2020; color: #ff8080; }
#spell-slots-wrap { margin-bottom: 8px; margin-top: 4px; }
#spell-slots-label { font-size: 10px; color: #8888cc; letter-spacing: 1px; text-transform: uppercase; margin-bottom: 4px; }
#spell-slots-row { display: flex; gap: 8px; }
.slot-pip { font-size: 11px; color: #a0a8e0; }
.slot-pip span { color: #e0e8ff; font-weight: bold; }
.rest-btn {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 5px;
  background: rgba(20,40,20,0.9);
  border: 1px solid #2a5a1a;
  border-radius: 3px;
  color: #6aad28;
  font-family: 'Courier New', monospace;
  font-size: 11px;
  cursor: pointer;
  text-align: center;
  pointer-events: all;
}
.rest-btn:hover { background: rgba(30,60,20,0.9); border-color: #4a9a28; }
.rest-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.inventory-btn {
  display: block;
  width: 100%;
  padding: 5px;
  background: rgba(20,20,40,0.9);
  border: 1px solid #3a2a6a;
  border-radius: 3px;
  color: #a090e8;
  font-family: 'Courier New', monospace;
  font-size: 11px;
  cursor: pointer;
  text-align: center;
  pointer-events: all;
}
.inventory-btn:hover { background: rgba(30,20,60,0.9); border-color: #6a50c8; }
.inventory-btn .hud-hotkey-hint {
  border-color: rgba(181, 163, 255, 0.34);
  background: rgba(11, 9, 22, 0.92);
  color: #e6deff;
}
.stat-row { display:flex; justify-content:space-between; font-size:12px; color:#a0b888; line-height:2; }
.stat-val { color: #e8e0cc; font-weight: bold; }

/* ── Ability score grid ─────────────────────── */
#ability-scores {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  margin: 6px 0;
  padding: 6px 0;
  border-top: 1px solid #1e3810;
  border-bottom: 1px solid #1e3810;
}
.ab-score {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  background: rgba(255,255,255,0.03);
  border-radius: 2px;
  padding: 2px 4px;
  line-height: 1.6;
}
.ab-name {
  font-size: 9px;
  color: #6aad28;
  letter-spacing: 0;
  text-transform: uppercase;
  margin-right: 4px;
}
.ab-right { white-space: nowrap; }
.ab-val {
  font-size: 11px;
  color: #e8e0cc;
  font-weight: bold;
}
.ab-mod {
  font-size: 9px;
  color: #a0b888;
  margin-left: 2px;
}

/* ── Skills panel ───────────────────────────── */
#skills-details {
  margin-top: 6px;
  pointer-events: all;
}
.skills-summary {
  font-size: 10px;
  color: #6aad28;
  letter-spacing: 2px;
  text-transform: uppercase;
  cursor: pointer;
  user-select: none;
  list-style: none;
  padding: 4px 0 2px;
  border-top: 1px solid #1e3810;
}
.skills-summary::-webkit-details-marker { display: none; }
#skills-list { padding-top: 2px; }
.skill-row {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: #708860;
  line-height: 1.8;
}
.skill-proficient { color: #c8da98; }

/* ── Chat Panel ─────────────────────────────── */
#chat-panel {
  position: absolute;
  bottom: 0; left: 0;
  width: 100%;
  background: rgba(4,10,4,0.88);
  border-top: 1px solid #2a4a18;
  z-index: 10;
  height: 100px;
  display: flex;
  flex-direction: column;
}
#chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
  font-size: 11px;
  line-height: 1.5;
}
#chat-log::-webkit-scrollbar { width: 4px; }
#chat-log::-webkit-scrollbar-track { background: #0a0a0a; }
#chat-log::-webkit-scrollbar-thumb { background: #2a4a18; }
.chat-msg { color: #c8d8b0; }
.chat-msg .chat-from { color: #f0d060; }
.chat-msg.system { color: #607850; font-style: italic; }
.chat-msg.xp { color: #80c0ff; }
.chat-msg.combat { color: #ff8080; }
.chat-msg.combat-dim { color: #506040; }
.chat-msg.kill { color: #ffd700; }
#chat-input-row {
  display: flex;
  border-top: 1px solid #1e3810;
  padding: 4px 6px;
  gap: 6px;
}
#chat-prefix { font-size: 11px; color: #6aad28; line-height: 28px; white-space: nowrap; }
#chat-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #e8e0cc;
  font-family: 'Courier New', monospace;
  font-size: 12px;
}

/* ── Mini-map ────────────────────────────────── */
#minimap {
  position: absolute;
  top: 8px; left: 8px;
  width: 90px; height: 90px;
  border: 1px solid #2a4a18;
  background: #020804;
  z-index: 10;
  pointer-events: none;
}

/* ── Quest Tracker ───────────────────────────── */
#quest-tracker {
  width: 100%;
  max-height: 236px;
  overflow: hidden;
  background: rgba(7, 15, 8, 0.9);
  border: 1px solid #2f4938;
  border-radius: 3px;
  pointer-events: none;
}

.quest-tracker-title {
  padding: 7px 9px 6px;
  border-bottom: 1px solid rgba(42, 74, 24, 0.85);
  color: #9fc66b;
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.quest-tracker-list {
  max-height: 198px;
  overflow-y: auto;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.quest-tracker-list::-webkit-scrollbar {
  width: 4px;
}

.quest-tracker-list::-webkit-scrollbar-track {
  background: rgba(6, 12, 6, 0.72);
}

.quest-tracker-list::-webkit-scrollbar-thumb {
  background: #355723;
}

.quest-track-item {
  background: rgba(6, 14, 6, 0.9);
  border: 1px solid rgba(91, 128, 54, 0.4);
  border-radius: 3px;
  padding: 6px;
}

.quest-track-header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 5px;
  font-size: 11px;
}

.quest-track-name {
  color: #e6ddb8;
  line-height: 1.3;
}

.quest-track-progress {
  color: #b5ca95;
  white-space: nowrap;
}

.quest-track-bar {
  width: 100%;
  height: 5px;
  border: 1px solid rgba(60, 92, 38, 0.8);
  background: rgba(8, 16, 8, 0.94);
  border-radius: 2px;
  overflow: hidden;
}

.quest-track-fill {
  height: 100%;
  background: linear-gradient(90deg, #5c8f35, #9bcc53);
  transition: width 0.25s ease;
}

.quest-track-empty {
  font-size: 11px;
  color: #7d9470;
  padding: 6px;
}

.hud-collapse-btn {
  display: none;
  align-items: center;
  justify-content: center;
  align-self: flex-end;
  min-height: 28px;
  padding: 4px 10px;
  background: rgba(6,14,6,0.92);
  border: 1px solid #2f4938;
  border-radius: 999px;
  color: #cfe7b1;
  font-family: 'Courier New', monospace;
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
  cursor: pointer;
}

#quest-tracker-modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.74);
  z-index: 530;
}

.quest-tracker-modal-box {
  width: min(94vw, 420px);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  background: rgba(7, 15, 8, 0.97);
  border: 1px solid #355723;
  border-radius: 5px;
  box-shadow: 0 16px 38px rgba(0,0,0,0.45);
}

.quest-tracker-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.quest-tracker-modal-title {
  color: #9fc66b;
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
}

#quest-tracker-mobile-list {
  max-height: calc(80vh - 70px);
  padding: 0;
}

/* ── Connection status ──────────────────────── */
#status-bar {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 13px; color: #6aad28;
  letter-spacing: 2px;
  pointer-events: none;
  z-index: 9;
}

/* ── Character Select Screen ──────────────────────────── */
#char-select-screen {
  position: fixed; inset: 0;
  display: none; flex-direction: column; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, #0d1a0d 0%, #020408 100%);
  z-index: 100;
}
.char-select-box { text-align: center; width: 660px; max-width: 95vw; }
.select-title {
  font-size: 26px; font-weight: bold; color: #c8a856;
  letter-spacing: 4px; text-transform: uppercase;
  text-shadow: 0 0 20px rgba(200,168,86,0.4); margin-bottom: 4px;
}
.select-sub { font-size: 11px; color: #5a7a3a; letter-spacing: 3px; text-transform: uppercase; margin-bottom: 22px; }
.char-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 10px; }
.char-slot {
  border: 1px solid #2a4a18; border-radius: 4px; height: 176px; cursor: pointer;
  background: rgba(5,12,5,0.9); transition: border-color 0.2s, background 0.2s;
  display: flex; align-items: center; justify-content: center; position: relative; overflow: hidden;
}
.char-slot:hover { border-color: #6aad28; background: rgba(10,24,10,0.95); }
.slot-empty { text-align: center; color: #3d6b22; }
.slot-empty-icon { font-size: 26px; margin-bottom: 6px; }
.slot-empty-label { font-size: 10px; letter-spacing: 2px; text-transform: uppercase; }
.slot-filled { padding: 12px; width: 100%; text-align: center; }
.slot-class-icon { font-size: 34px; margin-bottom: 4px; }
.slot-char-name { font-size: 14px; color: #e8e0cc; font-weight: bold; margin-bottom: 2px; }
.slot-char-class { font-size: 10px; color: #8ab060; text-transform: uppercase; letter-spacing: 2px; margin-bottom: 6px; }
.slot-char-level { font-size: 11px; color: #a0b888; margin-bottom: 10px; }
.slot-delete-btn {
  position: absolute; top: 5px; right: 5px;
  background: rgba(100,15,15,0.85); border: 1px solid #7a1515;
  color: #ff8080; font-size: 9px; letter-spacing: 1px; text-transform: uppercase;
  padding: 3px 7px; border-radius: 2px; cursor: pointer; font-family: 'Courier New', monospace;
}
.slot-delete-btn:hover { background: rgba(160,25,25,0.95); }
.char-screen-error { color: #ff6060; font-size: 12px; min-height: 18px; letter-spacing: 1px; }

/* ── Class Select Overlay ────────────────────────────── */
#class-select-overlay {
  position: fixed; inset: 0; background: rgba(2,4,8,0.94);
  display: none; flex-direction: column; align-items: center; justify-content: center;
  z-index: 110;
}
.class-select-box { width: 720px; max-width: 95vw; text-align: center; }
.class-select-title { font-size: 20px; color: #c8a856; letter-spacing: 4px; text-transform: uppercase; margin-bottom: 18px; }
.class-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 18px; }
.class-card {
  border: 1px solid #2a4a18; border-radius: 4px; padding: 14px 10px;
  cursor: pointer; background: rgba(5,12,5,0.9); transition: border-color 0.2s; text-align: center;
}
.class-card:hover { border-color: #6aad28; }
.class-card.selected { border-color: #c8a856; background: rgba(22,18,4,0.95); }
.class-icon-lg { font-size: 30px; margin-bottom: 6px; }
.class-name-lg { font-size: 12px; color: #e8e0cc; font-weight: bold; letter-spacing: 2px; text-transform: uppercase; margin-bottom: 5px; }
.class-desc-sm { font-size: 10px; color: #7a9060; line-height: 1.5; margin-bottom: 7px; }
.class-stats-sm { font-size: 9px; color: #4a6a30; letter-spacing: 1px; }
.char-create-form { display: flex; gap: 10px; align-items: center; justify-content: center; flex-wrap: wrap; margin-bottom: 8px; }
.char-create-form .login-input { width: 200px; margin-bottom: 0; }
.create-btn {
  background: linear-gradient(180deg, #4a8c1c, #2d5a10); border: 1px solid #6aad28; border-radius: 2px;
  color: #e8f0d0; font-family: 'Courier New', monospace; font-size: 12px;
  font-weight: bold; letter-spacing: 2px; text-transform: uppercase; padding: 11px 20px; cursor: pointer;
}
.create-btn:hover { background: linear-gradient(180deg, #5aab22, #3a7015); }
.cancel-btn {
  background: transparent; border: 1px solid #3d6b22; border-radius: 2px;
  color: #5a7a3a; font-family: 'Courier New', monospace; font-size: 12px;
  letter-spacing: 2px; text-transform: uppercase; padding: 11px 20px; cursor: pointer;
}
.cancel-btn:hover { border-color: #6aad28; color: #8ab060; }
.create-error { color: #ff6060; font-size: 12px; min-height: 18px; letter-spacing: 1px; }

/* ── Spell Bar ──────────────────────────────── */
#spell-bar {
  position: absolute;
  bottom: 106px; left: 50%;
  transform: translateX(-50%);
  display: flex; gap: 6px;
  z-index: 10;
}
.spell-btn {
  position: relative;
  width: 68px; min-height: 64px;
  background: rgba(6,10,18,0.92);
  border: 1px solid #1e3050;
  border-radius: 3px;
  cursor: pointer;
  padding: 5px 4px 4px;
  font-family: 'Courier New', monospace;
  color: #c8d8f0;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  transition: border-color 0.15s, background 0.15s;
  overflow: hidden;
}
.spell-btn:hover        { border-color: #4488cc; background: rgba(12,20,40,0.95); }
.spell-btn.active       { border-color: #88ccff; box-shadow: 0 0 8px rgba(136,204,255,0.4); }
.spell-btn.on-cooldown  { opacity: 0.55; cursor: not-allowed; }
.spell-btn.buff-active  { border-color: #ffd700; box-shadow: 0 0 10px rgba(255,215,0,0.5); animation: buff-pulse 0.8s ease-in-out infinite alternate; }
@keyframes buff-pulse { from { box-shadow: 0 0 6px rgba(255,215,0,0.3); } to { box-shadow: 0 0 14px rgba(255,215,0,0.7); } }
.spell-hotkey-badge {
  position: absolute;
  top: 3px;
  left: 3px;
  min-width: 15px;
  height: 15px;
  padding: 0 4px;
  border: 1px solid rgba(136, 204, 255, 0.55);
  border-radius: 999px;
  background: rgba(8, 18, 34, 0.94);
  color: #d7ecff;
  font-size: 9px;
  font-weight: bold;
  line-height: 13px;
  text-align: center;
  box-shadow: 0 0 6px rgba(0,0,0,0.35);
}
.spell-icon   { font-size: 18px; line-height: 1; }
.spell-name   { font-size: 8px; letter-spacing: 0.5px; text-transform: uppercase; text-align: center; color: #a0b8d8; line-height: 1.3; }
.spell-slot-label { font-size: 8px; color: #8888cc; }
.spell-cd-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.62);
  display: none; align-items: center; justify-content: center;
  font-size: 16px; font-weight: bold; color: #fff;
  pointer-events: none;
}

/* ══ Character Sheet ══════════════════════════════════════════════════════════ */
#character-modal,
#leave-world-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.72);
  z-index: 520;
  opacity: 0;
  transition: opacity 0.18s ease;
}
#character-modal.open,
#leave-world-modal.open {
  opacity: 1;
}

.char-sheet-box {
  width: min(1040px, 94vw);
  max-height: 90vh;
  overflow: auto;
  padding: 24px;
  border: 2px solid #715621;
  border-radius: 6px;
  background:
    radial-gradient(circle at top left, rgba(100,78,26,0.18), transparent 34%),
    linear-gradient(180deg, rgba(16,18,14,0.98), rgba(6,8,6,0.98));
  box-shadow: 0 24px 60px rgba(0,0,0,0.5);
  transform: translateY(22px) scale(0.985);
  opacity: 0;
  transition: transform 0.2s ease, opacity 0.2s ease;
}
#character-modal.open .char-sheet-box,
#leave-world-modal.open .confirm-box {
  transform: translateY(0) scale(1);
  opacity: 1;
}
.char-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}
.char-sheet-kicker {
  font-size: 10px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: #8d7442;
  margin-bottom: 4px;
}
.char-sheet-title {
  font-size: 28px;
  color: #e0c88a;
  letter-spacing: 3px;
  text-transform: uppercase;
}
.char-sheet-body {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 18px;
}
.char-sheet-summary,
.char-sheet-panel {
  background: rgba(10,10,10,0.78);
  border: 1px solid rgba(184,146,66,0.35);
  border-radius: 5px;
}
.char-sheet-summary {
  padding: 18px;
  text-align: center;
}
.char-sheet-emblem {
  width: 96px;
  height: 96px;
  margin: 0 auto 14px;
  border-radius: 50%;
  border: 1px solid rgba(240,216,122,0.35);
  display: grid;
  place-items: center;
  font-size: 42px;
  background: radial-gradient(circle, rgba(89,64,20,0.55), rgba(18,18,18,0.9));
}
.char-sheet-name {
  font-size: 24px;
  color: #f4ead2;
  margin-bottom: 4px;
}
.char-sheet-class {
  font-size: 12px;
  color: #9fbf7b;
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-bottom: 10px;
}
.char-sheet-banner {
  display: inline-block;
  padding: 5px 12px;
  border: 1px solid #725820;
  background: rgba(58,40,12,0.88);
  color: #f0d87a;
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 16px;
}
.char-sheet-progress-label,
.char-sheet-panel-title {
  font-size: 11px;
  color: #a48a4c;
  letter-spacing: 2px;
  text-transform: uppercase;
}
.char-sheet-progress-label { margin-bottom: 6px; }
.char-sheet-progress-bar {
  height: 10px;
  background: #1a1400;
  border: 1px solid #503800;
  overflow: hidden;
}
.char-sheet-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #8b5e00, #d4a017);
}
.char-sheet-progress-text {
  margin-top: 6px;
  font-size: 10px;
  color: #b39a68;
}
.char-sheet-summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 16px 0;
}
.char-sheet-summary-grid div {
  padding: 8px;
  border: 1px solid rgba(184,146,66,0.16);
  background: rgba(255,255,255,0.02);
  border-radius: 3px;
  text-align: left;
}
.char-sheet-summary-grid span {
  display: block;
  font-size: 10px;
  color: #9ab684;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.char-sheet-summary-grid b {
  display: block;
  margin-top: 2px;
  font-size: 16px;
  color: #f0e6cc;
}
.char-sheet-details {
  display: grid;
  grid-template-columns: minmax(260px, 320px) 1fr;
  gap: 18px;
}
.char-sheet-equip-panel {
  grid-row: span 2;
}
.char-sheet-equip-grid {
  margin: 8px auto 0;
}
.char-sheet-equip-slot {
  width: 62px;
  height: 62px;
  background: rgba(40,24,8,0.72);
  border-color: rgba(184,146,66,0.34);
  color: #a79574;
}
.char-sheet-equip-slot.occupied {
  border-color: #c8a856;
  background: rgba(68,42,10,0.88);
}
.char-sheet-equip-slot.occupied:hover {
  border-color: #ffd74a;
  background: rgba(92,58,12,0.94);
}
.char-sheet-panel {
  padding: 16px;
}
.char-sheet-panel-title {
  margin-bottom: 12px;
}
.char-sheet-abilities {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
  padding: 0;
  border: 0;
}
.char-sheet-skills-panel #skills-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px 18px;
}
.char-sheet-skills-panel .skill-row {
  padding: 5px 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

/* ══ Confirmation Modal ══════════════════════════════════════════════════════ */
.confirm-box {
  width: min(420px, 92vw);
  padding: 22px 24px;
  border: 1px solid #725820;
  border-radius: 5px;
  background: linear-gradient(180deg, rgba(18,18,14,0.98), rgba(8,8,6,0.98));
  text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,0.45);
  transform: translateY(18px) scale(0.985);
  opacity: 0;
  transition: transform 0.18s ease, opacity 0.18s ease;
}
.confirm-kicker {
  color: #8d7442;
  font-size: 10px;
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.confirm-title {
  color: #f0d87a;
  font-size: 24px;
  margin-bottom: 10px;
}
.confirm-copy {
  color: #b9b29b;
  font-size: 13px;
  line-height: 1.6;
  margin-bottom: 18px;
}
.confirm-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
}

/* ══ Mobile Responsive (≤ 640px) ════════════════════════════════ */
@media (max-width: 640px) {

  .hud-collapse-btn {
    display: inline-flex;
  }

  #stats-hud.mobile-collapsed .hud-action-stack {
    display: none !important;
  }

  #stats-hud.mobile-collapsed {
    gap: 0;
  }

  #quest-tracker {
    display: none !important;
  }

  /* ── Login ── */
  .login-box {
    padding: 28px 20px;
    width: calc(100vw - 24px);
    min-width: unset;
  }
  .login-title { font-size: 26px; letter-spacing: 4px; }
  .login-sub   { margin-bottom: 22px; }
  /* 16px minimum prevents iOS Safari from zooming on focus */
  .login-input { font-size: 16px; }

  /* ── Character Select ── */
  .char-select-box  { width: 100%; padding: 0 10px; }
  .select-title     { font-size: 20px; letter-spacing: 2px; }
  .char-grid        { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .char-slot        { height: 148px; }
  .slot-class-icon  { font-size: 26px; }
  .slot-char-name   { font-size: 13px; }

  /* ── Class Select ── */
  #class-select-overlay          { align-items: flex-start; padding-top: 12px; overflow-y: auto; }
  .class-select-box              { width: 100%; padding: 0 10px 20px; }
  .class-select-title            { font-size: 16px; margin-bottom: 12px; }
  .class-grid                    { grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 12px; }
  .class-card                    { padding: 8px 5px; }
  .class-icon-lg                 { font-size: 22px; margin-bottom: 4px; }
  .class-name-lg                 { font-size: 9px; letter-spacing: 1px; margin-bottom: 0; }
  .class-desc-sm, .class-stats-sm { display: none; }
  .char-create-form              { flex-direction: column; gap: 8px; }
  .char-create-form .login-input { width: 100%; }

  /* ── Stats HUD: compact right panel ── */
  #stats-hud {
    right: 4px;
    width: 156px;
    top: 4px;
  }
  #player-hp-widget {
    width: 154px;
    left: 50%;
    bottom: 166px;
    padding: 6px 7px;
  }
  #player-hp-label {
    font-size: 9px;
  }
  #player-hp-text {
    font-size: 10px;
  }
  #player-hp-bar-bg {
    height: 8px;
  }
  .hud-action-stack {
    padding: 8px;
    gap: 5px;
  }
  .hud-action-btn,
  .inventory-btn,
  .logout-btn,
  .rest-btn {
    min-width: 0;
    font-size: 9px;
    line-height: 1.15;
    letter-spacing: 1px;
    white-space: normal;
    padding: 6px 4px;
  }
  .hud-hotkey-hint { min-width: 14px; height: 14px; font-size: 8px; }
  #spell-slots-label { font-size: 9px; }
  .slot-pip    { font-size: 10px; }
  .rest-btn    { font-size: 10px; padding: 6px; margin-top: 6px; }

  .char-sheet-box {
    width: 96vw;
    padding: 16px;
  }
  .char-sheet-title { font-size: 22px; }
  .char-sheet-body {
    grid-template-columns: 1fr;
  }
  .char-sheet-details {
    grid-template-columns: 1fr;
  }
  .char-sheet-equip-panel { grid-row: auto; }
  .char-sheet-skills-panel #skills-list {
    grid-template-columns: 1fr;
  }
  .confirm-actions {
    flex-direction: column;
  }

  /* ── Minimap: smaller ── */
  #minimap { width: 68px; height: 68px; top: 4px; left: 4px; }

  #quest-tracker { max-height: 148px; }
  .quest-tracker-list {
    max-height: 116px;
  }
  .quest-track-header {
    font-size: 10px;
  }

  /* ── Spell bar: larger touch targets ── */
  #spell-bar  { bottom: 88px; gap: 5px; }
  .spell-btn  { width: 74px; min-height: 70px; padding: 7px 4px 5px; }
  .spell-hotkey-badge { top: 4px; left: 4px; min-width: 16px; height: 16px; font-size: 9px; line-height: 14px; }
  .spell-icon { font-size: 20px; }
  .spell-name { font-size: 9px; }
  .spell-slot-label { font-size: 9px; }
  .spell-cd-overlay { font-size: 18px; }

  /* ── Chat: compact + 16px input to prevent zoom ── */
  #chat-panel   { height: 80px; }
  #chat-input   { font-size: 16px; }
  #chat-log     { font-size: 11px; }
  #chat-prefix  { display: none; }

  /* ── Game container: account for chat (80px) + spell bar (~78px) + gap ── */
  #game-container {
    height: calc(100% - 168px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
}

@media (max-width: 380px) {
  .class-grid { grid-template-columns: repeat(2, 1fr); }
  #stats-hud  { width: 142px; }
  #player-hp-widget { width: 140px; bottom: 158px; }
  .spell-btn  { width: 66px; }
}

/* ── Mobile landscape: phone rotated sideways ── */
@media (max-height: 480px) and (orientation: landscape) {
  /* Shrink chat to a thin strip so it doesn't eat the play area */
  #chat-panel   { height: 56px; }
  #chat-log     { display: none; }
  /* Game container: chat (56px) + spell bar (~60px) + gap */
  #game-container { height: calc(100% - 126px); }

  /* Spell bar sits just above the chat strip */
  #spell-bar    { bottom: 64px; gap: 4px; }
  .spell-btn    { width: 60px; min-height: 56px; padding: 5px 3px 4px; }
  .spell-hotkey-badge { min-width: 14px; height: 14px; font-size: 8px; line-height: 12px; }

  /* Compact HUD */
  #stats-hud    { right: 2px; width: 128px; top: 2px; gap: 4px; }
  .hud-action-stack { padding: 6px 8px; }
  #player-hp-widget {
    left: 50%;
    bottom: 122px;
    width: 126px;
    padding: 5px 6px;
  }
  #player-hp-label {
    margin-bottom: 3px;
    font-size: 8px;
    gap: 5px;
  }
  #player-hp-text {
    font-size: 9px;
  }
  #player-hp-bar-bg {
    height: 7px;
  }
  .hud-action-stack {
    gap: 4px;
  }
  .hud-action-btn,
  .inventory-btn,
  .logout-btn,
  .rest-btn {
    min-width: 0;
    line-height: 1.1;
    white-space: normal;
    padding: 5px 4px;
  }

  /* Minimap tiny */
  #minimap      { width: 56px; height: 56px; }

  #quest-tracker { max-height: 122px; }
  .quest-tracker-title {
    font-size: 9px;
    padding: 5px 7px;
  }
  .quest-tracker-list {
    max-height: 92px;
    padding: 4px;
    gap: 4px;
  }
  .quest-track-item {
    padding: 4px;
  }
  .quest-track-header {
    margin-bottom: 4px;
    font-size: 9px;
  }

  /* Login / overlays must scroll */
  .login-box, .char-select-box, .class-select-box { max-height: 96vh; overflow-y: auto; }
}

@media (hover: none), (pointer: coarse) {
  .hud-hotkey-hint,
  .spell-hotkey-badge {
    display: none;
  }

  .hud-action-btn,
  .inventory-btn,
  .logout-btn,
  .rest-btn {
    min-height: 40px;
    padding: 9px 10px;
    font-size: 11px;
    letter-spacing: 1px;
  }

  .hud-action-btn,
  .inventory-btn {
    gap: 0;
  }
}

/* ══ Shop Modal ════════════════════════════════════════════════════ */
#shop-modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.72);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.shop-box {
  background: rgba(5,12,5,0.97);
  border: 2px solid #c8a856;
  border-radius: 4px;
  padding: 24px 28px 20px;
  min-width: 340px;
  max-width: 480px;
  width: 90vw;
  max-height: 80vh;
  display: flex; flex-direction: column;
  box-shadow: 0 0 40px rgba(200,168,86,0.18);
}
.shop-title {
  font-size: 18px;
  font-weight: bold;
  color: #c8a856;
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.shop-gold-row {
  font-size: 13px;
  color: #f0d87a;
  margin-bottom: 4px;
}
.shop-hint {
  font-size: 10px;
  color: #b8a46a;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 10px;
}
.shop-items {
  overflow: auto;
  flex: 1;
  display: grid;
  gap: 0;
  border: 1px solid #7c6430;
  background: rgba(25,16,6,0.92);
  position: relative;
  background-image:
    linear-gradient(to right,  #6a5326 1px, transparent 1px),
    linear-gradient(to bottom, #6a5326 1px, transparent 1px);
  background-size: 36px 36px;
  min-height: 300px;
  max-height: 60vh;
}
.shop-grid-item {
  position: relative;
  background: rgba(45,28,8,0.9);
  border: 1px solid #c8a856;
  border-radius: 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  padding: 2px;
  user-select: none;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.03), 0 0 0 rgba(0,0,0,0);
}
.shop-grid-item:hover {
  border-color: #ffd74a;
  background: rgba(70,42,10,0.95);
}
.shop-grid-item[data-rarity="magic"],
.shop-grid-item[data-rarity="rare"] {
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.04), 0 0 12px var(--rarity-glow);
}
.shop-grid-item.sold-out {
  border-color: #6a5a40;
  background: rgba(28,24,16,0.92);
  cursor: not-allowed;
  filter: saturate(0.45) brightness(0.75);
}
.shop-item-price-tag {
  position: absolute;
  top: 2px;
  right: 3px;
  font-size: 9px;
  color: #f0d87a;
  font-weight: bold;
  text-shadow: 0 0 3px rgba(0,0,0,0.8);
}
.item-rarity-badge {
  position: absolute;
  left: 3px;
  top: 2px;
  padding: 1px 4px;
  border-radius: 999px;
  font-size: 7px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  background: rgba(8,8,8,0.78);
  border: 1px solid currentColor;
  z-index: 1;
}
.item-rarity-magic { color: #61b7ff; }
.item-rarity-rare { color: #f2c94c; }

/* ── Rarity colors in chat messages ──────────────────── */
.rarity-common { color: #c8a856; }
.rarity-magic { color: #61b7ff; font-weight: bold; }
.rarity-rare { color: #f2c94c; font-weight: bold; }

.shop-item-restock {
  position: absolute;
  left: 3px;
  bottom: 2px;
  font-size: 8px;
  color: #9ac870;
  text-shadow: 0 0 3px rgba(0,0,0,0.85);
  white-space: nowrap;
}
.shop-item-sold {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 10px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #e0b060;
  text-shadow: 0 0 6px rgba(0,0,0,0.9);
}
.shop-close-btn { margin-top: 14px; align-self: flex-end; }
@media (max-width: 640px) {
  .shop-box { padding: 16px 14px 14px; min-width: unset; }
  .shop-title { font-size: 15px; }
}


/* ══ Quest Modal ═══════════════════════════════════════════════════ */
#quest-modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.72);
  display: flex; align-items: center; justify-content: center;
  z-index: 205;
}
.quest-box {
  width: min(560px, 95vw);
  max-height: 86vh;
  overflow: auto;
  background: rgba(8,14,8,0.96);
  border: 2px solid #6a541e;
  border-radius: 6px;
  padding: 14px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.45);
}
.quest-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.quest-title {
  color: #e6ca82;
  font-size: 16px;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.quest-hint {
  font-size: 11px;
  color: #9db78b;
  margin-bottom: 10px;
}
.quest-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.quest-entry {
  border: 1px solid rgba(123,156,72,0.34);
  background: rgba(6,10,6,0.92);
  border-radius: 4px;
  padding: 10px;
}
.quest-entry h4 {
  margin: 0 0 6px;
  color: #f0dfb0;
  font-size: 14px;
}
.quest-entry p {
  margin: 0 0 8px;
  color: #c2ccb0;
  font-size: 12px;
  line-height: 1.4;
}
.quest-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: #a3b48f;
  font-size: 11px;
  margin-bottom: 8px;
}
.quest-status {
  text-transform: uppercase;
  letter-spacing: 1px;
}
.quest-actions {
  display: flex;
  gap: 8px;
}
.quest-action-btn {
  border: 1px solid #4a6f2a;
  background: linear-gradient(180deg, rgba(42,68,26,0.95), rgba(14,26,10,0.95));
  color: #d9e8c7;
  border-radius: 3px;
  padding: 6px 10px;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  cursor: pointer;
}
.quest-action-btn:hover {
  border-color: #87ba4a;
  color: #eef8de;
}
.quest-action-btn.turn-in {
  border-color: #836316;
  background: linear-gradient(180deg, rgba(92,64,16,0.95), rgba(30,22,8,0.95));
  color: #f7df9a;
}
.quest-action-btn.turn-in:hover {
  border-color: #d0a63e;
  color: #fff2cc;
}


/* ══ NPC Interaction Modal ═════════════════════════════════════════ */
#npc-interaction-modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.72);
  display: flex; align-items: center; justify-content: center;
  z-index: 204;
}
.npc-interaction-box {
  width: min(420px, 93vw);
  background: rgba(10,14,10,0.97);
  border: 1px solid #6a541e;
  border-radius: 6px;
  padding: 14px;
  box-shadow: 0 16px 48px rgba(0,0,0,0.45);
}
.npc-interaction-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.npc-interaction-title {
  color: #e6ca82;
  font-size: 15px;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.npc-interaction-hint {
  color: #9db78b;
  font-size: 11px;
  margin-bottom: 10px;
}
.npc-interaction-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.npc-interaction-action {
  border: 1px solid #3f5f28;
  background: linear-gradient(180deg, rgba(35,58,22,0.95), rgba(12,22,9,0.95));
  color: #d8e8c5;
  border-radius: 3px;
  padding: 8px 10px;
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
  cursor: pointer;
}
.npc-interaction-action:hover {
  border-color: #84b74b;
  color: #edf7dc;
}
@media (max-width: 640px) {
  .quest-box { width: 97vw; padding: 10px; }
  .quest-title { font-size: 14px; }
  .quest-entry { padding: 8px; }
  .quest-actions { flex-direction: column; }
}
/* ══ INVENTORY MODAL ══════════════════════════════════════════════════════════ */
#inventory-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.72);
  z-index: 500;
  pointer-events: all;
}

.inv-box {
  position: relative;
  background: rgba(6,10,6,0.97);
  border: 1px solid #3a2a5a;
  border-radius: 4px;
  padding: 14px 16px 16px;
  min-width: 560px;
  max-width: 96vw;
  max-height: 90vh;
  overflow-y: auto;
  font-family: 'Courier New', Courier, monospace;
  color: #c8c0d8;
}

.inv-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.inv-title {
  flex: 1;
  font-size: 15px;
  color: #c0a8ff;
  letter-spacing: 1px;
  font-weight: bold;
}
.inv-gold {
  font-size: 12px;
  color: #f0d87a;
}

.inv-body {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

/* ── Equipment paperdoll ──────────────────────────────────────────────────── */
.inv-equip {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.equip-label {
  font-size: 11px;
  color: #7060a8;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 4px;
}
.equip-label-small {
  font-size: 9px;
  color: #7060a8;
  text-align: center;
  margin-bottom: 2px;
}
.equip-grid {
  display: grid;
  grid-template-areas:
    ".       head    ."
    "weapon  armor   amulet"
    "ring1   belt    ring2"
    ".       boots   gloves";
  grid-template-columns: 68px 68px 68px;
  grid-template-rows: 68px 68px 68px 68px;
  gap: 4px;
}
.equip-slot-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.equip-slot {
  width: 58px;
  height: 58px;
  border: 1px solid #3a2a5a;
  border-radius: 3px;
  background: rgba(20,10,40,0.8);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: #908098;
  cursor: default;
  overflow: hidden;
  padding: 2px;
}
.equip-slot.occupied {
  border-color: #7050b8;
  background: rgba(30,10,60,0.9);
  cursor: pointer;
}
.equip-slot.occupied:hover { border-color: #c090ff; background: rgba(50,20,80,0.9); }

/* ── Backpack grid ────────────────────────────────────────────────────────── */
.inv-pack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.inv-grid {
  display: grid;
  border: 1px solid #3a2a5a;
  background: rgba(10,6,20,0.9);
  position: relative;
  /* background grid lines */
  background-image:
    linear-gradient(to right,  #2a1a4a 1px, transparent 1px),
    linear-gradient(to bottom, #2a1a4a 1px, transparent 1px);
  background-size: 36px 36px;
}

.inv-item {
  position: relative;
  background: rgba(30,10,60,0.88);
  border: 1px solid #6040a0;
  border-radius: 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  padding: 2px;
  user-select: none;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.03), 0 0 0 rgba(0,0,0,0);
}
.inv-item:hover { border-color: #c090ff; background: rgba(50,20,90,0.95); }
.inv-item[data-rarity="magic"],
.inv-item[data-rarity="rare"],
.char-sheet-equip-slot[data-rarity="magic"],
.char-sheet-equip-slot[data-rarity="rare"] {
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.04), 0 0 12px var(--rarity-glow);
}
.char-sheet-equip-slot[data-rarity="magic"],
.char-sheet-equip-slot[data-rarity="rare"] {
  border-color: var(--rarity-color);
}

.inv-item-icon {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  flex: 0 0 auto;
}
.inv-item-icon img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.45));
}
.inv-item-label {
  font-size: 8px;
  color: #b0a8c8;
  text-align: center;
  word-break: break-word;
  line-height: 1.2;
  margin-top: 2px;
  max-width: 100%;
  overflow: hidden;
}
.inv-item-qty {
  position: absolute;
  bottom: 2px;
  right: 3px;
  font-size: 9px;
  color: #f0d87a;
  font-weight: bold;
}

/* ── Tooltip ──────────────────────────────────────────────────────────────── */
.inv-tooltip {
  position: fixed;
  background:
    linear-gradient(180deg, rgba(40, 30, 10, 0.28), rgba(0, 0, 0, 0) 18%),
    linear-gradient(180deg, rgba(14, 10, 6, 0.98), rgba(5, 5, 8, 0.98));
  border: 1px solid #8f7742;
  border-radius: 4px;
  padding: 0;
  font-size: 12px;
  color: #d9d1bf;
  pointer-events: none;
  z-index: 600;
  max-width: 280px;
  min-width: 220px;
  white-space: normal;
  box-shadow:
    0 14px 28px rgba(0, 0, 0, 0.5),
    inset 0 0 0 1px rgba(255,255,255,0.03);
  font-family: Georgia, 'Times New Roman', serif;
}
.inv-tooltip[data-rarity="magic"] {
  border-color: #61b7ff;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.5), 0 0 18px rgba(97,183,255,0.18);
}
.inv-tooltip[data-rarity="rare"] {
  border-color: #f2c94c;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.5), 0 0 20px rgba(242,201,76,0.2);
}
.inv-tooltip-shell {
  padding: 10px 12px 11px;
}
.inv-tooltip-header {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 6px;
}
.inv-tooltip-name {
  font-size: 16px;
  font-weight: bold;
  line-height: 1.15;
  text-shadow: 0 0 10px rgba(0,0,0,0.35);
}
.inv-tooltip-rarity {
  font-family: 'Courier New', Courier, monospace;
  font-size: 10px;
  font-weight: bold;
  letter-spacing: 1.4px;
  text-transform: uppercase;
}
.inv-tooltip-type,
.inv-tooltip-meta {
  font-family: 'Courier New', Courier, monospace;
  font-size: 10px;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  color: #95876a;
}
.inv-tooltip-type {
  margin-bottom: 8px;
}
.inv-tooltip-section {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(201, 173, 98, 0.16);
}
.inv-tooltip-section:first-of-type {
  margin-top: 0;
}
.inv-tooltip-stats {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.inv-tooltip-stat {
  color: #e7dcc0;
  line-height: 1.3;
}
.inv-tooltip-flavor {
  color: #b8b0a0;
  font-style: italic;
  line-height: 1.35;
}
.inv-tooltip-affixes {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.inv-tooltip-affix-names {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.inv-tooltip-affix-pill {
  padding: 2px 6px;
  border: 1px solid rgba(97, 183, 255, 0.38);
  border-radius: 999px;
  background: rgba(30, 58, 96, 0.34);
  color: #9fd4ff;
  font-family: 'Courier New', Courier, monospace;
  font-size: 10px;
  letter-spacing: 0.4px;
}
.inv-tooltip-affix-line {
  color: #84c7ff;
  line-height: 1.3;
}
.inv-tooltip-affix-delta {
  color: #5dd37a;
  line-height: 1.3;
}

/* ── Context menu ─────────────────────────────────────────────────────────── */
.inv-context-menu {
  position: fixed;
  background: rgba(6,6,20,0.97);
  border: 1px solid #5a3a9a;
  border-radius: 3px;
  z-index: 700;
  display: flex;
  flex-direction: column;
  min-width: 100px;
  overflow: hidden;
}
.inv-context-menu button {
  background: none;
  border: none;
  border-bottom: 1px solid #2a1a4a;
  color: #c8c0e8;
  font-family: 'Courier New', Courier, monospace;
  font-size: 12px;
  padding: 7px 14px;
  cursor: pointer;
  text-align: left;
}
.inv-context-menu button:last-child { border-bottom: none; }
.inv-context-menu button:hover { background: rgba(90,50,160,0.5); color: #fff; }

@media (max-width: 640px) {
  .inv-box { min-width: unset; padding: 10px; }
  .equip-grid {
    grid-template-columns: 56px 56px 56px;
    grid-template-rows: 56px 56px 56px 56px;
  }
  .equip-slot { width: 48px; height: 48px; }
}

/* ── Level-up banner ──────────────────────────────────────────── */
#level-up-banner {
  position: fixed;
  top: 28%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.6);
  z-index: 200;
  pointer-events: none;
  opacity: 0;
  text-align: center;
  text-shadow: 0 0 28px rgba(255,210,90,0.8), 0 4px 14px rgba(0,0,0,0.9);
  font-family: 'Courier New', Courier, monospace;
  filter: drop-shadow(0 0 18px rgba(255,200,80,0.7));
}
#level-up-banner.show { animation: levelUpAnim 1800ms cubic-bezier(.18,.9,.32,1.4) forwards; }
.level-up-kicker {
  font-size: 12px;
  color: #f0d87a;
  letter-spacing: 8px;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.level-up-title {
  font-size: 56px;
  font-weight: bold;
  color: #ffe48c;
  letter-spacing: 4px;
  text-transform: uppercase;
  margin-bottom: 6px;
}
.level-up-sub {
  font-size: 16px;
  color: #ffeab8;
  letter-spacing: 3px;
}
@keyframes levelUpAnim {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  18%  { opacity: 1; transform: translate(-50%, -50%) scale(1.18); }
  28%  { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  78%  { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -55%) scale(0.95); }
}

/* ── Quest complete modal ────────────────────────────────────── */
#quest-complete-modal {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.55);
  z-index: 220;
  animation: questCompleteFade 200ms ease-out;
}
@keyframes questCompleteFade {
  from { background: rgba(0,0,0,0); }
  to   { background: rgba(0,0,0,0.55); }
}
.quest-complete-box {
  background: linear-gradient(180deg, #1a2010 0%, #0a0e08 100%);
  border: 2px solid #c8a856;
  padding: 30px 44px;
  text-align: center;
  border-radius: 4px;
  box-shadow: 0 0 80px rgba(200,168,86,0.45), inset 0 1px 0 rgba(255,255,255,0.06);
  min-width: 320px;
  max-width: 480px;
  animation: questCompleteRise 360ms cubic-bezier(.18,.9,.32,1.4);
}
@keyframes questCompleteRise {
  from { opacity: 0; transform: translateY(20px) scale(0.9); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.quest-complete-kicker {
  font-size: 11px;
  color: #f0d87a;
  letter-spacing: 8px;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.quest-complete-title {
  font-size: 24px;
  color: #ffe48c;
  letter-spacing: 2px;
  margin-bottom: 18px;
  text-shadow: 0 0 16px rgba(255,210,90,0.4);
}
.quest-complete-rewards {
  font-size: 14px;
  color: #e8e0cc;
  letter-spacing: 1px;
  line-height: 1.7;
  margin-bottom: 22px;
  background: rgba(0,0,0,0.3);
  padding: 12px 16px;
  border-radius: 3px;
  border: 1px solid rgba(200,168,86,0.25);
}
.quest-complete-reward-row { display: block; }
.quest-complete-reward-label {
  color: #8aa86a;
  margin-right: 6px;
}

/* ── Full-screen flash overlay (hit / crit / level) ─────────── */
#fx-flash {
  position: fixed; inset: 0;
  pointer-events: none;
  background: transparent;
  z-index: 150;
  opacity: 0;
}
#fx-flash.crit  { animation: fxFlashCrit 220ms ease-out; }
#fx-flash.hurt  { animation: fxFlashHurt 280ms ease-out; }
#fx-flash.level { animation: fxFlashLevel 700ms ease-out; }
@keyframes fxFlashCrit {
  0%   { opacity: 0;   background: rgba(255,200,60,0); }
  20%  { opacity: 0.55; background: rgba(255,200,60,0.55); }
  100% { opacity: 0;   background: rgba(255,200,60,0); }
}
@keyframes fxFlashHurt {
  0%   { opacity: 0;   background: rgba(220,40,40,0); }
  18%  { opacity: 0.5; background: rgba(220,40,40,0.5); }
  100% { opacity: 0;   background: rgba(220,40,40,0); }
}
@keyframes fxFlashLevel {
  0%   { opacity: 0;   background: rgba(255,220,120,0); }
  20%  { opacity: 0.45; background: rgba(255,220,120,0.45); }
  100% { opacity: 0;   background: rgba(255,220,120,0); }
}
