:root {
  --gold: #c9a961;
  --gold-dim: rgba(201, 169, 97, 0.45);
  --gold-glow: rgba(201, 169, 97, 0.35);
  --cream: #ede0c4;
  --bg-inner: #5c1219;
  --bg-outer: #1a0305;
  --ink: #f3e9d2;
  --ink-dim: rgba(243, 233, 210, 0.65);
}

#result {
  display: none !important;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: radial-gradient(
    ellipse at center,
    var(--bg-inner) 0%,
    var(--bg-outer) 75%
  );
  color: var(--ink);
  font-family: "Playfair Display", Georgia, serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

button {
  font-family: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

/* Subtle velvet noise overlay */
.velvet-noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.06;
  z-index: 1;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 0.6 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

.app {
  position: relative;
  z-index: 2;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  width: 100vw;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ---------- Controls ---------- */
.controls {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 32px 16px 8px;
  flex-shrink: 0;
}

@media (min-width: 600px) {
  .controls {
    padding-top: 48px;
  }
}

.pills {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding: 4px 16px;
  scroll-snap-type: x proximity;
  justify-content: center;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
}
.pills::-webkit-scrollbar {
  display: none;
}

.pill {
  flex: 0 0 auto;
  scroll-snap-align: center;
  padding: 8px 11px;
  font-family: "Playfair Display", Georgia, serif;
  font-size: 13px;
  letter-spacing: 0.04em;
  color: var(--ink-dim);
  background: rgba(20, 4, 6, 0.4);
  border: 1px solid var(--gold-dim);
  border-radius: 999px;
  transition:
    color 200ms ease,
    border-color 200ms ease,
    box-shadow 250ms ease,
    background 200ms ease;
  backdrop-filter: blur(4px);
}

.pill:hover {
  color: var(--ink);
  border-color: var(--gold);
}

.pill.is-active {
  color: var(--gold);
  border-color: var(--gold);
  background: rgba(201, 169, 97, 0.08);
  box-shadow:
    0 0 0 1px var(--gold-dim),
    0 0 18px var(--gold-glow);
}

.pill:disabled,
.step:disabled,
.roll-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
}

.step {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--gold-dim);
  color: var(--gold);
  font-size: 22px;
  line-height: 1;
  background: rgba(20, 4, 6, 0.4);
  transition:
    border-color 200ms ease,
    box-shadow 250ms ease,
    color 200ms ease;
}

.step:hover {
  border-color: var(--gold);
  box-shadow: 0 0 14px var(--gold-glow);
}

.step-count {
  font-size: 28px;
  font-weight: 600;
  color: var(--ink);
  min-width: 28px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ---------- Arena ---------- */
.arena {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  max-width: 420px;
  aspect-ratio: 9 / 16;
  margin: 0 auto;
}

.arena canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

/* dice-box sometimes renders a #dice-canvas wrapper */
.arena > div {
  width: 100%;
  height: 100%;
}

.result {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  text-align: center;
  opacity: 0;
  transition: opacity 600ms ease;
}

.result.is-visible {
  opacity: 1;
}

.result .total {
  font-family: "Playfair Display", Georgia, serif;
  font-weight: 700;
  font-size: clamp(72px, 22vw, 180px);
  line-height: 1;
  color: var(--cream);
  text-shadow:
    0 2px 20px rgba(0, 0, 0, 0.6),
    0 0 40px rgba(201, 169, 97, 0.15);
  letter-spacing: -0.02em;
}

.result .breakdown {
  margin-top: 10px;
  font-size: 18px;
  letter-spacing: 0.08em;
  color: var(--gold);
  opacity: 0.85;
  font-variant-numeric: tabular-nums;
}

/* ---------- Trigger ---------- */
.trigger {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 12px 16px calc(32px + env(safe-area-inset-bottom));
  flex-shrink: 0;
}

@media (min-width: 600px) {
  .trigger {
    padding-bottom: calc(56px + env(safe-area-inset-bottom));
  }
}

.shake-prompt {
  font-size: 18px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--gold);
  opacity: 0.9;
  animation:
    gentleShake 2.4s ease-in-out infinite,
    softPulse 2.4s ease-in-out infinite;
  transform-origin: center;
  display: none;
}

body.is-touch .shake-prompt {
  display: block;
}
body.is-touch .roll-btn {
  font-size: 13px;
  opacity: 0.7;
}

.roll-btn {
  padding: 12px 34px;
  border: 1px solid var(--gold);
  border-radius: 999px;
  font-family: "Playfair Display", Georgia, serif;
  font-size: 17px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
  background: rgba(20, 4, 6, 0.45);
  transition:
    color 200ms ease,
    background 200ms ease,
    box-shadow 250ms ease;
  backdrop-filter: blur(4px);
}

.roll-btn:hover {
  color: var(--cream);
  background: rgba(201, 169, 97, 0.1);
  box-shadow: 0 0 22px var(--gold-glow);
}

@keyframes gentleShake {
  0%,
  100% {
    transform: translateX(0) rotate(0);
  }
  20% {
    transform: translateX(-2px) rotate(-0.4deg);
  }
  40% {
    transform: translateX(2px) rotate(0.4deg);
  }
  60% {
    transform: translateX(-1.5px) rotate(-0.3deg);
  }
  80% {
    transform: translateX(1.5px) rotate(0.3deg);
  }
}

@keyframes softPulse {
  0%,
  100% {
    opacity: 0.6;
  }
  50% {
    opacity: 1;
  }
}

/* ---------- Overlay (iOS motion permission) ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(10, 2, 4, 0.7);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.overlay[hidden] {
  display: none;
}

.overlay-card {
  background: rgba(28, 6, 10, 0.95);
  border: 1px solid var(--gold-dim);
  border-radius: 14px;
  padding: 28px 26px 22px;
  max-width: 320px;
  width: 100%;
  text-align: center;
  box-shadow: 0 12px 50px rgba(0, 0, 0, 0.7);
}

.overlay-text {
  font-size: 20px;
  margin: 0 0 22px;
  color: var(--cream);
}

.overlay-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.overlay-btn {
  padding: 9px 18px;
  border-radius: 999px;
  border: 1px solid var(--gold-dim);
  color: var(--ink-dim);
  font-size: 14px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-family: "Playfair Display", Georgia, serif;
  background: transparent;
  transition:
    color 200ms ease,
    border-color 200ms ease,
    box-shadow 250ms ease;
}

.overlay-btn.primary {
  color: var(--gold);
  border-color: var(--gold);
}

.overlay-btn:hover {
  color: var(--cream);
  border-color: var(--gold);
  box-shadow: 0 0 14px var(--gold-glow);
}
