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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f0f2f5;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 20px;
}

.container {
    max-width: 900px;
    width: 100%;
    padding: 20px 0;
}

h1 {
    font-size: 32px;
    color: #2c3e50;
    margin-bottom: 15px;
    font-weight: 700;
    text-align: center;
}

.description {
    text-align: center;
    margin-bottom: 25px;
}

.description p {
    font-size: 14px;
    color: #555;
    line-height: 1.6;
    max-width: 700px;
    margin: 0 auto;
}

.controls {
    background: #fff;
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 20px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    border: 1px solid #e0e3e8;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control-group label {
    font-size: 13px;
    font-weight: 600;
    color: #2c3e50;
}

.control-group select,
.control-group input[type="range"] {
    width: 100%;
    padding: 8px;
    border: 2px solid #ddd;
    border-radius: 5px;
    font-size: 13px;
    background: white;
}

.control-group select {
    cursor: pointer;
}

.control-group input[type="range"] {
    cursor: pointer;
}

.animation-area {
    position: relative;
    height: 500px;
    background: #e8ecf0;
    border-radius: 10px;
    margin-bottom: 20px;
    overflow: hidden;
    border: 1px solid #d0d5de;
}

.timestep-display {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 14px;
    font-weight: 600;
    color: #2c3e50;
    background: rgba(255, 255, 255, 0.9);
    padding: 6px 12px;
    border-radius: 5px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    z-index: 100;
}

.user-box {
    position: absolute;
    top: 20px;
    left: 20px;
    width: 80px;
    height: 80px;
    background: #3498db;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    z-index: 10;
}

.bucket {
    position: absolute;
    top: 50%;
    left: 20px;
    transform: translateY(-50%);
    width: 140px;
    min-height: 200px;
    background: #27ae60;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    border: 4px solid #229954;
    z-index: 5;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    padding: 8px;
    gap: 4px;
}

.tokens-container {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    width: 100%;
    align-content: flex-start;
    overflow: hidden;
    max-height: 100%;
}

.token {
    width: 20px;
    height: 20px;
    background: #1e6f42;
    border-radius: 3px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.refill-box {
    position: absolute;
    bottom: 20px;
    left: 20px;
    width: 80px;
    height: 80px;
    background: #f1c40f;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    z-index: 10;
}

.request-particle {
    position: absolute;
    width: 50px;
    height: 50px;
    background: #3498db;
    border-radius: 6px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    z-index: 15;
    transition: all 0.05s linear;
}

.refill-particle {
    position: absolute;
    width: 50px;
    height: 50px;
    background: #f1c40f;
    border-radius: 6px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    z-index: 15;
    transition: all 0.05s linear;
}

.explosion {
    position: absolute;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(255, 107, 107, 0.8) 0%, rgba(255, 107, 107, 0) 70%);
    animation: explode 0.5s ease-out forwards;
    z-index: 20;
    pointer-events: none;
}

@keyframes explode {
    0% {
        transform: scale(0);
        opacity: 1;
    }
    100% {
        transform: scale(2);
        opacity: 0;
    }
}

.label {
    position: absolute;
    font-size: 14px;
    font-weight: 600;
    color: #2c3e50;
    background: rgba(255, 255, 255, 0.9);
    padding: 4px 10px;
    border-radius: 5px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Labels sit to the RIGHT of their elements */
.user-label {
    top: 20px;
    left: 110px;
}

.bucket-label {
    top: 50%;
    left: 170px;
    transform: translateY(-50%);
}

.refill-label {
    bottom: 20px;
    left: 110px;
}

.feedback-text {
    position: absolute;
    font-size: 20px;
    font-weight: 700;
    pointer-events: none;
    animation: slideDownFade 1.7s ease-out forwards;
}

.feedback-text.accepted {
    color: #27ae60;
}

.feedback-text.rejected {
    color: #e74c3c;
}

.feedback-text.overflow {
    color: #f39c12;
}

@keyframes slideDownFade {
    0% {
        opacity: 1;
        transform: translateY(0);
    }
    60% {
        opacity: 1;
        transform: translateY(40px);
    }
    100% {
        opacity: 0;
        transform: translateY(80px);
    }
}

.stats {
    background: #fff;
    padding: 20px;
    border-radius: 10px;
    border: 1px solid #e0e3e8;
    overflow-x: auto;
}

.stats h3 {
    font-size: 20px;
    color: #2c3e50;
    margin-bottom: 15px;
    font-weight: 700;
    text-align: center;
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0 auto;
}

.stats-table th,
.stats-table td {
    padding: 12px 20px;
    text-align: left;
    border-bottom: 1px solid #ddd;
}

.stats-table th {
    background: #e8ecef;
    font-weight: 700;
    color: #2c3e50;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stats-table td {
    font-size: 15px;
    color: #555;
}

.stats-table tr:last-child td {
    border-bottom: none;
}

.stats-table tbody tr:hover {
    background: #f8f9fa;
}

.stat-accepted {
    color: #27ae60;
    font-weight: 700;
    font-size: 16px;
}

.stat-rejected {
    color: #e74c3c;
    font-weight: 700;
    font-size: 16px;
}

.stat-overflow {
    color: #f39c12;
    font-weight: 700;
    font-size: 16px;
}

.stat-avg {
    color: #3498db;
    font-weight: 700;
    font-size: 16px;
}

@media (max-width: 640px) {
    body {
        padding: 10px;
    }

    h1 {
        font-size: 22px;
    }

    .description {
        margin-bottom: 16px;
    }

    .controls {
        padding: 12px;
        margin-bottom: 14px;
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .animation-area {
        margin-bottom: 14px;
    }

    .stats {
        padding: 12px;
    }

    .stats-table th,
    .stats-table td {
        padding: 8px 10px;
        font-size: 12px;
    }

    .stat-accepted,
    .stat-rejected,
    .stat-overflow,
    .stat-avg {
        font-size: 13px;
    }
}
