/* The dice tray, the /dice page (a full-window table with a docked tray) and the overlay of the
   game page. Colours, fonts and shapes come from the design tokens (web/tokens.css, which the
   overlay loads itself on first use). The table and the dock are the dark green "bar" colours in
   both themes, like the site's header. */

/* ---- the table ---- */
.dice-stage {
  position: relative;
  width: 100%;
  height: clamp(300px, 55vh, 620px);
  overflow: hidden;
  background:
    var(--dm-mat-dark), radial-gradient(ellipse at 50% 35%, var(--dm-bar-raised), var(--dm-bar) 75%);
  background-size:
    var(--dm-hex-tile-width) var(--dm-hex-tile-height),
    auto;
}
.dice-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* ---- the /dice page: the table is the whole window; the site header on top, the dock on the bottom ---- */
body.dice-page {
  height: 100dvh;
  overflow: hidden;
  background: var(--dm-bar);
}
body.dice-page main {
  position: static;
  max-width: none;
  padding: 0;
}
.dice-ui {
  position: fixed;
  inset: 0;
  color: var(--dm-on-bar);
  background: var(--dm-bar);
}
.dice-ui .dice-stage {
  position: absolute;
  inset: 0;
  height: auto;
}
.dice-ui .dice-noscript {
  position: relative;
  padding: var(--dm-space-4);
}
/* the site header floats over the table, see-through */
body.dice-page .site-header {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 30;
  background-color: color-mix(in srgb, var(--dm-bar) 78%, transparent);
  background-image: none;
  border-bottom-color: transparent;
  backdrop-filter: blur(6px);
}
.dice-dock {
  position: absolute;
  z-index: 10;
  left: 0;
  right: 0;
  bottom: 0;
  padding: var(--dm-space-3) var(--dm-space-4) max(var(--dm-space-3), env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--dm-bar) 82%, transparent);
  border-top: 2px solid var(--dm-gold);
  backdrop-filter: blur(8px);
}
.dice-dock .dice-tray {
  max-width: 54rem;
  margin: 0 auto;
}

/* ---- the tray (shared by the page and the overlay) ---- */
.dice-tray {
  color: var(--dm-on-bar);
  font-family: var(--dm-font-sans);
  font-weight: var(--dm-weight-body);
}
.dice-buttons {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: var(--dm-space-2);
}
.dice-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.1rem;
  min-height: 3.4rem;
  margin: 0;
  padding: 0.3rem 0.2rem;
  font: inherit;
  font-weight: var(--dm-weight-strong);
  color: var(--dm-on-bar);
  --edge: var(--dm-bar-edge);
  --fill: var(--dm-bar-raised);
  cursor: pointer;
  transition:
    background-color 0.12s,
    transform 0.12s;
}
.dice-button svg {
  width: 1.9rem;
  height: 1.9rem;
  color: var(--dm-gold-light);
}
.dice-button:hover {
  --fill: var(--dm-bar-edge);
}
.dice-button:active {
  transform: scale(0.96);
}
.dice-button:focus-visible,
.dice-throw:focus-visible,
.dice-clear:focus-visible,
.dice-close:focus-visible,
.dice-notation:focus-visible,
.dice-3d input:focus-visible {
  outline: var(--dm-focus-width) solid var(--dm-bar-focus);
  outline-offset: var(--dm-focus-offset);
}
.dice-cup {
  margin: var(--dm-space-3) 0 var(--dm-space-2);
}
.dice-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.dice-notation {
  width: 100%;
  box-sizing: border-box;
  min-height: 2.75rem;
  font: inherit;
  font-size: 1.1rem;
  padding: 0.4rem 0.9rem;
  color: var(--dm-on-bar);
  --dm-fill: var(--dm-bar-raised);
  --dm-edge: var(--dm-bar-edge);
}
.dice-notation::placeholder {
  color: var(--dm-on-bar-muted);
  opacity: 1;
}
.dice-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--dm-space-2);
  align-items: center;
}
.dice-actions button {
  --edge: var(--dm-gold);
  --fill: var(--dm-gold);
  min-height: 2.75rem;
  margin: 0;
  font: inherit;
  font-weight: var(--dm-weight-strong);
  padding: 0.3rem 1.5rem;
  cursor: pointer;
  color: var(--dm-on-gold);
}
.dice-actions button:hover:not([disabled]) {
  --edge: var(--dm-gold-light);
  --fill: var(--dm-gold-light);
}
.dice-actions button.secondary {
  --edge: var(--dm-bar-edge);
  --fill: var(--dm-bar);
  color: var(--dm-on-bar);
}
.dice-actions button.secondary:hover:not([disabled]) {
  --fill: var(--dm-bar-raised);
}
.dice-actions button[disabled] {
  opacity: 0.6;
  cursor: progress;
}
.dice-throw {
  flex: 1 1 8rem;
}
.dice-3d {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 2.75rem;
  padding: 0 var(--dm-space-2);
  font-weight: var(--dm-weight-strong);
}
.dice-3d input {
  width: 1.25rem;
  height: 1.25rem;
  accent-color: var(--dm-gold);
}
.dice-message {
  min-height: 0;
  margin: var(--dm-space-1) 0 0;
  text-align: center;
  font-size: 0.9rem;
  color: var(--dm-on-bar-muted);
}
.dice-message:empty {
  display: none;
}
.dice-note {
  margin: var(--dm-space-1) 0 0;
  text-align: center;
  font-size: 0.8rem;
  color: var(--dm-on-bar-muted);
}

/* ---- the total over the table ---- */
.dice-readout {
  position: absolute;
  z-index: 2;
  top: calc(var(--dice-top, 0px) + var(--dm-space-2));
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--dm-space-1);
  margin: 0;
  pointer-events: none;
  text-align: center;
}
.dice-total {
  margin: 0;
  min-width: 4rem;
  font-size: clamp(2.6rem, 9vw, 4.5rem);
  font-weight: var(--dm-weight-strong);
  line-height: 1.1;
  color: var(--dm-on-bar);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
}
.dice-total:empty {
  display: none;
}
.dice-result {
  margin: 0;
  max-width: calc(100% - 2rem);
  padding: 0.15rem 0.9rem;
  font-size: 1.05rem;
  font-weight: var(--dm-weight-strong);
  color: var(--dm-on-bar);
  --dm-fill: var(--dm-bar);
  --dm-edge: var(--dm-bar-edge);
  overflow-wrap: anywhere;
}
.dice-result:empty {
  display: none;
}
.dice-readout.has-result .dice-total {
  animation: dice-pop 0.35s ease-out;
}
@keyframes dice-pop {
  from {
    transform: scale(0.7);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

/* ---- the overlay on the game page ---- */
.dice-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(7, 20, 16, 0.55);
  font-family: var(--dm-font-sans);
  color: var(--dm-on-bar);
}
.dice-overlay[hidden] {
  display: none;
}
.dice-overlay .dice-overlay-stage {
  position: absolute;
  inset: 0;
  height: 100%;
  background: none;
}
.dice-overlay .dice-panel {
  position: absolute;
  left: 50%;
  bottom: max(0.75rem, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(36rem, calc(100vw - 1rem));
  max-height: 60vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-sizing: border-box;
  padding: var(--dm-space-3) var(--dm-space-4);
  background: var(--dm-bar);
  /* the edge follows the cut corners (.cut-frame in cut.css); the tray scrolls, not the panel */
  --edge: var(--dm-bar-edge);
}
.dice-overlay .dice-tray {
  margin: 0;
  min-height: 0;
  overflow: auto;
}
/* ---- dice on the game table (table.js): the layer over the 3D scene and the result cards ---- */
/* the tray is a small dialog that closes on Throw; the table stays visible behind it */
.dice-overlay.is-on-table {
  background: rgba(7, 20, 16, 0.25);
}
.dice-secret {
  margin-left: 0;
}
.dice-table-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  transition: opacity 0.5s ease;
}
.dice-table-canvas[hidden] {
  display: none;
}
.dice-table-canvas.is-fading {
  opacity: 0;
}
.dice-table-results {
  position: absolute;
  /* over the viewer's own hints: a result is short-lived and matters more */
  z-index: 50;
  top: max(0.75rem, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  width: min(22rem, calc(100% - 7rem));
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--dm-space-2);
  pointer-events: none;
  font-family: var(--dm-font-sans);
}
.dice-card {
  margin: 0;
  padding: var(--dm-space-2) var(--dm-space-3);
  text-align: center;
  color: var(--dm-on-bar);
  --fill: color-mix(in srgb, var(--dm-bar) 92%, transparent);
  --edge: var(--dm-gold);
  animation: dice-pop 0.35s ease-out;
}
.dice-card.is-secret {
  --edge: var(--dm-on-bar-muted);
}
.dice-card p {
  margin: 0;
}
.dice-card-who {
  font-size: 0.85rem;
  color: var(--dm-on-bar-muted);
  overflow-wrap: anywhere;
}
.dice-card-total {
  font-size: 2.2rem;
  font-weight: var(--dm-weight-strong);
  line-height: 1.1;
}
.dice-card-sum {
  font-size: 0.9rem;
  font-weight: var(--dm-weight-strong);
  overflow-wrap: anywhere;
}

@media (max-width: 30rem) {
  .dice-buttons {
    gap: var(--dm-space-1);
  }
  .dice-button {
    min-height: 3.25rem;
  }
  .dice-button svg {
    width: 1.6rem;
    height: 1.6rem;
  }
  .dice-3d {
    margin-left: 0;
  }
}
@media (max-height: 520px) and (orientation: landscape) {
  .dice-dock {
    padding-block: var(--dm-space-2);
  }
  .dice-cup {
    margin: var(--dm-space-2) 0 var(--dm-space-1);
  }
  .dice-button {
    min-height: 2.9rem;
  }
}
@media (prefers-reduced-motion: reduce) {
  .dice-button,
  .dice-readout.has-result .dice-total,
  .dice-card {
    transition: none;
    animation: none;
  }
}

/* ---- the dice style picker on the /dice page (picker.js, #96) ---- */
.dice-style-button {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
.dice-actions button.dice-style-button {
  padding-inline: 0.9rem 1.2rem;
}
.dice-swatch {
  --swatch-die: #2c7f61;
  --swatch-text: #fffaf0;
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 2.1rem;
  height: 2.1rem;
  clip-path: polygon(25% 3%, 75% 3%, 100% 50%, 75% 97%, 25% 97%, 0 50%);
  font-size: 0.8rem;
  font-weight: var(--dm-weight-strong);
  line-height: 1;
  color: var(--swatch-text);
  background-color: var(--swatch-die);
  background-image: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.28), transparent 60%);
}
.dice-style-button .dice-swatch {
  width: 1.6rem;
  height: 1.6rem;
  font-size: 0.6rem;
}
.dice-swatch.is-matte {
  background-image: none;
}
.dice-swatch.is-metal {
  background-image: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.45),
    transparent 40%,
    rgba(0, 0, 0, 0.25) 60%,
    rgba(255, 255, 255, 0.3)
  );
}
.dice-swatch.is-marble {
  background-image:
    linear-gradient(115deg, transparent 38%, rgba(128, 128, 128, 0.45) 41%, transparent 44%),
    linear-gradient(60deg, transparent 60%, rgba(128, 128, 128, 0.35) 62%, transparent 64%),
    radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.3), transparent 60%);
}
.dice-swatch.is-sparkle {
  background-image:
    radial-gradient(circle at 22% 30%, #fff 0 1px, transparent 1.5px),
    radial-gradient(circle at 70% 22%, #fff 0 1px, transparent 1.5px),
    radial-gradient(circle at 78% 70%, #fff 0 1px, transparent 1.5px),
    radial-gradient(circle at 30% 78%, #fff 0 1px, transparent 1.5px),
    radial-gradient(circle at 60% 55%, rgba(255, 255, 255, 0.25), transparent 60%);
}
.dice-swatch.is-wood {
  background-image: repeating-linear-gradient(
    170deg,
    rgba(0, 0, 0, 0.18) 0 1px,
    transparent 1px 4px,
    rgba(255, 255, 255, 0.08) 4px 5px,
    transparent 5px 7px
  );
}
.dice-styles {
  position: absolute;
  z-index: 20;
  left: 50%;
  bottom: calc(100% + var(--dm-space-2));
  transform: translateX(-50%);
  width: min(40rem, calc(100vw - 1rem));
  display: flex;
  flex-direction: column;
  max-height: min(34rem, calc(100dvh - 9rem));
  overflow: hidden;
  box-sizing: border-box;
  color: var(--dm-on-bar);
  background: var(--dm-bar);
  --edge: var(--dm-gold);
}
.dice-styles[hidden] {
  display: none;
}
.dice-styles-body {
  min-height: 0;
  overflow: auto;
  padding: var(--dm-space-3) var(--dm-space-4);
}
.dice-styles-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--dm-space-2);
  margin-bottom: var(--dm-space-2);
}
.dice-styles-title {
  margin: 0;
  font-size: 1.15rem;
  color: var(--dm-on-bar);
}
.dice-styles-close,
.dice-custom-use {
  min-height: 2.5rem;
  margin: 0;
  padding: 0.3rem 1.2rem;
  font: inherit;
  font-weight: var(--dm-weight-strong);
  cursor: pointer;
  color: var(--dm-on-gold);
  --edge: var(--dm-gold);
  --fill: var(--dm-gold);
}
.dice-styles-close.secondary {
  color: var(--dm-on-bar);
  --edge: var(--dm-bar-edge);
  --fill: var(--dm-bar);
}
.dice-styles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr));
  gap: var(--dm-space-2);
}
.dice-style {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 3rem;
  margin: 0;
  padding: 0.35rem 0.6rem;
  font: inherit;
  font-size: 0.9rem;
  font-weight: var(--dm-weight-strong);
  text-align: left;
  color: var(--dm-on-bar);
  cursor: pointer;
  --edge: var(--dm-bar-edge);
  --fill: var(--dm-bar-raised);
}
.dice-style:hover {
  --fill: var(--dm-bar-edge);
}
.dice-style[aria-pressed='true'] {
  --edge: var(--dm-gold);
}
.dice-style.is-locked .dice-swatch {
  opacity: 0.55;
}
.dice-style-name {
  flex: 1;
  min-width: 0;
  line-height: 1.2;
}
.dice-style-tier {
  flex: none;
  margin-left: 0.4rem;
  padding: 0 0.35rem;
  font-size: 0.7rem;
  line-height: 1.4;
  color: var(--dm-on-gold);
  background: var(--dm-gold-light);
}
.dice-style:focus-visible,
.dice-style-button:focus-visible,
.dice-styles-close:focus-visible,
.dice-custom-use:focus-visible,
.dice-custom input:focus-visible,
.dice-custom select:focus-visible {
  outline: var(--dm-focus-width) solid var(--dm-bar-focus);
  outline-offset: var(--dm-focus-offset);
}
.dice-custom {
  margin: var(--dm-space-3) 0 0;
  padding: var(--dm-space-2) 0 0;
  border: 0;
  border-top: 2px solid var(--dm-bar-edge);
}
.dice-custom.is-selected {
  border-top-color: var(--dm-gold);
}
.dice-custom legend {
  padding: 0 0.3rem;
  font-weight: var(--dm-weight-strong);
}
.dice-custom-note {
  margin: 0 0 var(--dm-space-2);
  font-size: 0.9rem;
  color: var(--dm-on-bar-muted);
}
.dice-styles-plans {
  margin: 0 0 var(--dm-space-3);
  font-size: 0.9rem;
  color: var(--dm-on-bar-muted);
}
.dice-custom-note a,
.dice-styles-plans a,
.dice-styles-status a {
  color: var(--dm-gold-light);
}
.dice-custom-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--dm-space-3);
  align-items: end;
  margin-bottom: var(--dm-space-2);
}
.dice-custom-field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.85rem;
  font-weight: var(--dm-weight-strong);
}
.dice-custom-field input[type='color'] {
  width: 3.2rem;
  height: 2.4rem;
  padding: 0.15rem;
  border: 1px solid var(--dm-bar-edge);
  background: var(--dm-bar-raised);
  cursor: pointer;
}
.dice-custom-field select {
  min-height: 2.4rem;
  padding: 0 0.5rem;
  font: inherit;
  color: var(--dm-on-bar);
  background: var(--dm-bar-raised);
  border: 1px solid var(--dm-bar-edge);
}
.dice-custom.is-locked .dice-custom-row {
  opacity: 0.55;
}
.dice-custom-use[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
}
.dice-custom-warning {
  margin: 0 0 var(--dm-space-2);
  font-size: 0.85rem;
  color: var(--dm-gold-light);
}
.dice-custom-warning:empty {
  display: none;
}
.dice-styles-status {
  margin: var(--dm-space-2) 0 0;
  font-size: 0.9rem;
  color: var(--dm-on-bar-muted);
}
.dice-styles-status:empty {
  display: none;
}
/* in the game's dice tray: the picker flows under the tray's buttons (the tray scrolls) */
.dice-extra-actions {
  display: contents;
}
.dice-styles.is-in-game {
  position: relative;
  left: auto;
  bottom: auto;
  transform: none;
  width: auto;
  max-height: none;
  margin-top: var(--dm-space-3);
}
.dice-styles.is-in-game .dice-styles-body {
  padding: var(--dm-space-3);
}
