/* ════════════════════════════════════════════════════════════════════
   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;
  --mp: #1f5fc4;
  --mp-light: #4d8cf0;
  --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);

  /* Mouse cursors: every rule that sets `cursor` also sets --cursor-kind
     (default / interact / attack / grab, inherited like `cursor`).
     js/ui/cursors.js draws that kind's sprite as a software cursor and hides
     the system one (html.soft-cursor); the plain `cursor` values are the
     fallback until the sprites have loaded. */

  /* 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);
  cursor: default; --cursor-kind: default;
}
/* Text fields keep the I-beam instead of inheriting the glove. */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), textarea { cursor: text; --cursor-kind: default; }

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; --cursor-kind: interact;
  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; --cursor-kind: default; }
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; --cursor-kind: interact; 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; --cursor-kind: interact; 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; --cursor-kind: interact;
  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; }
/* Party members: a blue name so the group stands out in a crowd. */
.nameplate.party .nameplate-name { color: #9fd0ff; }

.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; }
/* Quest giver marks over NPCs (overlays.js): ! = quest to take, ? = turn in. */
.quest-mark {
  font-family: "Cinzel", serif;
  font-weight: 700;
  font-size: 22px;
  line-height: 1;
  color: #ffd84a;
  text-shadow: 0 0 2px #000, 0 1px 0 #3a2400, 0 0 8px rgba(255, 196, 40, 0.75);
  animation: quest-mark-bob 1.6s ease-in-out infinite;
  margin-bottom: 1px;
}
.quest-mark.active { color: #b9b2a0; text-shadow: 0 0 2px #000, 0 1px 0 #222; animation: none; }
@keyframes quest-mark-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
.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); } }

/* ── Floating combat text (js/ui/combatText.js) ──
   Sizes here must stay in step with the row heights in config COMBAT_TEXT.styles.
   Outlines are layered text-shadows ("ink" rim + soft drop) so text reads on
   snow, grass and dark dungeon floors alike. */
.combat-text {
  --ct-ink: #140a03;
  --ct-outline: 1px 1px 0 var(--ct-ink), -1px 1px 0 var(--ct-ink), 1px -1px 0 var(--ct-ink), -1px -1px 0 var(--ct-ink),
    0 0 3px var(--ct-ink), 0 2px 4px rgba(0, 0, 0, 0.75);
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 50% 100%;
  white-space: nowrap;
  pointer-events: none;
  will-change: transform, opacity;
  font-family: var(--font-title);
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.02em;
  font-variant-numeric: lining-nums tabular-nums;
  text-shadow: var(--ct-outline);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Numbers */
.ct-damage { font-size: 22px; }
.ct-damage.ct-dealt { color: #fff2d2; }
.ct-damage.ct-taken { color: #ff5a48; }
.ct-damage.ct-other { font-size: 15px; color: #e3c2ae; }
.ct-heal { font-size: 22px; color: #86e870; }
/* Heavy blows (render/impact.js): the number slams in white-hot, tinted with
   the spell colour, shudders, then settles to the normal dealt/taken look. */
.ct-heavy .ct-punch {
  display: inline-block;
  transform-origin: 50% 70%;
  animation: ct-punch 520ms cubic-bezier(0.2, 0.9, 0.25, 1) both;
}
@keyframes ct-punch {
  0% { transform: scale(2.4) rotate(-4deg); color: #fff; text-shadow: var(--ct-outline), 0 0 14px var(--ct-color, #fff), 0 0 26px var(--ct-color, #fff); }
  14% { transform: scale(0.86) translateX(3px) rotate(2deg); color: #fff; }
  22% { transform: scale(1.12) translateX(-3px) rotate(-1deg); }
  30% { transform: scale(0.98) translateX(2px); }
  40% { transform: scale(1.04) translateX(-1px); text-shadow: var(--ct-outline), 0 0 8px var(--ct-color, #fff); }
  100% { transform: scale(1.06); text-shadow: var(--ct-outline), 0 0 6px color-mix(in srgb, var(--ct-color, #fff) 55%, transparent); }
}
@media (prefers-reduced-motion: reduce) { .ct-heavy .ct-punch { animation: none; } }

.ct-heal.ct-other { font-size: 15px; color: #a9d9a0; }
.ct-absorb { font-size: 19px; color: #a9c9ff; }
.ct-absorb .status-glyph { width: 15px; height: 15px; filter: drop-shadow(0 0 1px var(--ct-ink)) drop-shadow(0 1px 2px #000); }

/* Status taking hold: glyph in a coin (like the nameplate badges) + name */
.ct-status {
  font-size: 15px;
  letter-spacing: 0.05em;
  color: color-mix(in srgb, var(--ct-color) 70%, #fff);
  gap: 5px;
}
.ct-glyph {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  color: var(--ct-color);
  background: radial-gradient(circle at 35% 30%, color-mix(in srgb, var(--ct-color) 45%, #2a1a0e), #120a05 80%);
  border: 1px solid var(--ct-color);
  box-shadow: 0 0 6px color-mix(in srgb, var(--ct-color) 70%, transparent), 0 1px 2px #000;
}
.ct-glyph:empty { display: none; }
.ct-glyph .status-glyph { width: 12px; height: 12px; }

.ct-exp { font-size: 14px; letter-spacing: 0.06em; color: #c7adff; }
/* Casino outcomes over the player who spun (ui/casino.js onStationSpin). */
.ct-fortune { font-size: 15px; letter-spacing: 0.05em; font-family: var(--font-title); font-weight: 700; }
.ct-fortune-win { color: #ffd56a; }
.ct-fortune-red { color: #ff7a6e; }
.ct-fortune-black { color: #e8e2d6; }
.ct-fortune-green { color: #7ee08f; }

/* Personal banners: level up, quest, spell learned, death */
.ct-banner {
  flex-direction: column;
  gap: 3px;
  text-shadow: none;
  filter: drop-shadow(0 0 1px var(--ct-ink)) drop-shadow(0 0 1px var(--ct-ink)) drop-shadow(0 2px 3px rgba(0, 0, 0, 0.8));
}
.ct-caption {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--gold-bright);
}
.ct-caption::before,
.ct-caption::after {
  content: "";
  width: 18px;
  height: 1px;
  background: linear-gradient(90deg, transparent, currentColor);
}
.ct-caption::after { background: linear-gradient(90deg, currentColor, transparent); }
.ct-title {
  font-size: 26px;
  letter-spacing: 0.05em;
  padding: 0 2px 2px; /* room for the gradient's descenders */
  color: transparent;
  -webkit-background-clip: text;
  background-clip: text;
  background-image: linear-gradient(180deg, #fff8dc 0%, #f3d995 38%, #d4ae62 62%, #9c7a45 100%);
}
.ct-quest .ct-title { font-size: 19px; }
.ct-learned .ct-caption { color: #b9dcff; }
.ct-learned .ct-title { font-size: 21px; background-image: linear-gradient(180deg, #f0f8ff 0%, #9fd1ff 45%, #4f93e0 100%); }
.ct-death .ct-caption { color: #ffb0a4; }
.ct-death .ct-title { font-size: 30px; background-image: linear-gradient(180deg, #ffb3a6 0%, #e2493c 50%, #8f1a12 100%); }

.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.encumbered { background: rgba(160, 104, 24, 0.32); border-color: #d99a3a; color: #ffe0b0; box-shadow: none; padding-left: 6px; cursor: help; --cursor-kind: default; }
.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; }
/* Own mana bar (player frame only), a touch slimmer than health. */
.bar.mp { height: 14px; }
.bar.mp .bar-fill { background: linear-gradient(180deg, var(--mp-light), var(--mp) 60%, #0f2f6e); }
.bar.mp .bar-text { font-size: 0.7rem; }
@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; }

/* ── Party frame (under the player frame, js/ui/party.js) ── */
.unit-column { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; }
.party-frame {
  margin-left: 8px;
  width: 200px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px 8px 8px;
  border: 2px solid var(--wood-900);
  border-radius: 6px;
  background: var(--woodgrain), linear-gradient(180deg, rgba(58, 38, 20, 0.9), rgba(28, 18, 9, 0.9));
  box-shadow: inset 0 0 0 1px rgba(212, 174, 98, 0.4), 0 4px 14px rgba(0, 0, 0, 0.45);
  color: var(--parchment-light);
  pointer-events: auto;
}
.party-header { display: flex; align-items: center; justify-content: space-between; }
.party-title {
  font-family: var(--font-title);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
}
.party-leave { padding: 1px 8px; font-size: 0.68rem; }
.party-member {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 4px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.22);
}
.party-member.nearby { cursor: pointer; --cursor-kind: interact; }
.party-member.nearby:hover { background: rgba(212, 174, 98, 0.16); }
.party-member.offline { opacity: 0.5; }
.party-member-level {
  min-width: 22px;
  height: 22px;
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--wood-900);
  background: radial-gradient(circle at 40% 30%, var(--gold-bright), var(--gold) 60%, var(--gold-dim));
  border: 1px solid var(--wood-900);
  flex-shrink: 0;
}
.party-member-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.party-member-name {
  font-family: var(--font-title);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--gold-bright);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
}
.party-leader { color: var(--gold); margin-right: 3px; }
.party-you { font-family: var(--font-body); font-weight: 400; font-size: 0.7rem; color: var(--parchment-dark); }
.party-member-zone { font-size: 0.7rem; font-style: italic; color: var(--parchment-dark); }
.party-member .bar.small { height: 7px; }
.party-kick {
  padding: 0 5px;
  font-size: 0.9rem;
  line-height: 1.1;
  background: transparent;
  border: none;
  box-shadow: none;
  color: var(--parchment-dark);
  opacity: 0;
}
.party-member:hover .party-kick,
.party-kick:focus-visible,
body.pad-active .party-kick { opacity: 1; }
.party-kick:hover { color: #fff; filter: none; }
.unit-invite { flex-shrink: 0; padding: 1px 8px; font-size: 0.66rem; }
.party-invite-body p { margin: 0 0 12px; }
.party-invite-actions { display: flex; gap: 8px; justify-content: flex-end; }
.party-invite-actions .primary-button { width: auto; margin-top: 0; padding: 7px 16px; font-size: 0.85rem; }
#win-party-invite { width: 300px; }
#win-party-summon { width: 300px; }
#win-summon-picker { width: 300px; }
.summon-picker-body p { margin: 0 0 10px; }
.summon-picker-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.summon-member {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px 10px;
  text-align: left; font-size: 0.85rem;
}
.summon-member .summon-member-name { flex: 1; font-weight: 600; }
.summon-member .summon-member-zone { font-size: 0.75rem; opacity: 0.75; }
.summon-member:disabled { opacity: 0.5; cursor: default; --cursor-kind: default; }
.summon-picker-note { font-size: 0.75rem; opacity: 0.75; margin: 0; }
.stat-buff { color: #ffb36b; font-weight: 600; }
.stat-buffs { display: flex; flex-direction: column; gap: 3px; margin-bottom: 8px; font-size: 0.82rem; }
.stat-buff-row { padding-left: 8px; border-left: 3px solid var(--status-color); }

/* ── 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.announce { color: #ffd27a; border-color: #c9892e; background: rgba(40, 22, 6, 0.92); }
.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;
  max-height: calc(100vh - 260px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(212, 174, 98, 0.45) transparent;
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--parchment-light);
  text-shadow: 0 1px 2px #000, 0 0 4px #000;
  cursor: pointer; --cursor-kind: interact;
}
.tracker-heading {
  flex-shrink: 0;
  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 { flex-shrink: 0; }
.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; }
/* Main story first: a brighter heading, the "Next:" step in italics. */
.tracker-heading.main { color: var(--gold-bright); border-bottom-color: rgba(240, 200, 110, 0.75); }
.tracker-quest.next .tracker-quest-name { font-style: italic; }
.tracker-quest.next .tracker-objective::before { content: "➜"; font-size: 0.75rem; top: 0.1em; }
.tracker-optional { font-style: italic; opacity: 0.75; }
.tracker-objective.tracker-return { color: #b8f0a0; font-style: italic; }
.tracker-objective.tracker-return::before { content: "➜"; font-size: 0.75rem; top: 0.1em; color: #b8f0a0; }

/* ── 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-history-entry.server { color: #ffd27a; font-weight: 700; }
.chat-history-entry.server .chat-history-name { color: #ffb347; }

.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; --cursor-kind: 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 {
  display: flex;
  gap: 6px;
  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; --cursor-kind: default;
}
.slot.filled { cursor: pointer; --cursor-kind: interact; }
.slot.filled:active { cursor: grabbing; --cursor-kind: grab; }
.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 { -webkit-user-select: none; user-select: none; }
/* Pointer drag (js/ui/panels.js): the icon follows the pointer, the grab glove
   shows everywhere and hover tooltips stay hidden until the drop. */
.drag-ghost { position: fixed; left: 0; top: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; pointer-events: none; opacity: 0.9; filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.6)); }
.drag-ghost > img { width: 100%; height: 100%; object-fit: contain; }
body.pointer-dragging, body.pointer-dragging * { cursor: grabbing !important; --cursor-kind: grab !important; -webkit-user-select: none; user-select: none; }
body.pointer-dragging .tooltip { display: none !important; }
/* Software cursor (js/ui/cursors.js): the system cursor is hidden and the
   sprite drawn on #soft-cursor instead (no size limit, no fallback to the
   system arrow at the window edges), text fields included. */
html.soft-cursor, html.soft-cursor * { cursor: none !important; }
#soft-cursor { position: fixed; left: 0; top: 0; z-index: 2147483647; pointer-events: none; will-change: transform; }
#soft-cursor.hidden { display: none; }

.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,
.drag-ghost .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; --cursor-kind: interact; }
.hotbar-slot.filled { cursor: pointer; --cursor-kind: interact; }
.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; --cursor-kind: interact;
}
.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; }
/* Not enough mana for the slot's spell. */
.hotbar-slot.no-mana img,
.hotbar-slot.no-mana .item-chip { filter: grayscale(0.6) brightness(0.55) sepia(0.4) hue-rotate(180deg); }
.hotbar-slot.no-mana { box-shadow: inset 0 0 0 2px rgba(77, 140, 240, 0.55); }
.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; --cursor-kind: interact; }
.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; --cursor-kind: default;
  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); }
.inventory-grid .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); }
.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); }

/* Bag windows (ui/bags.js): one per open bag, 8 slots in two rows. */
.bag-window { width: 260px; }
.bag-own-weight { font-size: 0.85rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
/* The bank (ui/bank.js): 16 slots, 4 × 4, plus what it holds / its capacity. */
#win-bank { width: 260px; }
.inventory-grid.drag-over { outline: 1px dashed var(--bronze); outline-offset: 4px; border-radius: 3px; }
/* A bag in a slot: a stitched corner mark; brighter while its window is open. */
.slot.is-bag::after {
  content: "";
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 9px;
  height: 9px;
  border-right: 2px solid var(--gold-dim);
  border-bottom: 2px solid var(--gold-dim);
  border-radius: 0 0 3px 0;
  pointer-events: none;
}
.slot.is-bag.bag-open { box-shadow: 0 0 0 1px var(--gold), 0 0 10px rgba(243, 217, 149, 0.55), inset 0 2px 6px rgba(0, 0, 0, 0.8); }
.slot.is-bag.bag-open::after { border-color: var(--gold-bright); }
/* Shared consumable cooldown: potions / elixirs in the bags dim while it runs. */
body.consumables-cooling .slot.is-consumable img,
body.consumables-cooling .slot.is-consumable .item-chip { filter: grayscale(0.75) brightness(0.6); }

/* Weight carried / capacity (Bags window, bag windows). */
.bag-weight-row { margin-top: 8px; }
.weight-meter { display: flex; align-items: center; gap: 8px; font-size: 0.82rem; color: var(--ink-soft); }
.weight-label { font-family: var(--font-title); font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; }
.weight-bar {
  flex: 1;
  height: 7px;
  border-radius: 4px;
  background: rgba(42, 28, 15, 0.25);
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(156, 122, 69, 0.6);
  overflow: hidden;
}
.weight-fill { display: block; height: 100%; background: linear-gradient(180deg, #b99556, #7c5d2c); transition: width 0.2s ease-out; }
.weight-value { font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--ink); }
.weight-near .weight-fill { background: linear-gradient(180deg, #e0a040, #a86a18); }
.weight-over .weight-fill { background: linear-gradient(180deg, var(--hp-light), var(--blood)); }
.weight-over .weight-value { color: var(--bad); font-weight: 700; }

.gold-amount {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-weight: 700;
  color: var(--ink);
}
/* Bags window: the purse is a button that opens the drop-gold form (ui/goldDrop.js). */
.bag-gold-button {
  background: none;
  border: 1px solid transparent;
  border-radius: 3px;
  padding: 2px 6px;
  box-shadow: none;
  cursor: pointer;
}
.bag-gold-button:hover, .bag-gold-button:focus-visible, .bag-gold-button[aria-expanded="true"] {
  border-color: var(--gold-dim);
  background: rgba(243, 217, 149, 0.15);
}
.gold-drop { display: flex; align-items: center; gap: 6px; margin-top: 8px; }
.gold-drop label { font-family: var(--font-title); font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); }
/* A text box, not type="number": no spinner eating the width, and the
   software cursor stays like on every other text field. */
.gold-drop input[type="text"] {
  flex: 1;
  min-width: 4em;
  width: auto;
  padding: 4px 8px;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.gold-drop button { width: auto; margin: 0; padding: 4px 10px; font-size: 0.8rem; }
.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);
}

/* Spell affinity wheels (js/ui/spellWheel.js): bonus by spell hue */
.aff-wheels { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.aff-wheel { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.aff-title { font-family: var(--font-title); font-size: 0.7rem; font-weight: 700; letter-spacing: 0.06em; color: var(--ink-soft); }
.aff-svg { display: block; width: 100%; max-width: 172px; height: auto; overflow: visible; cursor: crosshair; touch-action: none; }
.aff-plot { fill: rgba(90, 60, 33, 0.1); stroke: none; }
.aff-spoke { stroke: rgba(90, 60, 33, 0.22); stroke-width: 0.6; }
.aff-grid { fill: none; stroke: rgba(90, 60, 33, 0.38); stroke-width: 0.7; stroke-dasharray: 1.5 2; }
.aff-shape path { stroke-width: 0.6; opacity: 0.82; }
.aff-outline { fill: none; stroke: var(--ink); stroke-width: 1.2; stroke-linejoin: round; }
.aff-scale {
  font-family: var(--font-body);
  font-size: 7px;
  fill: var(--ink-soft);
  stroke: var(--parchment);
  stroke-width: 2px;
  paint-order: stroke;
  pointer-events: none;
}
.aff-ring-edge { fill: none; stroke: var(--wood-600); stroke-width: 1; }
.aff-spell { stroke: var(--ink); stroke-width: 1.1; }
.aff-needle line { stroke: var(--ink); stroke-width: 1; stroke-dasharray: 2 2; }
.aff-needle circle { stroke: var(--ink); stroke-width: 1.2; }
.aff-needle { pointer-events: none; }
.aff-hole { fill: var(--parchment-light); stroke: var(--bronze); stroke-width: 1.4; }
.aff-center {
  font-family: var(--font-title);
  font-size: 12px;
  font-weight: 700;
  fill: var(--ink);
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}
.aff-center.zero { fill: var(--ink-faint); }
.aff-readout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 1.3em;
  font-size: 0.8rem;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.aff-readout b { color: var(--ink); }
.aff-readout .aff-pos { color: var(--good); }
.aff-readout .aff-zero { color: var(--ink-faint); }
.aff-none { color: var(--ink-faint); font-style: italic; }
.aff-sources { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px 8px; font-size: 0.78rem; margin-top: 2px; }

/* 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; --cursor-kind: interact;
  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: pointer; --cursor-kind: interact; }
.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; }

/* Skills (ui/skills.js) */
#win-skills { width: 400px; }

/* Scout report (js/ui/scout.js) */
#win-scout { width: 320px; }
.scout-panel { display: flex; flex-direction: column; gap: 4px; }
.scout-head { display: flex; align-items: center; gap: 10px; }
.scout-head-text { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
.scout-portrait {
  position: relative;
  flex-shrink: 0;
  width: 112px;
  height: 112px;
  border-radius: 50%;
  border: 2px solid var(--bronze);
  background: radial-gradient(circle at 50% 42%, rgba(255, 250, 235, 0.95), rgba(214, 190, 146, 0.9) 70%, rgba(150, 118, 76, 0.9));
  box-shadow: inset 0 0 12px rgba(60, 38, 18, 0.45), 0 1px 3px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}
.scout-portrait-canvas { display: block; width: 112px; height: 112px; }
.scout-portrait.failed .scout-portrait-canvas { display: none; }
.scout-portrait.failed::after {
  content: attr(data-initial);
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: var(--font-title);
  font-size: 2.6rem;
  font-weight: 700;
  color: var(--ink-soft);
}
.scout-name { font-family: var(--font-title); font-weight: 700; font-size: 1.05rem; color: var(--ink); overflow-wrap: anywhere; }
.scout-verdict { font-size: 0.86rem; font-style: italic; padding: 4px 8px; border-radius: 4px; background: rgba(90, 60, 33, 0.08); }
.scout-verdict.complete { color: var(--good); }
.scout-verdict.partial { color: var(--ink-soft); }
.scout-grid { grid-template-columns: repeat(3, 1fr); gap: 4px 12px; }
.scout-grid .scout-health-row { grid-column: 1 / -1; }
.scout-q {
  display: inline-block;
  min-width: 1.4em;
  text-align: center;
  font-family: var(--font-title);
  font-weight: 700;
  color: var(--ink-faint);
  border-bottom: 1px dashed var(--ink-faint);
  cursor: help;
}
.scout-gone { font-size: 0.75rem; font-weight: 400; color: var(--ink-faint); }
.scout-spells { display: flex; flex-wrap: wrap; gap: 4px 6px; }
.scout-spell {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px 2px 2px;
  border: 1px solid rgba(90, 60, 33, 0.3);
  border-radius: 12px;
  background: rgba(255, 248, 230, 0.45);
  font-weight: 700;
  font-size: 0.85rem;
}
.scout-spell img, .scout-spell-dot { width: 20px; height: 20px; border-radius: 50%; flex-shrink: 0; }
.scout-spell-dot { display: inline-block; border: 1px solid rgba(0, 0, 0, 0.45); }
.scout-none { color: var(--ink-faint); font-style: italic; font-size: 0.85rem; }
.scout-resist-unknown { display: flex; justify-content: center; padding: 18px 0; font-size: 1.6rem; }
.aff-wheels.single { grid-template-columns: 1fr; justify-items: center; }
.aff-wheels.single .aff-wheel { width: 100%; max-width: 200px; }
.aff-title:empty { display: none; }
.skills-panel { display: flex; flex-direction: column; gap: 7px; }
.skill-points {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  border: 1px solid rgba(156, 122, 69, 0.55);
  border-radius: 4px;
  font-family: var(--font-title);
  font-size: 0.78rem;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  background: rgba(255, 250, 235, 0.3);
}
.skill-points strong { font-size: 1.05rem; color: var(--ink); }
.skill-points.has-points { border-color: var(--gold-dim); background: linear-gradient(90deg, rgba(212, 174, 98, 0.35), rgba(255, 250, 235, 0.25)); }
.skill-points.has-points strong { color: #7a4a10; }
.skill-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 8px 8px 7px;
  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));
}
.skill-icon {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--wood-900);
  border-radius: 5px;
  color: var(--gold-bright);
  background: var(--woodgrain), radial-gradient(circle at 50% 40%, var(--wood-500), var(--wood-800));
  box-shadow: inset 0 0 0 1px rgba(212, 174, 98, 0.45), 0 1px 2px rgba(0, 0, 0, 0.35);
}
.skill-glyph { width: 26px; height: 26px; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.7)); }
.skill-row.unlearned .skill-icon { color: #a99a7c; filter: grayscale(0.6); }
.skill-main { flex: 1; min-width: 0; }
.skill-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.skill-name { font-family: var(--font-title); font-weight: 700; font-size: 0.95rem; }
.skill-rank { font-family: var(--font-title); font-size: 0.72rem; letter-spacing: 0.05em; color: var(--ink-soft); white-space: nowrap; }
.skill-desc { font-size: 0.84rem; line-height: 1.3; color: var(--ink); margin: 2px 0 3px; }
.skill-chance { font-size: 0.78rem; color: var(--ink-soft); }
.skill-nearby { font-size: 0.78rem; color: var(--ink-faint); font-style: italic; }
.skill-nearby:empty { display: none; }
.skill-nearby.ready { color: var(--good); font-style: normal; font-weight: 700; }
.skill-meta { font-size: 0.72rem; color: var(--ink-faint); margin-top: 2px; }
.skill-actions { display: flex; flex-direction: column; gap: 5px; flex-shrink: 0; width: 58px; }
.skill-add { padding: 2px 0; font-size: 1rem; line-height: 1.1; }
.skill-use { padding: 6px 0; font-size: 0.72rem; font-variant-numeric: tabular-nums; }
.skill-use.ready {
  color: #fff4d6;
  background: var(--woodgrain), linear-gradient(180deg, #8d3c24 0%, #6f2a18 50%, #561f11 100%);
}

/* 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-card-giver { font-size: 0.8rem; font-style: italic; color: var(--ink-soft); margin-top: 2px; }
.quest-card.ready .quest-card-giver { color: var(--ink); font-weight: 600; }
.quest-objective-zone { font-size: 0.85em; font-style: italic; color: var(--ink-soft); }
.quest-objective.locked { color: var(--ink-soft); opacity: 0.7; }
.quest-objective-tag { font-size: 0.85em; font-style: italic; color: var(--ink-soft); }
.quest-tags { display: inline-flex; gap: 4px; vertical-align: middle; margin-left: 4px; }
.quest-tag {
  font-family: var(--font-body); font-weight: 600; font-size: 0.68rem; letter-spacing: 0.04em;
  padding: 0 5px; border-radius: 3px; border: 1px solid rgba(120, 90, 40, 0.45); color: var(--ink-soft);
}
.quest-tag.main { color: #6a3f0a; border-color: #b8862e; background: rgba(212, 174, 98, 0.25); }
.quest-card.main { border-left: 3px solid #b8862e; }
.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; --cursor-kind: 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; --cursor-kind: interact; }
.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; --cursor-kind: interact;
}
.audio-volume:disabled { opacity: 0.45; cursor: default; --cursor-kind: 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; }

/* Graphics window (ui/graphics.js): a tab per settings page */
#win-graphics { width: 360px; }
.graphics-body { display: flex; flex-direction: column; gap: 10px; }
.graphics-tabs { display: flex; gap: 0; border-bottom: 1px solid var(--bronze); }
.graphics-tabs .graphics-tab {
  flex: 1;
  padding: 6px 8px;
  font-size: 0.72rem;
  border-radius: 4px 4px 0 0;
  border-bottom: 0;
  color: var(--parchment-dark);
  background: var(--woodgrain), linear-gradient(180deg, var(--wood-700), var(--wood-800));
  box-shadow: inset 0 1px 0 rgba(255, 220, 160, 0.12);
}
.graphics-tabs .graphics-tab + .graphics-tab { margin-left: 4px; }
.graphics-tabs .graphics-tab.active {
  color: #fff6da;
  background: var(--woodgrain), linear-gradient(180deg, #8a5a22, #5a3712);
  box-shadow: inset 0 0 0 1px var(--gold), inset 0 0 10px rgba(255, 200, 110, 0.35);
}
.graphics-page[hidden] { display: none !important; }
.impact-presets.weather-quality { grid-template-columns: repeat(3, 1fr); }
.weather-label { font-family: var(--font-title); }
.graphics-hint { margin: 0; font-size: 0.8rem; font-style: italic; color: var(--ink-faint); }

/* Spell Impact page (ui/impactLab.js) */
.impact-presets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; border-radius: 4px; box-shadow: 0 0 0 1px var(--gold-dim); overflow: hidden; }
.impact-presets .impact-preset,
.impact-presets .weather-quality-option {
  padding: 5px 2px;
  font-size: 0.66rem;
  border-radius: 0;
  border: 0;
  border-right: 1px solid var(--wood-900);
  color: var(--parchment-dark);
  background: var(--woodgrain), linear-gradient(180deg, var(--wood-700), var(--wood-800));
  box-shadow: inset 0 1px 0 rgba(255, 220, 160, 0.12);
}
.impact-presets .impact-preset:last-child,
.impact-presets .weather-quality-option:last-child { border-right: 0; }
.impact-presets .impact-preset.active,
.impact-presets .weather-quality-option.active {
  color: #fff6da;
  background: var(--woodgrain), linear-gradient(180deg, #8a5a22, #5a3712);
  box-shadow: inset 0 0 0 1px var(--gold), inset 0 0 10px rgba(255, 200, 110, 0.35);
}
.impact-lab { display: flex; flex-direction: column; gap: 8px; max-height: min(70vh, 680px); overflow-y: auto; padding-right: 4px; }
.impact-lab > .section-label { margin: 6px 0 0; }
.impact-lab > * { flex-shrink: 0; } /* the body scrolls; rows keep their height */
.impact-slider { display: flex; flex-direction: column; gap: 6px; }
.impact-slider-label { font-family: var(--font-title); font-size: 0.74rem; color: var(--ink); letter-spacing: 0.05em; }
.impact-groups { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.impact-layers { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.impact-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 7px;
  margin: 0;
  border: 1px solid var(--bronze);
  border-radius: 4px;
  background: rgba(255, 250, 235, 0.3);
  font-size: 0.82rem;
  color: var(--ink-faint);
  cursor: pointer; --cursor-kind: interact;
  transition: background 0.12s ease, color 0.12s ease;
}
.impact-chip input { position: absolute; opacity: 0; pointer-events: none; }
.impact-chip::before {
  content: "";
  width: 9px;
  height: 9px;
  flex-shrink: 0;
  transform: rotate(45deg);
  border: 1px solid var(--gold-dim);
  background: #4a3a2a;
}
.impact-chip:has(input:checked) { color: var(--ink); background: rgba(212, 174, 98, 0.32); }
.impact-chip:has(input:checked)::before { background: radial-gradient(circle at 35% 30%, #fff2c4, var(--gold) 60%, #7a5a20); box-shadow: 0 0 5px rgba(255, 210, 120, 0.8); }
.impact-chip:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 1px; }
.impact-tests { display: grid; grid-template-columns: 34px 1fr 1fr; gap: 6px; }
.impact-tests .impact-color { grid-row: span 2; width: 34px; height: 100%; min-height: 58px; padding: 0; border: 1px solid var(--wood-900); border-radius: 4px; background: none; cursor: pointer; --cursor-kind: interact; }
.impact-tests .impact-test { padding: 6px 4px; font-size: 0.7rem; }
.impact-hint { margin: 0; font-size: 0.8rem; font-style: italic; color: var(--ink-faint); }
.impact-readout { display: flex; align-items: center; gap: 7px; font-size: 0.8rem; color: var(--ink-soft); font-variant-numeric: tabular-nums; min-height: 1.3em; }
.impact-swatch { width: 10px; height: 10px; flex-shrink: 0; border-radius: 50%; box-shadow: 0 0 0 1px var(--wood-900), 0 0 6px currentColor; }

#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-weight { margin-top: 4px; color: #d8c8a2; }
.tt-faint { color: #a8977a; font-size: 0.85em; }
.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; }
.tt-mana { color: var(--mp-light); font-size: 0.82rem; font-weight: 700; }
.tt-mana.short { color: #ef7a64; }
.spell-mana { color: var(--mp); font-weight: 700; }
.tt-compare { margin-top: 6px; padding-top: 5px; border-top: 1px solid rgba(212, 174, 98, 0.3); }
.tt-compare-head { color: #bfae8a; font-size: 0.8rem; font-style: italic; margin-bottom: 2px; }
.tt-up { color: #9fe37e; }
.tt-rare { color: #d6a8ff; text-shadow: 0 0 6px rgba(190, 120, 255, 0.35); }
.tt-title.rare { color: #d6a8ff; text-shadow: 0 0 8px rgba(190, 120, 255, 0.45); }
.stat-rare { display: grid; gap: 2px; margin: 2px 0 6px; font-size: 0.86rem; }
.tt-down { color: #ef7a64; }

/* ── Ground item labels (hold Alt, js/ui/groundInspect.js) ── */
.ground-label {
  position: absolute;
  left: 0;
  top: 0;
  max-width: 200px;
  width: max-content;
  padding: 3px 8px 4px;
  pointer-events: auto;
  cursor: pointer; --cursor-kind: interact;
  border: 1px solid var(--wood-900);
  border-radius: 3px;
  background: rgba(20, 12, 6, 0.88);
  box-shadow: inset 0 0 0 1px var(--gold-dim), 0 2px 6px rgba(0, 0, 0, 0.5);
  color: #efe2c2;
  font-size: 0.78rem;
  line-height: 1.25;
  text-align: center;
  white-space: nowrap;
  will-change: transform;
}
.ground-label:hover { box-shadow: inset 0 0 0 1px var(--gold-bright), 0 2px 6px rgba(0, 0, 0, 0.5); }
.ground-label .gl-name { font-weight: 700; color: var(--gold-bright); overflow: hidden; text-overflow: ellipsis; }
.ground-label .gl-stats { color: #bfae8a; font-size: 0.72rem; overflow: hidden; text-overflow: ellipsis; }
.ground-label .gl-mark { margin-right: 4px; }
.ground-label.rare { box-shadow: inset 0 0 0 1px rgba(190, 120, 255, 0.7), 0 0 8px rgba(190, 120, 255, 0.35); }
.ground-label.rare .gl-name { color: #d6a8ff; }
.ground-label[data-verdict="upgrade"] .gl-mark { color: #9fe37e; }
.ground-label[data-verdict="downgrade"] .gl-mark { color: #ef7a64; }
.ground-label[data-verdict="mixed"] .gl-mark { color: #e8b84a; }
.ground-label[data-verdict="same"] .gl-mark { color: #9c8e74; }

/* ── 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; }
}

/* ════════════════════════════════════════════════════════════════════
   Controller (js/gamepad/) — only visible while body.pad-active
   ════════════════════════════════════════════════════════════════════ */
.pad-key { display: none; }
body.pad-active .pad-key { display: inline-flex; }
body.pad-active .hotbar-slot .key:not(.pad-key),
body.pad-active .spell-bound:not(.pad-key) { display: none; }

.hotbar-slot .key.pad-key {
  align-items: center;
  gap: 1px;
  top: 2px;
  left: 2px;
  padding: 0;
  overflow: visible;
  cursor: default; --cursor-kind: default;
  pointer-events: none;
}
.spell-bound.pad-key { align-items: center; gap: 1px; }

/* Button glyphs: Xbox-coloured coins for the face buttons, small iron plates for the rest. */
.pad-glyph {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  font-family: var(--font-title);
  font-weight: 700;
  line-height: 1;
  color: #fff;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.8);
  vertical-align: middle;
}
.pad-face {
  width: 1.45em;
  height: 1.45em;
  border-radius: 50%;
  font-size: 0.82em;
  border: 1px solid rgba(0, 0, 0, 0.6);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 1px 2px rgba(0, 0, 0, 0.6);
}
.pad-a { background: radial-gradient(circle at 35% 30%, #7fd35a, #3d8a26); }
.pad-b { background: radial-gradient(circle at 35% 30%, #ef6a56, #a3281f); }
.pad-x { background: radial-gradient(circle at 35% 30%, #67a8f0, #2a5ea8); }
.pad-y { background: radial-gradient(circle at 35% 30%, #f6d35c, #b88a16); color: #2a1c0f; text-shadow: none; }
.pad-plate {
  min-width: 1.45em;
  height: 1.3em;
  padding: 0 0.35em;
  border-radius: 3px;
  font-size: 0.72em;
  background: linear-gradient(180deg, var(--iron-light), var(--iron));
  border: 1px solid rgba(0, 0, 0, 0.6);
}
.pad-plus { margin: 0 1px; font-size: 0.8em; color: var(--gold-bright); text-shadow: 0 1px 1px #000; }
.hotbar-slot .pad-key .pad-glyph { font-size: 0.9rem; }
.hotbar-slot .pad-key .pad-plate { font-size: 0.6rem; }
.pad-glyphs { display: inline-flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 4px; font-size: 0.9rem; color: var(--ink-soft); }
.pad-help dt { display: flex; align-items: center; gap: 3px; flex-wrap: wrap; }

/* Holding LB / RB: the slots of that layer light up, the rest step back. */
body.pad-layer-1 .hotbar-slot:not([data-pad-layer="1"]),
body.pad-layer-2 .hotbar-slot:not([data-pad-layer="2"]) { opacity: 0.45; }
body:not(.pad-layer-1):not(.pad-layer-2).pad-active .hotbar-slot:not([data-pad-layer="0"]) { opacity: 0.8; }
body.pad-layer-1 .hotbar-slot[data-pad-layer="1"],
body.pad-layer-2 .hotbar-slot[data-pad-layer="2"] { box-shadow: 0 0 0 2px var(--gold), 0 0 10px rgba(243, 217, 149, 0.55); }

/* Menu focus ring: dark / gold / dark bands so it reads on parchment and on wood alike. */
.pad-focus {
  outline: 2px solid var(--wood-900) !important;
  outline-offset: 1px;
  box-shadow: 0 0 0 4px var(--gold-bright), 0 0 0 6px var(--wood-900), 0 0 18px 5px rgba(243, 217, 149, 0.85) !important;
  position: relative;
  z-index: 2;
  animation: pad-focus-pulse 1.4s ease-in-out infinite;
}
@keyframes pad-focus-pulse {
  50% { box-shadow: 0 0 0 4px var(--gold), 0 0 0 6px var(--wood-900), 0 0 10px 2px rgba(243, 217, 149, 0.55); }
}
.pad-picked {
  outline: 2px dashed var(--focus) !important;
  outline-offset: 3px;
}

/* Contextual button hints above the action bar. */
.pad-prompt {
  position: absolute;
  left: 50%;
  bottom: 104px;
  transform: translateX(-50%);
  display: flex;
  gap: 14px;
  padding: 5px 14px;
  border-radius: 4px;
  border: 1px solid var(--wood-900);
  background: var(--woodgrain), linear-gradient(180deg, rgba(74, 48, 26, 0.92), rgba(33, 21, 11, 0.92));
  box-shadow: inset 0 0 0 1px rgba(212, 174, 98, 0.45), 0 4px 12px rgba(0, 0, 0, 0.5);
  color: var(--parchment-light);
  font-size: 0.92rem;
  white-space: nowrap;
  pointer-events: none;
}
.pad-hint { display: inline-flex; align-items: center; gap: 6px; }
.pad-hint .pad-glyph { font-size: 0.95rem; }
/* The aim hint sits in the same place and wins while aiming. */
.aim-hint:not(.hidden) ~ .pad-prompt { display: none; }

/* Quick-chat wheel (Y). */
.pad-wheel {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  z-index: 90;
  pointer-events: none;
}
.pad-wheel-ring {
  position: absolute;
  left: -150px;
  top: -150px;
  width: 300px;
  height: 300px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(20, 12, 6, 0.2) 0 28%, rgba(20, 12, 6, 0.72) 29% 70%, rgba(20, 12, 6, 0) 71%);
  box-shadow: 0 0 0 1px rgba(212, 174, 98, 0.35) inset;
}
.pad-wheel-pointer {
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  opacity: 0;
  transition: opacity 80ms;
}
.pad-wheel-pointer.visible { opacity: 1; }
.pad-wheel-pointer::after {
  content: "";
  position: absolute;
  left: -7px;
  top: -66px;
  border: 7px solid transparent;
  border-bottom: 12px solid var(--gold-bright);
  filter: drop-shadow(0 0 4px rgba(243, 217, 149, 0.8));
}
.pad-wheel-option {
  position: absolute;
  left: 0;
  top: 0;
  min-width: 92px;
  padding: 7px 12px;
  white-space: nowrap;
  border-radius: 4px;
  text-align: center;
  font-family: var(--font-title);
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--ink);
  background: var(--grain), linear-gradient(180deg, var(--parchment-light), var(--parchment-dark));
  border: 1px solid var(--bronze);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.55);
  transition: background 80ms, color 80ms, box-shadow 80ms;
}
.pad-wheel-option.selected {
  color: var(--gold-bright);
  background: var(--woodgrain), linear-gradient(180deg, var(--wood-500), var(--wood-800));
  border-color: var(--gold);
  box-shadow: 0 0 0 1px var(--gold-bright), 0 0 14px rgba(243, 217, 149, 0.7), 0 3px 8px rgba(0, 0, 0, 0.55);
}
.pad-wheel-centre {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(-50%, -50%);
  max-width: 120px;
  text-align: center;
  font-size: 0.85rem;
  line-height: 1.2;
  color: var(--parchment-light);
  text-shadow: 0 1px 2px #000;
}
.pad-wheel-centre strong { display: block; font-family: var(--font-title); color: var(--gold-bright); }
.pad-wheel-hint {
  position: absolute;
  left: 0;
  top: 170px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  font-size: 0.85rem;
  color: var(--parchment-light);
  text-shadow: 0 1px 2px #000;
}

/* ════════════════════════════════════════════════════════════════════
   Backstory book (js/ui/backstory/) — first-login chronicle
   ════════════════════════════════════════════════════════════════════ */
.backstory {
  position: fixed;
  inset: 0;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 1.8vh, 18px);
  padding: 48px 16px 16px;
  overflow: hidden;
  animation: bs-open 0.6s ease both;
  user-select: none;
  -webkit-user-select: none;
}
.backstory.hidden { display: none; }
.backstory.bs-closing { animation: bs-close 0.36s ease forwards; pointer-events: none; }
@keyframes bs-open { from { opacity: 0; } to { opacity: 1; } }
@keyframes bs-close { to { opacity: 0; } }

.bs-void {
  position: absolute;
  inset: -10%;
  z-index: -1;
  background:
    radial-gradient(ellipse at 50% 45%, rgba(122, 79, 208, 0.22) 0%, transparent 55%),
    radial-gradient(1px 1px at 12% 20%, rgba(255, 240, 210, 0.8), transparent),
    radial-gradient(1px 1px at 78% 14%, rgba(255, 240, 210, 0.7), transparent),
    radial-gradient(1.5px 1.5px at 64% 82%, rgba(255, 240, 210, 0.6), transparent),
    radial-gradient(1px 1px at 30% 88%, rgba(255, 240, 210, 0.6), transparent),
    radial-gradient(1px 1px at 92% 58%, rgba(255, 240, 210, 0.6), transparent),
    radial-gradient(1.5px 1.5px at 6% 64%, rgba(255, 240, 210, 0.5), transparent),
    radial-gradient(1px 1px at 46% 8%, rgba(255, 240, 210, 0.6), transparent),
    radial-gradient(1px 1px at 86% 90%, rgba(255, 240, 210, 0.5), transparent),
    linear-gradient(180deg, #07060d 0%, #0d0a16 55%, #150e0a 100%);
  animation: bs-void-drift 60s ease-in-out infinite alternate;
}
@keyframes bs-void-drift { to { transform: translate(2%, -1.5%) scale(1.03); } }

.bs-skip {
  position: absolute;
  top: 12px;
  right: 14px;
  padding: 6px 14px;
  font-size: 0.85rem;
  background: rgba(20, 12, 6, 0.55);
  box-shadow: inset 0 0 0 1px rgba(212, 174, 98, 0.4);
  color: var(--gold);
}

.bs-stage { perspective: 1700px; display: flex; justify-content: center; }

.bs-book {
  /* Same shape as the painted spreads in public/lore (1372×768). */
  --bs-w: min(94vw, calc((100vh - 190px) * 1.786), 1400px);
  position: relative;
  width: var(--bs-w);
  aspect-ratio: 1372 / 768;
  container-type: inline-size;
  transform-style: preserve-3d;
  animation: bs-book-in 0.8s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
@keyframes bs-book-in { from { transform: translateY(18px) scale(0.94) rotateX(8deg); opacity: 0; } }
.bs-book.bs-fade .bs-page { animation: bs-page-fade 0.45s ease; }
@keyframes bs-page-fade { from { opacity: 0.2; } }

/* Leather cover peeking out around the pages, with gilt tooling. */
.bs-cover-edge {
  position: absolute;
  inset: -2.2cqi -1.6cqi;
  border-radius: 1.2cqi;
  background:
    radial-gradient(ellipse at 50% 40%, rgba(255, 220, 160, 0.08), transparent 70%),
    var(--woodgrain),
    linear-gradient(180deg, #5a2416 0%, #3d160c 60%, #2a0e07 100%);
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.7), inset 0 0 0 0.35cqi #2a0e07, inset 0 0 0 0.55cqi rgba(212, 174, 98, 0.55), inset 0 0 2.4cqi rgba(0, 0, 0, 0.6);
}

/* Paper: two layered stacks of leaves under each page, then the page itself. */
.bs-page,
.bs-face {
  position: absolute;
  top: 0;
  height: 100%;
  overflow: hidden;
  color: var(--ink);
  background:
    var(--grain),
    radial-gradient(ellipse at 50% 50%, var(--parchment-light) 0%, var(--parchment) 70%, var(--parchment-dark) 100%);
}
.bs-left { left: 0; width: 50%; border-radius: 0.6cqi 0 0 0.6cqi; cursor: w-resize; --cursor-kind: interact; }
.bs-right { left: 50%; width: 50%; border-radius: 0 0.6cqi 0.6cqi 0; cursor: e-resize; --cursor-kind: interact; }
.bs-single { display: none; }
/* Stacked leaves peeking out under each page. */
.bs-left { box-shadow: -0.25cqi 0.25cqi 0 #cdb88a, -0.5cqi 0.5cqi 0 #b9a273; }
.bs-right { box-shadow: 0.25cqi 0.25cqi 0 #cdb88a, 0.5cqi 0.5cqi 0 #b9a273; }
/* Gutter shading where each page curves into the spine. It belongs to the
   page (drawn over its picture), so it travels with a page being turned. */
.bs-left::before,
.bs-right::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 5cqi;
  z-index: 2;
  pointer-events: none;
}
.bs-left::before { right: 0; background: linear-gradient(to left, rgba(40, 22, 6, 0.42), rgba(40, 22, 6, 0.16) 30%, rgba(40, 22, 6, 0.04) 70%, transparent); }
.bs-right::before { left: 0; background: linear-gradient(to right, rgba(40, 22, 6, 0.42), rgba(40, 22, 6, 0.16) 30%, rgba(40, 22, 6, 0.04) 70%, transparent); }
.bs-text { z-index: 3; }
.bs-spine {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(50% - 0.35cqi);
  width: 0.7cqi;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(40, 22, 6, 0.4) 50%, transparent);
  z-index: 8;
}

/* The turning page (book.js `startFoldTurn`): its unlifted part, the
   underside folded over the crease, and the shadow it casts. Positioned and
   clipped per frame from script. */
.bs-turn { position: absolute; inset: 0; pointer-events: none; }
.bs-turn > * { position: absolute; }
.bs-turn .bs-page { cursor: default; --cursor-kind: default; }
.bs-turn-cast { z-index: 6; }
.bs-turn-front { z-index: 7; }
.bs-turn-flap-wrap { inset: 0; z-index: 9; }
.bs-turn-flap { transform-origin: 0 0; will-change: transform, clip-path; }
.bs-turn-sheen { position: absolute; inset: 0; z-index: 4; pointer-events: none; }

/* Narrow screens: the single page turns as a leaf. */
.bs-leaf {
  position: absolute;
  top: 0;
  height: 100%;
  z-index: 6;
  transform-style: preserve-3d;
  pointer-events: none;
}
.bs-leaf .bs-face { left: 0; width: 100%; backface-visibility: hidden; -webkit-backface-visibility: hidden; }
.bs-face-back { transform: rotateY(180deg); }
.bs-face::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(90deg, rgba(30, 16, 4, 0.5), rgba(255, 245, 220, 0.25) 60%, rgba(30, 16, 4, 0.1));
  opacity: 0;
  animation: bs-leaf-shade 0.7s ease both;
}
@keyframes bs-leaf-shade { 50% { opacity: 1; } }

/* Text side. */
.bs-text {
  position: absolute;
  inset: 7% 9% 9% 10%;
  display: flex;
  flex-direction: column;
  font-size: clamp(12px, 1.42cqi, 21px);
  line-height: 1.5;
  overflow-y: auto;
  scrollbar-width: thin;
}
.bs-chapter {
  font-family: var(--font-title);
  font-weight: 600;
  font-size: 0.78em;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--gold-dim);
}
.bs-text h2 {
  margin: 0.15em 0 0.3em;
  font-size: 1.9em;
  line-height: 1.15;
  color: var(--ink);
}
.bs-rule {
  height: 0.9em;
  margin-bottom: 0.9em;
  background:
    radial-gradient(circle, var(--gold-dim) 0 0.16em, transparent 0.18em) center / 1em 100% no-repeat,
    linear-gradient(90deg, transparent, var(--gold-dim) 15%, var(--gold-dim) 44%, transparent 44%, transparent 56%, var(--gold-dim) 56%, var(--gold-dim) 85%, transparent) center / 100% 1px no-repeat;
}
.bs-body p { margin: 0 0 0.75em; text-align: justify; hyphens: auto; }
.bs-body p.bs-dropcap { display: flow-root; }
.bs-dropcap::first-letter {
  float: left;
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 2.85em;
  line-height: 0.85;
  margin: 0.06em 0.1em 0 0;
  color: var(--blood);
  text-shadow: 0.04em 0.04em 0 var(--gold);
}
.bs-text-cover { justify-content: center; text-align: center; }
.bs-text-cover .bs-body p { text-align: center; font-style: italic; }
.bs-text-cover h2 { font-size: 2.4em; }
.bs-cover-title { margin-bottom: 0.4em; }
.bs-finis {
  margin-top: auto;
  text-align: center;
  font-family: var(--font-title);
  letter-spacing: 0.4em;
  color: var(--gold-dim);
}

/* Painted spreads: each page shows its half of the chapter image. */
.bs-spread-half {
  position: absolute;
  inset: 0;
  background-color: var(--parchment);
  background-repeat: no-repeat;
  background-size: 200% 100%;
}
.bs-half-left { background-position: 0 0; }
.bs-half-right { background-position: 100% 0; }
/* Text over a spread sits in the right page's frame. Defaults fit the painted
   text box; a page's `textBox` (pages.js) overrides them per chapter. */
.bs-text.bs-on-spread {
  inset: var(--bs-top, 13.5%) var(--bs-right, 15.5%) var(--bs-bottom, 13%) var(--bs-left, 9.5%);
  font-size: clamp(11px, 1.3cqi, 20px);
  /* Keeps ink readable where the drawing runs under the text. */
  text-shadow: 0 0 2px var(--parchment-light), 0 0 5px var(--parchment-light), 0 0 9px var(--parchment);
}
.bs-text.bs-on-spread .bs-dropcap::first-letter { text-shadow: 0.04em 0.04em 0 var(--gold), 0 0 6px var(--parchment-light); }

/* Progressive reveal: sentences surface like wet ink, one after another. */
.bs-text .bs-sentence,
.bs-text .bs-chapter,
.bs-text h2,
.bs-text .bs-rule,
.bs-text .bs-finis { opacity: 0; }
.bs-text.bs-revealing .bs-chapter,
.bs-text.bs-revealing h2,
.bs-text.bs-revealing .bs-rule { animation: bs-ink-in 0.7s ease forwards; }
.bs-text.bs-revealing .bs-sentence {
  animation: bs-ink-in 0.9s ease forwards;
  animation-delay: calc(0.45s + var(--i) * 0.42s);
}
.bs-text.bs-revealing .bs-finis { animation: bs-ink-in 1s ease forwards; animation-delay: calc(0.6s + var(--count) * 0.42s); }
.bs-text.bs-revealed .bs-sentence,
.bs-text.bs-revealed .bs-chapter,
.bs-text.bs-revealed h2,
.bs-text.bs-revealed .bs-rule,
.bs-text.bs-revealed .bs-finis { opacity: 1; animation: none; filter: none; }
.bs-text.bs-hold * { animation: none !important; }
@keyframes bs-ink-in {
  from { opacity: 0; filter: blur(3px); color: var(--ink-faint); }
  to { opacity: 1; filter: blur(0); }
}

/* Controls. */
.bs-controls {
  margin-top: 1.4vh;
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: 94vw;
}
.bs-nav { min-width: 9.5em; padding: 8px 16px; font-size: 0.92rem; white-space: nowrap; }
.bs-next {
  color: #fff4d6;
  background: var(--woodgrain), linear-gradient(180deg, #8d3c24 0%, #6f2a18 50%, #561f11 100%);
}
.bs-next.bs-final { animation: bs-final-glow 2.2s ease-in-out infinite; }
@keyframes bs-final-glow {
  50% { box-shadow: inset 0 1px 0 rgba(255, 200, 160, 0.35), inset 0 0 0 1px rgba(243, 217, 149, 0.8), 0 0 18px rgba(243, 217, 149, 0.55); }
}
.bs-dots { display: flex; gap: 9px; align-items: center; }
.bs-dot {
  width: 11px;
  height: 11px;
  min-width: 0;
  padding: 0;
  border: 1px solid var(--gold-dim);
  border-radius: 1px;
  transform: rotate(45deg);
  background: transparent;
  box-shadow: none;
}
.bs-dot:hover { filter: none; background: rgba(212, 174, 98, 0.35); }
.bs-dot:active { transform: rotate(45deg); }
.bs-dot.read { background: var(--gold-dim); }
.bs-dot.active { background: var(--gold-bright); border-color: var(--gold-bright); box-shadow: 0 0 8px rgba(243, 217, 149, 0.7); }
.bs-hint {
  display: flex;
  gap: 18px;
  font-size: 0.78rem;
  color: rgba(232, 217, 181, 0.55);
}
.bs-hint kbd { font-size: 0.72rem; margin-right: 2px; }
.bs-pad-hint { display: none; }
body.pad-active .bs-pad-hint { display: inline; }
body.pad-active .bs-hint > span:not(.bs-pad-hint) { display: none; }

/* Narrow screens: one page at a time, the whole spread above the text. */
.backstory.bs-narrow .bs-book {
  --bs-w: min(94vw, 560px);
  aspect-ratio: auto;
  height: calc(100dvh - 170px);
}
.backstory.bs-narrow .bs-left,
.backstory.bs-narrow .bs-right,
.backstory.bs-narrow .bs-spine { display: none; }
.backstory.bs-narrow .bs-single,
.backstory.bs-narrow .bs-leaf-single .bs-face {
  display: flex;
  flex-direction: column;
  left: 0;
  width: 100%;
  padding: 5% 6% 9%;
  overflow-y: auto;
  border-radius: 0.6cqi;
  box-shadow: inset 2.6cqi 0 2.4cqi -1.4cqi rgba(60, 35, 10, 0.45), 0.6cqi 0.6cqi 0 #b9a273;
}
.backstory.bs-narrow .bs-cover-edge { inset: -6px; }
.bs-art-spread { position: relative; flex: 0 0 auto; width: 100%; aspect-ratio: 1372 / 768; margin: 0 auto 10px; }
.bs-art-spread img { width: 100%; height: 100%; object-fit: cover; display: block; border-radius: 2px; box-shadow: 0 1px 4px rgba(60, 35, 10, 0.35); }
.backstory.bs-narrow .bs-text.bs-on-spread { inset: auto; font-size: clamp(14px, 4cqi, 17px); text-shadow: none; }
.backstory.bs-narrow .bs-text { position: relative; inset: auto; overflow: visible; font-size: clamp(14px, 4cqi, 17px); }
.backstory.bs-narrow .bs-nav { min-width: 0; padding: 8px 10px; font-size: 0.8rem; }
.backstory.bs-narrow .bs-controls { gap: 10px; }
.backstory.bs-narrow .bs-dots { gap: 6px; }
.backstory.bs-narrow .bs-dot { width: 8px; height: 8px; }
.backstory.bs-narrow .bs-hint { display: none; }
.bs-leaf-single { left: 0; width: 100%; transform-origin: left center; }
.bs-leaf-single.bs-turn-forward { animation: bs-single-out 0.7s cubic-bezier(0.45, 0.05, 0.3, 1) forwards; }
.bs-leaf-single.bs-turn-back { animation: bs-single-in 0.7s cubic-bezier(0.45, 0.05, 0.3, 1) forwards; }
@keyframes bs-single-out { to { transform: rotateY(-100deg); opacity: 0.2; } }
@keyframes bs-single-in { from { transform: rotateY(-100deg); opacity: 0.2; } to { transform: rotateY(0deg); opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .backstory *, .backstory { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
  .bs-leaf, .bs-turn { display: none; }
}

/* ════════════════════════════════════════════════════════════════════
   Minigames — quest puzzles (js/ui/puzzles.js) and the Gambler's Court
   (js/ui/casino.js). Buttons inside boards are .mg-cell (no UI sounds).
   ════════════════════════════════════════════════════════════════════ */

.interact-prompt {
  position: absolute;
  left: 50%;
  bottom: 142px;
  transform: translateX(-50%);
  padding: 5px 14px;
  border-radius: 4px;
  border: 1px solid var(--wood-900);
  background: var(--woodgrain), linear-gradient(180deg, rgba(74, 48, 26, 0.92), rgba(33, 21, 11, 0.92));
  box-shadow: inset 0 0 0 1px rgba(212, 174, 98, 0.45), 0 4px 12px rgba(0, 0, 0, 0.5);
  color: var(--parchment-light);
  font-size: 0.92rem;
  white-space: nowrap;
  pointer-events: none;
  animation: window-in 0.14s ease-out;
}
.interact-prompt { display: inline-flex; align-items: center; gap: 7px; }
/* A little mouse with the left button lit: "click". */
.interact-click {
  position: relative; flex: none;
  width: 11px; height: 16px;
  border: 1.5px solid var(--gold-bright); border-radius: 6px 6px 7px 7px;
}
.interact-click::before {
  content: ""; position: absolute; left: 0; top: 0;
  width: 50%; height: 45%;
  border-radius: 5px 0 0 0;
  background: var(--gold-bright);
}

.mg-cell {
  padding: 0;
  min-width: 0;
  letter-spacing: 0;
  border-radius: 3px;
  font-family: var(--font-title);
}
.mg-cell:hover { filter: brightness(1.12); }
.mg-cell:active { transform: none; }

/* ── Puzzle window ─────────────────────────────────── */
.puzzle-window { min-width: 300px; }
.puzzle-window .window-body { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.pz-board-wrap { position: relative; padding: 8px; border-radius: 6px;
  background: var(--woodgrain), linear-gradient(180deg, var(--wood-600), var(--wood-800));
  box-shadow: inset 0 0 0 1px var(--gold-dim), inset 0 2px 10px rgba(0, 0, 0, 0.7), 0 2px 6px rgba(0, 0, 0, 0.35); }
.pz-board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--pz-cols), var(--pz-cell));
  grid-template-rows: repeat(var(--pz-rows), var(--pz-cell));
  width: calc(var(--pz-cols) * var(--pz-cell));
  height: calc(var(--pz-rows) * var(--pz-cell));
  touch-action: none;
  user-select: none;
}
.pz-board.pz-absolute { display: block; background: rgba(0, 0, 0, 0.45); border-radius: 3px; }
.pz-status { font-family: var(--font-title); font-size: 0.82rem; letter-spacing: 0.04em; color: var(--ink-soft); min-height: 1.2em; text-align: center; }
.pz-hint { margin: 0; max-width: 340px; font-size: 0.85rem; font-style: italic; color: var(--ink-faint); text-align: center; }
.pz-actions { display: flex; gap: 10px; }
.pz-actions button { padding: 6px 16px; font-size: 0.85rem; }
.pz-solved-seal {
  position: absolute; left: 50%; top: 50%;
  padding: 8px 22px;
  transform: translate(-50%, -50%) rotate(-8deg) scale(1.6);
  font-family: var(--font-title); font-weight: 700; font-size: 1.5rem; letter-spacing: 0.14em; text-transform: uppercase;
  color: #fff4d6; background: radial-gradient(circle at 40% 35%, #b5452b, #6f2a18 70%);
  border-radius: 8px; box-shadow: 0 0 0 3px var(--gold), 0 6px 18px rgba(0, 0, 0, 0.6);
  text-shadow: 0 1px 2px #000;
  opacity: 0; pointer-events: none;
}
.pz-solved .pz-solved-seal { animation: pz-seal 0.45s cubic-bezier(0.2, 1.4, 0.4, 1) forwards; }
.pz-solved .pz-board { filter: saturate(1.25) brightness(1.08); }
@keyframes pz-seal { to { opacity: 1; transform: translate(-50%, -50%) rotate(-8deg) scale(1); } }

/* Sliding tiles */
.pz-tile {
  position: absolute; left: 0; top: 0;
  width: var(--pz-cell); height: var(--pz-cell);
  border: 1px solid rgba(20, 12, 6, 0.85);
  box-shadow: inset 0 0 0 1px rgba(243, 217, 149, 0.35), inset 0 -3px 6px rgba(0, 0, 0, 0.35);
  transition: transform 0.12s ease-out, filter 0.12s ease;
}
.pz-tile.home { box-shadow: inset 0 0 0 1px rgba(243, 217, 149, 0.75), inset 0 -3px 6px rgba(0, 0, 0, 0.3); }
.pz-numeral {
  position: absolute; left: 4px; top: 3px;
  font-size: 0.68rem; font-weight: 700; color: #fff4d6;
  text-shadow: 0 1px 2px #000, 0 0 3px #000;
}
.pz-solved .pz-numeral { opacity: 0; transition: opacity 0.3s; }

/* Rune lanterns */
.pz-lantern {
  margin: 3px;
  border-radius: 50%;
  border: 2px solid #1a1612;
  background: radial-gradient(circle at 40% 35%, #5a544c, #2a2622 70%);
  box-shadow: inset 0 0 0 2px var(--iron), 0 2px 3px rgba(0, 0, 0, 0.5);
  transition: background 0.15s ease, box-shadow 0.15s ease;
}
.pz-flame { display: block; width: 46%; height: 46%; margin: auto; border-radius: 50% 50% 45% 45%; background: #1b1814; transition: background 0.15s; }
.pz-lantern.lit {
  background: radial-gradient(circle at 45% 40%, #fff6cf, #ffd56a 35%, #c47a12 75%);
  box-shadow: inset 0 0 0 2px #e0b441, 0 0 14px 3px rgba(255, 196, 80, 0.7);
}
.pz-lantern.lit .pz-flame { background: radial-gradient(circle at 50% 60%, #fff, #ffe9a6 60%, transparent 70%); }

/* Ichor pipes */
.pz-pipe {
  margin: 1px;
  background: radial-gradient(circle at 50% 50%, #3c342c, #241f1a);
  border: 1px solid #120e0a;
  overflow: hidden;
  color: #7a6a55;
}
.pz-pipe.flowing { color: #7dff9a; }
.pz-pipe-turn { display: block; width: 100%; height: 100%; transition: transform 0.15s ease-out; }
.pz-pipe-turn svg { display: block; width: 100%; height: 100%; }
.pz-pipe-wall { stroke: #6b5d4c; fill: #6b5d4c; stroke-linecap: butt; }
.pz-pipe-flow { stroke: currentColor; fill: currentColor; stroke-linecap: butt; transition: stroke 0.2s, fill 0.2s; }
.pz-pipe.flowing .pz-pipe-flow { filter: drop-shadow(0 0 4px rgba(125, 255, 154, 0.8)); }
.pz-pipe-heart { fill: #ff5a4a; filter: drop-shadow(0 0 6px rgba(255, 90, 74, 0.9)); }
.pz-pipe.source { background: radial-gradient(circle at 50% 50%, #5a2a22, #241f1a); }

/* Node weaving */
.pz-weave {
  border-radius: 0;
  border: none;
  background: color-mix(in srgb, var(--pz-tint, transparent) 22%, #2c2620);
  box-shadow: inset 0 0 0 1px rgba(212, 174, 98, 0.18);
  display: flex; align-items: center; justify-content: center;
}
.pz-node { width: 74%; height: 74%; position: relative; z-index: 2; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.7)); }
.pz-threads { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; }
.pz-threads polyline { fill: none; stroke-width: 0.34; stroke-linecap: round; stroke-linejoin: round; opacity: 0.8; }
.pz-threads polyline.done { opacity: 1; }
.pz-threads polyline.active { filter: drop-shadow(0 0 0.08px #fff); }

/* Frictionless stone */
.pz-ice {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.35) 0 12%, transparent 12% 52%, rgba(255, 255, 255, 0.18) 52% 56%, transparent 56%),
    linear-gradient(180deg, #cfe7f3, #9cc6dc);
  box-shadow: inset 0 0 0 1px rgba(60, 100, 130, 0.35);
  cursor: pointer; --cursor-kind: interact;
}
.pz-ice.rock { position: relative; cursor: default; --cursor-kind: default; }
.pz-ice.rock::after {
  content: "";
  position: absolute; inset: 6%;
  background: radial-gradient(circle at 38% 32%, #b3a999 0%, #7c7366 45%, #3e3830 80%);
  border-radius: 38% 46% 40% 50%;
  box-shadow: inset -3px -4px 6px rgba(0, 0, 0, 0.45), 0 2px 3px rgba(0, 0, 0, 0.4);
}
.pz-ice.goal {
  background:
    radial-gradient(circle, transparent 0 28%, rgba(212, 174, 98, 0.95) 30% 38%, transparent 40% 48%, rgba(212, 174, 98, 0.85) 50% 54%, transparent 56%),
    linear-gradient(180deg, #cfe7f3, #9cc6dc);
  animation: pz-goal 1.6s ease-in-out infinite;
}
.pz-ice.start { background: radial-gradient(circle, rgba(90, 60, 33, 0.25) 0 30%, transparent 32%), linear-gradient(180deg, #cfe7f3, #9cc6dc); }
@keyframes pz-goal { 50% { filter: brightness(1.18) drop-shadow(0 0 4px rgba(255, 213, 106, 0.8)); } }
.pz-puck {
  position: absolute; left: 0; top: 0;
  width: var(--pz-cell); height: var(--pz-cell);
  pointer-events: none;
  transition: transform 0.2s cubic-bezier(0.25, 0.9, 0.35, 1);
}
.pz-puck::after {
  content: "ᛟ";
  position: absolute; inset: 14%;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  font-size: calc(var(--pz-cell) * 0.4);
  color: #6e4526;
  background: radial-gradient(circle at 38% 32%, #fffaf0, #e8d9b5 55%, #b49a6c);
  box-shadow: 0 3px 5px rgba(0, 0, 0, 0.45), inset 0 -2px 3px rgba(0, 0, 0, 0.2);
}
.pz-arrows { display: grid; grid-template-columns: repeat(3, 40px); grid-template-rows: repeat(2, 34px); gap: 4px; }
.pz-arrow { padding: 0; font-size: 0.9rem; }
.pz-arrow[data-dir="0"] { grid-column: 2; grid-row: 1; }
.pz-arrow[data-dir="3"] { grid-column: 1; grid-row: 2; }
.pz-arrow[data-dir="2"] { grid-column: 2; grid-row: 2; }
.pz-arrow[data-dir="1"] { grid-column: 3; grid-row: 2; }

/* The puzzler's table */
#win-puzzle-table { width: 380px; }
.pz-table-intro { margin: 0 0 10px; font-size: 0.9rem; font-style: italic; color: var(--ink-soft); text-align: center; }
.pz-difficulty { display: flex; justify-content: center; gap: 6px; margin-bottom: 10px; }
.pz-diff { padding: 5px 14px; font-size: 0.8rem; opacity: 0.75; }
.pz-diff.active { opacity: 1; box-shadow: inset 0 0 0 1px var(--gold-bright), 0 0 8px rgba(243, 217, 149, 0.5); }
.pz-table-list { display: flex; flex-direction: column; gap: 8px; }
.pz-table-row { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 4px; background: rgba(90, 60, 33, 0.08); box-shadow: inset 0 0 0 1px rgba(90, 60, 33, 0.25); }
.pz-table-text { flex: 1; display: flex; flex-direction: column; font-size: 0.85rem; color: var(--ink-soft); line-height: 1.25; }
.pz-table-text strong { font-family: var(--font-title); font-size: 0.9rem; color: var(--ink); }
.pz-play { padding: 5px 14px; font-size: 0.8rem; }
.pz-table-icon { width: 38px; height: 38px; flex: none; border-radius: 4px; box-shadow: inset 0 0 0 1px var(--wood-900), 0 1px 2px rgba(0, 0, 0, 0.4); }
.pz-icon-sliding { background: conic-gradient(from 45deg, #d4ae62 0 25%, #2d5b8a 0 50%, #9c7a45 0 75%, #122238 0); }
.pz-icon-lights_out { background: radial-gradient(circle at 30% 30%, #ffd56a 0 14%, transparent 16%), radial-gradient(circle at 70% 70%, #ffd56a 0 14%, transparent 16%), radial-gradient(circle at 70% 30%, #4a4642 0 14%, transparent 16%), radial-gradient(circle at 30% 70%, #4a4642 0 14%, transparent 16%), #2a2622; }
.pz-icon-pipes { background: linear-gradient(90deg, transparent 40%, #7dff9a 40% 60%, transparent 60%), linear-gradient(0deg, transparent 40%, #7dff9a 40% 60%, transparent 60%) 0 0 / 100% 50% no-repeat, #2c2620; }
.pz-icon-connect { background: radial-gradient(circle at 25% 25%, #c0392b 0 12%, transparent 13%), radial-gradient(circle at 75% 75%, #c0392b 0 12%, transparent 13%), linear-gradient(45deg, transparent 46%, #c0392b 46% 54%, transparent 54%), #2c2620; }
.pz-icon-ice { background: radial-gradient(circle at 30% 65%, #e8d9b5 0 15%, transparent 17%), radial-gradient(circle at 75% 30%, #7c7366 0 16%, transparent 18%), linear-gradient(180deg, #cfe7f3, #9cc6dc); }

/* ── Casino shared ─────────────────────────────────── */
.casino-window .window-body { display: flex; flex-direction: column; gap: 8px; }
.cs-label { font-family: var(--font-title); font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); }
.cs-bet-row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; justify-content: center; }
.cs-step { width: 28px; height: 28px; padding: 0; font-size: 1.1rem; line-height: 1; }
.cs-bet { min-width: 54px; text-align: center; font-size: 1.05rem; }
.cs-presets { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.cs-preset { padding: 3px 8px; font-size: 0.75rem; opacity: 0.8; }
.cs-preset.active { opacity: 1; box-shadow: inset 0 0 0 1px var(--gold-bright), 0 0 6px rgba(243, 217, 149, 0.5); }
.cs-limits { font-size: 0.8rem; color: var(--ink-faint); text-align: center; font-style: italic; }
.cs-limits .gold-amount { font-style: normal; }
.cs-actions { display: flex; gap: 8px; justify-content: center; }
.cs-actions .primary-button { width: auto; min-width: 160px; margin-top: 0; }
.cs-symbol { width: 40px; height: 40px; image-rendering: pixelated; filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.45)); }
.cs-symbol.small { width: 22px; height: 22px; }
.cs-symbol-text { display: inline-flex; align-items: center; justify-content: center; font-size: 0.6rem; }

/* ── Roulette ──────────────────────────────────────── */
#win-roulette { width: 486px; }
.rl-top { display: flex; align-items: center; gap: 14px; }
.rl-wheel { width: 170px; height: 170px; flex: none; border-radius: 50%; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5); }
.rl-side { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.rl-result {
  width: 64px; height: 64px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-title); font-weight: 700; font-size: 1.6rem; color: #fff4d6;
  background: #3a2f26; box-shadow: 0 0 0 3px var(--gold), inset 0 2px 6px rgba(0, 0, 0, 0.6);
  text-shadow: 0 1px 2px #000;
}
.rl-result.rl-red, .rl-pill.rl-red { background: #a3231b; }
.rl-result.rl-black, .rl-pill.rl-black { background: #1a1a1a; }
.rl-result.rl-green, .rl-pill.rl-green { background: #1d7a3a; }
.rl-outcome { min-height: 2.4em; font-size: 0.9rem; text-align: center; color: var(--ink); }
.rl-history { display: flex; flex-wrap: wrap; gap: 3px; justify-content: center; }
.rl-pill { min-width: 22px; padding: 1px 4px; border-radius: 9px; font-family: var(--font-title); font-size: 0.68rem; color: #fff; text-align: center; }
.rl-board {
  display: grid;
  grid-template-columns: 30px repeat(12, 1fr) 34px;
  grid-template-rows: repeat(3, 30px) 28px 28px;
  gap: 2px;
  padding: 6px;
  border-radius: 5px;
  background: var(--grain), linear-gradient(180deg, #2a6b40, #1d4f2e);
  box-shadow: inset 0 0 0 2px var(--gold-dim), inset 0 0 16px rgba(0, 0, 0, 0.5);
}
.rl-spot {
  position: relative;
  border: 1px solid rgba(243, 217, 149, 0.55);
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.12);
  color: #fff4d6;
  font-size: 0.72rem;
  box-shadow: none;
  text-shadow: 0 1px 1px #000;
}
.rl-spot.rl-num.rl-red { background: #a3231b; }
.rl-spot.rl-num.rl-black { background: #1d1d1d; }
.rl-spot.rl-num.rl-green { background: #1d7a3a; font-size: 1rem; }
.rl-spot.rl-outside.rl-red { background: rgba(163, 35, 27, 0.75); }
.rl-spot.rl-outside.rl-black { background: rgba(20, 20, 20, 0.75); }
.rl-label { position: relative; z-index: 1; }
.rl-chip {
  position: absolute; right: -4px; top: -6px; z-index: 2;
  min-width: 20px; height: 20px; padding: 0 3px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 10px;
  font-size: 0.62rem; color: var(--ink);
  background: radial-gradient(circle at 35% 30%, #fff3c4, #e0b441 50%, #8a6414);
  box-shadow: 0 0 0 1px #5a3f0c, 0 0 0 3px rgba(255, 255, 255, 0.35) inset, 0 2px 3px rgba(0, 0, 0, 0.6);
  text-shadow: none;
}
.rl-spot.rl-won { box-shadow: 0 0 0 2px var(--gold-bright), 0 0 12px rgba(243, 217, 149, 0.9); }
.rl-spot.rl-hit { outline: 2px solid #fff; outline-offset: 1px; animation: rl-hit 0.8s ease-in-out 3; }
@keyframes rl-hit { 50% { filter: brightness(1.6); } }
.rl-chips { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: center; }
.rl-chip-pick {
  width: 38px; height: 38px; padding: 0; border-radius: 50%;
  color: var(--ink); font-size: 0.78rem; text-shadow: none;
  background: radial-gradient(circle at 35% 30%, #fff3c4, #e0b441 50%, #8a6414);
  box-shadow: 0 0 0 1px #5a3f0c, inset 0 0 0 4px rgba(255, 255, 255, 0.25), 0 2px 3px rgba(0, 0, 0, 0.5);
  opacity: 0.7;
}
.rl-chip-pick.active { opacity: 1; box-shadow: 0 0 0 2px var(--ink), 0 0 10px rgba(243, 217, 149, 0.9), inset 0 0 0 4px rgba(255, 255, 255, 0.25); transform: translateY(-2px); }
.rl-staked { margin-left: 8px; font-size: 0.85rem; }

/* ── One-armed bandit ──────────────────────────────── */
#win-slots { width: 380px; }
.sl-cabinet {
  padding: 10px 12px 12px;
  border-radius: 10px 10px 6px 6px;
  background: var(--woodgrain), linear-gradient(180deg, #4e2f1a, #2a180c);
  box-shadow: inset 0 0 0 2px var(--bronze), inset 0 0 0 4px #1a0f07, 0 3px 8px rgba(0, 0, 0, 0.5);
}
.sl-marquee {
  margin: 0 auto 8px; padding: 3px 12px; width: fit-content;
  font-family: var(--font-title); font-weight: 700; letter-spacing: 0.12em; font-size: 0.85rem; text-transform: uppercase;
  color: #fff4d6; border-radius: 4px;
  background: linear-gradient(180deg, #c98a18, #8a5a0e);
  box-shadow: 0 0 12px rgba(255, 196, 80, 0.6), inset 0 0 0 1px #fff3c4;
  text-shadow: 0 1px 2px #000;
}
.sl-window {
  position: relative;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
  padding: 6px;
  border-radius: 5px;
  background: #140c06;
  box-shadow: inset 0 0 0 2px var(--gold-dim);
}
.sl-window.sl-win { box-shadow: inset 0 0 0 2px var(--gold-bright), 0 0 18px rgba(255, 213, 106, 0.85); }
.sl-reel {
  display: flex; flex-direction: column; overflow: hidden;
  border-radius: 4px;
  background: linear-gradient(180deg, #bfae8a, #f3e8cc 30% 70%, #bfae8a);
  box-shadow: inset 0 6px 10px rgba(0, 0, 0, 0.45), inset 0 -6px 10px rgba(0, 0, 0, 0.45);
}
.sl-cell { height: 52px; display: flex; align-items: center; justify-content: center; opacity: 0.45; }
.sl-cell.sl-line { opacity: 1; }
.sl-cell .cs-symbol { width: 44px; height: 44px; }
.sl-reel.spinning .sl-cell { filter: blur(2px); opacity: 0.7; transform: translateY(6px); }
.sl-payline { position: absolute; left: 2px; right: 2px; top: 50%; height: 2px; margin-top: -1px; background: rgba(179, 52, 42, 0.85); box-shadow: 0 0 4px rgba(255, 90, 74, 0.8); pointer-events: none; }
.sl-outcome { margin-top: 8px; min-height: 1.3em; text-align: center; font-size: 0.92rem; color: var(--parchment-light); text-shadow: 0 1px 2px #000; }
.sl-paytable summary { cursor: pointer; --cursor-kind: interact; font-family: var(--font-title); font-size: 0.8rem; color: var(--ink-soft); }
.sl-paytable table { width: 100%; margin-top: 6px; border-collapse: collapse; font-size: 0.82rem; }
.sl-paytable td { padding: 2px 4px; border-bottom: 1px solid rgba(90, 60, 33, 0.18); }
.sl-pay-line { display: flex; gap: 2px; align-items: center; }
.sl-pay { font-family: var(--font-title); font-weight: 700; text-align: right; }
.sl-pay-note { color: var(--ink-faint); font-style: italic; }
.sl-any { display: inline-block; width: 22px; text-align: center; font-size: 0.6rem; color: var(--ink-faint); }

/* ── Blackjack ─────────────────────────────────────── */
#win-blackjack { width: 400px; }
.bj-felt {
  display: flex; flex-direction: column; gap: 8px;
  padding: 10px 12px;
  border-radius: 90px 90px 8px 8px / 40px 40px 8px 8px;
  background: var(--grain), radial-gradient(ellipse at 50% 30%, #2f7a4a, #1b4a2c 75%);
  box-shadow: inset 0 0 0 3px var(--wood-600), inset 0 0 0 5px var(--gold-dim), inset 0 0 18px rgba(0, 0, 0, 0.55);
  color: #fff4d6;
}
.bj-row { display: flex; flex-direction: column; align-items: center; gap: 4px; min-height: 96px; }
.bj-who { font-family: var(--font-title); font-size: 0.8rem; letter-spacing: 0.08em; text-shadow: 0 1px 2px #000; }
.bj-cards { display: flex; gap: 6px; min-height: 70px; }
.bj-card {
  position: relative;
  width: 48px; height: 68px;
  border-radius: 5px;
  background: linear-gradient(180deg, #fffaf0, #efe2c4);
  box-shadow: 0 0 0 1px #8a7152, 0 3px 6px rgba(0, 0, 0, 0.5);
  color: #1d1d1d;
  font-family: var(--font-title); font-weight: 700;
}
.bj-card.bj-new { animation: bj-deal 0.24s ease-out; }
.bj-card.bj-red { color: #a3231b; }
.bj-rank { position: absolute; left: 5px; top: 3px; font-size: 0.9rem; }
.bj-suit { position: absolute; left: 6px; top: 20px; font-size: 0.75rem; }
.bj-pip { position: absolute; right: 6px; bottom: 4px; font-size: 1.5rem; line-height: 1; }
.bj-back {
  background: repeating-linear-gradient(45deg, #7a2a1c 0 5px, #5a1d12 5px 10px);
  box-shadow: 0 0 0 1px #2a0f08, inset 0 0 0 3px #e8d9b5, inset 0 0 0 4px #7a2a1c, 0 3px 6px rgba(0, 0, 0, 0.5);
}
@keyframes bj-deal { from { opacity: 0; transform: translate(40px, -30px) rotate(12deg); } }
.bj-rule { text-align: center; font-size: 0.72rem; font-style: italic; color: rgba(243, 217, 149, 0.8); border-top: 1px solid rgba(243, 217, 149, 0.35); border-bottom: 1px solid rgba(243, 217, 149, 0.35); padding: 2px 0; }
.bj-outcome { min-height: 1.4em; text-align: center; font-family: var(--font-title); font-size: 0.95rem; text-shadow: 0 1px 2px #000; }
.bj-outcome.bj-won, .bj-outcome.bj-blackjack { color: var(--gold-bright); }
.bj-outcome.bj-lost, .bj-outcome.bj-bust { color: #ffb0a6; }

@media (prefers-reduced-motion: reduce) {
  .pz-tile, .pz-puck, .pz-pipe-turn { transition-duration: 0.01ms !important; }
  .bj-card.bj-new, .rl-spot.rl-hit, .pz-ice.goal { animation: none !important; }
}
