/* =========================================================
   Dice Roller — tool-specific styles.
   Layered on /tools/_shared/tool.css. Widget-body styles only;
   all colors reference shared tokens for dark/light theming.
   ========================================================= */

/* ---------- Die-type selector ---------- */
.dr-types {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  border: none;
  padding: 0;
  margin: 0 0 var(--space-5);
}
.dr-type {
  flex: 1 1 auto;
  min-width: 52px;
  padding: 9px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  color: var(--text-secondary);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-colors);
}
.dr-type:hover { border-color: var(--accent); color: var(--text); }
.dr-type:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.dr-type.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}

/* ---------- Controls ---------- */
.dr-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}
.dr-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.dr-field label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
}
.dr-stepper {
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface-2);
}
.dr-stepper:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.dr-step {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition-colors);
}
.dr-step:hover { background: var(--surface-inset); color: var(--text); }
.dr-stepper input {
  border: none;
  background: transparent;
  text-align: center;
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  padding: 10px 0;
  min-width: 0;
  -moz-appearance: textfield;
}
.dr-stepper input::-webkit-outer-spin-button,
.dr-stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.dr-stepper input:focus { outline: none; }

/* ---------- Notation preview ---------- */
.dr-notation {
  text-align: center;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent-soft-fg);
  margin: 0 0 var(--space-4);
}

.dr-actions { margin-bottom: var(--space-5); }

/* ---------- Results ---------- */
.dr-results {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--space-3);
  min-height: 72px;
  margin-bottom: var(--space-4);
}
.dr-die {
  --die-size: clamp(52px, 15vw, 68px);
  position: relative;
  width: var(--die-size);
  height: var(--die-size);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 2px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
  font-size: clamp(22px, 6vw, 28px);
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.dr-die.is-rolling { animation: dr-tumble 0.5s ease; }
@keyframes dr-tumble {
  0%   { transform: rotate(-14deg) scale(0.9); }
  50%  { transform: rotate(10deg) scale(1.06); }
  100% { transform: rotate(0) scale(1); }
}

/* Pip layout for d6 — a 3x3 grid, dots placed by [row,col] in JS.
   Padding/gap use the die's own size (calc on --die-size); percentage
   units here resolve against the containing block, not the die, which
   collapses the tracks. Pips use width + aspect-ratio, never a
   percentage height (which resolves to 0 inside fr tracks). */
.dr-die.is-pips {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: calc(var(--die-size) * 0.16);
  gap: calc(var(--die-size) * 0.04);
}
.dr-pip {
  width: 82%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--accent);
  align-self: center;
  justify-self: center;
}

/* ---------- Total ---------- */
.dr-total {
  text-align: center;
  font-size: clamp(17px, 4vw, 20px);
  font-weight: 600;
  color: var(--text);
  min-height: 1.5em;
  margin: 0 0 var(--space-6);
}
.dr-total strong {
  color: var(--accent);
  font-weight: 800;
  font-size: 1.25em;
}

/* ---------- History ---------- */
.dr-history-wrap {
  border-top: 1px solid var(--border);
  padding-top: var(--space-4);
}
.dr-history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-2);
}
.dr-clear {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  color: var(--text-muted);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 12px;
  cursor: pointer;
  transition: var(--transition-colors);
}
.dr-clear:hover { color: var(--text); border-color: var(--accent); }
.dr-history {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 200px;
  overflow-y: auto;
}
.dr-history li {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  font-size: 13px;
  color: var(--text-secondary);
  padding: 5px 2px;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
}
.dr-history li:last-child { border-bottom: none; }
.dr-history .dr-h-notation { font-weight: 600; color: var(--text-muted); flex-shrink: 0; }
.dr-history .dr-h-result { text-align: right; }
.dr-history .dr-h-total { font-weight: 700; color: var(--text); }
.dr-history-empty { color: var(--text-muted); font-size: 13px; padding: 6px 2px; }

@media (max-width: 380px) {
  .dr-controls { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  .dr-die.is-rolling { animation: none; }
}
