/* ════════════════════════════════════════════════════════════════════
   Spellglade — medieval UI theme
   Dark carved wood + iron-bound frames for the HUD, aged parchment inside
   windows, Cinzel for titles/labels and Alegreya for body text. Fonts are
   self-hosted (client/public/fonts, SIL OFL) so the game works offline/LAN.
   ════════════════════════════════════════════════════════════════════ */

@font-face { font-family: "Cinzel"; font-weight: 400; font-display: swap; src: url("/public/fonts/cinzel-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Cinzel"; font-weight: 600; font-display: swap; src: url("/public/fonts/cinzel-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Cinzel"; font-weight: 700; font-display: swap; src: url("/public/fonts/cinzel-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "Alegreya"; font-weight: 400; font-display: swap; src: url("/public/fonts/alegreya-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Alegreya"; font-weight: 400; font-style: italic; font-display: swap; src: url("/public/fonts/alegreya-latin-400-italic.woff2") format("woff2"); }
@font-face { font-family: "Alegreya"; font-weight: 700; font-display: swap; src: url("/public/fonts/alegreya-latin-700-normal.woff2") format("woff2"); }

:root {
  --font-title: "Cinzel", "Trajan Pro", Georgia, serif;
  --font-body: "Alegreya", "Iowan Old Style", Georgia, serif;

  /* Wood & iron (HUD chrome) */
  --wood-900: #140c06;
  --wood-800: #21150b;
  --wood-700: #2f1f11;
  --wood-600: #432c18;
  --wood-500: #5a3c21;
  --iron: #4a4642;
  --iron-light: #7c766e;

  /* Metals */
  --bronze: #9c7a45;
  --gold: #d4ae62;
  --gold-bright: #f3d995;
  --gold-dim: #8a6f3e;

  /* Parchment (window interiors) */
  --parchment: #e8d9b5;
  --parchment-light: #f3e8cc;
  --parchment-dark: #cdb88a;
  --ink: #2a1c0f;
  --ink-soft: #5b4429;
  --ink-faint: #8a7152;

  /* Semantic */
  --blood: #a3281f;
  --hp: #b8231a;
  --hp-light: #e2493c;
  --xp: #7a4fd0;
  --xp-light: #a98bf0;
  --good: #4d8f38;
  --bad: #b3342a;
  --focus: #7fc6ff;

  --slot-size: 46px;
  --bar-slot: 50px;
  --shadow-deep: 0 10px 30px rgba(0, 0, 0, 0.55);

  /* Aged-paper grain, tiled over parchment gradients. */
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.32 0 0 0 0 0.22 0 0 0 0 0.1 0 0 0 0.22 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  /* Wood grain for bars and title strips. */
  --woodgrain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='60'%3E%3Cfilter id='w'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.012 0.35' numOctaves='3' seed='4'/%3E%3CfeColorMatrix values='0 0 0 0 0.1 0 0 0 0 0.06 0 0 0 0 0.02 0 0 0 0.55 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23w)'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--font-body);
  font-size: 16px;
  color: var(--ink);
  background: var(--wood-900);
}

h1, h2, h3 { font-family: var(--font-title); font-weight: 700; margin: 0 0 10px; letter-spacing: 0.04em; }

input, button, select { font: inherit; }

kbd {
  display: inline-block;
  min-width: 1.5em;
  padding: 0 0.35em;
  border: 1px solid var(--gold-dim);
  border-bottom-width: 2px;
  border-radius: 3px;
  background: rgba(0, 0, 0, 0.35);
  color: var(--gold-bright);
  font-family: var(--font-title);
  font-size: 0.72em;
  font-weight: 700;
  line-height: 1.5;
  text-align: center;
}

.hidden { display: none !important; }

/* ── Shared building blocks ─────────────────────────── */

/* Parchment panel with an iron-bound wooden frame and gilded inner rule. */
.frame {
  position: relative;
  border: 3px solid var(--wood-700);
  border-radius: 6px;
  background:
    var(--grain),
    radial-gradient(ellipse at 50% 0%, var(--parchment-light) 0%, transparent 70%),
    radial-gradient(ellipse at 50% 120%, var(--parchment-dark) 0%, transparent 60%),
    var(--parchment);
  box-shadow:
    0 0 0 1px var(--wood-900),
    0 0 0 3px var(--bronze),
    0 0 0 4px var(--wood-900),
    inset 0 0 0 1px rgba(255, 245, 220, 0.5),
    inset 0 0 24px rgba(110, 72, 30, 0.35),
    var(--shadow-deep);
}
/* Iron corner studs */
.frame::before,
.frame::after {
  content: "";
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #d9d2c3, var(--iron) 55%, #1a1816);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  z-index: 2;
}
.frame::before { top: -8px; left: -8px; }
.frame::after { top: -8px; right: -8px; }

/* Buttons: carved wood with a gilded rim. */
button {
  border: 1px solid var(--wood-900);
  border-radius: 4px;
  padding: 8px 18px;
  color: var(--gold-bright);
  font-family: var(--font-title);
  font-weight: 700;
  letter-spacing: 0.05em;
  background:
    var(--woodgrain),
    linear-gradient(180deg, var(--wood-500) 0%, var(--wood-600) 45%, var(--wood-700) 100%);
  box-shadow: inset 0 1px 0 rgba(255, 220, 160, 0.25), inset 0 0 0 1px rgba(212, 174, 98, 0.35), 0 2px 3px rgba(0, 0, 0, 0.35);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.8);
  cursor: pointer;
  transition: filter 0.12s ease, transform 0.05s ease;
}
button:hover { filter: brightness(1.18); }
button:active { transform: translateY(1px); filter: brightness(0.95); }
button:disabled { filter: grayscale(0.7) brightness(0.8); opacity: 0.6; cursor: not-allowed; }
button:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.primary-button {
  width: 100%;
  padding: 11px 18px;
  font-size: 1rem;
  margin-top: 4px;
  color: #fff4d6;
  background:
    var(--woodgrain),
    linear-gradient(180deg, #8d3c24 0%, #6f2a18 50%, #561f11 100%);
  box-shadow: inset 0 1px 0 rgba(255, 200, 160, 0.35), inset 0 0 0 1px rgba(243, 217, 149, 0.55), 0 2px 4px rgba(0, 0, 0, 0.4);
}

.link-button {
  background: transparent;
  border: none;
  box-shadow: none;
  color: #7a3b18;
  text-shadow: none;
  padding: 4px 8px;
  font-size: 0.82rem;
}
.link-button:hover { color: var(--blood); filter: none; text-decoration: underline; }

.ghost-button {
  background: transparent;
  color: var(--ink-soft);
  text-shadow: none;
  border: 1px solid var(--gold-dim);
  box-shadow: none;
}
.ghost-button:hover { background: rgba(90, 60, 33, 0.1); color: var(--ink); filter: none; }

.danger-button {
  background: linear-gradient(180deg, #a13a2c, #7a2218);
  color: #fff0e0;
}

label {
  display: grid;
  gap: 5px;
  margin-bottom: 12px;
  font-family: var(--font-title);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}

input[type="text"],
input[type="password"],
input:not([type]) {
  width: 100%;
  border: 1px solid var(--gold-dim);
  border-radius: 3px;
  padding: 9px 11px;
  font-family: var(--font-body);
  font-size: 1rem;
  letter-spacing: normal;
  color: var(--ink);
  background: rgba(255, 250, 235, 0.75);
  box-shadow: inset 0 2px 4px rgba(90, 60, 30, 0.2);
}
input:focus { outline: 2px solid var(--gold); outline-offset: 0; background: #fffaf0; }

.hint { color: var(--ink-faint); margin: 8px 0 0; font-size: 0.88rem; font-style: italic; }
.status { color: #7a3b18; margin: 10px 0 0; font-size: 0.92rem; min-height: 1.2em; text-align: center; font-style: italic; }

/* Ornamental divider: ——— ✦ ——— */
.flourish {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--bronze);
  font-size: 0.8rem;
  margin: 6px auto 0;
  width: 70%;
}
.flourish span {
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--bronze), transparent);
}

.section-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-title);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 10px 0 6px;
}
.section-label::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--bronze), transparent);
}

/* ════════════════════════════════════════════════════════════════════
   Auth screens
   ════════════════════════════════════════════════════════════════════ */
.auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  height: 100%;
  overflow-y: auto;
  padding: 24px 16px;
  background:
    radial-gradient(ellipse at 50% 38%, rgba(214, 150, 70, 0.22) 0%, transparent 55%),
    radial-gradient(1px 1px at 12% 20%, rgba(255, 240, 210, 0.7), transparent),
    radial-gradient(1px 1px at 78% 14%, rgba(255, 240, 210, 0.6), transparent),
    radial-gradient(1.5px 1.5px at 64% 72%, rgba(255, 240, 210, 0.5), transparent),
    radial-gradient(1px 1px at 30% 82%, rgba(255, 240, 210, 0.55), transparent),
    radial-gradient(1px 1px at 90% 58%, rgba(255, 240, 210, 0.5), transparent),
    radial-gradient(1.5px 1.5px at 8% 64%, rgba(255, 240, 210, 0.45), transparent),
    radial-gradient(ellipse at 50% 120%, #2a1a0c 0%, transparent 60%),
    linear-gradient(180deg, #07070d 0%, #120d0a 60%, #1c120a 100%);
}

.auth-card {
  width: min(540px, 100%);
  padding: 26px 30px 22px;
}
.auth-card.frame::before { top: -8px; left: -8px; }

.auth-hero { text-align: center; margin-bottom: 20px; }
.auth-crest {
  width: 54px;
  height: 54px;
  margin: 0 auto 6px;
  color: #7a3b18;
}
.auth-crest svg { width: 100%; height: 100%; }
.auth-hero h1 {
  margin: 0;
  font-size: 2.3rem;
  letter-spacing: 0.08em;
  color: var(--ink);
  text-shadow: 0 1px 0 rgba(255, 245, 220, 0.8);
}
/* Game wordmark: "Spell" in forest green, "glade" a shade deeper. */
.game-title { white-space: nowrap; }
.game-title .title-spell { color: #3f6e36; }
.game-title .title-glade { color: #223f1e; }
.auth-tagline {
  margin: 6px 0 0;
  color: var(--ink-soft);
  font-style: italic;
  font-size: 1rem;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin-bottom: 18px;
  border-bottom: 2px solid var(--bronze);
}
.auth-tab {
  border: none;
  border-radius: 4px 4px 0 0;
  padding: 9px 0;
  background: transparent;
  box-shadow: none;
  color: var(--ink-faint);
  text-shadow: none;
}
.auth-tab:hover { color: var(--ink); filter: none; background: rgba(90, 60, 33, 0.08); }
.auth-tab.active {
  color: var(--gold-bright);
  background: var(--woodgrain), linear-gradient(180deg, var(--wood-500), var(--wood-700));
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.8);
}

.auth-advanced { margin-top: 14px; font-size: 0.85rem; color: var(--ink-faint); }
.auth-advanced summary { cursor: pointer; user-select: none; }
.auth-advanced label { margin-top: 8px; }

.auth-subheader {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--bronze);
}
.auth-subheader h2 { margin: 0; font-size: 1.2rem; }

/* Character selection: wooden plaques */
.character-list { display: flex; flex-direction: column; gap: 10px; }

.character-card {
  display: flex;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--gold-dim);
  border-radius: 4px;
  background: linear-gradient(180deg, rgba(255, 250, 235, 0.55), rgba(205, 184, 138, 0.35));
  box-shadow: inset 0 0 0 1px rgba(255, 245, 220, 0.4), 0 1px 3px rgba(60, 40, 20, 0.25);
  padding: 10px 12px;
  min-height: 70px;
}
.character-card.selectable { cursor: pointer; transition: box-shadow 0.15s ease, transform 0.15s ease; }
.character-card.selectable:hover {
  box-shadow: inset 0 0 0 1px var(--gold), 0 0 0 1px var(--gold), 0 4px 12px rgba(60, 40, 20, 0.35);
  transform: translateY(-1px);
}

.character-portrait {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-title);
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--gold-bright);
  border: 2px solid var(--gold);
  box-shadow: 0 0 0 2px var(--wood-800), inset 0 -4px 8px rgba(0, 0, 0, 0.45);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
}
.character-portrait.male { background: radial-gradient(circle at 40% 30%, #3f5f94, #1d2e4d); }
.character-portrait.female { background: radial-gradient(circle at 40% 30%, #8f3a5c, #4a1a2e); }

.character-info { flex: 1; min-width: 0; }
.character-name {
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 1.05rem;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.character-meta {
  color: var(--ink-soft);
  font-size: 0.88rem;
  margin-top: 2px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.enter-button { flex-shrink: 0; padding: 8px 14px; font-size: 0.8rem; }

.character-delete {
  flex-shrink: 0;
  background: transparent;
  border: none;
  box-shadow: none;
  color: var(--ink-faint);
  text-shadow: none;
  padding: 2px 9px;
  font-size: 1.2rem;
  line-height: 1.3;
}
.character-delete:hover { color: var(--bad); filter: none; }

.character-card.confirming {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  border-color: var(--bad);
  background: rgba(163, 40, 31, 0.1);
}
.character-delete-label { font-weight: 700; }
.character-delete-row { display: flex; gap: 8px; justify-content: flex-end; }
.character-delete-row button { padding: 6px 14px; font-size: 0.78rem; }

.character-card-new {
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  border: 1px dashed var(--bronze);
  background: rgba(255, 250, 235, 0.25);
  box-shadow: none;
  color: var(--ink-soft);
  text-shadow: none;
  cursor: pointer;
  padding: 12px;
}
.character-card-new:hover { background: rgba(255, 250, 235, 0.55); color: var(--ink); filter: none; }
.character-new-plus { font-size: 1.5rem; line-height: 1; color: #7a3b18; }
.character-slots { font-family: var(--font-body); font-weight: 400; font-size: 0.8rem; letter-spacing: normal; }

/* Character creation */
.char-create-layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
@media (max-width: 560px) { .char-create-layout { grid-template-columns: 1fr; } }

.char-preview {
  width: 100%;
  aspect-ratio: 1;
  border: 2px solid var(--wood-700);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 0 0 1px var(--bronze), inset 0 0 30px rgba(0, 0, 0, 0.6);
  background:
    radial-gradient(circle at 50% 35%, rgba(214, 150, 70, 0.45), transparent 60%),
    linear-gradient(180deg, #1c140d 0%, #2c1d10 100%);
}
.char-preview canvas { display: block; width: 100% !important; height: 100% !important; }

.model-picker-label {
  font-family: var(--font-title);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  margin-bottom: 5px;
}
.model-picker { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.model-option {
  background: rgba(255, 250, 235, 0.5);
  border: 1px solid var(--gold-dim);
  box-shadow: none;
  color: var(--ink-soft);
  text-shadow: none;
}
.model-option:hover { background: rgba(255, 250, 235, 0.85); filter: none; }
.model-option.active {
  color: var(--gold-bright);
  background: var(--woodgrain), linear-gradient(180deg, var(--wood-500), var(--wood-700));
  box-shadow: inset 0 0 0 1px var(--gold);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.8);
}

/* Asset preload progress */
.asset-progress { margin-top: 12px; }
.asset-progress-track {
  height: 8px;
  border-radius: 4px;
  background: rgba(60, 40, 20, 0.25);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}
.asset-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #8d3c24, var(--gold));
  transition: width 0.2s ease-out;
}
.asset-progress-label { display: block; margin-top: 4px; color: var(--ink-faint); font-size: 0.85rem; font-style: italic; }

/* ════════════════════════════════════════════════════════════════════
   Game screen: full-screen world with a floating HUD
   ════════════════════════════════════════════════════════════════════ */
.game-screen {
  position: fixed;
  inset: 0;
  overflow: hidden;
  user-select: none;
}

.world {
  position: absolute;
  inset: 0;
  background: #04050a;
}
.world canvas { display: block; width: 100%; height: 100%; }
/* Soft vignette so HUD elements read against bright tiles. */
.world::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 50%, transparent 55%, rgba(0, 0, 0, 0.45) 100%);
}

/* ── World overlays: nameplates + chat bubbles (js/ui/overlays.js) ── */
.world-overlays {
  position: absolute;
  inset: 0;
  z-index: 5;
  overflow: hidden;
  pointer-events: none;
}
/* Anchor sits at the entity's head; children stack upwards from it. */
.world-anchor {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  will-change: transform;
}
.world-anchor-stack {
  position: absolute;
  left: 0;
  bottom: 0;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 11px;
}

.nameplate {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.nameplate-name {
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 0.74rem;
  letter-spacing: 0.04em;
  line-height: 1.1;
  white-space: nowrap;
  color: #f4ead2;
  text-shadow: 0 0 2px #000, 0 1px 2px #000, 0 0 4px rgba(0, 0, 0, 0.8);
}
.nameplate.npc .nameplate-name { color: var(--gold-bright); }
.nameplate.npc .nameplate-name::before,
.nameplate.npc .nameplate-name::after { content: "✦"; font-size: 0.6em; color: var(--gold); margin: 0 4px; vertical-align: 0.15em; }
.nameplate.monster .nameplate-name { color: #ffb8a8; }

.nameplate-bar {
  position: relative;
  width: 58px;
  height: 7px;
  border: 1px solid #000;
  border-radius: 2px;
  background: linear-gradient(180deg, #140b06, #2a1a0e);
  box-shadow: 0 0 0 1px rgba(156, 122, 69, 0.85), 0 1px 3px rgba(0, 0, 0, 0.6);
  overflow: hidden;
}
.nameplate-fill {
  height: 100%;
  width: 100%;
  transition: width 0.25s ease-out;
  background: linear-gradient(180deg, #e2493c, #b8231a 60%, #7a150e);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
}
.nameplate.self .nameplate-fill,
.nameplate.player .nameplate-fill { background: linear-gradient(180deg, #8fd46b, #4d8f38 60%, #2d5a20); }
.nameplate.self .nameplate-bar { width: 50px; }
.nameplate.low .nameplate-fill { animation: hp-pulse 1s ease-in-out infinite; }
.nameplate-status { display: flex; gap: 2px; justify-content: center; }
.nameplate-status:empty { display: none; }
.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--status-color) 40%, #2a1a0e), #120a05 80%);
  border: 1px solid var(--status-color);
  box-shadow: 0 0 5px color-mix(in srgb, var(--status-color) 70%, transparent), 0 1px 2px #000;
  color: var(--status-color);
  animation: status-badge-in 0.25s ease-out;
}
.status-badge .status-glyph { width: 9px; height: 9px; }
@keyframes status-badge-in { from { transform: scale(0.2); opacity: 0; } }
.nameplate.charmed .nameplate-bar { box-shadow: 0 0 0 1px #ff69b4, 0 0 6px rgba(255, 105, 180, 0.8); }
.nameplate.targeted .nameplate-bar {
  width: 72px;
  height: 9px;
  box-shadow: 0 0 0 1px var(--gold-bright), 0 0 8px rgba(243, 217, 149, 0.75);
}
.nameplate.targeted .nameplate-name { color: #fff; }

.chat-bubble {
  position: relative;
  max-width: 220px;
  width: max-content;
  padding: 6px 11px 7px;
  border: 1px solid var(--wood-700);
  border-radius: 8px;
  background: var(--grain), linear-gradient(180deg, var(--parchment-light), var(--parchment));
  box-shadow: 0 0 0 1px var(--bronze), 0 4px 10px rgba(0, 0, 0, 0.5);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 0.9rem;
  line-height: 1.25;
  text-align: center;
  overflow-wrap: break-word;
  white-space: normal;
  transform-origin: 50% 100%;
}
/* Tail pointing down at the speaker */
.chat-bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -7px;
  width: 12px;
  height: 12px;
  transform: translateX(-50%) rotate(45deg);
  background: var(--parchment);
  border-right: 1px solid var(--wood-700);
  border-bottom: 1px solid var(--wood-700);
  box-shadow: 1px 1px 0 var(--bronze);
}
.chat-bubble.pop { animation: bubble-pop 0.18s ease-out; }
.chat-bubble.fading { opacity: 0; transition: opacity 0.4s ease; }
@keyframes bubble-pop { from { opacity: 0; transform: scale(0.85); } to { opacity: 1; transform: scale(1); } }

.hud { position: absolute; inset: 0; pointer-events: none; z-index: 10; }
.hud > * { pointer-events: auto; }

/* Dark wooden HUD plate (unit frames, chat, bars). */
.plate {
  border: 2px solid var(--wood-900);
  border-radius: 6px;
  background: var(--woodgrain), linear-gradient(180deg, rgba(58, 38, 20, 0.94), rgba(28, 18, 9, 0.94));
  box-shadow: inset 0 0 0 1px rgba(212, 174, 98, 0.45), 0 4px 14px rgba(0, 0, 0, 0.5);
}

/* ── Unit frames ────────────────────────────────────── */
.unit-frames {
  position: absolute;
  top: 14px;
  left: 14px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
  pointer-events: none;
}
.unit-frames > * { pointer-events: auto; }

.unit-frame {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 280px;
  padding: 8px 12px 8px 8px;
  border: 2px solid var(--wood-900);
  border-radius: 40px 8px 8px 40px;
  background: var(--woodgrain), linear-gradient(180deg, rgba(58, 38, 20, 0.94), rgba(28, 18, 9, 0.94));
  box-shadow: inset 0 0 0 1px rgba(212, 174, 98, 0.45), 0 4px 14px rgba(0, 0, 0, 0.5);
  color: var(--parchment-light);
}
.target-frame { width: 250px; }

.unit-portrait {
  position: relative;
  width: 58px;
  height: 58px;
  flex-shrink: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 1.6rem;
  color: var(--gold-bright);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
  border: 3px solid var(--gold);
  box-shadow: 0 0 0 2px var(--wood-900), inset 0 -6px 12px rgba(0, 0, 0, 0.5);
  background: radial-gradient(circle at 40% 30%, #3f5f94, #1d2e4d);
}
.unit-portrait.female { background: radial-gradient(circle at 40% 30%, #8f3a5c, #4a1a2e); }
.unit-portrait.hostile { background: radial-gradient(circle at 40% 30%, #8a2a1e, #3a0e08); border-color: #c0573f; }
.unit-portrait.friendly-player { background: radial-gradient(circle at 40% 30%, #3a6e3a, #163016); }
.target-frame .unit-portrait { width: 48px; height: 48px; font-size: 1.3rem; }

.unit-level {
  position: absolute;
  bottom: -6px;
  right: -6px;
  min-width: 24px;
  height: 24px;
  padding: 0 4px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--wood-900);
  text-shadow: none;
  background: radial-gradient(circle at 40% 30%, var(--gold-bright), var(--gold) 60%, var(--gold-dim));
  border: 2px solid var(--wood-900);
}

.unit-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.unit-name-row { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
.unit-name {
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  color: var(--gold-bright);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
}
.unit-kind { font-size: 0.72rem; color: var(--parchment-dark); font-style: italic; white-space: nowrap; }
.unit-status { display: flex; gap: 4px; min-height: 0; }
.unit-status:empty { display: none; }
.unit-status { flex-wrap: wrap; }
.status-pill {
  --status-color: #ff69b4;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-family: var(--font-title);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 1px 6px 1px 4px;
  border-radius: 3px;
  background: color-mix(in srgb, var(--status-color) 22%, rgba(20, 12, 6, 0.85));
  border: 1px solid var(--status-color);
  color: color-mix(in srgb, var(--status-color) 45%, #fff);
  box-shadow: 0 0 6px color-mix(in srgb, var(--status-color) 45%, transparent);
  white-space: nowrap;
}
.status-pill .status-glyph { width: 11px; height: 11px; color: var(--status-color); filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.8)); }
.status-pill .status-time { font-family: var(--font-body, inherit); font-weight: 400; opacity: 0.85; margin-left: 2px; letter-spacing: 0; }
.status-pill.compact { padding-right: 5px; }
.status-pill.compact .status-time { margin-left: 0; }
.status-pill.pvp { background: rgba(179, 52, 42, 0.3); border-color: #d9584a; color: #ffc9c0; box-shadow: none; padding-left: 6px; }
.status-pill.status-stun,
.status-pill.status-charm { animation: status-pill-pulse 1.1s ease-in-out infinite; }
@keyframes status-pill-pulse {
  50% { box-shadow: 0 0 10px color-mix(in srgb, var(--status-color) 80%, transparent); }
}

.unit-close {
  align-self: flex-start;
  padding: 0 6px;
  font-size: 1rem;
  line-height: 1.2;
  background: transparent;
  border: none;
  box-shadow: none;
  color: var(--parchment-dark);
}
.unit-close:hover { color: #fff; filter: none; }

/* Resource bars (health etc.) — iron trough with a glossy fill. */
.bar {
  position: relative;
  height: 18px;
  border: 1px solid #000;
  border-radius: 3px;
  background: linear-gradient(180deg, #120b06, #2a1a0e);
  box-shadow: 0 0 0 1px rgba(212, 174, 98, 0.35);
  overflow: hidden;
}
.bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 100%;
  transition: width 0.3s ease;
}
.bar-fill::after {
  content: "";
  position: absolute;
  inset: 0 0 50% 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0.05));
}
.bar.hp .bar-fill { background: linear-gradient(180deg, var(--hp-light), var(--hp) 60%, #7a150e); }
.bar.hp.low .bar-fill { animation: hp-pulse 1s ease-in-out infinite; }
@keyframes hp-pulse { 50% { filter: brightness(1.5); } }
.bar-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 2px #000, 0 0 3px #000;
}
.bar.small { height: 8px; }

/* ── Zone banner, title and toasts ──────────────────── */
.zone-banner {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  padding: 5px 34px;
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.1em;
  color: var(--gold-bright);
  text-shadow: 0 1px 2px #000;
  white-space: nowrap;
  pointer-events: none;
  background: var(--woodgrain), linear-gradient(180deg, rgba(58, 38, 20, 0.95), rgba(28, 18, 9, 0.95));
  border-top: 1px solid var(--gold-dim);
  border-bottom: 1px solid var(--gold-dim);
  clip-path: polygon(0 0, 100% 0, calc(100% - 14px) 50%, 100% 100%, 0 100%, 14px 50%);
}

.zone-title {
  position: absolute;
  top: 18%;
  left: 50%;
  font-family: var(--font-title);
  font-weight: 700;
  font-size: clamp(2rem, 4vw, 3.4rem);
  letter-spacing: 0.14em;
  color: var(--gold-bright);
  text-shadow: 0 2px 0 #000, 0 0 10px rgba(0, 0, 0, 0.85);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translateX(-50%);
  /* Only opacity/transform animate, so it runs on the compositor and never
     competes with the game for the main thread. */
  will-change: opacity, transform;
}
.zone-title.show { animation: zone-title 2.6s ease forwards; }
@keyframes zone-title {
  0% { opacity: 0; transform: translate(-50%, 10px) scale(0.96); }
  15% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  70% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -6px) scale(1); }
}

.toasts {
  position: absolute;
  top: 52px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  width: min(520px, 90vw);
}
.toast {
  padding: 6px 18px;
  border-radius: 4px;
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--gold-bright);
  text-align: center;
  text-shadow: 0 1px 2px #000;
  background: rgba(20, 12, 6, 0.82);
  border: 1px solid var(--gold-dim);
  animation: toast-in 0.18s ease-out;
  transition: opacity 0.4s ease;
}
.toast.error { color: #ffb3a8; border-color: #9a3a2c; }
.toast.success { color: #c9f0b0; border-color: #4d8f38; }
.toast.fade { opacity: 0; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } }

/* ── Quest tracker (right side) ─────────────────────── */
.quest-tracker {
  position: absolute;
  top: 70px;
  right: 16px;
  width: 250px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--parchment-light);
  text-shadow: 0 1px 2px #000, 0 0 4px #000;
  cursor: pointer;
}
.tracker-heading {
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  color: var(--gold);
  border-bottom: 1px solid rgba(212, 174, 98, 0.5);
  padding-bottom: 3px;
}
.tracker-quest-name { font-family: var(--font-title); font-weight: 700; font-size: 0.85rem; color: var(--gold-bright); }
.tracker-quest.ready .tracker-quest-name::after { content: " — Complete!"; color: #b8f0a0; font-family: var(--font-body); font-weight: 400; font-style: italic; }
.tracker-objective { font-size: 0.86rem; padding-left: 12px; position: relative; }
.tracker-objective::before { content: "◆"; position: absolute; left: 0; font-size: 0.6rem; top: 0.3em; color: var(--gold-dim); }
.tracker-objective.done { color: #a9d993; }
.tracker-objective.done::before { content: "✓"; font-size: 0.8rem; top: 0; color: #a9d993; }

/* ── Chat ───────────────────────────────────────────── */
.chat-box {
  position: absolute;
  left: 14px;
  bottom: 14px;
  width: min(400px, 30vw);
  min-width: 280px;
  display: flex;
  flex-direction: column;
  border: 2px solid var(--wood-900);
  border-radius: 6px;
  background: rgba(20, 12, 6, 0.62);
  box-shadow: inset 0 0 0 1px rgba(212, 174, 98, 0.3), 0 4px 14px rgba(0, 0, 0, 0.4);
  transition: background 0.2s ease;
}
.chat-box:hover, .chat-box.composing { background: rgba(20, 12, 6, 0.85); }

.chat-tabs { display: flex; gap: 2px; padding: 4px 6px 0; border-bottom: 1px solid rgba(212, 174, 98, 0.35); }
.chat-tab {
  padding: 3px 10px;
  font-size: 0.7rem;
  border: none;
  border-radius: 3px 3px 0 0;
  background: transparent;
  box-shadow: none;
  color: var(--parchment-dark);
}
.chat-tab:hover { color: var(--gold-bright); filter: none; }
.chat-tab.active { background: rgba(212, 174, 98, 0.22); color: var(--gold-bright); }

.chat-history-list {
  height: 150px;
  overflow-y: auto;
  padding: 6px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--gold-dim) transparent;
  user-select: text;
}
.chat-history-empty { color: var(--parchment-dark); font-size: 0.85rem; font-style: italic; }
.chat-history-entry {
  font-size: 0.92rem;
  line-height: 1.3;
  color: #f4ead2;
  word-break: break-word;
  text-shadow: 0 1px 1px #000;
}
.chat-history-name { font-weight: 700; margin-right: 4px; color: var(--gold-bright); }
.chat-history-entry.system { color: #e8cf8c; font-style: italic; }
.chat-history-entry.error { color: #ff9f8f; font-style: italic; }

.chat-compose { padding: 6px; border-top: 1px solid rgba(212, 174, 98, 0.35); }
.chat-compose input {
  padding: 6px 9px;
  font-size: 0.92rem;
  background: rgba(255, 250, 235, 0.92);
}
.chat-hint {
  padding: 3px 10px 5px;
  font-size: 0.78rem;
  color: var(--parchment-dark);
  font-style: italic;
  border-top: 1px solid rgba(212, 174, 98, 0.2);
}

/* ── Action dock: XP bar + action bar + potion ──────── */
.action-dock {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 5px;
}

.xp-bar {
  position: relative;
  height: 12px;
  border: 1px solid #000;
  border-radius: 6px;
  background: linear-gradient(180deg, #120b06, #2a1a0e);
  box-shadow: 0 0 0 1px rgba(212, 174, 98, 0.45);
  overflow: hidden;
  cursor: default;
}
.xp-bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: linear-gradient(180deg, var(--xp-light), var(--xp) 60%, #45297f);
  transition: width 0.4s ease;
}
/* Quarter notches */
.xp-bar::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(90deg, transparent calc(25% - 1px), rgba(0, 0, 0, 0.6) 25%, transparent calc(25% + 1px),
    transparent calc(50% - 1px), rgba(0, 0, 0, 0.6) 50%, transparent calc(50% + 1px),
    transparent calc(75% - 1px), rgba(0, 0, 0, 0.6) 75%, transparent calc(75% + 1px));
}
.xp-bar-label {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.66rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 1px #000, 0 0 2px #000;
  opacity: 0;
  transition: opacity 0.15s ease;
}
.xp-bar:hover .xp-bar-label { opacity: 1; }

.action-bar-row { display: flex; gap: 10px; align-items: stretch; }

.hotbar {
  display: grid;
  grid-template-columns: repeat(9, var(--bar-slot));
  gap: 5px;
  padding: 7px;
  border: 2px solid var(--wood-900);
  border-radius: 6px;
  background: var(--woodgrain), linear-gradient(180deg, rgba(74, 48, 26, 0.96), rgba(33, 21, 11, 0.96));
  box-shadow: inset 0 0 0 1px rgba(212, 174, 98, 0.5), inset 0 2px 0 rgba(255, 220, 160, 0.12), 0 6px 18px rgba(0, 0, 0, 0.55);
}

.potion-slot {
  padding: 7px;
  border: 2px solid var(--wood-900);
  border-radius: 6px;
  background: var(--woodgrain), linear-gradient(180deg, rgba(74, 48, 26, 0.96), rgba(33, 21, 11, 0.96));
  box-shadow: inset 0 0 0 1px rgba(212, 174, 98, 0.5), 0 6px 18px rgba(0, 0, 0, 0.55);
}

/* ── Slots (action bar, bags, equipment, spellbook) ──── */
.slot {
  position: relative;
  width: var(--slot-size);
  height: var(--slot-size);
  flex-shrink: 0;
  border-radius: 4px;
  border: 1px solid #000;
  background:
    radial-gradient(circle at 50% 40%, rgba(255, 255, 255, 0.06), transparent 70%),
    linear-gradient(180deg, #1a120b, #0d0805);
  box-shadow: 0 0 0 1px var(--gold-dim), inset 0 2px 6px rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
}
.slot.filled { cursor: grab; }
.slot.filled:active { cursor: grabbing; }
.slot:hover { box-shadow: 0 0 0 1px var(--gold-bright), 0 0 8px rgba(243, 217, 149, 0.5), inset 0 2px 6px rgba(0, 0, 0, 0.8); }
.slot.drop-ok { box-shadow: 0 0 0 2px #9fe37e, 0 0 12px rgba(159, 227, 126, 0.7), inset 0 2px 6px rgba(0, 0, 0, 0.8); }
.slot.drag-over { box-shadow: 0 0 0 2px var(--gold-bright), 0 0 14px rgba(243, 217, 149, 0.9), inset 0 0 12px rgba(243, 217, 149, 0.4); }
.slot.drag-source { opacity: 0.35; }

.slot img {
  width: 82%;
  height: 82%;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.8));
}
.slot .item-chip {
  width: 50%;
  height: 50%;
  border-radius: 50%;
  background: var(--item-color, var(--gold));
  box-shadow: inset 0 -3px 6px rgba(0, 0, 0, 0.5), 0 0 10px color-mix(in srgb, var(--item-color, var(--gold)) 60%, transparent);
}
.slot-placeholder {
  width: 64%;
  height: 64%;
  opacity: 0.22;
  pointer-events: none;
  color: var(--parchment-dark);
}
.slot-placeholder svg { width: 100%; height: 100%; }

.slot-count {
  position: absolute;
  right: 3px;
  bottom: 1px;
  font-size: 0.8rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 0 2px #000, 0 1px 1px #000, 0 0 3px #000;
  pointer-events: none;
}

/* Action bar slots */
.hotbar-slot { width: var(--bar-slot); height: var(--bar-slot); cursor: pointer; }
.hotbar-slot.filled { cursor: pointer; }
.hotbar-slot.filled::before {
  /* spell-coloured glow behind the icon */
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 3px;
  background: radial-gradient(circle at 50% 50%, color-mix(in srgb, var(--spell-color, #fff) 45%, transparent), transparent 72%);
  pointer-events: none;
}
.hotbar-slot img { position: relative; }
.hotbar-slot:active { transform: scale(0.95); }
.hotbar-slot.pressed { transform: scale(0.93); filter: brightness(1.4); }

.hotbar-slot .key {
  position: absolute;
  top: 1px;
  left: 2px;
  z-index: 3;
  max-width: calc(100% - 4px);
  padding: 0 3px;
  border: none;
  border-radius: 2px;
  background: transparent;
  box-shadow: none;
  font-family: var(--font-title);
  font-size: 0.66rem;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: 0;
  color: var(--parchment-light);
  text-shadow: 0 0 2px #000, 0 1px 1px #000, 0 0 3px #000;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.hotbar-slot .key:hover { color: var(--gold-bright); background: rgba(0, 0, 0, 0.6); filter: none; }

.hotbar-slot.empty .slot-empty-hint {
  font-size: 1.1rem;
  color: rgba(212, 174, 98, 0.25);
  pointer-events: none;
}

.hotbar-slot.rebinding { box-shadow: 0 0 0 2px var(--focus), 0 0 12px rgba(127, 198, 255, 0.8); }
.hotbar-slot.rebinding .key { background: var(--focus); color: #000; text-shadow: none; }

.hotbar-slot.aiming {
  box-shadow: 0 0 0 2px var(--focus), 0 0 14px rgba(127, 198, 255, 0.9), inset 0 0 12px rgba(127, 198, 255, 0.5);
  animation: aim-pulse 1s ease-in-out infinite;
}
@keyframes aim-pulse { 50% { box-shadow: 0 0 0 2px var(--focus), 0 0 22px rgba(127, 198, 255, 1), inset 0 0 16px rgba(127, 198, 255, 0.7); } }

/* Cooldown: a clockwise sweep plus remaining seconds. */
.cooldown {
  position: absolute;
  inset: 0;
  z-index: 2;
  border-radius: 3px;
  display: none;
  align-items: center;
  justify-content: center;
  background: conic-gradient(rgba(0, 0, 0, 0.78) calc(var(--cd, 0) * 1turn), rgba(0, 0, 0, 0.15) 0);
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 0.95rem;
  color: #fff;
  text-shadow: 0 0 3px #000, 0 1px 2px #000;
  pointer-events: none;
}
.hotbar-slot.cooling img { filter: grayscale(0.75) brightness(0.7) drop-shadow(0 1px 2px rgba(0, 0, 0, 0.8)); }
.hotbar-slot.cooling::before { opacity: 0.3; }
.hotbar-slot.ready-flash::after {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: 4px;
  pointer-events: none;
  animation: ready-flash 0.45s ease-out;
}
@keyframes ready-flash {
  from { box-shadow: 0 0 0 2px var(--gold-bright), 0 0 16px var(--gold-bright); }
  to { box-shadow: 0 0 0 2px transparent, 0 0 0 transparent; }
}

.potion-slot .slot { width: var(--bar-slot); height: var(--bar-slot); cursor: pointer; }
.potion-slot .slot.empty img { filter: grayscale(1) brightness(0.5); opacity: 0.5; }

/* ── Micro menu (bottom-right) ──────────────────────── */
.micro-menu {
  position: absolute;
  right: 14px;
  bottom: 14px;
  display: flex;
  gap: 5px;
  padding: 6px;
  border: 2px solid var(--wood-900);
  border-radius: 6px;
  background: var(--woodgrain), linear-gradient(180deg, rgba(74, 48, 26, 0.96), rgba(33, 21, 11, 0.96));
  box-shadow: inset 0 0 0 1px rgba(212, 174, 98, 0.5), 0 6px 18px rgba(0, 0, 0, 0.55);
}
.micro-button {
  position: relative;
  width: 44px;
  height: 44px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  background: linear-gradient(180deg, #2a1b0e, #140c06);
  box-shadow: 0 0 0 1px var(--gold-dim), inset 0 2px 5px rgba(0, 0, 0, 0.7);
  color: var(--gold);
}
.micro-button svg { width: 26px; height: 26px; }
.micro-button:hover { color: var(--gold-bright); box-shadow: 0 0 0 1px var(--gold-bright), 0 0 8px rgba(243, 217, 149, 0.4); filter: none; }
.micro-button.active { color: var(--gold-bright); background: linear-gradient(180deg, #5a3c21, #2f1f11); box-shadow: 0 0 0 1px var(--gold-bright), inset 0 0 10px rgba(243, 217, 149, 0.35); }
.micro-button .micro-key {
  position: absolute;
  bottom: 1px;
  right: 3px;
  font-size: 0.6rem;
  color: var(--parchment-dark);
  text-shadow: 0 1px 1px #000;
}
.micro-button .micro-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 0.66rem;
  line-height: 16px;
  color: #fff;
  background: var(--blood);
  border: 1px solid var(--gold);
  text-shadow: none;
}

/* ── Aim hint ───────────────────────────────────────── */
.aim-hint {
  position: absolute;
  left: 50%;
  bottom: 104px;
  transform: translateX(-50%);
  padding: 6px 16px;
  border-radius: 4px;
  background: rgba(10, 20, 32, 0.85);
  border: 1px solid var(--focus);
  color: #d8eeff;
  font-size: 0.95rem;
  text-shadow: 0 1px 1px #000;
  white-space: nowrap;
  pointer-events: none;
}
.aim-hint strong { color: #fff; }

/* ════════════════════════════════════════════════════════════════════
   Movable windows
   ════════════════════════════════════════════════════════════════════ */
.game-window {
  position: absolute;
  z-index: 20;
  display: flex;
  flex-direction: column;
  /* Leave the action bar uncovered so spells can always be dragged onto it. */
  max-height: calc(100vh - 140px);
  min-width: 240px;
  padding: 0;
  animation: window-in 0.14s ease-out;
}
@keyframes window-in { from { opacity: 0; transform: scale(0.97); } }

.window-title {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 7px 36px;
  cursor: move;
  border-bottom: 2px solid var(--wood-900);
  background: var(--woodgrain), linear-gradient(180deg, var(--wood-500), var(--wood-700));
  box-shadow: inset 0 -1px 0 var(--gold-dim), inset 0 1px 0 rgba(255, 220, 160, 0.2);
  border-radius: 3px 3px 0 0;
  touch-action: none;
}
.window-title h3 {
  margin: 0;
  font-size: 0.95rem;
  letter-spacing: 0.12em;
  color: var(--gold-bright);
  text-shadow: 0 1px 2px #000;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.window-title h3::before, .window-title h3::after { content: "✦"; font-size: 0.6em; color: var(--gold); margin: 0 8px; vertical-align: 0.2em; }

.window-close {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-body);
  font-size: 1.1rem;
  line-height: 1;
  border-radius: 3px;
  color: var(--parchment-light);
  background: linear-gradient(180deg, #7a2a1c, #4a130a);
  box-shadow: 0 0 0 1px var(--gold-dim);
}
.window-close:active { transform: translateY(-50%) scale(0.94); }

.window-body {
  padding: 12px 14px 12px;
  overflow-y: auto;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--bronze) transparent;
}
.window-hint {
  margin-top: 10px;
  font-size: 0.8rem;
  font-style: italic;
  color: var(--ink-faint);
  text-align: center;
}

/* Bags */
#win-bags { width: 260px; }
.inventory-grid {
  display: grid;
  grid-template-columns: repeat(4, var(--slot-size));
  gap: 8px;
  justify-content: center;
}
.inventory-grid .slot { box-shadow: 0 0 0 1px var(--bronze), inset 0 2px 6px rgba(0, 0, 0, 0.8); }
.inventory-grid .slot:hover { box-shadow: 0 0 0 1px var(--gold-bright), 0 0 8px rgba(243, 217, 149, 0.5), inset 0 2px 6px rgba(0, 0, 0, 0.8); }
.bag-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--bronze);
}
.bag-count { font-size: 0.85rem; color: var(--ink-soft); }

.gold-amount {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 700;
  color: var(--ink);
}
.gold-amount::before {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff3c4, #e0b441 45%, #8a6414);
  box-shadow: 0 0 0 1px #5a3f0c, 0 1px 2px rgba(0, 0, 0, 0.4);
}

/* Character: paper doll */
#win-character { width: 390px; }
.character-body { display: flex; flex-direction: column; gap: 6px; }

.paperdoll {
  position: relative;
  display: grid;
  grid-template-columns: var(--slot-size) 1fr var(--slot-size);
  grid-template-rows: repeat(3, var(--slot-size));
  gap: 12px 10px;
  padding: 10px 14px;
  border: 1px solid var(--bronze);
  border-radius: 4px;
  background: radial-gradient(ellipse at 50% 50%, rgba(90, 60, 33, 0.18), transparent 70%);
}
.paperdoll-figure {
  grid-column: 2;
  grid-row: 1 / span 3;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(90, 60, 33, 0.35);
  pointer-events: none;
}
.paperdoll-figure svg { height: 100%; max-height: 170px; }
.equip-cell { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.equip-label {
  font-family: var(--font-title);
  font-size: 0.56rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
  text-transform: uppercase;
}
.paperdoll [data-slot="head"] { grid-column: 1; grid-row: 1; }
.paperdoll [data-slot="chest"] { grid-column: 1; grid-row: 2; }
.paperdoll [data-slot="legs"] { grid-column: 1; grid-row: 3; }
.paperdoll [data-slot="weapon"] { grid-column: 3; grid-row: 1; }
.paperdoll [data-slot="offhand"] { grid-column: 3; grid-row: 2; }
.paperdoll [data-slot="accessory"] { grid-column: 3; grid-row: 3; }
.paperdoll .equip-cell .equip-label { display: none; }
/* Equipment slots nudge up so their placeholder shape shows what fits. */

.stats-panel { display: flex; flex-direction: column; }
.stats-empty { color: var(--ink-faint); font-style: italic; margin: 0; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 18px; }
.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 3px 0;
  border-bottom: 1px dotted rgba(90, 60, 33, 0.35);
}
.stat-label { font-family: var(--font-title); font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em; color: var(--ink-soft); }
.stat-value { font-weight: 700; font-size: 1rem; }
.stat-bonus { font-size: 0.8rem; color: var(--good); font-weight: 400; margin-left: 3px; }
.stat-colors { display: flex; flex-wrap: wrap; gap: 6px 12px; }
.stat-color-chip { display: inline-flex; align-items: center; gap: 5px; font-weight: 700; }
.stat-color-swatch {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.45);
  box-shadow: inset 0 -2px 3px rgba(0, 0, 0, 0.3);
}

/* PvP toggle as a wax-seal switch */
.pvp-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 0 0;
  padding: 8px 10px;
  border: 1px solid var(--bronze);
  border-radius: 4px;
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 400;
  letter-spacing: normal;
  color: var(--ink-soft);
  background: rgba(255, 250, 235, 0.35);
}
.pvp-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.pvp-switch {
  position: relative;
  width: 44px;
  height: 22px;
  flex-shrink: 0;
  border-radius: 11px;
  background: #4a3a2a;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.6), 0 0 0 1px var(--gold-dim);
  transition: background 0.15s ease;
}
.pvp-switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #cfc6b6, #7c766e);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  transition: left 0.15s ease, background 0.15s ease;
}
.pvp-toggle input:checked + .pvp-switch { background: #6e1b12; }
.pvp-toggle input:checked + .pvp-switch::after { left: 24px; background: radial-gradient(circle at 35% 30%, #ff8a70, #a3281f 60%, #5a0f08); }
.pvp-toggle input:focus-visible + .pvp-switch { outline: 2px solid var(--focus); outline-offset: 2px; }
.pvp-toggle strong { font-family: var(--font-title); font-size: 0.78rem; color: var(--ink); letter-spacing: 0.06em; }

/* Spellbook */
#win-spellbook { width: 460px; }
.spellbook { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.spellbook .spellbook-empty { grid-column: 1 / -1; }
.spellbook-empty { color: var(--ink-faint); font-style: italic; text-align: center; padding: 18px 8px; }
.spell-entry {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 8px 5px 5px;
  border: 1px solid rgba(156, 122, 69, 0.55);
  border-radius: 4px;
  background: linear-gradient(90deg, rgba(255, 250, 235, 0.5), rgba(255, 250, 235, 0.15));
}
.spell-entry:hover { background: linear-gradient(90deg, rgba(255, 250, 235, 0.8), rgba(255, 250, 235, 0.3)); }
.spell-entry .slot { --slot-size: 44px; cursor: grab; }
.spell-entry .slot::before {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 3px;
  background: radial-gradient(circle, color-mix(in srgb, var(--spell-color, #fff) 45%, transparent), transparent 72%);
  pointer-events: none;
}
.spell-entry .slot img { position: relative; }
.spell-info { flex: 1; min-width: 0; }
.spell-name { font-family: var(--font-title); font-weight: 700; font-size: 0.92rem; }
.spell-meta { font-size: 0.82rem; color: var(--ink-soft); }
.spell-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spell-meta { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spell-bound {
  position: absolute;
  top: -5px;
  right: -5px;
  z-index: 3;
  font-size: 0.66rem;
  pointer-events: none;
}
.spell-add { padding: 2px 8px; font-size: 0.64rem; margin-top: 2px; }

/* Quests */
#win-quests { width: 360px; }
.quest-card {
  border: 1px solid rgba(156, 122, 69, 0.6);
  border-radius: 4px;
  background: rgba(255, 250, 235, 0.4);
  padding: 9px 11px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 8px;
}
.quest-card.ready { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold), 0 0 10px rgba(212, 174, 98, 0.5); }
.quest-card-name { font-family: var(--font-title); font-weight: 700; font-size: 0.95rem; }
.quest-card-desc { font-size: 0.9rem; color: var(--ink-soft); font-style: italic; line-height: 1.35; }
.quest-objectives { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 2px; }
.quest-objective { font-size: 0.9rem; }
.quest-objective.done { color: var(--good); text-decoration: line-through; }
.quest-card-rewards { font-size: 0.85rem; color: var(--ink-soft); }
.quest-card-rewards strong { font-family: var(--font-title); font-size: 0.72rem; letter-spacing: 0.06em; color: var(--ink); }
.quest-button { align-self: flex-end; padding: 5px 14px; font-size: 0.78rem; }
.quest-empty { color: var(--ink-faint); font-style: italic; text-align: center; padding: 16px 6px; }

/* Merchant */
#win-merchant { width: 340px; }
.trade-gold { display: flex; justify-content: flex-end; }
.trade-list { display: flex; flex-direction: column; gap: 5px; }
.trade-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 4px 4px;
  border: 1px solid rgba(156, 122, 69, 0.55);
  border-radius: 4px;
  background: rgba(255, 250, 235, 0.4);
}
.trade-row .slot { --slot-size: 38px; cursor: default; }
.trade-row-info { flex: 1; min-width: 0; }
.trade-row-name { font-weight: 700; font-size: 0.92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trade-row-stats { font-size: 0.8rem; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trade-button { padding: 5px 10px; font-size: 0.72rem; white-space: nowrap; flex-shrink: 0; }
.trade-empty { color: var(--ink-faint); font-size: 0.88rem; font-style: italic; }
.sell-box {
  padding: 12px 10px;
  border: 1px dashed var(--bronze);
  border-radius: 4px;
  text-align: center;
  font-size: 0.85rem;
  font-style: italic;
  color: var(--ink-faint);
  background: rgba(255, 250, 235, 0.25);
  transition: background 0.15s ease, color 0.15s ease;
}
body.dragging-item #win-merchant .sell-box { background: rgba(212, 174, 98, 0.25); color: var(--ink); border-style: solid; }
#win-merchant.drag-over .sell-box { background: rgba(159, 227, 126, 0.3); border-color: var(--good); }

/* Game menu / keybinds / help */
#win-menu { width: 260px; }
.menu-body { display: flex; flex-direction: column; gap: 8px; padding: 16px; }
.menu-button { width: 100%; padding: 10px; }
.menu-button.danger { background: var(--woodgrain), linear-gradient(180deg, #7a2a1c, #4a130a); }
.menu-button.primary { margin-top: 6px; }

/* Music / sound-effect volume (game menu) — reuses the PvP wax-seal switch */
.audio-controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 4px;
  padding: 8px 10px 10px;
  border: 1px solid var(--bronze);
  border-radius: 4px;
  background: rgba(255, 250, 235, 0.35);
}
.audio-control { display: flex; flex-direction: column; gap: 8px; }
.audio-control-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.audio-toggle { display: flex; align-items: center; gap: 10px; margin: 0; cursor: pointer; }
.audio-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.audio-toggle input:checked + .pvp-switch { background: #5a4417; }
.audio-toggle input:checked + .pvp-switch::after { left: 24px; background: radial-gradient(circle at 35% 30%, #fff2c4, var(--gold) 60%, #7a5a20); }
.audio-toggle input:focus-visible + .pvp-switch { outline: 2px solid var(--focus); outline-offset: 2px; }
.audio-toggle strong { font-family: var(--font-title); font-size: 0.78rem; color: var(--ink); letter-spacing: 0.06em; }
.audio-volume-value { font-family: var(--font-body); font-size: 0.85rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.audio-volume {
  --fill: 60%;
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 8px;
  margin: 0;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--gold-dim) 0 var(--fill), #4a3a2a var(--fill) 100%);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.55), 0 0 0 1px var(--gold-dim);
  cursor: pointer;
}
.audio-volume:disabled { opacity: 0.45; cursor: default; }
.audio-volume::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid #5a3c21;
  background: radial-gradient(circle at 35% 30%, #fff2c4, var(--gold) 60%, #7a5a20);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}
.audio-volume::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid #5a3c21;
  background: radial-gradient(circle at 35% 30%, #fff2c4, var(--gold) 60%, #7a5a20);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}
.audio-volume:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }

#win-keybinds { width: 360px; }
.keybind-list { display: flex; flex-direction: column; gap: 4px; }
.keybind-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px;
  border-bottom: 1px dotted rgba(90, 60, 33, 0.35);
}
.keybind-row .keybind-name { flex: 1; font-size: 0.92rem; }
.keybind-row .keybind-name small { color: var(--ink-faint); font-style: italic; }
.keybind-button { min-width: 90px; padding: 4px 10px; font-size: 0.78rem; }
.keybind-button.listening { background: var(--focus); color: #000; text-shadow: none; }
.keybind-clear { padding: 4px 8px; font-size: 0.78rem; }
.keybind-fixed { min-width: 90px; text-align: center; }
.keybind-footer { display: flex; justify-content: flex-end; margin-top: 10px; }

#win-help { width: 420px; }
.help-body h4 {
  font-family: var(--font-title);
  font-size: 0.8rem;
  letter-spacing: 0.1em;
  margin: 12px 0 6px;
  color: var(--ink-soft);
}
.help-body h4:first-child { margin-top: 0; }
.help-body dl { display: grid; grid-template-columns: auto 1fr; gap: 5px 12px; margin: 0; font-size: 0.92rem; }
.help-body dt { white-space: nowrap; text-align: right; }
.help-body dd { margin: 0; }

/* ── Tooltip ────────────────────────────────────────── */
.tooltip {
  position: fixed;
  z-index: 100;
  max-width: 290px;
  min-width: 170px;
  padding: 9px 12px 10px;
  pointer-events: none;
  border: 2px solid var(--wood-900);
  border-radius: 4px;
  background: var(--grain), linear-gradient(180deg, rgba(38, 25, 13, 0.97), rgba(20, 12, 6, 0.97));
  box-shadow: inset 0 0 0 1px var(--gold-dim), 0 8px 20px rgba(0, 0, 0, 0.6);
  color: #efe2c2;
  font-size: 0.9rem;
  line-height: 1.35;
}
.tt-title { font-family: var(--font-title); font-weight: 700; font-size: 1rem; color: var(--gold-bright); }
.tt-sub { color: #bfae8a; font-size: 0.82rem; font-style: italic; margin-bottom: 4px; }
.tt-stat { color: #9fe37e; }
.tt-line { color: #efe2c2; }
.tt-desc { color: #f3d995; margin: 4px 0; }
.tt-price { margin-top: 5px; color: #e8cf8c; }
.tt-price .gold-amount { color: #f3d995; }
.tt-hint { margin-top: 6px; padding-top: 5px; border-top: 1px solid rgba(212, 174, 98, 0.3); color: #9c8e74; font-size: 0.78rem; font-style: italic; }
.tt-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 50%; border: 1px solid rgba(0, 0, 0, 0.5); vertical-align: -1px; margin-left: 3px; }
.tt-pattern { display: inline-grid; gap: 2px; margin: 6px 0 2px; padding: 4px; border: 1px solid rgba(212, 174, 98, 0.3); border-radius: 3px; }
.tt-pattern span { width: 9px; height: 9px; border-radius: 1px; background: rgba(255, 255, 255, 0.07); }
.tt-pattern span.on { background: var(--spell-color, var(--gold)); box-shadow: 0 0 4px var(--spell-color, var(--gold)); }
.tt-pattern span.caster { background: transparent; box-shadow: inset 0 0 0 2px #fff; border-radius: 50%; }
.tt-pattern span.on.caster { background: var(--spell-color, var(--gold)); box-shadow: inset 0 0 0 2px #fff; }
.tt-row { display: flex; justify-content: space-between; gap: 12px; }

/* Drag ghost for HTML5 drag (hidden offscreen, used via setDragImage). */
.drag-ghost { position: fixed; top: -200px; left: -200px; width: 44px; height: 44px; pointer-events: none; }

/* ── Death overlay ──────────────────────────────────── */
.death-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, rgba(40, 0, 0, 0.35) 0%, rgba(20, 0, 0, 0.85) 100%);
  z-index: 1000;
  pointer-events: none;
  animation: death-in 0.8s ease-out;
}
@keyframes death-in { from { opacity: 0; } }
.death-overlay-inner { text-align: center; }
.death-overlay-text {
  font-family: var(--font-title);
  color: #e0453a;
  font-size: clamp(2.4rem, 6vw, 4.4rem);
  font-weight: 700;
  letter-spacing: 0.16em;
  text-shadow: 0 3px 0 #1a0000, 0 0 30px rgba(0, 0, 0, 0.9);
}
.death-overlay-sub {
  margin-top: 8px;
  font-size: 1.2rem;
  font-style: italic;
  color: #f0c8bc;
  text-shadow: 0 1px 3px #000;
}

/* ── "New version available" banner (js/net/version.js) ── */
.update-banner {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px 8px 16px;
  color: var(--gold-bright);
  border: 2px solid var(--wood-900);
  border-radius: 6px;
  background: var(--woodgrain), linear-gradient(180deg, rgba(58, 38, 20, 0.97), rgba(28, 18, 9, 0.97));
  box-shadow: inset 0 0 0 1px var(--gold-dim), 0 4px 16px rgba(0, 0, 0, 0.5);
  font-size: 0.95rem;
}
.update-banner .primary-button { width: auto; margin-top: 0; padding: 6px 14px; font-size: 0.8rem; }

/* ── Small screens: tighten the HUD ─────────────────── */
@media (max-width: 1100px) {
  :root { --bar-slot: 42px; }
  .unit-frame { width: 230px; }
  .target-frame { width: 210px; }
  .quest-tracker { display: none; }
}
@media (max-width: 860px) {
  .chat-box { width: 260px; min-width: 0; }
  .chat-history-list { height: 100px; }
  .micro-menu { bottom: auto; top: 90px; flex-direction: column; }
}
@media (min-width: 2200px) {
  :root { --bar-slot: 60px; --slot-size: 52px; }
  html, body { font-size: 18px; }
}
