/* ─── Reset & Base ─── */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #050506;
    --surface: #111827;
    --surface-light: #1f2937;
    --accent: #00A7E1;
    --accent-glow: rgba(0, 167, 225, 0.35);
    --accent-soft: rgba(0, 167, 225, 0.15);
    --text: #eaeaea;
    --text-dim: #9ca3af;
    --dice-bg: #fafafa;
    /* Keeping this as it's used later, but it's not in the provided new :root block. Assuming it should remain or be updated to a dark mode equivalent if specified. For now, keeping original value. */
    --dot-color: #1a1a2e;
    /* Keeping this as it's used later. */
    --dice-size: min(56vw, 200px, 30vh);
    --radius: 24px;
    --radius-sm: 12px;
}

html,
body {
    height: 100dvh;
    overflow: hidden;
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

/* ─── Layout ─── */
.app {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    max-width: 420px;
    margin: 0 auto;
    justify-content: space-between;
}

header {
    text-align: center;
    padding: 1rem 1rem .2rem;
    flex-shrink: 0;
    position: relative;
    z-index: 10;
}

header h1 {
    font-size: 1.6rem;
    font-weight: 900;
    background: linear-gradient(135deg, var(--accent), #007bb5);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2rem;
    min-height: 0;
    overflow: hidden;
}

/* ─── Dice Layout ─── */
.dice-wrapper {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 40px;
    /* Small separation when horizontal */
    width: 100%;
}

/* Reduce size when 2 dice are present to fit screens */
.two-dice-mode {
    --dice-size: min(40vw, 150px, 20vh);
}

@media (max-width: 500px) {
    .dice-wrapper.two-dice-mode {
        flex-direction: column;
        gap: 30px;
        --dice-size: min(50vw, 130px, 25vh);
        /* Slightly larger when stacked */
    }
}

/* ─── 3D Dice ─── */
.dice-container {
    perspective: 600px;
    width: var(--dice-size);
    height: var(--dice-size);
    max-height: 40vh;
    cursor: pointer;
}

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

.dice.rolling {
    transition: none;
    animation: roll .8s ease-out;
}

@keyframes roll {
    0% {
        transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg);
    }

    20% {
        transform: rotateX(340deg) rotateY(200deg) rotateZ(100deg);
    }

    40% {
        transform: rotateX(620deg) rotateY(460deg) rotateZ(220deg);
    }

    60% {
        transform: rotateX(900deg) rotateY(700deg) rotateZ(300deg);
    }

    80% {
        transform: rotateX(1100deg) rotateY(900deg) rotateZ(350deg);
    }

    100% {
        transform: rotateX(1260deg) rotateY(1080deg) rotateZ(360deg);
    }
}

/* ─── Faces ─── */
.face {
    position: absolute;
    width: 100%;
    height: 100%;
    background: var(--dice-bg);
    border-radius: var(--radius);
    border: 2px solid rgba(0, 0, 0, .06);
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    padding: 16%;
    gap: 6%;
    box-shadow: inset 0 0 18px rgba(0, 0, 0, .06);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/*  positions */
.face-1 {
    transform: rotateY(0deg) translateZ(calc(var(--dice-size)/2));
}

.face-2 {
    transform: rotateY(90deg) translateZ(calc(var(--dice-size)/2));
}

.face-3 {
    transform: rotateX(90deg) translateZ(calc(var(--dice-size)/2));
}

.face-4 {
    transform: rotateX(-90deg) translateZ(calc(var(--dice-size)/2));
}

.face-5 {
    transform: rotateY(-90deg) translateZ(calc(var(--dice-size)/2));
}

.face-6 {
    transform: rotateY(180deg) translateZ(calc(var(--dice-size)/2));
}

/* ─── Dots ─── */
.dot {
    width: 100%;
    height: 100%;
    background: var(--dot-color);
    border-radius: 50%;
    display: none;
}

/* grid placement */
.dot.top-left {
    grid-area: 1/1;
    display: block;
}

.dot.top-right {
    grid-area: 1/3;
    display: block;
}

.dot.mid-left {
    grid-area: 2/1;
    display: block;
}

.dot.center {
    grid-area: 2/2;
    display: block;
}

.dot.mid-right {
    grid-area: 2/3;
    display: block;
}

.dot.bottom-left {
    grid-area: 3/1;
    display: block;
}

.dot.bottom-right {
    grid-area: 3/3;
    display: block;
}

/* ─── Hint text ─── */
.hint {
    font-size: .95rem;
    color: var(--text-dim);
    letter-spacing: .03em;
    animation: pulse 2s ease-in-out infinite;
}

.hint.hidden {
    opacity: 0;
    transition: opacity .3s;
}

@keyframes pulse {

    0%,
    100% {
        opacity: .5;
    }

    50% {
        opacity: 1;
    }
}

/* ─── Result flash ─── */
.result-flash {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    font-size: 5rem;
    font-weight: 900;
    color: var(--accent);
    text-shadow: 0 0 40px var(--accent-glow);
    pointer-events: none;
    z-index: 100;
    animation: flash-in .7s ease-out forwards;
}

@keyframes flash-in {
    0% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 0;
    }

    40% {
        transform: translate(-50%, -50%) scale(1.4);
        opacity: 1;
    }

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

/* ─── History footer ─── */
footer {
    padding: .4rem 1rem 1rem;
    text-align: center;
    width: 100%;
    flex-shrink: 0;
}

.history {
    display: flex;
    gap: .5rem;
    justify-content: center;
    flex-wrap: wrap;
}

.history-item {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--surface);
    border: 1px solid rgba(255, 255, 255, .06);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: .85rem;
    color: var(--text);
    animation: pop-in .3s cubic-bezier(.34, 1.56, .64, 1) forwards;
    opacity: 0;
}

.history-item:first-child {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 0 12px var(--accent-glow);
}

.btn.primary {
    background: linear-gradient(135deg, var(--accent), #007bb5);
    color: #fff;
    font-weight: 700;
    font-size: 1.2rem;
    box-shadow: 0 8px 25px var(--accent-glow);
}

@keyframes pop-in {
    0% {
        transform: scale(0);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ─── Footer ─── */
.app-footer {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-dim);
    margin-top: 1rem;
    padding-bottom: 0.5rem;
    line-height: 1.5;
    z-index: 10;
}

.app-footer a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}

/* ─── Shake on tap (haptic feedback visual) ─── */
.dice-container:active .dice:not(.rolling) {
    filter: brightness(1.1);
}