:root {
  color-scheme: dark;
  --bg: #111522;
  --panel: rgba(24, 30, 43, 0.92);
  --panel-edge: rgba(255, 255, 255, 0.14);
  --text: #f7f3df;
  --muted: #b9c0bf;
  --accent: #ffd166;
  --danger: #f26d6d;
  --control: #283044;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

#game {
  display: block;
  width: 100vw;
  height: 100vh;
  image-rendering: pixelated;
  background: #132118;
}

.panel {
  position: fixed;
  left: 50%;
  top: 50%;
  width: min(420px, calc(100vw - 32px));
  min-height: 480px;
  max-height: min(760px, calc(100vh - 32px));
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 28px;
  border: 1px solid var(--panel-edge);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  transform: translate(-50%, -50%);
}

.panel form {
  overflow-y: auto;
  padding-right: 2px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.mark {
  width: 32px;
  height: 32px;
  display: inline-block;
  background:
    linear-gradient(90deg, transparent 0 25%, #ffd166 25% 75%, transparent 75%),
    linear-gradient(transparent 0 20%, #5cc8ff 20% 80%, transparent 80%);
  image-rendering: pixelated;
}

h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1;
  letter-spacing: 0;
}

.status {
  min-height: 24px;
  color: var(--muted);
}

.connection,
.character {
  min-height: 0;
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 18px;
}

.hidden {
  display: none !important;
}

label,
fieldset {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  border: 0;
}

label span,
legend {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.2;
}

input {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  background: #111827;
  color: var(--text);
  outline: none;
}

input:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.segments {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.segment,
.connect,
.play,
.chat-send {
  min-height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  background: var(--control);
  color: var(--text);
  cursor: pointer;
}

.segment.selected {
  border-color: var(--accent);
  background: #374057;
}

.swatches {
  display: grid;
  grid-template-columns: repeat(4, 42px);
  gap: 10px;
}

.account-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  margin-top: auto;
}

.swatch {
  width: 42px;
  height: 42px;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  background: var(--swatch);
  cursor: pointer;
}

.swatch.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(255, 209, 102, 0.28);
}

.connect,
.play {
  width: 100%;
  border-color: #ffd166;
  background: #ffd166;
  color: #1d2430;
  font-weight: 800;
}

.play {
  margin-top: auto;
}

.connect:disabled,
.play:disabled {
  border-color: rgba(255, 255, 255, 0.1);
  background: #596174;
  color: #ccd1d5;
  cursor: progress;
}

.progression {
  position: fixed;
  right: 16px;
  top: 16px;
  width: min(220px, calc(100vw - 32px));
  display: grid;
  gap: 6px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(15, 19, 28, 0.72);
  color: var(--text);
  font-size: 12px;
}

.progression-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.progression-toggle {
  min-width: 24px;
  min-height: 24px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  background: var(--control);
  color: var(--text);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

.progression-body {
  display: grid;
  gap: 6px;
}

.progression.minimized {
  width: min(140px, calc(100vw - 32px));
}

.progression.minimized .progression-body {
  display: none;
}

.gold-text {
  color: #ffd166;
  font-weight: 700;
  font-size: 12px;
}

.hp-stack {
  display: grid;
  gap: 4px;
}

.hp-track {
  width: 100%;
  height: 8px;
  overflow: hidden;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.14);
}

.hp-track span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: 4px;
  background: #2ecc71;
  transition: width 120ms linear, background-color 180ms ease;
}

.hp-text {
  font-size: 12px;
  color: var(--muted);
}

.progress-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.progress-head span,
.xp-text {
  color: var(--muted);
}

.xp-track {
  width: 100%;
  height: 8px;
  overflow: hidden;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.14);
}

.xp-track span {
  display: block;
  width: 0%;
  height: 100%;
  background: #ffd166;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.stat-grid button {
  min-height: 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  background: var(--control);
  color: var(--text);
  cursor: pointer;
}

.stat-grid button:disabled {
  color: var(--muted);
  cursor: default;
  opacity: 0.62;
}

.window-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.window-actions button,
.window-close,
.interact-button,
.item-actions button,
.shop-list button {
  min-height: 28px;
  border: 1px solid #7a5a1e;
  border-radius: 3px;
  background: linear-gradient(180deg, #2e1e08 0%, #1a1208 100%);
  color: #e8c86a;
  cursor: pointer;
  font-size: 12px;
  letter-spacing: 0.03em;
}

.window-close:hover,
.interact-button:hover,
.item-actions button:hover,
.shop-list button:hover {
  background: linear-gradient(180deg, #3e2a10 0%, #2a1808 100%);
  border-color: #c8a040;
}

.window-actions button.selected {
  border-color: #ffd166;
  color: #ffd166;
}

.equipment-slot.legendary, .inventory-slot.legendary, .shop-row.legendary { border-left-color: #ffb84d; }
.equipment-slot.mythic,    .inventory-slot.mythic,    .shop-row.mythic    { border-left-color: #fb7185; }
.equipment-slot.epic,      .inventory-slot.epic,      .shop-row.epic      { border-left-color: #a855f7; }
.equipment-slot.rare,      .inventory-slot.rare,      .shop-row.rare      { border-left-color: #3b82f6; }
.equipment-slot.uncommon,  .inventory-slot.uncommon,  .shop-row.uncommon  { border-left-color: #22c55e; }
.equipment-slot.common,    .inventory-slot.common,    .shop-row.common    { border-left-color: rgba(255,255,255,0.18); }

.game-window {
  position: fixed;
  z-index: 70;
  right: 16px;
  top: 246px;
  width: min(360px, calc(100vw - 32px));
  max-height: calc(100vh - 260px);
  display: grid;
  gap: 10px;
  padding: 0;
  border: 2px solid #7a5a1e;
  border-radius: 4px;
  background: linear-gradient(180deg, #1a1208 0%, #110d06 100%);
  box-shadow: 0 0 0 1px #2e1e08 inset, 0 0 0 3px #0a0804 inset, 0 8px 32px rgba(0,0,0,0.85);
  color: var(--text);
  font-size: 13px;
  overflow-y: auto;
}

.game-window > *:not(.window-head) {
  padding: 0 10px;
}

.game-window > *:not(.window-head):last-child {
  padding-bottom: 10px;
}

.game-window > *:not(.window-head):first-child {
  padding-top: 10px;
}

.bags-window {
  width: min(380px, calc(100vw - 32px));
  max-height: calc(100vh - 260px);
  overflow-y: auto;
}

.house-chest-section {
  margin: 10px 12px 14px;
  padding: 10px 12px 12px;
  border: 1px solid rgba(110, 207, 141, 0.35);
  border-radius: 10px;
  background: rgba(12, 22, 18, 0.55);
}

.house-chest-head {
  margin-bottom: 6px;
}

.house-chest-hint {
  margin: 0 0 10px;
  font-size: 12px;
  line-height: 1.35;
  color: var(--muted);
}

.house-chest-hint strong {
  color: var(--accent);
  font-weight: 600;
}

.shop-window {
  left: 16px;
  right: auto;
  top: 96px;
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 110px);
  overflow-y: auto;
}

.trader-window {
  width: min(380px, calc(100vw - 32px));
  max-height: calc(100vh - 260px);
  overflow-y: auto;
}

.buy-house-window {
  width: min(320px, calc(100vw - 32px));
  max-height: none;
  overflow-y: visible;
}

.buy-house-body {
  display: grid;
  gap: 12px;
  padding-top: 4px;
}

.buy-house-line {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
}

.buy-house-line strong {
  color: var(--text);
  font-weight: 600;
}

.buy-house-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 4px;
}

.buy-house-actions button {
  flex: 1;
  min-width: 100px;
}

.companion-offer-window {
  width: min(360px, calc(100vw - 32px));
  max-height: none;
}

.companion-offer-body {
  display: grid;
  gap: 10px;
  padding-top: 4px;
}

.companion-offer-line {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.companion-offer-line strong {
  color: var(--text);
}

.companion-offer-hint {
  margin: 0;
  font-size: 11px;
  color: rgba(248, 250, 255, 0.55);
  line-height: 1.35;
}

.trader-stock {
  display: grid;
  gap: 6px;
}

.trader-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid #3a2810;
  border-radius: 3px;
  background: rgba(30, 18, 4, 0.7);
}

.trader-item.sold {
  opacity: 0.4;
}

.trader-item-info {
  display: grid;
  gap: 2px;
}

.trader-item-price {
  color: #ffd166;
  font-weight: 700;
  font-size: 12px;
  white-space: nowrap;
}

.trader-sell-head {
  padding-top: 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.10);
  color: var(--muted);
  font-size: 12px;
}

.sell-price {
  color: #ffd166;
  font-size: 11px;
}

.window-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 10px;
  background: linear-gradient(180deg, #2e1e08 0%, #1a1208 100%);
  border-bottom: 1px solid #7a5a1e;
  border-radius: 2px 2px 0 0;
}

.window-head strong {
  color: #e8c86a;
  font-size: 13px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.9);
  letter-spacing: 0.03em;
}

.slot-label,
.nearby-loot span,
.item-stats,
.shop-columns span,
.shop-gold {
  color: var(--muted);
}

.window-close,
.interact-button {
  padding: 0 10px;
}

.equipment-slots,
.inventory-slots {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.equipment-slot,
.inventory-slot {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-left-width: 3px;
  border-radius: 6px;
  background: rgba(17, 24, 39, 0.72);
}

.equipment-slot .slot-label {
  font-size: 11px;
  color: var(--muted);
}

.equipment-slot .item-body,
.inventory-slot .item-body {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 8px;
}

.equipment-slot.empty,
.inventory-slot.empty {
  align-items: center;
  justify-content: center;
  min-height: 64px;
  color: var(--muted);
}

.item-icon {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  display: block;
  background: var(--item-color);
  clip-path: polygon(50% 0, 90% 22%, 80% 100%, 20% 100%, 10% 22%);
}

.item-icon.potion {
  border-radius: 8px 8px 10px 10px;
  clip-path: none;
}

.item-icon.ring {
  border: 4px solid var(--item-color);
  border-radius: 50%;
  background: transparent;
  clip-path: none;
}

.item-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.nearby-loot {
  display: grid;
  gap: 4px;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  background: rgba(17, 24, 39, 0.62);
}

.item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.item-actions button {
  min-height: 24px;
  padding: 0 6px;
  font-size: 12px;
}

.shop-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.shop-columns section {
  min-width: 0;
  display: grid;
  gap: 6px;
}

.shop-list {
  max-height: 300px;
  overflow-y: auto;
  display: grid;
  gap: 6px;
}

.shop-row {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  grid-template-rows: auto auto;
  column-gap: 8px;
  row-gap: 2px;
  align-items: center;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-left-width: 3px;
  border-radius: 6px;
  background: rgba(17, 24, 39, 0.72);
}

.shop-row .item-icon {
  grid-column: 1;
  grid-row: 1 / 3;
  align-self: center;
}

.shop-row strong {
  grid-column: 2;
  grid-row: 1;
  align-self: end;
}

.shop-row .item-stats {
  grid-column: 2;
  grid-row: 2;
  align-self: start;
}

.shop-list button {
  grid-column: 3;
  grid-row: 1 / 3;
  align-self: center;
  min-width: 52px;
  padding: 0 8px;
  white-space: nowrap;
}

.shop-row.empty {
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto;
  min-height: 42px;
  color: var(--muted);
}

.shop-row strong,
.shop-row .item-stats {
  overflow-wrap: anywhere;
}

.chat {
  position: fixed;
  left: 16px;
  bottom: 16px;
  width: min(420px, calc(100vw - 32px));
  display: grid;
  grid-template-rows: 28px 26px minmax(112px, 180px) 42px;
  gap: 8px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(15, 19, 28, 0.72);
}

.chat-tabs {
  display: flex;
  gap: 6px;
}

.chat-tab {
  flex: 1;
  min-height: 24px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  background: rgba(30, 36, 48, 0.9);
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
}

.chat-tab.selected {
  color: var(--text);
  border-color: rgba(255, 209, 102, 0.45);
}

.chat-friends-pane {
  overflow-y: auto;
  font-size: 12px;
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  padding: 6px;
}

.friend-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 2px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.friend-row .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
}

.friend-row .dot.on {
  background: #5be38a;
}

.friend-row .dot.off {
  background: #555;
}

.chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.chat-toggle {
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  background: var(--control);
  color: var(--text);
  cursor: pointer;
}

.chat-toggle.has-unread {
  border-color: #ffd166;
  color: #ffd166;
}

.chat-icon-btn {
  display: none;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
  background: rgba(15, 19, 28, 0.85);
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
}

.chat-icon-btn::before {
  content: "";
  display: block;
  width: 20px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.65);
  border-radius: 4px;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -55%);
}

.chat-icon-btn::after {
  content: "";
  display: block;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-top: 5px solid rgba(255,255,255,0.65);
  position: absolute;
  bottom: 9px;
  left: 50%;
  transform: translateX(-60%);
}

.chat.minimized {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  grid-template-rows: unset;
}

.chat.minimized .chat-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat.minimized .chat-head,
.chat.minimized .chat-tabs,
.chat.minimized .chat-messages,
.chat.minimized .chat-friends-pane,
.chat.minimized .chat-form {
  display: none;
}

.chat-messages {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding-right: 4px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.35;
}

.chat-line {
  overflow-wrap: anywhere;
}

.chat-line.system {
  color: #b9c0bf;
}

.chat-line.npc .chat-name {
  color: #ffd27a;
  font-weight: 800;
}

.chat-line.npc {
  color: #e8dfc0;
}

.chat-name {
  color: #ffd166;
  font-weight: 800;
}

.chat-line.mod .chat-name {
  color: #c79cff;
  font-weight: 800;
}

.chat-line.mod {
  color: #e8d8ff;
}

.chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 76px;
  gap: 8px;
}

.chat-form input {
  min-height: 42px;
}

.chat-send {
  min-width: 76px;
  padding: 0 10px;
}

.mobile-controls {
  display: none;
}

.menu {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(8, 10, 16, 0.58);
  backdrop-filter: blur(4px);
}

.menu-panel {
  width: min(360px, calc(100vw - 32px));
  display: grid;
  gap: 16px;
  padding: 20px;
  border: 1px solid var(--panel-edge);
  border-radius: 8px;
  background: rgba(24, 30, 43, 0.96);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
}

.menu-session {
  text-align: center;
  padding-bottom: 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.menu-session-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  overflow-wrap: anywhere;
}

.menu-session-meta {
  margin-top: 6px;
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

.menu-session-sep {
  opacity: 0.5;
}

.menu-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.menu-head strong {
  font-size: 16px;
}

.menu-section {
  display: grid;
  gap: 14px;
}

.menu-debug-toggle {
  width: 100%;
  padding: 10px 14px;
  border-radius: 6px;
  border: 1px solid var(--panel-edge);
  background: var(--control);
  color: var(--text);
  cursor: pointer;
}

.menu-debug-toggle:hover {
  border-color: var(--accent);
}

.menu-debug-toggle[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
}

.menu-close,
.menu-apply {
  min-height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  background: var(--control);
  color: var(--text);
  cursor: pointer;
}

.menu-apply {
  border-color: #ffd166;
  background: #ffd166;
  color: #1d2430;
  font-weight: 800;
}

@media (max-width: 520px) {
  .panel {
    min-height: min(500px, calc(100vh - 32px));
    padding: 20px;
  }

  h1 {
    font-size: 26px;
  }

  .chat:not(.minimized) {
    left: 8px;
    right: 8px;
    bottom: 150px;
    width: auto;
    grid-template-rows: 28px minmax(64px, 100px) 42px;
  }

  .chat.minimized {
    left: 8px;
    bottom: 16px;
  }

  .progression {
    left: 8px;
    right: auto;
    top: 96px;
    width: min(200px, calc(100vw - 16px));
  }

  .progression.minimized {
    width: min(120px, calc(100vw - 16px));
  }

  .game-window {
    left: 8px;
    right: auto;
    top: 310px;
    width: min(260px, calc(100vw - 80px));
    max-height: calc(100vh - 320px);
    touch-action: pan-y;
  }

  .shop-window {
    top: 132px;
    width: min(360px, calc(100vw - 16px));
  }

  .shop-columns {
    grid-template-columns: 1fr;
  }

  .equipment-slots,
  .inventory-slots {
    grid-template-columns: 1fr;
    max-height: 220px;
    overflow-y: auto;
  }

  .menu-panel {
    width: calc(100vw - 20px);
    padding: 16px;
  }
}

@media (hover: none), (pointer: coarse) {
  .mobile-controls:not(.hidden) {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 10px;
    display: block;
    pointer-events: none;
    touch-action: none;
  }

  .mobile-joystick {
    position: absolute;
    left: 12px;
    bottom: 0;
    width: 140px;
    height: 140px;
    pointer-events: auto;
    touch-action: none;
  }

  .mobile-actions {
    position: absolute;
    right: 12px;
    bottom: 0;
    display: grid;
    grid-template-columns: repeat(2, 76px);
    gap: 8px;
  }

  .mobile-controls button {
    min-width: 52px;
    min-height: 52px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 8px;
    background: rgba(24, 30, 43, 0.86);
    color: var(--text);
    font-weight: 800;
    pointer-events: auto;
    touch-action: none;
    user-select: none;
  }

  .mobile-actions button {
    min-width: 76px;
    background: rgba(255, 209, 102, 0.9);
    color: #1d2430;
  }

}

/* ── Home spell cast bar ──────────────────────────────────────────────────── */
#cast-bar {
  position: fixed;
  bottom: 120px;
  left: 50%;
  transform: translateX(-50%);
  width: 200px;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  pointer-events: none;
  z-index: 60;
}
#cast-bar.casting {
  display: flex;
}
#cast-bar-label {
  color: #a8d4ff;
  font-size: 12px;
  font-weight: 600;
  text-shadow: 0 1px 4px rgba(0,0,0,0.8);
  letter-spacing: 0.04em;
}
#cast-bar-track {
  width: 100%;
  height: 8px;
  background: rgba(0,0,0,0.55);
  border: 1px solid rgba(168,212,255,0.4);
  border-radius: 4px;
  overflow: hidden;
}
#cast-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #4a9fff, #a8d4ff);
  border-radius: 4px;
  transition: none;
}

/* ── Equipment window rework ── */
.equipment-window {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 200px);
  overflow-y: auto;
}

.equip-layout {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 10px;
}

.equip-main-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.equip-slots-left,
.equip-slots-right {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.equip-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  flex-shrink: 0;
}

#charPreview {
  border: 1px solid #3a2810;
  border-radius: 3px;
  background: #0c0804;
  image-rendering: pixelated;
}

.char-stats-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 10px;
  align-items: center;
  padding-top: 4px;
  border-top: 1px solid #3a2810;
  font-size: 11px;
}

.char-stats-points-banner {
  flex-basis: 100%;
  margin: 0;
  padding: 4px 8px;
  border-radius: 4px;
  background: rgba(232, 200, 106, 0.08);
  border: 1px solid rgba(232, 200, 106, 0.35);
  color: #e8c86a;
  font-size: 11px;
  font-weight: 600;
}

.char-stat-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  border-radius: 4px;
  border: 1px solid #3a2810;
  background: rgba(0, 0, 0, 0.28);
  color: var(--muted);
}

.char-stat-chip strong {
  color: #e8c86a;
  font-weight: 700;
  min-width: 1.5em;
  text-align: right;
}

.char-talents-mini-section {
  display: grid;
  gap: 6px;
  padding-top: 4px;
  border-top: 1px solid #3a2810;
}

.char-talents-mini-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: 11px;
  color: var(--muted);
}

.char-talents-mini-head strong {
  color: var(--text);
  font-size: 12px;
}

.char-talent-pts-mini {
  color: #e8c86a;
  font-weight: 600;
  white-space: nowrap;
}

.char-talent-mini-icons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.char-talent-mini-empty {
  font-size: 11px;
  color: var(--muted);
  font-style: italic;
}

.char-talent-mini-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 5px 6px 4px;
  border-radius: 4px;
  border: 1px solid #3a2810;
  background: rgba(0, 0, 0, 0.22);
  max-width: 88px;
}

.char-talent-mini-node.on-bar {
  border-color: #7a5a1e;
  box-shadow: 0 0 0 1px rgba(232, 200, 106, 0.28);
}

.char-talent-mini-canvas {
  width: 24px;
  height: 24px;
  display: block;
  image-rendering: pixelated;
}

.char-talent-mini-name {
  font-size: 9px;
  line-height: 1.15;
  color: var(--muted);
  text-align: center;
  max-width: 76px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.equip-window-footer {
  padding-top: 2px;
}

.char-stat-chip .stat-plus-btn {
  width: 22px;
  height: 22px;
  font-size: 14px;
}

.stat-plus-btn {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid #7a5a1e;
  border-radius: 4px;
  background: #2e1e08;
  color: #e8c86a;
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  touch-action: manipulation;
  user-select: none;
}

.talents-open-btn {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #7a5a1e;
  border-radius: 4px;
  background: #2e1e08;
  color: #e8c86a;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  text-align: center;
}

.talents-open-btn:hover {
  background: #3e2a0a;
  border-color: #e8c86a;
}

.talent-window {
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 160px);
  overflow-y: auto;
  top: 200px;
  right: 16px;
}

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

.stat-plus-btn:not(:disabled):hover {
  background: #5a3a10;
  border-color: #e8c86a;
}

.char-stat-points {
  font-size: 10px;
  color: #e8c86a;
  text-align: center;
  padding: 2px 0 4px;
  font-weight: 700;
}

.equip-slot-mini {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 5px 6px;
  border: 1px solid #3a2810;
  border-left-width: 3px;
  border-radius: 3px;
  background: rgba(12, 8, 4, 0.7);
  cursor: pointer;
  min-height: 42px;
}

.equip-slot-mini:hover {
  background: rgba(30, 18, 4, 0.9);
  border-color: #7a5a1e;
}

.equip-slot-mini .slot-label {
  font-size: 10px;
  color: var(--muted);
  line-height: 1;
}

.equip-slot-mini .slot-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.equip-slot-mini.empty .slot-name {
  color: var(--muted);
  font-weight: normal;
}

.equip-slot-mini.legendary { border-left-color: #ffb84d; }
.equip-slot-mini.epic      { border-left-color: #a855f7; }
.equip-slot-mini.rare      { border-left-color: #3b82f6; }
.equip-slot-mini.uncommon  { border-left-color: #22c55e; }
.equip-slot-mini.common    { border-left-color: rgba(255,255,255,0.18); }

/* Talent section */
.talent-section {
  padding: 0 10px 10px;
  display: grid;
  gap: 8px;
}

.talent-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0 4px;
  border-top: 1px solid #3a2810;
  gap: 8px;
}

.talent-points-label {
  font-size: 12px;
  color: #e8c86a;
  font-weight: 700;
}

.talent-tree {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.talent-tree-group {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 5px;
  min-width: 0;
}

.talent-tree-title {
  margin: 0;
  font-size: 11px;
  line-height: 1.2;
  color: #e8c86a;
  text-align: center;
}

.talent-tree-spells {
  display: grid;
  grid-template-rows: repeat(3, minmax(112px, auto));
  gap: 6px;
}

.talent-unlock-btn,
.talent-equip-btn {
  margin-top: 4px;
  font-size: 10px;
  min-height: 20px;
  padding: 0 6px;
  border-radius: 3px;
  cursor: pointer;
  touch-action: manipulation;
  display: block;
  width: 100%;
  user-select: none;
}

.talent-unlock-btn {
  border: 1px solid #7a5a1e;
  background: #2e1e08;
  color: #e8c86a;
}

.talent-unlock-btn:hover {
  background: #3e2a0a;
  border-color: #e8c86a;
}

.talent-equip-btn {
  border: 1px solid #22c55e;
  background: #0e2010;
  color: #22c55e;
}

.talent-equip-btn:hover {
  background: #162a18;
}

.talent-node {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 6px;
  border: 1px solid #2e1e08;
  border-radius: 3px;
  background: #0e0a04;
  cursor: pointer;
  text-align: center;
  position: relative;
  min-width: 0;
}

.talent-node:hover:not(.locked) {
  border-color: #7a5a1e;
  background: #1a1208;
}

.talent-node.unlocked {
  border-color: #c8a040;
  background: #1a1208;
}

.talent-node.locked {
  opacity: 0.45;
  cursor: default;
}

.talent-node.equipped {
  border-color: #22c55e;
}

.talent-node-icon {
  width: 28px;
  height: 28px;
  display: block;
  image-rendering: pixelated;
}

.talent-node-name {
  font-size: 10px;
  font-weight: 700;
  color: #e8c86a;
  line-height: 1.2;
}

.talent-node-desc {
  font-size: 9px;
  color: var(--muted);
  line-height: 1.3;
}

.talent-node-tier {
  position: absolute;
  top: 3px;
  right: 4px;
  font-size: 9px;
  color: var(--muted);
}

.talent-xp-track {
  height: 4px;
  background: rgba(255,255,255,0.08);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 4px;
}
.talent-xp-fill {
  height: 100%;
  background: linear-gradient(90deg, #b8902a, #e8c86a);
  border-radius: 2px;
  transition: width 0.3s;
}

@media (max-width: 640px) {
  .talent-window {
    width: calc(100vw - 16px);
    right: 8px;
  }

  .talent-tree {
    grid-template-columns: 1fr;
  }

  .talent-tree-spells {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: none;
  }
}

/* ── Ability bar ── */
.ability-bar {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 2px solid #7a5a1e;
  border-radius: 4px;
  background: linear-gradient(180deg, #1a1208 0%, #110d06 100%);
  box-shadow: 0 0 0 1px #0a0804 inset, 0 4px 16px rgba(0,0,0,0.8);
  z-index: 50;
}

.ability-bar-toggle {
  width: 20px;
  height: 20px;
  border: 1px solid #7a5a1e;
  border-radius: 3px;
  background: #2e1e08;
  color: #e8c86a;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  flex-shrink: 0;
}

.ability-bar.minimized .ability-slots {
  display: none;
}

.ability-slots {
  display: flex;
  gap: 4px;
}

.ability-slot {
  position: relative;
  width: 52px;
  min-height: 60px;
  height: auto;
  border: 1px solid #3a2810;
  border-radius: 3px;
  background: #0e0a04;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  padding: 4px 2px 20px;
  cursor: pointer;
  overflow: hidden;
  gap: 0;
}

.potion-slot {
  flex-direction: row;
  align-items: center;
  justify-content: center;
  width: 48px;
  min-height: 48px;
  height: 48px;
  padding: 0;
  border-color: #2a6630;
  background: #080e08;
  position: relative;
}

.ability-slot-fill {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 3px;
  width: 100%;
  min-height: 0;
}

.ability-slot-fill canvas,
.ability-slot-fill .item-icon {
  flex-shrink: 0;
}

.ability-slot-fill .item-icon {
  margin-top: 0;
}

.ability-slot:hover {
  border-color: #7a5a1e;
  background: #1a1208;
}

.ability-slot.filled {
  border-color: #7a5a1e;
}

.ability-slot.cooling-down {
  cursor: wait;
}

.ability-slot canvas {
  display: block;
  image-rendering: pixelated;
}

.ability-cooldown {
  position: absolute;
  inset: 0;
  z-index: 2;
  background: rgba(0, 0, 0, 0.58);
  pointer-events: none;
  transform: scaleY(0);
  transform-origin: bottom;
}

.ability-cooldown-text {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  color: #ffffff;
  font-size: 14px;
  font-weight: 800;
  text-shadow: 0 1px 3px #000;
  pointer-events: none;
}

.ability-key {
  position: absolute;
  z-index: 4;
  bottom: 2px;
  right: 3px;
  font-size: 9px;
  font-weight: 700;
  color: var(--muted);
  line-height: 1;
  pointer-events: none;
}

.ability-slot-name {
  display: block;
  width: 100%;
  max-width: 100%;
  flex-shrink: 0;
  margin: 0;
  padding: 0 1px;
  font-size: 9px;
  font-weight: 700;
  line-height: 1.14;
  text-align: center;
  hyphens: auto;
  word-break: break-word;
  overflow-wrap: anywhere;
  color: #f5eacb;
  text-shadow:
    0 0 3px #000000,
    0 1px 0 rgba(12, 6, 2, 0.95),
    0 -1px 0 rgba(12, 6, 2, 0.85),
    1px 0 0 rgba(12, 6, 2, 0.85),
    -1px 0 0 rgba(12, 6, 2, 0.85);
}

.ability-bar-divider {
  width: 1px;
  height: 40px;
  background: #3a2810;
  align-self: center;
  flex-shrink: 0;
}

.safe-zone-indicator {
  position: relative;
  width: 40px;
  height: 48px;
  border: 1px solid #2a4a3a;
  border-radius: 3px;
  background: linear-gradient(180deg, #0e1a14 0%, #060a08 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  line-height: 1;
  flex-shrink: 0;
  user-select: none;
  filter: grayscale(0.15);
  cursor: default;
}

.safe-zone-icon {
  pointer-events: none;
}

.safe-zone-tooltip {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 8px;
  border-radius: 3px;
  border: 1px solid #3d6a52;
  background: rgba(8, 14, 11, 0.96);
  color: #c8f0dc;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s ease-out;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.55);
  z-index: 5;
}

.safe-zone-indicator:hover .safe-zone-tooltip,
.safe-zone-indicator.safe-zone-tooltip-pinned .safe-zone-tooltip {
  opacity: 1;
}

.home-teleport-slot {
  position: relative;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  width: 48px;
  min-height: 48px;
  height: 48px;
  padding: 0;
  flex-shrink: 0;
  cursor: pointer;
  border-color: #4a5a72;
}

.home-teleport-slot:hover {
  border-color: #6e8abf;
  background: linear-gradient(180deg, #121923 0%, #0b101a 100%);
}

.home-teleport-slot:active {
  border-color: #8aa8d9;
}

.home-teleport-key {
  right: 3px;
  bottom: 2px;
  color: #92b8e8;
}

.potion-slot:hover {
  border-color: #3a9944;
  background: #0e1a0e;
}

.potion-slot.has-potions {
  border-color: #3a9944;
}

.potion-slot.no-potions {
  opacity: 0.45;
}

.potion-key {
  right: 3px;
  bottom: 2px;
  color: #4a9944;
}

.potion-count {
  position: absolute;
  bottom: 2px;
  left: 3px;
  font-size: 10px;
  font-weight: 700;
  color: #66cc66;
  line-height: 1;
  pointer-events: none;
}

/* ── Mobile ability bar: vertical stack on right side, 3 slots ── */
body.mobile .ability-bar {
  bottom: auto;
  left: auto;
  top: 50%;
  right: 16px;
  transform: translateY(-50%);
  flex-direction: column;
  gap: 6px;
  /** Above joystick row / overlays so taps reach spells */
  z-index: 120;
  touch-action: manipulation;
}

body.mobile .ability-slot:not(.cooling-down) {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body.mobile .potion-slot,
body.mobile .home-teleport-slot,
body.mobile .ability-bar-toggle {
  touch-action: manipulation;
}

body.mobile .ability-slots {
  flex-direction: column;
  gap: 4px;
}

body.mobile .ability-bar-divider {
  width: 40px;
  height: 1px;
  align-self: center;
}

body.mobile .ability-bar-toggle {
  order: -1;
}

body.mobile .ability-slot[data-slot="3"],
body.mobile .ability-slot[data-slot="4"] {
  display: none;
}

/* —— Party / player context / trade / friends window —— */
.party-panel {
  position: fixed;
  left: 12px;
  top: 72px;
  z-index: 24;
  min-width: 140px;
  max-width: 220px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(12, 16, 24, 0.88);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}

.party-panel.minimized .party-members {
  display: none;
}

.party-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 12px;
}

.party-min {
  min-width: 26px;
  min-height: 22px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: var(--control);
  color: var(--text);
  cursor: pointer;
}

.party-members {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
}

.party-member-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.party-member-row .hpbar {
  flex: 1;
  height: 6px;
  background: #2a2230;
  border-radius: 3px;
  overflow: hidden;
}

.party-member-row .hpbar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #f26d6d, #ffd166);
}

.player-context-menu {
  position: fixed;
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(10, 14, 22, 0.95);
  box-shadow: 0 10px 36px rgba(0, 0, 0, 0.55);
}

.player-context-menu button {
  min-width: 120px;
  text-align: left;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: var(--control);
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
}

.friends-window {
  width: min(320px, calc(100vw - 40px));
  max-height: min(420px, 70vh);
}

.friends-window-list {
  max-height: 340px;
  overflow-y: auto;
  padding: 8px;
  font-size: 12px;
}

.trade-window {
  width: min(480px, calc(100vw - 32px));
}

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

.trade-sub {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 6px;
}

.trade-slots {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 8px;
}

.trade-slot {
  min-height: 44px;
  border: 1px dashed rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  background: rgba(20, 26, 38, 0.9);
  font-size: 10px;
  padding: 4px;
  color: var(--muted);
}

.trade-slot.filled {
  border-style: solid;
  border-color: rgba(255, 209, 102, 0.35);
  color: var(--text);
}

.trade-gold-row,
.trade-gold-readonly {
  font-size: 12px;
  margin-bottom: 6px;
}

.trade-gold-row input {
  width: 80px;
  margin-left: 6px;
}

.trade-actions {
  display: flex;
  gap: 8px;
  padding: 0 12px 12px;
}

.trade-lock,
.trade-ready-flag {
  font-size: 11px;
}
