/* ── Reset & Base ──────────────────────────────────── */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  width: 100%; height: 100%;
  background: #0a0a0a;
  color: #ccc;
  font-family: 'Courier New', 'Lucida Console', monospace;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

/* ── Sim Background ────────────────────────────────── */
.sim-bg {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
  opacity: 0.5;
}

/* ── LOBBY ─────────────────────────────────────────── */
#lobby {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  width: 100%; height: 100%;
  overflow-y: auto;
  padding: 24px 16px;
  position: relative;
  z-index: 1;
}

.lobby-box {
  width: 100%;
  max-width: 700px;
  background: rgba(17, 17, 17, 0.92);
  border: 1px solid #333;
  padding: 28px 32px 24px;
  position: relative;
}

/* Back to home link */
.back-home {
  display: inline-block;
  color: #555;
  font-size: 11px;
  text-decoration: none;
  letter-spacing: 1px;
  margin-bottom: 16px;
  transition: color 0.2s;
}
.back-home:hover { color: #ff6; }

/* Title */
.title-art {
  display: block;
  color: #ff6;
  font-size: 11px;
  line-height: 1.2;
  white-space: pre;
  text-align: left;
  margin-bottom: 4px;
  overflow-x: auto;
}
.subtitle {
  color: #555;
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid #1e1e1e;
}

/* Name row */
.lobby-name-row {
  margin-bottom: 20px;
}

/* Character selector */
.lobby-char-row {
  margin-bottom: 20px;
}
.char-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}
.char-option {
  width: 48px; height: 48px;
  border: 2px solid #222;
  cursor: pointer;
  background: #0d0d0d;
  display: flex; align-items: center; justify-content: center;
  image-rendering: pixelated;
  flex-shrink: 0;
  transition: border-color 0.1s;
}
.char-option:hover { border-color: #555; }
.char-option.selected { border-color: #ff6; box-shadow: 0 0 6px rgba(255,255,100,0.3); }
.char-option canvas { display: block; image-rendering: pixelated; }

/* Two-column layout */
.lobby-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
}
.lobby-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Column header */
.col-header {
  color: #6ff;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 2px;
  padding-bottom: 6px;
  border-bottom: 1px solid #222;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}
#roomCount {
  color: #444;
  font-size: 10px;
  letter-spacing: 0;
  text-transform: none;
}

/* Labels & inputs */
.field-label {
  display: block;
  color: #666;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 3px;
}
.hint {
  color: #333;
  text-transform: none;
  letter-spacing: 0;
}
input[type="text"] {
  display: block;
  width: 100%;
  background: #0d0d0d;
  border: 1px solid #333;
  color: #ff6;
  font-family: inherit;
  font-size: 14px;
  padding: 7px 10px;
  outline: none;
  margin-bottom: 2px;
}
input[type="text"]:focus { border-color: #666; }
input[type="text"]::placeholder { color: #333; }

/* Visibility toggle */
.visibility-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 2px 0;
}
.vis-btn {
  background: #0d0d0d;
  border: 1px solid #333;
  color: #555;
  font-family: inherit;
  font-size: 10px;
  letter-spacing: 1px;
  padding: 3px 12px;
  cursor: pointer;
  text-transform: uppercase;
}
.vis-btn[data-private="true"] {
  border-color: #a60;
  color: #a60;
}
.vis-btn:hover { border-color: #888; color: #888; }

/* Buttons */
.btn {
  display: block;
  width: 100%;
  font-family: inherit;
  font-size: 12px;
  padding: 9px 16px;
  cursor: pointer;
  border: 1px solid;
  text-align: center;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.btn-primary {
  background: #111;
  border-color: #ff6;
  color: #ff6;
}
.btn-primary:hover { background: #1a1a00; }
.btn-primary:active { background: #252500; }
.btn-secondary {
  background: #111;
  border-color: #6ff;
  color: #6ff;
}
.btn-secondary:hover { background: #001a1a; }
.btn-secondary:active { background: #002525; }

/* Divider */
.divider {
  color: #333;
  font-size: 10px;
  text-align: center;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 6px 0;
  position: relative;
}

/* Room list */
.room-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-height: 80px;
}
.room-empty {
  color: #333;
  font-size: 11px;
  padding: 16px 0;
  text-align: center;
}
.room-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid #1e1e1e;
  cursor: pointer;
  transition: border-color 0.1s;
}
.room-item:hover { border-color: #444; }
.room-item:hover .ri-name { color: #fff; }
.room-item.room-full { opacity: 0.35; cursor: default; pointer-events: none; }
.ri-name {
  flex: 1;
  color: #aaa;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ri-players {
  font-size: 10px;
  white-space: nowrap;
  color: #555;
}
.ri-players.warn { color: #a60; }
.ri-floor {
  color: #444;
  font-size: 10px;
  white-space: nowrap;
}

/* Pagination */
#roomPagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 6px;
  font-size: 10px;
  color: #444;
}
.page-btn {
  background: none;
  border: 1px solid #333;
  color: #555;
  font-family: inherit;
  font-size: 12px;
  padding: 2px 10px;
  cursor: pointer;
}
.page-btn:hover:not(:disabled) { border-color: #888; color: #ccc; }
.page-btn:disabled { opacity: 0.25; cursor: default; }

/* Error */
.error-msg {
  margin-top: 14px;
  color: #c44;
  font-size: 12px;
  min-height: 1.2em;
  text-align: center;
}

/* ── Room Management Panel ─────────────────────────── */
#roomPanel {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.88);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
}
.roompanel-box {
  background: #111;
  border: 1px solid #444;
  padding: 20px 24px;
  width: 90%; max-width: 340px;
  max-height: 90vh; overflow-y: auto;
}
.roompanel-header {
  display: flex; justify-content: space-between; align-items: center;
  color: #ff6; font-size: 13px;
  border-bottom: 1px solid #222;
  padding-bottom: 10px; margin-bottom: 14px;
}
.roompanel-name {
  color: #fff; font-size: 15px; font-weight: bold;
  margin-bottom: 14px; letter-spacing: 1px;
}
.roompanel-section {
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid #1e1e1e;
}
.roompanel-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.roompanel-label {
  color: #555; font-size: 10px; text-transform: uppercase;
  letter-spacing: 1px; margin-bottom: 8px;
}

/* Invite code */
.invite-row {
  display: flex; align-items: center; gap: 8px;
}
.invite-code {
  flex: 1;
  color: #6ff;
  font-size: 13px;
  background: #0a0a0a;
  border: 1px solid #2a2a2a;
  padding: 5px 10px;
  letter-spacing: 0.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.invite-copy-btn {
  background: #1a1a1a; border: 1px solid #444; color: #888;
  font-family: inherit; font-size: 10px; letter-spacing: 1px;
  padding: 5px 10px; cursor: pointer; text-transform: uppercase;
  white-space: nowrap;
}
.invite-copy-btn:hover { border-color: #6ff; color: #6ff; }
.invite-copied {
  color: #0f0; font-size: 10px; margin-top: 4px;
}

/* Room player list */
.rp-player {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid #1a1a1a;
  font-size: 12px;
}
.rp-player:last-child { border-bottom: none; }
.rp-swatch {
  width: 10px; height: 10px; flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.1);
}
.rp-name { flex: 1; color: #ccc; }
.rp-status { color: #555; font-size: 10px; }
.rp-actions { display: flex; gap: 4px; }
.rp-btn {
  background: none;
  border: 1px solid #333; color: #555;
  font-family: inherit; font-size: 10px;
  letter-spacing: 1px; padding: 2px 8px; cursor: pointer;
  text-transform: uppercase;
}
.rp-btn:hover { border-color: #888; color: #ccc; }
.rp-btn.danger { border-color: #422; color: #844; }
.rp-btn.danger:hover { border-color: #f44; color: #f44; }

/* Danger button */
.btn-danger {
  border-color: #833 !important;
  color: #c44 !important;
  background: #0a0000 !important;
}
.btn-danger:hover { background: #1a0000 !important; }

/* ── GAME Layout ───────────────────────────────────── */
#game {
  display: flex;
  flex-direction: column;
  width: 100%; height: 100%;
  position: relative;
  z-index: 1;
}
#gameHeader {
  background: #111;
  border-bottom: 1px solid #222;
  padding: 4px 10px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}
#roomLabel { color: #ff6; font-weight: bold; }
#floorLabel { color: #6ff; }
#playerCount { color: #555; margin-left: auto; }
.header-btn {
  background: none; border: 1px solid #333; color: #666;
  font-family: inherit; font-size: 10px; letter-spacing: 1px;
  padding: 1px 8px; cursor: pointer; text-transform: uppercase;
}
.header-btn:hover { border-color: #888; color: #ccc; }
#gfxIndicator {
  background: #111;
  border: 1px solid #336;
  color: #669;
  font-size: 9px;
  letter-spacing: 1px;
  padding: 1px 7px;
  cursor: default;
  user-select: none;
}

/* Badges */
.badge {
  font-size: 9px;
  letter-spacing: 1px;
  padding: 1px 6px;
  border: 1px solid;
}
.badge-host { border-color: #a60; color: #a60; }
.badge-private { border-color: #639; color: #a6f; }

#gameArea {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #080808;
  position: relative;
}
#gameCanvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#statsBar {
  background: #111;
  border-top: 1px solid #1e1e1e;
  padding: 4px 10px;
  font-size: 11px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  flex-shrink: 0;
}
#statsBar span { white-space: nowrap; }
#statHp { color: #0f0; }
#statStr { color: #f80; }
#statLvl { color: #ff6; }
#statGold { color: #ff0; }
#statHunger { color: #a60; }
#statWeapon { color: #aaf; }
#statArmor { color: #aaf; }
#statStatus { font-size: 11px; letter-spacing: 0.5px; }

#messageLog {
  background: #0a0a0a;
  border-top: 1px solid #1a1a1a;
  padding: 4px 10px;
  font-size: 11px;
  max-height: 80px;
  overflow-y: auto;
  flex-shrink: 0;
}
.msg-line { margin: 1px 0; }

/* ── Inventory ─────────────────────────────────────── */
#inventoryPanel {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: #111;
  border: 1px solid #ff6;
  z-index: 100;
  min-width: 300px;
  max-width: 92vw;
  max-height: 80vh;
  /* flex column so header stays pinned, only list scrolls */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.inv-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #ff6;
  font-size: 13px;
  border-bottom: 1px solid #222;
  padding: 12px 16px 10px;
  flex-shrink: 0;  /* never scroll away */
}
#invList {
  overflow-y: auto;
  padding: 0 16px 12px;
  flex: 1;
}
.btn-close {
  background: none;
  border: 1px solid #444;
  color: #666;
  font-size: 13px;
  cursor: pointer;
  padding: 2px 7px;
  font-family: inherit;
}
.btn-close:hover { color: #ccc; border-color: #888; }
.inv-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 4px;
  border-bottom: 1px solid #1a1a1a;
  font-size: 12px;
}
.inv-item:hover { background: #161616; }
.inv-item-name { flex: 1; color: #ccc; }
.inv-item-ch { color: #aaf; margin-right: 8px; min-width: 14px; text-align: center; }
.inv-sprite { width: 32px; height: 32px; image-rendering: pixelated; margin-right: 6px; flex-shrink: 0; }
.inv-btn {
  background: #1a1a1a;
  border: 1px solid #444;
  color: #6ff;
  font-family: inherit;
  font-size: 11px;
  padding: 3px 8px;
  cursor: pointer;
  margin-left: 4px;
}
.inv-btn:hover { border-color: #6ff; }
.inv-btn.drop { color: #f88; }
.inv-btn.drop:hover { border-color: #f88; }
.inv-empty { color: #444; font-size: 12px; padding: 10px; }
.inv-stat { font-size: 11px; font-family: inherit; margin: 0 4px; min-width: 52px; text-align: right; flex-shrink: 0; }
.inv-best-badge { font-size: 10px; font-weight: bold; color: #111; background: #ffd700; padding: 1px 5px; margin-right: 2px; flex-shrink: 0; letter-spacing: 0.5px; }

/* ── D-Pad ─────────────────────────────────────────── */
#dpad {
  display: none;
  position: fixed;
  bottom: 16px; right: 16px;
  z-index: 50;
}
.dpad-main { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.dpad-row { display: flex; gap: 2px; }
.dpad-btn {
  width: 48px; height: 48px;
  background: rgba(20, 20, 20, 0.85);
  border: 2px solid rgba(255, 255, 100, 0.25);
  border-radius: 0;
  color: #ff6;
  font-size: 18px;
  font-family: inherit;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  image-rendering: pixelated;
}
.dpad-btn:active { background: rgba(60, 60, 0, 0.9); border-color: rgba(255, 255, 100, 0.6); }
.dpad-diag {
  width: 36px !important; height: 36px !important;
  opacity: 0.5;
  border-radius: 0 !important;
}
.dpad-diag:active { opacity: 0.9; }

/* ── Mobile FAB ────────────────────────────────────── */
#mobileActions {
  display: none;
  position: fixed;
  bottom: 16px; left: 16px;
  z-index: 50;
  flex-direction: column;     /* toggle at bottom, grid expands upward */
  align-items: flex-start;
  gap: 8px;
}
.fab-main {
  width: 56px !important; height: 56px !important;
  background: rgba(20, 16, 4, 0.96) !important;
  border: 2px solid rgba(255, 210, 0, 0.55) !important;
  border-radius: 0 !important;
  box-shadow: 0 2px 14px rgba(0,0,0,0.7);
  flex-shrink: 0;
  z-index: 2;
  transition: transform 0.18s;
  image-rendering: pixelated;
}
.fab-main.open { transform: rotate(45deg); }
.fab-items {
  display: grid;
  grid-template-columns: repeat(3, 50px); /* 3 cols × 50px = 158px total incl gaps */
  grid-template-rows: repeat(2, 50px);
  gap: 8px;
  opacity: 0;
  transform: scale(0.4) translateY(20px);
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
  transform-origin: left bottom;
}
.fab-items.open {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: auto;
}
.mob-btn {
  width: 50px; height: 50px;
  background: rgba(16, 14, 6, 0.93);
  border: 2px solid rgba(255, 255, 100, 0.2);
  border-radius: 0;
  color: #ff6;
  font-size: 20px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
  flex-shrink: 0;
  image-rendering: pixelated;
}
.mob-btn:active { filter: brightness(1.4); }

/* ── FAB bottom row (toggle + quick-use) ───────────── */
.fab-bottom-row {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 8px;
}
#fabQuickUse { display: flex; flex-direction: row; gap: 8px; }
.fab-quick-btn {
  width: 50px; height: 50px;
  background: rgba(16, 14, 6, 0.93);
  border: 2px solid rgba(255, 100, 200, 0.3);
  border-radius: 0;
  font-family: 'Courier New', monospace;
  font-size: 24px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
  flex-shrink: 0;
  line-height: 1;
}
.fab-quick-btn:active { filter: brightness(1.5); }
.fab-quick-btn.potion { border-color: rgba(255, 80, 220, 0.55); color: #f4f; }
.fab-quick-btn.food   { border-color: rgba(200, 110, 20, 0.55); color: #f80; }
.fab-quick-sprite { width: 32px; height: 32px; image-rendering: pixelated; pointer-events: none; }
.fab-quick-count {
  position: absolute;
  bottom: 2px; right: 3px;
  font-size: 9px;
  font-family: inherit;
  color: #ff6;
  line-height: 1;
  pointer-events: none;
}

/* Distinct tint per action button */
#mobInv     { border-color: rgba(100,200,255,0.45); color: #6cf; }
#mobLog     { border-color: rgba(200,180,100,0.45); color: #db8; }
#mobRoom    { border-color: rgba(160,255,140,0.45); color: #8f8; }
#mobGfx     { border-color: rgba(200,100,255,0.45); color: #c6f; }
#mobExplore { border-color: rgba(255,140,80,0.45);  color: #fa6; }
#mobSettings{ border-color: rgba(160,160,160,0.45); color: #aaa; }

/* ── Mobile HUD ────────────────────────────────────── */
#mobileHud {
  display: none;
  position: absolute;
  top: 4px; left: 4px; right: 4px;
  z-index: 10;
  pointer-events: none;
}
#hudHp { height: 4px; border-radius: 2px; background: #300; overflow: hidden; }
#hudHp::after { content: ''; display: block; height: 100%; background: #0f0; transition: width 0.2s; }
#hudInfo {
  display: flex; justify-content: space-between;
  font-size: 10px; margin-top: 2px; color: #aaa;
  text-shadow: 0 0 4px #000;
}
#hudStats {
  display: flex; justify-content: space-between;
  font-size: 9px; margin-top: 1px; color: #888;
  text-shadow: 0 0 4px #000;
  gap: 4px;
}
#mobileMsg {
  display: none;
  position: fixed;
  bottom: calc(165px + 10px); left: 4px; right: 4px;
  z-index: 10;
  font-size: 10px; color: #ddd;
  text-shadow: 0 0 4px #000;
  pointer-events: none; text-align: center;
  max-height: 28px; overflow: hidden;
}

/* ── Mobile Log ────────────────────────────────────── */
#mobileLog {
  position: fixed; inset: 0;
  z-index: 200;
  background: rgba(0,0,0,0.94);
  display: flex; flex-direction: column;
}
.log-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px;
  color: #ff6; font-size: 13px;
  border-bottom: 1px solid #222;
  flex-shrink: 0;
}
#logContent {
  flex: 1; overflow-y: auto;
  padding: 8px 12px; font-size: 11px;
  -webkit-overflow-scrolling: touch;
}
#logContent .msg-line { margin: 3px 0; line-height: 1.4; }

/* ── Desktop inventory button ──────────────────────── */
#btnInventory {
  display: none;
  position: fixed; bottom: 10px; right: 10px;
  z-index: 50;
  background: rgba(20, 20, 20, 0.9);
  border: 1px solid #ff6;
  color: #ff6;
  font-family: inherit;
  font-size: 11px;
  padding: 8px 16px;
  cursor: pointer;
  letter-spacing: 1px;
}

/* ── Settings Panel ────────────────────────────────── */
#settingsPanel {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.88);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
}
.settings-box {
  background: #111;
  border: 1px solid #333;
  padding: 20px 24px;
  max-width: 300px; width: 90%;
}
.settings-header {
  display: flex; justify-content: space-between; align-items: center;
  color: #6ff; font-size: 13px;
  margin-bottom: 16px;
  border-bottom: 1px solid #1e1e1e;
  padding-bottom: 8px;
}
.settings-row {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px; font-size: 12px; color: #888;
}
.settings-row label { flex: 1; }
.zoom-controls { display: flex; align-items: center; gap: 10px; }
.zoom-btn {
  width: 30px; height: 30px;
  background: #1a1a1a; border: 1px solid #444; color: #888;
  font-size: 16px; font-family: inherit; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.zoom-btn:hover { border-color: #6ff; color: #6ff; }
#zoomLevel { color: #888; font-size: 12px; min-width: 38px; text-align: center; }
.settings-toggle {
  background: #1a1a1a; border: 1px solid #444; color: #888;
  font-family: inherit; font-size: 11px; padding: 5px 12px; cursor: pointer;
  letter-spacing: 1px;
}
.settings-toggle:hover { border-color: #6ff; color: #6ff; }
.settings-section { margin-top: 10px; padding-top: 10px; border-top: 1px solid #1e1e1e; }
.settings-section-label { color: #555; font-size: 10px; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 10px; display: block; }
.legend-item { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; font-size: 12px; }
.legend-swatch { width: 12px; height: 12px; flex-shrink: 0; border: 1px solid rgba(255,255,255,0.1); }
.legend-name { color: #aaa; flex: 1; }

/* Kick button */
.kick-btn {
  background: none;
  border: 1px solid #422;
  color: #844;
  font-family: inherit;
  font-size: 10px;
  padding: 1px 7px;
  cursor: pointer;
  letter-spacing: 1px;
}
.kick-btn:hover { border-color: #f44; color: #f44; }

/* ── Death Overlay ─────────────────────────────────── */
#deathOverlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.9);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
}
.death-box { text-align: center; }
.death-title {
  color: #c00; font-size: 36px; margin-bottom: 10px;
  animation: pulse 1.5s ease-in-out infinite;
}
.death-msg { color: #555; font-size: 13px; margin-bottom: 20px; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ── Tooltip ───────────────────────────────────────── */
.tooltip {
  position: fixed;
  background: #111; border: 1px solid #333;
  padding: 4px 8px; font-size: 11px;
  color: #aaa; z-index: 300;
  pointer-events: none; white-space: nowrap; max-width: 300px;
}

/* ── Floor Event Banner ────────────────────────────── */
#eventBanner {
  position: fixed;
  top: 18%; left: 50%;
  transform: translateX(-50%) translateY(-8px);
  background: rgba(8, 6, 2, 0.92);
  border: 1px solid currentColor;
  padding: 10px 28px;
  font-size: 14px; letter-spacing: 1px;
  z-index: 200; pointer-events: none;
  opacity: 0; transition: opacity 0.35s, transform 0.35s;
  white-space: nowrap;
  box-shadow: 0 0 24px rgba(255,200,0,0.15);
}
#eventBanner.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Damage Flash ──────────────────────────────────── */
.damage-flash {
  position: fixed; inset: 0;
  pointer-events: none; z-index: 150;
  opacity: 0; transition: opacity 0.08s;
}
.damage-flash.hit { background: rgba(255,0,0,0.18); opacity: 1; }
.damage-flash.kill { background: rgba(255,255,100,0.12); opacity: 1; }

/* ── Help Overlay ──────────────────────────────────── */
#helpOverlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 250;
  display: flex; align-items: center; justify-content: center;
}
.help-box {
  background: #111; border: 1px solid #333;
  padding: 24px 32px; max-width: 680px; width: 95%;
  max-height: 90vh; overflow-y: auto;
}
.help-title {
  color: #ff6; font-size: 14px; margin-bottom: 16px;
  border-bottom: 1px solid #222; padding-bottom: 8px;
}
.help-close { color: #444; font-size: 10px; float: right; margin-top: 2px; }
.help-cols { display: flex; gap: 32px; }
.help-col { flex: 1; }
.help-col h3 {
  color: #6ff; font-size: 11px; text-transform: uppercase; letter-spacing: 1px;
  margin: 12px 0 6px 0; border-bottom: 1px solid #1e1e1e; padding-bottom: 3px;
}
.help-col h3:first-child { margin-top: 0; }
.help-row { font-size: 11px; color: #888; margin: 4px 0; }
.help-row em { color: #ff6; font-style: normal; }
.hk {
  display: inline-block; background: #1a1a1a; border: 1px solid #333;
  color: #ff6; padding: 1px 5px; font-size: 10px; min-width: 20px; text-align: center;
}
.hs { font-size: 13px; font-weight: bold; margin-right: 2px; }

/* ── Shop Panel ────────────────────────────────────── */
#shopPanel {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.88);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
}
.shop-box {
  background: #111; border: 1px solid #0a0;
  padding: 16px 20px; max-width: 380px; width: 90%;
  max-height: 80vh; overflow-y: auto;
}
.shop-header {
  display: flex; justify-content: space-between; align-items: center;
  color: #0d0; font-size: 13px; margin-bottom: 12px;
  border-bottom: 1px solid #1e1e1e; padding-bottom: 8px; gap: 12px;
}
.shop-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 4px; border-bottom: 1px solid #1a1a1a; font-size: 12px;
}
.shop-item:hover { background: #161616; }
.shop-item-name { flex: 1; color: #ccc; }
.shop-item-cost { color: #ff0; margin: 0 8px; white-space: nowrap; }
.shop-buy { color: #0f0 !important; }
.shop-buy:hover { border-color: #0f0 !important; }

/* ── Game Length Selector ──────────────────────────── */
.game-length-row {
  display: flex; align-items: center; gap: 10px; margin: 8px 0;
}
.game-length-btns {
  display: flex; gap: 6px; flex-wrap: wrap;
}
.len-btn {
  background: #111; border: 1px solid #333; color: #888;
  padding: 5px 10px; font-family: inherit; font-size: 11px;
  cursor: pointer; display: flex; flex-direction: column; align-items: center;
  transition: border-color 0.15s, color 0.15s;
}
.len-btn:hover { border-color: #555; color: #ccc; }
.len-btn.active { border-color: #f80; color: #f80; }
.len-hint { font-size: 9px; color: #555; margin-top: 2px; }
.len-btn.active .len-hint { color: #a60; }

/* ── Victory Overlay ───────────────────────────────── */
#victoryOverlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 300;
  display: flex; align-items: center; justify-content: center;
}
.victory-box {
  background: #0a0d0a; border: 1px solid #3a3;
  padding: 32px 40px; max-width: 480px; width: 90%;
  text-align: center;
}
.victory-art {
  color: #ffd700; font-size: 11px; line-height: 1.3;
  margin: 0 0 12px 0; white-space: pre;
}
.victory-subtitle { color: #8f8; font-size: 13px; margin-bottom: 16px; }
.victory-stats {
  color: #aaa; font-size: 12px; margin-bottom: 20px; line-height: 1.8;
}
.victory-stats strong { color: #ffd700; }

/* ── Village Overlay ───────────────────────────────── */
#villageOverlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.88);
  z-index: 250;
  display: flex; align-items: center; justify-content: center;
}
.village-box {
  background: #0f0e0c; border: 1px solid #5a4020;
  width: min(520px, 96vw); max-height: 88vh;
  display: flex; flex-direction: column;
  box-shadow: 0 0 40px rgba(200,120,0,0.15);
}
.village-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; border-bottom: 1px solid #3a2a14;
  background: #161210;
}
.village-title { color: #d4a060; font-size: 14px; letter-spacing: 1px; }
.village-gold { color: #ffd700; font-size: 13px; }
.village-content {
  flex: 1; overflow-y: auto; padding: 12px 16px;
  scrollbar-width: thin; scrollbar-color: #3a2a14 #0f0e0c;
}
.village-footer {
  padding: 10px 16px; border-top: 1px solid #3a2a14;
  display: flex; align-items: center; gap: 12px;
  background: #161210;
}
.village-note { font-size: 11px; color: #f80; flex: 1; }

/* Village sections */
.vl-section {
  border: 1px solid #2a1e0e; background: #131109;
  margin-bottom: 10px; padding: 10px 12px;
}
.vl-npc-row {
  display: flex; align-items: center; gap: 12px; margin-bottom: 8px;
}
.vl-npc-sprite {
  image-rendering: pixelated; flex-shrink: 0;
  border: 1px solid #2a1e0e;
}
.vl-npc-name { color: #d4a060; font-size: 12px; font-weight: bold; margin-bottom: 2px; }
.vl-npc-desc { color: #666; font-size: 11px; }
.vl-service-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px 0; border-top: 1px solid #1e1608;
}
.vl-service-label { color: #aaa; font-size: 11px; }
.vl-cost { color: #ffd700; }
.vl-sell-price { color: #4f4; }
.vl-full-tag { color: #555; font-size: 11px; font-style: italic; }
.vl-section-title { color: #888; font-size: 10px; text-transform: uppercase;
  letter-spacing: 1px; margin-bottom: 6px; }
.vl-others { color: #556; font-size: 10px; margin-top: 6px; text-align: center; }
.vl-opener-note { color: #864; }

/* Village buttons */
.vl-btn {
  background: #1a1206; border: 1px solid #4a3018; color: #c8901c;
  padding: 4px 12px; font-family: inherit; font-size: 11px;
  cursor: pointer; transition: border-color 0.1s, color 0.1s;
  white-space: nowrap;
}
.vl-btn:hover { border-color: #c8901c; color: #ffd700; }
.vl-btn-heal:hover { border-color: #0f8; color: #0f8; }
.vl-btn-feed:hover { border-color: #fa0; color: #fa0; }
.vl-btn-smith:hover { border-color: #8af; color: #8af; }
.vl-btn-sell:hover { border-color: #4f4; color: #4f4; }

/* ── Mobile breakpoint ─────────────────────────────── */
@media (max-width: 768px) {
  .lobby-box { padding: 16px; }
  .title-art { font-size: 7px; }
  .lobby-cols { grid-template-columns: 1fr; gap: 20px; }
  #gameHeader { display: none; }
  #statsBar { display: none; }
  #messageLog { display: none; }
  #btnInventory { display: none !important; }
  #dpad { display: flex; }
  #mobileActions { display: flex; }
  #mobileHud { display: block; }
  #mobileMsg { display: block; }
  .help-cols { flex-direction: column; gap: 8px; }
  .help-box { padding: 16px; }

  /* Inventory: bottom-sheet on mobile */
  #inventoryPanel {
    top: auto; bottom: 0; left: 0; right: 0;
    transform: none;
    max-width: 100vw;
    max-height: 55vh;
    border-left: none; border-right: none; border-bottom: none;
    border-top: 2px solid #ff6;
    border-radius: 0;
  }
}
@media (min-width: 769px) {
  #btnInventory { display: block; }
}
