:root {
  --bg: #050304;
  --panel: #120a0c;
  --panel2: #1a0e12;
  --border: #4a2018;
  --border-lit: #8b3a22;
  --text: #e8dcc8;
  --muted: #8a7a6a;
  --gold: #c9a227;
  --gold-bright: #f0d060;
  --blood: #8b1515;
  --life: #a01818;
  --mana: #1a3a8a;
  --mana-bright: #3d6fd4;
  --common: #9d9d9d;
  --rare: #4a7dff;
  --epic: #a335ee;
  --legendary: #e0a40f;
  --mythic: #e33232;
  --unique: #ffffff;
  --font-display: "Cinzel", Georgia, serif;
  --font-ui: "Roboto Condensed", system-ui, sans-serif;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  overflow: hidden;
  user-select: none;
}

#app { height: 100%; position: relative; }

/* Build version — bottom left, non-interactive */
.app-version {
  position: fixed;
  left: max(0.55rem, env(safe-area-inset-left));
  bottom: max(0.4rem, env(safe-area-inset-bottom));
  z-index: 100;
  pointer-events: none;
  font-family: var(--font-ui);
  font-size: 0.68rem;
  font-weight: 400;
  letter-spacing: 0.06em;
  color: #6a6a6a;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.85);
  opacity: 0.85;
  user-select: none;
}

.screen {
  display: none;
  height: 100%;
  width: 100%;
  position: relative;
}

.screen.active { display: flex; }

/* ─── Title ─── */
#screen-title {
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(140, 20, 10, 0.35), transparent 55%),
    radial-gradient(ellipse at 50% 100%, rgba(40, 10, 5, 0.9), transparent 40%),
    linear-gradient(180deg, #1a0808, #050304 70%);
}

.blood-vignette {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at center, transparent 30%, rgba(0,0,0,0.75) 100%);
  pointer-events: none;
}

.title-card {
  position: relative;
  text-align: center;
  z-index: 1;
  padding: 2rem;
  animation: fadeUp 0.9s ease;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: none; }
}

.eyebrow {
  color: var(--blood);
  letter-spacing: 0.35em;
  text-transform: uppercase;
  font-size: 0.75rem;
  margin-bottom: 0.5rem;
}

.title-card h1 {
  font-family: var(--font-display);
  font-size: clamp(3.2rem, 10vw, 5.5rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  background: linear-gradient(180deg, #fff2d0 0%, #c9a227 40%, #8b1515 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 4px 20px rgba(139, 21, 21, 0.6));
  line-height: 1;
}

.tagline {
  color: var(--muted);
  margin: 1rem 0 2rem;
  font-size: 1.1rem;
  letter-spacing: 0.04em;
}

.title-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* Co-op lobby */
.multi-panel {
  width: min(480px, 94vw);
  padding: 1.25rem 1.35rem 1.4rem;
  max-height: 92vh;
  overflow: auto;
}
.mp-actions {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin: 0.85rem 0 0.5rem;
}
.mp-join-row {
  display: flex;
  gap: 0.45rem;
}
.mp-join-row input {
  flex: 1;
  text-align: center;
  letter-spacing: 0.35em;
  font-size: 1.15rem;
  font-weight: 700;
  font-family: var(--font-display);
  text-transform: uppercase;
  background: #0a0404;
  border: 1px solid var(--border);
  color: var(--gold-bright);
  padding: 0.55rem 0.6rem;
}
.net-status {
  font-size: 0.8rem;
  color: var(--muted);
  min-height: 1.2em;
  margin: 0.35rem 0 0.5rem;
}
.net-status[data-state="hosting"],
.net-status[data-state="joined"] { color: #40ff80; }
.net-status[data-state="error"],
.net-status[data-state="disconnected"] { color: #ff6060; }
.net-status[data-state="connecting"] { color: #f0d060; }
.mp-room-hint strong {
  color: var(--gold-bright);
  letter-spacing: 0.2em;
  font-size: 1.1rem;
}
.net-badge {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #70b8ff;
  border: 1px solid #4080c0;
  background: rgba(20, 40, 70, 0.7);
  padding: 0.2rem 0.45rem;
  white-space: nowrap;
}
.net-badge.hidden { display: none; }

.hint {
  margin-top: 1.75rem;
  color: var(--muted);
  font-size: 0.82rem;
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
  line-height: 1.45;
}

/* ─── Buttons ─── */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, #2a1410, #140808);
  color: var(--text);
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.75rem 1.4rem;
  cursor: pointer;
  transition: border-color 0.12s, box-shadow 0.12s, transform 0.1s;
}

.btn:hover:not(:disabled) {
  border-color: var(--border-lit);
  box-shadow: 0 0 12px rgba(139, 58, 34, 0.4);
  transform: translateY(-1px);
}

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

.btn.primary {
  background: linear-gradient(180deg, #6b1810, #3a0a08);
  border-color: #a03020;
  color: #f0d0a0;
}

.btn.primary:hover:not(:disabled) {
  box-shadow: 0 0 18px rgba(160, 40, 20, 0.55);
}

.btn.ghost { background: transparent; }

.btn.tiny {
  padding: 0.3rem 0.55rem;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
}

/* ─── Create ─── */
#screen-create {
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, #1a0a0a, #050304);
}

.create-panel {
  width: min(640px, 94vw);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.5rem;
}

.create-panel h2,
.end-panel h2 {
  font-family: var(--font-display);
  text-align: center;
  color: var(--gold);
  letter-spacing: 0.1em;
}

.panel {
  background: linear-gradient(180deg, rgba(30, 12, 12, 0.97), rgba(12, 6, 6, 0.98));
  border: 1px solid var(--border);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7), inset 0 0 40px rgba(0, 0, 0, 0.4);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field span {
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.field input {
  background: #0a0404;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.7rem 0.9rem;
  font-size: 1.05rem;
  font-family: var(--font-ui);
}

.field input:focus {
  outline: none;
  border-color: var(--border-lit);
}

.class-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
}

.class-card {
  border: 1px solid var(--border);
  padding: 1rem 0.7rem;
  text-align: center;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.35);
  transition: border-color 0.15s, background 0.15s;
}

.class-card:hover { border-color: var(--border-lit); }

.class-card.selected {
  border-color: var(--gold);
  background: rgba(201, 162, 39, 0.08);
  box-shadow: inset 0 0 0 1px rgba(201, 162, 39, 0.25);
}

.class-card .icon {
  font-size: 2rem;
  margin-bottom: 0.4rem;
  filter: grayscale(0.2);
}

.class-card h4 {
  font-family: var(--font-display);
  font-size: 0.95rem;
  color: var(--gold-bright);
  margin-bottom: 0.35rem;
}

.class-card p {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}
.skin-picker { display:flex; gap:.45rem; align-items:center; justify-content:center; color:var(--muted); }
.skin { border:1px solid var(--border); background:#120808; color:var(--text); padding:.45rem .7rem; cursor:pointer; }
.skin.selected { border-color:var(--gold); color:var(--gold-bright); }

/* ─── Shop ─── */
.shop-grid { display:flex; flex-direction:column; gap:.45rem; margin-top:.7rem; }
.shop-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  text-align: left;
  padding: 0.5rem 0.55rem;
  border: 1px solid var(--border);
  background: #090404;
  color: var(--text);
  cursor: pointer;
  font-family: var(--font-ui);
  position: relative;
}
.shop-item:hover { border-color: var(--gold); }
.shop-item:disabled { opacity: 0.45; cursor: default; }
.shop-item strong { color: var(--gold-bright); white-space: nowrap; font-size: 0.8rem; }
.shop-item.special {
  border-color: var(--legendary);
  background: linear-gradient(180deg, rgba(224, 164, 15, 0.14), #0c0505 70%);
  box-shadow: 0 0 12px rgba(224, 164, 15, 0.25), inset 0 0 10px rgba(224, 164, 15, 0.08);
}
.shop-mid { display: flex; flex-direction: column; gap: 0.15rem; flex: 1; min-width: 0; }
.shop-name { font-size: 0.82rem; font-weight: 700; }
.shop-stats { font-size: 0.68rem; color: var(--muted); line-height: 1.3; }
.shop-emoji { font-size: 1.4rem; }
.shop-panel { right: auto; left: 12px; width: min(400px, 94vw); }
.shop-price { flex-shrink: 0; min-width: 3.2rem; text-align: right; }

/* ─── 3D sprite icons ─── */
canvas.icon3d { display: inline-block; vertical-align: middle; pointer-events: none; }
.inv-icon { width: 80%; height: 80%; }
.equip-icon { width: 26px; height: 26px; margin-right: 4px; }
.equip-line { display: flex; align-items: center; }
.shop-icon { width: 42px; height: 42px; flex-shrink: 0; }
.class-icon { width: 76px; height: 76px; margin-bottom: 0.3rem; }
.belt-icon { width: 28px; height: 28px; }

/* ─── Boss indicator ─── */
.boss-status {
  color: #ff5040;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  margin-left: 0.5rem;
  text-shadow: 0 0 8px rgba(255, 40, 20, 0.7);
  animation: bossPulse 1.1s ease-in-out infinite;
}
.boss-status.hidden { display: none; }

@keyframes bossPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.panel-header-actions { display: flex; gap: 0.35rem; align-items: center; }

/* ─── Game ─── */
#screen-game {
  display: none;
  background: #000;
  position: relative;
  overflow: hidden;
}

#screen-game.active {
  display: block;
}

/* Transparent WebGL prop/light overlay — above world canvas, below HUD */
#game-3d {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
  z-index: 2;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.15s ease;
  background: transparent;
}
#game-3d.active {
  opacity: 1;
  visibility: visible;
}

#game {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  background: #0a0608;
  touch-action: none;
  z-index: 1;
}
/* Canvas always owns the map; 3D only adds props/glows on top */
#screen-game.world3d-on #game {
  background: #0a0608;
}

/* HUD top */
.hud-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 1rem;
  pointer-events: none;
  z-index: 10;
  background: linear-gradient(180deg, rgba(0,0,0,0.65), transparent);
}

.hud-top-right {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  pointer-events: auto;
}

.area-name {
  font-family: var(--font-display);
  color: var(--gold);
  letter-spacing: 0.08em;
  font-size: 0.95rem;
  text-shadow: 0 2px 8px #000;
}

.gold-display {
  color: var(--gold-bright);
  font-weight: 700;
  margin-right: 0.5rem;
  text-shadow: 0 1px 4px #000;
}

/* Bottom HUD */
.hud-bottom {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 0.5rem;
  padding: 0 1rem 0.6rem;
  pointer-events: none;
  z-index: 10;
  background: linear-gradient(0deg, rgba(0,0,0,0.85) 0%, rgba(0,0,0,0.4) 60%, transparent 100%);
}

.orb {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  border: 3px solid rgba(180, 140, 80, 0.55);
  position: relative;
  overflow: hidden;
  /* Glass rim */
  background:
    radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.22), transparent 42%),
    radial-gradient(circle at 70% 75%, rgba(0, 0, 0, 0.35), transparent 55%),
    #0a0404;
  box-shadow:
    0 0 22px rgba(0, 0, 0, 0.85),
    inset 0 0 18px rgba(0, 0, 0, 0.55),
    inset 0 2px 8px rgba(255, 255, 255, 0.12);
  pointer-events: auto;
  flex-shrink: 0;
}
.orb::before {
  /* Glass shine arc */
  content: "";
  position: absolute;
  inset: 6%;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 -10px 18px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  z-index: 3;
}
.orb::after {
  /* Top specular highlight */
  content: "";
  position: absolute;
  left: 18%;
  top: 10%;
  width: 42%;
  height: 28%;
  border-radius: 50%;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.35), transparent);
  pointer-events: none;
  z-index: 4;
}

.orb-life {
  border-color: rgba(160, 50, 40, 0.7);
  box-shadow:
    0 0 28px rgba(160, 20, 20, 0.4),
    inset 0 0 18px rgba(0, 0, 0, 0.55),
    inset 0 2px 8px rgba(255, 200, 180, 0.1);
}

.orb-mana {
  border-color: rgba(60, 90, 180, 0.65);
  box-shadow:
    0 0 28px rgba(40, 80, 200, 0.35),
    inset 0 0 18px rgba(0, 0, 0, 0.55),
    inset 0 2px 8px rgba(180, 200, 255, 0.1);
}

.orb-fill {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  transition: height 0.15s linear;
  z-index: 1;
}

.orb-life .orb-fill {
  /* Liquid meniscus + depth */
  background:
    linear-gradient(180deg, rgba(255, 160, 120, 0.55) 0%, transparent 14%),
    linear-gradient(180deg, #ff5050 0%, #e02828 35%, #6a0808 100%);
  box-shadow:
    0 0 18px rgba(220, 40, 40, 0.55),
    inset 0 4px 10px rgba(255, 200, 160, 0.25);
  border-radius: 0 0 50% 50% / 0 0 12% 12%;
}

.orb-mana .orb-fill {
  background:
    linear-gradient(180deg, rgba(160, 200, 255, 0.55) 0%, transparent 14%),
    linear-gradient(180deg, #60a0ff 0%, #3060e0 35%, #102860 100%);
  box-shadow:
    0 0 18px rgba(60, 120, 255, 0.5),
    inset 0 4px 10px rgba(180, 210, 255, 0.25);
  border-radius: 0 0 50% 50% / 0 0 12% 12%;
}

.orb-text {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 1.05rem;
  text-shadow: 0 1px 4px #000, 0 0 8px rgba(0, 0, 0, 0.6);
  z-index: 5;
}

.orb-label {
  position: absolute;
  bottom: 6px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.55rem;
  letter-spacing: 0.15em;
  color: rgba(255,255,255,0.55);
  z-index: 2;
}

.hud-center {
  flex: 1;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  pointer-events: auto;
  padding-bottom: 0.25rem;
}

.xp-bar {
  width: 100%;
  height: 14px;
  background: #0a0604;
  border: 1px solid #4a3020;
  position: relative;
  overflow: hidden;
}

.xp-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #3a5a10, #8ab820);
  transition: width 0.2s;
}

.xp-bar span {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  color: #e8e0c0;
  text-shadow: 0 1px 2px #000;
}

.skill-bar {
  display: flex;
  gap: 0.35rem;
}

.skill-slot {
  width: 48px;
  height: 48px;
  border: 2px solid #5a3018;
  background: linear-gradient(180deg, #1a0c08, #0a0404);
  position: relative;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 1.35rem;
  box-shadow: inset 0 0 10px rgba(0,0,0,0.6);
}

.skill-slot:hover,
.skill-slot.active {
  border-color: var(--gold);
  box-shadow: 0 0 10px rgba(201, 162, 39, 0.4);
}

.skill-slot .key {
  position: absolute;
  top: 1px;
  left: 3px;
  font-size: 0.55rem;
  color: var(--gold);
  font-weight: 700;
}

.skill-slot .rank {
  position: absolute;
  right: 3px;
  bottom: 1px;
  color: var(--gold-bright);
  font-size: 0.58rem;
  font-weight: 700;
  text-shadow: 0 1px 2px #000;
}

.skill-slot .cd {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: grid;
  place-items: center;
  font-size: 0.75rem;
  color: #fff;
  font-weight: 700;
}

.skill-slot.ready-flash {
  animation: readyPulse 0.3s ease;
}

@keyframes readyPulse {
  from { box-shadow: 0 0 16px rgba(201, 162, 39, 0.8); }
  to { box-shadow: none; }
}

.belt {
  display: flex;
  gap: 0.25rem;
}

.belt-slot {
  width: 36px;
  height: 36px;
  border: 1px solid #4a2818;
  background: #0c0604;
  display: grid;
  place-items: center;
  font-size: 1rem;
  position: relative;
  cursor: pointer;
}

.belt-slot .qty {
  position: absolute;
  bottom: 0;
  right: 2px;
  font-size: 0.6rem;
  color: #fff;
  font-weight: 700;
}

.belt-slot .key {
  position: absolute;
  top: 0;
  left: 2px;
  font-size: 0.5rem;
  color: var(--muted);
}

.controls-mini {
  font-size: 0.65rem;
  color: var(--muted);
  letter-spacing: 0.03em;
}

/* Side panels */
.side-panel {
  position: absolute;
  top: 48px;
  right: 12px;
  width: min(320px, 92vw);
  max-height: calc(100% - 180px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  z-index: 20;
  padding: 0.85rem;
  pointer-events: auto;
}

.side-panel.left {
  right: auto;
  left: 12px;
}

#panel-char {
  width: min(360px, 92vw);
  max-height: calc(100% - 145px);
}
#panel-char .char-stats,
#panel-quests .quest-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.side-panel.hidden { display: none; }

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.4rem;
  flex-shrink: 0;
}
.side-panel > .panel-hint {
  flex-shrink: 0;
}

.panel-header h3 {
  font-family: var(--font-display);
  color: var(--gold);
  letter-spacing: 0.1em;
  font-size: 1rem;
}

.inv-panel { width: min(360px, 94vw); }

/* Single scroll body for gear + bag (no nested equip scroller) */
.inv-scroll {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1 1 auto;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.shop-scroll {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1 1 auto;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.shop-scroll .shop-grid { margin-top: 0.35rem; }

.equip-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  margin-bottom: 0.55rem;
  /* Never its own scroller — scrolls with .inv-scroll */
  overflow: visible;
  max-height: none;
}

.inv-capacity {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
  font-size: 0.78rem;
  color: var(--muted);
  flex-wrap: wrap;
}
.inv-cap-text { font-weight: 700; color: var(--text); }
.inv-cap-actions { display: flex; gap: 0.3rem; flex-wrap: wrap; }

#btn-quests.has-ready {
  color: #ffd060;
  border-color: var(--gold);
  box-shadow: 0 0 8px rgba(240, 200, 60, 0.4);
  animation: bossPulse 1.2s ease-in-out infinite;
}

.quest-panel { width: min(380px, 94vw); }
.quest-list { display: flex; flex-direction: column; gap: 0.5rem; }
.quest-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}
.quest-count { font-size: 0.75rem; color: var(--muted); }
.quest-row {
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.4);
  padding: 0.5rem 0.55rem;
}
.quest-row.ready {
  border-color: var(--gold);
  background: linear-gradient(180deg, rgba(224, 164, 15, 0.12), rgba(0, 0, 0, 0.45));
}
.quest-row.claimed { opacity: 0.55; }
.quest-top {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.88rem;
}
.quest-prog { color: var(--gold-bright); font-weight: 700; font-size: 0.8rem; }
.quest-desc { color: var(--muted); font-size: 0.75rem; margin: 0.2rem 0 0.35rem; }
.quest-bar {
  height: 5px;
  background: #1a0a08;
  border: 1px solid #3a2010;
  margin-bottom: 0.35rem;
}
.quest-fill {
  height: 100%;
  background: linear-gradient(90deg, #8b3a22, #c9a227);
  transition: width 0.25s ease;
}
.quest-reward {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  color: var(--text);
}
.quest-done { color: #40ff40; font-weight: 700; }

.equip-slot {
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.4);
  padding: 0.45rem;
  min-height: 52px;
  cursor: pointer;
  font-size: 0.8rem;
}

.equip-slot .slot-name {
  color: var(--muted);
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 0.2rem;
}

.inv-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 3px;
  margin-bottom: 0.5rem;
}

.inv-cell {
  aspect-ratio: 1;
  border: 1px solid #3a2010;
  background: rgba(0,0,0,0.45);
  display: grid;
  place-items: center;
  font-size: 1.1rem;
  cursor: pointer;
  position: relative;
}

.inv-cell:hover { border-color: var(--gold); }
.inv-cell.empty { opacity: 0.5; }

.inv-cell .rarity-dot {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
}

.inv-cell .qty {
  position: absolute;
  bottom: 1px;
  left: 3px;
  font-size: 0.62rem;
  color: #fff;
  font-weight: 700;
  text-shadow: 0 1px 2px #000;
  z-index: 2;
}

.panel-hint {
  color: var(--muted);
  font-size: 0.72rem;
  text-align: center;
}

.char-stats {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.9rem;
}

.char-stats .row {
  display: flex;
  justify-content: space-between;
  padding: 0.3rem 0.4rem;
  background: rgba(0,0,0,0.3);
  border-left: 2px solid var(--border);
}

.char-stats .row.highlight {
  border-left-color: var(--gold);
  color: var(--gold-bright);
}

.char-stats .section {
  font-family: var(--font-display);
  color: var(--gold);
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  margin-top: 0.5rem;
  margin-bottom: 0.15rem;
}

.points-title { display: flex; justify-content: space-between; align-items: center; }
.points-title b { color: var(--gold-bright); font-family: var(--font-ui); letter-spacing: 0; }
.upgrade-row > span:last-child,
.skill-upgrade > span:last-child { display: flex; align-items: center; gap: 0.45rem; }
.skill-upgrade > span:first-child { display: flex; flex-direction: column; }
.skill-upgrade small { color: var(--muted); font-size: 0.68rem; margin-top: 0.12rem; }
.point-btn {
  width: 24px;
  height: 24px;
  border: 1px solid var(--gold);
  background: #301008;
  color: var(--gold-bright);
  font-weight: 700;
  cursor: pointer;
}
.point-btn:disabled { opacity: 0.3; cursor: default; }

/* Tooltip */
.tooltip {
  position: absolute;
  z-index: 50;
  pointer-events: none;
  background: rgba(10, 4, 4, 0.95);
  border: 1px solid var(--border);
  padding: 0.55rem 0.7rem;
  max-width: 240px;
  font-size: 0.82rem;
  box-shadow: 0 8px 24px rgba(0,0,0,0.7);
  line-height: 1.4;
}

.tooltip.hidden { display: none; }

.tooltip .name { font-weight: 700; margin-bottom: 0.25rem; }
.tooltip .meta { color: var(--muted); font-size: 0.75rem; }
.tooltip .stat { color: #a0c0ff; }

.rarity-common { color: var(--common); }
.rarity-rare { color: var(--rare); }
.rarity-epic { color: var(--epic); }
.rarity-legendary { color: var(--legendary); }
.rarity-mythic { color: var(--mythic); }

/* Rainbow (unique rarity) — animated hue cycle */
.rainbow-text {
  background: linear-gradient(90deg, #ff4040, #ffb040, #f0ff50, #50ff70, #40c0ff, #b060ff, #ff4040);
  background-size: 300% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: rainbowShift 3s linear infinite;
  font-weight: 700;
}

@keyframes rainbowShift {
  from { background-position: 0% 0; }
  to { background-position: 300% 0; }
}

.rainbow-dot {
  background: conic-gradient(#ff4040, #ffb040, #f0ff50, #50ff70, #40c0ff, #b060ff, #ff4040);
  animation: rainbowSpin 2.5s linear infinite;
}

@keyframes rainbowSpin {
  from { filter: hue-rotate(0deg); }
  to { filter: hue-rotate(360deg); }
}

/* Pickup toast */
.pickup-toast {
  position: absolute;
  top: 56px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  font-weight: 700;
  font-size: 0.95rem;
  text-shadow: 0 2px 6px #000;
  pointer-events: none;
  animation: toastIn 0.25s ease;
}

.pickup-toast.hidden { display: none; }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* Overlay */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: grid;
  place-items: center;
  z-index: 40;
}

.overlay.hidden { display: none; }

.end-panel {
  width: min(420px, 92vw);
  padding: 1.5rem;
  text-align: center;
}

.end-panel p {
  color: var(--muted);
  margin: 0.75rem 0 1.1rem;
  line-height: 1.5;
}

.end-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  margin-bottom: 1.25rem;
  text-align: left;
}

.end-stats div {
  background: rgba(0,0,0,0.35);
  padding: 0.5rem 0.65rem;
  font-size: 0.88rem;
}

.end-stats span {
  display: block;
  color: var(--muted);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Sell button */
.sell-btn {
  position: absolute;
  bottom: 1px;
  left: 1px;
  right: 1px;
  padding: 2px 0;
  font-size: 0.55rem;
  font-weight: 700;
  font-family: var(--font-ui);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gold-bright);
  background: linear-gradient(180deg, rgba(80, 40, 10, 0.92), rgba(30, 12, 5, 0.95));
  border: 1px solid var(--gold);
  border-bottom: none;
  cursor: pointer;
  z-index: 3;
  transition: background 0.12s, box-shadow 0.12s;
}
.sell-btn:hover {
  background: linear-gradient(180deg, rgba(140, 80, 20, 0.95), rgba(60, 25, 8, 0.95));
  box-shadow: 0 0 8px rgba(201, 162, 39, 0.5);
}

.equip-slot .sell-btn {
  position: relative;
  bottom: auto;
  left: auto;
  right: auto;
  margin-top: 4px;
  display: block;
  text-align: center;
  border: 1px solid var(--gold);
  padding: 3px 6px;
}

/* Item comparison tooltip */
.item-tooltip {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  background: rgba(8, 3, 4, 0.96);
  border: 1px solid var(--border-lit);
  padding: 0.6rem 0.75rem;
  max-width: 260px;
  min-width: 160px;
  font-size: 0.8rem;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.8), inset 0 0 16px rgba(0, 0, 0, 0.3);
  line-height: 1.5;
  font-family: var(--font-ui);
}

.item-tooltip .tt-name {
  font-weight: 700;
  font-size: 0.88rem;
  margin-bottom: 0.3rem;
}

.item-tooltip .tt-rarity {
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 0.35rem;
  opacity: 0.75;
}

.item-tooltip .tt-slot {
  font-size: 0.68rem;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 0.35rem;
}

.item-tooltip .tt-stat {
  display: flex;
  justify-content: space-between;
  padding: 1px 0;
}

.item-tooltip .tt-stat .tt-label {
  color: var(--muted);
}

.item-tooltip .tt-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.35rem 0;
}

.item-tooltip .tt-price {
  color: var(--gold-bright);
  font-size: 0.75rem;
  margin-top: 0.25rem;
}

.item-tooltip .tt-vs {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  font-size: 0.75rem;
  font-weight: 700;
}

.item-tooltip .tt-vs-name {
  color: var(--muted);
  font-weight: 400;
  font-size: 0.68rem;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 150px;
}

.stat-better { color: #40ff40 !important; }
.stat-worse { color: #ff4040 !important; }
.stat-neutral { color: var(--text); }
.crit-stat { color: #ffd040 !important; text-shadow: 0 0 8px rgba(255, 200, 40, 0.35); }
.char-stats small { font-weight: 400; opacity: 0.85; font-size: 0.75em; }
.item-tooltip .tt-delta { font-weight: 700; margin-left: 0.25rem; opacity: 0.95; }
.shop-stats .stat-better,
.shop-stats .stat-worse { font-weight: 700; }

/* Save / load slots */
.saves-panel {
  width: min(520px, 94vw);
  max-height: 80vh;
  overflow: auto;
  padding: 1rem 1.1rem 1.2rem;
}
.save-slots {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin-top: 0.6rem;
}
.save-slot {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  gap: 0.55rem;
  align-items: center;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.45);
  padding: 0.55rem 0.65rem;
}
.save-slot.empty { opacity: 0.75; }
.save-slot-num {
  font-family: var(--font-display);
  color: var(--gold);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
}
.save-slot-info {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
}
.save-slot-info strong {
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.save-slot-info small { color: var(--muted); font-size: 0.72rem; }
.save-slot-time { opacity: 0.8; }
.save-slot-meta { color: var(--muted); font-size: 0.8rem; }
.save-slot-actions { display: flex; gap: 0.3rem; flex-wrap: wrap; justify-content: flex-end; }
.save-slot-empty { color: var(--muted); font-size: 0.85rem; }

/* ─── Mobile touch controls (ML-style skill wheel) ─── */
.touch-controls {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 15;
}
.touch-controls.hidden { display: none; }

.touch-stick {
  position: absolute;
  left: max(10px, env(safe-area-inset-left));
  bottom: max(88px, calc(env(safe-area-inset-bottom) + 72px));
  width: 112px;
  height: 112px;
  pointer-events: auto;
  touch-action: none;
}
.stick-base {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 2px solid rgba(201, 162, 39, 0.45);
  background: rgba(8, 3, 4, 0.35);
  position: relative;
}
.stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #c9a227, #5a2818);
  border: 2px solid rgba(240, 208, 96, 0.7);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
  transition: transform 0.05s linear;
}
.touch-stick.active .stick-base {
  border-color: rgba(240, 208, 96, 0.85);
  background: rgba(20, 8, 6, 0.5);
}

/* Right-side skill wheel (inspired by Mobile Legends) */
.touch-actions.ml-wheel {
  position: absolute;
  right: max(6px, env(safe-area-inset-right));
  /* Extra height so potions/Run under Atk still clear the HUD orbs */
  bottom: max(92px, calc(env(safe-area-inset-bottom) + 78px));
  width: 168px;
  height: 220px;
  pointer-events: none;
  touch-action: none;
}
.skill-arc {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.touch-btn {
  position: absolute;
  min-width: 52px;
  min-height: 52px;
  border-radius: 50%;
  border: 2px solid rgba(201, 162, 39, 0.55);
  background: rgba(10, 4, 4, 0.82);
  color: var(--text);
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 0.85rem;
  pointer-events: auto;
  touch-action: none;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.55);
  display: grid;
  place-items: center;
  padding: 0;
}
.touch-btn.skill {
  width: 54px;
  height: 54px;
  min-width: 54px;
  min-height: 54px;
  font-size: 1.15rem;
}
/* Arc positions around the big attack button */
.touch-btn.sk-1 { left: 4px;   top: 58px; }
.touch-btn.sk-2 { left: 28px;  top: 8px; }
.touch-btn.sk-3 { left: 78px;  top: 0; }
.touch-btn.sk-4 { left: 118px; top: 32px; }
.touch-btn.sk-5 { left: 118px; top: 88px; }

.touch-btn.atk {
  left: 52px;
  top: 52px;
  width: 72px;
  height: 72px;
  min-width: 72px;
  min-height: 72px;
  background: radial-gradient(circle at 40% 35%, #c03020, #501008 70%);
  border-color: #e05030;
  font-size: 1rem;
  letter-spacing: 0.04em;
  z-index: 2;
  box-shadow: 0 0 16px rgba(200, 40, 20, 0.45), 0 4px 14px rgba(0, 0, 0, 0.6);
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, color 0.15s;
}
/* Near NPC: Atk becomes Talk / Interact */
.touch-btn.atk.interact {
  background: radial-gradient(circle at 40% 35%, #c9a227, #5a3810 70%);
  border-color: #f0d060;
  color: #fff4d0;
  font-size: 0.92rem;
  box-shadow: 0 0 18px rgba(240, 200, 60, 0.55), 0 4px 14px rgba(0, 0, 0, 0.6);
}
/* Potions + Run under Atk (same pad style as skills) */
.touch-btn.run,
.touch-btn.potion {
  width: 48px;
  height: 48px;
  min-width: 48px;
  min-height: 48px;
  font-size: 0.85rem;
  z-index: 2;
}
.touch-btn.pot-hp { left: 18px;  top: 138px; }
.touch-btn.pot-mp { left: 68px;  top: 152px; }
.touch-btn.run    { left: 118px; top: 138px; }
.touch-btn.run { border-color: var(--gold); color: var(--gold-bright); }
/* Legacy selector no longer used — keep harmless */
#touch-side,
.touch-side { display: none !important; }
.touch-btn .sk-icon { font-size: 1.2rem; line-height: 1; }
.touch-btn .sk-key {
  position: absolute;
  top: 2px;
  left: 5px;
  font-size: 0.55rem;
  opacity: 0.7;
}
.touch-btn .sk-cd {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.62);
  font-size: 0.85rem;
  color: #fff;
  font-weight: 700;
}
.touch-btn.on-cd { opacity: 0.85; }
.touch-btn.active-skill {
  border-color: #f0d060;
  box-shadow: 0 0 14px rgba(240, 200, 60, 0.55);
}
.touch-btn.active,
.touch-btn:active {
  transform: scale(0.92);
  border-color: var(--gold-bright);
}
.touch-btn.run.active {
  background: rgba(80, 50, 10, 0.95);
}

/* Hide combat pads while trading */
body.merchant-open #touch-controls,
body.merchant-open .touch-controls {
  opacity: 0.15;
  pointer-events: none;
}

body.touch-mode .controls-mini { display: none; }
body.touch-mode .hud-bottom {
  padding-bottom: max(0.35rem, env(safe-area-inset-bottom));
  /* Keep center XP/belt clear of the right skill wheel + run/potion row */
  padding-right: 0.35rem;
  gap: 0.25rem;
}
body.touch-mode .hud-top {
  padding-top: max(0.45rem, env(safe-area-inset-top));
}
/* On phone: skill bar + potion belt are redundant (use touch pads / Run) */
body.touch-mode .skill-bar { display: none; }
body.touch-mode .belt,
body.touch-mode #belt { display: none !important; }
body.touch-mode .controls-mini { display: none; }
/* Shorter XP bar so it doesn't collide with mana orb / touch buttons */
body.touch-mode .hud-center {
  max-width: min(42vw, 200px);
  flex: 0 1 auto;
  gap: 0.2rem;
  padding-bottom: 0.1rem;
}
body.touch-mode .xp-bar {
  width: 100%;
  max-width: 180px;
  height: 11px;
}
body.touch-mode .xp-bar span { font-size: 0.58rem; }
body.touch-mode .belt-slot {
  width: 30px;
  height: 30px;
  font-size: 0.9rem;
}
body.touch-mode .orb {
  width: 58px;
  height: 58px;
}
body.touch-mode .orb-text { font-size: 0.78rem; }
body.touch-mode .orb-label { font-size: 0.48rem; bottom: 3px; }
/* Stick also clears the shorter bottom HUD */
body.touch-mode .touch-stick {
  bottom: max(78px, calc(env(safe-area-inset-bottom) + 64px));
}

/* Pinned item inspect (mobile long-press) */
.item-tooltip.pinned {
  pointer-events: auto !important;
  max-height: 70vh;
  overflow: auto;
  border: 2px solid var(--gold);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.9);
  padding-bottom: 0.75rem;
}
.tt-close {
  display: block;
  width: 100%;
  margin-top: 0.65rem;
  padding: 0.55rem;
  border: 1px solid var(--gold);
  background: #1a0c08;
  color: var(--gold-bright);
  font-family: var(--font-ui);
  font-weight: 700;
  cursor: pointer;
}

/* First-run mobile tip */
.mobile-tip {
  position: absolute;
  inset: 0;
  z-index: 55;
  background: rgba(0, 0, 0, 0.72);
  display: grid;
  place-items: center;
  padding: 1rem;
}
.mobile-tip.hidden { display: none; }
.mobile-tip-card {
  width: min(360px, 94vw);
  background: var(--panel);
  border: 1px solid var(--border-lit);
  padding: 1.1rem 1.2rem;
}
.mobile-tip-card h3 {
  font-family: var(--font-display);
  color: var(--gold);
  margin-bottom: 0.6rem;
}
.mobile-tip-card ul {
  margin: 0 0 1rem 1.1rem;
  color: var(--text);
  font-size: 0.88rem;
  line-height: 1.5;
}
.mobile-tip-card li { margin-bottom: 0.35rem; }

/* Responsive + merchant split layout */
@media (max-width: 900px) {
  .orb { width: 56px; height: 56px; }
  .orb-text { font-size: 0.78rem; }
  .orb-label { font-size: 0.48rem; bottom: 3px; }
  .skill-slot { width: 40px; height: 40px; font-size: 1.1rem; }
  .class-grid { grid-template-columns: 1fr; }
  .controls-mini { display: none; }
  /* Shorter XP on all narrow screens (not only touch-mode) */
  .hud-center {
    max-width: min(40vw, 170px);
    flex: 0 1 auto;
    gap: 0.18rem;
  }
  .xp-bar {
    max-width: 160px;
    height: 10px;
  }
  .xp-bar span { font-size: 0.55rem; }
  .belt-slot { width: 28px; height: 28px; font-size: 0.85rem; }
  .hud-bottom {
    gap: 0.25rem;
    padding: 0 0.4rem max(0.3rem, env(safe-area-inset-bottom));
  }
  .hud-top-right {
    flex-wrap: wrap;
    justify-content: flex-end;
    max-width: 58vw;
    gap: 0.25rem;
  }
  .hud-top-right .btn.tiny { padding: 0.28rem 0.4rem; font-size: 0.72rem; }
  .area-name { font-size: 0.72rem; max-width: 40vw; }
  .title-card { padding: 1.2rem; }
  .title-card h1 { font-size: 2.4rem; }
  .saves-panel { max-height: 85vh; }
  .save-slot {
    grid-template-columns: 1fr;
    gap: 0.35rem;
  }
  .save-slot-actions { justify-content: flex-start; }

  /* Default: one panel at a time, full-width bottom sheet */
  .side-panel {
    top: auto !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-width: none !important;
    max-height: min(58vh, 520px);
    border-radius: 14px 14px 0 0;
    z-index: 30;
    padding-bottom: max(0.85rem, env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .side-panel.left { left: 0 !important; right: 0 !important; }
  .side-panel .inv-scroll,
  .side-panel .shop-scroll {
    flex: 1 1 auto;
    min-height: 0;
  }

  body.merchant-open .quest-panel,
  body.merchant-open #panel-quests,
  body.merchant-open #panel-char {
    display: none !important;
  }
  body.merchant-open .hud-bottom {
    opacity: 0.22;
    pointer-events: none;
  }
  body.merchant-open .hud-top {
    opacity: 0.55;
    pointer-events: none;
  }
  body.merchant-open .hud-top-right {
    pointer-events: auto;
    opacity: 1;
  }

  /* Sell buttons always visible under icon — keep cell width stable */
  .inv-cell {
    min-height: 56px;
    overflow: visible;
    aspect-ratio: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3px 2px;
  }
  .inv-cell .sell-btn {
    position: relative;
    bottom: auto;
    left: auto;
    right: auto;
    display: block;
    width: 100%;
    margin-top: 2px;
    padding: 5px 2px;
    font-size: 0.62rem;
    border: 1px solid var(--gold);
    flex-shrink: 0;
  }
  .equip-slot .sell-btn {
    padding: 5px 6px;
    font-size: 0.68rem;
  }
  /* Keep bag grid columns stable on mobile (no landscape squeeze) */
  .inv-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 5px;
  }

  /* Quests: full-screen friendly sheet */
  .quest-panel {
    max-height: min(72vh, 640px) !important;
  }
  .quest-row { padding: 0.65rem 0.7rem; }
  .quest-reward {
    flex-wrap: wrap;
    gap: 0.45rem;
  }
  .quest-reward .btn {
    min-height: 40px;
    padding: 0.4rem 0.75rem;
  }
}

/* ── Merchant tabs (portrait, mobile-game style) ── */
.merchant-tabs {
  position: absolute;
  left: 0;
  right: 0;
  top: max(40px, env(safe-area-inset-top));
  z-index: 45;
  display: flex;
  align-items: stretch;
  gap: 0;
  padding: 0;
  background: linear-gradient(180deg, #1a0c0c, #0e0606);
  border-bottom: 2px solid var(--border-lit);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.55);
  pointer-events: auto;
}
.merchant-tabs.hidden { display: none !important; }
.merchant-tab {
  flex: 1;
  appearance: none;
  border: none;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.7rem 0.5rem;
  min-height: 44px;
  cursor: pointer;
}
.merchant-tab.active {
  color: var(--gold-bright);
  border-bottom-color: var(--gold);
  background: rgba(201, 162, 39, 0.08);
}
.merchant-tab.close {
  flex: 0 0 52px;
  color: var(--text);
  font-size: 1.1rem;
  border-left: 1px solid var(--border);
}

/*
 * PORTRAIT merchant — one full sheet at a time (Shop | Bag tabs).
 * Like AFK Arena / Diablo Immortal vendor: tab bar + single scroll panel.
 */
@media (max-width: 900px) and (orientation: portrait) {
  body.merchant-open #panel-shop,
  body.merchant-open #panel-inv {
    top: calc(max(40px, env(safe-area-inset-top)) + 48px) !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    height: auto !important;
    max-height: none !important;
    border-radius: 0 !important;
    z-index: 42 !important;
    padding: 0.55rem 0.65rem max(0.65rem, env(safe-area-inset-bottom)) !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
    box-sizing: border-box !important;
    box-shadow: none;
    border-top: none;
  }
  /* Tab hides the inactive panel (class .hidden still applies from JS) */
  body.merchant-open #panel-shop.hidden,
  body.merchant-open #panel-inv.hidden {
    display: none !important;
  }
  body.merchant-open #panel-shop .panel-header,
  body.merchant-open #panel-inv .panel-header {
    flex-shrink: 0;
    margin-bottom: 0.4rem;
  }
  /* Hide redundant X — tabs have close */
  body.merchant-open #panel-shop .panel-header [data-close],
  body.merchant-open #panel-inv .panel-header [data-close] {
    display: none;
  }
  body.merchant-open #panel-shop .shop-scroll,
  body.merchant-open #panel-inv .inv-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  /* Gear is NOT its own scroll — one continuous bag scroll */
  body.merchant-open #panel-inv .equip-grid {
    overflow: visible !important;
    max-height: none !important;
    flex-shrink: 0;
  }
  body.merchant-open #panel-inv .inv-grid {
    overflow: visible !important;
    flex: none;
  }
  body.merchant-open .shop-item {
    padding: 0.55rem 0.5rem;
    min-height: 56px;
  }
  body.merchant-open .shop-icon,
  body.merchant-open .shop-emoji {
    width: 42px !important;
    height: 42px !important;
    font-size: 1.35rem;
  }
  body.merchant-open .shop-name { font-size: 0.88rem; }
  body.merchant-open .shop-stats {
    font-size: 0.72rem;
    -webkit-line-clamp: 3;
  }
  body.merchant-open .shop-price { font-size: 0.85rem; min-width: 3.2rem; }

}

/*
 * LANDSCAPE merchant — true parallel columns (50/50).
 * Shop left | Bag right. Same item widths as portrait. One scroll each.
 */
@media (max-width: 1100px) and (orientation: landscape) {
  body.merchant-open .merchant-tabs { display: none !important; }

  body.merchant-open #panel-shop,
  body.merchant-open #panel-shop.shop-panel {
    top: max(36px, env(safe-area-inset-top)) !important;
    left: 0 !important;
    right: auto !important;
    bottom: 0 !important;
    width: 50% !important;
    max-width: 50% !important;
    height: auto !important;
    max-height: none !important;
    border-radius: 0 !important;
    border-right: 1px solid var(--border-lit) !important;
    z-index: 42 !important;
    padding: 0.45rem 0.5rem max(0.45rem, env(safe-area-inset-bottom)) !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
    box-sizing: border-box !important;
  }
  body.merchant-open #panel-inv,
  body.merchant-open #panel-inv.inv-panel {
    top: max(36px, env(safe-area-inset-top)) !important;
    right: 0 !important;
    left: auto !important;
    bottom: 0 !important;
    width: 50% !important;
    max-width: 50% !important;
    height: auto !important;
    max-height: none !important;
    border-radius: 0 !important;
    z-index: 42 !important;
    padding: 0.45rem 0.5rem max(0.45rem, env(safe-area-inset-bottom)) !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
    box-sizing: border-box !important;
    box-shadow: none;
    border-top: none;
  }
  /* Force both visible in landscape even if tab hid one */
  body.merchant-open #panel-shop.hidden,
  body.merchant-open #panel-inv.hidden {
    display: flex !important;
  }
  body.merchant-open #panel-shop .shop-scroll,
  body.merchant-open #panel-inv .inv-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  /* Single inventory scroll — equip does not scroll alone */
  body.merchant-open #panel-inv .equip-grid {
    overflow: visible !important;
    max-height: none !important;
    flex-shrink: 0;
  }
  body.merchant-open #panel-inv .inv-grid {
    overflow: visible !important;
    flex: none;
    /* Same 4-col bag as portrait — do not squeeze item width */
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  }
  body.merchant-open .shop-item {
    padding: 0.45rem 0.45rem;
    min-height: 52px;
  }
  body.merchant-open .shop-icon,
  body.merchant-open .shop-emoji {
    width: 40px !important;
    height: 40px !important;
    font-size: 1.3rem;
    flex-shrink: 0;
  }
  body.merchant-open .shop-name { font-size: 0.82rem; }
  body.merchant-open .shop-stats {
    font-size: 0.68rem;
    -webkit-line-clamp: 2;
  }
  body.merchant-open .shop-price {
    font-size: 0.8rem;
    min-width: 3rem;
  }

  body.touch-mode .touch-actions.ml-wheel,
  .touch-actions.ml-wheel {
    bottom: max(14px, env(safe-area-inset-bottom));
    transform: scale(0.78);
    transform-origin: bottom right;
  }
  body.touch-mode .touch-stick,
  .touch-stick {
    bottom: max(14px, env(safe-area-inset-bottom));
    transform: scale(0.8);
    transform-origin: bottom left;
  }
  body.touch-mode .hud-center {
    max-width: min(36vw, 160px);
  }
}

@media (pointer: coarse) {
  .touch-controls:not(.hidden) { display: block; }
}
