/* Mapsworn — wooden / parchment medieval theme */
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  height: 100%; width: 100%;
  font-family: 'IM Fell English', 'Georgia', serif;
  color: #f5f0d6;
  background: #2a1f14;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

/* Reusable wood plank gradient — oak with grain */
.wood-bg {
  background:
    repeating-linear-gradient(180deg,
      rgba(0,0,0,0.18) 0 1px, transparent 1px 7px),
    repeating-linear-gradient(0deg,
      rgba(255,210,150,0.04) 0 1px, transparent 1px 12px),
    linear-gradient(180deg, #6f3f1c 0%, #4a2510 50%, #5a3018 100%);
  border: 2px solid #1a0a04;
  box-shadow: 0 0 0 2px #2a1f14, 0 0 0 4px #5a3018;
}

#map {
  position: absolute; inset: 0;
  background: #b8c2bd;
  z-index: 1;
}
.leaflet-container { background: #b8c2bd !important; }

/* Sky mode — atmospheric tint + drifting cloud overlay */
#map.sky-mode .leaflet-tile-pane {
  filter: hue-rotate(190deg) saturate(0.6) brightness(1.15) contrast(0.85);
}
#map.sky-mode::before {
  content: '';
  position: absolute; inset: 0;
  z-index: 350;
  pointer-events: none;
  background:
    radial-gradient(ellipse 200px 80px at 20% 30%, rgba(255,255,255,0.5) 0%, transparent 60%),
    radial-gradient(ellipse 250px 100px at 70% 60%, rgba(255,255,255,0.4) 0%, transparent 60%),
    radial-gradient(ellipse 180px 70px at 50% 80%, rgba(255,255,255,0.35) 0%, transparent 60%),
    linear-gradient(180deg, rgba(120,180,230,0.18) 0%, rgba(180,210,240,0.10) 100%);
  animation: cloudDrift 30s linear infinite alternate;
}
@keyframes cloudDrift {
  0%   { background-position: 0 0, 0 0, 0 0, 0 0; }
  100% { background-position: 60px 0, -50px 0, 30px 0, 0 0; }
}

/* No more dark filter — bright PK-style map */
#fx {
  position: absolute; inset: 0;
  pointer-events: none;
  z-index: 400;
}

/* ---- TOP HUD: avatar + name + resources strip ---- */
#hud-top {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 500;
  pointer-events: none;
  padding: 6px 8px;
}
.hud-top-row {
  display: flex; align-items: center; gap: 8px;
  background:
    repeating-linear-gradient(0deg,
      rgba(0,0,0,0.15) 0 1px, transparent 1px 8px),
    linear-gradient(180deg, #6a3a18 0%, #44210d 100%);
  border: 2px solid #1a0a04;
  border-radius: 4px;
  padding: 5px 8px;
  pointer-events: auto;
  box-shadow: 0 0 0 2px #ad7a3c, 0 3px 0 #1a0a04;
  max-width: 100%;
  overflow-x: auto;
}
.avatar {
  width: 38px; height: 38px;
  background: linear-gradient(180deg, #f3dfb4, #c8a878);
  border: 2px solid #2a1207;
  box-shadow: inset 0 0 0 2px #6a3a18;
  flex: 0 0 auto;
}
.avatar canvas { width: 100%; height: 100%; image-rendering: pixelated; }
.info { flex: 0 0 auto; min-width: 80px; }
.info .name {
  font-family: 'Cinzel', serif; font-weight: 900;
  font-size: 15px;
  color: #ffe788;
  letter-spacing: 0.5px;
  text-shadow: 1px 1px 0 #1a0a04, 2px 2px 4px rgba(0,0,0,0.6);
  line-height: 1.1;
}
.info .lvl {
  font-family: 'Cinzel', serif;
  font-size: 11px;
  font-weight: 700;
  color: #ffffff;
  text-shadow: 1px 1px 0 #1a0a04;
}

.resource-strip {
  display: flex; gap: 5px;
  margin-left: auto;
  flex-wrap: nowrap;
  overflow-x: auto;
  max-width: 60vw;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.resource-strip::-webkit-scrollbar { display: none; }
.resource-strip .coin { flex: 0 0 auto; }
.coin {
  display: flex; gap: 3px; align-items: center;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid #2a1207;
  border-radius: 3px;
  padding: 2px 5px;
  font-family: 'Cinzel', serif;
  font-size: 13px;
  font-weight: 700;
  color: #ffe788;
}
.coin .ico {
  width: 16px; height: 16px;
  image-rendering: pixelated;
  flex: 0 0 auto;
}

/* ---- BOTTOM HUD: gold / pages / HP pills ---- */
#hud-bottom {
  position: absolute;
  /* Sit above the PK-style action toolbar (~70px tall) */
  bottom: 72px; left: 0; right: 0;
  z-index: 500;
  display: flex; gap: 6px;
  padding: 8px 12px 10px;
  background:
    repeating-linear-gradient(180deg,
      rgba(0,0,0,0.18) 0 1px, transparent 1px 7px),
    linear-gradient(180deg, #6f3f1c 0%, #4a2510 100%);
  border-top: 3px solid #1a0a04;
  box-shadow: inset 0 2px 0 #ad7a3c;
}
.hud-pill {
  flex: 1;
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, #2a1207 0%, #1a0a04 100%);
  border: 2px solid #ad7a3c;
  border-radius: 6px;
  padding: 4px 8px;
  box-shadow: inset 0 0 0 1px #6a3a18;
  font-family: 'IM Fell English', serif;
  align-items: center;
  justify-content: center;
  min-height: 36px;
}
.hud-pill .pill-label {
  font-size: 10px;
  color: #ffd970;
  letter-spacing: 1px;
  text-transform: uppercase;
  font-weight: 700;
}
.hud-pill .pill-value {
  font-family: 'Cinzel', serif;
  font-weight: 900;
  font-size: 15px;
  line-height: 1;
}
.hud-pill .pill-sep { color: #6a3a18; margin: 0 2px; }
.gold-pill .pill-value { color: #ffe788; }
.pages-pill .pill-value { color: #d8e8ff; }
.pages-pill.ready {
  border-color: #5fd16e !important;
  animation: levelReadyGlow 1.5s ease-in-out infinite alternate;
}
.pages-pill.ready .pill-label::after {
  content: ' · LVL UP READY';
  color: #5fd16e;
  font-weight: 900;
}
@keyframes levelReadyGlow {
  0%   { box-shadow: inset 0 0 0 1px #6a3a18, 0 0 0 0 rgba(95,209,110,0); }
  100% { box-shadow: inset 0 0 0 1px #6a3a18, 0 0 12px rgba(95,209,110,0.7); }
}
.hp-pill { padding: 6px; }
.hp-pill .bar.hp {
  width: 100%; height: 18px;
  background: #1a0a04;
  border: 1px solid #6a3a18;
  border-radius: 3px;
  position: relative;
  overflow: hidden;
}
.hp-pill #hp-fill {
  height: 100%;
  background: linear-gradient(180deg, #7adb7a 0%, #2a8c2a 100%);
  width: 100%;
  transition: width 0.25s ease;
}
.hp-pill #hp-text {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: #fff;
  font-family: 'Cinzel', serif; font-weight: 700;
  text-shadow: 1px 1px 0 #1a0a04;
}

/* ---- ACTION BUTTONS — PK-style golden tabs ---- */
/* ---- PK-style horizontal action toolbar ----
   Modeled on original PK's bottom strip (Items / Create / Travel / Messages / ...).
   Buttons sit in a single row across the bottom of the screen with icon + label. */
#actions {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex; flex-direction: row;
  gap: 2px;
  padding: 4px 6px 6px;
  z-index: 500;
  background:
    repeating-linear-gradient(0deg, rgba(0,0,0,0.18) 0 1px, transparent 1px 7px),
    linear-gradient(180deg, #4a2510 0%, #2a1408 100%);
  border-top: 2px solid #ad7a3c;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.5);
  justify-content: space-between;
}
/* Overflow popup — rises above the bar when MORE is tapped */
#actions-secondary {
  position: fixed;
  left: 6px; right: 6px;
  bottom: 70px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 6px;
  background:
    repeating-linear-gradient(0deg, rgba(0,0,0,0.18) 0 1px, transparent 1px 7px),
    linear-gradient(180deg, #4a2510 0%, #2a1408 100%);
  border: 2px solid #ad7a3c;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.6);
  z-index: 600;
}
#actions-secondary.hidden { display: none; }
#menu-badge,
#chat-badge {
  position: absolute;
  top: 2px; right: 2px;
  background: #e64f4f;
  color: #fff;
  border-radius: 8px;
  padding: 0 5px;
  font-size: 9px;
  font-weight: 700;
}
#menu-badge.hidden,
#chat-badge.hidden { display: none; }
/* The PK-style button: icon on top, small label below. */
.actbtn {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  height: 56px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1px;
  font-family: 'Cinzel', serif; font-weight: 900;
  background:
    radial-gradient(circle at 30% 30%, #fce67d 0%, transparent 60%),
    linear-gradient(180deg, #d8a850 0%, #ad7a3c 50%, #6a3a18 100%);
  color: #2a1207;
  border: 2px solid #1a0a04;
  border-radius: 5px;
  box-shadow:
    inset 0 1px 0 rgba(255, 240, 180, 0.7),
    inset 0 -2px 0 rgba(0,0,0,0.4),
    0 2px 0 #1a0a04;
  cursor: pointer;
  text-shadow: 1px 1px 0 rgba(255,240,180,0.5);
  padding: 0;
  transition: transform 0.05s, box-shadow 0.05s;
}
.actbtn .ic { font-size: 18px; line-height: 1; }
.actbtn .lab { font-size: 9px; letter-spacing: 1px; line-height: 1; }
.actbtn:hover {
  background:
    radial-gradient(circle at 30% 30%, #fff0a0 0%, transparent 60%),
    linear-gradient(180deg, #e8c060 0%, #c08850 50%, #7a4a28 100%);
}
.actbtn:active {
  transform: translateY(2px);
  box-shadow:
    inset 0 1px 0 rgba(255, 240, 180, 0.7),
    inset 0 -2px 0 rgba(0,0,0,0.4);
}
#actions #btn-flag .ic { filter: hue-rotate(-30deg); }
#actions #btn-mute, #actions #btn-help {
  /* legacy refs kept to avoid breaking nothing else — same baseline now */
  width: auto; height: 56px;
  font-size: 14px;
  align-self: flex-end;
}

/* ---- LOG ---- */
#log {
  position: absolute;
  /* Above HUD pills (~50px) + action toolbar (~70px) = clears 120px */
  bottom: 140px; left: 12px;
  width: 65%; max-width: 420px;
  max-height: 30%;
  overflow: hidden;
  z-index: 500;
  pointer-events: none;
  transition: bottom 180ms ease-out, opacity 180ms ease-out;
}
/* When the overflow menu is open above the bar, push the log up so it doesn't
   cover the popup grid. */
body.menu-open #log {
  bottom: 240px;
  opacity: 0.6;
}
.log-line {
  background: rgba(20, 8, 4, 0.92);
  border: 1px solid #ad7a3c;
  border-left: 4px solid #fce67d;
  padding: 5px 10px;
  margin-top: 3px;
  font-family: 'Georgia', serif;
  font-size: 14px;
  color: #ffffff;
  animation: logFade 6s forwards;
  border-radius: 0 4px 4px 0;
}
.log-line.combat { border-left-color: #e64f4f; }
.log-line.loot   { border-left-color: #5fd16e; }
.log-line.system { border-left-color: #5fa8d1; }
@keyframes logFade {
  0% { opacity: 0; transform: translateX(-10px); }
  10% { opacity: 1; transform: translateX(0); }
  85% { opacity: 1; }
  100% { opacity: 0; }
}

/* ---- MODAL ---- */
#modal {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
#modal.hidden { display: none; }
.modal-card {
  background:
    repeating-linear-gradient(0deg,
      rgba(0,0,0,0.06) 0 1px, transparent 1px 12px),
    linear-gradient(180deg, #f3dfb4 0%, #d8b884 100%);
  color: #2a1207;
  border: 3px solid #2a1207;
  box-shadow: 0 0 0 2px #ad7a3c, 0 0 0 4px #2a1207, 8px 8px 0 rgba(0,0,0,0.5);
  width: 92%; max-width: 420px;
  max-height: 85vh;
  overflow: auto;
  border-radius: 6px;
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  background: linear-gradient(180deg, #6f3f1c 0%, #44210d 100%);
  color: #fce67d;
  padding: 8px 12px;
  border-bottom: 3px solid #1a0a04;
  font-family: 'Cinzel', serif;
  font-weight: 700;
  letter-spacing: 2px;
  font-size: 14px;
  text-shadow: 1px 1px 0 #1a0a04;
}
#modal-close {
  background: #4a1a1a; color: #fff;
  border: 2px solid #1a0a04;
  width: 26px; height: 26px;
  font-family: inherit; font-weight: 700;
  cursor: pointer;
  border-radius: 3px;
}
#modal-body {
  padding: 12px;
  font-family: 'Georgia', 'IM Fell English', serif;
  font-size: 14px;
  line-height: 1.55;
  color: #1a0a04;
}
#modal-body p, #modal-body div, #modal-body span { color: inherit; }
#modal-body b { color: #4a1a0a; }

/* Inventory grid */
.inv-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.inv-slot {
  aspect-ratio: 1;
  background: rgba(26, 10, 4, 0.08);
  border: 2px solid #6a3a18;
  border-radius: 4px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  font-family: 'IM Fell English', serif;
  font-size: 11px;
  color: #2a1207;
  padding: 2px;
}
.inv-slot canvas { width: 32px; height: 32px; image-rendering: pixelated; }
.inv-slot .qty { font-size: 10px; color: #6a3a18; font-weight: 700; }
.inv-slot.equip-slot { padding: 4px; aspect-ratio: auto; }
.inv-slot .bonus { font-size: 10px; color: #2a8c2a; line-height: 1.3; min-height: 11px; font-weight: 700; }
.inv-slot.usable { cursor: pointer; border-color: #2a8c2a; box-shadow: 0 0 0 2px rgba(42,140,42,0.25); }
.inv-slot.usable:hover { background: rgba(42,140,42,0.12); }
.inv-slot.usable:active { transform: scale(0.95); }

/* Equipment rarity halos & name colors */
.rarity-common { /* default */ }
.rarity-uncommon { box-shadow: inset 0 0 0 2px #1eaa1e, 0 0 6px rgba(30,170,30,0.4); border-color: #1eaa1e !important; }
.rarity-rare     { box-shadow: inset 0 0 0 2px #2a7add, 0 0 7px rgba(42,122,221,0.45); border-color: #2a7add !important; }
.rarity-epic     { box-shadow: inset 0 0 0 2px #a040c0, 0 0 8px rgba(160,64,192,0.5);  border-color: #a040c0 !important; }
.rarity-legendary{ box-shadow: inset 0 0 0 2px #ff8000, 0 0 9px rgba(255,128,0,0.55);  border-color: #ff8000 !important; }
.rarity-name.rarity-common    { color: #2a1207; }
.rarity-name.rarity-uncommon  { color: #1eaa1e; }
.rarity-name.rarity-rare      { color: #2a7add; }
.rarity-name.rarity-epic      { color: #a040c0; }
.rarity-name.rarity-legendary { color: #ff8000; }
.equip-cell.rarity-uncommon, .equip-cell.rarity-rare,
.equip-cell.rarity-epic,    .equip-cell.rarity-legendary { border-width: 2px; }

/* Equip row (character sheet) */
.equip-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.equip-cell {
  background: rgba(26, 10, 4, 0.08);
  border: 2px solid #6a3a18;
  border-radius: 4px;
  padding: 4px;
  text-align: center;
  font-size: 10px;
  color: #2a1207;
  display: flex; flex-direction: column;
  align-items: center; justify-content: flex-start;
  min-height: 90px;
}
.equip-cell .slot-label { color: #1a0a04; font-size: 10px; letter-spacing: 1px; margin-bottom: 3px; font-weight: 800; }
.equip-cell canvas { image-rendering: pixelated; }
.equip-cell .slot-name { font-size: 11px; color: #2a1207; margin-top: 2px; font-weight: 700; }
.equip-cell .empty { color: #ad7a3c; font-size: 10px; margin-top: 24px; font-style: italic; }
.equip-cell .bonus { font-size: 10px; color: #2a8c2a; font-weight: 700; }

/* Spec grid */
.spec-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}
.spec-btn {
  background: linear-gradient(180deg, #ad7a3c 0%, #6a3a18 100%);
  border: 2px solid #1a0a04;
  color: #fce67d;
  padding: 6px 8px;
  text-align: left;
  font-family: 'IM Fell English', serif;
  cursor: pointer;
  border-radius: 4px;
  box-shadow: inset 0 0 0 1px #f3dfb4;
}
.spec-btn:active { transform: translateY(1px); }
.spec-btn .spec-name { color: #fce67d; font-family: 'Cinzel', serif; font-weight: 700; font-size: 12px; }
.spec-btn .spec-desc { font-size: 10px; color: #f3dfb4; line-height: 1.4; margin-top: 2px; }
.spec-current {
  background: rgba(252, 230, 125, 0.15);
  border: 2px solid #6a3a18;
  border-radius: 4px;
  padding: 8px;
}

/* Skill list */
.skill-list {
  display: flex; flex-direction: column;
  gap: 4px;
  max-height: 180px;
  overflow-y: auto;
}
.skill-row {
  display: flex; gap: 6px;
  padding: 4px 6px;
  background: rgba(26, 10, 4, 0.05);
  border: 1px solid #ad7a3c;
  border-radius: 3px;
  align-items: center;
}
.skill-info { flex: 1; font-size: 12px; color: #1a0a04; }
.skill-info .rank { color: #1a6618; font-weight: 700; }
.skill-info .skill-desc { color: #3a1f08; font-size: 11px; line-height: 1.4; font-style: normal; }
.skill-row .skill-up { width: 36px !important; flex: 0 0 auto; }

.ach-grid { display: flex; flex-direction: column; gap: 4px; max-height: 200px; overflow-y: auto; }
.ach-row {
  display: flex; gap: 6px;
  padding: 4px 6px;
  background: rgba(26, 10, 4, 0.05);
  border: 1px solid #ad7a3c;
  border-radius: 3px;
  align-items: center;
}
.ach-row.got { background: rgba(95, 209, 110, 0.15); }

/* ---- SPLASH ---- */
#splash {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse at center, rgba(60, 100, 140, 0.3) 0%, rgba(8, 10, 16, 0.95) 70%),
    linear-gradient(180deg, #2a4060 0%, #1a2030 50%, #050810 100%);
  display: flex; align-items: center; justify-content: center;
  z-index: 2000;
  padding: 20px;
}
#splash.hidden { display: none; }
.splash-card {
  text-align: center;
  background:
    repeating-linear-gradient(0deg,
      rgba(0,0,0,0.04) 0 1px, transparent 1px 12px),
    linear-gradient(180deg, #f3dfb4 0%, #d8b884 100%);
  color: #2a1207;
  border: 4px solid #1a0a04;
  box-shadow: 0 0 0 2px #ad7a3c, 0 0 0 6px #1a0a04, 0 0 60px rgba(252, 230, 125, 0.2);
  padding: 28px 24px;
  width: 100%; max-width: 380px;
  border-radius: 8px;
}
.splash-card h1 {
  margin: 0;
  font-family: 'Cinzel', serif;
  font-weight: 900;
  font-size: 28px;
  color: #fce67d;
  letter-spacing: 3px;
  text-shadow: 2px 2px 0 #1a0a04, 4px 4px 8px rgba(0,0,0,0.5);
  background: linear-gradient(180deg, #fce67d 0%, #ad7a3c 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(2px 2px 0 #1a0a04);
}
.splash-card .tag {
  margin: 4px 0 16px;
  font-family: 'Cinzel', serif;
  color: #8a1a1a;
  letter-spacing: 8px;
  font-size: 14px;
  font-weight: 700;
}
.splash-card p {
  font-family: 'Georgia', serif;
  color: #1a0a04;
  font-size: 14px;
  line-height: 1.5;
}
.splash-card label {
  display: block; margin: 16px 0 8px;
  font-family: 'Cinzel', serif;
  font-size: 11px;
  color: #4a2510;
  letter-spacing: 2px;
  text-transform: uppercase;
}
.splash-card input {
  width: 100%; padding: 10px;
  background: #fefae0;
  border: 2px solid #6a3a18;
  color: #2a1207;
  font-family: 'IM Fell English', serif;
  font-size: 16px;
  text-align: center;
  margin-top: 4px;
  border-radius: 4px;
}
.splash-card input:focus { outline: none; border-color: #fce67d; box-shadow: 0 0 0 2px #ad7a3c; }
.splash-card button {
  margin-top: 16px;
  width: 100%; padding: 14px;
  background: linear-gradient(180deg, #ad7a3c 0%, #6a3a18 100%);
  color: #fce67d;
  border: 3px solid #1a0a04;
  font-family: 'Cinzel', serif;
  font-weight: 900;
  font-size: 14px;
  letter-spacing: 3px;
  cursor: pointer;
  border-radius: 4px;
  box-shadow: inset 0 0 0 1px #f3dfb4, 0 4px 0 #1a0a04;
  text-shadow: 1px 1px 0 #1a0a04;
}
.splash-card button:active {
  transform: translateY(2px);
  box-shadow: inset 0 0 0 1px #f3dfb4, 0 2px 0 #1a0a04;
}
.splash-card .hint {
  font-size: 11px; color: #8a6e1c;
  margin-top: 12px;
  font-style: italic;
}

/* ---- Floating combat text ---- */
.float-text {
  position: absolute;
  pointer-events: none;
  font-family: 'Cinzel', serif;
  font-weight: 900;
  font-size: 16px;
  text-shadow: 2px 2px 0 #1a0a04, -2px -2px 0 #1a0a04, 2px -2px 0 #1a0a04, -2px 2px 0 #1a0a04;
  z-index: 600;
  animation: floatUp 1.2s forwards;
}
.float-text.dmg  { color: #ff5f5f; }
.float-text.heal { color: #5fd16e; }
.float-text.xp   { color: #fce67d; }
@keyframes floatUp {
  0% { transform: translateY(0); opacity: 1; }
  100% { transform: translateY(-40px); opacity: 0; }
}

/* ---- Leaflet sprite markers ---- */
.leaflet-tile-container img,
.leaflet-tile {
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
}
.sprite-icon { background: transparent !important; border: none !important; }
.sprite-icon canvas { image-rendering: pixelated; display: block; }

.leaflet-control-zoom { display: none; }
.leaflet-control-attribution {
  font-family: 'IM Fell English', serif !important;
  font-size: 9px !important;
  background: rgba(0,0,0,0.5) !important;
  color: #888 !important;
}
.leaflet-control-attribution a { color: #b0c4de !important; }

/* ---- Mob HP bar (above sprite) ---- */
.mob-hp {
  position: absolute;
  left: 50%; top: -10px;
  transform: translateX(-50%);
  width: 32px; height: 5px;
  background: #1a0a04;
  border: 1px solid #1a0a04;
  pointer-events: none;
  border-radius: 1px;
  box-shadow: 0 0 0 1px #ad7a3c;
}
.mob-hp .fill { width: 100%; height: 100%; background: #5fd16e; transition: width 0.3s ease; }

/* Level pip above any entity (peer / monster / NPC) */
.lvl-pip {
  position: absolute;
  left: 50%; top: -22px;
  transform: translateX(-50%);
  background: linear-gradient(180deg, #fce67d, #ad7a3c);
  border: 1px solid #1a0a04;
  color: #1a0a04;
  font-family: 'Cinzel', serif;
  font-weight: 900;
  font-size: 9px;
  padding: 0 4px;
  border-radius: 2px;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: 0 1px 0 rgba(0,0,0,0.3);
}

/* Peer name label below the pip */
/* Monster idle bob */
.sprite-icon canvas {
  animation: idleBob 2.5s ease-in-out infinite;
}
@keyframes idleBob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-2px); }
}

/* Particle puff (kill / hit) */
.fx-puff {
  position: absolute;
  width: 22px; height: 22px;
  pointer-events: none;
  z-index: 700;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,210,90,0.9) 0%, rgba(255,140,30,0.5) 40%, rgba(255,80,30,0) 80%);
  animation: puff 0.6s ease-out forwards;
}
@keyframes puff {
  0%   { transform: scale(0.4); opacity: 1; }
  100% { transform: scale(2.4); opacity: 0; }
}

/* Screen shake on big hits */
.shake { animation: shake 0.35s ease-in-out; }
@keyframes shake {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(-4px, 2px); }
  50% { transform: translate(3px, -2px); }
  75% { transform: translate(-2px, 3px); }
}

/* Waypoint pin */
.wp-icon { background: transparent !important; border: none !important; }
.wp-pin {
  font-size: 22px;
  text-align: center;
  cursor: pointer;
  text-shadow: 0 0 3px rgba(0,0,0,0.7);
}
.wp-pin .wp-name {
  display: block;
  font-family: 'Cinzel', serif;
  font-size: 9px;
  color: #ffe788;
  text-shadow: 1px 1px 0 #1a0a04;
  margin-top: -4px;
  background: rgba(20,8,4,0.85);
  padding: 1px 4px;
  border: 1px solid #ad7a3c;
  border-radius: 3px;
  white-space: nowrap;
}

/* Infused weapon — pulsing glow + sparkles */
.eq-overlay.infused {
  --glow: #ffe788;
  animation: weaponPulse 1.4s ease-in-out infinite alternate;
}
@keyframes weaponPulse {
  0%   { filter: drop-shadow(0 0 2px var(--glow)) drop-shadow(0 0 4px var(--glow)); }
  100% { filter: drop-shadow(0 0 6px var(--glow)) drop-shadow(0 0 14px var(--glow)) brightness(1.15); }
}
@keyframes sparkleUp {
  0%   { transform: translateY(0)   scale(0.7); opacity: 0; }
  20%  { opacity: 1; }
  100% { transform: translateY(-22px) scale(1.2); opacity: 0; }
}

/* Burning flag territory — pulsing red */
.flag-burning {
  animation: flagBurn 1.4s infinite;
}
@keyframes flagBurn {
  0%, 100% { stroke-opacity: 0.7; fill-opacity: 0.15; }
  50%      { stroke-opacity: 1.0; fill-opacity: 0.35; }
}

.peer-name {
  position: absolute;
  left: 50%; top: -12px;
  transform: translateX(-50%);
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 10px;
  color: #fce67d;
  text-shadow: 1px 1px 0 #1a0a04, -1px -1px 0 #1a0a04;
  white-space: nowrap;
  pointer-events: none;
}

/* ---- Chat panel — collapsible drawer ---- */
#chat-panel {
  position: absolute;
  left: 8px; bottom: 80px;
  width: 320px;
  max-width: calc(100vw - 100px);
  z-index: 700;
  pointer-events: auto;
}
#chat-panel.hidden { display: none; }
.chat-frame {
  background:
    repeating-linear-gradient(0deg, rgba(0,0,0,0.18) 0 1px, transparent 1px 7px),
    linear-gradient(180deg, #2a1a08 0%, #1a0a04 100%);
  border: 2px solid #ad7a3c;
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.6);
}
.chat-header {
  display: flex; justify-content: space-between; align-items: center;
  background: linear-gradient(180deg, #6f3f1c 0%, #44210d 100%);
  color: #ffe788;
  padding: 5px 10px;
  border-bottom: 2px solid #1a0a04;
  font-family: 'Cinzel', serif;
  font-weight: 900;
  font-size: 12px;
  letter-spacing: 2px;
}
.chat-header button {
  background: #4a1a1a; color: #fff;
  border: 1px solid #1a0a04;
  font-family: inherit; font-weight: 700;
  width: 22px; height: 22px;
  cursor: pointer; border-radius: 2px;
}
#chat-log {
  height: 200px;
  max-height: 35vh;
  overflow-y: auto;
  padding: 6px 8px;
  display: flex; flex-direction: column-reverse;
}
#chat-form { padding: 6px 8px; border-top: 2px solid #ad7a3c; background: rgba(0,0,0,0.4); }
#chat-badge {
  display: inline-block;
  margin-left: 3px;
  background: #e64f4f;
  color: #fff;
  border-radius: 8px;
  padding: 0 5px;
  font-size: 10px;
  font-weight: 700;
}
#chat-badge.hidden { display: none; }
.chat-line {
  background: rgba(20, 8, 4, 0.92);
  border: 1px solid #ad7a3c;
  border-left: 3px solid #c869b8;
  padding: 4px 8px;
  margin-top: 2px;
  font-family: 'Georgia', serif;
  font-size: 13px;
  color: #ffffff;
  border-radius: 0 3px 3px 0;
}
.chat-line .who { color: #fce67d; font-weight: 700; }
.chat-line.me .who { color: #88ddff; }
.chat-line.system { border-left-color: #5fa8d1; color: #d8e8ff; font-style: normal; }
.chat-line.guild { border-left-color: #5fd16e; }
.chat-line.guild .who { color: #5fd16e; }
.chat-line.pm { border-left-color: #c869b8; }
.chat-line.pm .who { color: #c869b8; }
#chat-form { display: block; }
#chat-input {
  width: 100%;
  background: rgba(20, 14, 8, 0.95);
  border: 2px solid #6a3a18;
  color: #ffffff;
  padding: 7px 10px;
  font-family: 'Georgia', serif;
  font-size: 14px;
  border-radius: 3px;
}
#chat-input:focus { outline: none; border-color: #fce67d; }

/* ---- Dungeon overlay (sewer) ---- */
#dungeon {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 1400;
  display: flex; align-items: center; justify-content: center;
  padding: 12px;
}
#dungeon.hidden { display: none; }
.dungeon-frame {
  background:
    repeating-linear-gradient(0deg, rgba(0,0,0,0.18) 0 1px, transparent 1px 7px),
    linear-gradient(180deg, #2a2018 0%, #1a1208 100%);
  border: 4px solid #1a0a04;
  box-shadow: 0 0 0 2px #6a3a18, 0 0 40px rgba(60, 100, 80, 0.3);
  padding: 8px;
  max-width: 100%;
  max-height: 100%;
  overflow: auto;
  border-radius: 6px;
}
.dungeon-header {
  display: flex; align-items: center; gap: 8px;
  background: #1a0a04;
  padding: 6px 10px;
  border: 2px solid #6a3a18;
  font-family: 'Cinzel', serif;
  color: #aaff88;
  letter-spacing: 2px;
  margin-bottom: 6px;
}
#dungeon-title {
  font-weight: 900;
  font-size: 14px;
  flex: 0 0 auto;
}
#dungeon-room-label {
  flex: 1;
  font-size: 11px;
  color: #88aa88;
  font-style: italic;
  letter-spacing: 1px;
}
#dungeon-flee {
  background: #4a1a1a; color: #fff;
  border: 2px solid #1a0a04;
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 1px;
  padding: 4px 10px;
  cursor: pointer;
  border-radius: 3px;
}
.dungeon-stage {
  position: relative;
  background:
    repeating-linear-gradient(45deg, #1a1208 0 4px, #2a2018 4px 8px),
    #1a1208;
  border: 3px solid #6a3a18;
  box-shadow: inset 0 0 20px rgba(0,0,0,0.7);
  padding: 0;
  display: inline-block;
}
#dungeon-grid {
  display: grid;
  gap: 0;
  position: relative;
}
.d-cell {
  background:
    repeating-linear-gradient(0deg, rgba(255,220,180,0.04) 0 1px, transparent 1px 6px),
    linear-gradient(180deg, #4a3a28 0%, #2a2018 100%);
  border: 1px solid rgba(0,0,0,0.4);
  cursor: pointer;
}
.d-cell:hover { background: linear-gradient(180deg, #6a4a38 0%, #4a2a18 100%); }
.d-wall {
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,0.3) 0 12px, rgba(255,255,255,0.05) 12px 14px),
    linear-gradient(180deg, #5a4030 0%, #3a2818 100%) !important;
  border: 1px solid #1a0a04 !important;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.5);
  cursor: not-allowed !important;
}
.d-water {
  background:
    repeating-linear-gradient(90deg, #1a3a28 0 4px, #2a4838 4px 8px),
    #1a3a28 !important;
  box-shadow: inset 0 0 8px rgba(0,0,0,0.5);
}

/* Cavern theme — grey stone with crystal veins */
.dungeon-stage.theme-cavern {
  background:
    repeating-linear-gradient(45deg, #1a1818 0 5px, #2a2828 5px 10px),
    #1a1818;
}
.dungeon-stage.theme-cavern .d-cell {
  background:
    repeating-linear-gradient(0deg, rgba(180,200,220,0.05) 0 1px, transparent 1px 7px),
    linear-gradient(180deg, #4a4a52 0%, #2a2a32 100%);
}
.dungeon-stage.theme-cavern .d-wall {
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,0.4) 0 14px, rgba(180,200,220,0.08) 14px 16px),
    linear-gradient(180deg, #404048 0%, #1a1a22 100%) !important;
}
.dungeon-stage.theme-cavern .d-water {
  background:
    repeating-linear-gradient(90deg, #1a3858 0 4px, #2a4868 4px 8px),
    #1a3858 !important;
}
.dungeon-stage.theme-cavern #dungeon-log { color: #aaccee; }

/* Grove theme — mossy stone, wooden walls, green grass paths */
.dungeon-stage.theme-grove {
  background:
    repeating-linear-gradient(45deg, #1a3018 0 5px, #2a4028 5px 10px),
    #1a3018;
}
.dungeon-stage.theme-grove .d-cell {
  background:
    repeating-linear-gradient(0deg, rgba(120,180,80,0.06) 0 1px, transparent 1px 6px),
    linear-gradient(180deg, #3a5a28 0%, #2a4018 100%);
}
.dungeon-stage.theme-grove .d-wall {
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,0.3) 0 11px, rgba(120,80,30,0.15) 11px 13px),
    linear-gradient(180deg, #5a3a18 0%, #2a1808 100%) !important;
}
.dungeon-stage.theme-grove .d-water {
  background:
    repeating-linear-gradient(90deg, #2a4818 0 4px, #3a5828 4px 8px),
    #2a4818 !important;
}
.dungeon-stage.theme-grove #dungeon-log { color: #aaff88; }

/* Roc Nest — sky cliff stone with feathers */
.dungeon-stage.theme-rocnest .d-cell {
  background:
    repeating-linear-gradient(0deg, rgba(255,200,150,0.06) 0 1px, transparent 1px 6px),
    linear-gradient(180deg, #c8b89a 0%, #8a7a5a 100%);
}
.dungeon-stage.theme-rocnest .d-wall {
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,0.3) 0 12px, rgba(255,255,200,0.1) 12px 14px),
    linear-gradient(180deg, #8a7a5a 0%, #4a3a28 100%) !important;
}
.dungeon-stage.theme-rocnest .d-water {
  background: linear-gradient(180deg, #88ccee 0%, #4488aa 100%) !important;
}
.dungeon-stage.theme-rocnest #dungeon-log { color: #ffe0a0; }

/* Dojo — bamboo + tatami */
.dungeon-stage.theme-dojo .d-cell {
  background:
    repeating-linear-gradient(45deg, #d8c89a 0 6px, #c8b888 6px 12px),
    #d8c89a;
}
.dungeon-stage.theme-dojo .d-wall {
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,0.2) 0 8px, rgba(0,80,0,0.4) 8px 12px),
    linear-gradient(180deg, #4a6818 0%, #2a3818 100%) !important;
}
.dungeon-stage.theme-dojo .d-water {
  background: #1a2818 !important;
}
.dungeon-stage.theme-dojo #dungeon-log { color: #ffe080; }

/* Dragon Lair — magma + obsidian */
.dungeon-stage.theme-dragonlair .d-cell {
  background:
    repeating-linear-gradient(0deg, rgba(255,80,0,0.08) 0 1px, transparent 1px 5px),
    linear-gradient(180deg, #4a1808 0%, #200800 100%);
}
.dungeon-stage.theme-dragonlair .d-wall {
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,0.5) 0 12px, rgba(255,80,0,0.15) 12px 14px),
    linear-gradient(180deg, #2a0808 0%, #100000 100%) !important;
}
.dungeon-stage.theme-dragonlair .d-water {
  background:
    repeating-linear-gradient(90deg, #ff6020 0 4px, #d04010 4px 8px),
    #ff6020 !important;
  box-shadow: inset 0 0 20px rgba(255, 100, 0, 0.6);
}
.dungeon-stage.theme-dragonlair #dungeon-log { color: #ffaa66; }

/* Manor interior — wood plank floor + cozy walls */
.dungeon-stage.theme-manor .d-cell {
  background:
    repeating-linear-gradient(0deg, rgba(0,0,0,0.18) 0 1px, transparent 1px 11px),
    linear-gradient(180deg, #b48a52 0%, #8a6a38 100%);
}
.dungeon-stage.theme-manor .d-wall {
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,0.3) 0 13px, rgba(255,235,180,0.1) 13px 15px),
    linear-gradient(180deg, #6a4a28 0%, #2a1808 100%) !important;
}
.dungeon-stage.theme-manor #dungeon-log { color: #ffe788; }

/* Tavern — wood plank floor with red rug border */
.dungeon-stage.theme-tavern .d-cell {
  background:
    repeating-linear-gradient(0deg, rgba(0,0,0,0.18) 0 1px, transparent 1px 11px),
    linear-gradient(180deg, #b48a52 0%, #6a4a28 100%);
}
.dungeon-stage.theme-tavern .d-wall {
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,0.4) 0 14px, rgba(255,235,180,0.1) 14px 16px),
    linear-gradient(180deg, #4a2810 0%, #1a0a04 100%) !important;
}
.dungeon-stage.theme-tavern #dungeon-log { color: #ffe788; }

/* Trade Post — stone floor + light walls */
.dungeon-stage.theme-tradepost .d-cell {
  background:
    repeating-linear-gradient(45deg, #d8c8a0 0 8px, #c0b088 8px 16px),
    #d8c8a0;
}
.dungeon-stage.theme-tradepost .d-wall {
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,0.3) 0 12px, rgba(255,235,180,0.15) 12px 14px),
    linear-gradient(180deg, #6a583a 0%, #3a2818 100%) !important;
}
.dungeon-stage.theme-tradepost #dungeon-log { color: #fce67d; }

/* Castle — purple/blue marble + red carpet */
.dungeon-stage.theme-castle .d-cell {
  background:
    repeating-linear-gradient(0deg, rgba(255,255,255,0.04) 0 1px, transparent 1px 8px),
    linear-gradient(180deg, #6a5a8a 0%, #38284a 100%);
}
.dungeon-stage.theme-castle .d-wall {
  background:
    repeating-linear-gradient(90deg, rgba(0,0,0,0.5) 0 14px, rgba(180,160,255,0.15) 14px 16px),
    linear-gradient(180deg, #2a1a48 0%, #100828 100%) !important;
}
.dungeon-stage.theme-castle #dungeon-log { color: #c8a8ff; }

/* Phase 37 — Combat ability bar (shown only during combat, above the main action bar) */
#combat-bar {
  position: fixed;
  left: 6px; right: 6px;
  bottom: 78px;            /* sits just above the main action bar */
  display: none;
  flex-direction: row;
  gap: 4px;
  padding: 5px;
  background:
    repeating-linear-gradient(0deg, rgba(0,0,0,0.18) 0 1px, transparent 1px 7px),
    linear-gradient(180deg, #3a1a08 0%, #1a0a04 100%);
  border: 2px solid #e64f4f;
  border-radius: 6px;
  box-shadow: 0 4px 14px rgba(230,79,79,0.5), 0 -2px 0 rgba(0,0,0,0.5);
  z-index: 550;
  animation: combatPulse 1.6s ease-in-out infinite;
}
@keyframes combatPulse {
  0%, 100% { box-shadow: 0 4px 14px rgba(230,79,79,0.5), 0 -2px 0 rgba(0,0,0,0.5); }
  50%      { box-shadow: 0 4px 24px rgba(230,79,79,0.85), 0 -2px 0 rgba(0,0,0,0.5); }
}
.cbtn {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  height: 52px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  background:
    radial-gradient(circle at 30% 30%, #fce67d 0%, transparent 60%),
    linear-gradient(180deg, #d8a850 0%, #ad7a3c 50%, #6a3a18 100%);
  color: #2a1207;
  border: 2px solid #1a0a04;
  border-radius: 5px;
  box-shadow:
    inset 0 1px 0 rgba(255,240,180,0.7),
    inset 0 -2px 0 rgba(0,0,0,0.4),
    0 2px 0 #1a0a04;
  cursor: pointer;
  font-family: 'Cinzel', serif; font-weight: 900;
  text-shadow: 1px 1px 0 rgba(255,240,180,0.5);
  padding: 0;
  transition: transform 0.05s, opacity 0.2s, filter 0.2s;
}
.cbtn .ic  { font-size: 16px; line-height: 1; }
.cbtn .lab { font-size: 9px;  letter-spacing: 1px; line-height: 1; }
.cbtn .cd  { font-size: 10px; color: #6a3a18; line-height: 1; min-height: 10px; }
.cbtn:active { transform: translateY(2px); box-shadow: inset 0 1px 0 rgba(255,240,180,0.7), inset 0 -2px 0 rgba(0,0,0,0.4); }
.cbtn.on-cd {
  opacity: 0.55;
  filter: grayscale(0.6) brightness(0.7);
  cursor: not-allowed;
}
.cbtn.on-cd .cd { color: #e64f4f; font-weight: 700; }
.cbtn.flee {
  background:
    radial-gradient(circle at 30% 30%, #ff8a6a 0%, transparent 60%),
    linear-gradient(180deg, #e64f4f 0%, #8a1a1a 50%, #3a0a04 100%);
  color: #fce67d;
}

/* Phase 34 — house and structure interiors */
.dungeon-stage.theme-house .d-cell      { background: repeating-linear-gradient(0deg, rgba(0,0,0,0.15) 0 1px, transparent 1px 12px), #a8825a; }
.dungeon-stage.theme-house .d-wall      { background: linear-gradient(180deg, #4a2818 0%, #2a1408 100%) !important; }
.dungeon-stage.theme-apothecary .d-cell { background: repeating-linear-gradient(45deg, #5a7a4a 0 12px, #4a6a3a 12px 24px); }
.dungeon-stage.theme-apothecary .d-wall { background: linear-gradient(180deg, #2a3a1a 0%, #0a1a04 100%) !important; }
.dungeon-stage.theme-granary .d-cell    { background: repeating-linear-gradient(90deg, #c8a868 0 16px, #b89858 16px 32px); }
.dungeon-stage.theme-granary .d-wall    { background: linear-gradient(180deg, #6a4818 0%, #2a1808 100%) !important; }
.dungeon-stage.theme-lodge .d-cell      { background: repeating-linear-gradient(0deg, rgba(255,255,255,0.1) 0 1px, transparent 1px 10px), #d8c8a0; }
.dungeon-stage.theme-lodge .d-wall      { background: linear-gradient(180deg, #8a6a48 0%, #4a2818 100%) !important; }
.dungeon-stage.theme-tinker .d-cell     { background: repeating-linear-gradient(45deg, #7a6a4a 0 12px, #6a5a3a 12px 24px); }
.dungeon-stage.theme-tinker .d-wall     { background: linear-gradient(180deg, #3a2818 0%, #1a0a04 100%) !important; }
.dungeon-stage.theme-farm .d-cell       { background: repeating-linear-gradient(0deg, #5a8a3a 0 14px, #4a7a2a 14px 28px); }
.dungeon-stage.theme-farm .d-wall       { background: linear-gradient(180deg, #4a3818 0%, #1a0a04 100%) !important; }
.dungeon-stage.theme-lumbermill .d-cell { background: repeating-linear-gradient(90deg, #8a6a3a 0 18px, #7a5a2a 18px 36px); }
.dungeon-stage.theme-lumbermill .d-wall { background: linear-gradient(180deg, #4a2818 0%, #1a0a04 100%) !important; }
.dungeon-stage.theme-quarry .d-cell     { background: repeating-linear-gradient(0deg, #aaaaaa 0 12px, #888888 12px 24px); }
.dungeon-stage.theme-quarry .d-wall     { background: linear-gradient(180deg, #4a4a4a 0%, #1a1a1a 100%) !important; }
.dungeon-stage.theme-blacksmith .d-cell { background: repeating-linear-gradient(0deg, rgba(0,0,0,0.3) 0 1px, transparent 1px 10px), #5a3a28; }
.dungeon-stage.theme-blacksmith .d-wall { background: linear-gradient(180deg, #2a1408 0%, #0a0402 100%) !important; }
.dungeon-stage.theme-barber .d-cell     { background: repeating-linear-gradient(0deg, #d8d0c8 0 14px, #c8c0b8 14px 28px); }
.dungeon-stage.theme-barber .d-wall     { background: linear-gradient(180deg, #6a4858 0%, #2a1828 100%) !important; }
.dungeon-stage.theme-stable .d-cell     { background: repeating-linear-gradient(0deg, #8a6a3a 0 14px, #7a5a2a 14px 28px); }
.dungeon-stage.theme-stable .d-wall     { background: linear-gradient(180deg, #4a2818 0%, #1a0a04 100%) !important; }
.dungeon-stage.theme-trainer .d-cell    { background: repeating-linear-gradient(45deg, #7a8a4a 0 14px, #6a7a3a 14px 28px); }
.dungeon-stage.theme-trainer .d-wall    { background: linear-gradient(180deg, #3a4818 0%, #1a2008 100%) !important; }
.dungeon-stage.theme-monk .d-cell       { background: repeating-linear-gradient(0deg, #c8a868 0 12px, #b89858 12px 24px); }
.dungeon-stage.theme-monk .d-wall       { background: linear-gradient(180deg, #4a3818 0%, #2a1808 100%) !important; }
.dungeon-stage.theme-inn .d-cell        { background: repeating-linear-gradient(0deg, rgba(0,0,0,0.2) 0 1px, transparent 1px 11px), #b48a52; }
.dungeon-stage.theme-inn .d-wall        { background: linear-gradient(180deg, #4a2810 0%, #1a0a04 100%) !important; }
.dungeon-stage.theme-house #dungeon-log,
.dungeon-stage.theme-apothecary #dungeon-log,
.dungeon-stage.theme-granary #dungeon-log,
.dungeon-stage.theme-lodge #dungeon-log,
.dungeon-stage.theme-tinker #dungeon-log,
.dungeon-stage.theme-farm #dungeon-log,
.dungeon-stage.theme-lumbermill #dungeon-log,
.dungeon-stage.theme-quarry #dungeon-log,
.dungeon-stage.theme-blacksmith #dungeon-log,
.dungeon-stage.theme-barber #dungeon-log,
.dungeon-stage.theme-stable #dungeon-log,
.dungeon-stage.theme-trainer #dungeon-log,
.dungeon-stage.theme-monk #dungeon-log,
.dungeon-stage.theme-inn #dungeon-log { color: #ffe788; }

/* Phase 35 — PK-authentic structure interiors */
.dungeon-stage.theme-cathedral .d-cell  { background: repeating-linear-gradient(0deg, rgba(255,255,255,0.08) 0 1px, transparent 1px 10px), linear-gradient(180deg, #d4c0a8 0%, #8a7a68 100%); }
.dungeon-stage.theme-cathedral .d-wall  { background: linear-gradient(180deg, #b89878 0%, #4a3818 100%) !important; }
.dungeon-stage.theme-magetower .d-cell  { background: repeating-linear-gradient(0deg, rgba(180,160,255,0.1) 0 1px, transparent 1px 8px), linear-gradient(180deg, #3a2a5a 0%, #1a0a2a 100%); }
.dungeon-stage.theme-magetower .d-wall  { background: linear-gradient(180deg, #1a0a3a 0%, #08001a 100%) !important; }
.dungeon-stage.theme-magetower #dungeon-log { color: #c8a8ff; }
.dungeon-stage.theme-library .d-cell    { background: repeating-linear-gradient(0deg, rgba(0,0,0,0.15) 0 1px, transparent 1px 12px), #a88858; }
.dungeon-stage.theme-library .d-wall    { background: linear-gradient(180deg, #4a3018 0%, #1a0a04 100%) !important; }
.dungeon-stage.theme-watchtower .d-cell { background: repeating-linear-gradient(0deg, #888888 0 12px, #6a6a6a 12px 24px); }
.dungeon-stage.theme-watchtower .d-wall { background: linear-gradient(180deg, #3a3a3a 0%, #1a1a1a 100%) !important; }
.d-door {
  background:
    repeating-linear-gradient(0deg, #aa7733 0 3px, #553311 3px 6px),
    #553311 !important;
  border: 1px solid #ffcc66 !important;
  cursor: pointer !important;
  animation: doorPulse 1.4s infinite;
}
@keyframes doorPulse {
  0%, 100% { box-shadow: inset 0 0 0 1px rgba(255,204,102,0.3); }
  50% { box-shadow: inset 0 0 8px rgba(255,204,102,0.7); }
}

#dungeon-overlay {
  position: absolute; inset: 0;
  pointer-events: none;
}
.d-sprite {
  position: absolute;
  pointer-events: auto;
  cursor: pointer;
  image-rendering: pixelated;
}
.d-sprite canvas { width: 100%; height: 100%; image-rendering: pixelated; }
.d-hp {
  position: absolute;
  left: 4px; top: -4px;
  width: calc(100% - 8px);
  height: 3px;
  background: #1a0a04;
  border: 1px solid #1a0a04;
  z-index: 1100;
}
.d-hp div { height: 100%; background: #5fd16e; }

#dungeon-log {
  margin-top: 6px;
  background: #1a0a04;
  border: 2px solid #6a3a18;
  padding: 6px 8px;
  max-height: 100px;
  overflow-y: auto;
  font-family: 'IM Fell English', serif;
  font-size: 12px;
  color: #aaff88;
}
.d-log { padding: 1px 0; }
.d-log.combat { color: #ff8888; }
.d-log.loot { color: #88ff88; }
.d-log.system { color: #88aaff; font-style: italic; }

/* ---- Tutorial overlay ---- */
#tutorial {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1500;
  pointer-events: auto;
  padding: 16px;
}
#tutorial.hidden { display: none; }
.tut-card {
  background:
    repeating-linear-gradient(0deg, rgba(0,0,0,0.04) 0 1px, transparent 1px 12px),
    linear-gradient(180deg, #f3dfb4 0%, #d8b884 100%);
  color: #2a1207;
  border: 4px solid #1a0a04;
  box-shadow: 0 0 0 2px #ad7a3c, 0 0 0 6px #1a0a04;
  width: 100%; max-width: 420px;
  border-radius: 8px;
  overflow: hidden;
}
.tut-header {
  display: flex; align-items: center; gap: 8px;
  background: linear-gradient(180deg, #6f3f1c 0%, #44210d 100%);
  color: #fce67d;
  padding: 8px 12px;
  border-bottom: 3px solid #1a0a04;
  font-family: 'Cinzel', serif;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-shadow: 1px 1px 0 #1a0a04;
}
#tut-step-num {
  background: #1a0a04;
  color: #fce67d;
  padding: 2px 8px;
  border-radius: 3px;
  font-size: 11px;
  flex: 0 0 auto;
}
#tut-title { flex: 1; font-size: 14px; }
#tut-skip {
  background: #4a1a1a;
  color: #fff;
  border: 2px solid #1a0a04;
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 1px;
  padding: 4px 10px;
  cursor: pointer;
  border-radius: 3px;
}
#tut-body {
  padding: 12px 16px;
  font-family: 'Georgia', serif;
  font-size: 14px;
  line-height: 1.6;
  color: #1a0a04;
}
#tut-body p { margin: 0 0 10px; }
#tut-body b { color: #6f3f1c; }
.tut-check {
  background: rgba(95, 209, 110, 0.2);
  border: 1px solid #2a8c2a;
  padding: 4px 8px;
  font-family: 'Cinzel', serif;
  font-size: 11px;
  color: #2a8c2a;
  border-radius: 3px;
  margin-top: 6px;
  font-weight: 700;
}
.tut-actions {
  display: flex; gap: 6px;
  padding: 10px 16px 14px;
  border-top: 2px solid #ad7a3c;
}
.tut-actions button {
  flex: 1;
  padding: 10px;
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 2px;
  background: linear-gradient(180deg, #ad7a3c 0%, #6a3a18 100%);
  color: #fce67d;
  border: 2px solid #1a0a04;
  cursor: pointer;
  border-radius: 4px;
  box-shadow: inset 0 0 0 1px #f3dfb4, 0 3px 0 #1a0a04;
  text-shadow: 1px 1px 0 #1a0a04;
}
.tut-actions button:active {
  transform: translateY(2px);
  box-shadow: inset 0 0 0 1px #f3dfb4, 0 1px 0 #1a0a04;
}
.tut-actions button.pulse {
  animation: tutPulse 1s infinite;
}
.tut-arrow {
  font-family: 'Cinzel', serif;
  font-size: 28px;
  font-weight: 900;
  color: #ffe788;
  text-shadow: 0 0 10px rgba(252,230,125,0.9), 2px 2px 0 #1a0a04;
  animation: arrowSlide 0.8s ease-in-out infinite alternate;
  pointer-events: none;
}
@keyframes arrowSlide {
  0%   { transform: translateX(0); }
  100% { transform: translateX(8px); }
}
@keyframes tutPulse {
  0%, 100% { box-shadow: inset 0 0 0 1px #f3dfb4, 0 3px 0 #1a0a04, 0 0 0 0 rgba(252, 230, 125, 0.5); }
  50% { box-shadow: inset 0 0 0 1px #f3dfb4, 0 3px 0 #1a0a04, 0 0 0 8px rgba(252, 230, 125, 0); }
}

/* ---- Active buff strip ---- */
#buff-strip {
  position: absolute;
  /* Pinned just under the HUD pills so it never overlaps the bottom action toolbar
     or the MORE popup that rises above it. */
  left: 12px;
  bottom: 140px;
  z-index: 550;
  display: flex; flex-wrap: wrap; gap: 4px;
  max-width: calc(100vw - 24px);
  pointer-events: none;
  transition: bottom 180ms ease-out, opacity 180ms ease-out;
}
/* Slide buff chips out of the way when the MORE popup is open */
body.menu-open #buff-strip { bottom: 290px; opacity: 0.6; }
.buff-chip {
  background: rgba(20, 8, 4, 0.92);
  border: 2px solid #5fd16e;
  border-radius: 4px;
  padding: 3px 7px;
  font-family: 'Cinzel', serif;
  font-weight: 700;
  font-size: 11px;
  color: #aaffaa;
  display: flex; align-items: center; gap: 4px;
  box-shadow: 0 2px 0 #1a0a04;
}
.buff-chip .buff-time { color: #ffe788; font-size: 10px; }
/* Recoil bounce on attack/chop/mine — purely visual */
/* Recoil keyframes — start at 0, animate to the offset, STAY there (forwards fill). */
@keyframes hero-recoil-up    { from { transform: translate(0, 0); } to { transform: translate(0, -18px); } }
@keyframes hero-recoil-down  { from { transform: translate(0, 0); } to { transform: translate(0,  18px); } }
@keyframes hero-recoil-left  { from { transform: translate(0, 0); } to { transform: translate(-18px, 0); } }
@keyframes hero-recoil-right { from { transform: translate(0, 0); } to { transform: translate( 18px, 0); } }
.sprite-icon canvas { will-change: transform; }
.sprite-icon.recoil-up    canvas:not(.eq-overlay) { animation: hero-recoil-up    160ms ease-out forwards; }
.sprite-icon.recoil-down  canvas:not(.eq-overlay) { animation: hero-recoil-down  160ms ease-out forwards; }
.sprite-icon.recoil-left  canvas:not(.eq-overlay) { animation: hero-recoil-left  160ms ease-out forwards; }
.sprite-icon.recoil-right canvas:not(.eq-overlay) { animation: hero-recoil-right 160ms ease-out forwards; }

.buff-chip.event-chip {
  animation: eventPulse 1.6s ease-in-out infinite;
  font-size: 10px;
  letter-spacing: 1px;
}
@keyframes eventPulse {
  0%, 100% { box-shadow: 0 2px 0 #1a0a04, 0 0 0 0 currentColor; }
  50%      { box-shadow: 0 2px 0 #1a0a04, 0 0 8px 2px currentColor; }
}

/* ---- Zoom controls ---- */
#zoom-controls {
  position: absolute;
  right: 8px;
  top: 60px;
  display: flex; flex-direction: column; gap: 4px;
  z-index: 600;
}
#zoom-controls button {
  width: 36px; height: 36px;
  font-family: 'Cinzel', serif;
  font-weight: 900;
  font-size: 18px;
  background:
    radial-gradient(circle at 30% 30%, #fce67d 0%, transparent 50%),
    linear-gradient(180deg, #d8a850 0%, #ad7a3c 50%, #6a3a18 100%);
  color: #2a1207;
  border: 2px solid #1a0a04;
  border-radius: 6px;
  box-shadow: inset 0 1px 0 rgba(255,240,180,0.7), 0 3px 0 #1a0a04;
  cursor: pointer;
}
#zoom-controls button:active { transform: translateY(2px); box-shadow: inset 0 1px 0 rgba(255,240,180,0.7), 0 1px 0 #1a0a04; }

/* ---- Toast stack (slide-in notifications) ---- */
#toast-stack {
  position: absolute;
  top: 90px; right: 12px;
  z-index: 800;
  display: flex; flex-direction: column; gap: 6px;
  pointer-events: none;
  max-width: 280px;
}
.toast {
  background:
    repeating-linear-gradient(0deg, rgba(0,0,0,0.18) 0 1px, transparent 1px 7px),
    linear-gradient(180deg, #2a1808 0%, #1a0a04 100%);
  border: 2px solid #ad7a3c;
  border-left: 4px solid #fce67d;
  padding: 6px 10px;
  font-family: 'Cinzel', serif;
  font-size: 12px;
  color: #ffe788;
  border-radius: 4px;
  animation: toastIn 0.4s cubic-bezier(.2,1,.4,1) forwards, toastOut 0.5s 4.5s forwards;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
  pointer-events: auto;
}
.toast.achievement { border-left-color: #5fd16e; }
.toast.levelup     { border-left-color: #c869b8; }
.toast.warning     { border-left-color: #e64f4f; }
.toast .toast-title { color: #ffe788; font-weight: 900; letter-spacing: 1px; }
.toast .toast-body  { color: #f5f0d6; font-family: 'Georgia', serif; font-size: 12px; margin-top: 2px; }
@keyframes toastIn  { from { transform: translateX(120%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes toastOut { from { transform: translateX(0); opacity: 1; } to { transform: translateX(120%); opacity: 0; } }

/* Big level-up banner */
#banner-host { position: absolute; top: 35%; left: 0; right: 0; z-index: 750; pointer-events: none; }
.level-banner {
  text-align: center;
  font-family: 'Cinzel', serif;
  font-weight: 900;
  font-size: 42px;
  letter-spacing: 6px;
  color: #fce67d;
  text-shadow: 0 0 20px rgba(252,230,125,0.8), 2px 2px 0 #1a0a04, 4px 4px 12px rgba(0,0,0,0.7);
  background: radial-gradient(ellipse at center, rgba(252,230,125,0.15) 0%, transparent 70%);
  padding: 20px;
  animation: bannerPop 2.2s ease-out forwards;
}
@keyframes bannerPop {
  0%   { transform: scale(0.4); opacity: 0; }
  20%  { transform: scale(1.1); opacity: 1; }
  35%  { transform: scale(1.0); opacity: 1; }
  85%  { transform: scale(1.0); opacity: 1; }
  100% { transform: scale(1.4); opacity: 0; }
}

/* Day/night map tint */
#map.tint-dawn .leaflet-tile-pane  { filter: brightness(0.95) saturate(1.1) sepia(0.18); }
#map.tint-day  .leaflet-tile-pane  { filter: none; }
#map.tint-dusk .leaflet-tile-pane  { filter: brightness(0.85) saturate(1.2) sepia(0.32) hue-rotate(-18deg); }
#map.tint-night .leaflet-tile-pane { filter: brightness(0.55) saturate(0.7) hue-rotate(195deg); }

/* ---- Mobile UX ---- */
@media (max-width: 600px) {
  #actions button { width: 64px; height: 48px; font-size: 12px; }
  #actions #btn-mute, #actions #btn-help, #actions #btn-fullscreen { width: 48px; height: 38px; font-size: 16px; }
  .hud-pill .pill-value { font-size: 17px; }
  .hud-pill .pill-label { font-size: 11px; }
  #zoom-controls button { width: 44px; height: 44px; font-size: 22px; }
  #chat-panel { width: calc(100vw - 100px); }
  .modal-card { max-width: 95% !important; }
  #log { width: 60% !important; }
}
@media (orientation: landscape) and (max-height: 600px) {
  #actions { gap: 3px; }
  #actions button { height: 36px; font-size: 11px; }
  #hud-bottom { padding: 4px 10px 6px; }
  .hud-pill { min-height: 30px; padding: 3px 6px; }
  #log { max-height: 22%; }
}

/* Connection status dot */
#player-status {
  position: absolute;
  top: 60px; left: 50%;
  transform: translateX(-50%);
  z-index: 600;
  background: rgba(26, 10, 4, 0.85);
  border: 1px solid #ad7a3c;
  padding: 3px 10px;
  font-family: 'IM Fell English', serif;
  font-size: 11px;
  color: #c8a878;
  display: flex; align-items: center; gap: 6px;
  border-radius: 3px;
}
#player-status .dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #e64f4f;
}
#player-status .dot.connected { background: #5fd16e; box-shadow: 0 0 4px #5fd16e; }
