:root {
  --ink: #f8f5f0;
  --muted: #9898a9;
  --panel: #181a26;
  --panel-light: #222433;
  --line: rgba(255, 255, 255, .1);
  --accent: #ffb84d;
  --accent-soft: #ffd68b;
  --purple: #9b8cff;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  background: #11131c;
  font-family: "Atkinson Hyperlegible", "Segoe UI", Arial, sans-serif;
}

button { font: inherit; }
.app-shell { min-height: 100vh; display: grid; grid-template-rows: 2fr 1fr; overflow: hidden; }
.roll-stage {
  position: relative;
  min-height: 66vh;
  background: radial-gradient(circle at 50% 46%, #282a3d 0, #191b29 42%, #11131c 80%);
  isolation: isolate;
}
.roll-stage.critical-fail { animation: critical-flash .8s ease-out; }
.roll-stage::before, .roll-stage::after { content: ""; position: absolute; z-index: -1; border: 1px solid rgba(155,140,255,.13); border-radius: 50%; }
.roll-stage::before { width: 55vw; height: 55vw; max-width: 680px; max-height: 680px; left: 50%; top: 50%; transform: translate(-50%, -43%); }
.roll-stage::after { width: 70vw; height: 70vw; max-width: 860px; max-height: 860px; left: 50%; top: 50%; transform: translate(-50%, -43%); opacity: .5; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 27px 5vw; }
.brand-mark { display: grid; place-items: center; width: 37px; height: 37px; border-radius: 11px; color: #25202b; background: var(--accent); font-size: 21px; box-shadow: 0 0 25px rgba(255,184,77,.2); }
h1, h2, p { margin: 0; }
h1 { font-size: 20px; line-height: 1; letter-spacing: -.03em; }
.topbar p { margin-top: 5px; color: var(--muted); font-size: 12px; }
.tool-link { margin-left: auto; color: var(--accent-soft); font-size: 12px; text-decoration: none; }
.tool-link:hover { color: var(--ink); text-decoration: underline; }
.live-dot { display: flex; align-items: center; gap: 7px; margin-left: auto; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .09em; }
.live-dot span { width: 7px; height: 7px; border-radius: 50%; background: #72e6a5; box-shadow: 0 0 9px #72e6a5; }
.roll-content { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: calc(66vh - 90px); padding: 20px; text-align: center; }
.eyebrow { color: var(--purple); font-size: 12px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; }
.result-wrap { display: flex; flex-direction: column; align-items: center; margin: 10px 0 27px; }
.result-number { color: var(--accent-soft); font-size: clamp(110px, 20vw, 220px); font-weight: 600; letter-spacing: -.1em; line-height: .9; text-indent: -.1em; text-shadow: 0 0 40px rgba(255,184,77,.12); transition: transform .15s ease; }
.result-number.bump { transform: scale(1.08); }
.result-number.rolling { animation: dice-roll .48s ease-in-out; }
.result-caption { margin-top: 13px; color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .12em; }
.roll-button { display: flex; align-items: center; justify-content: center; gap: 10px; min-width: 210px; padding: 14px 20px; border: 1px solid rgba(255,214,139,.5); border-radius: 12px; color: #211d19; background: var(--accent); box-shadow: 0 7px 25px rgba(255,184,77,.16); cursor: pointer; font-weight: 700; transition: transform .15s ease, background .15s ease; }
.roll-button:hover { background: #ffc86b; transform: translateY(-2px); }
.roll-button:active { transform: translateY(1px) scale(.98); }
.roll-button.rolling .roll-icon { animation: icon-spin .48s ease-in-out; }
.roll-button:focus-visible, .die-option:focus-visible, .reset-button:focus-visible { outline: 3px solid var(--purple); outline-offset: 3px; }
.roll-icon { font-size: 21px; line-height: 0; }
kbd { margin-left: 5px; padding: 3px 5px; border: 1px solid rgba(33,29,25,.25); border-radius: 4px; font-size: 11px; }
.helper-text { margin-top: 12px; color: #696a7a; font-size: 11px; }
.controls-panel { display: flex; flex-direction: column; justify-content: center; gap: 18px; padding: 27px 5vw 30px; border-top: 1px solid var(--line); background: var(--panel); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; }
h2 { margin-top: 5px; font-size: 22px; letter-spacing: -.04em; }
.die-display { color: var(--accent); font-size: 17px; font-weight: 700; }
.die-options { display: grid; grid-template-columns: repeat(6, 1fr); gap: 9px; }
.die-option { padding: 13px 4px; border: 1px solid var(--line); border-radius: 9px; color: #c0bfca; background: var(--panel-light); cursor: pointer; font-size: 15px; font-weight: 700; transition: color .15s, border-color .15s, background .15s; }
.die-option:hover { border-color: rgba(255,184,77,.6); color: var(--ink); }
.die-option.selected { border-color: var(--accent); color: #241e16; background: var(--accent); font-weight: 500; }
.tally-card { display: grid; grid-template-columns: 1fr auto; gap: 13px 20px; padding: 13px 15px; border: 1px solid var(--line); border-radius: 11px; background: rgba(255,255,255,.025); }
.switch-row { display: flex; align-items: center; gap: 11px; cursor: pointer; }
.switch { position: relative; display: block; width: 37px; height: 21px; }
.switch input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.slider { position: absolute; inset: 0; border-radius: 30px; background: #3d3e4c; transition: background .2s; }
.slider::before { content: ""; position: absolute; width: 15px; height: 15px; left: 3px; top: 3px; border-radius: 50%; background: #aaaab5; transition: transform .2s, background .2s; }
.switch input:checked + .slider { background: var(--purple); }
.switch input:checked + .slider::before { transform: translateX(16px); background: white; }
.switch-copy { display: flex; flex-direction: column; gap: 2px; }
.switch-copy strong { font-size: 13px; font-weight: 500; }
.switch-copy small { color: var(--muted); font-size: 10px; }
.tally-total { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; }
.tally-total strong { color: var(--accent-soft); font-size: 23px; }
.roll-history { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; max-height: 45px; margin: 0; padding: 10px 0 0; overflow-y: auto; border-top: 1px solid var(--line); list-style: none; }
.roll-history li { padding: 4px 8px; border-radius: 5px; color: #d7d5df; background: var(--panel-light); font-size: 12px; }
.roll-history li strong { color: var(--accent-soft); }
.roll-history .history-empty { padding: 0; color: #727282; background: transparent; font-size: 11px; }
.all-history-section { grid-column: 1 / -1; padding-top: 2px; }
.history-heading { margin-bottom: 7px; color: var(--purple); font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.all-history { display: flex; flex-wrap: wrap; gap: 6px; max-height: 60px; margin: 0; padding: 0; overflow-y: auto; list-style: none; }
.all-history li { padding: 4px 8px; border-radius: 5px; color: #d7d5df; background: var(--panel-light); font-size: 12px; }
.all-history li strong { color: var(--accent-soft); }
.all-history .history-empty { padding: 0; color: #727282; background: transparent; font-size: 11px; }
.history-actions { display: flex; justify-content: flex-end; gap: 16px; }
.reset-button { align-self: flex-end; padding: 0; border: 0; color: #727282; background: transparent; cursor: pointer; font-size: 11px; }
.reset-button:hover { color: var(--accent-soft); }

@keyframes dice-roll {
  0% { transform: rotate(0deg) scale(1); filter: blur(0); opacity: 1; }
  25% { transform: rotate(-10deg) scale(.88); filter: blur(3px); opacity: .72; }
  50% { transform: rotate(12deg) scale(1.08); filter: blur(5px); opacity: .5; }
  75% { transform: rotate(-7deg) scale(.94); filter: blur(2px); opacity: .8; }
  100% { transform: rotate(0deg) scale(1); filter: blur(0); opacity: 1; }
}

@keyframes icon-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes critical-flash {
  0%, 100% { background: radial-gradient(circle at 50% 46%, #282a3d 0, #191b29 42%, #11131c 80%); box-shadow: inset 0 0 0 rgba(202, 74, 81, 0); }
  25% { background: radial-gradient(circle at 50% 46%, #713440 0, #4b2635 42%, #241823 80%); box-shadow: inset 0 0 110px rgba(202, 74, 81, .48); }
  55% { background: radial-gradient(circle at 50% 46%, #482735 0, #2b202e 42%, #17151f 80%); box-shadow: inset 0 0 65px rgba(202, 74, 81, .2); }
}

@media (max-width: 560px) {
  .app-shell { grid-template-rows: auto auto; }
  .roll-stage { min-height: 64vh; }
  .roll-content { min-height: calc(64vh - 90px); }
  .topbar { padding: 22px 6vw; }
  .controls-panel { padding: 25px 6vw 28px; }
  .die-options { gap: 6px; }
  .die-option { padding: 11px 2px; font-size: 12px; }
}



