/* ===================== 命运骰子 ===================== */
.dice-portal {
    border: 1px solid rgba(220, 170, 80, 0.38);
    background:
        linear-gradient(135deg, rgba(180, 120, 40, 0.14), rgba(120, 60, 30, 0.1)),
        rgba(255, 255, 255, 0.04);
}

.dice-portal:hover {
    border-color: rgba(255, 200, 100, 0.65);
    box-shadow: 0 0 28px rgba(220, 160, 60, 0.22);
}

.dice-portal .library-portal-glow {
    background: radial-gradient(circle, rgba(255, 190, 80, 0.16), transparent 60%);
}

.dice-portal .library-portal-icon {
    background: rgba(180, 120, 40, 0.22);
    color: #ffd89a;
    box-shadow: 0 0 16px rgba(220, 160, 60, 0.28);
}

.dice-portal .library-portal-title {
    color: #ffe8c0;
}

body.dice-mode #particle-bg {
    background:
        radial-gradient(ellipse at 22% 16%, rgba(180, 120, 40, 0.28), transparent 48%),
        radial-gradient(ellipse at 78% 84%, rgba(120, 60, 140, 0.22), transparent 42%),
        #000;
}

.dice-view:not(.active) {
    display: none !important;
}

.dice-view.active {
    display: block !important;
    position: relative;
    z-index: 20;
    background: transparent;
    min-height: 100vh;
}

.dice-scroll {
    min-height: 100vh;
    padding: 24px 20px 48px;
    overflow-y: auto;
}

.dice-shell {
    max-width: 880px;
    margin: 0 auto;
}

.dice-header {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 28px;
}

.dice-header > div:first-child {
    width: 100%;
    min-width: 0;
}

.dice-header .back-home-btn {
    flex-shrink: 0;
}

.dice-kicker {
    margin: 0 0 4px;
    font-size: 11px;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: rgba(255, 200, 120, 0.55);
}

.dice-title {
    margin: 0;
    font-size: 28px;
    font-weight: 600;
    color: #ffe8c8;
    text-shadow: 0 0 18px rgba(255, 180, 80, 0.25);
}

.dice-sub {
    margin: 6px 0 0;
    font-size: 13px;
    color: rgba(255, 220, 180, 0.55);
    letter-spacing: 0.08em;
}

.dice-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    padding: 20px;
    border: 1px solid rgba(220, 170, 80, 0.22);
    border-radius: 16px;
    background: rgba(12, 10, 8, 0.55);
}

.dice-field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.dice-field label {
    font-size: 12px;
    letter-spacing: 0.1em;
    color: rgba(255, 210, 150, 0.7);
}

.dice-field input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid rgba(220, 170, 80, 0.28);
    border-radius: 10px;
    background: rgba(20, 16, 10, 0.7);
    color: #fff5e8;
    font-size: 18px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.dice-field input:focus {
    border-color: rgba(255, 200, 100, 0.55);
    box-shadow: 0 0 12px rgba(220, 160, 60, 0.2);
}

.dice-presets {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.dice-preset {
    padding: 6px 14px;
    border: 1px solid rgba(220, 170, 80, 0.28);
    border-radius: 999px;
    background: rgba(40, 30, 15, 0.5);
    color: rgba(255, 220, 170, 0.85);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
}

.dice-preset:hover,
.dice-preset.active {
    border-color: rgba(255, 200, 100, 0.6);
    background: rgba(180, 120, 40, 0.25);
    color: #ffe8c0;
    box-shadow: 0 0 12px rgba(220, 160, 60, 0.2);
}

.dice-roll-wrap {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-top: 4px;
}

.dice-formula {
    font-size: 15px;
    letter-spacing: 0.12em;
    color: rgba(255, 200, 120, 0.65);
}

#dice-btn-roll {
    min-width: 140px;
    font-size: 16px;
    letter-spacing: 0.15em;
}

#dice-btn-roll:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* 投掷区 */
.dice-arena {
    position: relative;
    min-height: 220px;
    max-height: clamp(240px, 42vh, 400px);
    margin-top: 28px;
    padding: 24px 16px 28px;
    padding-right: 10px;
    border: 1px solid rgba(220, 170, 80, 0.18);
    border-radius: 18px;
    background:
        radial-gradient(ellipse at 50% 100%, rgba(180, 120, 40, 0.12), transparent 55%),
        rgba(8, 6, 4, 0.5);
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    align-items: flex-start;
    justify-content: center;
    gap: 20px 18px;
    perspective: 900px;
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(220, 170, 80, 0.55) rgba(20, 16, 10, 0.45);
}

.dice-arena::-webkit-scrollbar {
    width: 8px;
}

.dice-arena::-webkit-scrollbar-track {
    margin: 10px 2px;
    background: rgba(20, 16, 10, 0.5);
    border-radius: 6px;
}

.dice-arena::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, rgba(255, 200, 100, 0.65), rgba(180, 120, 40, 0.45));
    border-radius: 6px;
    border: 1px solid rgba(255, 200, 100, 0.15);
}

.dice-arena::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 200, 100, 0.8);
}

.dice-arena.has-overflow {
    box-shadow: inset 0 -18px 24px -12px rgba(0, 0, 0, 0.45);
}

.dice-arena.is-rolling::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: radial-gradient(circle at 50% 40%, rgba(255, 200, 80, 0.08), transparent 60%);
    pointer-events: none;
    animation: dice-arena-pulse 0.6s ease-in-out infinite alternate;
}

@keyframes dice-arena-pulse {
    from { opacity: 0.4; }
    to { opacity: 1; }
}

.dice-die {
    position: relative;
    width: 72px;
    height: 88px;
    display: flex;
    flex-direction: column;
    align-items: center;
    transform: translateY(0);
    opacity: 1;
}

.dice-die.rolling {
    animation: dice-pop-in 0.42s cubic-bezier(0.22, 1.15, 0.36, 1) backwards;
    animation-delay: var(--dice-pop-delay, 0s);
}

.dice-cube {
    width: 64px;
    height: 64px;
    position: relative;
    transform-style: preserve-3d;
    transform: rotateX(-18deg) rotateY(24deg);
    will-change: transform;
}

.dice-die.rolling .dice-cube {
    animation: dice-tumble var(--dice-roll-speed, 0.4s) linear infinite;
}

.dice-die.landed .dice-cube {
    animation: dice-land 0.52s cubic-bezier(0.34, 1.35, 0.64, 1) forwards;
}

@keyframes dice-pop-in {
    0% {
        transform: translateY(56px) scale(0.55);
        opacity: 0;
    }
    70% {
        transform: translateY(-6px) scale(1.04);
        opacity: 1;
    }
    100% {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

@keyframes dice-tumble {
    0% {
        transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg) translateY(0);
    }
    25% {
        transform: rotateX(calc(var(--dice-tumble-x, 720deg) * 0.25))
            rotateY(calc(var(--dice-tumble-y, 900deg) * 0.25))
            rotateZ(45deg)
            translateY(-10px);
    }
    50% {
        transform: rotateX(calc(var(--dice-tumble-x, 720deg) * 0.5))
            rotateY(calc(var(--dice-tumble-y, 900deg) * 0.5))
            rotateZ(90deg)
            translateY(0);
    }
    75% {
        transform: rotateX(calc(var(--dice-tumble-x, 720deg) * 0.75))
            rotateY(calc(var(--dice-tumble-y, 900deg) * 0.75))
            rotateZ(135deg)
            translateY(-6px);
    }
    100% {
        transform: rotateX(var(--dice-tumble-x, 720deg))
            rotateY(var(--dice-tumble-y, 900deg))
            rotateZ(180deg)
            translateY(0);
    }
}

@keyframes dice-land {
    0% {
        transform: rotateX(calc(var(--dice-tumble-x, 720deg) + 40deg))
            rotateY(calc(var(--dice-tumble-y, 900deg) + 30deg))
            rotateZ(24deg)
            scale(1.1);
    }
    45% {
        transform: rotateX(-22deg) rotateY(28deg) rotateZ(-4deg) scale(1.06);
    }
    70% {
        transform: rotateX(-14deg) rotateY(20deg) rotateZ(2deg) scale(0.98);
    }
    100% {
        transform: rotateX(-18deg) rotateY(24deg) rotateZ(0deg) scale(1);
    }
}

.dice-face {
    position: absolute;
    width: 64px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid rgba(220, 170, 80, 0.45);
    border-radius: 10px;
    background:
        linear-gradient(145deg, rgba(60, 45, 25, 0.95), rgba(30, 22, 12, 0.98));
    box-shadow: inset 0 0 18px rgba(255, 200, 100, 0.12);
    backface-visibility: hidden;
}

.dice-num {
    font-size: 22px;
    font-weight: 700;
    color: #ffe8c0;
    text-shadow: 0 0 10px rgba(255, 180, 80, 0.4);
    line-height: 1;
    font-variant-numeric: tabular-nums;
    max-width: 58px;
    overflow: hidden;
    text-overflow: clip;
    white-space: nowrap;
}

.dice-die--digits-3 .dice-num {
    font-size: 15px;
    letter-spacing: -0.02em;
    max-width: 60px;
}

.dice-die--digits-4 .dice-num {
    font-size: 12px;
    letter-spacing: -0.03em;
    max-width: 60px;
}

.dice-die--digits-3 .dice-cube,
.dice-die--digits-3 .dice-face,
.dice-die--digits-4 .dice-cube,
.dice-die--digits-4 .dice-face {
    width: 68px;
    height: 68px;
}

.dice-die--digits-3 .dice-face-front,
.dice-die--digits-4 .dice-face-front  { transform: translateZ(34px); }
.dice-die--digits-3 .dice-face-back,
.dice-die--digits-4 .dice-face-back   { transform: rotateY(180deg) translateZ(34px); }
.dice-die--digits-3 .dice-face-right,
.dice-die--digits-4 .dice-face-right  { transform: rotateY(90deg) translateZ(34px); }
.dice-die--digits-3 .dice-face-left,
.dice-die--digits-4 .dice-face-left   { transform: rotateY(-90deg) translateZ(34px); }
.dice-die--digits-3 .dice-face-top,
.dice-die--digits-4 .dice-face-top    { transform: rotateX(90deg) translateZ(34px); }
.dice-die--digits-3 .dice-face-bottom,
.dice-die--digits-4 .dice-face-bottom { transform: rotateX(-90deg) translateZ(34px); }

.dice-face-front  { transform: translateZ(32px); }
.dice-face-back   { transform: rotateY(180deg) translateZ(32px); }
.dice-face-right  { transform: rotateY(90deg) translateZ(32px); }
.dice-face-left   { transform: rotateY(-90deg) translateZ(32px); }
.dice-face-top    { transform: rotateX(90deg) translateZ(32px); }
.dice-face-bottom { transform: rotateX(-90deg) translateZ(32px); }

.dice-shadow {
    width: 52px;
    height: 10px;
    margin-top: 10px;
    border-radius: 50%;
    background: radial-gradient(ellipse, rgba(0, 0, 0, 0.55), transparent 70%);
    transition: transform 0.3s, opacity 0.3s;
}

.dice-die.rolling .dice-shadow {
    animation: dice-shadow-bounce var(--dice-roll-speed, 0.4s) ease-in-out infinite alternate;
}

.dice-die.landed {
    animation: dice-settle 0.35s ease-out forwards;
}

@keyframes dice-settle {
    0% { transform: translateY(-4px); }
    100% { transform: translateY(0); }
}

.dice-die.landed .dice-shadow {
    transform: scale(1);
    opacity: 0.85;
}

@keyframes dice-shadow-bounce {
    from { transform: scale(0.75); opacity: 0.45; }
    to   { transform: scale(1.1); opacity: 0.7; }
}

.dice-empty-hint {
    color: rgba(255, 210, 150, 0.45);
    font-size: 14px;
    letter-spacing: 0.08em;
    text-align: center;
    padding: 24px;
}

/* 结果 */
.dice-result {
    margin-top: 24px;
    padding: 18px 20px;
    border: 1px solid rgba(220, 170, 80, 0.22);
    border-radius: 14px;
    background: rgba(12, 10, 8, 0.55);
    text-align: center;
}

.dice-result.hidden {
    display: none;
}

.dice-result-label {
    margin: 0 0 12px;
    font-size: 12px;
    letter-spacing: 0.12em;
    color: rgba(255, 200, 120, 0.6);
}

.dice-result-values {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-bottom: 14px;
    max-height: 160px;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 4px 6px 8px;
    scrollbar-width: thin;
    scrollbar-color: rgba(220, 170, 80, 0.5) rgba(20, 16, 10, 0.35);
}

.dice-result-values::-webkit-scrollbar {
    width: 6px;
}

.dice-result-values::-webkit-scrollbar-track {
    background: rgba(20, 16, 10, 0.35);
    border-radius: 4px;
}

.dice-result-values::-webkit-scrollbar-thumb {
    background: rgba(220, 170, 80, 0.55);
    border-radius: 4px;
}

.dice-result-values::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 200, 100, 0.75);
}

.dice-result-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid rgba(220, 170, 80, 0.35);
    background: rgba(180, 120, 40, 0.18);
    color: #ffe8c0;
    font-size: 16px;
    font-weight: 600;
}

.dice-result-total {
    font-size: 22px;
    color: #ffd080;
    letter-spacing: 0.06em;
}

.dice-result-total span {
    font-size: 32px;
    font-weight: 700;
    color: #ffe8a0;
    text-shadow: 0 0 16px rgba(255, 180, 60, 0.35);
    margin-left: 6px;
}

@media (max-width: 560px) {
    .dice-controls {
        grid-template-columns: 1fr;
    }

    .dice-roll-wrap {
        flex-direction: column;
    }

    .dice-cube,
    .dice-face {
        width: 56px;
        height: 56px;
    }

    .dice-face-front  { transform: translateZ(28px); }
    .dice-face-back   { transform: rotateY(180deg) translateZ(28px); }
    .dice-face-right  { transform: rotateY(90deg) translateZ(28px); }
    .dice-face-left   { transform: rotateY(-90deg) translateZ(28px); }
    .dice-face-top    { transform: rotateX(90deg) translateZ(28px); }
    .dice-face-bottom { transform: rotateX(-90deg) translateZ(28px); }

    .dice-num { font-size: 18px; }
}
