/* Reset and base styles */
html {
    margin: 0;
    padding: 0;
    overflow-x: hidden;
    width: 100%;
    /* Gradient on HTML to let body pseudo-element stack on top */
    background: linear-gradient(135deg, rgb(230, 210, 185) 0%, rgb(210, 190, 165) 100%);
    background-attachment: fixed;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    padding: 40px 20px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: rgb(134, 83, 64);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    width: 100%;
    overflow-x: hidden;
    /* Ensure body doesn't cover its own pseudo-element if it background was here */
    background: transparent;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url('resources/background.png');
    background-size: cover;
    background-position: center;
    opacity: 0.3;
    z-index: -1;
}

.container {
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 50px;
    align-items: center;
    margin-top: -100px;
}

/* Disclaimer */
.disclaimer {
    position: fixed;
    bottom: 10px;
    left: 10px;
    text-align: left;
    font-size: 0.7rem;
    color: rgba(235, 220, 205, 0.8);
    background: rgba(45, 30, 12, 0.7);
    padding: 6px 16px;
    border-radius: 8px;
    border: 1px solid rgba(65, 50, 32, 0.5);
    max-width: 400px;
    line-height: 1.3;
}

/* Token Bar */
.token-bar-container {
    position: fixed;
    bottom: 70px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    max-width: 900px;
    height: 40px;
    background: rgb(235, 220, 205);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    border: 5px solid rgb(65, 50, 32);
}

.token-bar {
    display: flex;
    height: 100%;
    width: 100%;
}

.token-segment {
    height: 100%;
    transition: width 1s ease-out;
}

.token-segment.yellow {
    background: rgb(211, 165, 42);
}

.token-segment.red {
    background: rgb(186, 59, 80);
}

.token-segment.green {
    background: rgb(146, 152, 62);
}

.token-segment.gray {
    background: rgb(131, 132, 133);
}

.token-segment.brown {
    background: rgb(134, 83, 64);
}

.token-segment.blue {
    background: rgb(17, 127, 138);
}

/* Groups Container - Triangle Layout */
.groups-container {
    position: relative;
    width: 100%;
    max-width: 900px;
    height: 550px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.groups-container .group:nth-child(1) {
    position: absolute;
    top: 1px;
    left: 50%;
    transform: translateX(-50%);
}

.groups-container .group:nth-child(2) {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(calc(-50% - 155px));
}

.groups-container .group:nth-child(3) {
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(calc(-50% + 155px));
}

.group {
    width: 280px;
    height: 280px;
    border-radius: 50%;
    background: linear-gradient(145deg, rgba(65, 50, 32, 0.75), rgba(45, 30, 12, 0.75));
    box-shadow:
        inset 0 6px 15px rgba(0, 0, 0, 0.5),
        0 15px 40px rgba(55, 40, 22, 0.5);
    border: 5px solid rgb(65, 50, 32);
    display: flex;
    align-items: center;
    justify-content: center;
    /* Isolate group rendering */
    contain: paint;
}

.group-tokens {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    align-items: center;
    justify-items: center;
    width: 180px;
}

.group-tokens .token:first-child {
    grid-column: 1 / -1;
    justify-self: center;
}

.token {
    width: 75px;
    height: 75px;
    border-radius: 50%;
    background-size: cover;
    background-position: center;
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.5);
    /* Performance optimizations for mobile */
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    transform: translate3d(0, 0, 0);
    will-change: transform, opacity;
}

/* Token Images */
.token.blue {
    background-image: url('resources/water.png');
    background-color: rgb(17, 127, 138);
}

.token.gray {
    background-image: url('resources/mountain.png');
    background-color: rgb(131, 132, 133);
}

.token.brown {
    background-image: url('resources/trunk.png');
    background-color: rgb(134, 83, 64);
}

.token.green {
    background-image: url('resources/leaves.png');
    background-color: rgb(146, 152, 62);
}

.token.yellow {
    background-image: url('resources/fields.png');
    background-color: rgb(211, 165, 42);
}

.token.red {
    background-image: url('resources/house.png');
    background-color: rgb(186, 59, 80);
}

/* Toast */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: linear-gradient(145deg, rgba(65, 50, 32, 0.75), rgba(45, 30, 12, 0.75));
    color: rgb(235, 220, 205);
    padding: 20px 25px;
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4);
    border: 3px solid rgb(65, 50, 32);
    max-width: 320px;
    opacity: 0;
    transform: translateX(400px);
    transition: all 1s ease;
    z-index: 2000;
}

.toast.show {
    opacity: 1;
    transform: translateX(0);
}

.toast.falling {
    opacity: 0;
    transform: translate3d(0, 1000px, 0) rotate(45deg);
    transition: all 1.2s ease-in;
}

.toast-content {
    display: flex;
    align-items: flex-start;
}

.toast-content p {
    margin: 0;
    font-size: 1.1rem;
    line-height: 1.5;
}

.toast-content strong {
    color: rgb(211, 165, 42);
    font-weight: 700;
}

/* Controls */
.controls {
    display: flex;
    justify-content: center;
    padding: 20px 0;
}

.btn-draw {
    background: linear-gradient(135deg, rgb(166, 172, 82), rgb(146, 152, 62));
    color: white;
    padding: 20px 50px;
    font-size: 1.5rem;
    font-weight: 800;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    box-shadow: 0 8px 25px rgba(146, 152, 62, 0.4);
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.btn-draw:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 35px rgba(146, 152, 62, 0.5);
}

.btn-draw:active {
    transform: translateY(-2px);
}

.btn-draw:disabled {
    background: linear-gradient(135deg, rgb(160, 160, 160), rgb(131, 132, 133));
    cursor: not-allowed;
    transform: none;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.btn-draw:disabled:hover {
    transform: none;
}

/* Mobile Responsiveness */
@media (max-width: 600px) {
    body {
        padding: 20px 10px;
        align-items: center; /* Center vertically if space allows */
    }

    .container {
        gap: 25px;
        margin-top: 0;
        height: auto;
        min-height: calc(100vh - 40px);
        justify-content: center;
        padding-bottom: 20px;
        /* Removed padding-left to keep content centered */
    }

    .groups-container {
        display: contents;
    }

    .groups-container .group:nth-child(1),
    .groups-container .group:nth-child(2),
    .groups-container .group:nth-child(3) {
        position: static;
        transform: none;
        margin: 0 auto;
    }

    .group {
        width: 180px; 
        height: 180px;
        border: 4px solid rgb(65, 50, 32);
        box-shadow: 
            inset 0 4px 10px rgba(0, 0, 0, 0.4),
            0 8px 20px rgba(55, 40, 22, 0.4);
    }

    .group-tokens {
        width: 120px;
        gap: 12px;
    }

    .token {
        width: 50px;
        height: 50px;
        box-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
    }

    .token-bar-container {
        position: fixed;
        /* Position center of bar at 10px from edge + half of thickness (12px) = 22px */
        /* To center a 300px wide element at 22px, left = 22 - 150 = -128px */
        left: -128px;
        top: 50%;
        width: 300px;
        height: 24px;
        transform: translateY(-50%) rotate(-90deg);
        transform-origin: center center;
        border: 3px solid rgb(65, 50, 32);
        margin: 0;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
        z-index: 1000;
        pointer-events: none;
    }

    .disclaimer {
        display: none;
    }

    .toast {
        top: 20px;
        right: 15px;
        left: 15px;
        max-width: none;
        padding: 15px;
        text-align: center;
        border-width: 2px;
    }
}
