body {
    font-family: 'Arial', sans-serif;
    margin: 0;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: flex-start; /* Align to top for better content flow */
    min-height: 100vh;
    transition: background-color 0.3s, color 0.3s;
}

/* Light Mode */
body.light-mode {
    background-color: #f0f2f5;
    color: #333;
}

body.light-mode .container {
    background-color: #ffffff;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

body.light-mode button {
    background-color: #007bff;
    color: white;
}

body.light-mode button:hover {
    background-color: #0056b3;
}

/* Dark Mode */
body.dark-mode {
    background-color: #2c3e50;
    color: #ecf0f1;
}

body.dark-mode .container {
    background-color: #34495e;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

body.dark-mode button {
    background-color: #2ecc71;
    color: white;
}

body.dark-mode button:hover {
    background-color: #27ae60;
}

.container {
    padding: 30px;
    border-radius: 10px;
    text-align: center;
    width: 100%;
    max-width: 600px;
}

/* Main App Controls (Dice vs Lottery) */
.main-controls {
    margin-bottom: 20px;
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

.main-controls button {
    padding: 12px 25px;
    font-size: 1.1em;
    font-weight: bold;
}

.app-section {
    display: none; /* Hidden by default */
    width: 100%;
}

.app-section:not(.hidden) {
    display: block; /* Show active section */
}

.hidden {
    display: none !important;
}


h1 {
    margin-bottom: 20px;
    color: inherit; /* Inherit color from body for theme changes */
}

.controls {
    margin-bottom: 30px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px; /* Adjusted gap for new button */
    align-items: center;
}

.controls label {
    font-size: 1.1em;
}

.controls input[type="number"] {
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 5px;
    width: 80px;
    text-align: center;
    font-size: 1em;
    -moz-appearance: textfield; /* Remove arrows in Firefox */
}

.controls input[type="number"]::-webkit-outer-spin-button,
.controls input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none; /* Remove arrows in Chrome, Safari, Edge */
    margin: 0;
}

button {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.2s ease-in-out;
}

#clearHistoryButton, #clearLotteryHistoryButton { /* Specific style for clear history buttons */
    background-color: #dc3545; /* Red color */
    color: white;
}

body.dark-mode #clearHistoryButton, body.dark-mode #clearLotteryHistoryButton {
    background-color: #e74c3c; /* Dark mode red */
}

#clearHistoryButton:hover, #clearLotteryHistoryButton:hover {
    background-color: #c82333;
}

body.dark-mode #clearHistoryButton:hover, body.dark-mode #clearLotteryHistoryButton:hover {
    background-color: #c0392b;
}


.dice-display {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 30px;
    min-height: 80px; /* Ensure space for dice */
}

.die {
    width: 60px;
    height: 60px;
    border: 2px solid; /* Will inherit color */
    border-radius: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 2em;
    font-weight: bold;
    transition: transform 0.1s ease-out;
    background-color: inherit; /* Inherit background for theme */
    color: inherit; /* Inherit color for theme */
}

.die.rolling {
    animation: rollAnimation 0.5s infinite;
}

@keyframes rollAnimation {
    0% { transform: translate(0, 0) rotate(0deg) scale(1); }
    25% { transform: translate(5px, -5px) rotate(5deg) scale(1.05); }
    50% { transform: translate(0, 0) rotate(0deg) scale(1); }
    75% { transform: translate(-5px, 5px) rotate(-5deg) scale(1.05); }
    100% { transform: translate(0, 0) rotate(0deg) scale(1); }
}

/* Lottery specific styles */
.lottery-numbers-display {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 30px;
    min-height: 80px; /* Ensure space for numbers */
}

.lottery-number {
    width: 50px;
    height: 50px;
    border-radius: 50%; /* Make them circular */
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5em;
    font-weight: bold;
    border: 2px solid;
    transition: transform 0.1s ease-out;
    background-color: #ffc107; /* Yellow background for numbers */
    color: #333;
}

body.dark-mode .lottery-number {
    background-color: #f39c12; /* Darker yellow for dark mode */
    color: #ecf0f1;
}

.lottery-number.generating {
    animation: generateNumberAnimation 0.8s infinite;
}

@keyframes generateNumberAnimation {
    0% { transform: scale(0.8) rotateY(0deg); opacity: 0.5; }
    50% { transform: scale(1.1) rotateY(180deg); opacity: 1; }
    100% { transform: scale(0.8) rotateY(360deg); opacity: 0.5; }
}


#totalDisplay {
    font-size: 1.5em;
    font-weight: bold;
    margin-top: 20px;
    color: inherit;
}

.history-section {
    margin-top: 40px;
    border-top: 1px solid; /* Will inherit color */
    padding-top: 20px;
}

.history-section h2 {
    margin-bottom: 15px;
    color: inherit;
}

#rollHistory, #lotteryHistory, #winningNumbersList {
    list-style: none;
    padding: 0;
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid #ccc;
    border-radius: 5px;
    text-align: left;
}

body.dark-mode #rollHistory, body.dark-mode #lotteryHistory, body.dark-mode #winningNumbersList {
    border-color: #555;
}

body.light-mode #rollHistory, body.light-mode #lotteryHistory, body.light-mode #winningNumbersList {
    border-color: #ddd;
}

#rollHistory li, #lotteryHistory li, #winningNumbersList li {
    padding: 8px 15px;
    border-bottom: 1px solid;
    font-size: 0.95em;
}

body.dark-mode #rollHistory li, body.dark-mode #lotteryHistory li, body.dark-mode #winningNumbersList li {
    border-color: #444;
}

body.light-mode #rollHistory li, body.light-mode #lotteryHistory li, body.light-mode #winningNumbersList li {
    border-color: #eee;
}

#rollHistory li:last-child, #lotteryHistory li:last-child, #winningNumbersList li:last-child {
    border-bottom: none;
}

/* Responsive adjustments */
@media (max-width: 480px) {
    .container {
        padding: 20px;
    }
    .main-controls button {
        font-size: 1em;
        padding: 10px 20px;
    }
    .controls {
        flex-direction: column;
        gap: 10px;
    }
    .controls input[type="number"] {
        width: 100px;
    }
    .die, .lottery-number {
        width: 50px;
        height: 50px;
        font-size: 1.5em;
    }
}
