.dice-header-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 7px 13px;
  border-color: color-mix(in srgb, var(--accent-2) 44%, var(--line));
  color: var(--ink);
  white-space: nowrap;
}

.dice-header-button span:first-child { color: var(--accent-2); font-size: 20px; line-height: 1; }
.dice-header-button:hover { background: color-mix(in srgb, var(--accent-2) 15%, var(--panel)); }

#diceTrayRoot { position: relative; z-index: 3100; }
.dice-overlay { position: fixed; inset: 0; background: rgba(7, 5, 4, .72); }
.dice-panel {
  --die-face: #8d293c;
  --die-ink: #fff4dd;
  position: fixed;
  z-index: 1;
  top: 2vh;
  right: 1.5vw;
  width: min(1120px, 97vw);
  height: 96vh;
  height: 96dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--accent-2) 43%, var(--line));
  border-radius: 12px;
  background: var(--bg);
  color: var(--ink);
  box-shadow: 0 26px 80px rgba(0, 0, 0, .54);
}
.dice-panel[data-dice-theme="azure"], .dice-swatch [data-dice-theme="azure"] { --die-face: #2b5e81; --die-ink: #f5faff; }
.dice-panel[data-dice-theme="forest"], .dice-swatch [data-dice-theme="forest"] { --die-face: #276b49; --die-ink: #f3ffe9; }
.dice-panel[data-dice-theme="amethyst"], .dice-swatch [data-dice-theme="amethyst"] { --die-face: #69437f; --die-ink: #fff0ff; }
.dice-panel[data-dice-theme="gold"], .dice-swatch [data-dice-theme="gold"] { --die-face: #aa792e; --die-ink: #20160e; }
.dice-panel[data-dice-theme="obsidian"], .dice-swatch [data-dice-theme="obsidian"] { --die-face: #24242c; --die-ink: #fff6e5; }
.dice-panel[data-dice-theme="ivory"], .dice-swatch [data-dice-theme="ivory"] { --die-face: #eee1bf; --die-ink: #392b24; }
.dice-panel[data-dice-theme="copper"], .dice-swatch [data-dice-theme="copper"] { --die-face: #a95433; --die-ink: #fff3de; }
.dice-panel[data-dice-theme="rose"], .dice-swatch [data-dice-theme="rose"] { --die-face: #a94f68; --die-ink: #fff5f8; }
.dice-panel[data-dice-theme="turquoise"], .dice-swatch [data-dice-theme="turquoise"] { --die-face: #247a79; --die-ink: #f4ffff; }
.dice-swatch [data-dice-theme="wine"] { --die-face: #8d293c; --die-ink: #fff4dd; }

.dice-panel button, .dice-panel select { cursor: pointer; }
.dice-panel button:disabled { cursor: not-allowed; opacity: .45; }
.dice-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 73px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel-2) 72%, var(--panel));
}
.dice-eyebrow { color: var(--accent-2); font-size: 10px; font-weight: 800; letter-spacing: .1em; }
.dice-panel-header h2 { margin: 1px 0 0; font-size: 20px; line-height: 1.2; }
.dice-panel-header .icon-button { flex: 0 0 36px; min-width: 36px; min-height: 36px; padding: 0; }
.dice-panel-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(250px, 29%); flex: 1; min-height: 0; }
.dice-panel-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.dice-tray {
  flex: 0 0 68%;
  min-height: 0;
  padding: 14px;
  overflow: auto;
  background: color-mix(in srgb, var(--panel-2) 67%, var(--panel));
}
.dice-tray-empty { display: grid; align-content: center; justify-items: center; height: 100%; color: var(--muted); }
.dice-tray-empty p { margin: 6px 0; }
.dice-tray-mark { font-size: 70px; color: color-mix(in srgb, var(--accent-2) 42%, var(--muted)); }
.dice-tray-outcome { display: flex; flex-direction: column; gap: 16px; min-height: 100%; }
.dice-result-head, .dice-result-total { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dice-result-head { color: var(--muted); font-size: 11px; font-weight: 800; }
.dice-result-dice-list { display: flex; align-content: center; align-items: center; justify-content: center; flex: 1; flex-wrap: wrap; gap: 12px; }
.dice-result-die {
  display: grid;
  place-items: center;
  align-content: center;
  width: 73px;
  height: 73px;
  flex: 0 0 73px;
  background: var(--die-face);
  color: var(--die-ink);
  clip-path: polygon(50% 1%, 94% 24%, 94% 76%, 50% 99%, 6% 76%, 6% 24%);
  filter: drop-shadow(0 6px 3px rgba(0,0,0,.16));
  text-align: center;
}
.dice-result-die[data-type="d4"] { clip-path: polygon(50% 2%, 98% 96%, 2% 96%); }
.dice-result-die[data-type="d6"] { clip-path: polygon(8% 8%, 92% 8%, 92% 92%, 8% 92%); }
.dice-result-die[data-type="d8"] { clip-path: polygon(50% 1%, 97% 50%, 50% 99%, 3% 50%); }
.dice-result-die[data-type="d10"] { clip-path: polygon(50% 1%, 95% 36%, 82% 86%, 50% 99%, 18% 86%, 5% 36%); }
.dice-result-die[data-type="d20"] { clip-path: polygon(50% 1%, 87% 16%, 99% 50%, 87% 84%, 50% 99%, 13% 84%, 1% 50%, 13% 16%); }
.dice-result-die[data-type="d100"] { width: 88px; flex-basis: 88px; }
.dice-result-die span { font-size: 10px; opacity: .9; }
.dice-result-die strong { font-size: 27px; line-height: 1; }
.dice-result-die small { font-size: 10px; }
.dice-panel[data-animating="true"] .dice-result-die { animation: dice-land .78s cubic-bezier(.16,.85,.34,1) both; animation-delay: calc(var(--die-order) * 8ms); }
@keyframes dice-land {
  0% { opacity: .3; transform: translate(20px,-36px) rotate(105deg) scale(.72); }
  65% { opacity: 1; transform: translate(-5px,5px) rotate(-12deg) scale(1.06); }
  100% { transform: translate(0,0) rotate(0) scale(1); }
}
.dice-result-total { margin-top: auto; padding: 9px 16px; border-top: 1px solid var(--line); color: var(--accent-2); font-weight: 800; }
.dice-result-total strong { font-size: 34px; line-height: 1; }

.dice-controls { position: relative; display: flex; flex: 1; flex-direction: column; justify-content: space-between; gap: 8px; min-height: 0; padding: 12px 15px; overflow: auto; border-top: 1px solid var(--line); }
.dice-selection-summary { display: flex; align-items: center; gap: 9px; min-height: 28px; color: var(--muted); font-size: 12px; }
.dice-selection-summary > span { white-space: nowrap; }
.dice-selection-summary .ghost { min-height: 27px; padding: 3px 8px; font-size: 11px; }
.dice-selected-list { display: flex; flex: 1; flex-wrap: wrap; align-items: center; gap: 4px; }
.dice-selected-token { display: inline-flex; align-items: center; gap: 4px; padding: 1px 4px 1px 7px; border: 1px solid var(--line); border-radius: 4px; color: var(--ink); background: var(--panel-2); font-weight: 700; }
.dice-selected-token button { min-width: 19px; min-height: 19px; padding: 0; border: 0; background: transparent; color: var(--ink); }
.dice-picker { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.dice-pick { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-width: 0; min-height: 60px; padding: 5px 2px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel-2); color: var(--ink); font-size: 12px; }
.dice-pick:hover { border-color: var(--accent-2); }
.dice-pick-add { position: absolute; top: 1px; right: 6px; color: var(--accent-2); font-size: 14px; font-weight: 800; }
.dice-pick-shape { width: 20px; height: 20px; background: var(--die-face); clip-path: polygon(50% 0, 98% 27%, 98% 73%, 50% 100%, 2% 73%, 2% 27%); }
.dice-pick-shape[data-type="d4"] { clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.dice-pick-shape[data-type="d6"] { clip-path: inset(0 0 0 0); }
.dice-control-bottom { display: flex; align-items: end; gap: 9px; }
.dice-color-control { position: relative; flex: 1; min-width: 0; }
.dice-color-control > button { min-height: 38px; width: 100%; white-space: nowrap; }
.dice-palette { position: absolute; z-index: 3; left: 0; bottom: calc(100% + 7px); display: grid; grid-template-columns: repeat(5, 30px); gap: 5px; padding: 8px; border: 1px solid var(--line); border-radius: 5px; background: var(--panel); box-shadow: var(--shadow); }
.dice-swatch { display: grid; place-items: center; width: 30px; height: 30px; padding: 3px; border: 1px solid transparent; border-radius: 4px; background: transparent; }
.dice-swatch[aria-pressed="true"] { border-color: var(--accent-2); }
.dice-swatch span { width: 20px; height: 20px; border-radius: 50%; background: var(--die-face); border: 1px solid color-mix(in srgb, var(--ink) 45%, transparent); }
.dice-privacy { display: grid; gap: 2px; min-width: 122px; color: var(--muted); font-size: 11px; }
.dice-privacy select { width: 100%; min-height: 38px; color: var(--ink); background: var(--panel-2); border: 1px solid var(--line); }
.dice-roll-button { min-width: 100px; min-height: 38px; background: var(--accent); color: #fff; font-weight: 800; }
.dice-status { min-height: 15px; margin: 0; color: var(--muted); font-size: 11px; }

.dice-history { display: flex; flex-direction: column; min-width: 0; min-height: 0; border-left: 1px solid var(--line); }
.dice-history-top { padding: 14px; border-bottom: 1px solid var(--line); }
.dice-history-top h3 { margin: 0 0 9px; font-size: 16px; }
.dice-history-filters { display: flex; gap: 4px; flex-wrap: wrap; }
.dice-history-filters button { padding: 5px 8px; border: 1px solid var(--line); border-radius: 4px; background: transparent; color: var(--muted); font-size: 11px; }
.dice-history-filters button[aria-pressed="true"] { background: color-mix(in srgb, var(--accent-2) 18%, var(--panel)); color: var(--ink); border-color: var(--accent-2); }
.dice-history-list { flex: 1; min-height: 0; overflow: auto; padding: 10px; }
.dice-history-item { margin-bottom: 8px; padding: 11px; border: 1px solid var(--line); border-radius: 5px; background: var(--panel-2); overflow-wrap: anywhere; }
.dice-history-heading { display: flex; justify-content: space-between; gap: 8px; }
.dice-history-heading time, .dice-history-item small { color: var(--muted); font-size: 11px; }
.dice-history-item small { display: block; margin: 5px 0; }
.dice-history-formula { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--accent-2); font-size: 13px; }
.dice-history-formula strong { font-size: 23px; }
.dice-history-item details { margin-top: 6px; font-size: 12px; }
.dice-history-item summary { cursor: pointer; color: var(--ink); }
.dice-history-results { display: flex; gap: 6px; flex-wrap: wrap; margin: 7px 0; }
.dice-history-results span { padding: 3px 5px; border-radius: 3px; background: color-mix(in srgb, var(--die-face) 22%, var(--panel)); }
.dice-history-item p { margin: 5px 0; color: var(--muted); }
.dice-empty { color: var(--muted); }
.dice-mobile-tabs { display: none; }

#diceNotificationRoot { position: fixed; z-index: 3200; top: 90px; right: 18px; display: grid; gap: 8px; pointer-events: none; }
.dice-notification { max-width: min(330px, 90vw); padding: 10px 14px; border: 1px solid var(--accent-2); border-radius: 5px; background: var(--panel); color: var(--ink); box-shadow: var(--shadow); font-size: 12px; }

@media (max-width: 900px) {
  .dice-panel { inset: 0; width: 100vw; height: 100vh; height: 100dvh; max-width: 100vw; border-radius: 0; }
  .dice-mobile-tabs { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid var(--line); }
  .dice-mobile-tabs button { min-height: 43px; border: 0; border-bottom: 2px solid transparent; background: var(--panel); color: var(--muted); }
  .dice-mobile-tabs button[aria-selected="true"] { border-bottom-color: var(--accent-2); color: var(--ink); font-weight: 800; }
  .dice-panel-body { display: block; overflow: hidden; }
  .dice-panel-main, .dice-history { height: 100%; }
  .dice-panel-body[data-mobile-tab="tray"] .dice-history, .dice-panel-body[data-mobile-tab="history"] .dice-panel-main { display: none; }
  .dice-history { border-left: 0; }
}

@media (max-width: 520px) {
  .dice-header-button { min-width: 40px; padding: 7px; }
  .dice-header-button span:last-child { display: none; }
  .dice-panel-header { min-height: 65px; padding: 10px 13px; }
  .dice-panel-header h2 { font-size: 17px; }
  .dice-tray { flex-basis: 65%; padding: 10px; }
  .dice-controls { padding: 8px; gap: 7px; }
  .dice-picker { gap: 3px; }
  .dice-pick { min-height: 50px; font-size: 11px; }
  .dice-pick-shape { width: 16px; height: 16px; }
  .dice-selection-summary { flex-wrap: wrap; }
  .dice-control-bottom { gap: 5px; }
  .dice-color-control > button, .dice-privacy select { padding-left: 5px; padding-right: 5px; font-size: 11px; }
  .dice-privacy { min-width: 88px; }
  .dice-roll-button { min-width: 73px; padding: 5px; }
  .dice-result-die { width: 58px; height: 58px; flex-basis: 58px; }
  .dice-result-die[data-type="d100"] { width: 70px; flex-basis: 70px; }
  .dice-result-die strong { font-size: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  .dice-panel[data-animating="true"] .dice-result-die { animation: none; }
}

@media print {
  #diceTrayRoot, #diceNotificationRoot, #diceTrayButton { display: none !important; }
}
