/* Picker page — confetti + paper-tactile flourishes that the Tailwind
   utilities alone do not give us. */

.confetti-piece {
    position: fixed;
    top: -16px;
    width: 10px;
    height: 14px;
    border-radius: 2px;
    pointer-events: none;
    z-index: 9999;
    animation-name: confetti-fall;
    animation-timing-function: cubic-bezier(0.2, 0.6, 0.4, 1);
    animation-fill-mode: forwards;
    transform: rotate(0deg);
}

@keyframes confetti-fall {
    to {
        transform: translateY(110vh) rotate(720deg);
        opacity: 0;
    }
}

.paper-grain {
    background-image:
        radial-gradient(rgba(0, 0, 0, 0.04) 1px, transparent 1px),
        radial-gradient(rgba(0, 0, 0, 0.03) 1px, transparent 1px);
    background-size: 6px 6px, 9px 9px;
    background-position: 0 0, 3px 3px;
}

.dark .paper-grain {
    background-image:
        radial-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px),
        radial-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px);
}

.stage-canvas {
    width: 100%;
    height: 360px;
    max-height: min(60vh, 480px);
    display: block;
}

@media (min-width: 768px) {
    .stage-canvas {
        height: 480px;
    }
}

.mode-tab[aria-pressed='true'] {
    background: linear-gradient(135deg, #6366f1, #4f46e5);
    color: white;
    box-shadow: 0 8px 24px -10px rgba(79, 70, 229, 0.6);
}

@media (prefers-reduced-motion: reduce) {
    .confetti-piece {
        display: none;
    }
}

/* CSS 3D dice — real perspective cube, faces are DOM nodes so the
   text stays crisp at any rotation. */
.dice-scene {
    position: relative;
    perspective: 1000px;
    perspective-origin: 50% 45%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.dice-scene::before {
    content: '';
    position: absolute;
    bottom: 16%;
    left: 50%;
    width: 200px;
    height: 26px;
    transform: translateX(-50%);
    background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.45) 0%, rgba(0, 0, 0, 0) 65%);
    filter: blur(6px);
    pointer-events: none;
}

.dice-cube {
    --size: 140px;
    width: var(--size);
    height: var(--size);
    position: relative;
    transform-style: preserve-3d;
    transform: rotateX(-25deg) rotateY(35deg);
    will-change: transform;
}

.dice-face {
    position: absolute;
    inset: 0;
    background:
        linear-gradient(135deg, #ffffff 0%, #f1f5f9 55%, #cbd5e1 100%);
    border: 2px solid #1a1a2e;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: -apple-system, BlinkMacSystemFont, Inter, system-ui, sans-serif;
    font-weight: 900;
    font-size: clamp(14px, calc(var(--size) * 0.20), 30px);
    color: #0b0b14;
    backface-visibility: hidden;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.85),
        inset 0 -10px 16px rgba(0, 0, 0, 0.06);
    overflow: hidden;
    padding: 0 10px;
    text-align: center;
    line-height: 1;
    word-break: break-word;
}

.dice-face-front  { transform: translateZ(calc(var(--size) / 2)); }
.dice-face-back   { transform: rotateY(180deg) translateZ(calc(var(--size) / 2)); }
.dice-face-right  { transform: rotateY(90deg)  translateZ(calc(var(--size) / 2)); }
.dice-face-left   { transform: rotateY(-90deg) translateZ(calc(var(--size) / 2)); }
.dice-face-top    { transform: rotateX(90deg)  translateZ(calc(var(--size) / 2)); }
.dice-face-bottom { transform: rotateX(-90deg) translateZ(calc(var(--size) / 2)); }

.dice-face.is-winner {
    background:
        linear-gradient(135deg, #fffbeb 0%, #fde68a 55%, #fbbf24 100%);
    border-color: #a16207;
    color: #422006;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.85),
        0 0 28px 6px rgba(251, 191, 36, 0.5);
}

/* d2 — card flip. Two faces, no thickness, slightly tall card aspect. */
.dice-d2 {
    --card-w: 110px;
    --card-h: 160px;
    width: var(--card-w);
    height: var(--card-h);
}

.dice-d2 {
    --card-w: 130px;
    --card-h: 180px;
}

.dice-d2 .dice-face {
    width: var(--card-w);
    height: var(--card-h);
    inset: 0;
    border-radius: 14px;
    font-size: clamp(16px, calc(var(--card-w) * 0.20), 30px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    word-break: keep-all;
}

.dice-d2 .dice-face-front { transform: translateZ(2px); }
.dice-d2 .dice-face-back  { transform: rotateY(180deg) translateZ(2px); }

/* d8, d12, d20 — polyhedra rendered as a parent cube with face divs whose
   transforms are computed in JS and applied inline. Each face div holds an
   inline SVG (triangle for d8/d20, pentagon for d12) so the polygon stroke
   and centered name stay crisp at any rotation. */

.dice-d4, .dice-d8, .dice-d12, .dice-d20 {
    --size: 200px;
    width: var(--size);
    height: var(--size);
}

/* Mouse drag affordance */
.dice-scene {
    cursor: grab;
    touch-action: none;
    user-select: none;
}
.dice-scene.is-dragging {
    cursor: grabbing;
}
.dice-cube {
    pointer-events: none; /* drag captured by .dice-scene; faces shouldn't steal */
}

.dice-d4 .dice-face-tri,
.dice-d8 .dice-face-tri,
.dice-d12 .dice-face-pent,
.dice-d20 .dice-face-tri {
    /* Face div sized so the visible polygon edge equals the polyhedron's 3D
       edge in screen space. JS sets --face-size per shape based on geometry. */
    width: var(--face-size, 130px);
    height: var(--face-size, 130px);
    margin-left: calc(var(--face-size, 130px) / -2);
    margin-top: calc(var(--face-size, 130px) / -2);
    left: 50%;
    top: 50%;
    inset: auto;
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
    display: block;
    overflow: visible;
}

.dice-d8 .dice-face-tri svg,
.dice-d12 .dice-face-pent svg,
.dice-d20 .dice-face-tri svg {
    width: 100%;
    height: 100%;
    display: block;
    overflow: visible;
}

.dice-d8 .dice-face-tri polygon,
.dice-d12 .dice-face-pent polygon,
.dice-d20 .dice-face-tri polygon {
    fill: #f1f5f9;
}

.dice-d8 .dice-face-tri.is-winner polygon,
.dice-d12 .dice-face-pent.is-winner polygon,
.dice-d20 .dice-face-tri.is-winner polygon {
    fill: #fbbf24;
    stroke: #a16207;
    filter: drop-shadow(0 0 14px rgba(251, 191, 36, 0.55));
}

.dice-d8 .dice-face-tri.is-winner text,
.dice-d12 .dice-face-pent.is-winner text,
.dice-d20 .dice-face-tri.is-winner text {
    fill: #422006;
}
