.dice3d-tool-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    border: 2px solid #ccc;
    border-radius: 12px;
    max-width: 600px;
    width: 100%;
    background: #ffffff;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    margin: 20px auto 40px;
    box-sizing: border-box;
    /* Ensure padding is included in width */
}

/* --- Fullscreen Simulation for iOS/Mobile --- */
body.dice3d-simulated-fullscreen {
    overflow: hidden;
    /* Hide body scrollbars */
}

.dice3d-tool-container.dice3d-simulated-fullscreen-active {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    max-width: 100%;
    border-radius: 0;
    overflow-y: auto;
    background-color: #fff;
}


.dice3d-tool-container h2 {
    text-align: center;
    color: #333;
    margin-top: 0;
    margin-bottom: 50px;
}

.dice3d-tab-content {
    display: none;
    flex-direction: column;
    align-items: center;
}

.dice3d-tab-content.active {
    display: flex;
}


.dice3d-controls {
    display: flex;
    flex-direction: row;
    /* Horizontal on desktop */
    flex-wrap: wrap;
    justify-content: center;
    gap: 20px;
    width: 100%;
}

.dice3d-control-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.dice3d-input-row {
    display: flex;
    gap: 5px;
    align-items: center;
}


.dice3d-control-group label {
    font-weight: 500;
    font-size: 16px;
}

.dice3d-control-group select,
.dice3d-control-group input {
    padding: 10px;
    border-radius: 6px;
    border: 1px solid #ccc;
    min-width: 80px;
    text-align: center;
    font-size: 15px;
}

/* Override theme styles for inputs and selects */
.dice3d-tool-container input[type="text"],
.dice3d-tool-container input[type="number"],
.dice3d-tool-container select {
    background-color: #fff;
    border: 1px solid #ccc;
    border-radius: 6px;
    outline: none;
    box-shadow: none;
}

.dice3d-tool-container input[type="text"]:hover,
.dice3d-tool-container input[type="number"]:hover,
.dice3d-tool-container select:hover,
.dice3d-tool-container input[type="text"]:active,
.dice3d-tool-container input[type="number"]:active,
.dice3d-tool-container select:active {
    background-color: #fff;
    /* Force white background */
    border: 1px solid #ccc;
    /* Prevent theme from changing border on hover */
    box-shadow: none;
}

.dice3d-tool-container input[type="text"]:focus,
.dice3d-tool-container input[type="number"]:focus,
.dice3d-tool-container select:focus {
    border: 1px solid #8ab4f8;
    /* Light blue highlight on focus */
    background-color: #fff;
    /* Ensure white background on focus */
    box-shadow: 0 0 0 1px rgba(138, 180, 248, 0.4);
    /* Add a soft shadow */
}

.dice3d-control-group select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='24' height='24' viewBox='0 0 20 20' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M6 8L10 12L14 8' stroke='%236B7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 5px center;
    background-size: 20px;
    padding-right: 35px;
    cursor: pointer;
}

#custom-sides {
    width: 80px;
}

/* Hide number input spinners */
.dice3d-control-group input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}

.dice3d-control-group input[type="number"]::-webkit-outer-spin-button,
.dice3d-control-group input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.dice3d-hidden {
    display: none !important;
}

.dice3d-scene-container {
    display: flex;
    flex-wrap: wrap;
    gap: 30px;
    justify-content: center;
    margin-bottom: 20px;
    min-height: 150px;
    /* Reserve space */
}

.dice3d-scene {
    width: 130px;
    height: 130px;
    perspective: 600px;
}

.dice3d-cube {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 2s cubic-bezier(0.1, 0.9, 0.3, 1);
}

.no-transition {
    transition: none !important;
}

.dice3d-face {
    position: absolute;
    width: 130px;
    height: 130px;
    background: #fff;
    border: 1px solid #bbb;
    border-radius: 10px;
    box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 38px;
    font-weight: bold;
    font-family: sans-serif;
    padding: 5px;
    box-sizing: border-box;
}

/* Styles for non-D6 dice faces */
.dice-face-generic {
    width: 130px;
    height: 130px;
    background: #fff;
    border: 1px solid #bbb;
    border-radius: 10px;
    box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 42px;
    font-weight: bold;
    font-family: sans-serif;
    box-sizing: border-box;
    cursor: pointer;
}

/* --- Keyframes for various non-D6 dice animations --- */
@keyframes tumble-x {
    from {
        transform: rotateX(0deg);
        opacity: 0.8;
    }

    to {
        transform: rotateX(1080deg);
        opacity: 1;
    }
}

@keyframes tumble-y {
    from {
        transform: rotateY(0deg);
        opacity: 0.8;
    }

    to {
        transform: rotateY(1080deg);
        opacity: 1;
    }
}

@keyframes tumble-xy {
    from {
        transform: rotateX(0) rotateY(0);
        opacity: 0.8;
    }

    to {
        transform: rotateX(-720deg) rotateY(-720deg);
        opacity: 1;
    }
}

@keyframes tumble-z {
    from {
        transform: rotateZ(0deg);
        opacity: 0.8;
    }

    to {
        transform: rotateZ(1080deg);
        opacity: 1;
    }
}

@keyframes continuous-roll {
    from {
        transform: rotateX(0) rotateY(0) rotateZ(0);
    }

    to {
        transform: rotateX(360deg) rotateY(360deg) rotateZ(360deg);
    }
}

@keyframes dice-settle {

    0%,
    100% {
        transform: translate(0, 0);
    }

    25% {
        transform: translate(-4px, -4px);
    }

    50% {
        transform: translate(2px, 2px);
    }

    75% {
        transform: translate(-1px, -1px);
    }
}

.dice3d-settle {
    animation: dice-settle 0.5s ease-out;
}

/* --- Classes to apply the random animations --- */
.dice3d-tumbling {
    animation-duration: 2.5s;
    animation-timing-function: cubic-bezier(0.1, 0.9, 0.3, 1);
    animation-fill-mode: forwards;
}

.dice3d-tumble-x {
    animation-name: tumble-x;
}

.dice3d-tumble-y {
    animation-name: tumble-y;
}

.dice3d-tumble-xy {
    animation-name: tumble-xy;
}

.dice3d-tumble-z {
    animation-name: tumble-z;
}

.dice3d-continuous-roll {
    animation: continuous-roll 20s linear infinite;
}

.dice3d-dot {
    display: block;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #333;
}

.dice3d-face-dots {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    place-items: center;
    padding: 10px;
    box-sizing: border-box;
}

/* --- Correct Pip Placement --- */
/* Face 1 */
.dice3d-face-dots.dice3d-face1 .dice3d-dot:nth-child(1) {
    grid-area: 2 / 2;
}

/* Face 2 */
.dice3d-face-dots.dice3d-face2 .dice3d-dot:nth-child(1) {
    grid-area: 1 / 1;
}

.dice3d-face-dots.dice3d-face2 .dice3d-dot:nth-child(2) {
    grid-area: 3 / 3;
}

/* Face 3 */
.dice3d-face-dots.dice3d-face3 .dice3d-dot:nth-child(1) {
    grid-area: 1 / 1;
}

.dice3d-face-dots.dice3d-face3 .dice3d-dot:nth-child(2) {
    grid-area: 2 / 2;
}

.dice3d-face-dots.dice3d-face3 .dice3d-dot:nth-child(3) {
    grid-area: 3 / 3;
}

/* Face 4 */
.dice3d-face-dots.dice3d-face4 .dice3d-dot:nth-child(1) {
    grid-area: 1 / 1;
}

.dice3d-face-dots.dice3d-face4 .dice3d-dot:nth-child(2) {
    grid-area: 1 / 3;
}

.dice3d-face-dots.dice3d-face4 .dice3d-dot:nth-child(3) {
    grid-area: 3 / 1;
}

.dice3d-face-dots.dice3d-face4 .dice3d-dot:nth-child(4) {
    grid-area: 3 / 3;
}

/* Face 5 */
.dice3d-face-dots.dice3d-face5 .dice3d-dot:nth-child(1) {
    grid-area: 1 / 1;
}

.dice3d-face-dots.dice3d-face5 .dice3d-dot:nth-child(2) {
    grid-area: 1 / 3;
}

.dice3d-face-dots.dice3d-face5 .dice3d-dot:nth-child(3) {
    grid-area: 2 / 2;
}

.dice3d-face-dots.dice3d-face5 .dice3d-dot:nth-child(4) {
    grid-area: 3 / 1;
}

.dice3d-face-dots.dice3d-face5 .dice3d-dot:nth-child(5) {
    grid-area: 3 / 3;
}

/* Face 6 */
.dice3d-face-dots.dice3d-face6 .dice3d-dot:nth-child(1) {
    grid-area: 1 / 1;
}

.dice3d-face-dots.dice3d-face6 .dice3d-dot:nth-child(2) {
    grid-area: 2 / 1;
}

.dice3d-face-dots.dice3d-face6 .dice3d-dot:nth-child(3) {
    grid-area: 3 / 1;
}

.dice3d-face-dots.dice3d-face6 .dice3d-dot:nth-child(4) {
    grid-area: 1 / 3;
}

.dice3d-face-dots.dice3d-face6 .dice3d-dot:nth-child(5) {
    grid-area: 2 / 3;
}

.dice3d-face-dots.dice3d-face6 .dice3d-dot:nth-child(6) {
    grid-area: 3 / 3;
}


.dice3d-face1 {
    transform: rotateY(0deg) translateZ(65px);
}

.dice3d-face2 {
    transform: rotateY(90deg) translateZ(65px);
}

.dice3d-face3 {
    transform: rotateY(180deg) translateZ(65px);
}

.dice3d-face4 {
    transform: rotateY(-90deg) translateZ(65px);
}

.dice3d-face5 {
    transform: rotateX(90deg) translateZ(65px);
}

.dice3d-face6 {
    transform: rotateX(-90deg) translateZ(65px);
}

.dice3d-roll-btn {
    padding: 8px 20px;
    background-color: #238839;
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 500;
    transition: background-color 0.3s, transform 0.1s ease;
}

.dice3d-result-summary {
    min-height: 27px;
    /* Reserve space to prevent layout shift */
    font-size: 20px;
    font-weight: 500;
    color: #333;
    text-align: center;
}

.dice3d-summary-note {
    font-size: 16px;
    color: #6c757d;
}

.dice3d-stats-container.is-visible {
    display: block;
}

.dice3d-result-number {
    color: #238839;
    font-weight: 500;
}

.dice3d-player-highlight {
    color: #0056b3;
    /* A distinct blue for the player's name */
    font-weight: 500;
}

.dice3d-game-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin: 15px 0 0 0;
}

#dice3d-clear-stats-btn {
    background-color: #6c757d;
}

#dice3d-settings-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #0873e6;
    padding: 8px;
}

#dice3d-back-btn {
    background-color: #0873e6;
}

#dice3d-fullscreen-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    background-color: #0873e6;
}

#dice3d-fullscreen-btn svg {
    width: 23px;
    height: 23px;
}

#dice3d-settings-btn svg {
    width: 20px;
    height: 20px;
    fill: white;
}


.dice3d-settings-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 25px;
}

#dice3d-clear-settings-btn {
    background-color: #6c757d;
}

/* Add a consistent click effect for all buttons */
.dice3d-tool-container button:active {
    transform: scale(0.98);
}

/* Override theme styles for buttons to prevent unwanted hover/focus effects */
.dice3d-roll-btn:hover,
.dice3d-roll-btn:focus,
.dice3d-roll-btn:active {
    outline: none;
    box-shadow: none;
    color: #fff;
    /* Ensure text color remains white */
}

#dice3d-roll-btn:hover,
#dice3d-roll-btn:focus,
#dice3d-roll-btn:active,
#dice3d-save-settings-btn:hover,
#dice3d-save-settings-btn:focus,
#dice3d-save-settings-btn:active {
    background-color: #238839;
}

#dice3d-clear-stats-btn:hover,
#dice3d-clear-stats-btn:focus,
#dice3d-clear-stats-btn:active,
#dice3d-clear-settings-btn:hover,
#dice3d-clear-settings-btn:focus,
#dice3d-clear-settings-btn:active {
    background-color: #6c757d;
}

#dice3d-settings-btn:hover,
#dice3d-settings-btn:focus,
#dice3d-settings-btn:active,
#dice3d-back-btn:hover,
#dice3d-back-btn:focus,
#dice3d-back-btn:active,
#dice3d-fullscreen-btn:hover,
#dice3d-fullscreen-btn:focus,
#dice3d-fullscreen-btn:active {
    background-color: #0873e6;
}

.dice3d-players-section {
    width: 100%;
    max-width: 350px;
    /* Match controls width */
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    /* Left-align checkboxes */
    gap: 10px;
}

.dice3d-player-toggle-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
    font-size: 16px;
    cursor: pointer;
}

.dice3d-player-toggle-label input[type="checkbox"] {
    width: 1.2em;
    height: 1.2em;
    cursor: pointer;
    vertical-align: middle;
    /* Better alignment with text */
}

.dice3d-player-toggle-label:has(input:disabled) {
    color: #999;
    cursor: not-allowed;
}

.dice3d-hidden {
    display: none;
}

.dice3d-player-inputs-wrapper-styles {
    display: flex;
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    padding-left: 25px;
    box-sizing: border-box;
}

.dice3d-player-input-group {
    display: flex;
    gap: 8px;
    padding: 5px 0;
    width: 100%;
}

.dice3d-player-name {
    flex-grow: 1;
    padding: 10px;
    border-radius: 6px;
    border: 1px solid #ccc;
    font-size: 15px;
}

.dice3d-add-player-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 5px 8px;
    border-radius: 6px;
    border: 1px solid #ccc;
    cursor: pointer;
    background: #f0f0f0;
    font-weight: 500;
    margin-left: 25px;
    transition: transform 0.1s ease;
    color: #333;
    /* Set a dark color for the text */
}

/* Prevent theme from changing Add Player button on hover/focus */
.dice3d-add-player-btn:hover,
.dice3d-add-player-btn:focus,
.dice3d-add-player-btn:active {
    background: #f0f0f0;
    color: #333;
}

.dice3d-remove-player-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: transparent;
    border: none;
    color: #dc3545;
    /* Red color */
    cursor: pointer;
    padding: 0;
    /* Clickable area */
    transition: transform 0.1s ease;
}

.dice3d-remove-player-btn:hover,
.dice3d-remove-player-btn:focus,
.dice3d-remove-player-btn:active {
    background-color: transparent;
    color: #dc3545;
}

.dice3d-remove-player-btn svg {
    width: 25px;
    height: 25px;
}

.dice3d-add-player-btn svg {
    width: 21px;
    height: 21px;
}

.dice3d-stats-container {
    display: none;
    /* Hidden by default */
    width: 100%;
    max-width: 500px;
    margin-top: 20px;
    max-height: 200px;
    overflow: auto;
}

.dice3d-stats-table {
    width: 100%;
    border-collapse: collapse;
    text-align: center;
}

.dice3d-stats-table th,
.dice3d-stats-table td {
    padding: 8px 12px;
    border: 1px solid #ddd;
    font-size: 17px;
}

.dice3d-stats-table th {
    background-color: #e9ecef;
    font-weight: 500;
}

.dice3d-new-roll {
    color: #dc3545;
    /* A distinct red color */
    font-weight: 500;
}

.faq-list {
    margin-top: 1rem;
}

.faq-list dt {
    font-weight: 500;
    font-size: 1.1em;
}

.faq-list dd {
    margin-left: 0;
    margin-top: 0.5rem;
    margin-bottom: 1rem;
    padding-left: 1rem;
    padding-bottom: 10px;
    border-bottom: 1px dashed #ddd;
}

/* mobile responsiveness */
@media (max-width: 600px) {
    .dice3d-tool-container {
        margin-left: 0;
        margin-right: 0;
        padding-left: 0;
        padding-right: 0;
        border-radius: 0;
        border-left: none;
        border-right: none;
        box-shadow: none;
    }

    .dice3d-controls {
        flex-direction: column;
        align-items: center;
    }

    .dice3d-players-section,
    .dice3d-stats-container {
        max-width: 100%;
        /* Ensure sections fit mobile screens */
    }

    .dice3d-player-inputs-wrapper-styles {
        padding-left: 0;
    }

    .dice3d-add-player-btn {
        margin-left: 0;
    }
}