/* FABLED UI - Clean, sharp Diablo-style */
:root {
  --feed-h: 2rem;
  --bars-h: 3.125rem;
  --safe-t: calc(env(safe-area-inset-top, 0px) + var(--feed-h) + 0.375rem);
  --safe-r: calc(env(safe-area-inset-right, 0px) + 0.5rem);
  --safe-b: calc(env(safe-area-inset-bottom, 0px) + 0.5rem);
  --safe-l: calc(env(safe-area-inset-left, 0px) + 0.5rem);
  --hud-gap: clamp(0.25rem, 1.5vw, 0.5rem);
  --mobile-touch-size: clamp(6rem, 26vmin, 7.5rem);
  --portrait-size: clamp(2.25rem, 12vmin, 4rem);
  --bar-height: clamp(0.875rem, 4vmin, 1.625rem);
  --unit-name-size: clamp(0.5625rem, 2.5vmin, 0.9375rem);
  --bar-text-size: clamp(0.5rem, 2vmin, 0.75rem);
  --level-badge-size: clamp(1rem, 5vmin, 1.75rem);
  /* Color palette – dark, warm brown (no green cast) */
  --bg-dark: #161210;
  --bg-panel: #211c18;
  --stone: #2d2620;
  --stone-dark: #211c18;
  --wood: #3a3228;
  --wood-dark: #2a2218;
  --border: rgba(75,60,50,0.6);
  --border-l: rgba(105,85,65,0.5);
  --border-highlight: rgba(232,184,74,0.2);
  --text: #e8e0d0;
  --text-dim: rgba(232,224,208,0.85);
  --text-mute: rgba(232,224,208,0.55);
  --blue: #6ba4e7;
  --purple: #9b7ed9;
  --green: #5eb55e;
  --red: #d65c5c;
  --gold: #e8b84a;
  --bevel-light: transparent;
  --bevel-dark: rgba(0,0,0,0.25);
  /* UI system – sharp edges, clean spacing. All scale with Settings → UI Scale. */
  --ui-scale: 1;
  --ui-xs: calc(4px * var(--ui-scale, 1));
  --ui-sm: calc(8px * var(--ui-scale, 1));
  --ui-md: calc(12px * var(--ui-scale, 1));
  --ui-lg: calc(16px * var(--ui-scale, 1));
  --ui-xl: calc(20px * var(--ui-scale, 1));
  --ui-2xl: calc(24px * var(--ui-scale, 1));
  --ui-radius: 0;
  --ui-panel-border: 1px solid var(--border-l);
  --ui-shadow: 0 2px 8px rgba(0,0,0,0.4);
  --ui-shadow-overlay: 0 8px 24px rgba(0,0,0,0.5);
  /* Font sizes (3 only): title, text, subtext. px-based so Font Size slider only affects these. */
  --ui-font-scale: 1;
  --ui-font-title: calc(clamp(16px, 2vmin, 20px) * var(--ui-font-scale, 1));
  --ui-font-text: calc(clamp(13px, 1.8vmin, 16px) * var(--ui-font-scale, 1));
  --ui-font-subtext: calc(clamp(10px, 1.4vmin, 13px) * var(--ui-font-scale, 1));
}

/* Reset */
@font-face { font-family: "MedievalSharp"; src: url("/assets/fonts/skranji-regular.ttf") format("truetype"); }
html, body { margin: 0; padding: 0; width: 100%; height: 100%; background: #000; overflow: hidden; touch-action: pan-x pan-y pinch-zoom !important; -webkit-touch-callout: none !important; user-select: none !important; overscroll-behavior: none !important; font-family: "MedievalSharp", serif; position: fixed; }
*, *::before, *::after { box-sizing: border-box; -webkit-user-drag: none; -webkit-tap-highlight-color: transparent; margin: 0; padding: 0; font-family: inherit; user-select: none !important; -webkit-user-select: none !important; -moz-user-select: none !important; -ms-user-select: none !important; }
input, textarea, select { background: none; border: none; outline: none; font-family: inherit; pointer-events: auto !important; touch-action: auto !important; user-select: text !important; -webkit-user-select: text !important; -moz-user-select: text !important; -ms-user-select: text !important; -webkit-touch-callout: default !important; }
button, button *, button::before, button::after { user-select: none !important; -webkit-user-select: none !important; -moz-user-select: none !important; -ms-user-select: none !important; -webkit-touch-callout: none !important; }
button { background: none; border: none; outline: none; font-family: inherit; pointer-events: auto !important; touch-action: auto !important; }
[class*="icon"], [class*="Icon"], span[class*="icon"], span[class*="Icon"] { user-select: none !important; -webkit-user-select: none !important; -webkit-touch-callout: none !important; }

/* Canvas & game area – fill viewport on all devices (mobile, tablet, laptop, 4K) */
html { height: 100%; font-size: 16px; -webkit-text-size-adjust: 100%; }
body { min-height: 100%; min-height: 100dvh; }
canvas { display: block; image-rendering: pixelated !important; image-rendering: crisp-edges; transform: translateZ(0); touch-action: none; pointer-events: none; user-select: none; position: absolute; left: 0; top: 0; }
#gameContainer {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  contain: layout style paint;
}
#compositeCanvas { z-index: 3; pointer-events: auto; touch-action: none; }
/* HUD Grid */
.hud-root { position: fixed; inset: 0; pointer-events: none; z-index: 1000; width: 100%; height: 100%; height: 100dvh; }
.hud-element { pointer-events: auto; cursor: pointer; }
.hud-pane-base { position: absolute; inset: 0; pointer-events: none; background: none !important; z-index: 1; padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l); }
/* Top row: player (flex) | menu button (auto) | target (flex) – button flush between */
.hud-pane-base-grid { display: grid; width: 100%; height: 100%; grid-template: "tl tc tr" auto "ml c mr" 1fr "bl bc br" auto / 1fr auto 1fr; align-items: start; }
.hud-area { display: flex; justify-content: center; align-items: center; pointer-events: none; overflow: visible; min-width: 0; }
.hud-area.topLeft { grid-area: tl; justify-content: flex-start; align-items: stretch; flex-direction: column; padding: var(--hud-gap); padding-left: max(var(--hud-gap), env(safe-area-inset-left)); }
.hud-area.topCenter { grid-area: tc; display: flex; justify-content: center; align-items: center; padding: var(--hud-gap); }
.hud-area.topRight { grid-area: tr; display: flex; justify-content: flex-end; align-items: flex-start; padding: var(--hud-gap); padding-right: max(var(--hud-gap), env(safe-area-inset-right)); }
.hud-area.middleLeft { grid-area: ml; justify-content: flex-start; }
.hud-area.center { grid-area: c; }
.hud-area.middleRight { grid-area: mr; justify-content: flex-end; }
.hud-area.bottomLeft { grid-area: bl; justify-content: flex-start; align-items: flex-end; padding: 0 0 max(var(--hud-gap), env(safe-area-inset-bottom)) max(var(--hud-gap), env(safe-area-inset-left)); }
.hud-area.bottomCenter { grid-area: bc; margin-top: auto; flex-direction: column; justify-content: flex-end; align-items: center; padding-bottom: 0; }
.hud-area.bottomRight { grid-area: br; justify-content: flex-end; align-items: flex-end; padding: 0 max(var(--hud-gap), env(safe-area-inset-right)) max(var(--hud-gap), env(safe-area-inset-bottom)) 0; }
/* Mobile: swap joystick and action button when preferred */
@media (max-width: 767px) {
  .hud-pane.joystick-on-right .hud-area.bottomLeft { grid-area: br; justify-content: flex-end; padding: 0 max(var(--hud-gap), env(safe-area-inset-right)) max(var(--hud-gap), env(safe-area-inset-bottom)) 0; }
  .hud-pane.joystick-on-right .hud-area.bottomRight { grid-area: bl; justify-content: flex-start; padding: 0 0 max(var(--hud-gap), env(safe-area-inset-bottom)) max(var(--hud-gap), env(safe-area-inset-left)); }
}

/* Bottom bar: FPS above clock, ping below clock */
.bottom-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  justify-content: center;
  pointer-events: none;
}
.bottom-bar .server-clock,
.bottom-bar-fps,
.bottom-bar-ping {
  font-family: var(--font-ui, MedievalSharp, sans-serif);
  font-size: var(--ui-font-text);
  color: var(--gold, #c9a227);
  text-shadow: 0 1px 2px rgba(0,0,0,0.8);
  white-space: nowrap;
}
.bottom-bar .server-clock { }
.bottom-bar-fps { color: var(--text-muted, #aaa); font-size: var(--ui-font-subtext); }
.bottom-bar-ping { color: var(--text-muted, #aaa); font-size: var(--ui-font-subtext); }

/* Quick-access slots (mobile only, above clock) */
.quick-slots {
  display: flex;
  gap: var(--hud-gap);
  margin-bottom: var(--hud-gap);
  pointer-events: auto;
}
.quick-slot {
  --quick-slot-size: clamp(2.25rem, 10vmin, 2.75rem);
  width: var(--quick-slot-size);
  height: var(--quick-slot-size);
  min-width: var(--quick-slot-size);
  min-height: var(--quick-slot-size);
  padding: 0;
  background: var(--stone);
  border: var(--ui-panel-border);
  border-radius: 6px;
  box-shadow: var(--ui-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
}
.quick-slot:active { transform: scale(0.96); }
.quick-slot .quick-slot-icon {
  width: 1.75rem;
  height: 1.75rem;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  image-rendering: pixelated;
}
.quick-slot .quick-slot-qty {
  position: absolute;
  bottom: 1px;
  right: 3px;
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--gold);
  text-shadow: 0 1px 1px rgba(0,0,0,0.9);
}
.quick-slot-empty .quick-slot-icon { opacity: 0.4; }

/* XP bar (below quick slots, purple, shows skill closest to leveling) */
.xp-bar-container {
  width: 100%;
  max-width: 12rem;
  margin-bottom: var(--hud-gap);
  display: flex;
  flex-direction: column;
  align-items: center;
}
.xp-bar {
  width: 100%;
  height: 0.5rem;
  background: rgba(40, 20, 50, 0.9);
  border: 1px solid rgba(120, 80, 140, 0.6);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}
.xp-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #6b3a8e, #9b5dc4);
  border-radius: 3px;
  transition: width 0.2s ease-out;
}
/* Large screens (2K): scale up so rem-based UI isn’t tiny */
@media (min-width: 2560px) {
  html { font-size: 20px; }
  :root {
    --portrait-size: clamp(4rem, 5vmin, 7rem);
    --bar-height: clamp(1.5rem, 2.5vmin, 2.25rem);
    --unit-name-size: clamp(0.9rem, 2vmin, 1.25rem);
    --level-badge-size: clamp(1.25rem, 3vmin, 2.25rem);
    --ui-font-title: calc(clamp(20px, 2vmin, 26px) * var(--ui-font-scale, 1));
    --ui-font-text: calc(clamp(16px, 1.6vmin, 19px) * var(--ui-font-scale, 1));
    --ui-font-subtext: calc(clamp(12px, 1.2vmin, 16px) * var(--ui-font-scale, 1));
    --hud-gap: clamp(0.35rem, 1.2vw, 0.75rem);
    --ui-xs: calc(0.25rem * var(--ui-scale, 1));
    --ui-sm: calc(0.5rem * var(--ui-scale, 1));
    --ui-md: calc(0.75rem * var(--ui-scale, 1));
    --ui-lg: calc(1rem * var(--ui-scale, 1));
    --ui-xl: calc(1.25rem * var(--ui-scale, 1));
    --ui-2xl: calc(1.5rem * var(--ui-scale, 1));
  }
}

/* 4K: larger base so entire UI scales up */
@media (min-width: 3840px) {
  html { font-size: 28px; }
  :root {
    --portrait-size: clamp(5rem, 4.5vmin, 9rem);
    --bar-height: clamp(1.75rem, 2.2vmin, 2.75rem);
    --unit-name-size: clamp(1rem, 1.8vmin, 1.5rem);
    --level-badge-size: clamp(1.5rem, 2.8vmin, 2.5rem);
    --ui-font-title: calc(clamp(22px, 1.8vmin, 32px) * var(--ui-font-scale, 1));
    --ui-font-text: calc(clamp(18px, 1.5vmin, 22px) * var(--ui-font-scale, 1));
    --ui-font-subtext: calc(clamp(14px, 1.2vmin, 18px) * var(--ui-font-scale, 1));
    --hud-gap: clamp(0.5rem, 1vw, 1rem);
    --feed-h: 2.5rem;
    --bars-h: 3.75rem;
    --ui-xs: calc(0.3rem * var(--ui-scale, 1));
    --ui-sm: calc(0.6rem * var(--ui-scale, 1));
    --ui-md: calc(0.85rem * var(--ui-scale, 1));
    --ui-lg: calc(1.15rem * var(--ui-scale, 1));
    --ui-xl: calc(1.5rem * var(--ui-scale, 1));
    --ui-2xl: calc(1.75rem * var(--ui-scale, 1));
  }
  .item-tooltip {
    max-width: 28rem;
    padding: 1.25rem 1.5rem;
  }
  .tooltip-icon {
    width: 3.5rem;
    height: 3.5rem;
  }
  .context-menu {
    min-width: 16rem;
    padding: 0.5rem;
  }
  .quantity-picker-content {
    min-width: 26rem;
    padding: 2rem;
  }
  .qty-btn {
    width: 3.25rem;
    height: 3.25rem;
  }
  .qty-input {
    width: 8rem;
    height: 3.25rem;
  }
}

/* Mobile: bottom bar stays in grid with joystick/button (no extra row, no gap) */
/* Shared: Stone panel */
.stone-panel { background: var(--stone); border: var(--ui-panel-border); border-radius: var(--ui-radius); box-shadow: var(--ui-shadow); }

/* Top HUD Layout - scales with viewport */
.top-hud { display: flex; align-items: stretch; gap: var(--hud-gap); width: 100%; min-width: 0; }
.unit-panel { display: flex; align-items: stretch; gap: var(--hud-gap); flex: 1; min-width: 0; }
.unit-panel.target-panel { opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.unit-panel.target-panel.visible { opacity: 1; pointer-events: auto; }
.target-bars { justify-content: flex-end; }
.unit-portrait { 
  position: relative; width: var(--portrait-size); height: var(--portrait-size); flex-shrink: 0;
  background: var(--stone);
  border: var(--ui-panel-border);
  border-radius: var(--ui-radius);
  box-shadow: var(--ui-shadow);
  overflow: hidden;
}
.portrait-canvas { width: 100% !important; height: 100% !important; image-rendering: pixelated; display: block !important; position: static !important; pointer-events: none; }
.level-badge { 
  position: absolute; bottom: -2px; right: -2px; min-width: var(--level-badge-size); height: var(--level-badge-size);
  background: var(--gold);
  color: #1a1510; font-size: calc(var(--level-badge-size) * 0.55); font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--ui-radius); border: var(--ui-panel-border);
  box-shadow: var(--ui-shadow);
  padding: 0 4px;
}
.unit-bars { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 0.125rem; }
.unit-bars .health-bar { height: var(--bar-height); margin: 0; }
.unit-bars .mana-bar { height: calc(var(--bar-height) * 0.7); margin: 0; }
.buffs-bar { display: none; flex-wrap: wrap; gap: 0.25rem; margin-top: 0.125rem; align-items: center; }
.buffs-bar .buff-slot {
  display: flex; align-items: center; gap: 0.2rem;
  background: rgba(0,0,0,0.4); border: 1px solid rgba(255,220,150,0.3);
  border-radius: 4px; padding: 0.15rem 0.35rem;
  font-size: 0.65rem; color: var(--gold); min-height: 1.5rem;
}
.buffs-bar .buff-icon {
  width: 16px; height: 16px; flex-shrink: 0;
  background-size: contain; background-repeat: no-repeat; background-position: center;
  image-rendering: pixelated;
}
.buffs-bar .buff-icon-fallback { background: none; font-size: 0.9rem; line-height: 1; }
.buffs-bar .buff-duration { font-variant-numeric: tabular-nums; }
.unit-name { font-size: var(--unit-name-size); font-weight: 600; color: var(--gold); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1; }
.target-name { text-align: right; }
/* Target panel: bars (name + health) left, portrait right */
.unit-panel.target-panel { flex-direction: row; }

/* Menu Button - soft rounded corners */
.menu-btn { 
  pointer-events: auto;
  display: flex; align-items: center; justify-content: center;
  width: var(--portrait-size);
  height: var(--portrait-size);
  flex-shrink: 0;
  background: var(--wood);
  color: var(--text);
  border: var(--ui-panel-border);
  border-radius: 6px;
  font-size: var(--ui-font-title);
  box-shadow: var(--ui-shadow);
  transition: transform 0.1s, border-color 0.15s;
  user-select: none !important; -webkit-user-select: none !important; -webkit-touch-callout: none !important;
}
.menu-btn:active, .menu-btn.pressed { transform: scale(0.98); border-color: var(--gold); }

/* Joystick — 4-direction virtual stick, fantasy stone style */
.joystick-container { pointer-events: auto; touch-action: none; width: var(--mobile-touch-size); height: var(--mobile-touch-size); flex-shrink: 0; }
.joystick-zone {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 40%, #3e3830, #2a251e);
  border: 1px solid #3d3530;
  box-shadow: inset 0 1px 2px rgba(255,240,200,0.06), 0 2px 4px rgba(0,0,0,0.3);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: box-shadow 0.08s, border-color 0.08s;
}
.joystick-zone.active {
  border-color: #6a5a3a;
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.4), 0 0 6px rgba(255,200,100,0.15);
}
.joystick-stick {
  position: absolute;
  left: 50%; top: 50%;
  width: 36%;
  height: 36%;
  margin: -18% 0 0 -18%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #5a4a38, #3d3228);
  border: 1px solid #4a3a28;
  box-shadow: inset 0 1px 2px rgba(255,220,150,0.1), 0 2px 4px rgba(0,0,0,0.4);
  pointer-events: none;
  transition: transform 0.06s ease-out;
}

/* Action Button — matches joystick style (dark stone), same size */
.action-btn { 
  pointer-events: auto;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: var(--mobile-touch-size);
  height: var(--mobile-touch-size);
  min-width: var(--mobile-touch-size);
  min-height: var(--mobile-touch-size);
  border-radius: 50%;
  flex-shrink: 0;
  touch-action: none;
  background: radial-gradient(circle at 40% 40%, #3e3830, #2a251e);
  border: 1px solid #3d3530;
  color: var(--text);
  box-shadow: inset 0 1px 2px rgba(255,240,200,0.06), 0 2px 4px rgba(0,0,0,0.3);
  transition: transform 0.1s ease-out, box-shadow 0.08s, border-color 0.08s;
  will-change: transform;
}
.action-btn:active, .action-btn.pressed { 
  transform: scale(0.94); 
  border-color: #5a5040;
  box-shadow: inset 0 2px 6px rgba(0,0,0,0.4), 0 2px 4px rgba(0,0,0,0.35);
}
/* Pulsing glow when target selected */
.action-btn.has-target {
  animation: action-pulse 1.5s ease-in-out infinite;
}
@keyframes action-pulse {
  0%, 100% { box-shadow: inset 0 1px 2px rgba(255,240,200,0.06), 0 2px 4px rgba(0,0,0,0.3); }
  50% { box-shadow: inset 0 1px 2px rgba(255,240,200,0.1), 0 2px 8px rgba(255,200,100,0.2); }
}
.action-btn-icon { font-size: var(--ui-font-title); line-height: 1; filter: drop-shadow(0 2px 3px rgba(0,0,0,0.5)); user-select: none !important; -webkit-user-select: none !important; -webkit-touch-callout: none !important; }
.action-btn-label { font-size: var(--ui-font-subtext); font-weight: 600; margin-top: 0.25rem; opacity: 0.9; text-transform: uppercase; letter-spacing: 0.03em; text-shadow: 0 1px 2px rgba(0,0,0,0.6); }

/* Placement panel — arrows + Place/Cancel when placing objects (mobile) */
.placement-panel {
  pointer-events: auto;
  margin-bottom: 0.5rem;
  background: rgba(0,0,0,0.6);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 12px;
  padding: 0.75rem;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}
.placement-panel[hidden] { display: none !important; }
.placement-panel-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}
/* When placement active: hide joystick & action button, full-width placement bar across bottom */
.hud-pane.placement-active .hud-area.bottomLeft,
.hud-pane.placement-active .hud-area.bottomRight { display: none !important; }
.hud-pane.placement-active .hud-area.bottomCenter {
  grid-column: 1 / -1;
  justify-content: stretch;
  padding-left: max(var(--hud-gap), env(safe-area-inset-left));
  padding-right: max(var(--hud-gap), env(safe-area-inset-right));
  padding-bottom: max(var(--ui-sm), env(safe-area-inset-bottom));
}
.hud-pane.placement-active .hud-area.bottomCenter .bottom-bar { display: none; }
.hud-pane.placement-active .placement-panel {
  flex: 1;
  width: 100%;
  margin: 0;
  max-width: none;
}
.hud-pane.placement-active .placement-panel-inner {
  flex-direction: row;
  justify-content: center;
  align-items: center;
  gap: 1rem;
  width: 100%;
}
.placement-arrows {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-rows: auto auto auto;
  gap: 0.35rem;
  align-items: center;
  justify-items: center;
}
.placement-arrows .placement-arrow-up { grid-column: 2; grid-row: 1; }
.placement-arrows .placement-arrow-left { grid-column: 1; grid-row: 2; }
.placement-arrows .placement-arrow-right { grid-column: 3; grid-row: 2; }
.placement-arrows .placement-arrow-down { grid-column: 2; grid-row: 3; }
.placement-arrow {
  width: 2.75rem;
  height: 2.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 8px;
  color: rgba(255,255,255,0.95);
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s, transform 0.1s;
}
.placement-arrow:hover { background: rgba(255,255,255,0.18); }
.placement-arrow:active { transform: scale(0.92); }
.placement-arrow svg { width: 1rem; height: 1rem; pointer-events: none; }
.placement-actions {
  display: flex;
  gap: 0.6rem;
  width: 100%;
  justify-content: center;
}
.hud-pane.placement-active .placement-actions {
  width: auto;
  flex: 0 0 auto;
  gap: 0.75rem;
}
.placement-panel-btn {
  flex: 1;
  min-height: 3rem;
  padding: 0.6rem 1rem;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,0.3);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.1s, background 0.15s;
}
.hud-pane.placement-active .placement-panel-btn {
  flex: 0 0 auto;
  min-width: 6rem;
}
.placement-panel-btn:active { transform: scale(0.96); }
.placement-panel-place { background: #16a34a; color: #fff; }
.placement-panel-place:hover { background: #15803d; }
.placement-panel-cancel { background: #b91c1c; color: #fff; }
.placement-panel-cancel:hover { background: #991b1b; }

/* Bars - Fantasy style */
.health-bar, .mana-bar { 
  background: var(--stone-dark); 
  border: var(--ui-panel-border); 
  border-radius: var(--ui-radius); 
  width: 100%; 
  position: relative; 
  overflow: hidden;
}
.health-bar { height: var(--bar-height); display: none; }
.mana-bar { height: calc(var(--bar-height) * 0.7); }
.health-fill { background: var(--red); height: 100%; }
.mana-fill { background: var(--blue); height: 100%; width: 0%; transition: width 0.2s; }
.health-text, .mana-text { position: absolute; inset: 0; color: var(--text); font-weight: 600; text-shadow: 1px 1px 1px #000, 0 0 3px rgba(0,0,0,0.8); display: flex; align-items: center; justify-content: center; pointer-events: none; z-index: 1; }
.health-text { font-size: var(--ui-font-subtext); }
.mana-text { font-size: var(--ui-font-subtext); }

/* Mobile Menu */
.mobile-menu { 
  position: fixed; 
  inset: 0; 
  z-index: 10000; 
  pointer-events: auto; 
  touch-action: auto;
}
.mobile-menu-backdrop { 
  position: absolute; 
  inset: 0; 
  background: rgba(0,0,0,0); 
  transition: background 0.3s; 
  pointer-events: auto;
  touch-action: auto;
}
.mobile-menu.open .mobile-menu-backdrop { background: rgba(10,8,5,0.85); }
.mobile-menu-panel { 
  position: absolute; 
  bottom: 0; 
  left: 0; 
  right: 0; 
  height: 85vh;
  background: var(--bg-panel);
  border: var(--ui-panel-border); 
  border-bottom: none;
  border-radius: var(--ui-radius);
  display: flex; 
  flex-direction: column;
  transform: translateY(100%); 
  transition: transform 0.3s cubic-bezier(0.32,0.72,0,1);
  box-shadow: var(--ui-shadow-overlay);
  overflow: hidden;
  pointer-events: auto;
  touch-action: auto;
}
.mobile-menu.open .mobile-menu-panel { transform: translateY(0); }
.mobile-menu-header { 
  display: flex; align-items: center; justify-content: space-between; 
  padding: var(--ui-md) var(--ui-lg); 
  border-bottom: var(--ui-panel-border);
  background: var(--stone-dark);
}
.mobile-menu-title { font-size: var(--ui-font-title); font-weight: 600; color: var(--gold); }
.mobile-menu-close { 
  width: 40px; 
  height: 40px; 
  border-radius: var(--ui-radius);
  background: var(--stone); 
  border: var(--ui-panel-border);
  color: var(--text); 
  font-size: var(--ui-font-title);
  display: flex; 
  align-items: center; 
  justify-content: center; 
  cursor: pointer;
  pointer-events: auto !important;
  touch-action: manipulation !important;
  z-index: 10001;
  position: relative;
}
.mobile-menu-close:active { transform: scale(0.98); }
.mobile-menu-content { 
  flex: 1; 
  min-height: 0;
  overflow-y: auto; 
  padding: var(--ui-md) var(--ui-md) 90px; 
  -webkit-overflow-scrolling: touch; 
  background: var(--bg-panel);
  color: var(--text);
  pointer-events: auto;
  touch-action: auto;
  display: flex;
  flex-direction: column;
}
.mobile-menu-content::-webkit-scrollbar { width: 6px; }
.mobile-menu-content::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); border-radius: var(--ui-radius); }
.mobile-menu-content::-webkit-scrollbar-thumb { background: var(--border-l); border-radius: var(--ui-radius); }
/* Ensure all text in mobile menu is visible */
.mobile-menu-content * {
  color: inherit;
}
.mobile-menu-content .menu-section {
  flex: 0 0 auto;
  min-height: min-content;
  color: var(--text);
  pointer-events: auto;
  touch-action: auto;
}
.mobile-menu-content .menu-section-equipment {
  overflow: visible;
  min-height: 0;
}
.mobile-menu-content .menu-section-equipment .character-sheet-body {
  overflow: visible;
}
.mobile-menu-content .menu-section-map {
  flex: 1;
  min-height: 0;
}
.mobile-menu-content .menu-section-map .map-panel {
  height: 100%;
  max-height: none;
}

/* Tab Bar */
.mobile-menu-tabs { 
  position: absolute; bottom: 0; left: 0; right: 0; 
  display: flex; justify-content: space-around; 
  padding: var(--ui-sm) var(--ui-sm) max(var(--ui-sm), env(safe-area-inset-bottom));
  background: var(--stone-dark);
  border-top: var(--ui-panel-border);
}
.mobile-tab { 
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: var(--ui-sm); min-width: 44px;
  background: transparent; color: var(--text-mute);
  border-radius: var(--ui-radius);
  transition: color 0.2s, transform 0.15s, background 0.2s;
}
.mobile-tab:active { transform: scale(0.92); }
.mobile-tab.active { 
  color: var(--gold); 
  background: rgba(232,184,74,0.12);
  border-bottom: 2px solid var(--gold);
}
.mobile-tab .tab-icon { font-size: var(--ui-font-title); line-height: 1; }
.mobile-tab .tab-label { font-size: var(--ui-font-subtext); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }

  /* Menu Sections - Desktop Panel Style - Always Visible */
  .menu-section { 
    width: 100%; 
    overflow: hidden;
    padding: var(--ui-lg);
    display: block !important; /* Always visible on desktop */
  }
  .menu-section-inventory { 
    width: 100%;
    padding: 0;
    display: block !important;
  }
  .menu-section-equipment { 
    padding: var(--ui-lg);
    display: block !important;
  }
  .menu-section-settings, .menu-section-keybindings { 
    display: flex !important; 
    flex-direction: column; 
    gap: var(--ui-md);
    padding: var(--ui-lg);
  }
  .menu-section-chat { 
    height: 100%; 
    padding: 0 !important; 
    overflow: hidden;
    display: block !important;
  }

/* Inventory/Equipment Grid */
.inventory-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--ui-sm); padding: var(--ui-xs); }
.menu-section-empty.shop-empty { padding: var(--ui-2xl); text-align: center; color: var(--text-mute); font-size: var(--ui-font-text); }
.shop-gold {
  font-weight: 700; color: var(--gold); margin-bottom: var(--ui-md); padding: var(--ui-md) var(--ui-sm);
  background: var(--stone-dark); border-radius: var(--ui-radius);
  font-size: var(--ui-font-text);
}
.shop-section { margin-bottom: var(--ui-lg); }
.shop-section-title {
  font-weight: 600; margin-bottom: var(--ui-sm); color: var(--text-dim); font-size: var(--ui-font-subtext);
  text-transform: uppercase; letter-spacing: 0.08em; padding-bottom: var(--ui-xs);
  border-bottom: 1px solid var(--border-l);
}
.shop-buy-list, .shop-sell-list { display: flex; flex-direction: column; gap: var(--ui-sm); }
.shop-row {
  display: flex; align-items: center; gap: var(--ui-md); flex-wrap: nowrap;
  padding: var(--ui-sm) var(--ui-md); background: rgba(0,0,0,0.2);
  border: 1px solid var(--border); border-radius: var(--ui-radius);
  border-left: 3px solid var(--border-l);
}
.shop-item-icon {
  width: 36px; height: 36px; flex-shrink: 0; border-radius: var(--ui-radius);
  border: var(--ui-panel-border); background: var(--stone-dark);
  box-shadow: var(--ui-shadow);
}
.shop-item-tooltip-trigger { cursor: pointer; }
.shop-item-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); font-size: var(--ui-font-text); }
.shop-price { flex-shrink: 0; color: var(--gold); font-weight: 600; font-size: var(--ui-font-text); }
.shop-btn {
  flex-shrink: 0; padding: var(--ui-sm) var(--ui-md); border-radius: var(--ui-radius);
  border: var(--ui-panel-border); background: var(--stone-dark); color: var(--text);
  cursor: pointer; font-family: inherit; font-size: var(--ui-font-text); font-weight: 600;
  transition: background 0.2s, border-color 0.2s;
}
.shop-btn:hover { background: var(--stone); border-color: var(--border-l); }
.shop-buy-btn { border-color: var(--green); color: var(--green); }
.shop-buy-btn:hover { background: rgba(94,181,94,0.15); border-color: var(--green); }
.shop-sell-btn { border-color: var(--gold); color: var(--gold); }
.shop-sell-btn:hover { background: rgba(232,184,74,0.12); border-color: var(--gold); }

/* Shop dialogue (NPC trade – merchant stall / in-world feel) */
.shop-dialogue {
  position: fixed;
  inset: 0;
  z-index: 10001;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--ui-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  box-sizing: border-box;
}
.shop-dialogue.visible { opacity: 1; pointer-events: auto; }
.shop-dialogue-backdrop {
  position: absolute; inset: 0; cursor: pointer;
  background: rgba(26,21,16,0.85);
}
.shop-dialogue-panel {
  position: relative;
  width: 100%;
  max-width: 420px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border: var(--ui-panel-border);
  border-radius: var(--ui-radius);
  box-shadow: var(--ui-shadow-overlay);
  overflow: hidden;
  box-sizing: border-box;
}
.shop-dialogue-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--ui-md) var(--ui-lg);
  border-bottom: var(--ui-panel-border);
  background: var(--wood-dark);
  flex-shrink: 0;
  box-sizing: border-box;
}
.shop-dialogue-title {
  margin: 0; font-size: var(--ui-font-title); font-weight: 700; color: var(--gold);
}
.shop-dialogue-close {
  width: 32px; height: 32px; padding: 0; border: var(--ui-panel-border);
  border-radius: var(--ui-radius);
  background: var(--stone-dark); color: var(--text-dim); font-size: var(--ui-font-text); cursor: pointer; line-height: 1;
  transition: background 0.2s, color 0.2s;
}
.shop-dialogue-close:hover { background: var(--stone); color: var(--text); }
.shop-dialogue-content {
  flex: 1; overflow-y: auto; padding: var(--ui-lg);
  background: var(--bg-panel); color: var(--text); box-sizing: border-box;
}
.shop-dialogue-content::-webkit-scrollbar { width: 6px; }
.shop-dialogue-content::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); border-radius: var(--ui-radius); }
.shop-dialogue-content::-webkit-scrollbar-thumb { background: var(--border-l); border-radius: var(--ui-radius); }
.shop-dialogue-content .shop-gold { margin-top: 0; }

/* Mobile: fill from below top bar (chat preview) to bottom */
@media (max-width: 767px) {
  .shop-dialogue { align-items: stretch; justify-content: flex-end; padding: 0; }
  .shop-dialogue-panel {
    position: absolute;
    top: calc(env(safe-area-inset-top, 0px) + var(--feed-h));
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: none;
    max-height: none;
    height: auto;
    border-radius: var(--ui-radius);
    border: var(--ui-panel-border);
    border-top: var(--ui-panel-border);
  }
  .shop-dialogue-header { padding: var(--ui-lg); border-bottom: var(--ui-panel-border); }
  .shop-dialogue-title { font-size: var(--ui-font-title); }
  .shop-dialogue-close { width: 36px; height: 36px; }
  .shop-dialogue-content { padding: var(--ui-lg); font-size: var(--ui-font-subtext); }
  .shop-dialogue-content .shop-gold { margin: 0 0 var(--ui-md) 0; padding: var(--ui-sm) 0; font-size: var(--ui-font-text); }
  .shop-dialogue-content .shop-section { margin-bottom: var(--ui-lg); }
  .shop-dialogue-content .shop-section:last-child { margin-bottom: 0; }
  .shop-dialogue-content .shop-section-title { margin: 0 0 var(--ui-sm) 0; font-size: var(--ui-font-text); }
  .shop-dialogue-content .shop-buy-list,
  .shop-dialogue-content .shop-sell-list { gap: var(--ui-sm); }
  .shop-dialogue-content .shop-row { padding: var(--ui-sm); gap: var(--ui-sm); }
  .shop-dialogue-content .shop-item-name,
  .shop-dialogue-content .shop-price,
  .shop-dialogue-content .shop-btn { font-size: var(--ui-font-subtext); }
  .shop-dialogue-content .shop-item-icon { width: 32px; height: 32px; }
  .shop-dialogue-content .shop-btn { padding: var(--ui-sm) var(--ui-md); }
}

/* World map overlay – scrollable/zoomable */
.map-overlay {
  position: fixed;
  inset: 0;
  z-index: 10001;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--ui-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  box-sizing: border-box;
}
.map-overlay.visible { opacity: 1; pointer-events: auto; }
.map-overlay-backdrop {
  position: absolute;
  inset: 0;
  cursor: pointer;
  background: rgba(26,21,16,0.85);
}
.map-overlay-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  max-width: 95vw;
  max-height: 90vh;
  background: var(--bg-panel);
  border: var(--ui-panel-border);
  border-radius: var(--ui-radius);
  box-shadow: var(--ui-shadow-overlay);
  overflow: hidden;
  box-sizing: border-box;
}
.map-overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--ui-md) var(--ui-lg);
  border-bottom: var(--ui-panel-border);
  background: var(--wood-dark);
  flex-shrink: 0;
}
.map-overlay-title {
  margin: 0;
  font-size: var(--ui-font-title);
  font-weight: 700;
  color: var(--gold);
}
.map-overlay-close {
  width: 32px;
  height: 32px;
  padding: 0;
  border: var(--ui-panel-border);
  border-radius: var(--ui-radius);
  background: var(--stone-dark);
  color: var(--text-dim);
  font-size: var(--ui-font-text);
  cursor: pointer;
  line-height: 1;
  transition: background 0.2s, color 0.2s;
}
.map-overlay-close:hover { background: var(--stone); color: var(--text); }
.map-overlay-viewport {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: #1a1a2e;
  cursor: grab;
}
.map-overlay-viewport:active { cursor: grabbing; }
.map-overlay-content {
  display: block;
}
.map-canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.map-overlay-hint {
  padding: var(--ui-sm) var(--ui-lg);
  font-size: var(--ui-font-subtext);
  color: var(--text-dim);
  text-align: center;
  border-top: var(--ui-panel-border);
}

/* Map as pane – same layout as chat: panel > header, scrollable view, legend at bottom */
.menu-section-map {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  padding: 0;
}
.map-unavailable {
  padding: var(--ui-md);
  color: var(--text-dim);
}
.map-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: calc(100vh - 220px);
  background: var(--stone-dark);
  border-radius: var(--ui-radius);
  border: var(--ui-panel-border);
  overflow: hidden;
  box-shadow: var(--ui-shadow);
}
.map-header {
  display: flex;
  align-items: center;
  gap: var(--ui-sm);
  padding: var(--ui-sm) var(--ui-md);
  background: var(--wood-dark);
  border-bottom: var(--ui-panel-border);
  flex-shrink: 0;
}
.map-zoom-in, .map-zoom-out {
  width: 36px;
  height: 36px;
  padding: 0;
  border: var(--ui-panel-border);
  border-radius: var(--ui-radius);
  background: var(--stone-dark);
  color: var(--text);
  font-size: var(--ui-font-title);
  line-height: 1;
  cursor: pointer;
}
.map-zoom-in:hover, .map-zoom-out:hover {
  background: var(--stone);
}
.map-zoom-label {
  min-width: 3.5em;
  font-size: var(--ui-font-subtext);
  color: var(--text-dim);
}
.map-center-btn {
  margin-left: auto;
  padding: var(--ui-sm) var(--ui-md);
  border: var(--ui-panel-border);
  border-radius: var(--ui-radius);
  background: var(--stone-dark);
  color: var(--text);
  font-size: var(--ui-font-subtext);
  cursor: pointer;
}
.map-center-btn:hover {
  background: var(--stone);
}
.map-view {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  background: #1a1a2e;
}
.map-viewport {
  position: absolute;
  inset: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  cursor: grab;
  touch-action: none;
  user-select: none;
}
.map-viewport:active {
  cursor: grabbing;
}
.map-content {
  display: block;
}
.map-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--ui-sm) var(--ui-md);
  padding: var(--ui-sm) var(--ui-md);
  font-size: var(--ui-font-subtext);
  color: var(--text-dim);
  border-top: var(--ui-panel-border);
  background: var(--stone-dark);
  flex-shrink: 0;
}
.map-legend-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  vertical-align: middle;
}
.map-legend-dot.map-legend-you {
  background: #fff;
  border: 1px solid #c00;
}
.ui-window-map .ui-window-content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  padding: 0;
}
.ui-window-map .menu-section-map {
  flex: 1;
  min-height: 0;
  height: auto;
}
.ui-window-map .map-panel {
  max-height: none;
}

.equipment-grid.mobile-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 15px; }
/* Character sheet (D&D / WoW style) – single pane with equipment, stats, skills */
.character-sheet {
  display: flex;
  flex-direction: column;
  gap: var(--ui-md);
  max-width: 100%;
  color: var(--text);
}
.character-sheet-header {
  display: flex;
  gap: var(--ui-lg);
  align-items: flex-start;
  padding: var(--ui-md);
  background: linear-gradient(180deg, var(--wood-dark) 0%, var(--stone-dark) 100%);
  border: 2px solid var(--border-l);
  border-radius: var(--ui-radius);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.06), 0 2px 8px rgba(0,0,0,0.4);
}
.character-sheet-identity {
  flex: 1;
  min-width: 0;
}
.character-sheet-name {
  margin: 0 0 var(--ui-sm) 0;
  font-size: var(--ui-font-title);
  font-weight: 700;
  color: var(--gold);
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  letter-spacing: 0.02em;
}
.character-sheet-stats {
  background: transparent;
  border: none;
  padding: 0;
}
.character-sheet-body {
  display: flex;
  flex-direction: column;
  gap: var(--ui-md);
}
.character-sheet-block {
  padding: var(--ui-md);
  background: var(--stone-dark);
  border: 1px solid var(--border);
  border-radius: var(--ui-radius);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}
.character-sheet-block-title {
  margin: 0 0 var(--ui-sm) 0;
  font-size: var(--ui-font-text);
  font-weight: 700;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.character-sheet-equipment {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.character-sheet-equipment .hud-slot { min-height: 64px; }
.character-sheet-skills {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px;
  padding: 0;
}
.character-effect-row .effect-item-name { font-weight: bold; color: var(--text); margin-bottom: 2px; font-size: var(--ui-font-subtext); }
.character-effect-row .effect-item-desc { font-size: var(--ui-font-subtext); color: var(--text-mute); font-style: italic; line-height: 1.35; }
.character-layout { display: flex; flex-direction: column; gap: 15px; }
.character-equipment-section { }
.character-stats-section { background: var(--stone-dark); border-radius: var(--ui-radius); padding: var(--ui-md); border: var(--ui-panel-border); }
.character-stats-title { font-size: var(--ui-font-title); font-weight: bold; color: var(--text); margin-bottom: 10px; text-align: center; }
.character-stats-divider { height: 1px; background: var(--border); margin: 10px 0; }
.character-stat-row { padding: 8px 0; border-bottom: 1px solid var(--border); }
.character-stat-row:last-child { border-bottom: none; }
.character-stat-row .stat-name { color: var(--text-dim); font-size: var(--ui-font-text); margin-bottom: 4px; }
.character-stat-row .stat-values { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.character-stat-row .stat-base { color: var(--text); font-size: var(--ui-font-text); }
.character-stat-row .stat-modifier { font-size: var(--ui-font-text); font-weight: bold; }
.character-stat-row .stat-mod-positive { color: var(--green); }
.character-stat-row .stat-mod-negative { color: var(--red); }
.character-stat-row .stat-final { color: var(--text); font-size: var(--ui-font-text); font-weight: bold; }
.character-effect-row { padding: 6px 0; border-bottom: 1px solid var(--border); }
.character-effect-row:last-child { border-bottom: none; }
.character-effect-row .effect-text { color: var(--text-dim); font-size: var(--ui-font-subtext); line-height: 1.4; }
.hud-slot { 
  position: relative; 
  display: flex; 
  flex-direction: column; 
  align-items: center; 
  justify-content: center;
  color: var(--text); 
  padding: var(--ui-sm);
  background: var(--stone);
  border-radius: var(--ui-radius); 
  border: var(--ui-panel-border);
  aspect-ratio: 1; 
  overflow: hidden;
  box-shadow: var(--ui-shadow);
  transition: border-color 0.15s, background 0.15s;
  pointer-events: auto !important;
  touch-action: manipulation !important;
  cursor: pointer;
  -webkit-tap-highlight-color: rgba(232,184,74,0.2);
  -webkit-touch-callout: none;
  user-select: none;
  z-index: 1;
}
.hud-slot:active {
  transform: scale(0.98);
  border-color: var(--gold);
}
/* Only disable pointer events on non-interactive child elements (icons, labels) */
/* But allow buttons and inputs to work */
.hud-slot .slot-icon,
.hud-slot .slot-label,
.hud-slot .slot-quantity {
  pointer-events: none;
  touch-action: none;
}
/* Ensure buttons and inputs inside slots work */
.hud-slot button,
.hud-slot input,
.hud-slot textarea,
.hud-slot [role="button"] {
  pointer-events: auto !important;
  touch-action: auto !important;
}
.hud-slot .slot-icon { width: 32px; height: 32px; background-size: contain; background-repeat: no-repeat; background-position: center; image-rendering: pixelated; }
.hud-slot .slot-quantity { position: absolute; bottom: 2px; right: 4px; font-size: var(--ui-font-subtext); font-weight: bold; text-shadow: 1px 1px 2px #000, 0 0 4px #000; color: var(--gold); }
.hud-slot .slot-label { margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; width: 100%; text-align: center; font-size: var(--ui-font-subtext); opacity: 0.85; }
.equipment-grid .hud-slot { min-height: 80px; background: var(--stone-dark); }
.equipment-grid .hud-slot.empty-slot { background: var(--bg-dark); border: 1px dashed var(--border); }
.equipment-grid .hud-slot.empty-slot .slot-label { color: var(--text-mute); display: block; font-size: var(--ui-font-subtext); }
.equipment-grid .hud-slot.empty-slot .slot-label.slot-placeholder { font-style: italic; }


/* List Cards (Skills, Recipes, Keybindings) */
.mobile-skills, .mobile-crafting { 
  display: flex; 
  flex-direction: column; 
  gap: 10px; 
  color: var(--text);
}
.recipe-card, .keybinding-row { 
  display: flex; 
  flex-direction: column;
  gap: var(--ui-md); 
  padding: var(--ui-md) var(--ui-lg);
  background: var(--bg-panel); 
  border: var(--ui-panel-border); 
  border-radius: var(--ui-radius);
  box-shadow: var(--ui-shadow);
  color: var(--text);
}
.recipe-desc { font-size: var(--ui-font-subtext); color: var(--text-mute); }
.recipe-ingredients { 
  display: flex; 
  flex-direction: column; 
  gap: 4px; 
  margin-top: 8px; 
  padding-top: 8px; 
  border-top: 1px solid var(--border); 
}
.recipe-ingredients-label {
  font-size: var(--ui-font-subtext);
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}
.recipe-ingredient { 
  display: flex; 
  justify-content: space-between; 
  align-items: center; 
  font-size: var(--ui-font-subtext); 
  padding: var(--ui-xs) var(--ui-sm); 
  background: var(--stone-dark); 
  border: 1px solid var(--border);
  border-radius: var(--ui-radius);
}
.recipe-ingredient { 
  color: var(--text);
}
.recipe-ingredient .ingredient-name { 
  color: var(--text); 
}
.recipe-ingredient .ingredient-amount { 
  font-weight: 600; 
  color: var(--text);
}
.recipe-ingredient.ingredient-count-ok .ingredient-amount { 
  color: var(--green); 
}
.recipe-ingredient.ingredient-count-missing .ingredient-amount { 
  color: var(--red); 
}
.skills-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  padding: 16px;
}

.skill-slot {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: var(--ui-lg);
  padding: var(--ui-lg);
  background: var(--bg-panel);
  border: var(--ui-panel-border);
  border-radius: var(--ui-radius);
  box-shadow: var(--ui-shadow);
}

.skill-slot-icon {
  font-size: var(--ui-font-title);
  width: 64px;
  height: 64px;
  min-width: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--stone);
  border: var(--ui-panel-border);
  border-radius: var(--ui-radius);
  box-shadow: 
    inset 0 1px 0 rgba(255,255,255,0.1),
    inset 0 -1px 0 rgba(0,0,0,0.3);
}

.skill-slot-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.skill-slot-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.skill-slot-name {
  font-weight: 600;
  font-size: var(--ui-font-text);
  color: var(--text);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.skill-slot-level {
  font-size: var(--ui-font-subtext);
  font-weight: 700;
  color: var(--gold);
  background: rgba(232,184,74,0.2);
  padding: 3px 8px;
  border-radius: 4px;
  border: 1px solid rgba(232,184,74,0.4);
  flex-shrink: 0;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.1);
}

.skill-slot-progress {
  width: 100%;
}

.skill-slot-progress-bar {
  height: 10px;
  background: var(--stone-dark);
  border: 1px solid var(--border);
  border-radius: 5px;
  overflow: hidden;
  box-shadow: inset 0 2px 4px rgba(0,0,0,0.3);
}

.skill-slot-progress-fill {
  height: 100%;
  background: linear-gradient(180deg, #9b7aff 0%, #7a5ec9 50%, #5d3fa8 100%);
  border-radius: 4px;
  transition: width 0.4s ease;
  box-shadow: 
    inset 0 1px 0 rgba(255,255,255,0.3),
    0 0 8px rgba(155,122,255,0.4);
  position: relative;
}

.skill-slot-progress-fill::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 50%;
  background: linear-gradient(180deg, rgba(255,255,255,0.2) 0%, transparent 100%);
  border-radius: 4px 4px 0 0;
}

.skill-slot-xp {
  font-size: var(--ui-font-subtext);
  color: var(--text-dim);
  text-align: left;
  font-weight: 500;
}

.recipe-name { 
  font-weight: 600; 
  font-size: var(--ui-font-text); 
  color: var(--text); 
}
.recipe-card { 
  position: relative;
  transition: all 0.2s;
}
.recipe-card-disabled {
  opacity: 0.7;
  background: linear-gradient(180deg, var(--stone-dark) 0%, var(--stone) 100%);
}
.recipe-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}
.recipe-icon {
  font-size: var(--ui-font-title);
  flex-shrink: 0;
}
.recipe-name {
  font-weight: 600;
  font-size: var(--ui-font-text);
  flex: 1;
}
.recipe-desc {
  font-size: var(--ui-font-subtext);
  color: var(--text-mute);
  margin-bottom: 8px;
  line-height: 1.3;
}
.recipe-ingredients-label,
.recipe-requirements-label {
  font-size: var(--ui-font-subtext);
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}
.recipe-requirements {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.recipe-requirement {
  font-size: var(--ui-font-subtext);
  padding: 4px 8px;
  margin: 2px 0;
  border-radius: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.requirement-met {
  background: rgba(62, 255, 0, 0.1);
  color: var(--green);
  border: 1px solid rgba(62, 255, 0, 0.3);
}
.requirement-missing {
  background: rgba(255, 68, 68, 0.1);
  color: var(--red);
  border: 1px solid rgba(255, 68, 68, 0.3);
}
.recipe-craft-btn { 
  padding: var(--ui-md) var(--ui-lg); 
  background: var(--green);
  color: var(--text); 
  font-weight: 600; 
  border-radius: var(--ui-radius);
  border: var(--ui-panel-border);
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s;
  white-space: nowrap;
  width: 100%;
  margin-top: var(--ui-sm);
}
.recipe-craft-btn:active:not(:disabled) { 
  transform: scale(0.98); 
}
.recipe-craft-btn-disabled {
  background: var(--stone-dark);
  color: var(--text-mute);
  border-color: var(--border);
  cursor: not-allowed;
  opacity: 0.6;
}
.recipe-craft-btn:disabled {
  cursor: not-allowed;
}
.keybinding-row .label { flex: 1; color: var(--text-dim); font-size: var(--ui-font-text); }
.keybinding-row .key-button { 
  padding: var(--ui-sm) var(--ui-md); 
  background: var(--stone-dark); border: var(--ui-panel-border);
  color: var(--gold); border-radius: var(--ui-radius);
  font-family: monospace; font-size: var(--ui-font-subtext); min-width: 60px; text-align: center;
}
.keybinding-row .key-button:active { transform: scale(0.98); background: var(--stone); }
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-mute); }

/* Chat */
.chat-panel { 
  display: flex; flex-direction: column; height: 100%; max-height: calc(100vh - 220px);
  background: var(--stone-dark); border-radius: var(--ui-radius); border: var(--ui-panel-border);
  overflow: hidden; box-shadow: var(--ui-shadow);
}
.chat-messages { flex: 1; min-height: 200px; overflow-y: auto; overscroll-behavior: contain; padding: var(--ui-md); display: flex; flex-direction: column; gap: var(--ui-xs); }
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border-l); border-radius: var(--ui-radius); }
.chat-msg { padding: var(--ui-sm) var(--ui-md); border-radius: var(--ui-radius); background: rgba(0,0,0,0.2); display: flex; gap: var(--ui-sm); align-items: baseline; }
.chat-msg:hover { background: rgba(0,0,0,0.3); }
/* Chat Cast Bar (single-line progress bar shown as chat message) */
.chat-cast-bar {
  padding: var(--ui-sm) var(--ui-md);
  border-radius: var(--ui-radius);
  background: rgba(0,0,0,0.2);
}
.chat-cast-track {
  height: 14px;
  background: rgba(0,0,0,0.4);
  border-radius: var(--ui-radius);
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.5);
}
.chat-cast-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(180deg, #e8b84a, #c89030);
  border-radius: 6px;
  box-shadow: 0 0 6px rgba(232,184,74,0.5);
}
/* Mobile cast bar in notification area */
.chat-cast-bar-mobile {
  position: fixed;
  top: env(safe-area-inset-top, 10px);
  left: 10px;
  right: 10px;
  z-index: 9999;
  padding: 8px 12px;
  background: rgba(30,25,18,0.95);
  border: 1px solid rgba(232,184,74,0.3);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.chat-time { color: var(--text-mute); font-size: var(--ui-font-subtext); }
.chat-sender { color: var(--blue); font-weight: 600; font-size: var(--ui-font-subtext); }
.chat-sender::after { content: ':'; margin-right: 4px; }
.chat-text { color: var(--text-dim); font-size: var(--ui-font-subtext); word-break: break-word; line-height: 1.3; }
.chat-item-link { color: var(--gold); cursor: pointer; text-decoration: none; border-bottom: 1px dotted var(--gold); }
.chat-item-link:hover { color: var(--bevel-light); border-bottom-color: currentColor; }
.chat-system { background: rgba(155,126,217,0.1); border-left: 2px solid var(--purple); }
.chat-system .chat-sender { color: #b8a0e8; font-style: italic; }
.chat-success { border-left-color: var(--green); } .chat-success .chat-text { color: #8ed88e; }
.chat-warning { border-left-color: var(--gold); } .chat-warning .chat-text { color: #f0d070; }
.chat-error { border-left-color: var(--red); } .chat-error .chat-text { color: #e89090; }
.chat-input-area { display: flex; gap: var(--ui-sm); padding: var(--ui-md); background: var(--stone); border-top: var(--ui-panel-border); }
.chat-panel .chat-input { 
  flex: 1; padding: var(--ui-sm) var(--ui-md);
  background: var(--stone-dark); color: var(--text);
  border: var(--ui-panel-border); border-radius: var(--ui-radius); font-size: var(--ui-font-text);
}
.chat-panel .chat-input:focus { border-color: var(--gold); outline: none; }
.chat-panel .chat-input::placeholder { color: var(--text-mute); }
.chat-send-btn { 
  padding: var(--ui-sm) var(--ui-lg);
  background: var(--wood); color: var(--text);
  border: var(--ui-panel-border); border-radius: var(--ui-radius);
  font-weight: 600; font-size: var(--ui-font-subtext);
}
.chat-send-btn:active { transform: scale(0.98); }

/* Settings */
.setting-card { padding: var(--ui-lg); background: var(--bg-panel); border: var(--ui-panel-border); border-radius: var(--ui-radius); box-shadow: var(--ui-shadow); }
.setting-card-title { font-size: var(--ui-font-subtext); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--gold); margin-bottom: var(--ui-md); }
.setting-control { display: flex; align-items: center; justify-content: space-between; gap: var(--ui-lg); padding: var(--ui-sm) 0; }
.setting-control:not(:last-child) { border-bottom: 1px solid var(--border); }
.menu-section-settings label { flex: 1; color: var(--text-dim); font-size: var(--ui-font-text); }
/* Slider value (e.g. percentage): only Font Size slider affects this, not UI Scale */
.setting-slider-value { font-size: var(--ui-font-text); }
.menu-section-settings input[type="range"] { width: 100px; accent-color: var(--gold); height: 6px; background: var(--stone-dark); border-radius: var(--ui-radius); }
.menu-section-settings button { 
  padding: var(--ui-md) var(--ui-xl); background: var(--wood); color: var(--text);
  border: var(--ui-panel-border); border-radius: var(--ui-radius); font-weight: 600; width: 100%;
}
.menu-section-settings button:active { transform: scale(0.98); }

/* Action Sheet */
.item-action-sheet { position: fixed; inset: 0; z-index: 20000; display: flex; flex-direction: column; justify-content: flex-end; pointer-events: auto; }
.action-sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0); transition: background 0.2s; }
.item-action-sheet.visible .action-sheet-backdrop { background: rgba(10,8,5,0.8); }
.action-sheet-content { 
  position: relative; 
  background: var(--bg-panel);
  border: var(--ui-panel-border); border-bottom: none;
  border-radius: var(--ui-radius);
  padding: var(--ui-lg) max(var(--ui-lg), env(safe-area-inset-bottom)) var(--ui-lg) var(--ui-lg);
  transform: translateY(100%); transition: transform 0.25s cubic-bezier(0.32,0.72,0,1);
  box-shadow: var(--ui-shadow-overlay);
}
.item-action-sheet.visible .action-sheet-content { transform: translateY(0); }
.action-sheet-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--ui-md); padding-bottom: var(--ui-sm); border-bottom: var(--ui-panel-border);
}
.action-sheet-toolbar-link {
  width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
  border: var(--ui-panel-border); border-radius: var(--ui-radius); background: var(--stone-dark);
  color: var(--gold); font-size: var(--ui-font-title); cursor: pointer; transition: background 0.2s, color 0.2s;
}
.action-sheet-toolbar-link:hover { background: var(--stone); color: var(--text); }
.action-sheet-toolbar-link:active { transform: scale(0.98); }
.action-sheet-toolbar-close {
  width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
  border: var(--ui-panel-border); border-radius: var(--ui-radius); background: var(--stone-dark);
  color: var(--red); font-size: var(--ui-font-title); font-weight: 700; line-height: 1; cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.action-sheet-toolbar-close:hover { background: rgba(214,92,92,0.2); border-color: var(--red); color: var(--red); }
.action-sheet-toolbar-close:active { transform: scale(0.98); }
.action-sheet-header { display: flex; gap: var(--ui-lg); padding-bottom: var(--ui-lg); border-bottom: var(--ui-panel-border); margin-bottom: var(--ui-lg); }
.action-sheet-icon { 
  position: relative; width: 64px; height: 64px; border-radius: var(--ui-radius);
  background: var(--stone); border: var(--ui-panel-border);
  display: flex; align-items: center; justify-content: center;
}
.action-sheet-icon img { width: 48px; height: 48px; image-rendering: pixelated; object-fit: contain; }
.action-sheet-sprite { image-rendering: pixelated; transform: scale(2); }
.action-sheet-emoji { font-size: var(--ui-font-title); }
.action-sheet-quantity { position: absolute; bottom: -4px; right: -4px; background: rgba(0,0,0,0.9); color: var(--gold); font-size: var(--ui-font-subtext); font-weight: 700; padding: var(--ui-xs) var(--ui-sm); border-radius: var(--ui-radius); border: var(--ui-panel-border); }
.action-sheet-info { flex: 1; min-width: 0; }
.action-sheet-name { font-size: var(--ui-font-title); font-weight: bold; margin-bottom: var(--ui-xs); }
.action-sheet-desc { font-size: var(--ui-font-subtext); color: var(--text-mute); line-height: 1.3; margin-bottom: var(--ui-sm); }
.action-sheet-effects { font-size: var(--ui-font-subtext); color: #8ed88e; font-weight: 500; margin-bottom: var(--ui-xs); }
.action-sheet-stats { font-size: var(--ui-font-subtext); color: var(--blue); font-weight: 500; margin-bottom: var(--ui-xs); }
.action-sheet-stats.tool-stats { color: var(--gold); }
.action-sheet-buttons { display: flex; flex-direction: column; gap: var(--ui-md); }
.action-sheet-buttons-row { display: flex; align-items: stretch; gap: var(--ui-sm); flex-wrap: wrap; }
.action-sheet-buttons-row .action-sheet-btn { flex: 1; min-width: 0; }
.action-sheet-btn.btn-link-icon { flex: 0 0 auto; min-width: 48px; padding: var(--ui-md); }
.action-sheet-btn.btn-link-icon .btn-label { display: none; }
.action-sheet-btn { 
  display: flex; align-items: center; justify-content: center; gap: var(--ui-sm);
  padding: var(--ui-md) var(--ui-lg); border-radius: var(--ui-radius);
  font-size: var(--ui-font-text); font-weight: 600; color: var(--text);
  border: var(--ui-panel-border);
}
.action-sheet-btn:active { transform: scale(0.97); }
.action-sheet-btn .btn-icon { font-size: var(--ui-font-title); }
.btn-equip { background: #4080c0; border-color: var(--blue); color: var(--text); }
.btn-use { background: var(--green); border-color: var(--green); color: var(--text); }
.btn-drop { background: var(--red); border-color: var(--red); color: var(--text); }
.btn-link { background: transparent; border-color: var(--gold); color: #1a1510; }
.btn-unequip { background: var(--gold); border-color: var(--gold); color: #1a1510; }
.btn-cancel { background: var(--stone); border-color: var(--border-l); }
.action-sheet-btn.btn-quick-slot .btn-label,
.action-sheet-btn.btn-quick-slot-pick .btn-label { color: #fff; }

/* Quantity Picker */
.drop-quantity-picker { position: fixed; inset: 0; z-index: 10002; display: flex; align-items: center; justify-content: center; opacity: 0; transition: opacity 0.2s; }
.drop-quantity-picker.visible { opacity: 1; }
.quantity-picker-content { 
  background: var(--stone); border: var(--ui-panel-border);
  border-radius: var(--ui-radius); padding: var(--ui-2xl); min-width: 280px; max-width: 90vw; text-align: center;
  transform: scale(0.9); transition: transform 0.2s;
  box-shadow: var(--ui-shadow-overlay);
}
.drop-quantity-picker.visible .quantity-picker-content { transform: scale(1); }
.quantity-picker-title { font-size: var(--ui-font-title); font-weight: 700; color: var(--gold); margin-bottom: var(--ui-xs); }
.quantity-picker-subtitle { font-size: var(--ui-font-subtext); color: var(--text-mute); margin-bottom: var(--ui-xl); }
.quantity-picker-input-row { display: flex; align-items: center; justify-content: center; gap: var(--ui-md); margin-bottom: var(--ui-lg); }
.qty-btn { 
  width: 44px; height: 44px; border-radius: var(--ui-radius);
  border: var(--ui-panel-border); background: var(--stone-dark);
  color: var(--text); font-size: var(--ui-font-title); font-weight: 600;
}
.qty-btn:hover { background: var(--stone); }
.qty-btn:active { transform: scale(0.98); }
.qty-input { 
  width: 80px; height: 44px; border-radius: var(--ui-radius);
  border: var(--ui-panel-border); background: var(--stone-dark);
  color: var(--gold); font-size: var(--ui-font-title); font-weight: 600; text-align: center;
}
.qty-input:focus { border-color: var(--gold); }
.quantity-picker-presets { display: flex; gap: var(--ui-sm); justify-content: center; margin-bottom: var(--ui-xl); }
.qty-preset { 
  flex: 1; padding: var(--ui-sm) var(--ui-lg); border-radius: var(--ui-radius);
  border: var(--ui-panel-border); background: var(--stone-dark);
  color: var(--text-dim); font-size: var(--ui-font-text);
}
.qty-preset:hover { background: var(--stone); color: var(--text); }
.qty-preset:active { transform: scale(0.98); }
.quantity-picker-actions { display: flex; gap: var(--ui-md); }
.qty-action { 
  flex: 1; padding: var(--ui-md) var(--ui-xl); border-radius: var(--ui-radius); border: var(--ui-panel-border);
  font-size: var(--ui-font-text); font-weight: 600;
}
.qty-action:active { transform: scale(0.98); }
.qty-cancel { background: var(--stone-dark); border-color: var(--border-l); color: var(--text-dim); }
.qty-cancel:hover { background: var(--stone); }
.qty-confirm { background: var(--red); border-color: var(--red); color: var(--text); }

/* Cast Bar */
.cast-bar { position: fixed; top: calc(env(safe-area-inset-top, 0px) + var(--feed-h) + var(--bars-h) + 12px); left: 8px; right: 8px; z-index: 4500; pointer-events: none; display: none; }
.cast-bar.visible { display: block; }
.cast-bar-track { height: 20px; background: var(--stone-dark); border: var(--ui-panel-border); border-radius: var(--ui-radius); overflow: hidden; }
.cast-bar-fill { height: 100%; width: var(--cast-bar-progress, 0%); background: var(--gold); border-radius: var(--ui-radius); transition: width 0.05s linear; }

/* Live Feed */
.live-feed-container { 
  position: fixed; top: 0; left: 0; right: 0; z-index: 5000;
  height: var(--feed-h); padding-top: env(safe-area-inset-top, 0);
  background: var(--bg-panel);
  border-bottom: var(--ui-panel-border);
  display: flex; align-items: center; overflow: hidden; cursor: pointer;
  transition: border-color 0.2s;
}
.live-feed-container:hover { border-bottom-color: var(--gold); }
.live-feed-container::before { content: '💬'; font-size: var(--ui-font-subtext); margin: 0 8px 0 10px; opacity: 0.6; }
.live-feed-container:hover::before { opacity: 1; }
.live-feed { flex: 1; height: 100%; position: relative; overflow: hidden; }
.live-feed-messages { position: absolute; bottom: 0; left: 0; right: 0; display: flex; flex-direction: column; justify-content: flex-end; }
.feed-msg { font-size: var(--ui-font-subtext); line-height: var(--feed-h); height: var(--feed-h); color: var(--text-dim); padding: 0 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: 0; transform: translateY(100%); transition: opacity 0.25s, transform 0.25s; }
.feed-msg.show { opacity: 1; transform: translateY(0); }
.feed-player { color: var(--blue); font-weight: 600; margin-right: 4px; }
.feed-xp { color: #93c5fd; }
.feed-skill { color: #b8a0e8; }
.feed-levelup { color: var(--gold); font-weight: 700; text-shadow: 0 0 10px rgba(232,184,74,0.6); }
.feed-success { color: #8ed88e; }
.feed-warning { color: var(--gold); }
.feed-error { color: #e89090; }
.feed-info { color: var(--text-mute); }
.feed-chat { color: var(--text-dim); }

/* Level Up */
.level-up-overlay { position: fixed; inset: 0; z-index: 25000; display: flex; align-items: center; justify-content: center; pointer-events: none; opacity: 0; transition: opacity 0.3s; background: transparent; }
.level-up-overlay.show { opacity: 1; }
.level-up-overlay.hide { opacity: 0; }
.level-up-content { position: relative; text-align: center; animation: lvlBounce 0.5s cubic-bezier(0.34,1.56,0.64,1); }
.level-up-icon { font-size: 5rem; margin-bottom: 12px; animation: lvlPulse 0.6s ease infinite; filter: drop-shadow(0 0 20px rgba(232,184,74,0.8)); }
.level-up-title { font-size: 3rem; font-weight: 900; color: var(--gold); text-shadow: 0 0 10px #c80, 0 0 30px rgba(200,120,0,1), 0 0 60px rgba(180,100,0,0.8), 0 4px 0 #640; letter-spacing: 6px; margin-bottom: 12px; }
.level-up-level { font-size: 5rem; font-weight: 900; color: var(--text); text-shadow: 0 0 15px var(--gold), 0 0 40px rgba(232,184,74,0.9), 0 0 80px rgba(200,150,50,0.6), 0 4px 0 #444; }
@keyframes lvlBounce { 0% { transform: scale(0.3); opacity: 0; } 50% { transform: scale(1.1); } 100% { transform: scale(1); opacity: 1; } }
@keyframes lvlPulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.15); } }

/* Inventory gain popup (pickup, craft, gather, etc.) */
.inventory-gain-overlay {
  position: fixed;
  inset: 0;
  z-index: 25000;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.35s ease;
  background: transparent;
}
.inventory-gain-overlay.show { opacity: 1; }
.inventory-gain-overlay.hide { opacity: 0; }
.inventory-gain-content {
  position: relative;
  text-align: center;
  padding: 1.5rem 2rem;
  animation: invGainBounce 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.inventory-gain-icons {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.inventory-gain-icon {
  width: 48px !important;
  height: 48px !important;
  border-radius: 8px;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border: 2px solid rgba(232, 184, 74, 0.4);
  box-shadow: 0 2px 8px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.1);
}
.inventory-gain-label {
  font-family: var(--font-ui, MedievalSharp, sans-serif);
  font-size: var(--ui-font-title);
  font-weight: 700;
  color: var(--gold);
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
  margin-bottom: 0.25rem;
  letter-spacing: 0.03em;
}
.inventory-gain-text {
  font-size: var(--ui-font-text);
  color: var(--text);
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  line-height: 1.4;
  max-width: 320px;
}
@keyframes invGainBounce { 0% { transform: scale(0.4); opacity: 0; } 55% { transform: scale(1.05); } 100% { transform: scale(1); opacity: 1; } }

/* Tooltip */
.item-tooltip { 
  position: fixed; z-index: 30000; pointer-events: none;
  background: var(--bg-panel); border: var(--ui-panel-border);
  border-radius: var(--ui-radius); padding: var(--ui-md) var(--ui-lg); max-width: calc(280px * var(--ui-scale, 1));
  box-shadow: var(--ui-shadow-overlay);
}
.tooltip-header { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.tooltip-icon { width: 32px; height: 32px; image-rendering: pixelated; background-size: contain; background-repeat: no-repeat; }
.tooltip-name { font-size: var(--ui-font-text); font-weight: bold; text-shadow: 0 2px 4px rgba(0,0,0,0.5); }
.tooltip-type { font-size: var(--ui-font-subtext); color: var(--text-mute); text-transform: uppercase; }
.tooltip-divider { height: 2px; background: linear-gradient(90deg, transparent, var(--border-l) 50%, transparent); margin: 8px 0; }
.tooltip-stats, .tooltip-effects, .tooltip-triggers { display: flex; flex-direction: column; gap: 4px; }
.tooltip-stat { font-size: var(--ui-font-text); color: var(--text-dim); }
.stat-positive { color: var(--green); font-weight: 600; }
.stat-negative { color: var(--red); font-weight: 600; }
.tooltip-effect-label { font-size: var(--ui-font-subtext); color: var(--text-mute); text-transform: uppercase; }
.tooltip-effect { font-size: var(--ui-font-text); color: #8ed88e; }
.tooltip-trigger-label { font-size: var(--ui-font-subtext); color: var(--gold); margin-top: 4px; }
.tooltip-trigger-effect { font-size: var(--ui-font-subtext); color: #d8b0e0; padding-left: 12px; }
.tooltip-description { font-size: var(--ui-font-subtext); font-style: italic; color: var(--text-mute); line-height: 1.4; }
.tooltip-footer { margin-top: 8px; font-size: var(--ui-font-subtext); color: #5a5045; text-transform: uppercase; letter-spacing: 1px; text-align: right; }
.tooltip-actions { pointer-events: auto; display: flex; align-items: center; justify-content: flex-end; gap: 6px; margin-top: 4px; }
.tooltip-link-btn { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; padding: 0; border: 1px solid var(--border-l); border-radius: 6px; background: rgba(90,74,56,0.5); color: var(--gold); font-size: var(--ui-font-text); cursor: pointer; transition: background 0.15s, color 0.15s; }
.tooltip-link-btn:hover { background: rgba(232,184,74,0.2); color: var(--text); }
.tooltip-link-btn:active { transform: scale(0.96); }

/* Context Menu */
.context-menu { position: fixed; z-index: 30000; background: var(--bg-panel); border: var(--ui-panel-border); border-radius: var(--ui-radius); padding: var(--ui-xs); min-width: calc(150px * var(--ui-scale, 1)); box-shadow: var(--ui-shadow-overlay); }

/* ===== Loading, character creation, intro ===== */
:root {
  --load-w: min(90vw, 440px);
  --load-gap: 1.5rem;
  --load-pad: 1rem;
}

#loadingOverlay {
  position: fixed;
  inset: 0;
  background: #0d0b09 url('/main.gif') center/cover no-repeat;
  color: #e8e0d0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  z-index: 9999;
  padding: var(--load-pad);
  box-sizing: border-box;
  transition: opacity 0.5s ease;
}
#loadingOverlay::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 80% 70% at 50% 50%, transparent 50%, rgba(0,0,0,0.5) 100%);
  pointer-events: none;
  transition: opacity 0.6s ease;
}
#loadingOverlay .loading-fade-to-black {
  position: absolute;
  inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
  z-index: 10;
  transition: opacity 0.6s ease-out;
}
#loadingOverlay.overlay-fading-to-black .loading-fade-to-black { opacity: 1; }

/* Loading: logo bottom fixed at viewport center, controls flow below */
#loadingOverlay .loading-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: var(--load-w);
  flex: 1;
  min-height: 0;
  opacity: 0;
  transition: opacity 0.6s ease-out;
}
#loadingOverlay.loading-visible .loading-content {
  opacity: 1;
  animation: load-fade-in 0.5s ease-out both;
}
@keyframes load-fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
.loading-content.content-exiting {
  opacity: 0;
  animation: none;
}
.loading-content.content-exiting .loading-title,
.loading-content.content-exiting .loading-play-wrap {
  opacity: 0;
}

/* Logo bottom fixed at viewport center; title area height = 50vh minus top padding */
.loading-title {
  width: 100%;
  height: calc(50vh - var(--load-pad));
  min-height: 60px;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  flex-shrink: 0;
  transition: opacity 0.6s ease-out;
}
.loading-title-img {
  width: 100%;
  height: auto;
  max-height: clamp(96px, 34vh, 260px);
  object-fit: contain;
  display: block;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.4));
}

.loading-bottom {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--load-gap);
  flex-shrink: 0;
  padding-top: var(--load-gap);
}
.loading-panel {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.625rem;
}
#loadingOverlay.loading-play-visible .loading-panel { display: none !important; }

.loading-text {
  text-align: center;
  font-family: "MedievalSharp", serif;
  font-size: clamp(15px, 2.7vmin, 19px);
  color: #1a1410;
  text-shadow:
    0 1px 2px rgba(255,255,255,0.6),
    0 0 4px rgba(255,255,255,0.3),
    0 2px 4px rgba(0,0,0,0.15);
  letter-spacing: 0.05em;
  min-height: 1.25em;
}
.loading-text.loading-text--hidden { opacity: 0; min-height: 0; overflow: hidden; }

.progress-bar {
  width: 100%;
  height: 3px;
  background: rgba(0,0,0,0.35);
  border-radius: 2px;
  overflow: hidden;
}
.progress-bar::before {
  content: "";
  display: block;
  height: 100%;
  width: 36%;
  background: #e8b84a;
  border-radius: 2px;
  animation: load-pulse 1.4s ease-in-out infinite;
}
@keyframes load-pulse {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(400%); }
}
#loadingOverlay.loading-play-visible .progress-bar::before {
  animation: none;
  width: 100%;
  transform: none;
}
.progress-fill { height: 100%; width: 0%; visibility: hidden; }

.loading-play-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
  transition: opacity 0.6s ease-out;
}
.loading-play-wrap.play-exiting { opacity: 0; pointer-events: none; }
.loading-play-wrap[hidden] { display: none !important; }

.loading-play-btn {
  padding: 0.75rem 2.5rem;
  font-family: "MedievalSharp", serif;
  font-size: clamp(15px, 2.4vmin, 19px);
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #1a1612;
  background: linear-gradient(180deg, #c9a02a 0%, #a87c1a 100%);
  border: 2px solid rgba(40, 30, 15, 0.9);
  border-radius: 6px;
  cursor: pointer;
  transition: filter 0.2s, transform 0.1s, box-shadow 0.2s;
  box-sizing: border-box;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.25);
}
.loading-play-btn:hover {
  filter: brightness(1.15);
  box-shadow: 0 6px 24px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.3);
}
.loading-play-btn:active { transform: scale(0.98); }

/* Character creation — two squares, fills viewport */
#loadingOverlay.char-creation-mode .loading-title,
#loadingOverlay.char-creation-mode .loading-panel {
  display: none !important;
}
#loadingOverlay.char-creation-mode {
  align-items: stretch;
  justify-content: center;
}
@media (max-width: 639px) {
  #loadingOverlay.char-creation-mode {
    padding: 0.5rem;
  }
}
#loadingOverlay.char-creation-mode .loading-content {
  flex: 1;
  width: 100%;
  max-width: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--load-pad);
  box-sizing: border-box;
  min-height: 0;
}
#loadingOverlay.char-creation-mode .loading-bottom {
  width: 100%;
  min-width: 0;
  max-width: min(96vw, 720px);
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: center;
}
@media (max-width: 639px) {
  #loadingOverlay.char-creation-mode .loading-bottom {
    flex: 1;
    min-height: 0;
  }
}
#loadingOverlay.char-creation-mode .loading-play-wrap {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: transparent;
  border: none;
}
@media (max-width: 639px) {
  #loadingOverlay.char-creation-mode .loading-play-wrap {
    flex: 1;
    min-height: 0;
  }
}

.char-creation-pane {
  width: 100%;
  max-width: min(96vw, 720px);
  padding: 0.5rem;
  background: linear-gradient(160deg, rgba(28, 24, 20, 1) 0%, rgba(22, 18, 14, 1) 100%);
  border: 1px solid rgba(232, 184, 74, 0.18);
  border-radius: 8px;
  box-sizing: border-box;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4), inset 0 1px 0 rgba(232, 184, 74, 0.06);
  opacity: 0;
  transition: opacity 0.6s ease-out;
  display: flex;
  flex-direction: column;
}
.char-creation-pane.char-creation-enter { opacity: 1; }
.char-creation-pane.char-creation-exiting {
  opacity: 0;
  transition: opacity 0.6s ease-out;
  pointer-events: none;
}

/* Mobile: 90% viewport window, centered, fields scroll, button fixed at bottom */
@media (max-width: 639px) {
  .char-creation-pane {
    width: 90vw;
    max-width: 90vw;
    height: 90dvh;
    max-height: 90dvh;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }
  .character-creation-wrap {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }
}
/* Desktop: use available vertical space, avoid unnecessary scroll */
@media (min-width: 640px) {
  .char-creation-pane {
    max-height: 92vh;
    overflow: auto;
    align-self: center;
  }
  .character-creation-wrap {
    width: 100%;
  }
}

/* Desktop: two equal squares. Mobile: stacked column */
.char-creation-layout {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto 1fr;
  gap: 0.5rem;
  width: 100%;
  max-width: 95vw;
  margin: 0 auto;
}
@media (max-width: 639px) {
  .char-creation-layout {
    grid-template-rows: 1fr minmax(0, auto);
    flex: 1;
    min-height: 0;
    overflow: hidden;
    gap: 0.5rem;
    padding-bottom: env(safe-area-inset-bottom, 0.25rem);
  }
}
@media (min-width: 640px) {
  .char-creation-layout {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto;
    max-width: min(90vw, 680px);
  }
}

.char-creation-preview-section,
.char-creation-options-section {
  width: 100%;
  min-width: 0;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  background: rgba(0,0,0,0.2);
  border-radius: 6px;
  border: 1px solid rgba(232, 184, 74, 0.08);
}
@media (min-width: 640px) {
  .char-creation-preview-section,
  .char-creation-options-section {
    min-height: min(55vh, 480px);
    overflow: hidden;
  }
}
.char-creation-preview-section {
  position: relative;
  justify-content: center;
  align-items: center;
  flex-shrink: 0;
}
@media (max-width: 639px) {
  .char-creation-preview-section {
    flex: 1;
    min-height: 0;
    min-width: 0;
    align-self: stretch;
    justify-self: stretch;
  }
}
.char-creation-options-section {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
@media (max-width: 639px) {
  .char-creation-options-section {
    min-height: 0;
    overflow: hidden;
  }
}
@media (min-width: 640px) {
  .char-creation-options-section {
    min-height: 200px;
  }
}

.char-creation-preview-wrap {
  position: absolute;
  inset: 0.5rem;
  display: flex;
  justify-content: center;
  align-items: center;
}
.char-creation-preview-box {
  flex-shrink: 0;
  position: relative;
}
.char-creation-preview {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  width: 100%;
  height: 100%;
  display: block;
}

.char-preview-arrow {
  position: absolute;
  width: 2rem;
  height: 2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(24, 20, 16, 0.9);
  border: 1px solid rgba(232, 184, 74, 0.2);
  border-radius: 5px;
  cursor: pointer;
  z-index: 1;
  color: rgba(232, 224, 208, 0.6);
  padding: 0;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.char-preview-arrow:hover {
  color: #e8b84a;
  border-color: rgba(232, 184, 74, 0.4);
  background: rgba(32, 28, 22, 0.95);
}
.char-preview-arrow svg { width: 0.75rem; height: 0.75rem; }
.char-preview-arrow--left { left: 0.25rem; top: 50%; transform: translateY(-50%); }
.char-preview-arrow--right { right: 0.25rem; top: 50%; transform: translateY(-50%); }

.char-creation-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: #e8e0d0;
  margin: 0 0 0.375rem;
  flex-shrink: 0;
  letter-spacing: 0.02em;
}
.char-creation-form {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.char-creation-fields {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  touch-action: pan-y;
}
@media (max-width: 639px) {
  .char-creation-fields {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    touch-action: pan-y;
  }
}
.char-creation-field { display: flex; flex-direction: column; gap: 0.125rem; }
.char-creation-label { font-size: 0.75rem; color: rgba(232, 224, 208, 0.6); }
.char-creation-input,
.char-creation-select {
  width: 100%;
  font-size: 0.875rem;
  color: #e8e0d0;
  background: rgba(18, 15, 12, 0.8);
  border: 1px solid rgba(90, 80, 65, 0.4);
  padding: 0.375rem 0.5rem;
  min-height: 2rem;
  border-radius: 5px;
  box-sizing: border-box;
}
.char-creation-select {
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 12 12'%3E%3Cpath fill='%23e8b84a' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  padding-right: 1.75rem;
}
.char-creation-input:focus,
.char-creation-select:focus {
  border-color: rgba(232, 184, 74, 0.5);
  outline: none;
  box-shadow: 0 0 0 2px rgba(232, 184, 74, 0.15);
}
.char-creation-input::placeholder { color: rgba(232, 224, 208, 0.4); }
@media (max-width: 639px) {
  .char-creation-input,
  .char-creation-select { min-height: 2.5rem; }
}
.char-creation-appearance {
  padding-top: 0.5rem;
  margin-top: 0.25rem;
  border-top: 1px solid rgba(232, 184, 74, 0.12);
}
.char-creation-section-label {
  font-size: 0.65rem;
  color: rgba(232, 224, 208, 0.55);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 0.25rem;
}
.char-creation-equipment {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.375rem 0.5rem;
}
.char-creation-random-wrap { display: flex; flex-direction: column; gap: 0.125rem; }
.char-creation-random-btn {
  width: 100%;
  height: 2rem;
  font-size: 0.75rem;
  font-family: "MedievalSharp", serif;
  color: rgba(232, 224, 208, 0.7);
  background: rgba(22, 19, 16, 0.7);
  border: 1px solid rgba(90, 80, 65, 0.35);
  border-radius: 5px;
  cursor: pointer;
  padding: 0 0.5rem;
  box-sizing: border-box;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.char-creation-random-btn:hover {
  color: #e8e0d0;
  border-color: rgba(232, 184, 74, 0.35);
  background: rgba(28, 24, 20, 0.8);
}
@media (max-width: 639px) {
  .char-creation-random-btn { min-height: 2.5rem; }
}

.char-creation-actions {
  flex-shrink: 0;
}
.char-creation-btn {
  flex-shrink: 0;
  width: 100%;
  padding: 0.65rem 1.25rem;
  font-family: "MedievalSharp", serif;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #1a1612;
  background: linear-gradient(180deg, #c9a02a 0%, #a87c1a 100%);
  border: 2px solid rgba(40, 30, 15, 0.9);
  border-radius: 6px;
  cursor: pointer;
  transition: filter 0.2s, transform 0.1s, box-shadow 0.2s;
  box-sizing: border-box;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.25);
}
@media (max-width: 639px) {
  .char-creation-btn {
    min-height: 44px;
    padding: 0.65rem 0.75rem;
  }
}
.char-creation-btn:hover:not(:disabled) {
  filter: brightness(1.15);
  box-shadow: 0 6px 24px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.3);
}
.char-creation-btn:active:not(:disabled) { transform: scale(0.98); }
.char-creation-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.char-creation-error {
  min-height: 0;
  overflow: hidden;
  margin-top: 0.25rem;
  margin-bottom: 0;
  font-size: 0.75rem;
  color: #e74c3c;
  width: 100%;
  flex-shrink: 0;
}
.char-creation-error:not(:empty) { min-height: 1.25rem; }

#loadingOverlay.loading-fade-out .loading-content { opacity: 0; }

/* Intro — black, centered title.png */
#loadingOverlay.intro-screen {
  background: #000;
  background-image: none;
  transition: opacity 1s ease-out;
}
#loadingOverlay.intro-screen::before { display: none; }
#loadingOverlay.intro-screen::before { display: none; }
#loadingOverlay.intro-screen .intro-content {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 11;
  opacity: 0;
  transition: opacity 0.6s ease-out;
}
#loadingOverlay.intro-screen .intro-content.intro-visible { opacity: 1; }
#loadingOverlay.intro-screen .intro-unit {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: min(90vw, 400px);
}
#loadingOverlay.intro-screen .intro-unit .intro-title {
  width: 100%;
  height: auto;
  max-height: min(50vh, 45vw);
  object-fit: contain;
  display: block;
  transform-origin: center center;
  animation: intro-scale 4s ease-out forwards;
}
@keyframes intro-scale {
  0% { transform: scale(0); }
  100% { transform: scale(1); }
}

/* Connection Status */
.connection-status { font-family: "MedievalSharp", serif; }
.connection-status.reconnecting { background: linear-gradient(135deg, rgba(232,184,74,0.9), rgba(200,150,40,0.9)) !important; color: #1a1510 !important; animation: pulse-warning 1.5s ease-in-out infinite; }
.connection-status.failed { background: linear-gradient(135deg, rgba(214,92,92,0.95), rgba(180,60,60,0.95)) !important; }
@keyframes pulse-warning { 0%, 100% { opacity: 1; } 50% { opacity: 0.7; } }

/* Connection lost — matches loading screen (black, white, minimal) */
.connection-lost-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: #000;
  color: #fff;
  z-index: 10002;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 2rem;
  box-sizing: border-box;
}
.connection-lost-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  width: 35vw;
  min-width: 200px;
  max-width: 90vw;
  text-align: center;
}
.connection-lost-title {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: var(--ui-font-title);
  font-weight: 600;
  color: #fff;
  letter-spacing: 0.04em;
}
.connection-lost-text {
  margin: 0;
  font-size: var(--ui-font-text);
  color: rgba(255, 255, 255, 0.75);
  line-height: 1.5;
  font-family: system-ui, -apple-system, sans-serif;
}
.connection-lost-reload {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: var(--ui-font-subtext);
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #fff;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 4px;
  padding: 0.75rem 2rem;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.connection-lost-reload:hover {
  border-color: #fff;
  background: rgba(255, 255, 255, 0.08);
}
.connection-lost-reload:active {
  background: rgba(255, 255, 255, 0.12);
}
@media (max-width: 767px) {
  .connection-lost-content {
    width: 85vw;
    max-width: 85vw;
  }
  .unit-panel { max-width: none; }
}

/* ═══════════════════════════════════════════════════════════════════════════════
   WIDE VIEWPORT - Hide touch controls only; top bar stays 1/3 | 1/3 | 1/3
   ═══════════════════════════════════════════════════════════════════════════════ */

@media (min-width: 768px) {
  /* Hide touch controls when wide (desktop); top bar layout unchanged */
  .joystick-container { display: none !important; }
  .action-btn { display: none !important; }
  .live-feed-container { display: none !important; }

  .unit-panel { max-width: 16rem; }

  .hud-pane-base { padding: 0 !important; }
  .hud-area.bottomLeft {
    grid-area: bl;
    justify-content: flex-start;
    align-items: flex-end;
    padding: 0 0 1.25rem 1.25rem;
  }
  .hud-area.bottomCenter { display: none; }
  .hud-area.bottomRight { display: none; }
  .hud-area.middleLeft { display: none; }
  .hud-area.middleRight { display: none; }
  .health-text,
  .mana-text {
    font-size: var(--bar-text-size);
  }

  /* Right Side Panel - Action Bar (WoW Style) - Always Visible */
  .mobile-menu {
    position: fixed;
    inset: 0;
    z-index: 10000;
    pointer-events: none;
    display: block !important; /* Always visible on desktop */
  }
  /* Force menu to be open on desktop */
  .mobile-menu {
    opacity: 1 !important;
    visibility: visible !important;
  }
  .mobile-menu-backdrop {
    display: none !important; /* No backdrop on desktop */
  }
  .mobile-menu-panel {
    bottom: 0;
    left: auto;
    right: 0;
    top: 0;
    width: var(--desktop-panel-width);
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    border-left: 2px solid var(--border-l);
    border-bottom: none;
    transform: translateX(0) !important; /* Always visible on desktop */
    box-shadow: -4px 0 20px rgba(0,0,0,0.8);
    z-index: 1000;
    pointer-events: auto;
    display: flex !important; /* Always visible */
    opacity: 1 !important;
    visibility: visible !important;
  }
  /* Force menu to appear open on desktop */
  .mobile-menu,
  .mobile-menu.open {
    transform: none !important;
  }
  .mobile-menu.open .mobile-menu-panel {
    transform: translateX(0) !important;
  }
  .mobile-menu-header {
    padding: 20px 24px;
    border-bottom: 2px solid var(--border-l);
    min-height: 60px;
  }
  .mobile-menu-title {
    font-size: var(--ui-font-title);
    font-weight: 600;
  }
  .mobile-menu-close {
    display: none !important; /* Hide close button on desktop - panel is always visible */
  }
  .mobile-menu-content {
    padding: 0;
    overflow-y: auto;
    overflow-x: hidden;
    height: calc(100vh - 60px - 70px); /* Full height minus header and tabs */
    display: block !important; /* Always visible */
  }
  .mobile-menu-content::-webkit-scrollbar {
    width: 10px;
  }
  .mobile-menu-content::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.2);
  }
  .mobile-menu-content::-webkit-scrollbar-thumb {
    background: var(--border-l);
    border-radius: 5px;
  }
  .mobile-menu-content::-webkit-scrollbar-thumb:hover {
    background: var(--border);
  }

  /* Tab Bar - Desktop Size */
  .mobile-menu-tabs {
    position: static;
    display: flex;
    padding: 0;
    border-bottom: 2px solid var(--border-l);
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
    min-height: 70px;
  }
  .mobile-menu-tabs::-webkit-scrollbar {
    display: none;
  }
  .mobile-tab {
    flex: 0 0 auto;
    min-width: 90px;
    padding: 16px 20px;
    cursor: pointer;
    transition: all 0.2s;
    border-bottom: 3px solid transparent;
    background: transparent;
    position: relative;
    white-space: nowrap;
  }
  .mobile-tab:hover:not(.active) {
    background: rgba(232,184,74,0.1);
  }
  .mobile-tab.active {
    border-bottom-color: var(--gold);
    background: rgba(232,184,74,0.15);
    color: var(--gold);
  }
  .mobile-tab .tab-icon {
    font-size: var(--ui-font-title);
    line-height: 1;
    margin-bottom: 6px;
  }
  .mobile-tab .tab-label {
    font-size: var(--ui-font-subtext);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }

  /* Inventory/Equipment - Desktop Grid Size */
  .inventory-grid {
    grid-template-columns: repeat(6, 1fr);
    gap: 12px;
    padding: 24px;
  }
  .equipment-grid.mobile-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    padding: 24px;
  }
  .hud-slot {
    padding: 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    aspect-ratio: 1;
    min-height: 64px;
  }
  .hud-slot:active {
    transform: translateY(0) scale(0.98);
  }
  .hud-slot .slot-icon {
    width: 52px;
    height: 52px;
  }
  .hud-slot .slot-quantity {
    font-size: var(--ui-font-subtext);
  }
  .hud-slot .slot-label {
    font-size: var(--ui-font-subtext);
  }
  .equipment-grid .hud-slot {
    min-height: 90px;
  }

  /* Skills Grid - Desktop Size */
  .skills-grid {
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
    padding: 24px;
  }
  .skill-slot {
    padding: 20px;
    gap: 20px;
  }
  .skill-slot-icon {
    width: 72px;
    height: 72px;
    min-width: 72px;
    font-size: var(--ui-font-title);
  }
  .skill-slot-name {
    font-size: var(--ui-font-text);
  }
  .skill-slot-level {
    font-size: var(--ui-font-subtext);
    padding: 4px 10px;
  }
  .skill-slot-progress-bar {
    height: 12px;
  }
  .skill-slot-xp {
    font-size: var(--ui-font-subtext);
  }

  /* Cards - Desktop Size */
  .mobile-crafting {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 24px;
  }
  .recipe-card, .keybinding-row {
    padding: 18px 20px;
    gap: 16px;
    cursor: pointer;
    transition: all 0.2s;
  }
  .keybinding-row:hover {
    transform: translateX(3px);
  }
  .recipe-name {
    font-size: var(--ui-font-text);
  }
  .recipe-desc {
    font-size: var(--ui-font-subtext);
  }
  .recipe-craft-btn {
    padding: 14px 28px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: var(--ui-font-text);
  }

  /* Keybindings - Desktop Size */
  .keybinding-row .label {
    font-size: var(--ui-font-text);
  }
  .keybinding-row .key-button {
    padding: 12px 20px;
    min-width: 90px;
    font-size: var(--ui-font-text);
    cursor: pointer;
    transition: all 0.2s;
  }
  .keybinding-row .key-button:hover {
    transform: translateY(-1px);
  }

  /* Chat - WoW Style Bottom Panel */
  /* Chat - Bottom Left (WoW Style) */
  .menu-section-chat {
    position: static; /* Not fixed, part of bottomLeft area */
    width: 100%;
    max-width: 500px;
    height: var(--desktop-chat-height);
    border: 2px solid var(--border-l);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.8);
    display: flex;
    flex-direction: column;
    pointer-events: auto;
  }
  .chat-panel {
    height: 100%;
    border-radius: 0;
    border: none;
    background: transparent;
    box-shadow: none;
  }
  .chat-messages {
    padding: 16px 20px;
    gap: 6px;
    flex: 1;
    overflow-y: auto;
    min-height: 0;
  }
  .chat-messages::-webkit-scrollbar {
    width: 10px;
  }
  .chat-messages::-webkit-scrollbar-thumb {
    background: var(--border-l);
    border-radius: 5px;
  }
  .chat-msg {
    padding: 10px 14px;
    cursor: pointer;
    transition: background 0.2s;
    border-radius: 4px;
    font-size: var(--ui-font-text);
  }
  .chat-msg:hover {
    background: rgba(0,0,0,0.3);
  }
  .chat-time {
    font-size: var(--ui-font-subtext);
  }
  .chat-sender {
    font-size: var(--ui-font-text);
  }
  .chat-text {
    font-size: var(--ui-font-text);
  }
  .chat-input-area {
    padding: 14px 20px;
    gap: 12px;
    border-top: 2px solid var(--border);
    background: rgba(0,0,0,0.2);
    min-height: 60px;
  }
  .chat-panel .chat-input {
    padding: 12px 16px;
    font-size: var(--ui-font-text);
  }
  .chat-send-btn {
    padding: 12px 24px;
    font-size: var(--ui-font-text);
    cursor: pointer;
    transition: all 0.2s;
    min-width: 100px;
  }
  .chat-send-btn:hover {
    transform: translateY(-1px);
  }

  /* Settings - Desktop Size */
  .menu-section {
    padding: 0px;
  }
  .menu-section-inventory {
    padding: 0;
  }
  .menu-section-equipment {
    padding: 24px;
  }
  .menu-section-settings, .menu-section-keybindings {
    padding: 24px;
  }
  .setting-card {
    padding: 20px 24px;
    border-radius: 8px;
  }
  .setting-card-title {
    font-size: var(--ui-font-subtext);
    margin-bottom: 16px;
  }
  .setting-control {
    padding: 12px 0;
    gap: 20px;
  }
  .menu-section-settings label {
    font-size: var(--ui-font-text);
  }
  .menu-section-settings input[type="range"] {
    width: 140px;
  }
  .menu-section-settings button {
    padding: 14px 28px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: var(--ui-font-text);
  }
  .menu-section-settings button:hover {
    transform: translateY(-1px);
  }

  /* Action Sheet - Desktop Size */
  .item-action-sheet {
    align-items: center;
    justify-content: center;
  }
  .action-sheet-content {
    position: relative;
    bottom: auto;
    left: auto;
    right: auto;
    width: 520px;
    max-width: 90vw;
    border-radius: 8px;
    padding: 28px;
    transform: scale(0.95);
  }
  .item-action-sheet.visible .action-sheet-content {
    transform: scale(1);
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  }
  .action-sheet-header {
    gap: 20px;
    padding-bottom: 20px;
    margin-bottom: 20px;
  }
  .action-sheet-icon {
    width: 80px;
    height: 80px;
    border-radius: 6px;
  }
  .action-sheet-icon img {
    width: 72px;
    height: 72px;
  }
  .action-sheet-name {
    font-size: var(--ui-font-title);
  }
  .action-sheet-desc {
    font-size: var(--ui-font-text);
  }
  .action-sheet-buttons {
    gap: 14px;
  }
  .action-sheet-btn {
    padding: 16px 24px;
    font-size: var(--ui-font-text);
    cursor: pointer;
    transition: all 0.2s;
  }
  .action-sheet-btn:hover {
    transform: translateY(-2px);
  }

  /* Cast Bar - Desktop Size & Position (Above Chat) */
  .cast-bar {
    bottom: calc(var(--desktop-chat-height) + 30px);
    left: 20px;
    right: auto;
    width: 450px;
    max-width: calc(100vw - var(--desktop-panel-width) - 40px);
    transform: none;
  }
  .cast-bar-track {
    height: 32px;
    border-radius: 6px;
  }

  /* Live Feed - Hidden on Desktop (WoW Style) */
  .live-feed-container {
    display: none !important;
  }

  /* Tooltip - Desktop Size */
  .item-tooltip {
    max-width: 400px;
    padding: 20px 24px;
    border-radius: 8px;
  }
  .tooltip-header {
    gap: 14px;
    margin-bottom: 14px;
  }
  .tooltip-icon {
    width: 48px;
    height: 48px;
  }
  .tooltip-name {
    font-size: var(--ui-font-text);
  }
  .tooltip-type {
    font-size: var(--ui-font-subtext);
  }
  .tooltip-stat {
    font-size: var(--ui-font-text);
  }
  .tooltip-effect {
    font-size: var(--ui-font-text);
  }
  .tooltip-description {
    font-size: var(--ui-font-text);
  }

  /* Context Menu - Desktop Size */
  .context-menu {
    min-width: 220px;
    padding: 8px;
    border-radius: 6px;
  }

  /* Quantity Picker - Desktop Size */
  .quantity-picker-content {
    min-width: 400px;
    padding: 32px;
    border-radius: 10px;
  }
  .quantity-picker-title {
    font-size: var(--ui-font-title);
    margin-bottom: 8px;
  }
  .quantity-picker-subtitle {
    font-size: var(--ui-font-text);
    margin-bottom: 24px;
  }
  .qty-btn {
    width: 50px;
    height: 50px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: var(--ui-font-title);
  }
  .qty-btn:hover {
    transform: scale(1.1);
  }
  .qty-input {
    width: 120px;
    height: 50px;
    font-size: var(--ui-font-title);
    text-align: center;
  }
  .qty-preset {
    padding: 12px 24px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: var(--ui-font-text);
  }
  .qty-preset:hover {
    transform: translateY(-1px);
  }
  .qty-action {
    padding: 16px 28px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: var(--ui-font-text);
  }
  .qty-action:hover {
    transform: translateY(-1px);
  }

}

/* Large Desktop - Enhanced Sizing */
@media (min-width: 1200px) {
  :root {
    --desktop-panel-width: 440px;
    --desktop-unit-frame-width: 360px;
    --desktop-portrait-size: 90px;
    --desktop-bar-height: 36px;
    --desktop-chat-height: 240px;
  }
  .inventory-grid {
    grid-template-columns: repeat(7, 1fr);
    gap: 14px;
    padding: 28px;
  }
  .equipment-grid.mobile-grid {
    grid-template-columns: repeat(5, 1fr);
    gap: 16px;
    padding: 28px;
  }
  .action-sheet-content {
    width: 580px;
    padding: 32px;
  }
  .item-tooltip {
    max-width: 440px;
    padding: 24px 28px;
  }
  .cast-bar {
    width: 500px;
  }
  .unit-name {
    font-size: var(--ui-font-title);
  }
  .health-text {
    font-size: var(--ui-font-text);
  }
  .mana-text {
    font-size: var(--ui-font-subtext);
  }
  .level-badge {
    min-width: 36px;
    height: 36px;
    font-size: var(--ui-font-text);
  }
  
}