/* ================================================================
   Earthen Realm — UI Stylesheet
   Fantasy / GPS theme: dark parchment, warm amber, earthy nature
   ================================================================ */

/* ---- Design tokens ---- */
:root {
  --bg-deep:       rgba(13, 8, 3, 0.94);
  --bg-panel:      rgba(20, 13, 6, 0.93);
  --bg-hover:      rgba(44, 26, 10, 0.96);
  --border:        rgba(130, 80, 22, 0.50);
  --border-hi:     rgba(195, 138, 40, 0.80);
  --text:          #dfc99a;
  --text-dim:      #8e7048;
  --text-bright:   #f0e0b4;
  --accent:        #c48a30;
  --accent-bright: #e0aa50;
  --radius:        5px;
  --shadow-panel:  0 4px 22px rgba(0,0,0,0.65);
  --inset-hi:      inset 0 0 0 1px rgba(255, 195, 80, 0.04);
  --font-body:     'Crimson Text', 'Palatino Linotype', Georgia, serif;
  --font-display:  'Cinzel', 'Palatino Linotype', Georgia, serif;
  --hud-h:         88px;
  --side-w:        228px;
  --side-w-col:    42px;
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; overflow: hidden; background: #080503; }

/* ---- Map: full-screen base ---- */
#map {
  position: fixed;
  inset: 0;
  z-index: 1;
}

/* ---- HUD overlay ---- */
#game-ui {
  position: fixed;
  inset: 0;
  z-index: 1000;
  pointer-events: none;
}
#game-ui > * { pointer-events: auto; }

/* ================================================================
   LEFT SIDE PANEL
   ================================================================ */
#hud-side {
  position: absolute;
  left: 0; top: 0;
  bottom: var(--hud-h);
  width: var(--side-w);
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  box-shadow: 2px 0 18px rgba(0,0,0,0.45), var(--inset-hi);
  transition: width 0.20s ease;
  overflow: hidden;
}

/* Collapsed state */
#hud-side.collapsed { width: var(--side-w-col); }
#hud-side.collapsed #hud-side-body { opacity: 0; visibility: hidden; }
#hud-side.collapsed .side-toggle-label { display: none; }
#hud-side.collapsed .side-toggle-arrow { transform: rotate(180deg); }

/* Toggle strip */
.side-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 12px;
  background: rgba(26, 15, 6, 0.85);
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  color: var(--accent);
  font-family: var(--font-display);
  font-size: 10px;
  letter-spacing: 2px;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.14s;
  white-space: nowrap;
  flex-shrink: 0;
}
.side-toggle:hover { background: rgba(46, 26, 10, 0.95); }
.side-toggle-arrow {
  font-size: 9px;
  transition: transform 0.20s;
  flex-shrink: 0;
}
.side-toggle-label { flex: 1; text-align: left; }

/* Scrollable body */
#hud-side-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.16s, visibility 0.16s;
}
#hud-side-body::-webkit-scrollbar { width: 3px; }
#hud-side-body::-webkit-scrollbar-track { background: transparent; }
#hud-side-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ---- Sections ---- */
.hud-section {
  padding: 10px 13px;
  border-bottom: 1px solid rgba(110, 65, 15, 0.22);
}
.hud-section:last-child { border-bottom: none; }

.hud-section-title {
  font-family: var(--font-display);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 9px;
}

/* ---- Inventory ---- */
.inv-grid { display: flex; flex-direction: column; gap: 2px; }
.inv-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 2px 0;
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--text);
}
.inv-ico { width: 19px; text-align: center; font-size: 13px; flex-shrink: 0; }
.inv-name { flex: 1; font-size: 13px; color: var(--text-dim); }
.inv-val {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-bright);
  min-width: 22px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.inv-val-food { font-size: 11px; }

/* ---- Character stats ---- */
.char-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 3px 14px;
  font-family: var(--font-body);
  font-size: 13px;
}
.char-key { color: var(--text-dim); }
.char-val { color: var(--text-bright); font-weight: 600; }

/* ---- Build grid ---- */
.build-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}

/* ================================================================
   BOTTOM HUD
   ================================================================ */
#hud-bottom {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: var(--hud-h);
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 22px rgba(0,0,0,0.55), var(--inset-hi);
  padding: 0 14px;
}

/* Vitals cluster */
#hud-vitals {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  padding: 8px 0;
  flex-shrink: 0;
  min-width: 270px;
}

.vital-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.vital-ico {
  width: 16px;
  text-align: center;
  font-size: 13px;
  flex-shrink: 0;
}
.vital-hp-ico      { color: #d04040; }
.vital-hunger-ico  { color: #c06820; }
.vital-stamina-ico { color: #30a050; }

.vital-bar-bg {
  flex: 1;
  height: 11px;
  background: rgba(0,0,0,0.45);
  border-radius: 5px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.05);
  min-width: 100px;
  max-width: 180px;
}
.vital-bar {
  height: 100%;
  border-radius: 5px;
  transition: width 0.30s ease;
}
.vital-bar-hp {
  background: linear-gradient(90deg, #801818 0%, #c02828 100%);
  box-shadow: 0 0 5px rgba(180, 30, 30, 0.35);
}
.vital-bar-hunger {
  background: linear-gradient(90deg, #803000 0%, #be5800 100%);
  box-shadow: 0 0 5px rgba(180, 90, 0, 0.35);
}
.vital-bar-stamina {
  background: linear-gradient(90deg, #144e20 0%, #208538 100%);
  box-shadow: 0 0 5px rgba(30, 140, 50, 0.35);
}
.vital-val {
  width: 54px;
  text-align: right;
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Vertical divider */
.hud-vdiv {
  width: 1px;
  height: 54px;
  background: var(--border);
  margin: 0 14px;
  flex-shrink: 0;
}

/* Actions */
#hud-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ================================================================
   TOP-RIGHT UTILITIES
   ================================================================ */
#hud-util {
  position: absolute;
  top: 10px; right: 10px;
  display: flex;
  gap: 6px;
}

/* ================================================================
   BUTTONS
   ================================================================ */
.er-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: linear-gradient(180deg, #3c2310 0%, #221206 100%);
  border: 1px solid var(--border);
  border-bottom-color: rgba(70, 38, 8, 0.8);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  text-shadow: 0 1px 2px rgba(0,0,0,0.55);
  box-shadow: 0 2px 7px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,190,70,0.07);
  transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
  white-space: nowrap;
  line-height: 1.2;
  user-select: none;
}
.er-btn:hover:not(:disabled) {
  background: linear-gradient(180deg, #5a3318 0%, #3c2310 100%);
  border-color: var(--border-hi);
  color: var(--text-bright);
  box-shadow: 0 2px 10px rgba(195,135,35,0.20), inset 0 1px 0 rgba(255,190,70,0.10);
}
.er-btn:active:not(:disabled) {
  transform: translateY(1px);
  box-shadow: 0 1px 3px rgba(0,0,0,0.45);
}
.er-btn:disabled {
  opacity: 0.36;
  cursor: not-allowed;
}
.er-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Small (build grid) */
.er-btn-sm {
  font-size: 12px;
  padding: 5px 7px;
  gap: 3px;
  justify-content: flex-start;
}

/* Action bar */
.er-btn-action {
  font-size: 14px;
  padding: 8px 18px;
}

/* Icon-only (utility bar) */
.er-btn-icon {
  padding: 6px 10px;
  font-size: 15px;
  gap: 0;
  min-width: 34px;
  justify-content: center;
}

/* Full-width (character panel) */
.er-btn-block {
  width: 100%;
  justify-content: center;
  font-size: 13px;
  padding: 6px 10px;
}

/* Accent (claim tile) */
.er-btn-claim {
  border-color: rgba(170, 120, 35, 0.65);
  background: linear-gradient(180deg, #46300c 0%, #2a1c06 100%);
}
.er-btn-claim:hover:not(:disabled) {
  border-color: #e8ae40;
  background: linear-gradient(180deg, #664618 0%, #46300c 100%);
}

/* ================================================================
   TOAST
   ================================================================ */
#game-toast {
  position: fixed;
  bottom: calc(var(--hud-h) + 16px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-deep);
  border: 1px solid var(--border-hi);
  color: var(--text-bright);
  padding: 9px 22px;
  border-radius: 18px;
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  z-index: 3000;
  box-shadow: 0 4px 18px rgba(0,0,0,0.55), 0 0 0 1px rgba(195,138,40,0.12);
  opacity: 0;
  transition: opacity 0.28s;
  pointer-events: none;
  white-space: nowrap;
  max-width: 80vw;
  text-align: center;
}

/* Active food-buff badge — top-center pill with a live countdown */
#hud-buff {
  position: fixed;
  top: 10px; left: 50%;
  transform: translateX(-50%);
  display: none;
  background: linear-gradient(180deg, rgba(36,52,28,0.95), rgba(22,34,16,0.95));
  border: 1px solid rgba(120,180,90,0.5);
  color: #cfe8b8;
  padding: 5px 14px;
  border-radius: 16px;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  z-index: 2400;
  pointer-events: none;
  box-shadow: 0 3px 12px rgba(0,0,0,0.5);
  white-space: nowrap;
}

/* ================================================================
   CIRCULAR GATHER TIMER
   ================================================================ */
#circular-timer {
  position: fixed;
  left: 50%;
  bottom: calc(var(--hud-h) + 18px);
  transform: translateX(-50%);
  z-index: 2500;
  pointer-events: none;
  display: none;
  filter: drop-shadow(0 3px 10px rgba(0,0,0,0.7));
}

/* ================================================================
   MODALS (vendor, quest-log, eat, npc dialogue)
   ================================================================ */
#vendor-modal,
#quest-log-modal,
#eat-modal,
#npc-modal {
  background: linear-gradient(175deg, rgba(24,15,7,0.97) 0%, rgba(16,9,3,0.98) 100%) !important;
  border: 1px solid var(--border-hi) !important;
  border-radius: 8px !important;
  color: var(--text) !important;
  padding: 18px 22px !important;
  min-width: 340px !important;
  max-width: 500px !important;
  max-height: 76vh !important;
  overflow-y: auto !important;
  z-index: 5000 !important;
  box-shadow: 0 10px 36px rgba(0,0,0,0.75), 0 0 0 1px rgba(195,138,40,0.08) !important;
  font-family: var(--font-body) !important;
  font-size: 14px !important;
}
#vendor-modal::-webkit-scrollbar,
#quest-log-modal::-webkit-scrollbar,
#eat-modal::-webkit-scrollbar,
#npc-modal::-webkit-scrollbar { width: 4px; }
#vendor-modal::-webkit-scrollbar-thumb,
#quest-log-modal::-webkit-scrollbar-thumb,
#eat-modal::-webkit-scrollbar-thumb,
#npc-modal::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* Modal close buttons */
#vendor-modal-close,
#quest-log-close,
#eat-close,
#npc-modal-close {
  background: none !important;
  border: none !important;
  color: var(--text-dim) !important;
  font-size: 20px !important;
  cursor: pointer !important;
  padding: 0 2px !important;
  line-height: 1 !important;
  transition: color 0.12s !important;
}
#vendor-modal-close:hover,
#quest-log-close:hover,
#eat-close:hover,
#npc-modal-close:hover { color: var(--text-bright) !important; }

/* Modal title row */
#vendor-modal > div:first-child strong,
#quest-log-modal > div:first-child strong {
  font-family: var(--font-display) !important;
  font-size: 15px !important;
  color: var(--accent-bright) !important;
  letter-spacing: 1px !important;
}

/* ---- Generic modal buttons (vendor, eat, quest, npc) ---- */
#vendor-modal-body button,
#quest-log-body button,
#eat-list button,
#npc-modal-body button {
  background: linear-gradient(180deg, #3c2310 0%, #221206 100%);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  padding: 5px 13px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  margin: 0;
}
#vendor-modal-body button:hover:not(:disabled),
#quest-log-body button:hover:not(:disabled),
#eat-list button:hover:not(:disabled),
#npc-modal-body button:hover:not(:disabled) {
  background: linear-gradient(180deg, #5a3318 0%, #3c2310 100%);
  border-color: var(--border-hi);
  color: var(--text-bright);
}
#vendor-modal-body button:disabled,
#eat-list button:disabled,
#npc-modal-body button:disabled { opacity: 0.38; cursor: not-allowed; }

/* Inputs in modals */
#vendor-modal-body input,
#eat-list input {
  background: rgba(8,4,1,0.85);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-bright);
  padding: 4px 7px;
  font-family: var(--font-body);
  font-size: 13px;
  outline: none;
}
#vendor-modal-body input:focus,
#eat-list input:focus { border-color: var(--border-hi); }

/* ================================================================
   LOGIN FORM
   ================================================================ */
#login-box {
  background: rgba(6, 3, 1, 0.80) !important;
  backdrop-filter: blur(5px) !important;
}
#login-form {
  background: linear-gradient(175deg, rgba(28,17,7,0.98) 0%, rgba(18,10,4,0.98) 100%) !important;
  border: 1px solid var(--border-hi) !important;
  border-radius: 10px !important;
  color: var(--text) !important;
  box-shadow: 0 14px 44px rgba(0,0,0,0.80) !important;
  gap: 12px !important;
  min-width: 300px !important;
  font-family: var(--font-body) !important;
  padding: 2rem 2.5rem !important;
}
#login-form h2 {
  color: var(--accent-bright) !important;
  font-family: var(--font-display) !important;
  font-size: 20px !important;
  letter-spacing: 3px !important;
  text-transform: uppercase !important;
  margin: 0 0 4px !important;
  text-align: center !important;
  text-shadow: 0 2px 10px rgba(195,140,40,0.28) !important;
}
#login-form input[type="text"],
#login-form input[type="password"] {
  background: rgba(8,4,1,0.82) !important;
  border: 1px solid var(--border) !important;
  border-radius: 4px !important;
  color: var(--text-bright) !important;
  padding: 9px 12px !important;
  font-family: var(--font-body) !important;
  font-size: 15px !important;
  outline: none !important;
  transition: border-color 0.15s !important;
  width: 100% !important;
}
#login-form input:focus {
  border-color: var(--border-hi) !important;
  box-shadow: 0 0 0 2px rgba(195,138,40,0.13) !important;
}
#login-form input::placeholder { color: var(--text-dim) !important; }
#login-btn, #register-btn, #guest-btn {
  background: linear-gradient(180deg, #3c2310 0%, #221206 100%) !important;
  border: 1px solid var(--border-hi) !important;
  color: var(--text) !important;
  font-family: var(--font-body) !important;
  font-size: 14px !important;
  font-weight: 600 !important;
  padding: 8px 14px !important;
  border-radius: var(--radius) !important;
  cursor: pointer !important;
  transition: background 0.12s !important;
}
#login-btn:hover, #register-btn:hover, #guest-btn:hover {
  background: linear-gradient(180deg, #5a3318 0%, #3c2310 100%) !important;
  color: var(--text-bright) !important;
}
#login-error { color: #d04040 !important; font-size: 13px !important; text-align: center !important; min-height: 16px !important; }

/* ================================================================
   LEAFLET POPUP OVERRIDES
   ================================================================ */
.leaflet-popup-content-wrapper {
  background: linear-gradient(175deg, rgba(24,15,7,0.97) 0%, rgba(16,9,3,0.97) 100%);
  color: var(--text);
  border: 1px solid var(--border-hi);
  border-radius: var(--radius);
  box-shadow: 0 6px 24px rgba(0,0,0,0.65);
  font-family: var(--font-body);
  font-size: 14px;
}
.leaflet-popup-tip { background: rgba(18, 10, 4, 0.97); }
.leaflet-popup-close-button { color: var(--text-dim) !important; font-size: 17px !important; font-weight: 400 !important; }
.leaflet-popup-close-button:hover { color: var(--text-bright) !important; }
.leaflet-popup-content { margin: 11px 13px; line-height: 1.5; }

/* Buttons inside popups */
.leaflet-popup-content button,
.building-popup button,
.inn-popup button,
.storage-popup button {
  background: linear-gradient(180deg, #3c2310 0%, #221206 100%);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  margin: 0;
  transition: background 0.12s, border-color 0.12s;
  display: inline-block;
}
.leaflet-popup-content button:hover:not(:disabled),
.building-popup button:hover:not(:disabled),
.inn-popup button:hover:not(:disabled),
.storage-popup button:hover:not(:disabled) {
  background: linear-gradient(180deg, #5a3318 0%, #3c2310 100%);
  border-color: var(--border-hi);
  color: var(--text-bright);
}
.leaflet-popup-content button:disabled,
.building-popup button:disabled { opacity: 0.38; cursor: not-allowed; }

/* Destructive demolish control — muted red, set off from the other actions */
.building-demolish-row { margin-top: 9px; padding-top: 7px; border-top: 1px solid rgba(110,60,10,0.28); }
.leaflet-popup-content button.building-demolish {
  background: linear-gradient(180deg, #4a1818 0%, #2a0e0e 100%);
  border-color: rgba(150,60,50,0.55);
  color: #e6b0a6;
  font-size: 12px;
  padding: 4px 10px;
}
.leaflet-popup-content button.building-demolish:hover:not(:disabled) {
  background: linear-gradient(180deg, #6a2020 0%, #4a1818 100%);
  border-color: #b85a4a;
  color: #ffd8cf;
}

/* Inputs in popups */
.leaflet-popup-content input,
.shop-popup input,
.storage-popup input {
  background: rgba(8,4,1,0.85);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-bright);
  padding: 4px 7px;
  font-family: var(--font-body);
  font-size: 13px;
  outline: none;
}
.leaflet-popup-content input:focus,
.shop-popup input:focus,
.storage-popup input:focus { border-color: var(--border-hi); }

/* Tile (claimed land) popup */
.tile-popup { min-width: 150px; }
.tile-title {
  font-family: var(--font-display);
  font-size: 14px;
  color: var(--accent-bright);
  letter-spacing: 0.5px;
  margin-bottom: 3px;
}
.tile-meta { color: var(--text); font-size: 13px; }
.tile-cost { color: var(--text-dim); font-size: 13px; margin: 5px 0 7px; }
.tile-upgrade { width: 100%; }

/* Workshop gear-repair section */
.repair-section { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--border); }
.repair-title {
  font-family: var(--font-display); font-size: 12px; letter-spacing: 1px;
  text-transform: uppercase; color: var(--accent); margin-bottom: 5px;
}
.repair-empty { color: var(--text-dim); font-size: 13px; font-style: italic; }
.repair-row { padding: 5px 0; border-bottom: 1px solid rgba(110,60,10,0.18); }
.repair-row:last-child { border-bottom: none; }
.repair-row-name { color: var(--text-bright); font-size: 13px; }
.repair-dur { color: var(--text-dim); font-size: 11px; font-variant-numeric: tabular-nums; }
.repair-eq-tag { color: var(--text-dim); font-size: 11px; }
.repair-row-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 3px; }
.repair-cost { color: var(--text-dim); font-size: 12px; }

/* Leaflet draw toolbar */
.leaflet-draw-toolbar a { background-color: rgba(20,13,6,0.90); }

/* ================================================================
   BUILDING POPUP
   ================================================================ */
.building-popup { min-width: 180px; }
.building-title {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  color: var(--accent-bright);
  margin-bottom: 5px;
}
.building-level { font-size: 12px; color: var(--text-dim); margin-bottom: 2px; }
.building-stored { font-size: 13px; color: var(--text); margin-bottom: 6px; }
.building-actions { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 7px; }

/* ================================================================
   COOKING POPUP
   ================================================================ */
.cooking-popup { min-width: 220px; }
.cooking-title {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  color: var(--accent-bright);
  margin-bottom: 8px;
}
.cook-recipe { padding: 6px 0; border-bottom: 1px solid rgba(110,60,10,0.28); }
.cook-recipe:last-child { border-bottom: none; }
.cook-recipe-title { font-weight: 600; font-size: 13px; color: var(--text-bright); }
.cook-recipe-detail { font-size: 12px; color: var(--text-dim); margin-bottom: 4px; }
.cook-status { font-size: 12px; color: var(--text); }
.cook-remaining { margin: 4px 0; font-style: italic; color: var(--text-dim); font-size: 12px; }
.cook-locked-head { margin: 9px 0 3px; font-size: 10px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--text-dim); opacity: 0.7; }
.cook-locked { font-size: 12px; color: var(--text-dim); opacity: 0.6; border-bottom: none; padding: 3px 0; }

/* ================================================================
   SHOP POPUP
   ================================================================ */
.shop-popup { min-width: 234px; max-width: 290px; }
.shop-title {
  font-family: var(--font-display);
  font-weight: 600;
  margin-bottom: 8px;
  font-size: 14px;
  color: var(--accent-bright);
}
.shop-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 0;
  border-bottom: 1px solid rgba(110,60,10,0.22);
  font-size: 13px;
}
.shop-row:last-child { border-bottom: none; }
.shop-list-form { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }

/* ================================================================
   INN POPUP
   ================================================================ */
.inn-popup { min-width: 200px; }
.inn-title {
  font-family: var(--font-display);
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--accent-bright);
  font-size: 14px;
}
.inn-blurb { color: var(--text-dim); font-size: 13px; margin-bottom: 10px; font-style: italic; }
.inn-action { margin-top: 4px; }
.inn-owner-note { color: var(--text-dim); font-size: 12px; margin-top: 7px; font-style: italic; }

/* ================================================================
   STORAGE POPUP
   ================================================================ */
.storage-popup { min-width: 250px; }
.storage-title {
  font-family: var(--font-display);
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--accent-bright);
  font-size: 14px;
}
.storage-section {
  margin: 8px 0;
  padding-top: 8px;
  border-top: 1px solid rgba(110,60,10,0.22);
}
.storage-section:first-child { border-top: none; padding-top: 0; }
.storage-section-title {
  font-weight: 600;
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
}

/* ================================================================
   VENDOR MODAL ROWS
   ================================================================ */
.vendor-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid rgba(110,60,10,0.22);
  font-size: 13px;
}
.vendor-row:last-child { border-bottom: none; }

/* ================================================================
   QUEST NPC DIALOGUE
   ================================================================ */
.npc-quest-row { padding: 9px 0; border-bottom: 1px solid rgba(110,60,10,0.22); }
.npc-quest-row:last-child { border-bottom: none; }
.npc-quest-title { font-weight: 600; color: var(--text-bright); font-size: 14px; }
.npc-quest-desc { color: var(--text-dim); font-size: 13px; margin: 3px 0; }
.npc-quest-meta { color: var(--text-dim); font-size: 12px; }
.npc-quest-action { margin-top: 5px; }
.npc-progress { color: var(--text-dim); font-style: italic; font-size: 13px; }
/* Level-gated / chain-locked quests: shown but not yet acceptable. */
.npc-quest-locked { opacity: 0.55; }
.npc-locked { color: #c9a23a; font-size: 12px; font-style: italic; }

/* ================================================================
   QUEST LOG (modal)
   ================================================================ */
.quest-log-row { padding: 11px 0; border-bottom: 1px solid rgba(110,60,10,0.22); }
.quest-log-row:last-child { border-bottom: none; }
.quest-log-title { font-weight: 600; color: var(--text-bright); font-size: 14px; }
.quest-log-desc { color: var(--text-dim); font-size: 13px; margin: 3px 0 8px; }
.quest-log-bar-bg {
  height: 7px;
  background: rgba(0,0,0,0.42);
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.04);
}
.quest-log-bar {
  height: 100%;
  background: linear-gradient(90deg, #8a5e00, #c09010);
  transition: width 0.3s;
}
.quest-log-meta { color: var(--text-dim); font-size: 12px; margin-top: 4px; }
.quest-log-actions { margin-top: 7px; }
.quest-badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 9px;
  font-size: 10px;
  margin-left: 6px;
  vertical-align: middle;
}
.quest-badge-active { background: rgba(30,45,90,0.55); color: #88a8ff; border: 1px solid rgba(90,120,210,0.38); }
.quest-badge-done   { background: rgba(18,54,18,0.55); color: #80e880; border: 1px solid rgba(70,168,70,0.38); }

/* Daily board */
.daily-streak-badge { font-size: 11px; color: #f0b048; font-weight: 600; margin-left: 6px; }
.daily-claim {
  background: linear-gradient(180deg, #46300c, #2a1c06);
  border: 1px solid rgba(170,120,35,0.65);
  color: var(--text-bright);
  font-family: var(--font-body);
  font-size: 13px;
  padding: 5px 14px;
  border-radius: var(--radius);
  cursor: pointer;
}
.daily-claim:hover:not(:disabled) { border-color: #e8ae40; }
.daily-claim:disabled { opacity: 0.45; cursor: not-allowed; }

/* ================================================================
   ANIMAL MARKERS
   ================================================================ */
.animal-icon { position: relative; text-align: center; }
.animal-icon .animal-hp {
  position: absolute; top: -18px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.78); color: var(--text);
  padding: 1px 5px; border-radius: 3px;
  font-size: 10px; white-space: nowrap;
  border: 1px solid rgba(255,255,255,0.08);
  font-family: var(--font-body);
}
.animal-icon .animal-body {
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid rgba(0,0,0,0.55);
  box-shadow: 0 2px 8px rgba(0,0,0,0.45);
}
.animal-icon .animal-emoji { font-size: 17px; }
.animal-icon.animal-hit .animal-body {
  animation: animalHitFlash 0.24s ease;
}
@keyframes animalHitFlash {
  0%   { filter: brightness(3) saturate(0); transform: translateX(0); }
  30%  { transform: translateX(-4px); }
  55%  { transform: translateX(4px); }
  80%  { transform: translateX(-2px); }
  100% { filter: brightness(1) saturate(1); transform: translateX(0); }
}


/* ================================================================
   RESOURCE MARKERS
   ================================================================ */
.resource-cooldown { position: relative; text-align: center; }
.resource-cooldown .resource-cooldown-label {
  position: absolute; top: -26px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.78); color: var(--text);
  padding: 2px 5px; border-radius: 3px;
  font-size: 10px; white-space: nowrap;
  border: 1px solid rgba(255,255,255,0.07);
  font-family: var(--font-body);
}
.resource-cooldown .resource-cooldown-img {
  width: 32px; height: 32px;
  opacity: 0.32; filter: grayscale(1);
}
.resource-node { display: flex; align-items: center; justify-content: center; }
.resource-node-core {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid rgba(0,0,0,0.5);
  background: #7a8870;
  box-shadow: 0 2px 6px rgba(0,0,0,0.35);
}
.resource-iron .resource-node-core {
  background: radial-gradient(circle at 30% 30%, #c8d4da, #384e5c);
  border-color: #1c2e38;
}
.resource-herbs .resource-node-core {
  background: radial-gradient(circle at 30% 30%, #a8f0a0, #26682a);
  border-color: #164418;
}
.resource-berry_bush .resource-node-core {
  background: radial-gradient(circle at 30% 30%, #f0a0cc, #841e5e);
  border-color: #560e3e;
}
.resource-mithril .resource-node-core {
  background: radial-gradient(circle at 30% 30%, #e6faff, #4a8fb0);
  border-color: #2a5a72;
}
.resource-fishing_spot .resource-node-core {
  background: radial-gradient(circle at 30% 30%, #bfeaff, #1f6f9e);
  border-color: #134a6b;
}

/* ================================================================
   VENDOR MARKERS
   ================================================================ */
.vendor-icon { position: relative; text-align: center; }
.vendor-icon .vendor-body {
  width: 36px; height: 36px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #f8e080, #be7c18);
  border: 2px solid rgba(115,74,14,0.85);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 3px 10px rgba(0,0,0,0.45);
}
.vendor-icon .vendor-emoji { font-size: 19px; }

/* ================================================================
   QUEST NPC MARKERS
   ================================================================ */
.questnpc-icon { position: relative; text-align: center; }
.questnpc-icon .questnpc-body {
  width: 36px; height: 36px; border-radius: 50%;
  border: 2px solid rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 3px 10px rgba(0,0,0,0.45);
}
.questnpc-icon .questnpc-emoji { font-size: 19px; }
.questnpc-icon .questnpc-mark {
  position: absolute; top: -10px; right: -5px;
  background: #e0b818; color: #1a1000;
  width: 17px; height: 17px; border-radius: 50%;
  font-weight: 900; font-size: 12px;
  line-height: 15px; text-align: center;
  border: 1.5px solid rgba(0,0,0,0.4);
  box-shadow: 0 2px 6px rgba(0,0,0,0.45);
  animation: questPulse 1.7s ease-in-out infinite;
}
@keyframes questPulse {
  0%, 100% { transform: scale(1); box-shadow: 0 2px 6px rgba(0,0,0,0.45); }
  50%       { transform: scale(1.22); box-shadow: 0 2px 12px rgba(230,190,20,0.5); }
}

/* ================================================================
   BUILDING MARKERS
   ================================================================ */
.building-icon { position: relative; text-align: center; }
.building-icon .building-body {
  width: 34px; height: 34px; border-radius: 8px;
  background: radial-gradient(circle at 35% 30%, #b7855a, #6e4626);
  border: 2px solid rgba(45,28,12,0.85);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 3px 10px rgba(0,0,0,0.45);
}
.building-icon .building-emoji { font-size: 18px; line-height: 1; }

/* ================================================================
   PLAYER ICON
   ================================================================ */
.custom-player-icon { position: relative; text-align: center; }
.custom-player-icon .player-name {
  position: absolute; top: -20px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.78); color: var(--text);
  padding: 2px 6px; border-radius: 3px;
  font-size: 11px; white-space: nowrap;
  border: 1px solid rgba(255,255,255,0.07);
  font-family: var(--font-body);
}

/* ================================================================
   DAMAGE FLOATERS
   ================================================================ */
.damage-float {
  position: absolute;
  z-index: 2500;
  pointer-events: none;
  color: #f0cc50;
  font-weight: 700;
  font-size: 15px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.75), 0 0 8px rgba(240,190,0,0.35);
  transform: translate(-50%, -50%);
  animation: damage-float 0.85s ease-out forwards;
  font-family: var(--font-body);
}
@keyframes damage-float {
  0%   { opacity: 1; transform: translate(-50%, -50%) translateY(0); }
  100% { opacity: 0; transform: translate(-50%, -50%) translateY(-26px); }
}

/* ================================================================
   INVENTORY (Bag) modal
   ================================================================ */
#inventory-modal {
  background: linear-gradient(175deg, rgba(24,15,7,0.97) 0%, rgba(16,9,3,0.98) 100%);
  border: 1px solid var(--border-hi);
  border-radius: 8px;
  color: var(--text);
  padding: 18px 22px;
  width: 460px;
  max-width: 92vw;
  max-height: 80vh;
  overflow-y: auto;
  z-index: 5000;
  box-shadow: 0 10px 36px rgba(0,0,0,0.75), 0 0 0 1px rgba(195,138,40,0.08);
  font-family: var(--font-body);
  font-size: 14px;
}
#inventory-modal::-webkit-scrollbar { width: 4px; }
#inventory-modal::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
#inventory-modal > div:first-child strong {
  font-family: var(--font-display);
  font-size: 15px;
  color: var(--accent-bright);
  letter-spacing: 1px;
}
#inventory-close {
  background: none; border: none; color: var(--text-dim);
  font-size: 20px; cursor: pointer; padding: 0 2px; line-height: 1;
  transition: color 0.12s;
}
#inventory-close:hover { color: var(--text-bright); }

.inv-cat { margin-bottom: 14px; }
.inv-cat-title {
  font-family: var(--font-display);
  font-size: 12px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
  margin-bottom: 6px;
}

/* Equipment slot rows */
.inv-eq-row {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 0; border-bottom: 1px solid rgba(110,60,10,0.18);
}
.inv-eq-row:last-of-type { border-bottom: none; }
.inv-eq-slot {
  flex: 0 0 58px; color: var(--text-dim);
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px;
}
.inv-eq-name { flex: 1 1 auto; color: var(--text-bright); }
.inv-eq-stat { color: var(--text-dim); font-size: 12px; }
.inv-eq-empty .inv-eq-name { color: var(--text-dim); font-style: italic; }
.inv-eq-summary {
  margin-top: 7px; padding-top: 6px;
  border-top: 1px solid var(--border);
  color: var(--text); font-size: 13px;
}

/* Item rows */
.inv-item-row {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 0;
}
.inv-item-ico { flex: 0 0 20px; text-align: center; }
.inv-item-name { flex: 1 1 auto; color: var(--text-bright); }
.inv-item-qty { color: var(--text-dim); font-size: 13px; }
.inv-item-actions { flex: 0 0 auto; display: flex; gap: 5px; }

/* Buttons inside the bag */
#inventory-body button {
  background: linear-gradient(180deg, #3c2310 0%, #221206 100%);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
#inventory-body button:hover:not(:disabled) {
  background: linear-gradient(180deg, #5a3318 0%, #3c2310 100%);
  border-color: var(--border-hi);
  color: var(--text-bright);
}
#inventory-body button:disabled { opacity: 0.4; cursor: not-allowed; }

/* Durability bars (equipment panel + gear rows) */
.inv-dur { display: inline-flex; align-items: center; gap: 6px; flex: 1 1 90px; min-width: 80px; }
.inv-dur-bar-bg {
  flex: 1; height: 6px; background: rgba(0,0,0,0.45);
  border-radius: 4px; overflow: hidden; border: 1px solid rgba(255,255,255,0.05);
}
.inv-dur-bar { display: block; height: 100%; transition: width 0.3s; }
.inv-dur-ok     .inv-dur-bar { background: linear-gradient(90deg, #144e20, #208538); }
.inv-dur-mid    .inv-dur-bar { background: linear-gradient(90deg, #8a5e00, #c09010); }
.inv-dur-low    .inv-dur-bar { background: linear-gradient(90deg, #803000, #be5800); }
.inv-dur-broken .inv-dur-bar { background: linear-gradient(90deg, #801818, #c02828); }
.inv-dur-val { flex: 0 0 auto; font-size: 11px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.inv-broken-tag { color: #c8504a; font-size: 11px; }
.inv-eq-broken .inv-eq-name { color: #c87878; }

/* ================================================================
   MONOLITHS modal (name + teleport)
   ================================================================ */
#monolith-modal {
  background: linear-gradient(175deg, rgba(24,15,7,0.97) 0%, rgba(16,9,3,0.98) 100%);
  border: 1px solid var(--border-hi);
  border-radius: 8px;
  color: var(--text);
  padding: 18px 22px;
  width: 420px;
  max-width: 92vw;
  max-height: 80vh;
  overflow-y: auto;
  z-index: 5000;
  box-shadow: 0 10px 36px rgba(0,0,0,0.75), 0 0 0 1px rgba(195,138,40,0.08);
  font-family: var(--font-body);
  font-size: 14px;
}
#monolith-modal > div:first-child strong {
  font-family: var(--font-display); font-size: 15px; color: var(--accent-bright); letter-spacing: 1px;
}
#monolith-close {
  background: none; border: none; color: var(--text-dim);
  font-size: 20px; cursor: pointer; padding: 0 2px; line-height: 1; transition: color 0.12s;
}
#monolith-close:hover { color: var(--text-bright); }
.monolith-cd { font-size: 12px; color: var(--text-dim); margin-bottom: 10px; }
.monolith-cd-ready { color: #80c878; }
.monolith-row { padding: 9px 0; border-bottom: 1px solid rgba(110,60,10,0.22); }
.monolith-row:last-child { border-bottom: none; }
.monolith-name-line { display: flex; align-items: center; gap: 6px; }
.monolith-lvl { flex: 0 0 auto; font-size: 11px; color: var(--text-dim); }
.monolith-name {
  flex: 1 1 auto; min-width: 0; background: rgba(8,4,1,0.85);
  border: 1px solid var(--border); border-radius: 3px; color: var(--text-bright);
  padding: 4px 7px; font-family: var(--font-body); font-size: 13px; outline: none;
}
.monolith-name:focus { border-color: var(--border-hi); }
.monolith-row-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 5px; }
.monolith-where { color: var(--text-dim); font-size: 12px; }
#monolith-body button {
  background: linear-gradient(180deg, #3c2310 0%, #221206 100%);
  border: 1px solid var(--border); color: var(--text);
  font-family: var(--font-body); font-size: 12px; font-weight: 600;
  padding: 4px 11px; border-radius: var(--radius); cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
#monolith-body button:hover:not(:disabled) {
  background: linear-gradient(180deg, #5a3318 0%, #3c2310 100%);
  border-color: var(--border-hi); color: var(--text-bright);
}
#monolith-body button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ================================================================
   POPUP SCROLL (long building/workshop popups)
   ================================================================ */
/* Leaflet adds .leaflet-popup-scrolled + inline max-height when the popup's
   maxHeight option is set; this just themes the scrollbar to match. */
.leaflet-popup-scrolled {
  overflow-y: auto;
  padding-right: 4px;
}
.leaflet-popup-scrolled::-webkit-scrollbar { width: 5px; }
.leaflet-popup-scrolled::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ================================================================
   PLAYER DAMAGE FEEDBACK (shake + vignette + marker flash)
   ================================================================ */
/* Brief screen shake of the map world on taking a hit. */
.screen-shake { animation: screen-shake 0.30s cubic-bezier(.36,.07,.19,.97); }
@keyframes screen-shake {
  0%, 100% { transform: translate(0, 0); }
  15%      { transform: translate(-5px, 3px); }
  30%      { transform: translate(5px, -3px); }
  45%      { transform: translate(-4px, -2px); }
  60%      { transform: translate(4px, 2px); }
  80%      { transform: translate(-2px, 1px); }
}

/* Red edge vignette pulse. Sits above the map, below interactive HUD. */
#damage-vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1500;
  opacity: 0;
  box-shadow: inset 0 0 120px 30px rgba(170, 10, 10, 0.0);
  background: radial-gradient(ellipse at center,
    rgba(140,0,0,0) 55%, rgba(150,5,5,0.42) 100%);
}
#damage-vignette.active { animation: damage-vignette 0.42s ease-out; }
@keyframes damage-vignette {
  0%   { opacity: 0; }
  25%  { opacity: 1; }
  100% { opacity: 0; }
}

/* Flash the player marker red briefly (filter only — keeps Leaflet's
   positioning transform intact). */
.player-hit {
  animation: player-hit 0.34s ease;
}
@keyframes player-hit {
  0%, 100% { filter: none; }
  30%      { filter: brightness(1.6) sepia(1) saturate(6) hue-rotate(-35deg); }
}

/* ================================================================
   MOBILE / NARROW VIEWPORTS  (everything here is gated to small
   screens — desktop layout above is untouched)
   ================================================================ */
@media (max-width: 640px) {
  /* Taller bottom HUD so vitals + actions stack instead of overflowing. All
     bottom-anchored offsets read --hud-h, so they follow automatically. */
  :root { --hud-h: 116px; }

  /* Left panel becomes an overlay drawer: a thin toggle strip by default
     (JS collapses it on load for small screens), opening over the map. */
  #hud-side { width: min(82vw, 290px); box-shadow: 3px 0 26px rgba(0,0,0,0.7); }
  #hud-side.collapsed { width: var(--side-w-col); box-shadow: none; }

  /* Bottom HUD: stack vitals over a full-width action row. */
  #hud-bottom {
    flex-direction: column;
    height: var(--hud-h);
    align-items: stretch;
    justify-content: center;
    gap: 7px;
    padding: 8px 10px;
  }
  #hud-vitals { min-width: 0; width: 100%; gap: 5px; padding: 0; }
  .vital-bar-bg { max-width: none; }
  .hud-vdiv { display: none; }
  #hud-actions { width: 100%; gap: 6px; flex-wrap: nowrap; justify-content: space-between; }
  .er-btn-action { flex: 1 1 0; justify-content: center; font-size: 12px; padding: 9px 6px; }

  /* Bigger touch targets for the top-right utilities. */
  #hud-util { top: 8px; right: 8px; gap: 5px; }
  .er-btn-icon { min-width: 42px; padding: 9px 11px; font-size: 16px; }

  /* Let long server messages wrap instead of being clipped to one line. */
  #game-toast { white-space: normal; max-width: 92vw; }

  /* Chat: full-width above the taller mobile HUD. */
  #chat-panel { left: 6px; right: 6px; width: auto; bottom: 124px; max-height: 40vh; }
}

/* ================================================================
   CHAT (rate-limited: local proximity + global shout)
   ================================================================ */
#chat-panel {
  position: fixed; left: 12px; bottom: 96px;
  width: min(340px, 82vw); max-height: 46vh;
  display: flex; flex-direction: column;
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-panel), var(--inset-hi);
  z-index: 4000; font-family: var(--font-body); overflow: hidden;
}
#chat-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 7px 11px; border-bottom: 1px solid var(--border);
  color: var(--text-bright); font-weight: 600; font-size: 14px;
}
#chat-close { background: none; border: none; color: var(--text); font-size: 18px; line-height: 1; cursor: pointer; }
#chat-log { flex: 1; overflow-y: auto; padding: 8px 10px; display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text); }
.chat-msg { display: flex; align-items: baseline; gap: 6px; word-break: break-word; }
.chat-from { font-weight: 700; color: var(--accent-bright); flex-shrink: 0; }
.chat-mine .chat-from { color: #9ad07a; }
.chat-shout .chat-from { color: #e0aa50; }
.chat-shout { background: rgba(120, 72, 12, 0.16); border-radius: 4px; padding: 1px 3px; }
.chat-body { flex: 1; }
.chat-actions { display: none; gap: 2px; flex-shrink: 0; }
.chat-msg:hover .chat-actions { display: inline-flex; }
.chat-actions button { background: none; border: none; cursor: pointer; font-size: 11px; opacity: 0.55; padding: 0 2px; }
.chat-actions button:hover { opacity: 1; }
#chat-input-row { display: flex; gap: 4px; padding: 7px 8px; border-top: 1px solid var(--border); }
#chat-scope { background: var(--bg-hover); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); font-size: 12px; }
#chat-text { flex: 1; min-width: 0; background: rgba(0,0,0,0.35); color: var(--text-bright); border: 1px solid var(--border); border-radius: var(--radius); padding: 5px 8px; font-size: 13px; font-family: var(--font-body); }
#chat-text:focus { outline: none; border-color: var(--border-hi); }
#chat-send { flex-shrink: 0; }
