/* Dice toolbar / roller — the floating FAB, full-viewport roll layer, and the
   picker/controls panel. Loaded on every page via layout.html (the FAB is
   always visible); shares the page's CSS custom properties from style.css.
   Mirrors the dice-*.js module boundary — keep dice styling here, not in style.css. */
[x-cloak] { display: none !important; }

.dice-fab {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 50;
  width: 52px;
  height: 52px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  transition: transform 0.15s, filter 0.15s;

  &:hover { filter: brightness(1.1); }
  &:active { transform: scale(0.94); }
  &.is-hidden { opacity: 0; pointer-events: none; transform: scale(0); }
}

/* Dice roll across this full-viewport layer, behind the tray panel/FAB but
   above normal page content (a "sheet of paper" the dice tumble over). */
.dice-layer {
  position: fixed;
  inset: 0;
  /* A <canvas> is a replaced element: with auto width/height it takes its
     intrinsic 300x150 under inset:0 rather than stretching (Safari follows
     this to the letter; Chrome stretches anyway). Size it explicitly so
     clientWidth/clientHeight — which feed the camera aspect — are the viewport. */
  display: block;
  width: 100%;
  height: 100%;
  z-index: 40;
  pointer-events: none;
}

.dice-tray {
  position: fixed;
  right: 0;
  bottom: 0;
  z-index: 49;
  width: 100%;
  max-height: 60vh;
  background: var(--surface);
  border-top: 1px solid var(--border-strong);
  border-radius: 14px 14px 0 0;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.4);
  padding: 10px 14px calc(14px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 12px;
  transform: translateY(105%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);

  &.is-open { transform: translateY(0); }
}

.dice-tray__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.dice-tray__title {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
}

.dice-tray__close {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;

  &:hover { color: var(--text); }
}

.dice-readout {
  min-height: 1.4em;
}

.dice-result,
.dice-hint {
  margin: 0;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text);
}

.dice-hint { font-weight: 500; color: var(--muted); }

.dice-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.dice-chip {
  position: relative;
  flex: 1 1 auto;
  min-width: 48px;
  padding: 8px 6px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;

  &:hover { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--bg)); }
}

.dice-chip__n {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
  line-height: 18px;
  text-align: center;
}

.dice-skin {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dice-skin__label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted, var(--text));
}

.dice-skin__select {
  flex: 1;
  padding: 8px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;

  &:disabled { opacity: 0.5; cursor: default; }
}

.dice-actions {
  display: flex;
  gap: 8px;
}

.dice-btn {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--bg);
  color: var(--btn-text);
  transition: filter 0.15s, opacity 0.15s;

  &:disabled { opacity: 0.5; cursor: default; }
}

.dice-btn--go {
  flex: 2;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;

  &:not(:disabled):hover { filter: brightness(1.1); }
}

.dice-btn--ghost:not(:disabled):hover { border-color: var(--text); color: var(--text); }

.dice-fab:focus-visible,
.dice-tray__close:focus-visible,
.dice-chip:focus-visible,
.dice-skin__select:focus-visible,
.dice-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .dice-tray,
  .dice-fab { transition: none; }
}

@media (min-width: 560px) {
  .dice-tray {
    right: 16px;
    bottom: 84px;
    width: 360px;
    border: 1px solid var(--border-strong);
    border-radius: 14px;
    transform: translateY(120%);

    &.is-open { transform: translateY(0); }
  }
}
