:root {
  --ink: #2a1d33;
  --paper: #fff8ec;
  --paper-2: #f6ead6;
  --purple: #7a5cd6;
  --purple-dark: #4f3a9a;
  --gold: #ffc83a;
  --red: #ef5b5b;
  --green: #4fc36f;
  --blue: #4f9cf0;
  --hp: #ff5a6e;
  --shield: #5ab4f0;
  --card-w: 138px;
  --card-h: 172px;
  --round: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", "Segoe UI Rounded", "Segoe UI", system-ui, sans-serif;
  --emoji: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
  --shadow: 0 4px 0 rgb(42 29 51 / 0.9);
  font: 15px/1.35 var(--round);
  color: var(--ink);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #8fcfff;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

body { overscroll-behavior: none; touch-action: none; }
body.dragging, body.dragging * { cursor: grabbing !important; }
body.over-die, body.over-node { cursor: pointer; }

button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
[hidden] { display: none !important; }

canvas#world, canvas#dice {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: block;
}
canvas#world { z-index: 0; }
canvas#dice { z-index: 20; pointer-events: none; }

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

/* --- Buttons & panels ------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: 3px solid var(--ink);
  border-radius: 16px;
  background: var(--gold);
  color: var(--ink);
  font-weight: 800;
  font-size: 1.05rem;
  box-shadow: var(--shadow);
  transition: transform 0.08s, box-shadow 0.08s, filter 0.15s;
}
.btn:hover:not(:disabled) { transform: translateY(-2px); filter: brightness(1.06); box-shadow: 0 6px 0 var(--ink); }
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; filter: grayscale(0.6); }
.btn.purple { background: var(--purple); color: #fff; }
.btn.green { background: var(--green); }
.btn.blue { background: var(--blue); color: #fff; }
.btn.plain { background: var(--paper); }
.btn.small { padding: 6px 12px; font-size: 0.92rem; border-radius: 12px; }
.btn.big { padding: 14px 30px; font-size: 1.25rem; }
.link { background: none; border: 0; text-decoration: underline; opacity: 0.7; padding: 4px; }

.panel {
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 22px;
  box-shadow: 0 6px 0 var(--ink), 0 14px 40px rgb(42 29 51 / 0.25);
  padding: 18px 20px;
}
.panel h2 { margin: 0 0 6px; font-size: 1.6rem; line-height: 1.1; }
.panel h3 { margin: 14px 0 6px; font-size: 1.05rem; }
.panel p { margin: 6px 0; }
.muted { opacity: 0.7; }

/* --- Top bar ------------------------------------------------------------- */

#topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px max(10px, env(safe-area-inset-right)) 6px max(10px, env(safe-area-inset-left));
  background: rgb(255 248 236 / 0.92);
  border-bottom: 3px solid var(--ink);
  min-height: 48px;
  font-weight: 700;
}
#topbar .home { color: var(--ink); text-decoration: none; font-size: 1.3rem; padding: 0 6px; }
#topbar .brand { font-weight: 900; color: var(--purple); letter-spacing: 0.02em; margin-right: 4px; }
#topbar .stat { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; background: var(--paper-2); border: 2px solid rgb(42 29 51 / 0.2); white-space: nowrap; }
#topbar .level { gap: 6px; }
#topbar .xp { width: 46px; height: 8px; border-radius: 4px; background: rgb(42 29 51 / 0.15); overflow: hidden; }
#topbar .xp i { display: block; height: 100%; background: var(--purple); }
#topbar .asc { background: #ffe0ea; }
#topbar .spacer { flex: 1; }
#topbar .icon { border: 2px solid var(--ink); background: var(--paper); border-radius: 10px; min-width: 36px; height: 34px; font-size: 1rem; font-weight: 800; box-shadow: 0 2px 0 var(--ink); }
#topbar .icon:active { transform: translateY(2px); box-shadow: none; }
#topbar .icon.off { opacity: 0.45; }

/* --- Title ------------------------------------------------------------------- */

#title { display: flex; align-items: flex-start; justify-content: center; }
.title-card { margin-top: max(6vh, 30px); text-align: center; pointer-events: auto; }
.logo {
  margin: 0;
  font-size: clamp(2.8rem, 9vw, 6.2rem);
  font-weight: 900;
  letter-spacing: 0.01em;
  line-height: 1;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
}
.logo span {
  display: inline-block;
  color: #fff;
  -webkit-text-stroke: 3px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 6px 0 var(--ink);
  animation: bob 2.2s ease-in-out infinite;
  animation-delay: calc(var(--i) * 0.09s);
}
.logo span:nth-child(3n + 1) { color: var(--gold); }
.logo span:nth-child(3n + 2) { color: #ff8fb0; }
.logo span:nth-child(3n) { color: #8fd8ff; }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-10px) rotate(3deg); } }
.tagline { font-size: 1.15rem; font-weight: 800; color: #fff; text-shadow: 0 2px 0 var(--ink), 0 0 12px rgb(42 29 51 / 0.4); margin: 12px 0 22px; }
.title-buttons { display: flex; flex-direction: column; gap: 12px; align-items: center; }
.title-buttons .btn { min-width: 240px; }
.title-foot { color: #fff; text-shadow: 0 2px 0 var(--ink); font-weight: 700; margin-top: 18px; }

/* --- Character select ------------------------------------------------------ */

#select { display: flex; }
.select-heroes {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
}
.hero-tab { width: 74px; height: 74px; border-radius: 18px; border: 3px solid var(--ink); background: var(--paper); font-size: 2rem; box-shadow: var(--shadow); position: relative; }
.hero-tab.active { background: var(--gold); transform: translateY(-6px); }
.hero-tab.locked { filter: grayscale(1); opacity: 0.7; }
.hero-tab small { position: absolute; bottom: -8px; left: 50%; transform: translateX(-50%); font-size: 0.7rem; background: var(--ink); color: #fff; border-radius: 6px; padding: 0 5px; white-space: nowrap; }
.select-panel {
  position: absolute;
  right: max(16px, env(safe-area-inset-right));
  top: 64px;
  bottom: 110px;
  width: min(430px, 44vw);
  overflow-y: auto;
}
.select-panel .title { color: var(--purple); font-weight: 800; margin: 0; }
.stars { color: var(--gold); letter-spacing: 2px; -webkit-text-stroke: 1px var(--ink); }
.facts { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.fact { background: var(--paper-2); border-radius: 12px; padding: 4px 10px; font-weight: 700; border: 2px solid rgb(42 29 51 / 0.15); }
.knack-box { background: #efe6ff; border: 2px solid var(--purple); border-radius: 14px; padding: 8px 12px; margin: 8px 0; }
.knack-box b { color: var(--purple-dark); }
.select-bag { display: flex; gap: 14px; align-items: center; --cell: 54px; }
.select-bag .bag { flex: none; --gap: 4px; padding: 5px; border-radius: 16px; }
.select-bag .bag-cell { border-radius: 9px; }
.select-bag .gear-card.in-grid { border-width: 2px; border-radius: 10px; box-shadow: 0 2px 0 var(--ink); }
.select-bag .gear-card.in-grid .gc-text { display: none; }
.select-bag p { font-size: 0.85rem; flex: 1; min-width: 110px; }
.asc-picker { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.asc-picker b { font-size: 1.3rem; min-width: 60px; text-align: center; }
.asc-list { list-style: none; padding: 0; margin: 6px 0; font-size: 0.9rem; max-height: 150px; overflow-y: auto; }
.asc-list li { padding: 2px 0; }
.asc-list li.off { opacity: 0.35; }
.lock-note { background: #ffe8e8; border: 2px dashed var(--red); border-radius: 12px; padding: 10px; font-weight: 700; }

/* --- Map --------------------------------------------------------------------- */

.map-title {
  position: absolute;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 999px;
  padding: 6px 22px;
  text-align: center;
  box-shadow: var(--shadow);
}
.map-title b { display: block; font-size: 1.3rem; }
.map-title span { font-size: 0.85rem; opacity: 0.75; }
.map-choices {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 96vw;
}
.map-choices p { margin: 0; font-weight: 900; color: #fff; text-shadow: 0 2px 0 var(--ink); width: 100%; text-align: center; }
.map-choice { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 14px; border: 3px solid var(--ink); background: var(--paper); font-weight: 800; box-shadow: var(--shadow); }
.map-choice span { font-size: 1.3rem; }
.map-choice:hover { background: var(--c); transform: translateY(-2px); }
.tip { position: fixed; left: 0; top: 0; z-index: 30; max-width: 240px; background: var(--paper); border: 3px solid var(--ink); border-radius: 14px; padding: 8px 12px; box-shadow: var(--shadow); pointer-events: none; }
.tip b { display: block; }
.tip span { font-size: 0.88rem; }
.tip em { display: block; font-size: 0.8rem; color: var(--purple); font-style: normal; font-weight: 800; margin-top: 4px; }

/* --- Gear cards ---------------------------------------------------------------- */
/* Cards come in two looks. Loose cards (loot, the shop) are sized by how much
   room the gear takes: small, medium or large. Cards in the backpack grid
   (.in-grid) fill exactly the cells they cover. */

.gear-row { display: flex; gap: 10px; align-items: flex-end; justify-content: center; }
.gear-card {
  position: relative;
  width: var(--card-w);
  min-height: var(--card-h);
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: 0 4px 0 var(--ink);
  overflow: hidden;
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.2s, filter 0.2s;
  flex: none;
}
.gear-card.size-small { --card-w: 122px; --card-h: 150px; }
.gear-card.size-large { --card-w: 176px; --card-h: 196px; --slot: 60px; }
.gear-card.size-large .gc-name { font-size: 0.98rem; }
.gear-card.size-large .gc-icon { font-size: 1.45rem; }
.gear-card.size-large .gc-text { font-size: 0.86rem; }
.gear-card .gc-head { display: flex; align-items: center; gap: 5px; padding: 5px 6px; background: var(--kind); color: #fff; border-bottom: 3px solid var(--ink); min-height: 34px; }
.gc-icon { font-family: var(--emoji); font-size: 1.2rem; line-height: 1; filter: drop-shadow(0 1px 0 rgb(0 0 0 / 0.3)); flex: none; }
.gc-name { font-weight: 900; font-size: 0.85rem; line-height: 1.05; text-shadow: 0 1px 0 rgb(42 29 51 / 0.5); flex: 1; min-width: 0; overflow-wrap: anywhere; }
.gc-tags { display: flex; gap: 3px; flex-wrap: wrap; padding: 4px 6px 0; }
.badge { font-size: 0.66rem; font-weight: 900; background: #efe6ff; color: var(--purple-dark); border: 1.5px solid rgb(79 58 154 / 0.35); border-radius: 6px; padding: 0 4px; white-space: nowrap; line-height: 1.35; }
.badge.once { background: #ffe8d6; color: #9a4a10; border-color: rgb(154 74 16 / 0.3); }
.gc-star { position: absolute; top: 3px; right: 4px; width: 20px; height: 20px; border-radius: 50%; background: var(--gold); border: 2px solid var(--ink); color: var(--ink); font-size: 0.72rem; font-weight: 900; display: flex; align-items: center; justify-content: center; z-index: 1; }
.gear-card:not(.in-grid):has(.gc-star) .gc-head { padding-right: 28px; }
.footprint { display: grid; grid-template-columns: repeat(2, 6px); gap: 1px; padding: 2px; background: rgb(255 255 255 / 0.92); border-radius: 4px; flex: none; }
.footprint i { width: 6px; height: 6px; border-radius: 1.5px; background: rgb(42 29 51 / 0.14); }
.footprint i.on { background: var(--ink); }
.gc-text { padding: 5px 8px 0; font-size: 0.8rem; font-weight: 700; line-height: 1.2; flex: 1; }
.d-glyph { display: inline-flex; align-items: center; justify-content: center; width: 1.25em; height: 1.25em; border: 2px solid var(--ink); border-radius: 5px; font-size: 0.85em; font-weight: 900; background: #fff; vertical-align: -0.2em; }
.gc-slots { display: flex; gap: 6px; justify-content: center; align-items: center; padding: 6px 6px 8px; }
.gc-slot {
  width: var(--slot, 54px);
  height: var(--slot, 54px);
  flex: none;
  border: 3px dashed rgb(42 29 51 / 0.45);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgb(42 29 51 / 0.05);
  font-size: 0.7rem;
  font-weight: 900;
  text-align: center;
  line-height: 1;
  color: rgb(42 29 51 / 0.7);
}
.gc-slot.countdown { border-style: dotted; }
.gc-countdown { background: var(--ink); color: #fff; border-radius: 10px; padding: 1px 7px; font-weight: 900; white-space: nowrap; line-height: 1.2; }
.gc-countdown b { font-size: 1.1rem; }
.gc-countdown small { opacity: 0.75; font-size: 0.7rem; }
.gc-price { text-align: center; font-weight: 900; padding: 4px; background: #fff3c4; border-top: 2px solid rgb(42 29 51 / 0.2); }
.gc-note { text-align: center; font-size: 0.72rem; font-weight: 800; padding: 3px 4px; background: #e9e2ff; line-height: 1.2; }
.gc-overlay { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 900; pointer-events: none; z-index: 2; }
.gc-overlay.used { background: rgb(255 248 236 / 0.72); }
.gc-overlay.used span { transform: rotate(-12deg); border: 3px solid var(--ink); border-radius: 10px; padding: 2px 10px; background: var(--paper); font-size: 1.05rem; }
.gc-overlay.shock { background: rgb(255 230 80 / 0.35); color: var(--ink); top: 55%; text-align: center; }
.gc-overlay.shock span { background: #ffe850; border: 2px solid var(--ink); border-radius: 8px; padding: 0 6px; }
.gc-overlay.shock small { font-size: 0.65rem; }
.gear-card.used { filter: grayscale(0.5); }
.gear-card.shocked { animation: buzz 0.3s linear infinite; }
.gear-card.borrowed { border-color: #2f8f47; box-shadow: 0 4px 0 #2f8f47; }
.gear-card.rarity-rare .gc-head { background-image: linear-gradient(120deg, transparent 30%, rgb(255 255 255 / 0.35) 50%, transparent 70%); background-size: 200% 100%; animation: shine 3s linear infinite; }
.gear-card.small { --card-w: 108px; --card-h: 128px; --slot: 40px; }
.gear-card.small .gc-text { font-size: 0.68rem; padding: 3px 5px 0; }
.gear-card.small .gc-name { font-size: 0.72rem; }
.gear-card.small .gc-head { padding: 3px 5px; min-height: 0; }
.gear-card.small .gc-tags { padding: 2px 4px 0; }
.gear-card.small .badge { font-size: 0.58rem; }
.gear-card.small .gc-countdown b { font-size: 0.9rem; }
.gear-card.playable { transform: translateY(-3px); box-shadow: 0 7px 0 var(--ink); }
.gear-card.playable .gc-slot { border-color: var(--kind); background: color-mix(in srgb, var(--kind) 12%, transparent); }
.gear-card.can-drop { transform: translateY(-4px) scale(1.02); box-shadow: 0 8px 0 var(--ink), 0 0 0 4px var(--gold); z-index: 3; }
.gear-card.cant-drop { opacity: 0.45; filter: grayscale(0.7); }
.gc-slot.drop-hover { background: color-mix(in srgb, var(--gold) 55%, transparent); border-color: var(--ink); border-style: solid; }
.knack-slot.drop-hover, .knack-slot.can-drop { box-shadow: 0 0 0 4px var(--gold); }
.gear-card.thunk { animation: thunk 0.25s; }
.gear-card.fired { animation: fired 0.45s; }
.gear-card.refresh { animation: none; }
.gear-card.tick .gc-countdown { animation: thunk 0.3s; }
.gear-card.zapped { animation: buzz 0.2s linear 3; }
.gear-card.arrive { animation: arrive 0.5s ease-out; }
.gear-card.nope { animation: buzz 0.15s linear 2; }
.gear-card.pickable { cursor: pointer; }
.gear-card.pickable:hover { transform: translateY(-4px) rotate(-1deg); box-shadow: 0 8px 0 var(--ink); }
.gear-card.in-grid.pickable { cursor: grab; }
.gear-card.in-grid.pickable:hover { transform: translateY(-2px); box-shadow: 0 6px 0 var(--ink); }
.gear-card.chosen, .gear-card.chosen:hover { box-shadow: 0 4px 0 var(--ink), 0 0 0 4px var(--green); }
.gear-card.backpacked { opacity: 0.6; }

/* In the backpack grid. --cell is one cell, --gap the space between cells. */
.gear-card.in-grid { width: auto; min-height: 0; border-radius: 14px; --slot: min(54px, calc(var(--cell) * 0.6)); }
.gear-card.in-grid .gc-head { min-height: 0; padding: 4px 5px; gap: 4px; }
.gear-card.in-grid .gc-name { overflow-wrap: break-word; hyphens: auto; font-size: 0.74rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.gear-card.in-grid .gc-text { font-size: 0.7rem; padding: 3px 6px 0; overflow: hidden; }
.gear-card.in-grid .gc-tags { padding: 3px 5px 0; }
.gear-card.in-grid .badge { font-size: 0.58rem; }
.gear-card.in-grid .gc-slots { padding: 4px; gap: 4px; }
.gear-card.in-grid .gc-countdown { padding: 0 5px; }
.gear-card.in-grid .gc-countdown b { font-size: 0.9rem; }
.gear-card.in-grid .gc-star { width: 17px; height: 17px; font-size: 0.62rem; top: auto; bottom: 3px; right: 3px; }
/* Small: just the icon, the name and the slot. Hover for the rest. */
.gear-card.shape-1x1 { --slot: min(50px, calc(var(--cell) * 0.56)); }
.gear-card.shape-1x1 .gc-head { padding: 2px 4px; border-bottom-width: 2px; }
.gear-card.shape-1x1 .gc-icon { font-size: 0.95rem; }
.gear-card.shape-1x1 .gc-name { -webkit-line-clamp: 1; font-size: 0.6rem; }
.gear-card.shape-1x1 .gc-text, .gear-card.shape-1x1 .gc-tags { display: none; }
.gear-card.shape-1x1 .gc-slots { flex: 1; padding: 3px; }
/* Wide: words on the left, dice on the right. */
.gear-card.shape-2x1 { display: grid; grid-template: auto 1fr / 1fr auto; }
.gear-card.shape-2x1 .gc-head { grid-column: 1 / -1; }
.gear-card.shape-2x1 .gc-tags { display: none; }
.gear-card.shape-2x1 .gc-text { grid-column: 1; grid-row: 2; align-self: center; padding: 2px 3px 2px 7px; }
.gear-card.shape-2x1 .gc-slots { grid-column: 2; grid-row: 2; padding: 4px 6px 4px 0; }
.gear-card.shape-2x1 .gc-slots:has(.gc-slot + .gc-slot) { --slot: min(44px, calc(var(--cell) * 0.5)); }
.gear-card.shape-2x1 .gc-countdown { position: absolute; top: 3px; right: 5px; }
/* Tall: two slots stack. */
.gear-card.shape-1x2 .gc-head { flex-direction: column; gap: 1px; padding: 3px 4px; text-align: center; }
.gear-card.shape-1x2 .gc-name { font-size: 0.68rem; overflow-wrap: normal; hyphens: manual; width: 100%; }
.gear-card.shape-1x2 .gc-icon { font-size: 1.05rem; }
.gear-card.shape-1x2 .gc-slots { flex-wrap: wrap; }
.gear-card.shape-1x2 .gc-slots:has(.gc-slot + .gc-slot) { flex-direction: column; --slot: min(44px, calc(var(--cell) * 0.48)); }
.gear-card.shape-2x2 { --slot: min(60px, calc(var(--cell) * 0.66)); }
.gear-card.shape-2x2 .gc-name { font-size: 0.9rem; }
.gear-card.shape-2x2 .gc-icon { font-size: 1.35rem; }
.gear-card.shape-2x2 .gc-text { font-size: 0.8rem; }

.bag {
  --gap: 6px;
  display: grid;
  grid-template-columns: repeat(4, var(--cell));
  grid-template-rows: repeat(var(--rows, 4), var(--cell));
  gap: var(--gap);
  padding: 7px;
  background-color: #b98a57;
  background-image: radial-gradient(rgb(255 255 255 / 0.13) 1.5px, transparent 1.5px);
  background-size: 12px 12px;
  border: 3px solid var(--ink);
  border-radius: 20px;
  box-shadow: inset 0 3px 0 rgb(255 255 255 / 0.25), inset 0 -4px 0 rgb(0 0 0 / 0.15), 0 5px 0 var(--ink);
  position: relative;
}
.bag-cell { border: 2px dashed rgb(255 244 220 / 0.45); border-radius: 12px; background: rgb(0 0 0 / 0.08); }
.bag > .gear-card { z-index: 1; }
.bag-preview { z-index: 4; border: 3px solid var(--green); border-radius: 14px; background: rgb(79 195 111 / 0.3); pointer-events: none; }
.bag-preview.bad { border-color: var(--red); background: rgb(239 91 91 / 0.3); }
.gear-card.drag-source { opacity: 0.3; }
.gear-card.drag-ghost { position: fixed; left: 0; top: 0; z-index: 40; pointer-events: none; rotate: -3deg; scale: 1.04; box-shadow: 0 12px 24px rgb(42 29 51 / 0.35), 0 4px 0 var(--ink); }

#gear-tip { position: fixed; left: 0; top: 0; z-index: 36; pointer-events: none; filter: drop-shadow(0 10px 20px rgb(42 29 51 / 0.3)); }
@keyframes buzz { 0%, 100% { translate: 0 0; } 25% { translate: -2px 1px; } 75% { translate: 2px -1px; } }
@keyframes thunk { 0% { scale: 1; } 40% { scale: 1.08 0.94; } 100% { scale: 1; } }
@keyframes fired { 0% { scale: 1; } 30% { scale: 1.12; filter: brightness(1.4); } 100% { scale: 1; } }
@keyframes arrive { from { translate: 0 60px; opacity: 0; rotate: 8deg; } to { translate: 0 0; opacity: 1; rotate: 0deg; } }
@keyframes shine { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* --- Combat -------------------------------------------------------------------- */

.nameplate {
  position: absolute;
  left: 0;
  top: 0;
  width: 190px;
  margin-left: -95px;
  margin-top: -78px;
  pointer-events: auto;
  text-align: center;
}
.plate-name { font-weight: 900; color: #fff; text-shadow: 0 2px 0 var(--ink), 0 0 6px rgb(42 29 51 / 0.6); font-size: 0.98rem; white-space: nowrap; }
.tag { font-style: normal; font-size: 0.7rem; text-transform: uppercase; padding: 1px 6px; border-radius: 6px; border: 2px solid var(--ink); text-shadow: none; color: var(--ink); vertical-align: 2px; }
.tag.elite { background: #d8b0ff; }
.tag.boss { background: var(--gold); }
.hp-bar { position: relative; height: 22px; border: 3px solid var(--ink); border-radius: 999px; background: #5a3a4a; overflow: hidden; margin-top: 2px; box-shadow: 0 2px 0 var(--ink); display: flex; align-items: center; justify-content: center; }
.hp-fill { position: absolute; inset: 0 auto 0 0; background: linear-gradient(#ff8a9a, var(--hp)); transition: width 0.35s ease-out; }
.hp-bar span { position: relative; font-weight: 900; font-size: 0.8rem; color: #fff; text-shadow: 0 1px 0 var(--ink), 0 0 3px var(--ink); line-height: 1; }
.hp-bar.shielded { border-color: var(--shield); box-shadow: 0 0 0 2px var(--ink), 0 2px 0 2px var(--ink); }
.chips { display: flex; gap: 4px; justify-content: center; flex-wrap: wrap; margin-top: 4px; min-height: 24px; }
.chip { display: inline-flex; align-items: center; gap: 2px; background: var(--paper); border: 2px solid var(--ink); border-radius: 999px; padding: 0 6px 0 4px; font-size: 0.85rem; cursor: help; }
.chip b { font-size: 0.8rem; }
.chip.good { background: #e0f2ff; }
.chip.bad { background: #ffe4ec; }

#enemy-panel { position: absolute; top: 58px; right: max(12px, env(safe-area-inset-right)); display: flex; flex-direction: column; align-items: flex-end; }
#enemy-panel .gear-row { justify-content: flex-end; flex-wrap: wrap; max-width: 60vw; }
.row-label { margin: 0 0 4px; font-size: 0.75rem; font-weight: 900; color: #fff; text-shadow: 0 1px 0 var(--ink); text-transform: uppercase; letter-spacing: 0.05em; }
#combat.enemy-turn #enemy-panel .gear-card { box-shadow: 0 4px 0 var(--ink), 0 0 0 3px #ff7a7a; }

#combat { --cell: clamp(50px, min(8.4vh, 7.4vw), 84px); }
#player-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(10px, env(safe-area-inset-bottom));
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 12px;
  padding: 0 12px;
}
#player-gear.bag { --gap: 5px; padding: 6px; }
#borrowed { display: flex; flex-direction: column; align-items: center; animation: arrive 0.4s ease-out; }
#borrowed-gear { --gap: 5px; display: flex; gap: 6px; }
#end-turn {
  align-self: center;
  flex: none;
  padding: 14px 18px;
  border: 3px solid var(--ink);
  border-radius: 18px;
  background: var(--green);
  font-weight: 900;
  font-size: 1.1rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
}
#end-turn small { font-size: 0.65rem; opacity: 0.6; }
#end-turn:disabled { opacity: 0.5; filter: grayscale(0.7); cursor: not-allowed; }
#end-turn.pulse { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.08); box-shadow: 0 4px 0 var(--ink), 0 0 0 6px rgb(79 195 111 / 0.4); } }
#combat-hint {
  position: absolute;
  left: 50%;
  top: 60px;
  transform: translateX(-50%);
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 14px;
  padding: 6px 14px;
  font-weight: 800;
  box-shadow: var(--shadow);
  max-width: min(520px, 90vw);
  text-align: center;
  animation: arrive 0.4s ease-out;
  pointer-events: none;
}

#knack {
  flex: none;
  width: 170px;
  align-self: flex-end;
  background: #efe6ff;
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: 0 4px 0 var(--ink);
  padding: 6px 8px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-height: min(var(--card-h), calc(var(--cell) * 2 + 20px));
}
#knack.ready { box-shadow: 0 4px 0 var(--ink), 0 0 0 3px var(--gold); }
.knack-head { display: flex; align-items: center; gap: 6px; font-size: 0.95rem; cursor: help; }
.knack-icon { font-family: var(--emoji); font-size: 1.3rem; }
.knack-head .info { margin-left: auto; width: 18px; height: 18px; border-radius: 50%; background: var(--ink); color: #fff; font-size: 0.7rem; display: flex; align-items: center; justify-content: center; }
.meter { position: relative; height: 20px; border: 2px solid var(--ink); border-radius: 999px; background: #fff; overflow: hidden; display: flex; align-items: center; justify-content: center; flex: none; }
.meter-fill { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, #b08aff, var(--purple)); transition: width 0.3s; }
.meter.hot .meter-fill { background: linear-gradient(90deg, #ffb03a, #ff5a3a); }
.meter.full .meter-fill { background: linear-gradient(90deg, var(--gold), #ff9a3a); animation: shine 1.5s linear infinite; }
.meter span { position: relative; font-size: 0.72rem; font-weight: 900; line-height: 1; }
.knack-btn { border: 3px solid var(--ink); border-radius: 12px; background: #ddd; font-weight: 900; padding: 6px; box-shadow: 0 3px 0 var(--ink); }
.knack-btn.ready { background: var(--gold); animation: pulse 1.2s ease-in-out infinite; }
.knack-btn:disabled { opacity: 0.55; cursor: not-allowed; }
.knack-slot { border: 3px dashed var(--purple); border-radius: 14px; min-height: 56px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 1.6rem; background: #fff; }
.knack-slot small { font-size: 0.65rem; font-weight: 900; }
.knack-slot.off { opacity: 0.45; }
.belt { display: flex; gap: 5px; justify-content: center; }
.potion { width: 38px; height: 38px; border-radius: 12px; border: 3px solid var(--ink); background: #fff; font-size: 1.3rem; box-shadow: 0 3px 0 var(--ink); padding: 0; }
.potion:hover { transform: translateY(-2px) rotate(-8deg); }
.potion.empty { border-style: dashed; opacity: 0.35; box-shadow: none; }
.knack-note { margin: 0; font-size: 0.72rem; font-weight: 700; opacity: 0.8; line-height: 1.15; }

/* --- Rooms (shop, camp, events, rewards) ------------------------------------------ */

.room-panel {
  position: absolute;
  right: max(16px, env(safe-area-inset-right));
  top: 64px;
  max-height: calc(100% - 84px);
  width: min(560px, 50vw);
  overflow-y: auto;
  animation: arrive 0.35s ease-out;
}
.room-panel .choices { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.room-panel .choices .btn { justify-content: flex-start; text-align: left; }
.room-panel .row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-start; margin: 10px 0; }
.room-panel .actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.outcome { background: #fff3c4; border: 3px solid var(--ink); border-radius: 14px; padding: 10px 12px; font-weight: 700; margin: 10px 0; animation: arrive 0.3s ease-out; }
.roll-result { font-size: 1.4rem; font-weight: 900; }
.gains { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.gain { background: var(--paper); border: 2px solid var(--ink); border-radius: 999px; padding: 1px 10px; font-weight: 800; font-size: 0.9rem; }
.service { display: flex; align-items: center; gap: 10px; background: var(--paper-2); border-radius: 14px; padding: 8px 10px; border: 2px solid rgb(42 29 51 / 0.15); margin: 6px 0; }
.service .emoji { font-size: 1.8rem; font-family: var(--emoji); }
.service div { flex: 1; }
.service small { display: block; opacity: 0.75; }
.xp-line { display: flex; align-items: center; gap: 8px; font-weight: 800; }
.xp-line .xp-bar { flex: 1; height: 14px; border: 2px solid var(--ink); border-radius: 999px; overflow: hidden; background: #fff; }
.xp-line .xp-bar i { display: block; height: 100%; background: var(--purple); transition: width 0.8s ease-out; }
.levelup { background: linear-gradient(90deg, #ffe066, #ffb0d0); border: 3px solid var(--ink); border-radius: 14px; padding: 8px 12px; font-weight: 900; margin: 10px 0; animation: thunk 0.5s 2; }
.room-panel .row { align-items: flex-end; }

/* --- Backpack screen ------------------------------------------------------------------- */

.modal-card.wide { width: min(980px, 100%); }
.bag-hero { margin: 0 0 10px; }
.bag-layout { display: flex; gap: 22px; align-items: flex-start; --cell: clamp(58px, calc((100vw - 110px) / 4), 92px); }
.bag-side { flex: none; display: flex; flex-direction: column; gap: 10px; }
.bag-frame { padding-top: 14px; position: relative; }
.bag-frame::before { content: ''; position: absolute; left: 50%; top: 0; width: 38%; height: 30px; transform: translateX(-50%); border: 6px solid #7a5230; border-bottom: 0; border-radius: 18px 18px 0 0; }
.bag-meter { position: relative; height: 22px; border: 3px solid var(--ink); border-radius: 999px; background: #fff; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.bag-meter span { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, #ffd87a, #ffb03a); }
.bag-meter b { position: relative; font-size: 0.8rem; }
.bag-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
#bag-detail { display: flex; gap: 12px; align-items: flex-start; min-height: 150px; background: var(--paper-2); border-radius: 16px; padding: 10px; }
#bag-detail .detail-side { flex: 1; min-width: 0; }
#bag-detail .detail-side p { margin: 0 0 8px; font-size: 0.9rem; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.detail-actions small { opacity: 0.6; font-size: 0.7rem; }
.bag-empty-detail { margin: auto; text-align: center; font-weight: 800; opacity: 0.6; }
.stash-box { border: 3px dashed rgb(42 29 51 / 0.3); border-radius: 16px; padding: 8px 10px 10px; transition: background 0.15s, border-color 0.15s; }
.stash-box.drop-hover { background: #fff3c4; border-color: var(--gold); }
.stash-box h3 { margin: 0 0 8px; }
.stash-box h3 small { font-weight: 700; opacity: 0.6; font-size: 0.8rem; }
.stash { --gap: 6px; display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-start; min-height: calc(var(--cell) * 1); }
.stash .muted { margin: 0; }
.bag-help { font-size: 0.88rem; margin: 14px 0 0; opacity: 0.85; }
.stat-grid { display: grid; grid-template-columns: 1fr auto; gap: 4px 14px; font-weight: 700; }
.stat-grid b { text-align: right; }

/* --- Dialogue ----------------------------------------------------------------------- */

#dialogue { position: fixed; inset: 0; z-index: 28; display: flex; align-items: flex-end; justify-content: center; padding: 0 12px max(20px, env(safe-area-inset-bottom)); cursor: pointer; }
.dialogue-box {
  width: min(760px, 100%);
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 22px;
  box-shadow: 0 6px 0 var(--ink), 0 20px 50px rgb(42 29 51 / 0.35);
  padding: 16px 20px 10px;
  position: relative;
  animation: arrive 0.3s ease-out;
}
.speaker { position: absolute; top: -20px; left: 18px; background: var(--purple); color: #fff; border: 3px solid var(--ink); border-radius: 12px; padding: 2px 12px; font-weight: 900; box-shadow: 0 3px 0 var(--ink); }
.speaker.narrator { background: #8a6a4a; }
.speaker.villain { background: var(--red); }
#dialogue-text { font-size: 1.15rem; font-weight: 700; min-height: 3.1em; margin: 8px 0 4px; line-height: 1.4; }
.dialogue-foot { display: flex; justify-content: space-between; align-items: center; font-size: 0.8rem; font-weight: 800; }
.dialogue-foot .next { animation: bob 1.4s ease-in-out infinite; }

/* --- FX layer ------------------------------------------------------------------------ */

#fx { position: fixed; inset: 0; z-index: 25; pointer-events: none; overflow: hidden; }
.float-text {
  position: absolute;
  transform: translate(-50%, -50%);
  font-weight: 900;
  font-size: 1.7rem;
  color: #fff;
  -webkit-text-stroke: 2px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 3px 0 var(--ink);
  animation: float-up 1.2s ease-out forwards;
  white-space: nowrap;
}
.float-text.damage { color: #ff6a6a; }
.float-text.damage.big { font-size: 2.6rem; color: #ffd84a; }
.float-text.heal { color: #7aea8a; }
.float-text.poison { color: #b0ea5a; }
.float-text.burn { color: #ff9a3a; }
.float-text.block { color: #8fd0ff; font-size: 1.3rem; }
.float-text.good { color: #9fe0ff; font-size: 1.15rem; }
.float-text.bad { color: #ffb0d0; font-size: 1.15rem; }
.float-text.miss { color: #fff; font-size: 1.4rem; }
@keyframes float-up {
  0% { transform: translate(-50%, -30%) scale(0.4); opacity: 0; }
  15% { transform: translate(-50%, -70%) scale(1.25); opacity: 1; }
  30% { transform: translate(-50%, -80%) scale(1); }
  100% { transform: translate(-50%, -190%) scale(0.95); opacity: 0; }
}
.bubble { position: absolute; left: 0; top: 0; pointer-events: none; }
.bubble span {
  position: absolute;
  bottom: 12px;
  left: 0;
  transform: translateX(-50%);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 16px;
  padding: 6px 12px;
  font-weight: 800;
  width: max-content;
  max-width: 240px;
  box-shadow: 0 3px 0 var(--ink);
  animation: pop-in 0.3s ease-out;
}
.bubble span::after { content: ''; position: absolute; bottom: -12px; left: 50%; margin-left: -8px; border: 8px solid transparent; border-top-color: var(--ink); }
.bubble.out span { animation: pop-out 0.25s ease-in forwards; }
@keyframes pop-in { from { transform: translateX(-50%) scale(0.3); opacity: 0; } to { transform: translateX(-50%) scale(1); opacity: 1; } }
@keyframes pop-out { to { transform: translateX(-50%) scale(0.3); opacity: 0; } }
.banner {
  position: absolute;
  top: 34%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-weight: 900;
  font-size: clamp(1.6rem, 5vw, 2.8rem);
  color: #fff;
  -webkit-text-stroke: 3px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 5px 0 var(--ink);
  white-space: nowrap;
  animation: banner 1.4s ease-out forwards;
}
.banner.player { color: var(--gold); }
.banner.enemy { color: #ff9aa8; }
.banner.big { font-size: clamp(2.2rem, 8vw, 4.4rem); }
@keyframes banner {
  0% { transform: translate(-50%, -50%) scale(0.2) rotate(-10deg); opacity: 0; }
  18% { transform: translate(-50%, -50%) scale(1.15) rotate(3deg); opacity: 1; }
  30% { transform: translate(-50%, -50%) scale(1) rotate(0); }
  80% { opacity: 1; }
  100% { transform: translate(-50%, -80%) scale(1); opacity: 0; }
}
.flash { position: absolute; inset: 0; animation: flash 0.35s ease-out forwards; }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }
.confetti { position: absolute; top: -20px; width: 10px; height: 16px; border: 2px solid var(--ink); border-radius: 3px; animation: confetti 2.5s ease-in forwards; }
@keyframes confetti { to { transform: translate(var(--drift), 110vh) rotate(var(--spin)); } }

/* --- Modal & toast ----------------------------------------------------------------------- */

.modal { position: fixed; inset: 0; z-index: 30; background: rgb(42 29 51 / 0.55); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-card { position: relative; background: var(--paper); border: 3px solid var(--ink); border-radius: 22px; box-shadow: 0 6px 0 var(--ink); max-width: min(920px, 100%); max-height: calc(100% - 20px); overflow-y: auto; padding: 20px 22px; animation: arrive 0.3s ease-out; user-select: text; }
.modal-card h2 { margin: 0 0 8px; }
.modal-card .close { position: absolute; top: 10px; right: 10px; width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--ink); background: var(--paper); font-weight: 900; }
.help-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px 20px; }
.help-grid section { background: var(--paper-2); border-radius: 14px; padding: 8px 12px; }
.help-grid h3 { margin: 4px 0; }
.help-grid p, .help-grid li { font-size: 0.92rem; }
.menu-toggles { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0 14px; }
.status-list { list-style: none; padding: 0; margin: 0; }
.status-list li { margin: 4px 0; }
#toast { position: fixed; z-index: 35; top: 64px; left: 50%; transform: translateX(-50%); background: var(--gold); border: 3px solid var(--ink); border-radius: 16px; padding: 10px 18px; font-weight: 900; box-shadow: var(--shadow); animation: arrive 0.4s ease-out; text-align: center; }
.noscript { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 1.4rem; }

/* --- Smaller screens ------------------------------------------------------------------------ */

@media (max-width: 1100px) {
  :root { --card-w: 118px; --card-h: 150px; }
  .gear-card:not(.in-grid) { --slot: 46px; }
  .gear-card.size-large { --card-w: 150px; --card-h: 172px; --slot: 52px; }
  .gear-card.size-small { --card-w: 108px; --card-h: 136px; }
  #knack { width: 150px; }
  .gear-card.small { --card-w: 92px; --card-h: 112px; }
  .gear-card.small .gc-text { display: none; }
}

@media (max-width: 760px), (max-height: 560px) {
  :root { --card-w: 98px; --card-h: 128px; font-size: 14px; }
  #topbar { gap: 5px; padding-top: 4px; padding-bottom: 4px; min-height: 42px; }
  #topbar .brand, #topbar .floor, #topbar .hero-chip { display: none; }
  #topbar .stat { padding: 2px 6px; }
  #topbar .icon { min-width: 30px; height: 30px; }
  .gear-card:not(.in-grid) .gc-text { font-size: 0.7rem; padding: 3px 5px 0; }
  .gear-card:not(.in-grid) .gc-name { font-size: 0.74rem; }
  .gear-card:not(.in-grid) { --slot: 40px; }
  .gear-card.size-large { --card-w: 132px; --card-h: 150px; --slot: 46px; }
  .gear-card.size-small { --card-w: 90px; --card-h: 118px; }
  .gc-slot { font-size: 0.6rem; }
  #player-panel { gap: 6px; padding: 0 6px; }
  #knack { width: 116px; padding: 4px 5px; }
  .knack-note { display: none; }
  #end-turn { padding: 10px 10px; font-size: 0.95rem; }
  .gear-card.small { --card-w: 74px; --card-h: 92px; }
  .gear-card.small { --slot: 30px; }
  .gear-card.small .gc-name { font-size: 0.6rem; }
  .nameplate { width: 150px; margin-left: -75px; }
  .room-panel, .select-panel { left: 10px; right: 10px; width: auto; top: auto; bottom: 10px; max-height: 58%; }
  .select-panel { bottom: 104px; max-height: 52%; }
  .hero-tab { width: 58px; height: 58px; font-size: 1.6rem; }
  #combat-hint { font-size: 0.85rem; top: 50px; }
  .bag-layout { flex-direction: column; align-items: center; }
  .bag-info { width: 100%; }
}

@media (max-width: 560px) {
  #combat { --cell: min(calc((100vw - 150px) / 4), 7vh); }
  #btn-speed, #btn-sound, #btn-music, #topbar .xp { display: none; }
  #player-panel { flex-wrap: wrap; gap: 6px 8px; }
  #player-gear.bag { padding: 4px; --gap: 4px; }
  #knack { flex: 1 1 55%; width: auto; min-height: 0; flex-direction: row; align-items: center; flex-wrap: wrap; order: -1; padding: 4px 6px; }
  #knack .knack-head b { display: none; }
  #knack .meter { flex: 1; min-width: 80px; }
  #knack .knack-slot { min-height: 38px; flex-direction: row; font-size: 1.2rem; padding: 0 8px; }
  #knack .knack-btn { padding: 4px 8px; }
  #end-turn { order: -1; align-self: stretch; padding: 6px 12px; }
  #combat-hint { left: 8px; transform: none; max-width: calc(100vw - 130px); font-size: 0.78rem; padding: 4px 10px; }
  #borrowed .row-label { font-size: 0.6rem; }
  .gear-card.in-grid .gc-text { font-size: 0.62rem; }
  .gear-card.shape-1x2 .gc-name { font-size: 0.6rem; }
  .gear-card.shape-1x2 .gc-icon { font-size: 0.9rem; }
  .gear-card.shape-1x1 .gc-name { display: none; }
  #enemy-panel .gear-row { max-width: 70vw; }
}
.stars i { font-style: normal; opacity: 0.25; }
