body.dark {
    background: #121212;
    font-family: Inter, "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

body.dark::before,
body.dark::after {
    display: none;
}

body.dark header {
    background: #121212;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

body.dark main {
    max-width: none;
    margin: 0;
    padding: 0;
    animation: none;
}

.dice-page {
    --dice-card-bg: linear-gradient(180deg, #1e1e25 0%, #161619 100%);
    --dice-card-bd: rgba(255, 255, 255, 0.06);
    --dice-field-bg: #232329;
    --dice-field-bg-focus: #26262e;
    --dice-accent: #8774e1;
    --dice-accent-active: #6a5bc7;
    --dice-ink: #ffffff;
    --dice-ink-dim: rgba(255, 255, 255, 0.5);
    --dice-ink-faint: rgba(255, 255, 255, 0.4);
    --dice-chip-bg: #1e1e1e;
    --dice-chip-bd: #363636;

    min-height: calc(100vh - 60px);
    display: flex;
    flex-direction: column;
    color: var(--dice-ink);
    overflow-x: hidden;
}

.dice-body {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 520px;
    margin: 0 auto;
    padding: 16px 16px 24px;
    box-sizing: border-box;
}

.dice-card {
    position: relative;
    border-radius: 24px;
    border: 1px solid var(--dice-card-bd);
    background: var(--dice-card-bg);
    padding: 16px;
}

.dice-scale-card {
    padding-top: 12px;
    user-select: none;
    -webkit-user-select: none;
}

.dice-pills {
    display: flex;
    align-items: center;
    gap: 6px;
    height: 28px;
    margin-bottom: 8px;
    overflow: hidden;
    -webkit-mask-image: linear-gradient(90deg, #000 78%, transparent);
    mask-image: linear-gradient(90deg, #000 78%, transparent);
}

.dice-pills-empty {
    font-size: 12px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.25);
}

.dice-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    height: 24px;
    min-width: 46px;
    padding: 0 6px;
    box-sizing: border-box;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.4);
    font-size: 12px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.dice-pill.is-new {
    animation: dice-pill-in 260ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.dice-pill.is-win {
    background: rgba(34, 197, 94, 0.15);
    color: #4ade80;
}

@keyframes dice-pill-in {
    from {
        transform: scale(0.4);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.dice-ticks {
    position: relative;
    height: 16px;
    margin-bottom: 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--dice-ink-faint);
}

.dice-tick {
    position: absolute;
    top: 0;
    transform: translateX(-50%);
    line-height: 16px;
}

.dice-tick::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 100%;
    margin-top: 4px;
    transform: translateX(-50%);
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 5px solid rgba(255, 255, 255, 0.2);
}

.dice-track {
    position: relative;
    height: 40px;
    touch-action: none;
    cursor: pointer;
    outline: none;
    border-radius: 999px;
}

.dice-track.is-locked {
    cursor: default;
}

.dice-track-glow,
.dice-track-bar {
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: 20px;
    margin-top: -10px;
    display: flex;
    pointer-events: none;
}

.dice-track-glow {
    opacity: 0.7;
    filter: blur(12px);
    transform: scaleY(1.5);
}

.dice-track-bar {
    overflow: hidden;
    border-radius: 999px;
}

.dice-track-bar::after {
    content: '';
    position: absolute;
    inset: 0;
    background: repeating-linear-gradient(115deg, rgba(255, 255, 255, 0.13) 0 2px, transparent 2px 6px);
}

.dice-seg {
    height: 100%;
}

.dice-seg-rest {
    flex: 1;
}

.dice-seg.is-red {
    background: linear-gradient(90deg, #ff1f44, #8a0e20);
}

.dice-seg.is-red.is-rev {
    background: linear-gradient(90deg, #8a0e20, #ff1f44);
}

.dice-seg.is-zone {
    background: linear-gradient(90deg, #0b7a2d, #00e24b 50%, #0b7a2d);
}

.dice-track.is-drag-zone {
    cursor: grabbing;
}

.dice-thumb {
    position: absolute;
    top: 50%;
    width: 32px;
    height: 32px;
    margin: -16px 0 0 -16px;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5), 0 0 0 4px rgba(255, 255, 255, 0.08);
    pointer-events: none;
    outline: none;
    transition: transform 0.12s ease-out;
}

.dice-thumb.is-active {
    transform: scale(1.12);
}

.dice-thumb:focus-visible {
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5), 0 0 0 4px rgba(139, 120, 255, 0.6);
}

.dice-thumb span {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #5a4fbf;
}

.dice-track.is-locked .dice-thumb span {
    opacity: 0.6;
}

.dice-scanner {
    position: absolute;
    left: -1.5px;
    top: 50%;
    width: 3px;
    height: 32px;
    margin-top: -16px;
    z-index: 20;
    border-radius: 999px;
    background: #fff;
    box-shadow: 0 0 12px rgba(255, 255, 255, 0.9), 0 0 28px rgba(255, 255, 255, 0.5);
    opacity: 0;
    pointer-events: none;
    will-change: transform, opacity;
}

.dice-badge {
    position: absolute;
    left: 0;
    top: 50%;
    z-index: 30;
    padding: 4px 12px;
    border-radius: 12px;
    background: #26262e;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
    color: #fff;
    font-size: 17px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    will-change: transform, opacity;
}

.dice-badge.is-win {
    background: #16a34a;
    box-shadow: 0 0 22px rgba(34, 197, 94, 0.7);
}

.dice-badge.is-lose {
    background: #ef2d42;
    box-shadow: 0 0 22px rgba(239, 45, 66, 0.6);
}

.dice-fields {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.dice-fields-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.dice-field-wrap {
    display: block;
    min-width: 0;
}

.dice-label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    color: var(--dice-ink-dim);
}

.dice-field {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    height: 56px;
    padding: 0 16px;
    box-sizing: border-box;
    border-radius: 16px;
    border: 1px solid var(--dice-card-bd);
    background: var(--dice-field-bg);
    transition: border-color 0.15s, background-color 0.15s;
}

.dice-field:focus-within {
    border-color: rgba(139, 120, 255, 0.5);
    background: var(--dice-field-bg-focus);
}

.dice-field-input {
    width: 100%;
    min-width: 0;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--dice-ink);
    font: inherit;
    font-size: 20px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    outline: none;
}

.dice-field-input:disabled {
    opacity: 1;
    -webkit-text-fill-color: currentColor;
}

.dice-field-icon {
    flex: none;
    color: var(--dice-ink-faint);
    font-size: 18px;
    font-weight: 700;
}

.dice-value-flash {
    animation: dice-value-flash 450ms ease-out;
}

@keyframes dice-value-flash {
    0% {
        color: #8b78ff;
    }

    100% {
        color: #fff;
    }
}

.dice-roll {
    position: relative;
    overflow: hidden;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 52px;
    padding: 0 20px;
    border: none;
    border-radius: 18px;
    background: var(--dice-accent);
    color: #fff;
    font: inherit;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 6px 18px -8px rgba(135, 116, 225, 0.9);
    transition: transform 0.15s, background-color 0.15s, opacity 0.15s;
}

.dice-roll:active:not(:disabled) {
    transform: scale(0.975);
    background: var(--dice-accent-active);
}

.dice-roll:disabled {
    opacity: 0.4;
    cursor: default;
}

.dice-roll:not(:disabled)::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    animation: dice-sheen 3s linear infinite;
}

@keyframes dice-sheen {
    0% {
        transform: translate(-200%) skew(-45deg);
    }

    100% {
        transform: translate(200%) skew(-45deg);
    }
}

.dice-roll-text {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-variant-numeric: tabular-nums;
}

.dice-roll.is-playing .dice-roll-text::before {
    content: '';
    width: 15px;
    height: 15px;
    border-radius: 50%;
    border: 2px solid currentColor;
    border-top-color: transparent;
    opacity: 0.8;
    animation: dice-spin 0.7s linear infinite;
}

@keyframes dice-spin {
    to {
        transform: rotate(360deg);
    }
}

.dice-win-toast,
.game-error-toast {
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10000;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 8px 14px;
    border-radius: 12px;
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    animation: dice-toast-in 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.dice-win-toast[hidden],
.game-error-toast[hidden] {
    display: none;
}

.dice-win-toast {
    background: rgba(22, 163, 74, 0.95);
    box-shadow: 0 8px 28px rgba(22, 163, 74, 0.35);
}

.game-error-toast {
    background: rgba(239, 45, 66, 0.95);
    box-shadow: 0 8px 28px rgba(239, 45, 66, 0.35);
}

@keyframes dice-toast-in {
    from {
        opacity: 0;
        transform: translate(-50%, -12px);
    }

    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

@media (prefers-reduced-motion: reduce) {
    .dice-roll::after {
        animation: none;
    }
}