:root {
  --bg: #f5f7fb;
  --bg-soft: #eef2f8;
  --panel: rgba(255,255,255,0.82);
  --panel-strong: rgba(255,255,255,0.96);
  --text: #121826;
  --muted: #69758a;
  --line: rgba(18,24,38,.09);
  --line-strong: rgba(18,24,38,.14);
  --accent: #6aa7ff;
  --accent-2: #9fc5ff;
  --white: #ffffff;
  --shadow: 0 30px 80px rgba(44, 62, 96, .14);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 50% -15%, rgba(106,167,255,.22), transparent 38%),
    radial-gradient(circle at 100% 65%, rgba(159,197,255,.18), transparent 28%),
    linear-gradient(180deg, #fbfcfe 0%, #f3f6fb 100%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

button { font: inherit; }
button:focus-visible, [role="button"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }

.ambient {
  position: fixed;
  width: 520px;
  height: 520px;
  border-radius: 50%;
  filter: blur(110px);
  pointer-events: none;
  opacity: .55;
}
.ambient-a { left: -220px; top: 10%; background: rgba(177, 214, 255, .95); }
.ambient-b { right: -240px; bottom: -120px; background: rgba(223, 236, 255, .95); }
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .03;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.5'/%3E%3C/svg%3E");
}

.app-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
  position: relative;
  z-index: 1;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  color: #2f4a72;
  background: linear-gradient(145deg, #ffffff, #e7eef8);
  box-shadow: 0 10px 28px rgba(66, 96, 140, .15), inset 0 1px 0 rgba(255,255,255,.92);
  border: 1px solid rgba(47,74,114,.08);
  font-size: 22px;
}
.eyebrow {
  color: #6f7f97;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .18em;
}
.brand-title { font-size: 18px; font-weight: 900; letter-spacing: -.02em; }
.icon-btn, .text-btn {
  border: 1px solid var(--line);
  color: var(--text);
  background: rgba(255,255,255,.72);
  cursor: pointer;
  transition: .2s ease;
  box-shadow: 0 8px 24px rgba(44,62,96,.08);
}
.icon-btn:hover, .text-btn:hover { background: rgba(255,255,255,.96); border-color: var(--line-strong); }
.icon-btn { width: 42px; height: 42px; border-radius: 14px; }
.text-btn { padding: 9px 12px; border-radius: 12px; color: var(--muted); font-size: 12px; }

.hero {
  min-height: 650px;
  display: grid;
  place-items: center;
  align-content: center;
  padding: 48px 0 26px;
  text-align: center;
}
.hero-copy { max-width: 720px; margin-bottom: 12px; }
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 12px;
  border: 1px solid rgba(86,125,179,.16);
  border-radius: 999px;
  color: #5e7390;
  background: rgba(255,255,255,.78);
  box-shadow: 0 8px 24px rgba(44,62,96,.06);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .16em;
}
h1 {
  margin: 14px 0 8px;
  font-size: clamp(48px, 8vw, 88px);
  line-height: .94;
  letter-spacing: -.06em;
}
h1 span {
  background: linear-gradient(100deg, #0f1728 0%, #5a8ee0 42%, #9bc0ff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero-copy p {
  max-width: 590px;
  margin: 14px auto 0;
  color: var(--muted);
  font-size: clamp(14px, 2vw, 17px);
  line-height: 1.6;
}

.dice-stage {
  position: relative;
  width: min(440px, 88vw);
  height: 340px;
  display: grid;
  place-items: center;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.d12-wrap { position: relative; width: 230px; height: 230px; display: grid; place-items: center; }
.d12-shadow {
  position: absolute;
  width: 164px;
  height: 34px;
  border-radius: 50%;
  bottom: -18px;
  background: rgba(99, 121, 158, .22);
  filter: blur(15px);
  transform: scaleX(1.25);
}
.d12 {
  width: 196px;
  aspect-ratio: 1;
  position: relative;
  display: grid;
  place-items: center;
  clip-path: polygon(50% 0%, 79% 9%, 97% 32%, 97% 68%, 79% 91%, 50% 100%, 21% 91%, 3% 68%, 3% 32%, 21% 9%);
  background:
    radial-gradient(circle at 30% 24%, rgba(255,255,255,.95), transparent 23%),
    linear-gradient(145deg, #ffffff 0%, #f6f8fc 34%, #e5ebf4 68%, #ffffff 100%);
  border: 1px solid rgba(121, 146, 184, .15);
  box-shadow:
    inset -24px -30px 50px rgba(136, 157, 192, .18),
    inset 22px 22px 34px rgba(255,255,255,.95),
    0 24px 40px rgba(63, 84, 118, .18),
    0 4px 18px rgba(255,255,255,.65);
  filter: drop-shadow(0 18px 28px rgba(63,84,118,.12));
  transform: rotate(-4deg) scale(1);
  transition: transform .2s ease;
}
.d12::before {
  content: "";
  position: absolute;
  inset: 7px;
  clip-path: inherit;
  border: 1px solid rgba(122, 145, 178, .18);
  background: linear-gradient(180deg, rgba(255,255,255,.18), rgba(180,195,220,.08));
}
.dice-stage:hover .d12 { transform: rotate(2deg) scale(1.035); }

.facet {
  position: absolute;
  pointer-events: none;
  opacity: .95;
  border: 1px solid rgba(138, 160, 193, .22);
  background: linear-gradient(135deg, rgba(255,255,255,.95), rgba(226,233,244,.65));
  box-shadow: inset 0 1px 0 rgba(255,255,255,.75);
}
.f1 { width: 92px; height: 82px; top: 20px; left: 49px; clip-path: polygon(50% 0,100% 38%,81% 100%,19% 100%,0 38%); }
.f2 { width: 75px; height: 91px; top: 52px; left: 8px; clip-path: polygon(20% 0,100% 22%,80% 100%,0 75%); }
.f3 { width: 75px; height: 91px; top: 52px; right: 8px; clip-path: polygon(80% 0,0 22%,20% 100%,100% 75%); }
.f4 { width: 82px; height: 78px; bottom: 13px; left: 19px; clip-path: polygon(8% 0,100% 18%,82% 100%,20% 90%); }
.f5 { width: 82px; height: 78px; bottom: 13px; right: 19px; clip-path: polygon(92% 0,0 18%,18% 100%,80% 90%); }
.f6 { width: 98px; height: 84px; left: 46px; top: 55px; clip-path: polygon(50% 0,97% 34%,79% 100%,21% 100%,3% 34%); background: linear-gradient(145deg, rgba(255,255,255,.98), rgba(230,237,246,.72)); }
.dice-shine {
  position: absolute;
  width: 62px;
  height: 104px;
  border-radius: 50%;
  left: 28px;
  top: 10px;
  transform: rotate(35deg);
  background: linear-gradient(90deg, rgba(255,255,255,.92), rgba(255,255,255,0));
  filter: blur(10px);
  opacity: .68;
}
.dice-number {
  position: relative;
  z-index: 10;
  color: #2c3a4d;
  font-size: 64px;
  font-weight: 950;
  letter-spacing: -.06em;
  text-shadow: 0 1px 0 rgba(255,255,255,.75), 0 10px 18px rgba(113,130,158,.18);
}

.orbit {
  position: absolute;
  width: 285px;
  height: 92px;
  border: 1px solid rgba(127, 162, 220, .24);
  border-radius: 50%;
  transform: rotate(-14deg);
}
.orbit-two { width: 245px; height: 245px; transform: rotate(38deg) scaleY(.38); border-color: rgba(157, 190, 239, .22); }
.spark { position: absolute; width: 5px; height: 5px; border-radius: 50%; background: #ffffff; box-shadow: 0 0 16px rgba(143,183,255,.65); opacity: .85; }
.s1 { top: 85px; left: 78px; }
.s2 { top: 58px; right: 82px; width: 3px; height: 3px; }
.s3 { bottom: 68px; right: 52px; }
.s4 { bottom: 55px; left: 58px; width: 3px; height: 3px; }
.s5 { top: 135px; right: 28px; width: 2px; height: 2px; }
.result-flare {
  position: absolute;
  width: 260px;
  height: 260px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(150,193,255,.22), rgba(191,219,255,.08) 45%, transparent 68%);
  filter: blur(10px);
  opacity: 0;
  transform: scale(.6);
  pointer-events: none;
}

.actions { display: grid; justify-items: center; gap: 10px; }
.roll-btn {
  min-width: min(300px, 82vw);
  height: 62px;
  border: 1px solid rgba(106, 143, 199, .18);
  border-radius: 18px;
  color: #23324a;
  cursor: pointer;
  font-weight: 950;
  letter-spacing: .04em;
  background: linear-gradient(135deg, #ffffff 0%, #f2f6fc 55%, #e7eef9 100%);
  box-shadow: 0 16px 38px rgba(76,106,149,.12), inset 0 1px 0 rgba(255,255,255,.9);
  transition: transform .18s ease, filter .18s ease;
}
.roll-btn:hover { transform: translateY(-2px); filter: brightness(1.01); }
.roll-btn:active { transform: translateY(1px) scale(.99); }
.roll-btn:disabled { cursor: wait; opacity: .8; }
.roll-icon { display: inline-block; margin-right: 8px; font-size: 18px; }
.hint { color: #7f8ea6; font-size: 10px; font-weight: 800; letter-spacing: .12em; }

.history-card {
  width: min(780px, 100%);
  margin: 0 auto;
  padding: 20px;
  border-radius: 24px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,.9), rgba(255,255,255,.82));
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.history-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.history-head h2 { margin: 4px 0 0; font-size: 20px; letter-spacing: -.02em; }
.history { display: flex; gap: 9px; flex-wrap: wrap; margin-top: 18px; min-height: 48px; }
.history-empty { width: 100%; color: var(--muted); font-size: 13px; padding: 12px 0 6px; }
.history-chip {
  min-width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  border: 1px solid rgba(106,143,199,.14);
  color: #33435a;
  background: rgba(243,247,252,.96);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.88);
  font-weight: 900;
  animation: chipIn .28s ease both;
}
.history-chip:first-child {
  color: #23324a;
  background: linear-gradient(145deg, #ffffff, #e9f1fb);
  border-color: rgba(121, 159, 217, .2);
}

.rolling .d12 {
  animation: rollD12 1.05s cubic-bezier(.2,.8,.2,1) both;
}
.rolling .d12-shadow { animation: shadowBounce 1.05s ease both; }
.rolling .orbit-one { animation: orbitSpin .7s linear infinite; }
.rolling .orbit-two { animation: orbitSpin2 .85s linear infinite; }
.rolling .spark { animation: sparkle .6s ease-in-out infinite alternate; }
.result .result-flare { animation: flare .7s ease-out both; }
.result .dice-number { animation: numberPop .56s cubic-bezier(.2,.9,.25,1.35) both; }

@keyframes rollD12 {
  0%   { transform: translateY(0) rotate(-4deg) rotateX(0) rotateY(0) scale(1); }
  25%  { transform: translateY(-58px) rotate(130deg) rotateX(180deg) rotateY(210deg) scale(.92); }
  58%  { transform: translateY(8px) rotate(470deg) rotateX(400deg) rotateY(520deg) scale(1.05); }
  76%  { transform: translateY(-18px) rotate(610deg) rotateX(540deg) rotateY(690deg) scale(.98); }
  100% { transform: translateY(0) rotate(716deg) rotateX(720deg) rotateY(840deg) scale(1); }
}
@keyframes shadowBounce { 0%,100%{ transform: scaleX(1.25); opacity:.6;} 30%{ transform: scaleX(.75); opacity:.18;} 65%{ transform: scaleX(1.35); opacity:.48;} }
@keyframes orbitSpin { to { transform: rotate(346deg); } }
@keyframes orbitSpin2 { to { transform: rotate(-322deg) scaleY(.38); } }
@keyframes sparkle { to { transform: scale(2.4); opacity: 1; } }
@keyframes flare { 0%{ opacity:0; transform:scale(.45);} 35%{opacity:1;} 100%{opacity:0; transform:scale(1.45);} }
@keyframes numberPop { 0%{ transform:scale(.45); opacity:.25;} 65%{transform:scale(1.22);} 100%{transform:scale(1); opacity:1;} }
@keyframes chipIn { from{ transform:translateY(5px) scale(.9); opacity:0;} to{transform:none; opacity:1;} }

@media (max-width: 620px) {
  .app-shell { width: min(100% - 22px, 1120px); padding-top: 12px; }
  .hero { min-height: 610px; padding-top: 34px; }
  .dice-stage { height: 300px; }
  .d12-wrap { transform: scale(.92); }
  .history-card { border-radius: 20px; padding: 17px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}
