body {
    font-family: sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    background: #f4f4f4;
    transition: background-color 0.3s, color 0.3s;
}

body.dark-mode {
    background-color: #121212;
    color: #ffffff;
}

.top-bar {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    box-sizing: border-box;
}

h1 {
    color: #333;
}

body.dark-mode h1 {
    color: #ffffff;
}

.controls {
    margin-bottom: 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: center;
    justify-content: center;
    background: #fff;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

body.dark-mode .controls {
    background: #1e1e1e;
    box-shadow: 0 2px 4px rgba(255, 255, 255, 0.1);
}

.controls label {
    margin-right: 5px;
}

.controls input,
.controls select,
.controls button {
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
}

body.dark-mode .controls input,
body.dark-mode .controls select {
    background-color: #333;
    color: #fff;
    border-color: #555;
}

.roll-button {
    padding: 12px 28px;
    border-radius: 50px;
    font-size: 16px;
    background: #2684FF;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    border: none;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
    box-shadow: 0 4px 15px rgba(38, 132, 255, 0.3);
}

.controls button:hover {
    background: linear-gradient(135deg, #2684FF, #0052CC);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(38, 132, 255, 0.4);
}

.controls button:active {
    transform: translateY(1px);
    box-shadow: 0 2px 10px rgba(38, 132, 255, 0.3);
}

body.dark-mode .controls button {
    background: linear-gradient(135deg, #4C9AFF, #2684FF);
    box-shadow: 0 4px 15px rgba(38, 132, 255, 0.25);
}

body.dark-mode .controls button:hover {
    background: linear-gradient(135deg, #2684FF, #0052CC);
    box-shadow: 0 6px 20px rgba(38, 132, 255, 0.35);
}

#themeToggle {
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    cursor: pointer;
}

body.dark-mode #themeToggle {
    background-color: #333;
    color: #fff;
    border-color: #555;
}

#diceContainer {
    display: flex;
    flex-wrap: nowrap; /* Prevent dice from wrapping */
    justify-content: center;
    gap: 20px;
    margin: 30px auto;
    padding: 20px; /* Add padding for animation space */
    overflow-x: auto; /* Enable horizontal scrolling */
    overflow-y: hidden;
    width: 100%;
    max-width: 100%;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
    box-sizing: border-box;
}

#diceContainer::-webkit-scrollbar {
    display: none;
}

.dice {
    width: 70px !important;
    height: 70px !important;
    min-width: 70px !important;
    min-height: 70px !important;
    perspective: 1200px; /* Increased perspective */
    flex: 0 0 70px;
    transform-origin: center;
    position: relative;
    /* Removed initial transform: rotateX(5deg) rotateY(5deg); */
    overflow: visible; /* Allow cube to be fully visible */
}

.cube {
    width: 70px !important;
    height: 70px !important;
    min-width: 70px !important;
    min-height: 70px !important;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 1s cubic-bezier(.17,.67,.83,.67);
    transform-origin: center center center; /* Ensure rotation around center */
}

.face {
    position: absolute;
    width: 70px !important;
    height: 70px !important;
    min-width: 70px !important;
    min-height: 70px !important;
    background: #fff;
    border: 2px solid #bbb;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    backface-visibility: visible;
    transform-origin: center;
}

body.dark-mode .face {
    background: #333;
    border-color: #555;
}

/* 3D positioning for cube faces - back to 35px */
.face.front  { transform: rotateY(0deg) translateZ(35px); }
.face.back   { transform: rotateY(180deg) translateZ(35px); }
.face.right  { transform: rotateY(90deg) translateZ(35px); }
.face.left   { transform: rotateY(-90deg) translateZ(35px); }
.face.top    { transform: rotateX(90deg) translateZ(35px); }
.face.bottom { transform: rotateX(-90deg) translateZ(35px); }

.dots-grid {
    width: 100% !important;
    height: 100% !important;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    padding: 10%;
    box-sizing: border-box;
    justify-items: center;
    align-items: center;
}

.dot {
    width: 14px !important;
    height: 14px !important;
    min-width: 14px !important;
    min-height: 14px !important;
    background: #222;
    border-radius: 50%;
    flex-shrink: 0;
}

body.dark-mode .dot {
    background: #fff;
}

#result {
    margin-top: 10px;
    font-size: 1.2em;
    font-weight: bold;
    color: #333;
}

body.dark-mode #result {
    color: #fff;
}

.stopwatch {
    font-size: 1.5em;
    font-weight: bold;
    margin-left: 20px; /* Add margin to separate from button */
    padding: 8px 12px; /* Match button padding */
    background: #fff;
    border-radius: 4px; /* Match button border-radius */
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    min-width: 80px; /* Adjust width */
    text-align: center;
}

body.dark-mode .stopwatch {
    background: #1e1e1e;
    box-shadow: 0 2px 4px rgba(255, 255, 255, 0.1);
}

.total-result {
    font-size: 1.5em;
    font-weight: bold;
    margin-top: 20px;
    padding: 10px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

body.dark-mode .total-result {
    background: #1e1e1e;
    box-shadow: 0 2px 4px rgba(255, 255, 255, 0.1);
}

.history-container {
    margin-top: 20px;
    width: 80%;
    max-width: 600px;
}

.history-container h2 {
    text-align: center;
}

#historyList {
    list-style: none;
    padding: 0;
    max-height: 150px;
    overflow-y: auto;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 10px;
}

body.dark-mode #historyList {
    border-color: #555;
}

#historyList li {
    padding: 5px 0;
    border-bottom: 1px solid #eee;
}

body.dark-mode #historyList li {
    border-bottom-color: #444;
}

#historyList li:last-child {
    border-bottom: none;
}

.cube.rolling {
    animation: roll 1s cubic-bezier(.17,.67,.83,.67);
    transform-origin: center;
}

@keyframes roll {
    0% { 
        transform: rotateX(0deg) rotateY(0deg) scale(1);
    }
    100% { 
        transform: rotateX(720deg) rotateY(720deg) scale(1);
    }
}

/* Responsive adjustments */
@media (max-width: 600px) {
    .controls {
        flex-direction: column;
        align-items: stretch;
    }
    .controls label,
    .controls button {
        width: 100%;
        box-sizing: border-box;
    }
    .stopwatch {
        margin-left: 0;
        margin-top: 10px;
    }
}
@media (max-width: 480px) {
    .dice {
        width: 60px !important;
        height: 60px !important;
        min-width: 60px !important;
        min-height: 60px !important;
    }
    .cube {
        width: 60px !important;
        height: 60px !important;
        min-width: 60px !important;
        min-height: 60px !important;
    }
    .face {
        width: 60px !important;
        height: 60px !important;
        min-width: 60px !important;
        min-height: 60px !important;
    }
    .face.front  { transform: rotateY(0deg) translateZ(30px); }
    .face.back   { transform: rotateY(180deg) translateZ(30px); }
    .face.right  { transform: rotateY(90deg) translateZ(30px); }
    .face.left   { transform: rotateY(-90deg) translateZ(30px); }
    .face.top    { transform: rotateX(90deg) translateZ(30px); }
    .face.bottom { transform: rotateX(-90deg) translateZ(30px); }
    .dot {
        width: 12px !important;
        height: 12px !important;
        min-width: 12px !important;
        min-height: 12px !important;
    }
}
@media (max-width: 360px) {
    .dice {
        width: 50px !important;
        height: 50px !important;
        min-width: 50px !important;
        min-height: 50px !important;
    }
    .cube {
        width: 50px !important;
        height: 50px !important;
        min-width: 50px !important;
        min-height: 50px !important;
    }
    .face {
        width: 50px !important;
        height: 50px !important;
        min-width: 50px !important;
        min-height: 50px !important;
    }
    .face.front  { transform: rotateY(0deg) translateZ(25px); }
    .face.back   { transform: rotateY(180deg) translateZ(25px); }
    .face.right  { transform: rotateY(90deg) translateZ(25px); }
    .face.left   { transform: rotateY(-90deg) translateZ(25px); }
    .face.top    { transform: rotateX(90deg) translateZ(25px); }
    .face.bottom { transform: rotateX(-90deg) translateZ(25px); }
    .dot {
        width: 10px !important;
        height: 10px !important;
        min-width: 10px !important;
        min-height: 10px !important;
    }
}

/* Side panel styles */
.side-panel {
    position: fixed;
    top: 0;
    left: -100%;
    width: 300px;
    height: 100%;
    background: #fff;
    box-shadow: 2px 0 5px rgba(0,0,0,0.2);
    transition: left 0.3s ease;
    padding: 20px;
    z-index: 1000;
}

body.dark-mode .side-panel {
    background: #1e1e1e;
    box-shadow: 2px 0 5px rgba(255,255,255,0.1);
}

.side-panel.open {
    left: 0;
}

.menu-button {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 10px;
    color: #333;
    z-index: 1001;
}

.top-left-menu-button {
    position: absolute;
    top: 10px;
    left: 10px;
}

body.dark-mode .menu-button {
    color: #ffffff;
}

.menu-button:hover {
    opacity: 0.8;
}