:root {
    --bg: #f6f8fa;
    --bg-card: #ffffff;
    --text: #1f2328;
    --text-muted: #656d76;
    --accent: #238636;
    --accent-glow: rgba(35, 134, 54, 0.25);
    --accent-hover: #1a7f37;
    --border: #d0d7de;
    --dice-bg: #238636;
    --dice-dot: #ffffff;
    --error: #cf222e;
    --toggle-icon: #656d76;
}

[data-theme="dark"] {
    --bg: #0d1117;
    --bg-card: #161b22;
    --text: #e6edf3;
    --text-muted: #8b949e;
    --accent: #3fb950;
    --accent-glow: rgba(63, 185, 80, 0.2);
    --accent-hover: #2ea043;
    --border: #30363d;
    --dice-bg: #238636;
    --dice-dot: #e6edf3;
    --error: #f85149;
    --toggle-icon: #8b949e;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Outfit', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.5s, color 0.5s;
    overflow: hidden;
    position: relative;
}

canvas#particles {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

.container {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 32px;
    padding: 24px;
    max-width: 480px;
    width: 100%;
}

/* ── Dice ── */
.dice-wrap {
    perspective: 600px;
    width: 120px;
    height: 120px;
}

.dice {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.dice.rolling {
    animation: diceRoll 0.8s ease-in-out infinite;
}

@keyframes diceRoll {
    0%   { transform: rotateX(0deg)   rotateY(0deg)   rotateZ(0deg); }
    25%  { transform: rotateX(90deg)  rotateY(45deg)  rotateZ(90deg); }
    50%  { transform: rotateX(180deg) rotateY(135deg) rotateZ(180deg); }
    75%  { transform: rotateX(270deg) rotateY(200deg) rotateZ(270deg); }
    100% { transform: rotateX(360deg) rotateY(360deg) rotateZ(360deg); }
}

.dice-face {
    position: absolute;
    width: 120px;
    height: 120px;
    border-radius: 16px;
    background: var(--dice-bg);
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    padding: 16px;
    box-shadow: inset 0 0 0 2px rgba(255,255,255,0.1);
}

.dice-face.f-front  { transform: translateZ(60px); }
.dice-face.f-back   { transform: rotateY(180deg) translateZ(60px); }
.dice-face.f-right  { transform: rotateY(90deg)  translateZ(60px); }
.dice-face.f-left   { transform: rotateY(-90deg) translateZ(60px); }
.dice-face.f-top    { transform: rotateX(90deg)  translateZ(60px); }
.dice-face.f-bottom { transform: rotateX(-90deg) translateZ(60px); }

.dot {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--dice-dot);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.15);
    place-self: center;
}

/* Face 1: center only */
.face-1 .dot:nth-child(1) { grid-area: 2 / 2; }

/* Face 2: top-right, bottom-left */
.face-2 .dot:nth-child(1) { grid-area: 1 / 3; }
.face-2 .dot:nth-child(2) { grid-area: 3 / 1; }

/* Face 3: diagonal top-left → bottom-right */
.face-3 .dot:nth-child(1) { grid-area: 1 / 1; }
.face-3 .dot:nth-child(2) { grid-area: 2 / 2; }
.face-3 .dot:nth-child(3) { grid-area: 3 / 3; }

/* Face 4: four corners */
.face-4 .dot:nth-child(1) { grid-area: 1 / 1; }
.face-4 .dot:nth-child(2) { grid-area: 1 / 3; }
.face-4 .dot:nth-child(3) { grid-area: 3 / 1; }
.face-4 .dot:nth-child(4) { grid-area: 3 / 3; }

/* Face 5: four corners + center */
.face-5 .dot:nth-child(1) { grid-area: 1 / 1; }
.face-5 .dot:nth-child(2) { grid-area: 1 / 3; }
.face-5 .dot:nth-child(3) { grid-area: 2 / 2; }
.face-5 .dot:nth-child(4) { grid-area: 3 / 1; }
.face-5 .dot:nth-child(5) { grid-area: 3 / 3; }

/* Face 6: two columns of three */
.face-6 .dot:nth-child(1) { grid-area: 1 / 1; }
.face-6 .dot:nth-child(2) { grid-area: 1 / 3; }
.face-6 .dot:nth-child(3) { grid-area: 2 / 1; }
.face-6 .dot:nth-child(4) { grid-area: 2 / 3; }
.face-6 .dot:nth-child(5) { grid-area: 3 / 1; }
.face-6 .dot:nth-child(6) { grid-area: 3 / 3; }

/* ── Typography ── */
.title {
    font-family: 'Space Mono', monospace;
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
    text-align: center;
    line-height: 1.2;
}

.subtitle {
    font-size: 15px;
    color: var(--text-muted);
    font-weight: 300;
    text-align: center;
    max-width: 320px;
    line-height: 1.5;
}

/* ── Status ── */
.status {
    font-family: 'Space Mono', monospace;
    font-size: 13px;
    color: var(--text-muted);
    min-height: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.3s;
}

.status.visible { opacity: 1; }

.status .spinner {
    width: 14px;
    height: 14px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

.status.error { color: var(--error); }

/* ── Button ── */
.btn {
    font-family: 'Space Mono', monospace;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 14px 36px;
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.15) 0%, transparent 50%);
    opacity: 0;
    transition: opacity 0.3s;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px var(--accent-glow);
    border-color: var(--accent-hover);
}

.btn:hover::before { opacity: 1; }

.btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 10px var(--accent-glow);
}

.btn.loading-btn {
    opacity: 0.7;
    pointer-events: none;
}

/* ── Theme Toggle ── */
.theme-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--toggle-icon);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
}

.theme-toggle:hover {
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: 0 0 12px var(--accent-glow);
}

.theme-toggle svg { width: 18px; height: 18px; }

.theme-toggle .icon-sun,
.theme-toggle .icon-moon { display: none; }

[data-theme="dark"] .theme-toggle .icon-sun  { display: block; }
[data-theme="light"] .theme-toggle .icon-moon { display: block; }

/* ── Footer hint ── */
.hint {
    font-size: 12px;
    color: var(--text-muted);
    opacity: 0.5;
    font-family: 'Space Mono', monospace;
}

.hint a {
    color: var(--accent);
    text-decoration: none;
}

.hint a:hover { text-decoration: underline; }

/* ── Entrance animation ── */
.container > * {
    opacity: 0;
    transform: translateY(16px);
    animation: fadeUp 0.6s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.container > *:nth-child(1) { animation-delay: 0.1s; }
.container > *:nth-child(2) { animation-delay: 0.2s; }
.container > *:nth-child(3) { animation-delay: 0.3s; }
.container > *:nth-child(4) { animation-delay: 0.35s; }
.container > *:nth-child(5) { animation-delay: 0.4s; }
.container > *:nth-child(6) { animation-delay: 0.45s; }

@keyframes fadeUp {
    to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
    .dice.rolling { animation: none; }
    .container > * { animation: none; opacity: 1; transform: none; }
    .status .spinner { animation: none; }
}
