:root {
  --bg-1: #0b1224;
  --bg-2: #1a1a3a;
  --bg-3: #2a1a4a;
  --cube: #f6f4ee;
  --cube-edge: rgba(0, 0, 0, 0.07);
  --pip: #1f1f23;
  --pip-hi: rgba(255, 255, 255, 0.18);
  --text: #f1f1f5;
  --text-mute: rgba(241, 241, 245, 0.55);
  --accent: #f5b942;
  --accent-press: #d99a25;
  --shadow: rgba(0, 0, 0, 0.45);
  --shadow-soft: rgba(0, 0, 0, 0.25);
}

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

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", system-ui, sans-serif;
  background:
    radial-gradient(ellipse 80% 60% at 50% 0%, var(--bg-3), transparent 60%),
    linear-gradient(180deg, var(--bg-1) 0%, var(--bg-2) 100%);
  background-attachment: fixed;
  color: var(--text);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  -webkit-font-smoothing: antialiased;
}

.app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top, 0);
}

/* topbar */
.topbar {
  padding: 16px 20px 4px;
  text-align: center;
}

.title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 4px;
  opacity: 0.85;
  text-indent: 4px;
}

/* stage (centered content) */
.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 16px 20px 12px;
  min-height: 0;
}

/* ===== the 3D dice ===== */
.dice-stage {
  width: 200px;
  height: 200px;
  perspective: 900px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.dice-tilt {
  position: relative;
  width: 100%;
  height: 100%;
  transform: rotateX(-18deg) rotateY(22deg);
  transform-style: preserve-3d;
  filter: drop-shadow(0 18px 30px rgba(0, 0, 0, 0.5));
}

.dice {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transform: rotateX(0deg) rotateY(0deg);
  transition: transform 1.5s cubic-bezier(0.18, 0.7, 0.25, 1);
}

.face {
  position: absolute;
  inset: 0;
  background: linear-gradient(160deg, #ffffff 0%, var(--cube) 60%, #e6e2d6 100%);
  border-radius: 22px;
  box-shadow:
    inset 0 0 0 1px var(--cube-edge),
    inset 0 0 28px rgba(0, 0, 0, 0.05),
    0 0 0 1px rgba(255, 255, 255, 0.4);
  display: grid;
  padding: 14%;
}

.face-1, .face-2, .face-3, .face-4, .face-5 {
  grid-template-rows: repeat(3, 1fr);
  grid-template-columns: repeat(3, 1fr);
}

.face-6 {
  grid-template-rows: repeat(3, 1fr);
  grid-template-columns: repeat(2, 1fr);
}

.pip {
  width: 78%;
  aspect-ratio: 1;
  max-width: 28px;
  justify-self: center;
  align-self: center;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #5a5a60 0%, var(--pip) 60%, #0a0a0c 100%);
  box-shadow:
    inset -1px -2px 3px rgba(0, 0, 0, 0.5),
    inset 1px 1px 2px var(--pip-hi);
}

.face-6 .pip { max-width: 36px; }
.face-1 .pip { max-width: 32px; }

/* face positions */
.face-1 { transform: translateZ(100px); }
.face-2 { transform: rotateX(-90deg) translateZ(100px); }
.face-3 { transform: rotateY(90deg) translateZ(100px); }
.face-4 { transform: rotateY(-90deg) translateZ(100px); }
.face-5 { transform: rotateX(90deg) translateZ(100px); }
.face-6 { transform: rotateY(180deg) translateZ(100px); }

/* ===== result display ===== */
.result {
  min-height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 280px;
}

.result-num {
  font-size: clamp(72px, 22vw, 120px);
  font-weight: 900;
  line-height: 1;
  color: var(--accent);
  letter-spacing: -4px;
  font-variant-numeric: tabular-nums;
  text-shadow:
    0 0 32px rgba(245, 185, 66, 0.45),
    0 6px 24px rgba(245, 185, 66, 0.25);
  animation: pop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes pop {
  0%   { transform: scale(0.4); opacity: 0; }
  60%  { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.result-hint {
  font-size: 14px;
  color: var(--text-mute);
  letter-spacing: 0.5px;
  text-align: center;
  line-height: 1.5;
}

/* ===== roll button ===== */
.roll-btn {
  margin: 0 auto max(24px, env(safe-area-inset-bottom, 0));
  width: min(320px, calc(100% - 40px));
  height: 68px;
  padding: 0 24px;
  border: none;
  border-radius: 34px;
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-press) 100%);
  color: #1a1208;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 2px;
  cursor: pointer;
  box-shadow:
    0 8px 24px rgba(245, 185, 66, 0.4),
    0 2px 6px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
  transition: transform 0.1s ease-out, box-shadow 0.15s ease-out, opacity 0.2s, filter 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.roll-btn:not(:disabled):hover {
  filter: brightness(1.05);
}

.roll-btn:not(:disabled):active {
  transform: scale(0.96);
  box-shadow:
    0 4px 12px rgba(245, 185, 66, 0.35),
    0 1px 3px rgba(0, 0, 0, 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.4);
}

.roll-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  filter: saturate(0.4);
}

.roll-btn-icon {
  font-size: 22px;
  line-height: 1;
}

.roll-btn-text {
  font-size: 18px;
}

/* ===== accessibility / reduced motion ===== */
@media (prefers-reduced-motion: reduce) {
  .dice {
    transition-duration: 220ms;
  }
  .result-num {
    animation: none;
  }
}

/* small phones */
@media (max-width: 360px) {
  .dice-stage {
    width: 170px;
    height: 170px;
  }
  .face { padding: 12%; }
  .result { min-height: 86px; }
}
