:root {
    --dice-size: 80px;
    --transition-speed: 2.5s;
    --fade-speed: 1s;
}

body {
    /* Main body bg is handled by Tailwind classes in HTML, but here's a fallback/reset */
    margin: 0;
    font-family: 'Inter', sans-serif;
    overflow-x: hidden;
    /* Prevent popup from shifting viewport center */
}

/* 3D Container */
#container {
    position: relative;
    width: 100%;
    max-width: 600px;
    height: 600px;
    margin: 0 auto;
    /* Maintain center for circular dice positioning */
    /* Relative origin for absolute children (dice, button) */
}

/* Base dice wrapper */
.dice-wrap {
    perspective: 1200px;
    width: var(--dice-size);
    height: var(--dice-size);
    position: absolute;
    /* Centering offset logic will be handled in JS or via transform */
    top: 50%;
    left: 50%;
    margin-top: calc(var(--dice-size) / -2);
    margin-left: calc(var(--dice-size) / -2);
}

.dice {
    position: relative;
    width: 100%;
    height: 100%;
    transform-style: preserve-3d;
    transition: transform var(--transition-speed) cubic-bezier(0.2, 0.8, 0.3, 1);
}

/* Face Styles - Hybrid of User Request (Black) and Snippet (Structure) */
.face {
    position: absolute;
    width: var(--dice-size);
    height: var(--dice-size);
    background: #000000;
    /* User requirement */
    border: 2px solid #334155;
    /* From Snippet */
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    font-weight: 900;
    color: #ffffff;
    backface-visibility: hidden;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.5);
    /* Outer shadow from snippet (darkened) */
    user-select: none;
    overflow: hidden;
}

/* Centered Roll Button - Reference Style */
.center-roll-btn {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: #0f172a;
    /* Ciemne tło jak na screenie */
    color: #ffffff;
    font-weight: 800;
    font-size: 1.1rem;
    border: 5px solid #6366f1;
    /* Grubsza, niebieska ramka */
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 50;
    transition: box-shadow 0.3s ease, opacity 0.5s ease;
    text-transform: uppercase;
    box-shadow: 0 0 30px rgba(99, 102, 241, 0.6);
    /* Domyślnie 100% poświaty */
}

.center-roll-btn.hidden-roll {
    opacity: 0;
    pointer-events: none;
    box-shadow: 0 0 0px rgba(99, 102, 241, 0);
    /* Brak poświaty pri ukryciu */
}

.center-roll-btn:hover {
    box-shadow: 0 0 45px rgba(99, 102, 241, 0.8);
    /* Lekkie wzmocnienie na desktopie */
}

/* Mobile responsiveness scales the whole container down */
@media (max-width: 640px) {
    #container {
        width: 100%;
        height: auto;
        aspect-ratio: 1/1;
    }

    :root {
        --dice-size: 60px;
    }

    .face {
        /* Maximize inner content */
        font-size: 2.5rem;
        padding: 0;
        line-height: 1;
    }
}

/* Color overlay - hidden by default */
.color-overlay {
    position: absolute;
    inset: 0;
    opacity: 0;
    transition: opacity var(--fade-speed) ease-in-out;
    z-index: 1;
}

/* Letter must be above color overlay */
.letter {
    position: relative;
    z-index: 10;
    transition: color var(--fade-speed) ease-in-out;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

/* DYNAMIC 3D TRANSFORMS */
/* Ensure faces meet perfectly regardless of size */
.f-front {
    transform: rotateY(0deg) translateZ(calc(var(--dice-size) / 2));
}

.f-back {
    transform: rotateY(180deg) translateZ(calc(var(--dice-size) / 2));
}

.f-right {
    transform: rotateY(90deg) translateZ(calc(var(--dice-size) / 2));
}

.f-left {
    transform: rotateY(-90deg) translateZ(calc(var(--dice-size) / 2));
}

.f-top {
    transform: rotateX(90deg) translateZ(calc(var(--dice-size) / 2));
}

.f-bottom {
    transform: rotateX(-90deg) translateZ(calc(var(--dice-size) / 2));
}

/* Winner activation */
.winner .color-overlay {
    opacity: 0.8;
    /* Slightly transparent to keep texture/darkness check? Or full opacity? */
    /* The original had opacity 1. Let's stick effectively to that, but since backgrounds are dark, 
       we might want the color to pop. */
    opacity: 1;
}

.winner .letter {
    color: #ffffff;
}

/* Make sure the range slider looks good if not fully covered by Tailwind */
input[type=range] {
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    height: 10px;
    /* Force height */
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    height: 24px;
    width: 24px;
    border-radius: 50%;
    background: #6366f1;
    /* Indigo 500 */
    cursor: pointer;
    margin-top: -8px;
    /* Center thumb on track */
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.5);
    border: 2px solid #312e81;
    /* Dark indigo border */
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 8px;
    cursor: pointer;
    background: #334155;
    /* Slate 700 */
    border-radius: 4px;
    border: 1px solid #1e293b;
}

input[type=range]::-moz-range-thumb {
    height: 24px;
    width: 24px;
    border-radius: 50%;
    background: #6366f1;
    cursor: pointer;
    border: 2px solid #312e81;
}

input[type=range]::-moz-range-track {
    width: 100%;
    height: 8px;
    cursor: pointer;
    background: #334155;
    border-radius: 4px;
}

/* Result Popup Style */
.results-popup {
    position: relative;
    width: 95%;
    max-width: 440px;
    min-height: 180px;
    margin: 10px;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(20px);
    border: 2px solid rgba(99, 102, 241, 0.5);
    border-radius: 32px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
    box-shadow: 0 25px 60px rgba(0, 0, 0, 0.6);
    animation: popupFadeIn 0.5s cubic-bezier(0.16, 1, 0.3, 1);
    text-align: center;
}

.results-popup.desktop-side {
    position: absolute;
    left: 50%;
    margin-left: 320px;
    /* Force it to the right of the 600px container */
    top: 50%;
    transform: translateY(-50%);
    width: 360px;
    z-index: 100;
}

.try-again-message {
    font-size: 1.6rem;
    font-weight: 800;
    color: #475569;
    /* slate-600 */
    text-transform: uppercase;
    letter-spacing: 0.15em;
    margin-top: 1.5rem;
    opacity: 0.4;
    animation: fadeIn 1.5s ease-out forwards;
}

@media (min-width: 1024px) {
    .try-again-message {
        font-size: 2.8rem;
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 0.4;
        transform: translateY(0);
    }
}

@keyframes popupFadeIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.popup-close {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 30px;
    height: 30px;
    background: rgba(255, 255, 255, 0.05);
    border: none;
    border-radius: 50%;
    color: #94a3b8;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.popup-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

#wordsListPopup {
    max-height: 150px;
    overflow-y: auto;
    width: 100%;
    margin-top: 10px;
    padding: 5px;
}

#wordsListPopup::-webkit-scrollbar {
    width: 4px;
}

#wordsListPopup::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.3);
    border-radius: 2px;
}