/* ---------- Font ---------- */
/* A pixel font: it only looks crisp at sizes that are multiples of 10px. */
@font-face {
  font-family: "GAME";
  src: url("fonts/game.ttf") format("truetype");
  font-display: block;
}

/* ---------- Page and scaling stage ---------- */
html, body {
  margin: 0;
  height: 100%;
  background: #000;
  overflow: hidden;
  font-family: "GAME", Georgia, serif;
  font-synthesis: none; /* the font has no bold; never fake one */
  -webkit-font-smoothing: none;
  color: #f2e6d0;
  -webkit-tap-highlight-color: transparent;
}

/* The game is always 1280x720. JavaScript sets --scale so it fits the window. */
#game {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1280px;
  height: 720px;
  transform: translate(-50%, -50%) scale(var(--scale, 1));
  transform-origin: center center;
  overflow: hidden;
}

/* ---------- Screens ---------- */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.screen.active {
  display: flex;
}

/* ---------- Title screen ---------- */
/* The main menu uses the battle's grass background (the first frame of grass_terrain.png). */
#title-screen {
  background: #000 url("assets/scenes/grass_terrain.png") 0 -720px / 3840px 2160px no-repeat;
  image-rendering: pixelated;
}
#version-label {
  position: absolute; left: 16px; bottom: 12px;
  font-size: 24px; color: #f2e6d0;
  text-shadow: -2px 0 0 #000, 2px 0 0 #000, 0 -2px 0 #000, 0 2px 0 #000;
}
#leaderboard-version-label { font-size: 22px; color: #b9a98f; }
#leaderboard-version { font-family: inherit; font-size: 22px; color: #f2e6d0; background: #000; border: 3px solid #7a6a5a; padding: 2px 8px; }
.lb-sortable { cursor: pointer; }
.lb-sortable:hover { color: #f2e6d0; }

#title-screen { flex-direction: column; gap: 20px; }
#name-label { font-size: 28px; color: #f2e6d0; text-shadow: -2px 0 0 #000, 2px 0 0 #000, 0 -2px 0 #000, 0 2px 0 #000; }
#name-input {
  font-family: inherit;
  font-size: 36px;
  width: 440px;
  padding: 10px 18px;
  text-align: center;
  color: #f2e6d0;
  background: #1a0f0d;
  border: 3px solid #f2e6d0;
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}
#name-input::placeholder { color: #7a6a5a; }
#name-input:focus { border-color: #eece9a; }
#open-leaderboard {
  font-family: inherit;
  font-size: 28px;
  padding: 8px 40px;
  color: #f2e6d0;
  background: #000; /* solid, so it reads clearly over the grass */
  border: 3px solid #7a6a5a;
  cursor: pointer;
}
#open-leaderboard:hover, #open-leaderboard:focus-visible { border-color: #f2e6d0; background: #1a0f0d; outline: none; }
#start-button:disabled { color: #7a6a5a; border-color: #7a6a5a; cursor: default; } /* dimmed, but still solid */
#start-button:disabled:hover { background: #1a0f0d; color: #7a6a5a; }

#start-button {
  font-family: inherit;
  font-size: 40px;
  padding: 18px 72px;
  color: #f2e6d0;
  background: #1a0f0d; /* solid, so it reads clearly over the grass */
  border: 3px solid #f2e6d0;
  cursor: pointer;
  touch-action: manipulation;
}

#start-button:hover,
#start-button:focus-visible {
  background: #f2e6d0;
  color: #000;
  outline: none;
}

/* ---------- Gear screen ---------- */
/* The whole screen is one 240x135 picture (gear_select.png) drawn at 1280x720, so one art
   pixel is 1280/240 = 5.333 screen pixels. Everything below is placed in art pixels with --u. */
#gear-screen,
#encounter-screen {
  --u: calc(1280px / 240);
  background: #2e1a17 url("assets/ui/gear_select.png") 0 0 / 1280px 720px no-repeat;
  image-rendering: pixelated;
}

.gear-groups,
.gear-group {
  display: contents; /* the headings and grids are positioned on the screen itself */
}

#gear-screen h1,
#gear-screen h2,
#encounter-screen h1,
#encounter-screen h2 {
  position: absolute;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: normal;
}

/* Title box: x 81, y 16, 81 x 24 art pixels */
#gear-screen h1,
#encounter-screen h1 {
  left: calc(81 * var(--u));
  top: calc(16 * var(--u));
  width: calc(81 * var(--u));
  height: calc(24 * var(--u));
  font-size: 40px;
}

#gear-screen h2,
#encounter-screen h2 {
  height: calc(13 * var(--u));
  font-size: 30px;
}

/* Armour heading box: x 71, y 54, 41 wide. Weapons heading box: x 145, y 67, 38 wide. */
.gear-group:nth-child(1) h2 {
  left: calc(71 * var(--u));
  top: calc(54 * var(--u));
  width: calc(41 * var(--u));
}

.gear-group:nth-child(2) h2 {
  left: calc(145 * var(--u));
  top: calc(67 * var(--u));
  width: calc(38 * var(--u));
}

/* Squares are 22x22 art pixels, 25 apart (so 3 apart between them). */
.gear-grid {
  position: absolute;
  display: grid;
  gap: calc(3 * var(--u));
}

.armour-grid {
  left: calc(56 * var(--u));
  top: calc(69 * var(--u));
  grid-template-columns: repeat(3, calc(22 * var(--u))); /* 3 x 2 = 6 armour squares */
}

.weapon-grid {
  left: calc(140 * var(--u));
  top: calc(82 * var(--u));
  grid-template-columns: repeat(2, calc(22 * var(--u))); /* 2 weapon squares */
}

/* One gear square: the picture already draws the frame, so this is just a clickable area. */
.gear-slot {
  width: calc(22 * var(--u));
  height: calc(22 * var(--u));
  box-sizing: border-box;
  padding: 0;
  background: transparent;
  border: none;
  cursor: pointer;
  touch-action: manipulation;
}

.gear-slot img {
  width: 80%;
  height: 80%;
  object-fit: contain;
  pointer-events: none; /* clicks go to the button, not the image */
}

/* Pixel-art items are drawn at a whole-number scale (16px x 7 = 112px)
   so every pixel comes out the same size. */
.gear-slot img.pixel-art {
  width: 80px; /* 16px x 5 */
  height: 80px;
}

.gear-slot:hover {
  filter: brightness(0.92);
}

.gear-slot.selected {
  outline: 4px solid #eece9a;
  outline-offset: 0;
}

.gear-slot:focus-visible {
  outline: 4px solid #fff;
  outline-offset: 0;
}
/* ---------- Tick button (bottom right of a screen) ---------- */
[hidden] {
  display: none !important;
}

.tick-button,
.close-button {
  position: absolute;
  right: 48px;
  bottom: 36px;
  padding: 0;
  background: transparent;
  border: none;
  cursor: pointer;
  touch-action: manipulation;
}

.tick-button img,
.close-button img {
  display: block;
  width: 96px;   /* the icon is 16x16, so 96 is a clean 6x scale */
  height: 96px;
}

.tick-button:hover,
.tick-button:focus-visible,
.close-button:hover,
.close-button:focus-visible {
  filter: brightness(1.25);
  outline: none;
}

/* ---------- Item stat tooltip ---------- */
.tooltip {
  max-width: 380px;
  position: absolute;
  left: 0;
  top: 0;
  min-width: 190px;
  padding: 12px 16px;
  background: #1b0f08;
  border: 2px solid #eece9a;
  color: #f2e6d0;
  font-size: 20px;
  line-height: 1.5;
  pointer-events: none; /* so it never blocks clicks */
  z-index: 30000; /* above every screen, popup and message; only the black fade is higher */
}

.tooltip-name {
  font-size: 20px;
}

.tooltip-tier {
  margin-bottom: 10px;
  opacity: 0.75;
}

/* Space between the stat rows */
.tooltip-stats {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tooltip-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 28px;
}

.tooltip-row.tight {
  justify-content: flex-start;
  gap: 12px;
}

.stat-icon {
  width: 32px;   /* 16x16 icon at 2x scale */
  height: 32px;
  /* hard-edged shadow, down and to the right (offset x, offset y, blur, colour) */
  filter: drop-shadow(2px 2px 0 rgba(0, 0, 0, 0.7));
}

/* ---------- Pixel art ---------- */
/* Put class="pixel-art" on any small pixel-art image so enlarging it keeps
   hard edges instead of blurring. (Not for large drawn sprites that get
   shrunk down, which look better smoothed.) */
.pixel-art {
  image-rendering: crisp-edges; /* fallback for older browsers */
  image-rendering: pixelated;
}

/* ---------- Battle screen ---------- */
#battle-screen {
  background: #000;
}

/* The battle scene itself (background now; player and enemies go inside later). */
.battle-world {
  position: absolute;
  inset: 0;
  background: #a2bbe8; /* sky colour, behind the animated frames */
  isolation: isolate;  /* keeps the layers' z-index inside the scene, below the menu buttons */
  transition: filter 0.2s;
}

/* grass_terrain.png is a 3x3 sheet of 240x135 frames (the 5 that contain art), drawn 5.33x
   bigger so one frame fills the 1280x720 stage. Each frame is its own layer; the layers
   cross-fade into each other, one every second. */
.terrain-frame {
  position: absolute;
  inset: 0;
  background: url("assets/scenes/grass_terrain.png") 0 0 / 3840px 2160px no-repeat;
  image-rendering: pixelated;
  opacity: 0;
  animation: terrain-fade 5s linear infinite;
}

.terrain-frame:nth-child(1) { background-position: 0 -720px;        animation-delay: 0s; }
.terrain-frame:nth-child(2) { background-position: -1280px -720px;  animation-delay: 1s; }
.terrain-frame:nth-child(3) { background-position: 0 -1440px;       animation-delay: 2s; }
.terrain-frame:nth-child(4) { background-position: -1280px -1440px; animation-delay: 3s; }
.terrain-frame:nth-child(5) { background-position: -2560px -1440px; animation-delay: 4s; }

/* A layer fades in on top (0 to 12% of 5s = 0.6s), stays until the next one has fully faded
   in over it (32%), then vanishes. z-index keeps the fading-in layer on top, including when
   the loop wraps from the last frame back to the first. */
/* ANIMATION SWITCHED OFF for now: only the first frame is shown, as a still image.
   To bring the animation back, delete this rule. */
.terrain-frame {
  animation: none;
  opacity: 1;
}
.terrain-frame:not(:first-child) {
  display: none;
}

@keyframes terrain-fade {
  0%      { opacity: 0; z-index: 2; }
  12%     { opacity: 1; z-index: 2; }
  12.01%  { opacity: 1; z-index: 1; }
  32%     { opacity: 1; z-index: 1; }
  32.01%  { opacity: 0; z-index: 0; }
  100%    { opacity: 0; z-index: 0; }
}

/* Added while a menu is open. The slight zoom hides the soft edges blur creates. */
.battle-world.blurred {
  filter: blur(10px) brightness(0.6);
}

/* Menu buttons: a column on the left edge, just above the hotbar */
.battle-menu-buttons {
  position: absolute;
  left: 32px;
  top: 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.menu-button {
  padding: 0;
  border: none;
  background: none; /* the button art has its own frame */
  cursor: pointer;
  touch-action: manipulation;
}

.menu-button img {
  display: block;
  width: 96px;   /* 16x16 art at 6x, same size as the tick and close buttons */
  height: 96px;
  pointer-events: none;
}

.menu-button:hover,
.menu-button:focus-visible {
  filter: brightness(1.25);
  outline: none;
}

/* ---------- Menus on top of the battle ---------- */
.menu-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.menu-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* The sheet art is shown at 4x. Its drawn area is 152x126, so 608x504 here;
   the rest of the 160x150 image is empty and is cropped off. */
.sheet {
  position: relative;
  width: 608px;
  height: 504px;
  background: url("assets/ui/character_sheet.png") 0 0 / 640px 600px no-repeat;
  image-rendering: pixelated;
  user-select: none;
}

/* One place an item can sit (equipment slots and inventory spaces) */
.sheet-slot {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  touch-action: none; /* lets a finger drag items instead of scrolling the page */
}

.sheet-slot img {
  width: 48px;   /* 16x16 art at 3x, leaving a gap inside the 64px box */
  height: 48px;
  object-fit: contain;
  pointer-events: none;
  -webkit-user-drag: none;
}

.weapon-slot img {
  width: 80px;   /* 16x16 art at 5x, leaving a gap inside the larger weapon slot */
  height: 80px;
}

.sheet-slot.has-item {
  cursor: grab;
}

.sheet-slot.drag-source img {
  opacity: 0.35;
}

/* Lit up while dragging an item that belongs in this slot */
.sheet-slot.drop-ok {
  outline: 4px solid #eece9a;
  outline-offset: -4px;
}

/* The item following the pointer while dragging */
.drag-ghost {
  position: absolute;
  width: 48px;
  height: 48px;
  pointer-events: none;
  z-index: 30;
  filter: drop-shadow(3px 3px 0 rgba(0, 0, 0, 0.6));
}

/* Stat totals in the top five boxes on the right of the sheet */
.sheet-stat {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  font-weight: bold;
  pointer-events: auto; /* hovering shows where the stat comes from */
  text-shadow: 2px 2px 0 #000, -2px 2px 0 #000, 2px -2px 0 #000, -2px -2px 0 #000;
}

/* Close and tick buttons, bottom right while a menu is up */
.menu-nav {
  position: absolute;
  right: 48px;
  bottom: 36px;
  display: flex;
  gap: 16px;
}

.menu-nav .tick-button,
.menu-nav .close-button {
  position: static;
}

/* Used on the talent map, which is too wide for the buttons side by side */
.menu-nav.stacked {
  flex-direction: column;
}

/* ---------- Hover box: text and ability numbers ---------- */
.tooltip-text {
  margin-bottom: 10px;
  font-size: 20px;
  line-height: 1.35;
}

.current-rank {
  color: #eece9a;
}

.tooltip-final {
  color: #eece9a;
  font-weight: bold;
}

/* ---------- Talent screen and talent map ---------- */
#talent-screen {
  background: #3b2314;
}

/* The map is one full-screen picture (talent_map.png, 240x135 drawn at 1280x720). It covers
   the stage; the tick and close buttons sit on top of its right-hand margin. */
.talent-map {
  position: absolute;
  left: 0;
  top: 0;
  width: 1280px;
  height: 720px;
  background: #2e1a17 url("assets/ui/talent_map.png") 0 0 / 1280px 720px no-repeat;
  image-rendering: pixelated;
}

/* The header bar of the picture is x 7..233, y 7..24 art pixels = 37..1243 x 37..128 px */
.talent-title,
.talent-level,
.talent-points {
  position: absolute;
  top: 37px;
  height: 91px;
  display: flex;
  align-items: center;
}

.talent-title {
  left: 68px;
  font-size: 40px;
}

.talent-level {
  right: 330px;
  font-size: 30px;
}

.talent-points {
  right: 68px;
  font-size: 30px;
  color: #e87878; /* light red, like the talent star */
}

/* Arrows: the picture is set by talentmap.js (--arrow-image); each one is turned to point
   the right way. Lit arrows (parent talent learned) are full colour, the rest are dimmed. */
.talent-arrow {
  position: absolute;
  background: var(--arrow-image) 0 0 / 100% 100% no-repeat;
  image-rendering: pixelated;
  pointer-events: none;
  display: none;
}

.arrow-ready .talent-arrow {
  display: block;
}

.talent-arrow.arrow-dim {
  opacity: 0.3;
}

.talent-arrow.arrow-lit {
  filter: drop-shadow(1px 1px 0 rgba(0, 0, 0, 0.7));
}

/* Each box is talent_node.png (70x22 art) stretched to 160x59. */
.talent-box {
  position: absolute;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  font-family: inherit;
  color: #f2e6d0;
  /* the node is drawn in the top-left 70x22 of a 240x135 canvas, so crop to it */
  background: url("assets/ui/talent_node.png") 0 0 / 342.86% 613.64% no-repeat;
  image-rendering: pixelated;
  border: none;
  cursor: default;
  touch-action: manipulation;
}

/* The coloured left edge shows what kind of talent it is */
/* Set by talentmap.js once the node picture has been cut down to its drawn part */
.node-cropped .talent-box {
  background-image: var(--node-image);
  background-size: 100% 100%;
}

.talent-box[data-type="ability"] { box-shadow: inset 8px 0 0 #e08a3a; }
.talent-box[data-type="spell"]   { box-shadow: inset 8px 0 0 #5b8be0; }
.talent-box[data-type="passive"] { box-shadow: inset 8px 0 0 #5fb87a; }

.talent-name {
  font-size: 20px;
  font-weight: bold;
  line-height: 1.1;
  text-align: center;
}

.talent-rank {
  margin-top: 3px;
  font-size: 20px;
  opacity: 0.8;
}

.talent-box.is-locked {
  opacity: 0.45;
}

/* States are drawn as an outline round the picture */
.talent-box.is-available {
  outline: 3px solid #f2e6d0;
  cursor: pointer;
}

.talent-box.is-available:hover {
  filter: brightness(1.35);
}

.talent-box.is-learned {
  outline: 3px solid #eece9a;
}

.talent-box.is-maxed {
  outline: 3px solid #eece9a;
  filter: brightness(1.3);
}

.talent-box.has-pending {
  outline: 3px solid #6fd0a0;
}

.talent-box.is-start {
  outline: 3px dashed #eece9a;
}

/* ---------- Yes/no popup ---------- */
.popup {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
}

.popup-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 26px;
  padding: 36px 56px;
  background: #2a170d;
  border: 4px solid #eece9a;
}

.popup-box p {
  margin: 0;
  font-size: 30px;
}

.popup-buttons {
  display: flex;
  gap: 40px;
}

.popup-buttons .tick-button,
.popup-buttons .close-button {
  position: static;
}

.popup-buttons img {
  width: 80px;
  height: 80px;
}

/* ---------- Abilities as items (text labels until there are icons) ---------- */
.ability-chip {
  box-sizing: border-box;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px;
  font-size: 10px;
  font-weight: bold;
  line-height: 1.05;
  text-align: center;
  overflow: hidden;
  color: #f2e6d0;
  background: #1b0f09;
  border: 3px solid #e08a3a;
  pointer-events: none;
}


.ability-slot .ability-chip {
  width: 44px;
  height: 44px;
  font-size: 10px;
}

.drag-ghost.ability-chip {
  width: 48px;
  height: 48px;
}

/* ---------- Acquired talents list, right of the character sheet ---------- */
.menu-panel {
  position: relative;
}

/* The talent map is a full-stage picture, so its panel must not be centred or shrunk. */
#talent-panel {
  position: static;
}

.acquired {
  position: absolute;
  left: calc(100% + 28px);
  top: 0;
  width: 280px;
  max-height: 470px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.acquired-title {
  font-size: 30px;
}

.acquired-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  padding-right: 4px;
}

.acquired-empty {
  font-size: 20px;
  opacity: 0.6;
}

/* Each entry is inventory_talent_node.png (100x22 art) drawn at 2.5x = 250x55, the same
   scale as the talent map boxes. */
.acquired-talent {
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-sizing: border-box;
  width: 250px;
  height: 55px;
  flex: none;
  padding: 0 14px 0 18px;
  font-size: 20px;
  background: url("assets/ui/inventory_talent_node.png") 0 0 / 100% 100% no-repeat;
  image-rendering: pixelated;
  cursor: default;
}


.acquired-rank {
  font-weight: normal;
  opacity: 0.8;
}

/* Long names without an icon: the rank moves beside the name so the name can use two lines */
/* The name is on top and the rank is directly under it. With an icon, the icon is on the
   left and the name and rank are stacked to its right. A name that is too wide gets smaller
   text (the class is added in talentmap.js). */
.talent-box:has(.talent-icon) {
  display: grid;
  grid-template-columns: 40px 1fr;
  grid-template-rows: 1fr auto auto 1fr;
  align-items: center;
  column-gap: 4px;
  padding: 0 6px;
}
.talent-box:has(.talent-icon) .talent-icon {
  grid-column: 1;
  grid-row: 1 / 5;
  justify-self: center;
  align-self: center;
  width: 32px;
  height: 32px;
}
.talent-box:has(.talent-icon) .talent-name {
  grid-column: 2;
  grid-row: 2;
  margin: 0;
}
.talent-box:has(.talent-icon) .talent-rank {
  grid-column: 2;
  grid-row: 3;
  margin: 3px 0 0;
  text-align: center;
}

/* Cosmic Blast stays on one line; the text may spill slightly past the box edge. */
.talent-box[data-id="arcane-blast"] .talent-name {
  white-space: nowrap;
}

.talent-box.small-name .talent-name {
  font-size: 10px;
  line-height: 12px;
}

/* ---------- Icon drop shadow ---------- */
/* A small hard-edged shadow (down and right, no blur) so icons stand out from the background. */
.gear-slot img,
.sheet-slot img,
.talent-icon,
.hotbar-button img,
.stat-icon {
  filter: drop-shadow(2px 2px 0 rgba(0, 0, 0, 0.7));
}

/* ---------- Hotbar ---------- */
/* Bottom left of the battle (77x21 art at 5x = 385x105), leaving the rest of the screen for enemies */
.hotbar {
  z-index: 5;
  position: absolute;
  left: 32px;
  bottom: 32px;
  width: 385px;
  height: 105px;
}

.hotbar-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Auto Attack sits on the first slot of the hotbar (art pixels 4..16, drawn at 5x = 65px),
   covering the faded sword; the equipped weapon is drawn over it at 3x (48px), centred,
   so it stays clear of the slot's edges. */
.hotbar-button {
  font-family: inherit;
  position: absolute;
  left: 20px;
  top: 20px;
  width: 65px;
  height: 65px;
  padding: 0;
  border: none;
  background: none;
  cursor: default;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hotbar-button img {
  width: 48px; /* 16x16 art at 3x */
  height: 48px;
  pointer-events: none;
}

/* ---------- Hover box: bold key words and tier ---------- */
/* The pixel font has no bold, and the browser's fake bold smears it. Instead the text is
   drawn twice, one font pixel (2px at this size) apart, which stays perfectly crisp. */
.tooltip b {
  font-weight: normal;
  text-shadow: 2px 0 0 currentColor;
  margin-right: 2px;
}

.tooltip-tier-inline {
  margin-left: 10px;
  opacity: 0.75;
}

/* ---------- Container style ---------- */
/* container.png (16x16, 1-pixel frame) is used as a 9-slice frame: the corners and edges keep
   their pixels (drawn 3px thick) and the middle stretches. Every panel that used to have a
   plain coloured border now uses it, so the whole interface matches. */
.tooltip,
.popup-box,
#start-button,
.ability-chip {
  border-width: 3px;
  border-style: solid;
  border-color: transparent;
  border-image: url("assets/ui/container.png") 1 fill / 3px stretch;
  image-rendering: pixelated;
  background: none;
}

/* The coloured edge that shows an ability / spell / passive (on talents and ability labels).
   It is a thin strip inside the frame, because the frame picture is painted over shadows. */
.acquired-talent,
.ability-chip:not(.drag-ghost) {
  position: relative;
}

.acquired-talent::before,
.ability-chip::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 6px;
  background: var(--edge, transparent);
}

.acquired-talent[data-type="ability"],
.ability-chip.ability-ability { --edge: #e08a3a; }
.acquired-talent[data-type="spell"],
.ability-chip.ability-spell   { --edge: #5b8be0; }
.acquired-talent[data-type="passive"],
.ability-chip.ability-passive { --edge: #5fb87a; }

#start-button:hover,
#start-button:focus-visible {
  background: none;
  color: #f2e6d0;
  filter: brightness(1.4);
}

/* ---------- Battle units ---------- */
.battle-units {
  position: absolute;
  inset: 0;
}

/* One character or enemy. Its pictures are stacked and the CSS shows one at a time. */
.unit {
  position: absolute;
}

.unit-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  /* a hard-edged shadow, like the icons (a little bigger as these are drawn at 6x) */
  filter: drop-shadow(3px 3px 0 rgba(0, 0, 0, 0.6));
  animation: idle-a 1s step-end infinite;
}

/* The player's poses (hurt, attack, blink, spell): hidden until the unit has data-pose="that pose" */
.unit-frame.pose-frame {
  opacity: 0;
  animation: none;
}
.unit[data-pose] > .frame-a,
.unit[data-pose] > .frame-b {
  visibility: hidden; /* (hidden rather than stopped, so the idle beat carries on underneath) */
}
.unit[data-pose="hurt"] > .pose-hurt.pose-a,
.unit[data-pose="attack"] > .pose-attack.pose-a,
.unit[data-pose="blink"] > .pose-blink.pose-a,
.unit[data-pose="spell"] > .pose-spell.pose-a {
  animation: idle-a var(--pose-ms, 300ms) step-end 1 forwards;
}
.unit[data-pose="hurt"] > .pose-hurt.pose-b,
.unit[data-pose="attack"] > .pose-attack.pose-b,
.unit[data-pose="blink"] > .pose-blink.pose-b,
.unit[data-pose="spell"] > .pose-spell.pose-b {
  animation: idle-b var(--pose-ms, 300ms) step-end 1 forwards;
}

/* The idle loop: each frame shows for 0.5 seconds */
.unit-frame.frame-b {
  animation-name: idle-b;
}

@keyframes idle-a {
  0%   { opacity: 1; }
  50%  { opacity: 0; }
}

@keyframes idle-b {
  0%   { opacity: 0; }
  50%  { opacity: 1; }
}

/* ---------- Bars ---------- */
/* The player's Health, Energy and Mana bars sit directly above the hotbar */
.player-bars {
  position: absolute;
  left: 32px;
  bottom: 145px; /* 32px margin + 105px hotbar + 8px gap */
  width: 260px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 5;
}

.bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
}

/* The icon sits in one of your containers (38px = 32px icon at 2x + the 3px frame) */
.bar-icon-box {
  box-sizing: border-box;
  width: 44px; /* 32px icon (2x) + 3px frame + 3px breathing room each side */
  height: 44px;
  flex: none;
  border-width: 3px;
  border-style: solid;
  border-color: transparent;
  border-image: url("assets/ui/container.png") 1 fill / 3px stretch;
  image-rendering: pixelated;
}

.bar-icon {
  display: block;
  width: 32px; /* 16x16 art at 2x */
  height: 32px;
  filter: drop-shadow(2px 2px 0 rgba(0, 0, 0, 0.7));
}

.bar-frame,
.enemy-bar {
  box-sizing: border-box;
  border-width: 3px;
  border-style: solid;
  border-color: transparent;
  border-image: url("assets/ui/container.png") 1 fill / 3px stretch;
  image-rendering: pixelated;
}

.bar-frame {
  flex: 1;
  height: 28px;
  padding: 3px;
}

.bar-fill {
  height: 100%;
  width: 100%;
}

/* A small health bar centred above an enemy (96px wide, in its own coordinates) */
.enemy-bar {
  position: absolute;
  left: 4px;
  right: 4px;
  top: -20px;
  height: 16px;
  padding: 2px;
}

/* ---------- Turns ---------- */
.battle-units {
  pointer-events: none;
}

.unit.enemy {
  pointer-events: auto;
}

/* After clicking Auto Attack, enemies can be picked */
.battle-units.targeting .unit.enemy {
  cursor: pointer;
}

.battle-units.targeting .unit.enemy:hover .unit-frame {
  filter: drop-shadow(3px 3px 0 rgba(0, 0, 0, 0.6)) brightness(1.35);
}

.hotbar-button.selected {
  outline: 4px solid #eece9a;
  outline-offset: 0;
}

.hotbar-button {
  cursor: pointer;
}

.skip-button {
  position: absolute;
  left: 449px; /* just right of the hotbar */
  bottom: 32px;
  z-index: 5;
  width: 190px;
  height: 64px;
  font-family: inherit;
  font-size: 30px;
  color: #f2e6d0;
  border-width: 3px;
  border-style: solid;
  border-color: transparent;
  border-image: url("assets/ui/container.png") 1 fill / 3px stretch;
  image-rendering: pixelated;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}

.skip-button:hover {
  filter: brightness(1.4);
}

.turn-label {
  position: absolute;
  top: 36px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 40px;
  text-shadow: 3px 3px 0 rgba(0, 0, 0, 0.7);
  pointer-events: none;
}

.battle-banner {
  position: absolute;
  top: 250px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 100px;
  text-shadow: 6px 6px 0 rgba(0, 0, 0, 0.7);
  pointer-events: none;
  z-index: 12000;
}

.float-text {
  position: absolute;
  text-align: center;
  font-size: 40px;
  text-shadow: 3px 3px 0 rgba(0, 0, 0, 0.8);
  pointer-events: none;
  z-index: 1000;
  animation: float-up 0.9s ease-out forwards;
}

.float-text.damage  { color: #ff7070; }
.float-text.neutral { color: #f2e6d0; }

@keyframes float-up {
  from { transform: translateY(0);     opacity: 1; }
  to   { transform: translateY(-50px); opacity: 0; }
}

/* ---------- Hotbar abilities (step C) ---------- */
/* Slots 2-5 sit on the next four containers: 14 art pixels (70px) apart */
.hotbar-button[data-index="1"] { left: 90px; }
.hotbar-button[data-index="2"] { left: 160px; }
.hotbar-button[data-index="3"] { left: 230px; }
.hotbar-button[data-index="4"] { left: 300px; }

.hotbar-button.dark::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.hotbar-key {
  font-family: "GAME", Georgia, serif;
  position: absolute;
  left: 4px;
  top: 2px;
  font-size: 10px;
  color: #eece9a;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.9);
  pointer-events: none;
}

.hotbar-name {
  font-size: 10px;
  line-height: 12px;
  color: #f2e6d0;
  text-align: center;
  pointer-events: none;
}

.hotbar-cd {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  color: #f2e6d0;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.9);
  z-index: 1;
  pointer-events: none;
}

.menu-button[hidden] { display: none; }

.battle-units.targeting .unit.enemy.hit-preview .unit-frame {
  filter: drop-shadow(3px 3px 0 rgba(0, 0, 0, 0.6)) brightness(1.35);
}

.float-text.crit   { color: #eece9a; font-size: 50px; }
.float-text.heal   { color: #7be08a; }
.float-text.shield { color: #8fa4ff; }

.gear-lock-note {
  position: absolute;
  top: 8px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 20px;
  color: #eece9a;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.8);
  pointer-events: none;
}
.float-text { white-space: nowrap; width: 400px; margin-left: -200px; margin-right: 0; padding: 0; box-sizing: border-box; text-align: center; }

.stage-label {
  position: absolute;
  top: 40px;
  right: 32px;
  font-size: 30px;
  text-shadow: 3px 3px 0 rgba(0, 0, 0, 0.7);
  pointer-events: none;
}

/* The lock note sits centred above the character sheet / talent map */
#sheet-panel .gear-lock-note {
  top: -48px;
}
#talent-panel .gear-lock-note {
  top: 12px;
  z-index: 3;
}

/* Bar values: shown on the bar itself while hovering it */
.bar-frame { position: relative; }
.bar-row { height: 44px; }

.bar-text {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
  color: #f2e6d0;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.9);
  pointer-events: none;
  white-space: nowrap;
}

.bar-row:hover .bar-text,
.unit.enemy:hover .bar-text {
  display: flex;
}

.enemy-bar .bar-text {
  font-size: 10px;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.9);
}

/* Centre the icon inside its container */
.bar-icon-box {
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- Encounters ---------- */
.gear-slot {
  position: relative;
  font-family: inherit;
}

.offer-chip {
  font-size: 20px;
  line-height: 22px;
  color: #f2e6d0;
  text-align: center;
  padding: 0 6px;
  pointer-events: none;
}

.offer-price {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 20px;
  color: #f2e6d0;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.9);
  pointer-events: none;
  z-index: 2; /* in front of the tier border */
}

.gear-slot .offer-price img.pixel-art {
  width: 24px;
  height: 24px;
  filter: none;
}

.encounter-message {
  position: absolute;
  left: 160px;
  right: 160px;
  bottom: 20px;
  min-height: 60px;
  text-align: center;
  font-size: 20px;
  line-height: 26px;
  color: #eece9a;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.8);
  pointer-events: none;
}

#encounter-screen.blurred {
  filter: blur(10px) brightness(0.6);
}

.gold-display {
  position: absolute;
  top: 88px;
  right: 32px;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 30px;
  text-shadow: 3px 3px 0 rgba(0, 0, 0, 0.7);
  pointer-events: none;
}

.gold-display img {
  width: 32px;
  height: 32px;
  filter: drop-shadow(2px 2px 0 rgba(0, 0, 0, 0.7));
}

.battle-loot {
  position: absolute;
  top: 370px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 30px;
  color: #eece9a;
  text-shadow: 3px 3px 0 rgba(0, 0, 0, 0.8);
  pointer-events: none;
  z-index: 10;
}

#continue-button {
  z-index: 5;
}

.ability-chip.ability-loot { --edge: #a98d5a; }

/* The talent lock note sits in the middle of the top bar, left of "Level", and wraps */
#talent-panel .gear-lock-note {
  top: 45px;
  left: 270px;
  right: auto;
  width: 540px;
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 24px;
  z-index: 3;
}
.menu-overlay { z-index: 10; }

/* ---------- Black outlines instead of drop shadows on text with no container ---------- */
.bar-text {
  text-shadow: -2px 0px 0 #000, 2px 0px 0 #000, 0px -2px 0 #000, 0px 2px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000, 2px 2px 0 #000;
}

.enemy-bar .bar-text {
  text-shadow: -1px 0px 0 #000, 1px 0px 0 #000, 0px -1px 0 #000, 0px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;
}

.turn-label {
  text-shadow: -4px 0px 0 #000, 4px 0px 0 #000, 0px -4px 0 #000, 0px 4px 0 #000, -4px -4px 0 #000, 4px -4px 0 #000, -4px 4px 0 #000, 4px 4px 0 #000;
}

.stage-label {
  text-shadow: -3px 0px 0 #000, 3px 0px 0 #000, 0px -3px 0 #000, 0px 3px 0 #000, -3px -3px 0 #000, 3px -3px 0 #000, -3px 3px 0 #000, 3px 3px 0 #000;
}

.battle-banner {
  text-shadow: -10px 0px 0 #000, 10px 0px 0 #000, 0px -10px 0 #000, 0px 10px 0 #000, -10px -10px 0 #000, 10px -10px 0 #000, -10px 10px 0 #000, 10px 10px 0 #000;
}

.float-text {
  text-shadow: -4px 0px 0 #000, 4px 0px 0 #000, 0px -4px 0 #000, 0px 4px 0 #000, -4px -4px 0 #000, 4px -4px 0 #000, -4px 4px 0 #000, 4px 4px 0 #000;
}

.float-text.crit {
  text-shadow: -5px 0px 0 #000, 5px 0px 0 #000, 0px -5px 0 #000, 0px 5px 0 #000, -5px -5px 0 #000, 5px -5px 0 #000, -5px 5px 0 #000, 5px 5px 0 #000;
}

.gold-display {
  text-shadow: -3px 0px 0 #000, 3px 0px 0 #000, 0px -3px 0 #000, 0px 3px 0 #000, -3px -3px 0 #000, 3px -3px 0 #000, -3px 3px 0 #000, 3px 3px 0 #000;
}

.battle-loot {
  text-shadow: -3px 0px 0 #000, 3px 0px 0 #000, 0px -3px 0 #000, 0px 3px 0 #000, -3px -3px 0 #000, 3px -3px 0 #000, -3px 3px 0 #000, 3px 3px 0 #000;
}

.encounter-message {
  text-shadow: -2px 0px 0 #000, 2px 0px 0 #000, 0px -2px 0 #000, 0px 2px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000, 2px 2px 0 #000;
}

.hotbar-key {
  text-shadow: -1px 0px 0 #000, 1px 0px 0 #000, 0px -1px 0 #000, 0px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;
}

.hotbar-cd {
  text-shadow: -3px 0px 0 #000, 3px 0px 0 #000, 0px -3px 0 #000, 0px 3px 0 #000, -3px -3px 0 #000, 3px -3px 0 #000, -3px 3px 0 #000, 3px 3px 0 #000;
}

.gear-lock-note {
  text-shadow: -2px 0px 0 #000, 2px 0px 0 #000, 0px -2px 0 #000, 0px 2px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000, 2px 2px 0 #000;
}

.coin-icon {
  width: 1em;
  height: 1em;
  vertical-align: -0.12em;
  margin-left: 0.2em;
}

.gold-amount {
  white-space: nowrap;
}

#tools-heading .coin-icon {
  width: 30px;
  height: 30px;
}

/* Thinner outlines (about 60% of the first version) and bar text nudged down to centre it */
.bar-text {
  text-shadow: -1px 0px 0 #000, 1px 0px 0 #000, 0px -1px 0 #000, 0px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;
}

.enemy-bar .bar-text {
  text-shadow: -1px 0px 0 #000, 1px 0px 0 #000, 0px -1px 0 #000, 0px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;
}

.turn-label {
  text-shadow: -2px 0px 0 #000, 2px 0px 0 #000, 0px -2px 0 #000, 0px 2px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000, 2px 2px 0 #000;
}

.stage-label {
  text-shadow: -2px 0px 0 #000, 2px 0px 0 #000, 0px -2px 0 #000, 0px 2px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000, 2px 2px 0 #000;
}

.battle-banner {
  text-shadow: -6px 0px 0 #000, 6px 0px 0 #000, 0px -6px 0 #000, 0px 6px 0 #000, -6px -6px 0 #000, 6px -6px 0 #000, -6px 6px 0 #000, 6px 6px 0 #000;
}

.float-text {
  text-shadow: -2px 0px 0 #000, 2px 0px 0 #000, 0px -2px 0 #000, 0px 2px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000, 2px 2px 0 #000;
}

.float-text.crit {
  text-shadow: -3px 0px 0 #000, 3px 0px 0 #000, 0px -3px 0 #000, 0px 3px 0 #000, -3px -3px 0 #000, 3px -3px 0 #000, -3px 3px 0 #000, 3px 3px 0 #000;
}

.gold-display {
  text-shadow: -2px 0px 0 #000, 2px 0px 0 #000, 0px -2px 0 #000, 0px 2px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000, 2px 2px 0 #000;
}

.battle-loot {
  text-shadow: -2px 0px 0 #000, 2px 0px 0 #000, 0px -2px 0 #000, 0px 2px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000, 2px 2px 0 #000;
}

.encounter-message {
  text-shadow: -1px 0px 0 #000, 1px 0px 0 #000, 0px -1px 0 #000, 0px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;
}

.hotbar-key {
  text-shadow: -1px 0px 0 #000, 1px 0px 0 #000, 0px -1px 0 #000, 0px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;
}

.hotbar-cd {
  text-shadow: -2px 0px 0 #000, 2px 0px 0 #000, 0px -2px 0 #000, 0px 2px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000, 2px 2px 0 #000;
}

.gear-lock-note {
  text-shadow: -1px 0px 0 #000, 1px 0px 0 #000, 0px -1px 0 #000, 0px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;
}

.bar-text {
  padding-top: 4px;
  box-sizing: border-box;
}

.enemy-bar .bar-text {
  padding-top: 2px;
}

/* Stand-in label for items that have no picture yet */
.missing-art {
  font-size: 10px;
  line-height: 1.1;
  text-align: center;
  color: #fff;
  overflow: hidden;
  max-width: 100%;
  word-break: break-word;
  pointer-events: none;
}

.missing-ghost { background: rgba(122, 74, 68, 0.8); outline: 2px solid #eece9a; }

/* Compare box shown beside a tooltip while Shift is held */
.tooltip-compare { opacity: 0.95; }

/* Scroll bar in the talents list: square, dark track, brown thumb to match the containers */
.acquired-list {
  scrollbar-width: thin;
  scrollbar-color: #7a4a44 #1b0f08;
}
.acquired-list::-webkit-scrollbar { width: 14px; }
.acquired-list::-webkit-scrollbar-track {
  background: #1b0f08;
  border: 3px solid #5a3430;
}
.acquired-list::-webkit-scrollbar-thumb {
  background: #9b6a5f;
  border: 3px solid #1b0f08;
  border-radius: 0;
}
.acquired-list::-webkit-scrollbar-button { display: none; }

/* The shop message sits above the menu layer so it stays readable when the screen is blurred */
.encounter-message { z-index: 11; }
#encounter-screen:not(.active) ~ .encounter-message { display: none; }

/* Damage text lasts about a second longer */
.float-text.damage, .float-text.neutral, .float-text.heal, .float-text.shield {
  animation: float-up-slow 1.5s ease-out forwards;
}
@keyframes float-up-slow {
  0%   { transform: translateY(0);      opacity: 1; }
  70%  { opacity: 1; }
  100% { transform: translateY(-130px); opacity: 0; } /* further and faster than before */
}
/* Critical hits stay where they land, then fade */
.float-text.crit {
  animation: crit-stay 3s linear forwards;
  z-index: 1001;
}
@keyframes crit-stay {
  0%   { transform: scale(1.4); opacity: 1; }
  8%   { transform: scale(1);   opacity: 1; }
  80%  { transform: scale(1);   opacity: 1; }
  100% { transform: scale(1);   opacity: 0; }
}
.float-text .crit-tag { font-size: 0.6em; }

/* Temporary effects on the right of the battle */
.buff-bar {
  position: absolute;
  right: 32px;
  top: 190px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-end;
  z-index: 5;
}
.buff {
  box-sizing: border-box;
  width: 84px;
  min-height: 64px;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 18px;
  line-height: 1.1;
  background: #2a1612;
  border-width: 3px;
  border-style: solid;
  border-color: transparent;
  border-image: url("assets/ui/container.png") 1 fill / 3px stretch;
  image-rendering: pixelated;
  cursor: default;
  animation: buff-pop 0.35s ease-out;
}
.buff img { width: 48px; height: 48px; image-rendering: pixelated; }
@keyframes buff-pop {
  0%   { transform: scale(0.3); opacity: 0; }
  70%  { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(1); }
}

/* Talent numbers tracker, left of the character sheet */
.stat-tracker {
  position: absolute;
  right: calc(100% + 28px);
  top: 0;
  width: 280px;
  max-height: 470px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.stat-tracker-title { font-size: 30px; }
.stat-tracker-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: #7a4a44 #1b0f08;
}
.stat-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 20px;
  line-height: 1.3;
}
.stat-row span:last-child { color: #eece9a; text-align: right; }
.stat-tracker-empty { font-size: 20px; opacity: 0.6; }

/* ---------- Training ---------- */
.training-button {
  box-sizing: border-box;
  width: 96px;
  height: 96px;
  font-family: inherit;
  font-size: 18px;
  color: #f2e6d0;
  background: #2a1612;
  border-width: 3px;
  border-style: solid;
  border-color: transparent;
  border-image: url("assets/ui/container.png") 1 fill / 3px stretch;
  image-rendering: pixelated;
}
.training-slot {
  font-size: 20px;
  color: #f2e6d0;
  background: #2a1612;
  border-width: 3px;
  border-style: solid;
  border-color: transparent;
  border-image: url("assets/ui/container.png") 1 fill / 3px stretch;
}
.training-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}
.training-title { font-size: 48px; }
.training-points { font-size: 30px; color: #eece9a; }
.training-row { display: flex; gap: 18px; }
.training-hint { font-size: 20px; opacity: 0.8; max-width: 760px; text-align: center; }
.training-card {
  box-sizing: border-box;
  width: 190px;
  height: 260px;
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  font-family: inherit;
  color: #f2e6d0;
  font-size: 22px;
  background: #2a1612;
  border-width: 3px;
  border-style: solid;
  border-color: transparent;
  border-image: url("assets/ui/container.png") 1 fill / 3px stretch;
  image-rendering: pixelated;
  cursor: default;
}
.training-card img { width: 80px; height: 80px; }
.training-card.is-available { cursor: pointer; }
.training-card.is-available:hover { filter: brightness(1.25); }
.training-card.has-pending .training-bonus, .training-card.has-pending .training-ranks { color: #eece9a; }
.training-name { font-size: 28px; }
.training-bonus { font-size: 24px; }
#training-panel .gear-lock-note { top: -48px; }
#training-panel { position: relative; }

.training-button[hidden], .training-slot[hidden] { display: none !important; }

/* Text with no container gets a black outline instead of a shadow */
.training-title, .training-points {
  text-shadow: -3px 0 0 #000, 3px 0 0 #000, 0 -3px 0 #000, 0 3px 0 #000, -3px -3px 0 #000, 3px -3px 0 #000, -3px 3px 0 #000, 3px 3px 0 #000;
}
.training-points { text-shadow: -2px 0 0 #000, 2px 0 0 #000, 0 -2px 0 #000, 0 2px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000, 2px 2px 0 #000; }

/* Bonuses are boxes like the talents; long ones use smaller text */
.stat-tracker-list { gap: 8px; }
.stat-tracker-list .stat-row { font-size: 20px; line-height: 1.1; }
.stat-tracker-list .stat-row.small { font-size: 15px; }
.stat-tracker-list .stat-row span:last-child { color: #eece9a; opacity: 1; }

#popup-no[hidden] { display: none !important; }

.choice-title {
  font-size: 48px;
  margin-bottom: 24px;
  text-shadow: -3px 0 0 #000, 3px 0 0 #000, 0 -3px 0 #000, 0 3px 0 #000, -3px -3px 0 #000, 3px -3px 0 #000, -3px 3px 0 #000, 3px 3px 0 #000;
}
#ability-screen { background: #2e1a17; }
.ability-card { width: 250px; height: 330px; cursor: pointer; justify-content: flex-start; padding-top: 24px; }
.ability-card:hover { filter: brightness(1.25); }
.ability-card-row { font-size: 20px; color: #eece9a; }
.ability-card-text { font-size: 17px; line-height: 1.3; opacity: 0.85; text-align: center; }

/* ---------- Shops: sell-all buttons, darkened unsellable items ---------- */
.sell-all-button {
  position: absolute;
  box-sizing: border-box;
  font-family: inherit;
  font-size: 16px;
  color: #f2e6d0;
  background: #2a1612;
  border-width: 3px;
  border-style: solid;
  border-color: transparent;
  border-image: url("assets/ui/container.png") 1 fill / 3px stretch;
  image-rendering: pixelated;
  cursor: pointer;
  padding: 0;
}
.sell-all-button:hover { filter: brightness(1.3); }
.sell-all-button[hidden] { display: none !important; }
.sheet-slot.unsellable > * { filter: brightness(0.35); }

/* ---------- Calculation box (Shift over an ability / battle effect) ---------- */
.tooltip-compare.calc-box {
  background: none;
  border: none;
  box-shadow: none;
  padding: 0;
  width: 250px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.tooltip-compare.calc-box .stat-row { font-size: 18px; }
.tooltip-compare.calc-box .stat-row.small { font-size: 14px; }

/* ---------- Pixelated shadows under the player and mobs ---------- */
.unit-shadow {
  position: absolute;
  left: 10%;
  width: 80%;
  height: calc(var(--p) * 3);
  bottom: calc(var(--p) * -1.5);
  background: rgba(0, 0, 0, 0.5);
  /* a stepped ellipse, built from 3 rows of art pixels */
  clip-path: polygon(
    calc(var(--p) * 3) 0, calc(100% - var(--p) * 3) 0,
    calc(100% - var(--p) * 3) var(--p), calc(100% - var(--p)) var(--p),
    calc(100% - var(--p)) calc(var(--p) * 2), calc(100% - var(--p) * 3) calc(var(--p) * 2),
    calc(100% - var(--p) * 3) calc(var(--p) * 3), calc(var(--p) * 3) calc(var(--p) * 3),
    calc(var(--p) * 3) calc(var(--p) * 2), var(--p) calc(var(--p) * 2),
    var(--p) var(--p), calc(var(--p) * 3) var(--p)
  );
  pointer-events: none;
}
.battle-units.targeting .unit.enemy .unit-shadow { background: rgba(238, 206, 154, 0.35); }
.battle-units.targeting .unit.enemy.hit-preview .unit-shadow { background: rgba(238, 206, 154, 0.95); }
.battle-units.targeting .unit.enemy.hit-preview .unit-frame {
  filter: drop-shadow(3px 0 0 #eece9a) drop-shadow(-3px 0 0 #eece9a) drop-shadow(0 3px 0 #eece9a) drop-shadow(0 -3px 0 #eece9a) brightness(1.35);
}
.unit-shadow { background: rgba(0, 0, 0, 0.55); }

/* ---------- Shop slots that can be bought ---------- */
.gear-slot.locked-slot { opacity: 0.45; cursor: default; }
.gear-slot.locked-slot.buyable-slot { opacity: 0.9; cursor: pointer; }

/* Ability damage is yellow and spell damage is blue (for the player and mobs) */
.float-text.ability-damage { color: #ffe14a; }
.float-text.spell-damage { color: #4aa8ff; }
.float-text.ability-damage, .float-text.spell-damage {
  animation: float-up-slow 1.5s ease-out forwards;
}

/* The shadow stays a plain shadow when an enemy is highlighted: only the sprite lights up */
.battle-units.targeting .unit.enemy .unit-shadow,
.battle-units.targeting .unit.enemy.hit-preview .unit-shadow { background: rgba(0, 0, 0, 0.55); }

/* The weapon held in the player's hand (it bobs with the player's idle animation) */
.held-weapon {
  position: absolute;
  z-index: 3;
  pointer-events: none;
  filter: drop-shadow(3px 3px 0 rgba(0, 0, 0, 0.6));
  animation: weapon-bob 1s step-end infinite;
}
@keyframes weapon-bob {
  0%   { transform: translateY(0); }
  50%  { transform: translateY(var(--p)); }
}
.held-rock { pointer-events: none; }

.sell-all-button { font-size: 13px; line-height: 1; }

/* ---------- Battle log ---------- */
.battle-log {
  position: absolute;
  left: 450px;
  bottom: 8px;
  width: 800px;
  z-index: 20000;
}
.battle-log-line {
  box-sizing: border-box;
  height: 30px;
  padding: 0 12px;
  line-height: 24px;
  font-size: 18px;
  color: #f2e6d0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: #1a0f0d;
  border: 3px solid transparent;
  border-image: url("assets/ui/container.png") 1 fill / 3px stretch;
  image-rendering: pixelated;
  cursor: default;
}
.battle-log-panel {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 30px;
  height: 380px;
  box-sizing: border-box;
  overflow-y: auto;
  padding: 10px 14px;
  background: #1a0f0d;
  border: 3px solid transparent;
  border-image: url("assets/ui/container.png") 1 fill / 3px stretch;
  image-rendering: pixelated;
  font-size: 18px;
  line-height: 24px;
}
.battle-log:hover .battle-log-panel { display: block; }
.log-turn { color: #b9a68a; margin-top: 8px; border-bottom: 2px solid #4a2d28; }
.log-line { color: #f2e6d0; }
.log-ability { color: #ffe14a; }
.log-spell { color: #4aa8ff; }
.log-crit { color: #ffd21f; }
.log-heal { color: #7be08a; }
.log-hurt { color: #ff7070; }
.log-death { color: #9a8a78; }
.log-damage { color: #f2e6d0; }

/* Inventory button in the talent map's header bar */
#talent-screen.blurred { filter: blur(10px) brightness(0.6); }
.talent-inventory-button {
  position: absolute;
  left: 1150px;
  top: 150px;
  width: 64px;
  height: 64px;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
}
.talent-inventory-button img { width: 100%; height: 100%; }
.talent-inventory-button:hover { filter: brightness(1.3); }

/* The same size for every talent name */
.talent-box.small-name .talent-name { font-size: 20px; line-height: 1.1; }

/* "!" on the talent and training buttons when points are unspent */
#open-talents, #open-training, #encounter-talents, #encounter-training { position: relative; }
.point-badge {
  position: absolute;
  left: 4px;
  top: 2px;
  font-size: 26px;
  line-height: 1;
  color: #ffd21f;
  text-shadow: -2px 0 0 #000, 2px 0 0 #000, 0 -2px 0 #000, 0 2px 0 #000;
  pointer-events: none;
  z-index: 2;
}
.point-badge[hidden] { display: none; }

/* A brighter gold for critical hits */
.float-text.crit { color: #ffd21f; }

/* Cursor snapping: the reticle shows where the cursor has snapped to */
.battle-units.snapped, .battle-units.snapped * { cursor: none !important; }
.snap-reticle {
  position: absolute;
  width: 32px;
  height: 32px;
  margin: -16px 0 0 -16px;
  pointer-events: none;
  z-index: 9500;
  background:
    linear-gradient(#fff, #fff) 0 0 / 10px 3px no-repeat,
    linear-gradient(#fff, #fff) 0 0 / 3px 10px no-repeat,
    linear-gradient(#fff, #fff) 100% 0 / 10px 3px no-repeat,
    linear-gradient(#fff, #fff) 100% 0 / 3px 10px no-repeat,
    linear-gradient(#fff, #fff) 0 100% / 10px 3px no-repeat,
    linear-gradient(#fff, #fff) 0 100% / 3px 10px no-repeat,
    linear-gradient(#fff, #fff) 100% 100% / 10px 3px no-repeat,
    linear-gradient(#fff, #fff) 100% 100% / 3px 10px no-repeat;
  filter: drop-shadow(2px 2px 0 #000);
}
.snap-reticle[hidden] { display: none; }

/* ---------- Layout changes: menu buttons, battle log, Skip ---------- */
/* Menu buttons: the same size as the hotbar's containers, in a row in the top left corner */
.battle-menu-buttons {
  left: 32px;
  top: 32px;
  flex-direction: row;
  gap: 8px;
}
.battle-menu-buttons .menu-button img { width: 65px; height: 65px; }
.battle-menu-buttons .training-button { width: 65px; height: 65px; font-size: 13px; }
.battle-menu-buttons .point-badge { font-size: 20px; left: 3px; top: 1px; }

/* The battle log: centred, smaller, with a see-through background */
.battle-log {
  left: 50%;
  width: 560px;
  margin-left: -280px;
  bottom: 4px;
}
.battle-log-line, .skip-button {
  box-sizing: border-box;
  height: 26px;
  padding: 0 10px;
  line-height: 20px;
  font-size: 16px;
  background: rgba(26, 15, 13, 0.5);
  border: 3px solid transparent;
  border-image: url("assets/ui/container.png") 1 / 3px stretch;
}
.battle-log-panel {
  bottom: 26px;
  height: 300px;
  font-size: 16px;
  line-height: 21px;
  background: rgba(26, 15, 13, 0.5);
  border-image: url("assets/ui/container.png") 1 / 3px stretch;
}

/* Skip: under the hotbar, on the left, the same text and box height as the log but narrower */
.skip-button {
  left: 32px;
  bottom: 4px;
  width: 110px;
  font-family: inherit;
  text-align: center;
  color: #f2e6d0;
}

/* Final boss score */
.score-label {
  position: absolute;
  top: 92px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 28px;
  color: #ffd21f;
  text-shadow: -2px 0 0 #000, 2px 0 0 #000, 0 -2px 0 #000, 0 2px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000, 2px 2px 0 #000;
  pointer-events: none;
}
.score-label[hidden] { display: none; }
.banner-small { display: block; font-size: 40px; text-shadow: -4px 0 0 #000, 4px 0 0 #000, 0 -4px 0 #000, 0 4px 0 #000; }

/* ---------- Round of fixes (build 33) ---------- */
/* Skip uses the same solid container as the rest of the UI */
.skip-button {
  background: none;
  border: 3px solid transparent;
  border-image: url("assets/ui/container.png") 1 fill / 3px stretch;
}

/* Battle log: the bar sits at the very top of the screen and the full log opens downwards */
.battle-log { top: 4px; bottom: auto; }
.battle-log-panel { top: 26px; bottom: auto; }
.turn-label { top: 50px; }
.score-label { top: 108px; }

/* Log scroll bar: the same square bar as the talents list in the inventory */
.battle-log-panel {
  scrollbar-width: thin;
  scrollbar-color: #7a4a44 #1b0f08;
}
.battle-log-panel::-webkit-scrollbar { width: 14px; }
.battle-log-panel::-webkit-scrollbar-track { background: #1b0f08; border: 3px solid #5a3430; }
.battle-log-panel::-webkit-scrollbar-thumb { background: #9b6a5f; border: 3px solid #1b0f08; border-radius: 0; }
.battle-log-panel::-webkit-scrollbar-button { display: none; }

/* Enemy name / stats tooltip: only as big as its text */
.tooltip:has(.enemy-tip) { min-width: 0; padding: 8px 12px; }
.tooltip:has(.enemy-tip) .tooltip-text { margin-bottom: 0; }
.tooltip-text:empty { display: none; }

/* Turn counter under the stage number (the coin moves down a row during battle) */
.turn-counter {
  position: absolute;
  top: 80px;
  right: 32px;
  font-size: 24px;
  text-shadow: -3px 0 0 #000, 3px 0 0 #000, 0 -3px 0 #000, 0 3px 0 #000, -3px -3px 0 #000, 3px -3px 0 #000, -3px 3px 0 #000, 3px 3px 0 #000;
  pointer-events: none;
}
.turn-counter[hidden] { display: none; }
.gold-display.in-battle { top: 118px; }

/* Enemy tiles: one drawn grid of touching boxes with a dark, see-through line */
.spawn-grid { position: absolute; left: 0; top: 0; width: 1280px; height: 720px; pointer-events: none; z-index: 0; overflow: visible; }
.spawn-grid path { fill: none; stroke: rgba(0, 0, 0, 0.14); stroke-width: 4px; shape-rendering: crispEdges; }

/* Battle log: blurred backdrop so the text stays readable; turn headings are white */
.battle-log-panel, .battle-log-line { -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.log-turn { color: #ffffff; }

/* ---------- Round of fixes (build 40) ---------- */
/* "!" sits on the top right of the button's picture */
.badge-wrap { position: relative; display: inline-block; line-height: 0; }
.badge-wrap .point-badge { left: auto; right: 4px; top: 2px; }
.battle-menu-buttons .badge-wrap .point-badge, .battle-menu-buttons .point-badge { left: auto; right: 3px; top: 1px; }
.training-button .point-badge, .training-slot .point-badge { left: auto; right: 4px; }

/* Turn counter: the same outline as the stage counter */
.turn-counter {
  text-shadow: -2px 0px 0 #000, 2px 0px 0 #000, 0px -2px 0 #000, 0px 2px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000, 2px 2px 0 #000;
}

/* Loot notes: "+1 Item" pops up on the right and fades */
.battle-loot {
  top: 112px; /* top left, below the inventory button */
  left: 32px;
  right: auto;
  width: 420px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  text-align: left;
  font-size: 36px;
}
.loot-popup.tiered { filter: brightness(1.35) saturate(1.2); } /* trinkets and gear in their tier colour */
.loot-popup {
  color: #fff4d8;
  font-weight: bold;
  animation: loot-fade 2.6s ease-out forwards;
  text-shadow: -2px 0px 0 #000, 2px 0px 0 #000, 0px -2px 0 #000, 0px 2px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000, 2px 2px 0 #000;
}
@keyframes loot-fade {
  0%   { opacity: 0; transform: translateX(-20px); }
  10%  { opacity: 1; transform: translateX(0); }
  70%  { opacity: 1; }
  100% { opacity: 0; }
}

/* Burrowed enemies (the Bookworm underground) can't be pointed at; their bar fades */
.unit.enemy.burrowed { pointer-events: none; }
.unit.enemy.burrowed .enemy-bar { opacity: 0.35; }

/* ---------- Encounter screen pictures: one per shop/stage, each with its own layout (art pixels) ---------- */
#encounter-screen[data-layout="gear"] { background-image: url("assets/ui/gear_select.png"); }
#encounter-screen[data-layout="gear"] #offer-heading { left: calc(71 * var(--u)); top: calc(54 * var(--u)); width: calc(41 * var(--u)); }
#encounter-screen[data-layout="gear"] #offer-grid { left: calc(56 * var(--u)); top: calc(69 * var(--u)); grid-template-columns: repeat(3, calc(22 * var(--u))); }
#encounter-screen[data-layout="gear"] #tools-heading { left: calc(145 * var(--u)); top: calc(67 * var(--u)); width: calc(37 * var(--u)); }
#encounter-screen[data-layout="gear"] #tools-grid { left: calc(140 * var(--u)); top: calc(82 * var(--u)); grid-template-columns: repeat(2, calc(22 * var(--u))); }
#encounter-screen[data-layout="armour2"] { background-image: url("assets/ui/armoursmith_stage_2%2B.png"); }
#encounter-screen[data-layout="armour2"] #offer-heading { left: calc(57 * var(--u)); top: calc(54 * var(--u)); width: calc(41 * var(--u)); }
#encounter-screen[data-layout="armour2"] #offer-grid { left: calc(42 * var(--u)); top: calc(69 * var(--u)); grid-template-columns: repeat(3, calc(22 * var(--u))); }
#encounter-screen[data-layout="armour2"] #tools-heading { left: calc(141 * var(--u)); top: calc(67 * var(--u)); width: calc(42 * var(--u)); }
#encounter-screen[data-layout="armour2"] #tools-grid { left: calc(126 * var(--u)); top: calc(82 * var(--u)); grid-template-columns: repeat(3, calc(22 * var(--u))); }
#encounter-screen[data-layout="weapon1"] { background-image: url("assets/ui/weaponsmith_stage_1.png"); }
#encounter-screen[data-layout="weapon1"] #offer-heading { left: calc(74 * var(--u)); top: calc(54 * var(--u)); width: calc(37 * var(--u)); }
#encounter-screen[data-layout="weapon1"] #offer-grid { left: calc(69 * var(--u)); top: calc(69 * var(--u)); grid-template-columns: repeat(2, calc(22 * var(--u))); }
#encounter-screen[data-layout="weapon1"] #tools-heading { left: calc(133 * var(--u)); top: calc(67 * var(--u)); width: calc(37 * var(--u)); }
#encounter-screen[data-layout="weapon1"] #tools-grid { left: calc(128 * var(--u)); top: calc(82 * var(--u)); grid-template-columns: repeat(2, calc(22 * var(--u))); }
#encounter-screen[data-layout="weapon2"] { background-image: url("assets/ui/weaponsmith_stage_2%2B.png"); }
#encounter-screen[data-layout="weapon2"] #offer-heading { left: calc(61 * var(--u)); top: calc(54 * var(--u)); width: calc(37 * var(--u)); }
#encounter-screen[data-layout="weapon2"] #offer-grid { left: calc(56 * var(--u)); top: calc(69 * var(--u)); grid-template-columns: repeat(2, calc(22 * var(--u))); }
#encounter-screen[data-layout="weapon2"] #tools-heading { left: calc(130 * var(--u)); top: calc(67 * var(--u)); width: calc(41 * var(--u)); }
#encounter-screen[data-layout="weapon2"] #tools-grid { left: calc(115 * var(--u)); top: calc(82 * var(--u)); grid-template-columns: repeat(3, calc(22 * var(--u))); }
.reroll-button { position: absolute; background: #1a0f0d; border: calc(0.8 * var(--u)) solid #5a362f; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.reroll-button:hover, .reroll-button:focus-visible { filter: brightness(1.25); outline: none; }
.reroll-button .offer-price { position: static; }
.reroll-button[hidden] { display: none; }
#encounter-screen[data-layout="gear"] #reroll-button { left: calc(31 * var(--u)); top: calc(69 * var(--u)); }
#encounter-screen[data-layout="armour2"] #reroll-button { left: calc(17 * var(--u)); top: calc(69 * var(--u)); }
#encounter-screen[data-layout="weapon1"] #reroll-button { left: calc(44 * var(--u)); top: calc(69 * var(--u)); }
#encounter-screen[data-layout="weapon2"] #reroll-button { left: calc(31 * var(--u)); top: calc(69 * var(--u)); }
#encounter-screen[data-layout="chest"] { background-image: url("assets/ui/chest_encounter.png"); }
#encounter-screen[data-layout="chest"] #offer-heading { left: calc(66 * var(--u)); top: calc(67 * var(--u)); width: calc(37 * var(--u)); }
#encounter-screen[data-layout="chest"] #offer-grid { left: calc(74 * var(--u)); top: calc(82 * var(--u)); grid-template-columns: repeat(1, calc(22 * var(--u))); }
#encounter-screen[data-layout="chest"] #tools-heading { left: calc(126 * var(--u)); top: calc(67 * var(--u)); width: calc(41 * var(--u)); }
#encounter-screen[data-layout="chest"] #tools-grid { left: calc(111 * var(--u)); top: calc(82 * var(--u)); grid-template-columns: repeat(3, calc(22 * var(--u))); }

/* The encounter pictures already draw the frames, so the Training square is just the picture */
#encounter-training.training-slot { background: transparent; border: none; border-image: none; }

/* The player standing in the middle of the character sheet */
.sheet-player {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.sheet-player-inner {
  position: relative;
  width: 216px;  /* 18 art pixels x 12 */
  height: 264px; /* 22 art pixels x 12 */
}

/* Fast fade to black between encounters and stages */
#fade {
  position: absolute;
  inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
  z-index: 40000;
  transition: opacity 160ms ease-in-out;
}
#fade.on { opacity: 1; pointer-events: auto; } /* also blocks clicks while it fades */

/* Menu buttons: keep every button exactly the size of its picture so they line up */
.battle-menu-buttons { align-items: flex-start; }
.battle-menu-buttons .menu-button { line-height: 0; }
.badge-wrap { display: block; position: relative; line-height: 0; }

/* Compact tooltips: less space between lines in the same section */
.tooltip { line-height: 1.25; }
.tooltip-stats { gap: 4px; }
.tooltip-tier { margin-bottom: 6px; }
.tooltip-text { margin-bottom: 6px; line-height: 1.2; }
.tooltip-row { gap: 20px; }

/* ---------- Crentist's encounter screen (crentist_encounter1-10.png; positions in art pixels) ---------- */
.crentist-box { display: none; position: absolute; box-sizing: border-box; color: #f2e6d0; pointer-events: none; }
#encounter-screen[data-layout="crentist"] .crentist-box { display: block; }
#crentist-speech {
  left: calc(6 * var(--u)); top: calc(6 * var(--u));
  width: calc(59 * var(--u)); height: calc(47 * var(--u));
  padding: 10px 14px; font-size: 28px; line-height: 1.2; overflow: hidden;
}
#crentist-speech .untyped { visibility: hidden; }
#crentist-trade {
  left: calc(18 * var(--u)); top: calc(58 * var(--u));
  width: calc(35 * var(--u)); height: calc(13 * var(--u));
  display: none; align-items: center; justify-content: center; font-size: 34px;
}
#encounter-screen[data-layout="crentist"] #crentist-trade { display: flex; }

#encounter-screen[data-layout="crentist"] { background-size: 100% 100%; image-rendering: pixelated; }
#encounter-screen[data-layout="crentist"] #offer-heading,
#encounter-screen[data-layout="crentist"] #tools-heading { display: none; }

/* The four squares: his gold item, his trade item, the talent point, the talent reset */
#encounter-screen[data-layout="crentist"] #offer-grid {
  left: calc(11 * var(--u)); top: calc(75 * var(--u));
  grid-template-columns: repeat(2, calc(22 * var(--u)));
  gap: calc(5 * var(--u));
}
.offer-price.cant-afford { opacity: 0.45; }

/* Inventory, talents and training: the battle screen's menu buttons (65px, 8px apart, 32px from the corner),
   mirrored into the top right. Training, once unlocked, takes the far right and the others move left. */
#encounter-screen[data-layout="crentist"] #tools-grid {
  left: auto; right: 32px; top: 66px; width: auto; /* below the Settings and Encyclopedia buttons */
  grid-template-columns: none;
  grid-auto-flow: column;
  grid-auto-columns: 65px;
  gap: 8px;
}
#encounter-screen[data-layout="crentist"] #tools-grid .gear-slot { width: 65px; height: 65px; }
#encounter-screen[data-layout="crentist"] #tools-grid .gear-slot img { width: 65px; height: 65px; }
#encounter-screen[data-layout="crentist"] #tools-grid .gear-slot {
  border: none;
  border-image: none;
  background: none;
}
#encounter-screen[data-layout="crentist"] #tools-grid .gear-slot:hover { filter: brightness(1.25); }
/* "Crentist" title, in the free space left of the top buttons */
#encounter-screen[data-layout="crentist"] #encounter-title {
  left: 400px; top: 30px; width: 440px; height: 60px; font-size: 48px;
}
#encounter-screen[data-layout="crentist"] .stage-label { top: calc(30 * var(--u)); }
#encounter-screen[data-layout="crentist"] #leave-button { right: 32px; bottom: 28px; }
body:has(#encounter-screen[data-layout="crentist"].active) #gold-display { top: 208px; }
body:has(#encounter-screen[data-layout="crentist"].active) #encounter-message { left: 360px; right: 360px; }

/* Sold and discarded items fade away */
.fade-out-item { pointer-events: none; animation: item-fade-out 420ms ease-out forwards; }
@keyframes item-fade-out { from { opacity: 1; } to { opacity: 0; } }

/* No blue text-selection boxes when double-clicking things */
#game, #game * { user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }

/* Tier border: just inside the slot's own frame, so it touches the container without overlapping it */
.tiered { position: relative; }
.sheet-slot.tiered { position: absolute; }
.tiered::after {
  content: "";
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 3px var(--tier);
  pointer-events: none;
  z-index: 1;
}

.crentist-frames { position: absolute; inset: 0; z-index: 0; pointer-events: none; }
.crentist-frames { width: 100%; height: 100%; image-rendering: pixelated; }

/* Temporary effects show only their picture in a square box */
.buff.icon-only { width: 64px; height: 64px; min-height: 0; padding: 4px; }

/* In shops the container frame is part of the picture (1 art pixel thick): keep the tier border inside it */
#encounter-screen .gear-slot.tiered::after { inset: var(--u); }

/* ---------- Leaderboard ---------- */
#leaderboard-screen { background: #1a0f0d; justify-content: flex-start; padding: 28px 0 24px; gap: 8px; }
#leaderboard-heading { margin: 0; font-size: 52px; color: #f2e6d0; font-weight: normal; }
#leaderboard-note { margin: 0; font-size: 22px; color: #b9a98f; min-height: 26px; }
#leaderboard-list {
  width: 1080px; flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 4px;
  padding: 6px; background: #2a1612; border: 3px solid #5a3a33;
  user-select: none;
}
.lb-row {
  display: grid; grid-template-columns: 90px 1fr 140px 130px 240px; align-items: center; gap: 16px;
  font-family: inherit; font-size: 26px; color: #f2e6d0; text-align: left;
  padding: 6px 12px; background: #1a0f0d; border: 2px solid transparent; cursor: pointer;
}
.lb-row:hover { border-color: #eece9a; }
.lb-row span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-head { cursor: default; color: #b9a98f; background: #140b09; position: sticky; top: 0; z-index: 2; }
.lb-head:hover { border-color: transparent; }
.lb-mine { border-color: #5fd35f; color: #b8f0b8; }
#leaderboard-back {
  font-family: inherit; font-size: 30px; padding: 8px 48px; margin-top: 8px;
  color: #f2e6d0; background: transparent; border: 3px solid #f2e6d0; cursor: pointer;
}
#leaderboard-back:hover, #leaderboard-back:focus-visible { background: #f2e6d0; color: #000; outline: none; }

#build-view {
  position: absolute; inset: 40px 120px; z-index: 5; padding: 18px 28px; overflow-y: auto;
  background: #241410; border: 4px solid #eece9a; color: #f2e6d0;
}
#build-view[hidden] { display: none; }
#build-view h2 { margin: 0; font-size: 44px; font-weight: normal; }
#build-view h3 { margin: 0 0 6px; font-size: 24px; font-weight: normal; color: #eece9a; }
#build-view p { margin: 2px 0; font-size: 22px; }
.build-info { color: #b9a98f; margin-bottom: 10px !important; }
.build-close {
  position: absolute; top: 14px; right: 18px; font-family: inherit; font-size: 24px; padding: 4px 22px;
  color: #f2e6d0; background: transparent; border: 3px solid #f2e6d0; cursor: pointer;
}
.build-columns { display: grid; grid-template-columns: 170px 1fr 300px; gap: 28px; }
.build-section { margin-bottom: 16px; }
.build-grid { display: grid; grid-template-columns: repeat(8, 64px); gap: 8px; }
.build-slot {
  position: relative; width: 64px; height: 64px; box-sizing: border-box; display: flex; align-items: center; justify-content: center;
  background: #1a0f0d; border: 3px solid #4a2c26; font-size: 11px; text-align: center; line-height: 1.1;
}
.build-slot img { width: 48px; height: 48px; image-rendering: pixelated; pointer-events: none; }
.build-slot.tiered::after { inset: 0; }
.build-stat { display: flex; align-items: center; gap: 10px; font-size: 30px; }
.build-stat img { width: 32px; height: 32px; image-rendering: pixelated; }
.build-talent { cursor: default; }
.build-talent:hover { color: #eece9a; }


/* ---------- Round of fixes (build 62) ---------- */
/* Coins sit in the very top right while a menu (inventory, talents, training) is open, clear of the talents list */
body:has(#menu-overlay:not([hidden])) #gold-display.gold-display { top: 76px; right: 32px; z-index: 12; } /* above the Talents list */
/* No coins on the talent map */
body:has(#talent-panel:not([hidden])) #gold-display.gold-display,
body:has(#talent-screen.active) #gold-display.gold-display { display: none; }

/* In battle the talent map is a little smaller than the screen, so the blurred battle shows around its edges */
#talent-panel .talent-map { transform: scale(0.92); transform-origin: 50% 50%; }

/* Smaller yes/no popup (discard, confirm, reset...) */
.popup-box { gap: 16px; padding: 20px 28px; max-width: 460px; box-sizing: border-box; text-align: center; }
.popup-box p { font-size: 22px; line-height: 1.25; }
.popup-buttons { gap: 24px; }
.popup-buttons img { width: 56px; height: 56px; }

/* Death: only the background goes blurry (and slows); "You Died" and the Continue button stay sharp */
.battle-world .terrain-frame { transition: filter 1.5s ease-out, transform 1.5s ease-out; }
.battle-world.dead .terrain-frame { filter: blur(7px) brightness(0.8); transform: scale(1.04); }
/* The player, the enemies and the rest of the battle UI go blurry too; the battle log, "You Died", the score and Continue stay sharp. */
.battle-world .battle-units, .battle-world .player-bars, .battle-world .hotbar, .battle-world .skip-button, .battle-world .turn-label,
.battle-world .stage-label, .battle-world .turn-counter, .battle-world .buff-bar, .battle-world .battle-loot, .battle-world .battle-menu-buttons { transition: filter 1.5s ease-out; }
.battle-world.dead .battle-units, .battle-world.dead .player-bars, .battle-world.dead .hotbar, .battle-world.dead #skip-turn,
.battle-world.dead .turn-label, .battle-world.dead .stage-label, .battle-world.dead .turn-counter, .battle-world.dead .buff-bar,
.battle-world.dead .battle-loot, .battle-world.dead .battle-menu-buttons { filter: blur(5px) brightness(0.8); }
#restart-button.death-continue {
  position: absolute;
  left: 50%; right: auto; bottom: auto;
  width: 440px; height: 120px; margin-left: -220px;
  font-size: 56px; line-height: 1; padding: 0;
  z-index: 12001;
}

/* Crentist's screen is drawn entirely by his own picture: no other screen's art behind it to show through */
#encounter-screen[data-layout="crentist"] { background-image: none; background-color: #1a0f0d; }

#game-title { font-size: 120px; color: #eece9a; margin: 0 0 30px; text-shadow: 4px 4px 0 #5a3a33; }
.lb-row span:nth-child(2) { display: flex; align-items: center; gap: 10px; min-width: 0; }
.lb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-stat-icon { height: 30px; width: auto; flex: none; image-rendering: pixelated; }

/* Heavenly items glow a little */
.sheet-slot.glowing img, .encounter-offer.glowing img, .gear-slot.glowing img, .build-box.glowing img, .glowing > img, .glowing-item {
  filter: drop-shadow(0 0 2px rgba(255, 244, 200, 0.85)) drop-shadow(0 0 5px rgba(255, 222, 130, 0.4));
}
/* ...and still go dark in a shop that won't buy them */
.sheet-slot.glowing.unsellable > * { filter: drop-shadow(0 0 2px rgba(255, 244, 200, 0.85)) drop-shadow(0 0 5px rgba(255, 222, 130, 0.4)) brightness(0.35); }

body.talents-open #encounter-message { visibility: hidden; }

/* Bonuses in a leaderboard build: scrolls like the lists in the inventory */
.build-bonus-list { max-height: 230px; overflow-y: auto; padding-right: 6px; scrollbar-width: thin; scrollbar-color: #7a4a44 #1b0f08; }
.build-bonus-list::-webkit-scrollbar { width: 14px; }
.build-bonus-list::-webkit-scrollbar-track { background: #1b0f08; border: 3px solid #5a3430; }
.build-bonus-list::-webkit-scrollbar-thumb { background: #9b6a5f; border: 3px solid #1b0f08; border-radius: 0; }
.build-bonus-list::-webkit-scrollbar-button { display: none; }
.build-bonus-value { color: #eece9a; font-weight: normal; margin-left: 6px; }
.build-columns { grid-template-columns: 150px minmax(0, 1fr) 290px; gap: 24px; }
.build-grid { grid-template-columns: repeat(auto-fill, 64px); }
.build-bonus-list p { display: flex; justify-content: space-between; gap: 8px; font-size: 20px !important; }

/* a talent's icon shown in front of the damage it caused */
.float-icon { height: 1em; width: 1em; margin-right: 6px; vertical-align: -0.12em; image-rendering: pixelated; }
.float-text.crit .float-icon { height: 0.8em; width: 0.8em; }

/* ---------- Volume menu (Escape) ---------- */
#sound-menu { z-index: 45; }
.sound-box { min-width: 520px; max-width: none; gap: 22px; }
.end-run-button {
  font-family: inherit; font-size: 28px; padding: 6px 36px;
  color: #f2e6d0; background: transparent; border: 3px solid #f2e6d0; cursor: pointer;
}
.end-run-button:hover, .end-run-button:focus-visible { background: #f2e6d0; color: #000; outline: none; }
.end-run-button[hidden] { display: none; }
.sound-row { display: flex; align-items: center; justify-content: space-between; gap: 30px; font-size: 30px; width: 100%; }
.sound-row span { min-width: 200px; text-align: left; }
.sound-row input[type=range] { -webkit-appearance: none; appearance: none; width: 260px; height: 14px; margin: 0; background: #1b0f08; border: 2px solid #eece9a; cursor: pointer; }
.sound-row input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 18px; height: 30px; background: #eece9a; border: 2px solid #5a3a33; border-radius: 0; }
.sound-row input[type=range]::-moz-range-thumb { width: 14px; height: 26px; background: #eece9a; border: 2px solid #5a3a33; border-radius: 0; }

/* Hotbar borders: the slot's coloured border sits just inside its container (touching it, not overlapping), under the
   hotkey and the cooldown number. (The darkening for cooldowns uses ::after, so the border uses ::before here.) */
.hotbar-button.tiered { position: absolute; }
.hotbar-button.tiered::after { box-shadow: none; inset: 0; z-index: 2; }
.hotbar-button.tiered::before {
  content: "";
  position: absolute;
  inset: 0;
  box-shadow: inset 0 0 0 3px var(--tier);
  pointer-events: none;
  z-index: 1;
}
.hotbar-button.dark::after { z-index: 2; }
.hotbar-button .hotbar-key, .hotbar-button .hotbar-cd, .hotbar-button .hotbar-name { z-index: 3; }

/* ---------- Settings and Encyclopedia buttons (top right) ---------- */
.top-buttons { position: absolute; top: 8px; right: 32px; z-index: 13; display: flex; gap: 10px; }
.top-button { padding: 0; border: none; background: none; cursor: pointer; line-height: 0; }
.top-button img { width: 52px; height: 52px; }
.top-button:hover, .top-button:focus-visible { filter: brightness(1.25); outline: none; }
/* on the battle screen they join the row of inventory / talents / training buttons */
.battle-menu-buttons .top-buttons { position: static; display: contents; }
.battle-menu-buttons .top-button img { width: 65px; height: 65px; }
/* the stage, turn and coin counters sit below them */
.stage-label { top: 60px; }
.gold-display { top: 108px; }
/* (on the battle screen the buttons are in the top left, so its counters keep their old places) */
.battle-world .stage-label { top: 40px; }

/* Encyclopedia */
.ency-box { width: 1120px; max-width: 94%; padding: 24px 32px; gap: 16px; box-sizing: border-box; }
.ency-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 20px; max-height: 480px; overflow-y: auto; width: 100%; }
.ency-entry { display: flex; gap: 14px; align-items: flex-start; padding: 10px 12px; background: #1a0f0d; border: 3px solid #5a362f; }
.ency-picture { width: 72px; height: 72px; object-fit: contain; flex: none; }
.ency-text { display: flex; flex-direction: column; gap: 3px; text-align: left; }
.ency-name { font-size: 26px; color: #eece9a; }
.ency-stats { font-size: 16px; color: #b9a98f; }
.ency-description { font-size: 16px; line-height: 1.25; color: #f2e6d0; }
.ency-drops { font-size: 16px; color: #8fd18f; }
.ency-tabs { display: flex; gap: 12px; }
.ency-tab { font: inherit; font-size: 24px; color: #b9a98f; background: #1a0f0d; border: 3px solid #5a362f; padding: 4px 22px; cursor: pointer; }
.ency-tab.active { color: #eece9a; border-color: #c9a23a; }
.ency-mechanics { display: grid; grid-template-columns: 1fr; gap: 10px 20px; max-height: 480px; overflow-y: auto; width: 100%; text-align: left; }
.ency-mechanics[hidden], .ency-list[hidden] { display: none; }
.ency-section { padding: 10px 14px; background: #1a0f0d; border: 3px solid #5a362f; }
.ency-section h3 { margin: 0 0 4px; font-size: 24px; font-weight: normal; color: #eece9a; }
.ency-section p { margin: 0 0 6px; font-size: 18px; line-height: 1.3; color: #f2e6d0; }
.ency-section strong { font-weight: normal; color: #eece9a; text-shadow: 0.6px 0 0 currentColor, -0.6px 0 0 currentColor; }
.ency-empty { grid-column: 1 / -1; color: #b9a98f; font-size: 20px; padding: 12px; }
.ency-box .close-button { position: static; }
.ency-box .close-button img { width: 64px; height: 64px; }

/* Hotkey hints (the key shown in the corner of a button, like the numbers on the hotbar) */
.top-button[data-hint], .menu-button[data-hint] { position: relative; } /* (the Skip button is already positioned) */
#encounter-screen .gear-slot[data-hint]::before { left: 16%; top: 15%; } /* on the picture's own box, not the frame around it */
[data-hint]::before {
  content: attr(data-hint);
  font-family: "GAME", Georgia, serif;
  position: absolute;
  left: 4px;
  top: 2px;
  font-size: 10px;
  line-height: 1;
  color: #eece9a;
  text-shadow: -1px 0 0 #000, 1px 0 0 #000, 0 -1px 0 #000, 0 1px 0 #000;
  pointer-events: none;
  z-index: 3;
}

/* Execution: Critical Strike text is red and a little bigger */
.float-text.crit.execution-crit { color: #ff3a2e; font-size: 58px; }

/* The Wizard's speech: top left of his encounter, apart from the information text at the bottom */
#wizard-speech {
  display: none; position: absolute; left: 36px; top: 36px; width: 340px; min-height: 120px; box-sizing: border-box;
  padding: 12px 16px; font-size: 26px; line-height: 1.2; color: #f2e6d0; background: #1a0f0d; border: 3px solid #5a3a33;
  pointer-events: none; z-index: 2;
}
body:has(#encounter-screen.active[data-type="wizard"]) #wizard-speech { display: block; }
#wizard-speech .untyped { visibility: hidden; }
