:root {
  --bg-dark: #0f1419;
  --panel-bg: rgba(16, 23, 32, 0.78);
  --popup-bg: rgba(15, 22, 32, 0.72);
  --panel-border: #3d4f60;
  --gold: #f59e0b;
  --gold-light: #fde68a;
  --emerald: #10b981;
  --crimson: #ef4444;
  --mana: #3b82f6;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --cursor-arrow: url('assets/cursor-arrow.svg') 3 2, auto;
  --cursor-action: url('assets/cursor-sword.svg') 3 2, pointer;
  --cursor-target: url('assets/cursor-target.svg') 15 15, crosshair;
}

* {
  box-sizing: border-box;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* Disable the browser's double-tap-to-zoom on controls, without cancelling
   touch events: inventory double taps, scrolling and pinch gestures still work. */
button, a, [role="button"], .color-swatch, [data-dbl-equip], [data-container-action], [data-unequip-slot] {
  touch-action: manipulation;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-dark);
  color: var(--text-main);
  font-family: 'Courier New', Courier, monospace;
  cursor: var(--cursor-arrow);
}

canvas, img.pixel-icon {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* ====== ГЛАВНОЕ МЕНЮ И ЭКРАН СОЗДАНИЯ ПЕРСОНАЖА ====== */
#main-menu-screen,
#creation-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: radial-gradient(circle at center, #1a2e22 0%, #090d11 100%);
  overflow-y: auto;
}

.saved-heroes-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 360px;
  overflow-y: auto;
  padding-right: 4px;
}

.saved-hero-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: rgba(11, 18, 26, 0.82);
  border: 1px solid #3d5266;
}

.saved-hero-card:hover {
  border-color: var(--gold);
}

.danger-btn {
  background: rgba(127, 29, 29, 0.82);
  border: 1px solid #f87171;
  color: #fecaca;
  padding: 7px 11px;
  font-family: inherit;
  font-size: 0.78rem;
  cursor: var(--cursor-action);
}

.danger-btn:hover {
  background: rgba(185, 28, 28, 0.92);
}

.creator-card {
  width: 100%;
  max-width: 980px;
  max-height: 94vh;
  overflow-y: auto;
  background: var(--panel-bg);
  border: 3px solid var(--gold);
  box-shadow: 0 0 0 3px #000, 0 20px 50px rgba(0, 0, 0, 0.85);
  padding: 20px 24px;
  border-radius: 4px;
}

.creator-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px dashed var(--panel-border);
  padding-bottom: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 8px;
}

.creator-title {
  margin: 0;
  font-size: 1.4rem;
  color: var(--gold-light);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.server-badge {
  font-size: 0.82rem;
  padding: 4px 10px;
  background: #14532d;
  border: 1px solid #22c55e;
  color: #dcfce7;
}

.resume-banner {
  display: none;
  background: linear-gradient(90deg, #132a1e, #172536);
  border: 2px solid #22c55e;
  padding: 12px 14px;
  margin-bottom: 16px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.creator-grid {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 22px;
}

.preview-box {
  background: #0b1117;
  border: 2px solid var(--panel-border);
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

#hero-preview-canvas {
  width: 160px;
  height: 180px;
  background: radial-gradient(circle, #1e462b 0%, #0f172a 80%);
  border: 2px solid #475569;
}

.derived-stats-box {
  width: 100%;
  background: #131c26;
  border: 1px solid #334155;
  padding: 10px;
  font-size: 0.82rem;
  line-height: 1.5;
}

.derived-row {
  display: flex;
  justify-content: space-between;
}

.form-section {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 0.85rem;
  color: var(--gold-light);
  margin-bottom: 6px;
  font-weight: bold;
}

.pixel-input {
  width: 100%;
  padding: 8px 11px;
  background: #090d12;
  border: 2px solid var(--panel-border);
  color: #fff;
  font-family: inherit;
  font-size: 0.92rem;
  user-select: text;
}

.pixel-input:focus {
  outline: none;
  border-color: var(--gold);
}

.btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.choice-btn {
  background: #17212b;
  color: var(--text-main);
  border: 2px solid #334155;
  padding: 7px 12px;
  font-family: inherit;
  font-size: 0.84rem;
  cursor: var(--cursor-action);
}

.choice-btn:hover:not(:disabled) {
  border-color: #94a3b8;
}

.choice-btn.active {
  background: #3b2a10;
  border-color: var(--gold);
  color: var(--gold-light);
  font-weight: bold;
}

.choice-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  text-decoration: line-through;
}

.class-desc {
  margin-top: 6px;
  font-size: 0.82rem;
  color: #cbd5e1;
  min-height: 30px;
}

.swatch-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.color-swatch {
  width: 28px;
  height: 28px;
  border: 2px solid #334155;
  cursor: var(--cursor-action);
}

.color-swatch.active {
  border-color: #fff;
  box-shadow: 0 0 0 2px var(--gold);
}

.stats-editor {
  background: #0d141c;
  border: 2px solid #293544;
  padding: 10px 12px;
}

.stat-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 0.88rem;
}

.stat-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mini-btn {
  width: 26px;
  height: 26px;
  background: #1e293b;
  border: 1px solid #64748b;
  color: #fff;
  font-weight: bold;
  cursor: var(--cursor-action);
  font-family: inherit;
}

.mini-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.primary-btn {
  width: 100%;
  padding: 11px;
  margin-top: 8px;
  background: #15803d;
  border: 2px solid #4ade80;
  color: #fff;
  font-family: inherit;
  font-size: 1rem;
  font-weight: bold;
  text-transform: uppercase;
  cursor: var(--cursor-action);
}

.primary-btn:hover {
  background: #16a34a;
}

.error-msg {
  color: #fca5a5;
  font-size: 0.85rem;
  margin-top: 6px;
  min-height: 18px;
}

/* ====== ИГРОВОЙ ЭКРАН И HUD ====== */
#game-screen {
  position: fixed;
  inset: 0;
  display: none;
}

#world-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: var(--cursor-target);
}

.hud-top-left {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 15;
  background: var(--panel-bg);
  border: 2px solid var(--panel-border);
  padding: 10px 12px;
  min-width: 265px;
  max-width: 330px;
}

.hero-title-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.88rem;
  font-weight: bold;
  color: var(--gold-light);
  margin-bottom: 5px;
  gap: 6px;
}

.zone-pill {
  display: inline-block;
  padding: 2px 7px;
  font-size: 0.72rem;
  font-weight: bold;
  margin-bottom: 6px;
  border: 1px solid;
}

.zone-pill.safe {
  background: rgba(20, 83, 45, 0.9);
  border-color: #4ade80;
  color: #bbf7d0;
}

.zone-pill.wild {
  background: rgba(127, 29, 29, 0.85);
  border-color: #f87171;
  color: #fecaca;
}

.bar-wrap {
  position: relative;
  height: 15px;
  background: #090d12;
  border: 1px solid #475569;
  margin-bottom: 4px;
}

.bar-fill {
  height: 100%;
  transition: width 0.15s ease-out;
}

.bar-fill.hp { background: linear-gradient(90deg, #b91c1c, #ef4444); }
.bar-fill.mp { background: linear-gradient(90deg, #1d4ed8, #3b82f6); }
.bar-fill.xp { background: linear-gradient(90deg, #a16207, #facc15); }
.bar-fill.weight { background: linear-gradient(90deg, #0f766e, #14b8a6); }
.bar-fill.weight.heavy { background: linear-gradient(90deg, #b45309, #ef4444); }

.bar-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  text-shadow: 1px 1px 0 #000;
}

.hud-top-right {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 15;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

#minimap-canvas {
  width: 140px;
  height: 140px;
  background: #05080b;
  border: 2px solid var(--gold);
}

.hud-menu-buttons {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 340px;
}

.hud-btn {
  background: var(--panel-bg);
  border: 2px solid var(--panel-border);
  color: var(--text-main);
  padding: 6px 9px;
  font-family: inherit;
  font-size: 0.78rem;
  cursor: var(--cursor-action);
}

.hud-btn:hover {
  border-color: #94a3b8;
}

.hud-btn.highlight {
  border-color: var(--gold);
  color: var(--gold-light);
}

/* Входящие приглашения (в друзья / на торговлю) */
#invite-banner-box {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 38;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 440px);
}

.invite-card {
  background: rgba(15, 23, 42, 0.76);
  backdrop-filter: blur(5px);
  border: 2px solid #38bdf8;
  padding: 10px 14px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.55);
  font-size: 0.84rem;
}

/* Тосты */
#toast-container {
  position: fixed;
  top: 86px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000; /* notices must remain readable above a menu or modal */
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
  width: min(90vw, 480px);
}

.toast {
  background: rgba(12, 19, 28, 0.74);
  backdrop-filter: blur(4px);
  border: 2px solid var(--gold);
  padding: 8px 12px;
  font-size: 0.83rem;
  text-align: center;
  color: #fef3c7;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
}

/* Чат */
.chat-panel {
  position: fixed;
  bottom: 12px;
  left: 12px;
  z-index: 15;
  width: 310px;
  background: rgba(12, 18, 24, 0.85);
  border: 2px solid var(--panel-border);
  display: flex;
  flex-direction: column;
}

.chat-messages {
  height: 106px;
  overflow-y: auto;
  padding: 6px 8px;
  font-size: 0.76rem;
  line-height: 1.35;
}

.chat-input-row {
  display: flex;
  border-top: 1px solid var(--panel-border);
}

.chat-input-row input {
  flex: 1;
  background: #080c10;
  border: none;
  color: #fff;
  padding: 6px 8px;
  font-family: inherit;
  font-size: 0.78rem;
  user-select: text;
}

.chat-input-row button {
  background: #1e293b;
  border: none;
  color: var(--gold-light);
  padding: 0 10px;
  cursor: var(--cursor-action);
  font-family: inherit;
}

/* Модальные / всплывающие окна — П. 3 ТЗ: ПОЛУПРОЗРАЧНЫЕ! */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(4, 9, 15, 0.36);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 14px;
}

.modal-window {
  width: 100%;
  max-width: 620px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--popup-bg);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 2px solid var(--gold);
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.55);
  padding: 16px 18px;
}

.modal-window.modal-wide {
  max-width: 900px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(148, 163, 184, 0.35);
  padding-bottom: 8px;
  margin-bottom: 12px;
}

.quest-card, .inv-row, .friend-row {
  background: rgba(10, 17, 26, 0.62);
  border: 1px solid rgba(71, 85, 105, 0.85);
  padding: 10px;
  margin-bottom: 8px;
  font-size: 0.83rem;
}

.inv-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.inv-row.equipable-row {
  cursor: var(--cursor-action);
  transition: border-color 0.12s, background 0.12s;
}

.inv-row.equipable-row:hover {
  border-color: var(--gold);
  background: rgba(30, 41, 59, 0.72);
}

/* Двухколоночная компоновка окна Инвентаря + Кукла Экипировки (П. 4, 5, 6 ТЗ) */
.inventory-split-layout {
  display: grid;
  grid-template-columns: 310px 1fr;
  gap: 14px;
  align-items: start;
}

.paperdoll-panel {
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
  background: rgba(9, 15, 23, 0.64);
  border: 1px solid rgba(100, 116, 139, 0.75);
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.paperdoll-canvas {
  width: 128px;
  height: 144px;
  background: radial-gradient(circle, rgba(30, 70, 43, 0.78) 0%, rgba(11, 18, 28, 0.85) 80%);
  border: 2px solid #64748b;
}

.equip-slots-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  min-width: 0;
}

.equip-slot-box {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  box-sizing: border-box;
  background: rgba(15, 23, 42, 0.68);
  border: 1px dashed #475569;
  padding: 6px 7px;
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.72rem;
}

.equip-slot-box > img,
.equip-slot-box > span,
.equip-slot-box > div:first-child {
  flex-shrink: 0;
}
.equip-slot-box > div:not(:first-child) {
  min-width: 0;
  overflow: hidden;
}

.equip-slot-box.filled {
  border-style: solid;
  border-color: #f59e0b;
  background: rgba(59, 42, 16, 0.52);
  cursor: var(--cursor-action);
}

.equip-slot-box.filled:hover {
  border-color: #fde68a;
}

.price-tag {
  display: inline-block;
  color: #fde047;
  font-weight: bold;
  font-size: 0.74rem;
}

.trade-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* ====== МОБИЛЬНОЕ УПРАВЛЕНИЕ ====== */
#mobile-controls {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 20;
  display: none;
}

#joystick-zone {
  position: absolute;
  bottom: 24px;
  left: 24px;
  width: 132px;
  height: 132px;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.55);
  border: 2px solid rgba(245, 158, 11, 0.65);
  pointer-events: auto;
  touch-action: none;
}

#joystick-stick {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 52px;
  height: 52px;
  margin-left: -26px;
  margin-top: -26px;
  border-radius: 50%;
  background: rgba(245, 158, 11, 0.85);
  border: 2px solid #fef3c7;
}

#mobile-action-btn {
  position: absolute;
  bottom: 30px;
  right: 24px;
  width: 82px;
  height: 82px;
  border-radius: 50%;
  background: rgba(21, 128, 61, 0.9);
  border: 3px solid #86efac;
  color: #fff;
  font-family: inherit;
  font-weight: bold;
  font-size: 0.74rem;
  pointer-events: auto;
  cursor: var(--cursor-action);
}

#mobile-attack-btn {
  position: absolute;
  bottom: 124px;
  right: 34px;
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: rgba(185, 28, 28, 0.9);
  border: 3px solid #fca5a5;
  color: #fff;
  font-family: inherit;
  font-weight: bold;
  font-size: 0.74rem;
  pointer-events: auto;
  cursor: var(--cursor-action);
}

/* ====== КРАФТ, СОЗДАНИЕ РЕЦЕПТОВ И ЛАВКА NPC ====== */
.craft-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px;
  margin-bottom: 8px;
  background: rgba(11, 17, 23, 0.62);
  border: 1px solid rgba(51, 65, 85, 0.88);
}

.craft-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 172px;
}

.craft-btn {
  padding: 6px 10px;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: bold;
  border: 1px solid #4ade80;
  background: #14532d;
  color: #f0fdf4;
  cursor: var(--cursor-action);
  text-align: center;
}

.craft-btn:hover:not(:disabled) {
  background: #15803d;
}

.craft-btn.recipe-scribe {
  border-color: #f59e0b;
  background: #451a03;
  color: #fde68a;
}

.craft-btn.recipe-scribe:hover:not(:disabled) {
  background: #78350f;
}

.craft-btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.ing-pill {
  display: inline-block;
  padding: 2px 6px;
  margin-right: 5px;
  margin-top: 4px;
  font-size: 0.73rem;
  border: 1px solid #475569;
  background: #1e293b;
}

.ing-pill.ok {
  border-color: #4ade80;
  color: #bbf7d0;
}

.ing-pill.missing {
  border-color: #f87171;
  color: #fecaca;
}

@media (max-width: 820px), (pointer: coarse) {
  /* iOS focuses inputs below 16px by zooming the entire page. */
  .pixel-input, .chat-input-row input, textarea { font-size: 16px; }
  .craft-row {
    flex-direction: column;
    align-items: stretch;
  }
  .craft-actions {
    flex-direction: row;
    min-width: 0;
  }
  .craft-actions .craft-btn {
    flex: 1;
  }
  .creator-grid, .trade-columns, .inventory-split-layout {
    grid-template-columns: 1fr;
  }
  #mobile-controls {
    display: block;
  }
  .chat-panel {
    display: none;
  }
  .hud-top-left {
    top: 6px;
    left: 6px;
    width: 53vw;
    min-width: 0;
    max-width: 230px;
    padding: 6px 7px;
  }
  .hero-title-line { font-size: 0.72rem; }
  .zone-pill { font-size: 0.60rem; margin-bottom: 3px; padding: 2px 4px; }
  .hud-zone-meta { flex-wrap: wrap; gap: 1px 5px !important; font-size: 0.61rem !important; }
  .hud-keyboard-hints { display: none; }
  .hud-top-right {
    top: 6px;
    right: 6px;
    width: 41vw;
    max-width: 165px;
    gap: 4px;
  }
  #minimap-canvas { width: 72px; height: 72px; }
  .hud-menu-buttons { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 3px; }
  .hud-btn { padding: 4px 2px; font-size: 0.62rem; line-height: 1.2; }
  #btn-interact-pc { display: none; }
  /* Normal gameplay notices go to chat; this compact single toast is used
     only above menus/modals, where the chat is not visible. */
  #toast-container { top:max(6px,env(safe-area-inset-top)); width:min(88vw,320px); gap:0; }
  #toast-container .toast { border-width:1px; padding:5px 8px; font-size:.72rem; line-height:1.25; }
}

/* Компактная карта связанного мира и легенда регионов. */
.atlas-scroll { overflow:auto; padding:8px; border:1px solid #415161; background:#0a1118; }
.atlas-grid { display:grid; gap:4px; width:max-content; margin:auto; }
.atlas-cell { width:125px; min-height:82px; padding:8px; border:1px solid #526171; background:#15251d; font-size:.68rem; line-height:1.3; }
.atlas-cell.snow { background:#435d68; } .atlas-cell.desert { background:#705438; }
.atlas-cell.steppe { background:#56603a; } .atlas-cell.swamp { background:#304b3a; }
.atlas-cell.current { outline:2px solid #facc15; outline-offset:-2px; }
.atlas-cell strong { display:block; color:#fff4c3; margin:4px 0; }
.atlas-cell span { color:#d4ded1; }
.atlas-empty { width:125px; min-height:82px; }

/* Туман атласа и контейнеры: содержимое видно лишь владельцу окна. */
.atlas-cell.fog {background:linear-gradient(140deg,#141c23,#26313a);color:#8b9ba5;border-color:#3b4853;display:flex;align-items:center;justify-content:center;flex-direction:column;}
.atlas-cell.fog strong {font-size:1.15rem;color:#94a3b8;margin:0;}
.container-columns {display:grid;grid-template-columns:1fr 1fr;gap:12px;}
.container-pane {min-width:0;border:1px solid #405464;background:rgba(10,18,24,.8);padding:10px;}
.container-pane h3 {margin:0 0 8px;font-size:.86rem;color:#fde68a;}
.container-item {display:flex;gap:8px;align-items:center;border-bottom:1px dashed #40515e;padding:7px 2px;cursor:var(--cursor-action);}
.container-item:last-child {border-bottom:0;}
.container-item:focus {outline:2px solid #fbbf24;}
.container-item .item-info {min-width:0;flex:1;font-size:.78rem;color:#fde68a;}
.container-item .item-info small {display:block;color:#aab9c3;margin-top:3px;}
.container-hint {color:#cbd5e1;font-size:.77rem;line-height:1.5;margin:0 0 10px;}
#death-banner {position:fixed;z-index:35;left:50%;top:12%;transform:translateX(-50%);background:rgba(50,8,12,.92);border:2px solid #f87171;color:#fee2e2;padding:12px 20px;text-align:center;font-weight:bold;box-shadow:0 8px 28px #0009;pointer-events:none;}
@media(max-width:650px) {.container-columns {grid-template-columns:1fr;} .container-pane {max-height:35vh;overflow:auto;} .container-item {padding:9px 2px;}}

/* Targeted construction stays visible over the world, including on touch screens. */
#placement-banner { position:fixed;z-index:35;left:50%;bottom:65px;transform:translateX(-50%);
  display:flex;align-items:center;justify-content:center;gap:10px;max-width:90vw;
  padding:9px 12px;background:rgba(15,23,30,.96);border:2px solid #e4b75b;
  color:#fff1c4;font-size:.82rem;box-shadow:0 4px 16px rgba(0,0,0,.45); }
#placement-banner .choice-btn { white-space:nowrap; }
.craft-tabs { display:flex;flex-wrap:wrap;gap:7px;margin:10px 0; }
.craft-tabs button { flex:1 1 auto;min-height:38px; }

/* Компактные, доступные кнопки и отдельная нижняя панель действий. */
.name-suggestion-row {display:flex;gap:7px;align-items:stretch;}
.name-suggestion-row .pixel-input {flex:1;min-width:0;}
.name-suggestion-row .choice-btn {white-space:nowrap;}
.hud-action-bar {position:fixed;z-index:19;bottom:10px;left:50%;transform:translateX(-50%);display:flex;gap:4px;max-width:calc(100vw - 20px);overflow-x:auto;padding:3px;background:rgba(9,15,20,.78);border:1px solid #6b5b3c;}
.hud-action-bar .hud-btn {position:relative;flex:0 0 43px;width:43px;height:43px;padding:0;font-size:1.2rem;line-height:1;}
.hud-action-bar .hud-btn.fire-skill {flex:0 0 auto;width:auto;min-width:84px;padding:0 8px;font-size:.72rem;white-space:nowrap;}
.hud-action-bar .hud-btn.fire-skill:disabled {opacity:.46;cursor:not-allowed;}
.hud-action-bar .hud-btn.fire-skill.active {border-color:#fb923c;background:#72350f;}
.hud-action-bar .hud-btn.water-skill {border-color:#7dd3fc;color:#d7f4ff;}
.hud-action-bar .hud-btn[hidden] {display:none!important;}
.hud-action-bar .hud-badge {position:absolute;right:1px;top:0;color:#fde68a;font-size:.64rem;text-shadow:1px 1px #000;}
.hud-action-bar .hud-btn:focus-visible,.chat-heading button:focus-visible {outline:2px solid #fde68a;outline-offset:2px;}
.container-item .mini-btn {width:auto;min-width:max-content;height:auto;min-height:32px;padding:5px 8px;white-space:nowrap;flex:none;}
.chat-panel {bottom:68px;}
.chat-heading {display:flex;align-items:center;justify-content:space-between;gap:8px;padding:4px 7px;border-bottom:1px solid #40515e;color:#fde68a;font-size:.72rem;}
.chat-heading button {border:0;background:none;color:#cbd5e1;font:inherit;cursor:var(--cursor-action);}
.chat-panel.collapsed .chat-messages {height:auto;min-height:26px;max-height:40px;overflow:hidden;}
.chat-panel.collapsed .chat-messages>div:not(:last-child),.chat-panel.collapsed .chat-input-row {display:none;}
.shop-transaction-fx {position:absolute;z-index:3;left:50%;top:16%;pointer-events:none;display:flex;align-items:center;gap:9px;max-width:min(85vw,440px);padding:9px 14px;border:2px solid #facc15;background:#14251a;color:#fef3c7;box-shadow:0 6px 24px #000b;font-weight:bold;font-size:.8rem;animation:shop-receipt 1.6s ease-out both;}
.shop-transaction-fx img {image-rendering:pixelated;animation:shop-buy-item .75s ease-out both;}
.shop-transaction-fx.sell img {animation-name:shop-sell-item;}
@keyframes shop-receipt {0%{opacity:0;transform:translate(-50%,16px) scale(.85)} 18%,72%{opacity:1;transform:translate(-50%,0) scale(1)} 100%{opacity:0;transform:translate(-50%,-22px) scale(1.03)}}
@keyframes shop-buy-item {0%{transform:translateX(-30px) rotate(-25deg) scale(.6)} 100%{transform:translateX(0) rotate(0) scale(1)}}
@keyframes shop-sell-item {0%{transform:translateX(30px) rotate(25deg) scale(.6)} 100%{transform:translateX(0) rotate(0) scale(1)}}
@media (prefers-reduced-motion:reduce) {.shop-transaction-fx,.shop-transaction-fx img {animation-duration:.01ms;animation-iteration-count:1}.shop-transaction-fx{animation-duration:1.5s;}}
@media (max-width:820px), (pointer:coarse) {
  .hud-action-bar {bottom:3px;gap:3px;padding:2px;}
  .hud-action-bar .hud-btn {display:block;flex-basis:36px;width:36px;height:36px;font-size:1rem;}
  #btn-interact-pc {display:block;}
  #joystick-zone {bottom:58px;}
  #mobile-action-btn {bottom:64px;}
  #mobile-attack-btn {bottom:158px;}
  .chat-panel {display:flex;top:85px;right:6px;bottom:auto;left:auto;width:min(43vw,230px);}
  .chat-messages {height:85px;font-size:.68rem;}
  .chat-heading {font-size:.65rem;}
  .chat-heading strong {min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
  .chat-heading button {font-size:0;min-width:28px;min-height:28px;padding:2px;}
  .chat-heading button::before {font-size:.9rem;}
  .chat-heading button[aria-expanded="false"]::before {content:'▴';}
  .chat-heading button[aria-expanded="true"]::before {content:'▾';}
  .chat-input-row input {min-width:0;}
}
.cave-coins {display:flex;gap:8px;align-items:center;flex-wrap:wrap;padding:8px 2px;color:#fcd34d;font-size:.8rem;border-bottom:1px dashed #40515e;}
.cave-coins .choice-btn {padding:5px 8px;font-size:.73rem;}

/* Clear, keyboard- and touch-accessible attack-mode state. */
.hud-action-bar #btn-attack-mode.active {background:#7f1d1d;border-color:#fb7185;box-shadow:inset 0 0 0 2px #fca5a5;}

/* The floating details can be scrolled on a small screen. JS puts them on
   the opposite side of the selected point, leaving a second tap unobstructed. */
#item-inspection:not([hidden]) {position:fixed;z-index:90;right:16px;top:10%;width:min(340px,calc(100vw - 32px));
  box-sizing:border-box;max-height:75vh;overflow-y:auto;overscroll-behavior:contain;touch-action:pan-y;padding:13px 36px 13px 14px;
  color:#e6edf0;background:rgba(15,25,31,.97);border:2px solid #d0a655;
  box-shadow:0 8px 24px #000a;font-size:.77rem;line-height:1.45;}
#item-inspection-close {position:sticky;top:0;float:right;margin-right:-30px;z-index:1;}
#item-inspection h3 {margin:0 0 6px;color:#fde68a;font-size:.88rem;}
#item-inspection .bad {color:#fca5a5;}
#item-inspection .good {color:#86efac;}
#item-inspection .scroll-hint {display:none;color:#aab9c4;font-size:.68rem;}
#item-inspection.has-overflow .scroll-hint {display:block;}
[data-inspect] {cursor:var(--cursor-action);}
@media(max-width:650px) {#item-inspection:not([hidden]) {right:8px;width:min(300px,calc(100vw - 16px));max-height:52vh;}}

/* Profession and people abilities remain available in the action menu. */
.hud-action-bar .skill-button {border-color:#bb9153;background:#303027;}
.hud-action-bar .skill-button:disabled {opacity:.48;}
.skill-badge {position:absolute;right:2px;bottom:1px;font-size:.58rem;line-height:1;color:#fff4c2;text-shadow:1px 1px 2px #000;}
.skill-window {max-width:470px;box-sizing:border-box;max-height:min(80vh,620px);overflow-y:auto;overscroll-behavior:contain;touch-action:pan-y;}
.skill-field {display:block;margin:12px 0;color:#e8dfcb;font-size:.82rem;}
.skill-field select {display:block;width:100%;max-width:100%;box-sizing:border-box;margin-top:5px;}
.skill-summary {border:1px solid #695a3e;background:#141c20;padding:10px;margin:10px 0;color:#d9e6df;line-height:1.5;font-size:.78rem;}
@media(max-width:650px) {.skill-window {padding:12px;max-height:78dvh;} .skill-field select {font-size:16px;}}

/* v23: On touch screens retain health, mana and danger status, and put the
   less frequently needed numbers behind a compact, labelled disclosure. */
#hud-details-toggle, #btn-more-actions {display:none;}
#hud-zone-compact {display:none;}
.hud-more-actions {display:contents;}
.hud-action-label {display:none;}
#hud-details-toggle:focus-visible, #btn-more-actions:focus-visible {outline:2px solid #fde68a;outline-offset:2px;}
@media (max-width:820px), (pointer:coarse) {
  .hud-top-left {
    top:max(4px,env(safe-area-inset-top,0px));left:max(4px,env(safe-area-inset-left,0px));
    width:min(52vw,220px);max-width:220px;padding:3px 5px;border-width:1px;
  }
  .hud-top-left:not(.hud-details-open) .hud-detail {display:none!important;}
  .hero-title-line {min-height:28px;margin-bottom:1px;gap:3px;font-size:.69rem;}
  #hud-name {min-width:0;flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
  #hud-level {flex:none;white-space:nowrap;}
  #hud-details-toggle {
    display:block;flex:none;width:28px;height:28px;padding:0;
    font:700 18px/1 'Courier New',monospace;color:#fde68a;background:#202b30;
    border:1px solid #a1854e;cursor:var(--cursor-action);
  }
  #hud-details-toggle.weight-warning {position:relative;border-color:#fb923c;color:#fdba74;}
  #hud-details-toggle.weight-warning::after {content:'!';position:absolute;right:0;top:0;font:700 10px/1 monospace;color:#fff0bc;}
  .hud-top-left .zone-pill {display:block;width:100%;margin:0 0 2px;padding:1px 3px;
    overflow:hidden;white-space:nowrap;font-size:.60rem;line-height:1.25;}
  #hud-zone-compact {display:flex;min-width:0;}
  #hud-zone-status {flex:none;white-space:nowrap;}
  #hud-zone-location {min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
  #hud-zone-full {display:none;}
  .hud-top-left.hud-details-open .zone-pill {white-space:normal;}
  .hud-top-left.hud-details-open #hud-zone-compact {display:none;}
  .hud-top-left.hud-details-open #hud-zone-full {display:inline;}
  .hud-top-left .bar-wrap:not(.hud-detail) {height:13px;margin-bottom:2px;}
  .hud-top-left .bar-label {font-size:.62rem;}
  .hud-top-right {top:max(4px,env(safe-area-inset-top,0px));right:max(4px,env(safe-area-inset-right,0px));}
  .chat-panel.collapsed .chat-messages {min-height:0;max-height:24px;padding:3px 5px;}
  .chat-panel.collapsed .chat-messages>div:last-child {white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}

  /* Seven normally visible actions, with an eighth slot only near a fire.
     No horizontal scrollbar; the sheet opens only on demand. */
  .hud-action-bar {
    --hud-action-size:min(44px,calc((100vw - 36px)/7));
    z-index:25;bottom:max(3px,env(safe-area-inset-bottom,0px));
    gap:3px;padding:2px;max-width:calc(100vw - 8px);overflow:visible;
  }
  .hud-action-bar.has-fire {--hud-action-size:min(44px,calc((100vw - 38px)/8));}
  .hud-action-bar > .hud-btn, .hud-action-bar > .hud-more-toggle {
    display:block;position:relative;flex:0 0 var(--hud-action-size);
    width:var(--hud-action-size);height:var(--hud-action-size);padding:0;
    font-size:1.08rem;line-height:1;
  }
  .hud-action-bar > .hud-btn[hidden] {display:none!important;}
  .hud-action-bar > .hud-btn.fire-skill {min-width:0;white-space:normal;}
  .hud-action-bar .fire-text {display:none;}
  .hud-action-bar .fire-count {position:absolute;right:2px;bottom:1px;font-size:.60rem;color:#fff;text-shadow:1px 1px #000;}
  #btn-more-actions {
    display:flex;align-items:center;justify-content:center;flex-direction:column;
    color:#fde68a;background:#202b30;border:2px solid #aa8c4f;
    font:700 1.15rem/1 'Courier New',monospace;cursor:var(--cursor-action);
  }
  #btn-more-actions span {font-size:.57rem;line-height:1;}
  #btn-more-actions[aria-expanded="true"] {background:#544326;border-color:#fde68a;}
  .hud-more-actions {display:none;}
  .hud-action-bar.more-open .hud-more-actions {
    position:absolute;right:0;bottom:calc(100% + 7px);display:grid;
    grid-template-columns:repeat(3,minmax(0,1fr));gap:4px;
    width:min(288px,calc(100vw - 16px));padding:5px;
    background:rgba(12,19,24,.97);border:1px solid #a1854e;box-shadow:0 6px 18px #000a;
  }
  .hud-action-bar .hud-more-actions .hud-btn {
    display:flex;position:relative;align-items:center;justify-content:center;flex-direction:column;
    width:auto;min-width:0;height:51px;padding:3px;gap:3px;font-size:1rem;line-height:1;
  }
  .hud-more-actions .hud-action-label {display:block;font-size:.61rem;line-height:1;white-space:nowrap;}
  .hud-more-actions .skill-badge {top:2px;bottom:auto;right:3px;}
}
