#dice-box.dnd-dice-box {
  position: absolute !important;
  z-index: 2147483000;

  display: block;

  padding: 0;
  margin: 0;

  overflow: hidden;

  opacity: 0;
  visibility: hidden;
  pointer-events: none;

  background:
    radial-gradient(
      circle at 50% 45%,
      rgba(255, 234, 177, 0.05),
      rgba(31, 13, 8, 0.16) 55%,
      rgba(12, 5, 3, 0.42)
    );

  backdrop-filter: blur(1px);

  box-sizing: border-box;

  transition:
    opacity 250ms ease,
    visibility 0s linear 250ms;
}

#dice-box.dnd-dice-box.is-active {
  opacity: 1;
  visibility: visible;
  pointer-events: none;

  transition:
    opacity 250ms ease,
    visibility 0s linear 0s;
}

#dice-box.dnd-dice-box.is-leaving,
#dice-box.dnd-dice-box.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/*
 * Dice Box may add an internal wrapper around its canvas.
 * Force every layer to use the whole viewport.
 */
#dice-box.dnd-dice-box > div {
  position: absolute !important;
  inset: 0 !important;

  width: 100% !important;
  height: 100% !important;
}

#dice-box.dnd-dice-box canvas,
#dnd-dice-canvas {
  position: absolute !important;
  inset: 0 !important;

  display: block !important;
  width: 100% !important;
  height: 100% !important;

  max-width: none !important;
  max-height: none !important;

  padding: 0 !important;
  margin: 0 !important;

  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  #dice-box.dnd-dice-box {
    display: none;
  }
}

body.dnd-roll-active .site-header {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

body.dnd-roll-active {
  overflow: hidden;
}

.dice-theme-picker {
  position: relative;
  z-index: 500;
}

.dice-theme-picker__toggle {
  appearance: none;

  display: inline-flex;
  align-items: center;
  gap: 0.45rem;

  padding: 0.45rem 0;

  border: 1px solid rgba(183, 138, 63, 0.45);
  border-radius: 2px;

  background:
    linear-gradient(
      180deg,
      rgba(50, 24, 16, 0.96),
      rgba(24, 10, 7, 0.98)
    );

  box-shadow:
    inset 0 0 12px rgba(255, 220, 150, 0.05),
    0 3px 10px rgba(0, 0, 0, 0.25);

  color: #f0d8a2;

  cursor: pointer;

  font-family: "Cinzel", serif;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.045em;

  transition:
    border-color 150ms ease,
    background-color 150ms ease,
    transform 150ms ease;
}

.dice-theme-picker__toggle:hover {
  transform: translateY(-1px);
  border-color: rgba(220, 174, 91, 0.8);
}

.dice-theme-picker__toggle:focus-visible {
  outline: 3px solid rgba(183, 138, 63, 0.45);
  outline-offset: 2px;
}

.dice-theme-picker__die {
  display: grid;
  width: 1.55rem;
  height: 1.55rem;
  flex: 0 0 1.55rem;
  place-items: center;

  border: 1px solid rgba(218, 167, 84, 0.4);
  border-radius: 50%;

  background: rgba(140, 29, 24, 0.25);

  font-size: 0.83rem;
}

.dice-theme-picker__label {
  color: rgba(240, 216, 162, 0.7);
  text-transform: uppercase;
}

.dice-theme-picker__current {
  max-width: 10rem;

  overflow: hidden;

  color: #f5e4bc;

  text-overflow: ellipsis;
  white-space: nowrap;
}

.dice-theme-picker__chevron {
  margin-left: 0.15rem;

  transition: transform 150ms ease;
}

.dice-theme-picker__toggle[aria-expanded="true"]
.dice-theme-picker__chevron {
  transform: rotate(180deg);
}

.dice-theme-picker__menu {
  position: absolute;
  top: calc(100% + 0.45rem);
  right: 0;

  width: min(21rem, calc(100vw - 1.5rem));

  padding: 0.45rem;

  border: 1px solid rgba(183, 138, 63, 0.45);
  border-top: 3px solid #8c1d18;
  border-radius: 2px;

  background:
    linear-gradient(
      180deg,
      rgba(242, 224, 181, 0.99),
      rgba(228, 200, 141, 0.99)
    );

  box-shadow:
    0 18px 45px rgba(0, 0, 0, 0.45),
    inset 0 0 22px rgba(93, 53, 20, 0.06);
}

.dice-theme-picker__menu[hidden] {
  display: none;
}

.dice-theme-option {
  appearance: none;

  display: grid;
  width: 100%;
  grid-template-columns: 3rem minmax(0, 1fr);
  align-items: center;
  gap: 0.75rem;

  padding: 0.65rem;

  border: 1px solid transparent;
  border-radius: 2px;

  background: transparent;
  color: #2c1b12;

  cursor: pointer;
  text-align: left;

  transition:
    border-color 140ms ease,
    background-color 140ms ease,
    transform 140ms ease;
}

.dice-theme-option + .dice-theme-option {
  margin-top: 0.2rem;
}

.dice-theme-option:hover {
  transform: translateX(2px);

  border-color: rgba(140, 29, 24, 0.23);
  background: rgba(140, 29, 24, 0.06);
}

.dice-theme-option[aria-pressed="true"] {
  border-color: rgba(140, 29, 24, 0.4);

  background:
    linear-gradient(
      90deg,
      rgba(140, 29, 24, 0.12),
      rgba(140, 29, 24, 0.035)
    );
}

.dice-theme-option[aria-pressed="true"]::after {
  position: absolute;
  right: 0.8rem;

  color: #8c1d18;

  content: "✓";

  font-size: 1rem;
  font-weight: 700;
}

.dice-theme-option {
  position: relative;
}

.dice-theme-option__preview {
  display: grid;
  width: 2.8rem;
  height: 2.8rem;
  place-items: center;

  clip-path: polygon(
    50% 0%,
    90% 18%,
    100% 58%,
    72% 94%,
    28% 94%,
    0% 58%,
    10% 18%
  );

  font-family: "Cinzel", serif;
  font-size: 0.76rem;
  font-weight: 800;

  filter: drop-shadow(
    0 3px 3px rgba(0, 0, 0, 0.25)
  );
}

.dice-theme-option__preview--arrow {
  background: #8c1d18;
  color: #f4dca4;
}

.dice-theme-option__preview--blue-green-metal {
  background:
    linear-gradient(
      145deg,
      #4ba8a7 0%,
      #176b73 48%,
      #173e49 100%
    );

  color: #d9f1ed;

  box-shadow:
    inset 4px 4px 7px rgba(255, 255, 255, 0.25),
    inset -5px -6px 8px rgba(0, 0, 0, 0.3);
}

.dice-theme-option__preview--dice-of-rolling {
  background:
    radial-gradient(
      circle at 30% 25%,
      rgba(255, 255, 255, 0.22),
      transparent 18%
    ),
    radial-gradient(
      circle at 68% 62%,
      rgba(255, 255, 255, 0.14),
      transparent 28%
    ),
    linear-gradient(
      145deg,
      #2a2a2a 0%,
      #111111 58%,
      #050505 100%
    );

  color: #f5f5f5;

  text-shadow:
    0 0 4px rgba(255, 255, 255, 0.55),
    0 1px 2px rgba(0, 0, 0, 0.9);

  box-shadow:
    inset 4px 4px 8px rgba(255, 255, 255, 0.08),
    inset -6px -7px 10px rgba(0, 0, 0, 0.72),
    0 0 8px rgba(255, 255, 255, 0.08);

  position: relative;
  overflow: hidden;
}

.dice-theme-option__preview--dice-of-rolling::before,
.dice-theme-option__preview--dice-of-rolling::after {
  position: absolute;

  border-radius: 50%;

  background:
    radial-gradient(
      ellipse,
      rgba(255, 255, 255, 0.32),
      rgba(255, 255, 255, 0.08) 46%,
      transparent 72%
    );

  content: "";
  filter: blur(2px);
  pointer-events: none;
}

.dice-theme-option__preview--dice-of-rolling::before {
  width: 2.1rem;
  height: 0.85rem;

  top: 0.45rem;
  left: -0.35rem;

  transform: rotate(-24deg);
}

.dice-theme-option__preview--dice-of-rolling::after {
  width: 1.8rem;
  height: 0.75rem;

  right: -0.35rem;
  bottom: 0.35rem;

  transform: rotate(26deg);
}

.dice-theme-option__preview--dice-of-rolling {
  isolation: isolate;
}

.dice-theme-option__preview--dice-of-rolling::before,
.dice-theme-option__preview--dice-of-rolling::after {
  z-index: -1;
}

.dice-theme-option__preview--gemstone {
  background:
    linear-gradient(
      135deg,
      rgba(255, 255, 255, 0.55),
      transparent 25%
    ),
    linear-gradient(
      145deg,
      #38ba8a,
      #167a5b 55%,
      #084b39
    );

  color: #ecfff8;

  text-shadow:
    0 1px 2px rgba(0, 0, 0, 0.42);

  box-shadow:
    inset 4px 4px 8px rgba(255, 255, 255, 0.34),
    inset -5px -6px 9px rgba(0, 45, 31, 0.35);
}

.dice-theme-option__preview--genesys {
  background:
    linear-gradient(
      145deg,
      #f1bd55,
      #c58b28 55%,
      #7d5018
    );

  color: #641b22;

  box-shadow:
    inset 3px 3px 6px rgba(255, 255, 255, 0.3),
    inset -5px -6px 8px rgba(91, 47, 7, 0.25);
}

.dice-theme-option__preview--rock {
  background:
    radial-gradient(
      circle at 30% 25%,
      #888279,
      #55514b 55%,
      #2d2a27
    );

  color: #eee5d3;

  text-shadow:
    0 1px 2px rgba(0, 0, 0, 0.65);

  box-shadow:
    inset 2px 2px 5px rgba(255, 255, 255, 0.12),
    inset -5px -5px 8px rgba(0, 0, 0, 0.38);
}

.dice-theme-option__preview--rust {
  background:
    radial-gradient(
      circle at 30% 25%,
      #c87549,
      #9a4328 55%,
      #5c2418
    );

  color: #f3d6aa;

  box-shadow:
    inset 3px 3px 6px rgba(255, 215, 160, 0.18),
    inset -5px -6px 8px rgba(65, 15, 8, 0.34);
}

.dice-theme-option__preview--smooth {
  background:
    linear-gradient(
      145deg,
      #5876a5,
      #304d7a 58%,
      #182b49
    );

  color: #f1f4fa;

  box-shadow:
    inset 4px 4px 8px rgba(255, 255, 255, 0.22),
    inset -5px -6px 9px rgba(5, 18, 40, 0.32);
}

.dice-theme-option__preview--wooden {
  background:
    repeating-linear-gradient(
      105deg,
      rgba(255, 224, 172, 0.08) 0,
      rgba(255, 224, 172, 0.08) 3px,
      rgba(63, 29, 9, 0.06) 3px,
      rgba(63, 29, 9, 0.06) 7px
    ),
    linear-gradient(
      145deg,
      #a66b34,
      #74451f 58%,
      #43250f
    );

  color: #f0d6a1;

  box-shadow:
    inset 3px 3px 7px rgba(255, 225, 178, 0.18),
    inset -5px -6px 8px rgba(55, 25, 7, 0.35);
}

.dice-theme-option__content {
  display: block;
  min-width: 0;
  padding-right: 1.5rem;
}

.dice-theme-option__content strong,
.dice-theme-option__content small {
  display: block;
}

.dice-theme-option__content strong {
  color: #681814;

  font: 700 0.78rem "Cinzel", serif;
}

.dice-theme-option__content small {
  margin-top: 0.15rem;

  color: rgba(44, 27, 18, 0.68);

  font-size: 0.74rem;
  line-height: 1.3;
}

/* Desktop */
.dice-theme-picker__menu {
  position: fixed;
  z-index: 2147482000;

  top: 0;
  left: 0;
  right: auto;
  bottom: auto;

  width: min(21rem, calc(100vw - 2rem));
  max-height: calc(100dvh - 5.5rem);

  padding: 0.45rem;
  overflow-y: auto;

  border: 1px solid rgba(183, 138, 63, 0.45);
  border-top: 3px solid #8c1d18;
  border-radius: 2px;

  background:
    linear-gradient(
      180deg,
      rgba(242, 224, 181, 0.99),
      rgba(228, 200, 141, 0.99)
    );

  box-shadow:
    0 18px 45px rgba(0, 0, 0, 0.45),
    inset 0 0 22px rgba(93, 53, 20, 0.06);
}

.dice-theme-picker__menu[hidden] {
  display: none;
}

@media (max-width: 760px) {
  .dice-theme-picker {
    position: static;
  }

  .dice-theme-picker__label {
    display: none;
  }

  .dice-theme-picker__current {
    max-width: 7.25rem;
  }

  .dice-theme-picker__menu {
    position: fixed;
    z-index: 2147482000;

    inset: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    width: auto;
    max-height: none;

    padding:
      max(1rem, env(safe-area-inset-top))
      1rem
      max(1rem, env(safe-area-inset-bottom));

    overflow: hidden;

    border: 0;
    border-radius: 0;

    background:
      rgba(12, 7, 5, 0.82);

    backdrop-filter: blur(4px);

    box-shadow: none;
  }

  .dice-theme-picker__menu[hidden] {
    display: none;
  }

  .dice-theme-picker__menu::before {
    position: absolute;
    inset: 0;

    content: "";
  }

  .dice-theme-picker__menu-inner {
    position: relative;
    z-index: 1;

    width: min(100%, 28rem);
    max-height: min(
      82dvh,
      42rem
    );

    padding: 0.75rem;

    overflow-y: auto;
    overscroll-behavior: contain;

    border: 1px solid rgba(183, 138, 63, 0.55);
    border-top: 4px solid #8c1d18;
    border-radius: 4px;

    background:
      linear-gradient(
        180deg,
        rgba(242, 224, 181, 0.995),
        rgba(228, 200, 141, 0.995)
      );

    box-shadow:
      0 24px 60px rgba(0, 0, 0, 0.62),
      inset 0 0 22px rgba(93, 53, 20, 0.06);

    -webkit-overflow-scrolling: touch;
  }

  .dice-theme-option {
    min-height: 4.25rem;
  }
}

/* =========================================================
   Custom roll header button
   ========================================================= */

.custom-roll-toggle {
  appearance: none;

  display: inline-flex;
  align-items: center;
  gap: 0.42rem;

  padding: 0.45rem 0;

  border: 1px solid rgba(183, 138, 63, 0.48);
  border-radius: 2px;

  background:
    linear-gradient(
      180deg,
      rgba(50, 24, 16, 0.97),
      rgba(24, 10, 7, 0.98)
    );

  box-shadow:
    inset 0 0 12px rgba(255, 220, 150, 0.05),
    0 3px 10px rgba(0, 0, 0, 0.25);

  color: #f0d8a2;

  cursor: pointer;

  font: 700 0.67rem "Cinzel", serif;
  letter-spacing: 0.045em;
  text-transform: uppercase;

  transition:
    transform 150ms ease,
    border-color 150ms ease;
}

.custom-roll-toggle:hover {
  transform: translateY(-1px);
  border-color: rgba(220, 174, 91, 0.82);
}

.custom-roll-toggle:focus-visible {
  outline: 3px solid rgba(183, 138, 63, 0.45);
  outline-offset: 2px;
}

.custom-roll-toggle__icon {
  font-size: 1rem;
}

.custom-roll-toggle__chevron {
  transition: transform 150ms ease;
}

.custom-roll-toggle[aria-expanded="true"]
.custom-roll-toggle__chevron {
  transform: rotate(180deg);
}

/* =========================================================
   Custom roll menu
   ========================================================= */

.custom-roll-menu {
  position: fixed;
  z-index: 2147482100;

  top: 0;
  left: 0;

  width: min(32rem, calc(100vw - 2rem));
  max-height: calc(100dvh - 2rem);

  overflow: visible;

  opacity: 1;
}

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

.custom-roll-menu__backdrop {
  display: none;
}

.custom-roll-panel {
  display: grid;
  max-height: min(
    calc(100dvh - 5.5rem),
    48rem
  );
  grid-template-rows: auto minmax(0, 1fr) auto;

  overflow: hidden;

  border: 1px solid rgba(183, 138, 63, 0.6);
  border-top: 4px solid var(--red);
  border-radius: 3px;

  background:
    linear-gradient(
      180deg,
      #f1dfb5,
      #dec080
    );

  box-shadow:
    0 22px 60px rgba(0, 0, 0, 0.58),
    inset 0 0 24px rgba(92, 57, 25, 0.08);
}

.custom-roll-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;

  padding: 1rem 1.1rem;

  border-bottom: 1px solid rgba(140, 29, 24, 0.32);

  background:
    linear-gradient(
      180deg,
      rgba(255, 248, 225, 0.38),
      rgba(140, 29, 24, 0.035)
    );
}

.custom-roll-panel__header h2 {
  margin: 0.12rem 0 0;

  color: var(--red-dark);

  font: 700 1.25rem "Cinzel", serif;
}

.custom-roll-panel__close {
  appearance: none;

  display: grid;
  width: 2.55rem;
  height: 2.55rem;
  flex: 0 0 2.55rem;

  place-items: center;

  padding: 0;

  border: 1px solid rgba(140, 29, 24, 0.42);
  border-radius: 50%;

  background: var(--red-dark);
  color: #f5dfac;

  cursor: pointer;

  font-family: Arial, sans-serif;
  font-size: 1.5rem;
  font-weight: 400;
  line-height: 1;
}

.custom-roll-panel__close::before {
  display: block;

  content: "×";

  transform: translateY(-1px);
}

.custom-roll-panel__body {
  min-height: 0;

  padding: 1rem;

  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
}

.custom-roll-section + .custom-roll-section {
  padding-top: 1rem;
  margin-top: 1rem;

  border-top: 1px solid rgba(92, 57, 25, 0.2);
}

.custom-roll-section__heading {
  margin-bottom: 0.75rem;
}

.custom-roll-section__heading p {
  margin: 0.18rem 0 0;

  color: rgba(44, 27, 18, 0.68);

  font-size: 0.78rem;
}

.custom-roll-label {
  display: block;

  color: var(--red);

  font: 700 0.68rem "Cinzel", serif;
  letter-spacing: 0.075em;
  text-transform: uppercase;
}

/* =========================================================
   Dice selector
   ========================================================= */

.custom-roll-dice-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0.45rem;
}

.custom-roll-die-button {
  appearance: none;

  display: grid;
  min-width: 0;
  justify-items: center;
  gap: 0.35rem;

  padding: 0.5rem 0.25rem;

  border: 1px solid rgba(92, 57, 25, 0.24);
  border-radius: 2px;

  background:
    linear-gradient(
      180deg,
      rgba(255, 255, 255, 0.18),
      rgba(140, 29, 24, 0.045)
    );

  color: var(--red-dark);

  cursor: pointer;

  font: 700 0.64rem "Cinzel", serif;

  transition:
    transform 130ms ease,
    border-color 130ms ease,
    background-color 130ms ease;
}

.custom-roll-die-button:hover {
  transform: translateY(-2px);

  border-color: rgba(140, 29, 24, 0.5);
  background: rgba(140, 29, 24, 0.1);
}

.custom-roll-die-button:focus-visible {
  outline: 3px solid rgba(183, 138, 63, 0.45);
  outline-offset: 2px;
}

.custom-roll-die {
  display: grid;
  width: 2.5rem;
  height: 2.5rem;
  place-items: center;

  background:
    radial-gradient(
      circle at 30% 22%,
      #b43a31,
      #8c1d18 58%,
      #4e100d
    );

  color: #f4dca4;

  font: 700 0.7rem "Cinzel", serif;

  filter: drop-shadow(
    0 3px 3px rgba(0, 0, 0, 0.28)
  );
}

.custom-roll-die--d4 {
  clip-path: polygon(
    50% 2%,
    98% 94%,
    2% 94%
  );
}

.custom-roll-die--d6 {
  border-radius: 18%;
}

.custom-roll-die--d8 {
  clip-path: polygon(
    50% 0,
    100% 50%,
    50% 100%,
    0 50%
  );
}

.custom-roll-die--d10 {
  clip-path: polygon(
    50% 0,
    90% 20%,
    100% 66%,
    50% 100%,
    0 66%,
    10% 20%
  );
}

.custom-roll-die--d12 {
  clip-path: polygon(
    50% 0,
    79% 9%,
    98% 34%,
    98% 66%,
    79% 91%,
    50% 100%,
    21% 91%,
    2% 66%,
    2% 34%,
    21% 9%
  );
}

.custom-roll-die--d20,
.custom-roll-die--d100 {
  clip-path: polygon(
    50% 0,
    76% 8%,
    94% 29%,
    100% 55%,
    87% 82%,
    63% 100%,
    36% 100%,
    12% 82%,
    0 55%,
    6% 29%,
    24% 8%
  );
}

/* =========================================================
   Selected dice
   ========================================================= */

.custom-roll-selected-list {
  display: grid;
  gap: 0.5rem;

  margin-top: 0.65rem;
}

.custom-roll-selected-row {
  display: grid;
  grid-template-columns:
    minmax(4rem, 1fr)
    auto
    2.35rem
    auto;
  align-items: center;
  gap: 0.5rem;

  padding: 0.55rem 0.65rem;

  border: 1px solid rgba(92, 57, 25, 0.22);
  border-left: 4px solid var(--gold);

  background: rgba(166, 124, 50, 0.06);
}

.custom-roll-selected-row__name {
  color: var(--red-dark);

  font: 700 0.82rem "Cinzel", serif;
}

.custom-roll-selected-row__count {
  min-width: 2.35rem;

  font-size: 1rem;
  font-weight: 700;
  text-align: center;
}

.custom-roll-quantity-button,
.custom-roll-small-button {
  appearance: none;

  display: grid;
  width: 2.25rem;
  height: 2.25rem;
  place-items: center;

  border: 1px solid rgba(140, 29, 24, 0.34);
  border-radius: 2px;

  background: rgba(140, 29, 24, 0.07);
  color: var(--red-dark);

  cursor: pointer;

  font-size: 1rem;
  font-weight: 700;
}

.custom-roll-quantity-button:hover,
.custom-roll-small-button:hover {
  border-color: var(--red);
  background: rgba(140, 29, 24, 0.14);
}

/* =========================================================
   Modifier
   ========================================================= */

.custom-roll-modifier {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.custom-roll-modifier small {
  display: block;
  margin-top: 0.15rem;

  color: rgba(44, 27, 18, 0.66);

  font-size: 0.73rem;
}

.custom-roll-modifier__control {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.custom-roll-modifier input {
  width: 5.25rem;
  height: 2.35rem;

  border: 1px solid rgba(92, 57, 25, 0.3);
  border-radius: 2px;

  background: rgba(255, 248, 225, 0.66);
  color: var(--ink);

  font-size: 1rem;
  font-weight: 700;
  text-align: center;
}

/* =========================================================
   Expression and footer
   ========================================================= */

.custom-roll-expression-card {
  padding: 0.8rem;
  margin-top: 1rem;

  border: 1px solid rgba(140, 29, 24, 0.3);
  border-left: 4px solid var(--red);

  background: rgba(140, 29, 24, 0.055);
}

.custom-roll-expression {
  display: block;
  margin-top: 0.35rem;

  color: var(--ink);

  font-family: "Cinzel", serif;
  font-size: 1.05rem;
  font-weight: 700;

  overflow-wrap: anywhere;
}

.custom-roll-panel__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;

  padding: 0.85rem 1rem;

  border-top: 1px solid rgba(92, 57, 25, 0.24);

  background: rgba(92, 57, 25, 0.05);
}

.custom-roll-clear,
.custom-roll-submit {
  appearance: none;

  min-height: 2.65rem;
  padding: 0.55rem 0.9rem;

  border-radius: 2px;

  cursor: pointer;

  font: 700 0.72rem "Cinzel", serif;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.custom-roll-clear {
  border: 1px solid rgba(92, 57, 25, 0.3);

  background: rgba(255, 255, 255, 0.13);
  color: var(--ink);
}

.custom-roll-submit {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;

  border: 1px solid #6c1713;

  background:
    linear-gradient(
      180deg,
      #a82821,
      #741712
    );

  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.18),
    0 3px 8px rgba(0, 0, 0, 0.22);

  color: #f5dfac;
}

.custom-roll-submit:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.custom-roll-trigger {
  position: fixed;

  width: 1px;
  height: 1px;

  overflow: hidden;

  clip-path: inset(50%);

  opacity: 0;
  pointer-events: none;
}

/* =========================================================
   Mobile overlay
   ========================================================= */

@media (max-width: 760px) {
  .custom-roll-menu {
    position: fixed !important;
    z-index: 2147482100;

    inset: 0 !important;

    display: grid;
    width: 100dvw !important;
    height: 100dvh !important;
    max-height: none;

    place-items: center;

    padding:
      max(0.75rem, env(safe-area-inset-top))
      max(0.75rem, env(safe-area-inset-right))
      max(0.75rem, env(safe-area-inset-bottom))
      max(0.75rem, env(safe-area-inset-left));

    background: transparent;
  }

  .custom-roll-menu__backdrop {
    position: absolute;
    inset: 0;

    display: block;

    background: rgba(10, 6, 4, 0.84);

    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
  }

  .custom-roll-panel {
    position: relative;
    z-index: 1;

    width: min(100%, 31rem);
    height: min(92dvh, 48rem);
    max-height: none;
  }

  .custom-roll-dice-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .custom-roll-modifier {
    align-items: flex-start;
    flex-direction: column;
  }

  .custom-roll-modifier__control {
    width: 100%;
  }

  .custom-roll-modifier input {
    width: auto;
    min-width: 0;
    flex: 1;
  }

  body.custom-roll-menu-open {
    overflow: hidden;
    touch-action: none;
  }
}

.dnd-roll-result--error {
  border-color: #8c1d18;
}

.dnd-roll-result--error
.dnd-roll-result-expression {
  color: #b92c24;
}

/* =========================================================
   Advanced dice-result details
   ========================================================= */

.dnd-roll-advanced-details {
  display: grid;
  gap: 0.65rem;

  margin-top: 0.4rem;
}

.dnd-roll-detail-group {
  min-width: 0;
}

.dnd-roll-detail-group + .dnd-roll-detail-group {
  padding-top: 0.6rem;

  border-top: 1px solid rgba(92, 57, 25, 0.22);
}

.dnd-roll-detail-group-heading {
  margin-bottom: 0.35rem;

  color: var(--red-dark, #681814);

  font:
    700
    0.67rem
    "Cinzel",
    serif;

  letter-spacing: 0.055em;
  text-transform: uppercase;
}

.dnd-roll-detail-dice {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.dnd-roll-die {
  position: relative;

  display: inline-flex;
  min-width: 2.4rem;
  min-height: 2.25rem;
  align-items: center;
  justify-content: center;
  flex-direction: column;

  padding: 0.3rem 0.45rem;

  border: 1px solid rgba(92, 57, 25, 0.28);
  border-radius: 3px;

  background:
    linear-gradient(
      145deg,
      rgba(255, 255, 255, 0.18),
      rgba(166, 124, 50, 0.09)
    );

  color: var(--ink, #2c1b12);

  box-shadow:
    inset 0 0 8px rgba(92, 57, 25, 0.05),
    0 1px 2px rgba(45, 27, 12, 0.12);
}

.dnd-roll-die-value {
  font-size: 0.98rem;
  line-height: 1;
}

.dnd-roll-die-state {
  display: block;

  margin-top: 0.18rem;

  font-size: 0.48rem;
  font-weight: 800;
  letter-spacing: 0.045em;
  line-height: 1;
  text-transform: uppercase;
}

.dnd-roll-die-contribution {
  display: block;

  margin-top: 0.18rem;

  color: rgba(44, 27, 18, 0.68);

  font-size: 0.52rem;
  line-height: 1.05;
  white-space: nowrap;
}

/* Kept result */

.dnd-roll-die--kept {
  border-color: rgba(38, 116, 69, 0.55);

  background:
    linear-gradient(
      145deg,
      rgba(225, 248, 231, 0.48),
      rgba(52, 135, 77, 0.12)
    );

  box-shadow:
    inset 0 0 8px rgba(35, 113, 62, 0.08),
    0 0 0 1px rgba(35, 113, 62, 0.08);
}

.dnd-roll-die-state--kept {
  color: #236d3d;
}

/* Dropped result */

.dnd-roll-die--dropped {
  opacity: 0.55;

  border-color: rgba(92, 57, 25, 0.18);

  background: rgba(92, 57, 25, 0.05);
}

.dnd-roll-die--dropped
.dnd-roll-die-value {
  text-decoration: line-through;
}

.dnd-roll-die-state--dropped {
  color: rgba(70, 51, 38, 0.72);
}

/* Rerolled result */

.dnd-roll-die--rerolled {
  opacity: 0.58;

  border-style: dashed;
  border-color: rgba(82, 87, 125, 0.48);

  background: rgba(74, 81, 128, 0.08);
}

.dnd-roll-die--rerolled
.dnd-roll-die-value {
  text-decoration: line-through;
}

.dnd-roll-die-state--rerolled {
  color: #505783;
}

/* Exploding result */

.dnd-roll-die--exploded {
  border-color: rgba(171, 88, 21, 0.62);

  box-shadow:
    inset 0 0 9px rgba(190, 94, 20, 0.1),
    0 0 7px rgba(190, 94, 20, 0.16);
}

.dnd-roll-die-state--exploded {
  color: #a24d12;
}

/* Natural maximum */

.dnd-roll-die--critical {
  border-color: rgba(166, 124, 50, 0.78);

  background:
    linear-gradient(
      145deg,
      rgba(255, 241, 184, 0.66),
      rgba(185, 132, 35, 0.17)
    );

  box-shadow:
    inset 0 0 10px rgba(182, 128, 34, 0.12),
    0 0 8px rgba(196, 144, 45, 0.2);
}

/* Natural minimum */

.dnd-roll-die--critical-failure {
  border-color: rgba(140, 29, 24, 0.6);

  background:
    linear-gradient(
      145deg,
      rgba(255, 225, 219, 0.42),
      rgba(140, 29, 24, 0.12)
    );
}

@media (max-width: 760px) {
  .dnd-roll-detail-dice {
    gap: 0.28rem;
  }

  .dnd-roll-die {
    min-width: 2.2rem;
    min-height: 2.15rem;

    padding: 0.28rem 0.38rem;
  }
}

/* =========================================================
   Advanced custom-roll controls
   ========================================================= */

.custom-roll-choice-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.4rem;

  margin-top: 0.55rem;
}

.custom-roll-choice-grid--four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.custom-roll-choice-grid--five {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.custom-roll-choice {
  appearance: none;

  min-width: 0;
  min-height: 2.45rem;

  padding: 0.45rem 0.4rem;

  border: 1px solid rgba(92, 57, 25, 0.25);
  border-radius: 2px;

  background: rgba(255, 255, 255, 0.12);
  color: var(--ink);

  cursor: pointer;

  font:
    700
    0.62rem
    "Cinzel",
    serif;

  line-height: 1.2;
  text-align: center;
  text-transform: uppercase;

  transition:
    border-color 130ms ease,
    background-color 130ms ease,
    color 130ms ease;
}

.custom-roll-choice:hover {
  border-color: rgba(140, 29, 24, 0.5);
  background: rgba(140, 29, 24, 0.07);
}

.custom-roll-choice.is-selected,
.custom-roll-choice[aria-checked="true"] {
  border-color: var(--red);

  background:
    linear-gradient(
      180deg,
      rgba(140, 29, 24, 0.16),
      rgba(140, 29, 24, 0.07)
    );

  color: var(--red-dark);
}

.custom-roll-choice:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.custom-roll-field {
  display: grid;
  gap: 0.35rem;
}

.custom-roll-field--compact {
  max-width: 10rem;
  margin-top: 0.65rem;
}

.custom-roll-field__label {
  display: block;

  color: var(--red-dark);

  font:
    700
    0.64rem
    "Cinzel",
    serif;

  letter-spacing: 0.045em;
  text-transform: uppercase;
}

.custom-roll-field select,
.custom-roll-field input,
.custom-roll-condition select,
.custom-roll-condition input {
  width: 100%;
  min-height: 2.45rem;

  padding: 0.42rem 0.5rem;

  border: 1px solid rgba(92, 57, 25, 0.3);
  border-radius: 2px;

  background: rgba(255, 248, 225, 0.75);
  color: var(--ink);

  font-weight: 700;
}

.custom-roll-advanced-block {
  padding-top: 0.85rem;
  margin-top: 0.85rem;

  border-top: 1px solid rgba(92, 57, 25, 0.18);
}

.custom-roll-condition {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(5rem, 0.7fr);
  gap: 0.55rem;

  padding: 0.65rem;
  margin-top: 0.65rem;

  border: 1px solid rgba(92, 57, 25, 0.2);

  background: rgba(166, 124, 50, 0.055);
}

.custom-roll-condition label {
  display: grid;
  gap: 0.25rem;

  color: var(--red-dark);

  font-size: 0.7rem;
  font-weight: 700;
}

.custom-roll-warning {
  margin: 0.55rem 0 0;

  color: #8c1d18;

  font-size: 0.73rem;
  font-weight: 700;
}

/* Expression */

.custom-roll-expression-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.custom-roll-expression {
  width: 100%;
  min-height: 2.7rem;

  padding: 0.55rem 0.65rem;
  margin-top: 0.4rem;

  border: 1px solid rgba(140, 29, 24, 0.34);
  border-radius: 2px;

  background: rgba(255, 248, 225, 0.75);
  color: var(--ink);

  font-family: "Cinzel", serif;
  font-size: 0.95rem;
  font-weight: 700;
}

.custom-roll-expression.is-manual {
  border-color: rgba(52, 83, 132, 0.55);
  background: rgba(225, 235, 250, 0.45);
}

.custom-roll-reset-expression {
  appearance: none;

  padding: 0;

  border: 0;

  background: transparent;
  color: var(--red);

  cursor: pointer;

  font-size: 0.69rem;
  font-weight: 700;
  text-decoration: underline;
}

.custom-roll-expression-note {
  display: block;

  margin-top: 0.3rem;

  color: rgba(44, 27, 18, 0.66);

  font-size: 0.68rem;
}

/* =========================================================
   Roll history
   ========================================================= */

.custom-roll-history {
  padding-top: 1rem;
  margin-top: 1rem;

  border-top: 2px solid rgba(140, 29, 24, 0.3);
}

.custom-roll-history__heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;

  margin-bottom: 0.6rem;
}

.custom-roll-history__heading small {
  display: block;

  margin-top: 0.1rem;

  color: rgba(44, 27, 18, 0.6);

  font-size: 0.65rem;
}

.custom-roll-history__clear {
  appearance: none;

  padding: 0;

  border: 0;

  background: transparent;
  color: var(--red);

  cursor: pointer;

  font-size: 0.68rem;
  font-weight: 700;
  text-decoration: underline;
}

.custom-roll-history__empty {
  padding: 0.75rem;

  border: 1px dashed rgba(92, 57, 25, 0.28);

  color: rgba(44, 27, 18, 0.62);

  font-size: 0.75rem;
  font-style: italic;
  text-align: center;
}

.custom-roll-history__list {
  display: grid;
  gap: 0.4rem;
}

.custom-roll-history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.6rem;

  padding: 0.55rem 0.65rem;

  border: 1px solid rgba(92, 57, 25, 0.2);
  border-left: 4px solid var(--gold);

  background: rgba(166, 124, 50, 0.055);
}

.custom-roll-history-item__expression {
  display: block;

  color: var(--red-dark);

  font-family: "Cinzel", serif;
  font-size: 0.76rem;
  font-weight: 700;

  overflow-wrap: anywhere;
}

.custom-roll-history-item__meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;

  margin-top: 0.18rem;

  color: rgba(44, 27, 18, 0.65);

  font-size: 0.66rem;
}

.custom-roll-history-item__total {
  color: var(--ink);

  font-size: 1.1rem;
  font-weight: 800;
}

.custom-roll-history-item__reroll {
  appearance: none;

  min-height: 2.15rem;

  padding: 0.35rem 0.55rem;

  border: 1px solid rgba(140, 29, 24, 0.32);
  border-radius: 2px;

  background: rgba(140, 29, 24, 0.07);
  color: var(--red-dark);

  cursor: pointer;

  font:
    700
    0.62rem
    "Cinzel",
    serif;

  text-transform: uppercase;
}

.custom-roll-history-item__reroll:hover {
  border-color: var(--red);
  background: rgba(140, 29, 24, 0.14);
}

@media (max-width: 760px) {
  .custom-roll-choice-grid--four,
  .custom-roll-choice-grid--five {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .custom-roll-condition {
    grid-template-columns: 1fr;
  }
}

.custom-roll-collapsible {
  border-top: 1px solid rgba(92, 57, 25, 0.2);
}

.custom-roll-collapsible__summary {
  display: flex;
  min-height: 3.4rem;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;

  padding: 0.75rem 0;

  cursor: pointer;

  list-style: none;
}

.custom-roll-collapsible__summary::-webkit-details-marker {
  display: none;
}

.custom-roll-collapsible__summary small {
  display: block;

  margin-top: 0.12rem;

  color: rgba(44, 27, 18, 0.62);

  font-size: 0.7rem;
  font-weight: 400;
}

.custom-roll-collapsible__chevron {
  flex: 0 0 auto;

  color: var(--red-dark);

  font-size: 0.9rem;

  transition: transform 160ms ease;
}

.custom-roll-collapsible[open]
.custom-roll-collapsible__chevron {
  transform: rotate(180deg);
}

.custom-roll-collapsible__content {
  padding-bottom: 1rem;
}

.header-tool-button {
  appearance: none;

  display: inline-flex;
  height: 2.65rem;
  min-height: 2.65rem;

  align-items: center;
  justify-content: center;
  gap: 0.45rem;

  padding: 0 0.8rem;

  border: 1px solid rgba(183, 138, 63, 0.48);
  border-radius: 2px;

  background:
    linear-gradient(
      180deg,
      rgba(50, 24, 16, 0.97),
      rgba(24, 10, 7, 0.98)
    );

  box-sizing: border-box;

  color: #f0d8a2;

  font: 700 0.67rem "Cinzel", serif;
  letter-spacing: 0.045em;
  line-height: 1;
  text-transform: uppercase;
}

/* Unified floating dice tray */
.dice-tray-launcher { position: fixed; z-index: 2147482200; right: 1.35rem; bottom: 1.35rem; }
.dice-tray-launcher__button { position: relative; display: grid; width: 4.25rem; height: 4.25rem; overflow: hidden; place-items: center; padding: 0; border: 2px solid rgba(255,238,196,.72); border-radius: 50%; background-color: #35100d; background-image: url('../images/icons/dice_roll.png'); background-repeat: no-repeat; background-position: center; background-size: 148%; cursor: pointer; box-shadow: 0 10px 28px rgba(0,0,0,.48), 0 0 0 4px rgba(183,138,63,.14); transition: transform .16s ease, box-shadow .16s ease; }
.dice-tray-launcher__button:hover { transform: translateY(-3px) scale(1.03); box-shadow: 0 15px 34px rgba(0,0,0,.55), 0 0 0 5px rgba(183,138,63,.2); }
.dice-tray-launcher__button:focus-visible { outline: 3px solid #e2b662; outline-offset: 3px; }
.dice-tray-launcher__button img { width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.dice-tray-launcher__theme-proxy { position: absolute; width: 1px; height: 1px; overflow: hidden; padding: 0; border: 0; opacity: 0; pointer-events: none; }
.custom-roll-menu, .dice-theme-picker__menu { top: auto !important; right: 1.35rem !important; bottom: 6.25rem !important; left: auto !important; width: min(32rem, calc(100vw - 2rem)); }
.custom-roll-panel { grid-template-rows: auto auto minmax(0, 1fr) auto; }
.dice-theme-picker__menu { max-height: min(calc(100dvh - 8rem), 48rem); overflow: hidden auto; padding: 0; border: 1px solid rgba(183,138,63,.6); border-top: 4px solid #8c1d18; background: #efe0bd; box-shadow: 0 22px 55px rgba(0,0,0,.5); }
.dice-tray-panel__header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 1.1rem; border-bottom: 1px solid rgba(140,29,24,.32); background: linear-gradient(180deg, rgba(255,249,228,.98), rgba(231,209,164,.96)); }
.dice-tray-panel__header h2 { margin: .12rem 0 0; color: #5d100d; font: 700 1.25rem "Cinzel", serif; }
.dice-tray-tabs { display: grid; grid-template-columns: 1fr 1fr; padding: .45rem; border-bottom: 1px solid rgba(92,57,25,.2); background: rgba(92,57,25,.08); }
.dice-tray-tabs button { padding: .65rem .8rem; border: 0; border-bottom: 3px solid transparent; background: transparent; color: #6d5847; cursor: pointer; font: 700 .72rem "Cinzel", serif; letter-spacing: .04em; text-transform: uppercase; box-shadow: none; }
.dice-tray-tabs button:hover { color: #5d100d; }
.dice-tray-tabs button.is-active { border-bottom-color: #8c1d18; background: rgba(255,255,255,.35); color: #5d100d; }
.dice-theme-picker__menu-inner { padding: .55rem; }
.dice-tray-customize { min-height: 0; overflow-y: auto; }
.dice-tray-customize .dice-theme-picker__menu-inner { position: static; width: auto; max-height: none; padding: .55rem; overflow: visible; border: 0; border-radius: 0; background: transparent; box-shadow: none; }
.custom-roll-panel__footer[hidden], [data-dice-tray-content][hidden] { display: none; }
@media (max-width: 760px) {
  .dice-tray-launcher { right: .9rem; bottom: .9rem; }
  .dice-tray-launcher__button { width: 3.8rem; height: 3.8rem; }
  .custom-roll-menu, .dice-theme-picker__menu { right: .75rem !important; bottom: 5.4rem !important; left: .75rem !important; width: auto; max-height: calc(100dvh - 6.5rem); }
  .dice-theme-picker__menu { display: grid; grid-template-rows: auto auto minmax(0, 1fr); align-items: stretch; justify-content: stretch; inset: auto .75rem 5.4rem .75rem !important; padding: 0; overflow: hidden; border: 1px solid rgba(183,138,63,.6); border-top: 4px solid #8c1d18; border-radius: 2px; background: #efe0bd; backdrop-filter: none; box-shadow: 0 22px 55px rgba(0,0,0,.5); }
  .dice-theme-picker__menu[hidden] { display: none; }
  .dice-theme-picker__menu::before { display: none; }
  .dice-theme-picker__menu .dice-theme-picker__menu-inner { position: static; z-index: auto; width: auto; max-height: none; min-height: 0; padding: .55rem; overflow-y: auto; border: 0; border-radius: 0; background: transparent; box-shadow: none; }
  .dice-tray-customize .dice-theme-picker__menu-inner { position: static; z-index: auto; width: auto; max-height: none; min-height: 0; padding: .55rem; overflow: visible; border: 0; border-radius: 0; background: transparent; box-shadow: none; }
}