/* Non-floating header access keeps table and mobile primary actions unobstructed. */
.global-dice-trigger{display:inline-flex;align-items:center;justify-content:center;width:44px;height:44px;min-width:44px;min-height:44px;flex:0 0 44px;padding:6px;line-height:1;border-radius:10px}.global-dice-trigger .global-dice-icon{display:block;width:30px;height:30px;flex:none;background:none;filter:none;object-fit:contain}.global-dice-trigger:hover .global-dice-icon{transform:rotate(-8deg)}.global-dice-icon{transition:transform .15s}.global-dice-fallback{margin:0 0 1rem auto;cursor:pointer}
.global-dice-dialog{color:var(--theme-on-dark,#edf0f1);background:var(--theme-dark-panel,#15232c);border:1px solid var(--theme-dark-line,#53616b);border-radius:14px;width:min(900px,calc(100vw - 24px));max-width:calc(100vw - 24px);max-height:calc(100dvh - 24px);padding:0;overflow:auto;box-sizing:border-box;overscroll-behavior:contain;box-shadow:0 20px 80px var(--theme-shadow-heavy,#0009)}.global-dice-dialog::backdrop{background:var(--theme-backdrop,rgba(5,12,17,.72))}.global-dice-dialog *{box-sizing:border-box}.global-dice-top{position:sticky;top:0;z-index:2;background:var(--theme-dark-panel,#15232c);display:flex;align-items:center;gap:1rem;justify-content:space-between;border-bottom:1px solid var(--theme-dark-line,#3d505c);padding:.7rem 1rem}.global-dice-top h2{margin:0;font-size:1.2rem}.global-dice-top button{font-size:1.5rem;min-width:44px;min-height:44px}.global-dice-body{padding:1rem;overflow-wrap:anywhere}.global-dice-context{margin-top:0;color:var(--theme-dark-soft,#b9c9d2);font-size:.9rem}.global-dice-notice{padding:.75rem 1rem;margin:0;background:var(--theme-dark-field,#213845)}.global-dice-notice[role=alert]{color:var(--status-error-dark-ink,#ffc2c7)}.global-dice-bottom{display:flex;flex-wrap:wrap;justify-content:space-between;align-items:center;gap:.5rem;border-top:1px solid var(--theme-dark-line,#3d505c);padding:.75rem 1rem;font-size:.8rem;color:var(--theme-dark-soft,#b9c9d2)}.global-dice-dialog button,.global-dice-dialog input,.global-dice-dialog select{font:inherit;max-width:100%;border:1px solid var(--muted,#647983);border-radius:6px;background:var(--theme-dark-panel,#172d39);color:var(--theme-on-dark,#f4f5f5);padding:.55rem .7rem;min-height:42px}.global-dice-dialog button{cursor:pointer}.global-dice-dialog button.primary{background:var(--gold,#e8bc70);color:var(--theme-dark-ink,#15232c)}.global-dice-dialog :focus-visible{outline:3px solid var(--theme-dark-highlight,#f1c572);outline-offset:3px}.global-dice-dialog [disabled]{opacity:.55;cursor:wait}.global-dice-dialog .grid.two,.global-dice-dialog .form-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:1rem}.global-dice-dialog .full{grid-column:1/-1}.global-dice-dialog .field{display:flex;flex-direction:column;gap:.35rem;min-width:0}.global-dice-dialog .panel{margin-bottom:1rem;padding:1rem;border:1px solid var(--theme-dark-line,#3d505c);border-radius:9px;background:var(--theme-dark-panel,#10202a)}.global-dice-dialog .panel-top,.global-dice-dialog .actions{display:flex;align-items:center;flex-wrap:wrap;gap:.5rem;justify-content:space-between}.global-dice-dialog .panel h2{font-size:1.05rem;margin-top:0}.global-dice-dialog .hint{font-size:.85rem;color:var(--theme-dark-soft,#b9c9d2)}.global-dice-dialog .roll-total{font-size:2.5rem;font-weight:700}.global-dice-dialog .form-error{color:var(--status-error-dark-ink,#ffc2c7)}.global-dice-dialog .dice-breakdown>div{display:flex;justify-content:space-between;gap:1rem;border-bottom:1px solid var(--theme-dark-line,#3d505c);padding:.5rem 0}.global-dice-dialog .dice-favorites,.global-dice-dialog .dice-history{list-style:none;padding:0;margin:0}.global-dice-dialog .dice-favorites>li,.global-dice-dialog .dice-history>li{padding:.75rem 0;border-bottom:1px solid var(--theme-dark-line,#3d505c)}.global-dice-dialog summary{cursor:pointer;padding:.5rem 0}.global-dice-dialog summary>span{display:block}.global-dice-dialog .sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap}.global-dice-dialog [hidden]{display:none!important}#dialog .dialog-top>[data-global-dice]{font-size:.8rem;margin-left:auto;white-space:nowrap;min-height:40px}#dialog .dialog-top>h2{min-width:0}
@media(max-width:600px){.global-dice-dialog{width:calc(100vw - 12px);max-width:calc(100vw - 12px);max-height:calc(100dvh - 12px);border-radius:10px}.global-dice-body{padding:.7rem}.global-dice-dialog .grid.two,.global-dice-dialog .form-grid{grid-template-columns:minmax(0,1fr)}.global-dice-dialog .panel{padding:.75rem}.global-dice-dialog .dice-breakdown>div{flex-direction:column;gap:.25rem}.global-dice-bottom{padding:.6rem}.global-dice-dialog .actions>button{flex:1 1 auto}.topbar-tools{flex-wrap:wrap}#dialog .dialog-top{gap:.4rem}#dialog .dialog-top>[data-global-dice]{padding:.4rem}}
@media print{[data-global-dice],.global-dice-dialog,.global-dice-fallback{display:none!important}}
/* Shared dialog headings must never compete with Dice Roller or Close targets. */
#dialog .dialog-top{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:.65rem;align-items:center}
#dialog .dialog-top.has-dice-shortcut{grid-template-columns:minmax(0,1fr) auto auto}
#dialog .dialog-top>h2{min-width:0;overflow-wrap:anywhere;order:0;grid-column:1;grid-row:1}
#dialog .dialog-top>[data-global-dice]{margin-left:0;min-width:max-content;min-height:44px;justify-self:end;order:0;grid-column:2;grid-row:1}
#dialog .dialog-top>#dialog-close{min-width:44px;min-height:44px;justify-self:end;order:0;grid-column:2;grid-row:1}
#dialog .dialog-top.has-dice-shortcut>#dialog-close{grid-column:3}
@media(max-width:600px){#dialog .dialog-top{padding:.8rem;gap:.6rem}#dialog .dialog-top.has-dice-shortcut{grid-template-columns:minmax(0,1fr) auto}#dialog .dialog-top.has-dice-shortcut>h2{grid-column:1/-1;grid-row:1}#dialog .dialog-top>[data-global-dice]{justify-self:start;grid-column:1;grid-row:2}#dialog .dialog-top.has-dice-shortcut>#dialog-close{grid-column:2;grid-row:2}}

/* Dice controls show the result first; explanations and records expand on demand. */
.dice-controls .dice-quick{display:grid;grid-template-columns:repeat(7,minmax(0,1fr));gap:.3rem;margin:0 0 .8rem}
.dice-quick button{min-width:0;min-height:44px;padding:.4rem .1rem;font-size:.83rem;white-space:nowrap}
.dice-controls .form-grid{gap:0 .75rem}.dice-controls .field{margin-bottom:.7rem}.dice-controls .actions{gap:.5rem;justify-content:flex-start}
.dice-mode-help{margin:.1rem 0 .7rem;font-weight:400}.dice-mode-help[hidden]{display:none!important}
.dice-formula-help{margin-top:.55rem;font-size:.83rem;font-weight:400}.dice-formula-help>summary{cursor:pointer;min-height:44px;padding:.65rem 0;color:var(--teal,#0c6e72)}
.dice-formula-help p{margin:.35rem 0 .8rem;line-height:1.5}.dice-formula-help:focus-within{border-radius:4px}
.dice-roll-settings{margin-top:.6rem;font-size:.85rem;font-weight:400}.dice-roll-settings>summary{cursor:pointer;min-height:44px;padding:.65rem 0;color:var(--teal,#0c6e72)}
.dice-roll-settings>summary:focus-visible{outline:3px solid var(--teal,#0c6e72);outline-offset:2px;border-radius:4px}.dice-roll-settings-body{padding:.25rem 0 .5rem}.dice-confirm-option{display:flex;align-items:center;gap:.6rem;min-height:44px;cursor:pointer}.dice-confirm-option input[type=checkbox]{width:20px;min-width:20px;height:20px;margin:0;accent-color:var(--teal,#0c6e72)}.dice-confirm-option:has(input:disabled){opacity:.65;cursor:default}.dice-roll-settings .hint{margin:.3rem 0 0}
.global-dice-dialog .dice-roll-settings>summary{color:var(--theme-dark-accent,#badbd8)}.global-dice-dialog .dice-roll-settings>summary:focus-visible{outline-color:var(--theme-dark-highlight,#f1c572)}
.dice-section{border:1px solid var(--line,#cad5db);border-radius:7px;margin:0 0 .65rem;background:var(--white,#fff)}
.dice-section>summary{cursor:pointer;min-height:48px;padding:.7rem 1rem;font-size:.9rem;font-weight:650}
.dice-section-count{display:inline;font-weight:400;font-size:.8rem;color:var(--muted,var(--muted,#536470));margin-left:.35rem}
.dice-section-body{padding:0 1rem 1rem}.dice-section-body>.panel{margin:0;box-shadow:none}
.dice-section summary:focus-visible,.dice-formula-help summary:focus-visible,.dice-result-details summary:focus-visible{outline:3px solid var(--teal,#0c6e72);outline-offset:2px;border-radius:4px}
.dice-result-summary{display:flex;align-items:center;gap:1rem;margin:.25rem 0 .4rem}.dice-result-summary>p{margin:0;font-size:.9rem;overflow-wrap:anywhere}
.dice-result-details>summary{cursor:pointer;min-height:44px;padding:.55rem 0;font-size:.85rem}.dice-result-details .dice-breakdown{margin:.3rem 0}
.dice-layout .roll-result{align-self:start;padding:1.25rem}.dice-layout .roll-result h2{font-size:1.05rem;margin:0 0 .5rem}
.dice-layout .roll-result .dice-result-details>summary:focus-visible{outline-color:var(--theme-dark-highlight,#f1c572)}
.global-dice-dialog .dice-section{background:var(--theme-dark-panel,#10202a);border-color:var(--theme-dark-line,#3d505c);color:var(--theme-on-dark,#edf0f1)}
.global-dice-dialog .dice-section>summary{padding:.65rem .8rem;min-height:46px}.global-dice-dialog .dice-section-count{display:inline;color:var(--theme-dark-soft,#b9c9d2)}
.global-dice-dialog .dice-formula-help>summary{color:var(--theme-dark-accent,#badbd8)}.global-dice-dialog .dice-formula-help p{color:var(--theme-dark-muted,#c4d4de)}
.global-dice-dialog .dice-controls .form-grid{gap:0 .7rem}.global-dice-dialog .dice-controls .field{font-size:.85rem;color:var(--theme-on-dark,#edf0f1)}
.global-dice-dialog .dice-controls .actions{justify-content:flex-start}.global-dice-dialog .dice-layout{gap:.75rem}
.global-dice-dialog .dice-controls .dice-quick button{min-height:44px;padding:.4rem .1rem;font-size:.8rem}
.global-dice-dialog .dice-section summary:focus-visible,.global-dice-dialog .dice-formula-help summary:focus-visible,.global-dice-dialog .dice-result-details summary:focus-visible{outline-color:var(--theme-dark-highlight,#f1c572)}
.global-dice-dialog .form-error:not(:empty){display:block;background:var(--status-error-dark-surface,#3b2028);color:var(--status-error-dark-ink,#ffdce1);border:1px solid var(--status-error-dark-border,#ef9ca8);padding:.75rem}
.global-dice-dialog #global-local-result{margin-top:1rem}.global-dice-dialog #global-local-form .form-grid{grid-template-columns:minmax(0,1fr) minmax(0,1fr)}
@media(max-width:600px){.global-dice-dialog .dice-controls .form-grid{grid-template-columns:minmax(0,1fr) minmax(0,1fr)}.global-dice-dialog .dice-layout>.panel{margin-bottom:0}.global-dice-dialog .dice-layout{margin-bottom:.7rem}.dice-result-summary .roll-total{font-size:2.8rem}.dice-section-body{padding:0 .7rem .7rem}}
@media(max-width:360px){.dice-controls .dice-quick{grid-template-columns:repeat(4,minmax(0,1fr))}.global-dice-dialog .dice-controls .form-grid,.global-dice-dialog #global-local-form .form-grid{grid-template-columns:minmax(0,1fr)}}

@media(prefers-reduced-motion:reduce){.global-dice-icon{transition:none}.global-dice-trigger:hover .global-dice-icon{transform:none}}
