:root {
  color-scheme: dark;
  font-family: "Georgia", "Times New Roman", serif;
  /*font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;*/
  background: #202020;
  color: #ededed;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  --surface: #292929;
  --surface-raised: #363636;
  --border: #505050;
  --muted: #b8b8b8;
  --accent: #f0f0f0;
  --accent-dark: #555555;
  --warning: #e63131;
  --warning-good: #31e631; 
  --new-loot: rgb(242, 229, 113);
  --golden: #5e4a2b;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    linear-gradient(rgb(18 18 18 / 76%), rgb(18 18 18 / 82%)),
    var(--bg-image, url("./art/background.webp")) center / cover fixed,
    #202020;
}

@keyframes splashBlurFadeIn {
  0% {
    opacity: 1;
    filter: blur(12px);
  }
  100% {
    opacity: 1;
    filter: blur(0px);
  }
}

.splash-screen {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: flex;
  align-items: flex-start; /* align to top */
  justify-content: center;
  padding-top: 10vh; /* push down from top */
  background-color: #0f0f0f; /* Make sure this is fully opaque (not transparent) */
  color: #ffffff;
  text-align: center;
  opacity: 1;
  transition: opacity 0.5s ease-out, filter 0.5s ease-out;
  animation: splashBlurFadeIn 1.3s ease-out forwards;
}

.splash-screen.fade-out {
  transition: opacity 1s ease, filter 1s ease;
  opacity: 0;
  filter: blue(8px);
  pointer-events: none;
}

.splash-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.splash-image {
  max-width: 200px;
  height: auto;
  border-radius: 8px;
}

.splash-title {
  font-size: 2.5rem;
  margin: 0;
}

.splash-text {
  font-size: 1.1rem;
  color: #a0a0a0;
  margin: 0;
}

.splash-start-btn {
  margin-top: 20px;
  padding: 10px 24px;
  font-size: 1rem;
  font-weight: bold;
  background-color: #ffffff;
  color: #0f0f0f;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.1s ease;
}

.splash-start-btn:hover {
  background-color: #d0d0d0;
  transform: scale(1.05);
}

.splash-progress-bar {
  width: 240px;
  height: 4px;
  background-color: #2a2a2a;
  border-radius: 2px;
  overflow: hidden;
  margin-top: 12px;
}

.splash-progress-fill {
  width: 100%;
  height: 100%;
  background-color: #ffffff;
  transform-origin: left;
  transform: scaleX(1);
}

button,
select {
  font: inherit;
}

.page {
  width: min(1120px, calc(100% - 36px));
  margin: 0 auto;
  padding: 8px 0 24px;
}

.page-header,
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.page-header {
  align-items: flex-end;
  margin-bottom: 12px;
}

.header-actions {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
}

.eyebrow,
.summary-label {
  margin: 0 0 7px;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 1000;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

p {
  margin-top: 0;
}

h1,
h2,
h3 {
  margin-top: 0;
  font-family: Garamond, Georgia, serif;
  
  font-variant-caps: small-caps;
  font-synthesis: style weight small-caps;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2.4rem, 6vw, 4rem);
  letter-spacing: -0.06em;
  line-height: 1;

  text-shadow: 0 0 15px rgba(255, 140, 60, 0.4), 0 0 30px rgba(255, 120, 40, 0.2); /* orange glow */

  /* Creates a dotted line centered vertically across the entire width of the h1 */
  background: linear-gradient(to right, #ccc 50%, transparent 50%);
  background-size: 13px 1px; /* Controls dot spacing (12px) and dot thickness (2px) */
  background-repeat: repeat-x;
  background-position: center calc(50% + 4px); /* shifted slightly down */
}

/* Adds a solid background box directly behind the text characters so the dots don't cross through the letters */
h1 span {
  background-color: #121212; /* Change this to match your exact page/container background color */
  padding: 0 10px; /* Adjust spacing around the text */
}

h2 {
  margin-bottom: 0;
  font-size: 1.4rem;
}

h3 {
  margin-bottom: 5px;
  font-size: 1.1rem;
}

.status {
  margin: 0;
  color: var(--muted);
  line-height: 20px;
}

.status-panel {
  display: flex;
  min-height: 36px;
  align-items: center;
  margin-bottom: 12px;
  padding: 8px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 12px 0 0;
}

.game-end-dialog {
  max-width: 420px;
  width: 90vw;
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 12px;
  color: inherit;
  box-shadow: 0 18px 45px rgb(0 0 0 / 45%);
  text-align: center;
  
  /* Explicitly separate layers so the browser can load them reliably */
  background-color: #0f0f0f;
  /*background-image: linear-gradient(rgba(0,0,0, 0.75), rgba(0,0,0, 0.75)), url("./art/ending.webp");*/
  background-image: radial-gradient(circle, rgba(0, 0, 0, 0.2) 0%, rgba(0, 0, 0, 0.9) 80%), url("./art/ending.webp");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.game-end-dialog::backdrop {
  background: rgb(0 0 0 / 65%);
}

.game-end-dialog p,
.game-end-dialog h2 {
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.9), 0 0 8px rgba(0, 0, 0, 0.8);
}

.game-end-actions {
  display: flex !important;
  flex-direction: column !important;
  gap: 12px !important;
  margin-top: 16px !important;
  width: 100% !important;
}

.game-end-btn-wrapper {
  width: 100% !important;
  display: block !important;
}

.game-end-actions .button {
  width: 100% !important;
  white-space: normal !important;
  text-align: center !important;
  padding: 12px 16px !important;
}

.panel.player-stats-panel {
  margin-bottom: 12px;
  padding: 8px;
  background: #050505;
}

.player-stats-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.player-stats-heading h2,
#bag-panel > .section-heading h2,
#gear-panel > .section-heading h2 {
  margin: 0;
  font-size: 1.2rem;
  line-height: 1.2;
}

#player-stats-details {
  display: block;
  width: 100%;
}

.player-bars-container {
  flex: 1;
  min-width: 0;
}

.player-stats-icon-container {
  position: relative;
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
}

/* 4 horizontal hash lines passing behind the icon, extending a few px past the vertical lines */
.player-stats-icon-container::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: -4px;  /* extends a few px beyond the left vertical line */
  right: -240px; /* extends a few px beyond the right vertical line */
  background: linear-gradient(
    to bottom,
    transparent 8px,
    var(--surface) 8px, var(--surface) 9px,   /* 1st line (approx 15% down) */
    transparent 9px,
    transparent 21px,
    var(--surface) 21px, var(--surface) 22px, /* 2nd line (center-top) */
    transparent 22px,
    transparent 26px,
    var(--surface) 26px, var(--surface) 27px, /* 3rd line (center-bottom) */
    transparent 27px,
    transparent 40px,
    var(--surface) 40px, var(--surface) 41px, /* 4th line (approx 15% from bottom) */
    transparent 41px
  );
  z-index: 0;
}

/* Vertical hash marks to either side */
.player-stats-icon-container::after {
  content: "";
  position: absolute;
  top: -2px;
  bottom: -2px;
  left: -3px;
  right: -3px;
  border-left: 2px solid var(--surface);
  border-right: 2px solid var(--surface);
  pointer-events: none;
  z-index: 2;
}

/* Ensure the icon images sit above the background hash lines */
.player-stats-icon-container img {
  z-index: 1;
}

.player-stats-icon {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.overlay-icon {
  z-index: 1; /* Ensures hum0.webp sits directly on top of humanity-ring.webp */
  position: absolute;
  inset: 0;
  margin: auto;
  width: 98%;
  height: 98%;
  object-fit: contain;
  transform: /*translateX(1px)*/ translateY(-5px);
}

.bag-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-collapse-toggle {
  flex: 0 0 28px;
}

.player-stats-toggle {
  width: 28px;
  min-height: 28px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
}

.player-stats-toggle:hover:not(:disabled) {
  background: transparent;
  color: #fff;
}

.player-stats-compact {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  padding-top: 12px;
  font-family: "Georgia", "Times New Roman", serif;
}

.player-stats-compact span {
  min-width: 0;
  text-align: center;
}

#compact-player-level,
#compact-player-hp,
#compact-player-max-hp,
#compact-player-armor,
#compact-player-damage,
#compact-player-stamina {
  font-family: Garamond, Georgia, serif;
}

#compact-player-hp.is-low-hp {
  color: #ff8080;
}

/* --- PLAYER BARS STYLING --- */
.player-bars-container .meter {
  border-radius: 1 !important;
  border: 1px solid #111;
  background: repeating-linear-gradient(
    90deg,
    transparent,
    transparent 24px,
    rgba(0, 0, 0, 0.6) 24px,
    rgba(0, 0, 0, 0.6) 25px
  ), #333 !important;
}

/* HP fill color */
#player-hp-meter {
  background: repeating-linear-gradient(
    90deg,
    transparent,
    transparent 24px,
    rgba(0, 0, 0, 0.6) 24px,
    rgba(0, 0, 0, 0.6) 25px
  ), #a80000 !important;
}

/* Stamina fill color */
#player-stamina-meter {
  background: repeating-linear-gradient(
    90deg,
    transparent,
    transparent 24px,
    rgba(0, 0, 0, 0.6) 24px,
    rgba(0, 0, 0, 0.6) 25px
  ), #38761d !important;
}

.panel.monster-panel,
.panel.gear-panel,
.panel.bag-panel {
  padding: 8px;
  background: #050505;
}

.panel.prepare-monster {
  margin-bottom: 12px;
  padding: 8px;
  background: #000;
}

.prepare-monster h2 {
  font-size: 1rem;
}

.prepare-monster .monster-meter {
  margin: 8px 0 0;
}

.player-stats-panel > h2 {
  font-size: 1rem;
}

.panel.shop-panel {
  margin-bottom: 12px;
  padding: 8px;
  background: #050505;
}

.shop-header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.shop-refresh-button {
  margin-bottom: 12px;
}

.bag-shop-note {
  margin: 12px 0 0;
  font-style: italic;
}

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

/* Apply container-type only to main item containers that stretch horizontally */
.list-item.loot-item,
.gear-item,
.panel.shop-item {
  container-type: inline-size;
}

.panel.shop-item {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
  background: var(--surface-raised);
}

.shop-item-details {
  flex: 1 1 auto;
  min-width: 0;
}

.shop-item-details h3 {
  overflow-wrap: anywhere;
}

.shop-owned-count {
  color: #aaa;
  font-size: 0.72em;
  font-weight: 400;
}

.shop-item-details p {
  margin: 0;
}

.shop-item-actions {
  display: grid;
  flex: 0 0 auto;
  justify-items: end;
  gap: 8px;
}
.panel.player-stats-pan
.shop-price,
.bag-sale-value {
  font-family: "Georgia", "Times New Roman", serif;
  /*font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;*/
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--accent);
  white-space: nowrap;
}

.panel {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgb(41 41 41 / 95%);
  box-shadow: 0 18px 45px rgb(0 0 0 / 34%);
}

.panel.player-stats-panel {
  border: 1px solid var(--golden);
  outline: 1px solid var(--golden);
  outline-offset: -3px;
  border-radius: 12px;
  background: rgb(13 12 10 / 1.0); /* X% opacity version of #0d0c0a */
  box-shadow: 0 4px 20px rgb(0 0 0 / 25%);
}
.panel.monster-panel,
.panel.gear-panel,
.panel.bag-panel,
.panel.prepare-monster,
.panel.shop-panel {
  border: 1px solid var(--golden);
  outline: 1px solid var(--golden);
  outline-offset: -3px;
  border-radius: 12px;
  background: #0d0c0a;
  box-shadow: 0 4px 20px rgb(0 0 0 / 25%);
}

/* Dark Souls Item Description Dialog Styling */
#confirm-dialog.item-description-dialog {
  border: 1px solid var(--golden);
  background-color: #0c0a08;
  color: #c0b8aa;
  font-family: "Georgia", "Times New Roman", serif;
  padding: 18px 24px;
  max-width: 360px;
  box-shadow: 0 0 15px rgba(0, 0, 0, 0.9);
}

#confirm-dialog.item-description-dialog h2 {
  font-size: 1.25rem;
  font-weight: normal;
  color: #dcd3c1;
  margin: 0 0 8px 0;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--golden);
}

/* Ruled lines behind justified description text */
.item-desc-body {
  text-align: justify;
  font-size: 0.95rem;
  line-height: 1.8rem; /* Matches the background repeating line height */
  color: #b8b0a0;
  background-image: repeating-linear-gradient(
    to bottom,
    transparent,
    transparent calc(1.8rem - 1px),
    var(--golden) calc(1.8rem - 1px),
    var(--golden) 1.8rem
  );
  background-position: 0 0px;
  padding: 0;
  margin: 0;
}

/* Header metadata section (Weapon type, Attack type, etc.) */
.item-desc-header {
  font-size: 1.2rem;
  line-height: 1.8rem;
  color: #a09888;
  /*background-image: repeating-linear-gradient(
    to bottom,
    transparent,
    transparent calc(2rem - 1px),
    var(--golden) calc(2rem - 1px),
    var(--golden) 2rem
  );*/
  margin-bottom: 0;
}

.summary-card {
  display: flex;
  min-height: 104px;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  padding: 13px 17px;
}

.summary-value {
  margin-bottom: 4px;
  font-size: 1.0rem;
  line-height: 1;
}

.summary-card .muted {
  font-size: 0.76rem;
}

.stat-divider {
  color: var(--muted);
  font-size: 1.1rem;
}

.muted {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.5;
}

.meter {
  width: 100%;
  height: 8px;
  overflow: hidden;
  border-radius: 99px;
  background: #171717;
}

.meter span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 180ms ease-out;
}

.summary-card .meter {
  margin: 5px 0 8px;
}

.inventory-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  align-items: stretch;
  gap: 14px;
}

.inventory-grid.is-swapped #bag-panel {
  order: -1;
}

.inventory-grid.is-shop {
  grid-template-columns: minmax(0, 1fr);
}

.inventory-grid.is-shop #bag-panel {
  order: -1;
}

/* Container for shop sale actions */
.list-item.loot-item .bag-sale-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 0;
}

/* Base styles for non-shop views */
.bag-sale-stacked {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-content: center;
  gap: 4px;
  min-width: 0;
  max-width: 100%;
}

/* --- SHOP OVERRIDES --- */

/* 1. Turn shop loot cards into a 2-row grid */
.inventory-grid.is-shop .list-item.loot-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  grid-template-rows: auto auto;
  align-items: center;
  gap: 4px 10px;
}

/* 2. Text details on the left span both rows */
.inventory-grid.is-shop .list-item.loot-item .skill-copy,
.inventory-grid.is-shop .list-item.loot-item .item-details {
  grid-column: 1;
  grid-row: 1 / span 2;
  min-width: 0;
}

/* 3. Unwrap action containers so children map directly to the grid */
.inventory-grid.is-shop .list-item.loot-item .bag-sale-actions,
.inventory-grid.is-shop .list-item.loot-item .bag-sale-stacked {
  display: contents;
}

/* 4. Top row: Value text aligned right over columns 2 and 3 */
.inventory-grid.is-shop .list-item.loot-item .bag-sale-value {
  grid-column: 2 / span 2;
  grid-row: 1;
  justify-self: end;
}

/* 5. Bottom row: x1 badge in column 2 */
.inventory-grid.is-shop .list-item.loot-item .badge {
  grid-column: 2;
  grid-row: 2;
  justify-self: end;
}

/* 6. Bottom row: Sell button in column 3 */
.inventory-grid.is-shop .list-item.loot-item .button {
  grid-column: 3;
  grid-row: 2;
  justify-self: end;
}

.setting-option {
  display: flex;
  width: fit-content;
  align-items: center;
  gap: 10px;
  margin-top: 18px;
  cursor: pointer;
}

.setting-option input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  gap: 16px;
  margin-top: 12px;
}

.setting-item {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.game-speed-setting {
  display: grid;
  max-width: 360px;
  gap: 8px;
  margin-top: 20px;
}

.game-speed-setting label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.game-speed-setting input {
  width: 100%;
  accent-color: var(--accent);
}

.game-speed-labels {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.82rem;
}

.secondary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
  gap: 14px;
  margin-top: 14px;
}

.combat-panel,
.skills-panel,
.loot-panel {
  min-height: 0;
  padding-block: 4px;
  padding-inline: 4px;
}

.monster-panel {
  margin-bottom: 12px;
}

.loot-check-debug {
  margin-top: 12px;
  font-size: 0.78rem;
}

.quick-items-section hr {
  margin: 12px 0;
  border: 0;
  border-top: 1px solid var(--border);
}

.quick-items-list {
  display: flex;
  gap: 8px;
  overflow-x: auto;
}

.quick-item-button {
  flex: 0 0 110px;
  width: 88px;
  min-height: 40px;
  font-size: 0.6rem;
  overflow-wrap: anywhere;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  line-height: 1.0;
  text-align: center;
}

.quick-item-button.quick-item-flash {
  box-shadow: inset 0 0 0 2px #ffd400;
}

.quick-item-name {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.quick-item-count {
  white-space: nowrap;
}

#monster-reward {
  white-space: pre-line;
  font-size: 0.72rem;
  min-height: 4.5em;
}

.monster-select-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.monster-select-row label {
  flex: 0 0 auto;
  margin: 0;
}

.monster-select-row select {
  min-width: 0;
  flex: 1;
  color: #ffaa00;
}

.monster-card-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.monster-card-heading h3 {
  margin-bottom: 0;
}

.boss-killed-card {
  display: grid;
  gap: 8px;
  text-align: center;
}

.boss-killed-heading {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 12px;
}

.boss-killed-card h3,
.boss-killed-name,
.boss-killed-reward {
  margin: 0;
}

#boss-killed-reward {
  white-space: pre-line;
}

.boss-material-title {
  color: rgb(255, 250, 200); /* Light yellow accent */
}

.boss-shop-hint {
  display: inline-block;
  width: fit-content;
  justify-self: center;
  text-align: center;
  margin: 0;
  padding: 6px 10px;
  background:
    radial-gradient(circle, #fff176 1px, transparent 1.5px) left top / 8px 3px repeat-x,
    radial-gradient(circle, #fff176 1px, transparent 1.5px) left bottom / 8px 3px repeat-x,
    radial-gradient(circle, #fff176 1px, transparent 1.5px) left top / 3px 8px repeat-y,
    radial-gradient(circle, #fff176 1px, transparent 1.5px) right top / 3px 8px repeat-y;
  animation: shop-hint-marquee 1.6s linear infinite;
}

.boss-shop-hint[hidden] {
  display: none;
}

@keyframes shop-hint-marquee {
  to {
    background-position:
      left 8px top 0,
      left -8px bottom 0,
      left 0 top -8px,
      right 0 top 8px;
  }
}

.boss-killed-card h3 {
  color: #fff176;
  text-align: center;
}

.boss-killed-name {
  font-size: 1.15rem;
  font-weight: 700;
}

.monster-card-heading .badge {
  flex: 0 0 auto;
}

.gear-currency-count {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.84rem;
}

.gear-currency-count strong {
  margin-left: 4px;
  color: var(--accent);
}

.inline-stat {
  display: inline-flex;
  min-width: 28px;
  height: 28px;
  align-items: center;
  justify-content: center;
  margin-left: 5px;
  padding: 0 7px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  vertical-align: middle;
}

.game-over-panel {
  max-width: 680px;
  margin: 24px auto;
  padding: 8px;
  text-align: center;
}

.game-over-panel h2 {
  margin-bottom: 12px;
  font-size: 3rem;
  color: red;
}

#game-over-stats {
  white-space: pre-line;
}

.revive-prompt {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.revive-prompt p {
  color: var(--muted);
  white-space: pre-line;
}

.section-heading {
  margin-bottom: 20px;
}

label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 650;
}

select {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-raised);
  color: inherit;
}

option.boss-defeated {
  text-decoration: line-through;
}

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

.custom-dropdown {
  position: relative;
  flex: 1;
  min-width: 0;
}

.custom-dropdown .dropdown-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-raised);
  color: inherit;
  cursor: pointer;
}

.custom-dropdown .dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 10;
  max-height: 240px;
  overflow-y: auto;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 8px 24px rgb(0 0 0 / 40%);
}

.custom-dropdown .dropdown-item {
  padding: 10px 12px;
  border-radius: 6px;
  cursor: pointer;
}

.custom-dropdown .dropdown-item.is-italic {
  font-style: italic;
}

.custom-dropdown .dropdown-item.is-selected {
  color: #ffb074; /* Light orange color for the selected item */
  /*font-weight: bold; /* Optional: make it stand out */
}

.custom-dropdown .dropdown-item:hover:not(.is-disabled) {
  background: var(--surface-raised);
  color: var(--accent);
}

.custom-dropdown .dropdown-item.boss-item {
  font-weight: bold;
}

/* This now works reliably on custom div elements! */
.custom-dropdown .dropdown-item.boss-defeated {
  text-decoration: line-through;
  color: #777;
}

.custom-dropdown .dropdown-item.is-disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.custom-dropdown .dropdown-menu[hidden] {
  display: none !important;
}

.monster-card {
  margin-top: 8px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: linear-gradient(135deg, #3b3b3b, #292929);
}

.badge {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  justify-content: center;
  padding: 3px 9px;
  border-radius: 99px;
  background: #484848;
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 750;
  white-space: nowrap;
}

.badge-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.badge-max {
  font-size: 0.68rem;
  white-space: nowrap;
}

.monster-card h3 {
  margin-top: 9px;
  font-size: 1.35rem;
}

.monster-meter {
  position: relative;
  height: 24px;
  margin: 12px 0;
}

.monster-meter #monster-health-meter {
  background: var(--warning);
}

.monster-health-label {
  position: absolute;
  z-index: 1;
  inset: 0;
  display: flex !important;
  width: 100% !important;
  height: 100% !important;
  align-items: center;
  justify-content: center;
  border-radius: inherit;
  background: transparent !important;
  color: white;
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1;
  text-shadow: 0 1px 3px #000;
}

.combat-note {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.55;
}

.item-list {
  display: grid;
  gap: 10px;
}

.bag-tabs,
.combat-tabs {
  display: flex;
  gap: 4px;
  margin: -4px 0 12px;
  border-bottom: 1px solid var(--border);
}

.bag-tab {
  position: relative;
  flex: 1 1 0; /* Makes each tab take equal 25% width */
  min-height: 38px;
  padding: 7px 4px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: #101010; /* Near-black background for unselected state */
  color: var(--muted);
  font: inherit;
  text-align: center;
  cursor: pointer;
}

.bag-tab[aria-selected="true"] {
  background: var(--surface-raised);
  color: var(--accent);
}

.tab-indicator {
  position: absolute;
  top: 2px;
  right: 6px;
  color: var(--new-loot);
  font-size: 0.9rem;
  font-weight: bold;
  line-height: 1;
}

.combat-tabs {
  gap: 0;
  margin: 0 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.combat-tab {
  min-height: 38px;
  padding: 7px 12px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
}

.combat-tab {
  flex: 1 1 0;
  background: #383838;
}

.combat-tab + .combat-tab {
  border-left: 1px solid var(--border);
}

.bag-tab[aria-selected="true"] {
  background: var(--surface-raised);
  color: var(--accent);
}

.combat-tab[aria-selected="true"] {
  background: #bdbdbd;
  color: #202020;
}

.combat-tab:disabled,
.combat-tab[aria-disabled="true"] {
  background: #242424;
  color: #666;
  cursor: not-allowed;
  opacity: 0.7;
}

.shop-locked-tooltip {
  margin: -4px 0 12px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-raised);
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

.bag-tab:focus-visible,
.combat-tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-raised);
}

.list-item.loot-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 30px 70px; /* 1st column takes remaining space, 2nd column holds the badge at a fixed width, 3rd holds the button */
  align-items: center;
  gap: 12px;
}

.list-item.loot-item .button {
  width: 100%; /* Fills the fixed column width */
  text-align: center;
  padding-left: 3px;
  padding-right: 3px;
}

/* Ensure elements inside the grid don't break layout */
.list-item.loot-item .skill-copy {
  min-width: 0;
}

.list-item.loot-item .badge {
  justify-self: center;
}

.loot-item .skill-copy > h3 {
  margin-bottom: 0;
  line-height: 1.2;
}

.loot-item .skill-copy > p.item-description,
.gear-equipped-item .item-description {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.35;
}

.item-details {
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
}

#bag-items-list,
#bag-weapons-list,
#bag-armor-list,
#bag-materials-list {
  max-height: 530px;
  /*max-height: calc(100vh - 240px);*/
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 4px;
}

.cheat-loot-item {
  width: 100%;
  flex-direction: column;
  align-items: flex-start;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.cheat-loot-item:hover {
  border-color: var(--accent);
}

.cheat-loot-list {
  margin-top: 14px;
}

.crafted-loot-item {
  width: 100%;
  flex-direction: column;
  align-items: flex-start;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.crafted-loot-item .item-description {
  font-size: 0.78rem;
  line-height: 1.35;
}

.crafted-loot-item:hover {
  border-color: var(--accent);
}

.crafted-loot-item:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.upgrade-dialog {
  height: 80vh;
  height: 80dvh;              /* better on mobile browsers; falls back to vh */
  max-height: 80dvh;
  flex-direction: column;
}

/* only apply flex when open, so a closed dialog stays hidden */
.upgrade-dialog[open] {
  display: flex;
}

.upgrade-dialog #craft-options-list {
  flex: 1 1 auto;
  max-height: none !important;  /* overrides the inline 200px */
  min-height: 0;
  overflow-y: auto;
}

.upgrade-dialog .sell-confirm-actions {
  flex: 0 0 auto;
}

.loot-item.is-new-loot {
  border-color: var(--new-loot);
  box-shadow: 0 0 0 1px var(--new-loot);
}

.bag-sale-value {
  min-width: 0; /* Remove fixed min-width ch constraint that causes overflow */
  max-width: 100%;
  color: var(--accent);
  font-size: 0.82rem;
  text-align: right;
  white-space: nowrap;
}

.gear-item {
  display: grid;
  grid-template-columns: minmax(72px, 0.65fr) minmax(0, 1.35fr) auto;
  align-items: center;
  gap: 10px;
}

.gear-item.is-disabled {
  opacity: 0.55;
}

.gear-slot {
  font-size: 0.82rem;
  color: var(--accent);
}

.gear-equipped-item {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.gear-equipped-item .item-title {
  margin: 0;
  font-weight: 550;
}

.gear-equipped-item .item-description {
  overflow-wrap: anywhere;
}

.skill-copy,
.gear-equipped-item,
.shop-item-details {
  container-type: inline-size;
}

.item-title {
  margin-bottom: 3px;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  font-size: clamp(0.8rem, 8cqw, 1rem); /* scale to fit on line */
}

.loot-rarity.rarity-trash {
  color: #777;
}

.loot-rarity.rarity-common {
  color: #fff;
}

.loot-rarity.rarity-uncommon {
  color: rgb(60, 210, 97);
}

.loot-rarity.rarity-rare {
  color: rgb(69, 140, 255);
}

.loot-rarity.rarity-epic {
  color: rgb(176, 91, 255);
}

.loot-rarity.rarity-legendary {
  color: rgb(255, 140, 58);
}

.loot-rarity.rarity-mythic {
  border-radius: 3px;
  /*background: #fff;*/
  color: rgb(239, 37, 81);
}

.sell-confirm-dialog {
  width: min(420px, calc(100% - 32px));
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: inherit;
  box-shadow: 0 18px 45px rgb(0 0 0 / 45%);
}

.sell-confirm-dialog::backdrop {
  background: rgb(0 0 0 / 65%);
}

.sell-confirm-dialog h2 {
  margin-bottom: 14px;
}

.sell-confirm-dialog p {
  line-height: 1.6;
}

.sell-confirm-actions {
  display: grid;
  justify-items: center;
  gap: 8px;
  margin: 0;
}

.sell-confirm-actions .button {
  min-width: 120px;
}

.quantity-selector-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 16px 0;
}

.quantity-input {
  width: 70px;
  height: 38px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-raised);
  color: var(--accent);
  font: inherit;
  text-align: center;
}

/* Hide native number input spinners for cleaner custom look if desired */
.quantity-input::-webkit-outer-spin-button,
.quantity-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.sell-qty-total-price {
  text-align: center;
  margin-bottom: 16px;
}

.soul-quantity-dialog {
  text-align: center;
}

.sell-qty-header h2 {
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.quantity-selector-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 16px 0;
}

.qty-arrow-btn {
  background: transparent;
  border: none;
  color: var(--accent);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 12px;
}

.qty-arrow-btn:hover {
  color: #fff;
}

.quantity-input-stepper {
  width: 60px;
  background: transparent;
  border: none;
  color: #fff;
  font-family: Garamond, Georgia, serif;
  font-size: 1.5rem;
  text-align: center;
}

.quantity-input-stepper:focus {
  outline: none;
}

.quantity-input-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 2px 0;
}

.quantity-selector-container-stacked {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
}

.qty-number-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.qty-all-row {
  display: flex;
  justify-content: center;
}

.qty-all-btn,
.wide-action-btn {
  /* Takes 28% of the viewport width, but stays between 110px and 200px */
  width: clamp(110px, 28vw, 200px);
}

.horizontal-actions {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 16px;
}

.horizontal-actions .button {
  min-width: 100px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.item-description {
  max-width: 38ch;
  white-space: pre-line;
}

.item-level {
  margin: 7px 0 0;
  color: var(--accent);
  font-size: 0.77rem;
  font-weight: 650;
}

.button {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 8px 12px;
  border: 1 solid var(--golden);
  border-radius: 8px;
  background: var(--accent-dark);
  color: white;
  font-weight: 550;
  cursor: pointer;
}

.list-item .button,
.shop-item .button {
  font-size: 0.78rem;
  min-height: 30px;
  padding: 4px 8px;
}

.button:hover:not(:disabled) {
  background: #696969;
}

.button:disabled {
  background: #414141;
  color: #a2a2a2;
  cursor: not-allowed;
}

.reset-button {
  border: 1px solid #666;
  background: #454545;
}

.reset-button:hover:not(:disabled) {
  background: #646464;
}

.menu-toggle {
  display: inline-flex;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-raised);
  cursor: pointer;
}

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

.menu-toggle span {
  width: 18px;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
}

.ngplus-btn {
  display: flex;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-raised);
  color: #ffd24a;
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.ngplus-btn:hover {
  border-color: #ffd24a;
}

.site-menu {
  position: absolute;
  z-index: 2;
  top: calc(100% + 8px);
  right: 0;
  display: grid;
  min-width: 160px;
  gap: 4px;
  padding: 7px;
}

.menu-item {
  padding: 10px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.menu-item:hover {
  background: var(--surface-raised);
  color: var(--accent);
}

.content-page {
  max-width: 760px;
  margin: 0 auto;
  padding: 8px;
}

.content-page .section-heading {
  align-items: flex-start;
}

.content-page .section-heading > .button {
  flex: 0 0 auto;
  margin-left: auto;
}

.content-page .muted {
  margin: 14px 0;
}

.restore-key {
  display: block;
  width: 100%;
  min-height: 100px;
  resize: vertical;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #171717;
  color: var(--accent);
  font: 0.8rem/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
  overflow-wrap: anywhere;
}

.profile-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 12px;
}

.restore-instructions {
  margin-top: 20px !important;
}

.restore-instructions code {
  color: var(--accent);
}

.help-copy p {
  margin-bottom: 14px;
  color: var(--muted);
  line-height: 1.65;
}

.content-page h2:focus {
  outline: none;
}

.skill-item .badge,
.loot-item .badge {
  flex: 0 0 auto;
}

.skill-item.locked {
  opacity: 0.68;
}

.skill-copy {
  min-width: 0;
}

.empty-state {
  padding: 12px 2px;
}

footer {
  padding: 18px 2px 0;
  text-align: center;
}

footer p {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.error-panel {
  max-width: 720px;
  margin: 0 auto;
  padding: 26px;
  border-color: #666;
}

.error-panel h2 {
  margin-bottom: 10px;
}

.error-panel p {
  color: var(--muted);
  line-height: 1.6;
}

.button.secondary {
  background: #484848;
}

.button.player-stats-toggle,
.button.player-stats-toggle:hover:not(:disabled) {
  background: transparent;
}

/* Hide spacer line by default (narrow/mobile screens) */
.gear-spacer-hr {
  display: none;
}

/* Show spacer line on wide screens to align with Bag tabs */
@media (min-width: 741px) {
  .gear-spacer-hr {
    display: block;
    height: 38px; /* Height of the bag tabs */
    margin: -4px 0 12px;
    border: 0;
    border-bottom: 1px solid var(--border);
  }
}

@media (max-width: 740px) {
  .page {
    width: min(100% - 24px, 560px);
    padding-top: 8px;
  }

  .page-header {
    align-items: center;
    flex-wrap: nowrap;
    gap: 12px;
  }

  .header-actions {
    width: auto;
    flex: 0 1 auto;
  }

  .content-page {
    padding: 8px;
  }

  .content-page .section-heading {
    align-items: flex-start;
    flex-direction: row;
    gap: 12px;
  }

  .profile-actions {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .summary-card {
    min-width: 0;
    min-height: 96px;
    padding: 10px 8px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
  }

  /* .summary-card > .muted:last-child {
    margin-top: auto;
  } */

  .summary-label {
    font-size: 0.72rem;
  }

  .summary-value {
    /* margin-bottom: 0;
    line-name: 1; */
    font-size: clamp(1rem, 4.4vw, 1.4rem);
  }

  #player-level,
  #player-hp,
  #player-max-hp,
  #player-armor,
  #player-damage,
  #player-stamina,
  #player-max-stamina {
    font-size: 0.82rem !important;
    font-family: Garamond, Georgia, serif !important;
  }

  .player-hp-track {
    position: relative; /* ensures absolute children stay inside the track */
    overflow: hidden;   /* clips the pattern so it stays rounded inside the bar */
  }

  .hp-missing-bar {
    position: absolute;
    top: 0;
    height: 100%;
    background: repeating-linear-gradient(
      45deg,
      rgba(255, 255, 255, 0.15),
      rgba(255, 255, 255, 0.15) 2px,
      rgba(0, 0, 0, 0.3) 2px,
      rgba(0, 0, 0, 0.3) 4px
    );
    pointer-events: none;
  }

  .damage-breakdown-list {
    display: flex;
    flex-direction: column;
    gap: 1px;
    font-size: 0.88rem;
    font-family: Garamond, Georgia, serif !important;
    line-height: 1.25;
    color: inherit;
    margin: 2px 0 4px 0;
  }

  .damage-resisted {
    color: var(--warning);
    font-style: italic;
  }

  .summary-card .muted {
    font-size: 0.62rem;
    line-height: 1.3;
  }

  .inventory-grid,
  .secondary-grid {
    grid-template-columns: 1fr;
  }

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

  .shop-full {
    color: var(--muted);
  }

  .combat-panel,
  .skills-panel,
  .loot-panel {
    padding: 18px;
  }

  .gear-item {
    grid-template-columns: minmax(50px, 0.5fr) minmax(0, 1.5fr) auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .boss-shop-hint {
    animation: none;
  }

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
