:root {
    --bg-color: #1e293b;
    --text-color: #f8fafc;
    --primary-color: #3b82f6;
    --secondary-color: #8b5cf6;
    --panel-bg: rgba(255, 255, 255, 0.1);
    --font-main: 'Fredoka', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-color);
    color: var(--text-color);
    height: 100vh;
    overflow: hidden;
    /* We restore flex on body to support pages without #app, but #app pages will override/nest properly */
    display: flex;
    flex-direction: column;
    transition: background 0.5s ease, color 0.5s ease;
    background-size: 400% 400%;
    animation: gradientBG 15s ease infinite;
    max-height: 100vh;
}

/* For pages with #app wrapper, it takes over the flex container role */
#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100%;
    overflow: hidden;
    flex: 1; /* Ensure it fills body */
}

/* Themes */
body.theme-default {
    background: linear-gradient(-45deg, #1e293b, #0f172a, #334155, #1e293b);
}

body.theme-ocean {
    background: linear-gradient(-45deg, #0f4c75, #3282b8, #bbe1fa, #1b262c);
    --primary-color: #3282b8;
    --secondary-color: #bbe1fa;
}

body.theme-forest {
    background: linear-gradient(-45deg, #134e4a, #064e3b, #065f46, #047857);
    --primary-color: #34d399;
    --secondary-color: #10b981;
}

body.theme-sunset {
    background: linear-gradient(-45deg, #4a044e, #7c2d12, #c2410c, #fb923c);
    --primary-color: #fca5a5;
    --secondary-color: #fb923c;
}

body.theme-nebula {
    background: linear-gradient(-45deg, #312e81, #4c1d95, #c026d3, #db2777);
    --primary-color: #e879f9;
    --secondary-color: #d8b4fe;
}

@keyframes gradientBG {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}

header {
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(10px);
    padding: 0.5rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    gap: 1rem;
}

h1 {
    font-weight: 600;
    letter-spacing: 1px;
    background: linear-gradient(to right, #4ade80, #3b82f6);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

#turn-indicator {
    font-size: 1.25rem;
    font-weight: 500;
}

main {
    flex: 1 1 0; /* Force shrink */
    display: flex;
    padding: 0.5rem;
    gap: 0.5rem;
    overflow: hidden;
    min-height: 0;
}

#game-container {
    flex: 1;
    background: #0f172a;
    border-radius: 1rem;
    position: relative;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.5);
    transition: background 0.3s ease;
}

/* Board Textures */
#game-container.texture-plain {
    /* Default */
}

#game-container.texture-grid {
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px);
    background-size: 20px 20px;
}

#game-container.texture-dots {
    background-image: radial-gradient(rgba(255, 255, 255, 0.1) 1px, transparent 1px);
    background-size: 20px 20px;
}

#game-container.texture-felt {
    background-color: #35a541;
    /* Green Felt Base */
    background-image: url("data:image/svg+xml,%3Csvg width='4' height='4' viewBox='0 0 4 4' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 3h1v1H1V3zm2-2h1v1H3V1z' fill='%23000000' fill-opacity='0.1' fill-rule='evenodd'/%3E%3C/svg%3E");
}

#game-container.texture-wood {
    background-color: #855e42;
    background-image: repeating-linear-gradient(45deg, rgba(0, 0, 0, 0.05) 0px, rgba(0, 0, 0, 0.05) 2px, transparent 2px, transparent 4px);
}

canvas {
    max-width: 100%;
    max-height: 100%;
    border-radius: 0.5rem;
}

.settings-content {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 10px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    margin-top: 5px;
    border-left: 2px solid rgba(255, 255, 255, 0.1);
}

#controls {
    width: 250px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    overflow-y: auto;
    height: 100%;
    scrollbar-width: thin;
    /* Firefox */
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

#controls::-webkit-scrollbar {
    width: 6px;
}

#controls::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.control-panel,
#dice-container,
#player-status,
#legend {
    background: var(--panel-bg);
    padding: 1.5rem;
    border-radius: 1rem;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.05);
}

#dice-container {
    text-align: center;
}

#dice-display {
    font-size: 4rem;
    margin-bottom: 1rem;
    animation: bounce 2s infinite ease-in-out;
}

button#roll-btn {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border: none;
    padding: 1rem 2rem;
    color: white;
    font-family: inherit;
    font-size: 1.2rem;
    font-weight: 600;
    border-radius: 0.75rem;
    cursor: pointer;
    transition: transform 0.1s, filter 0.2s;
    width: 100%;
}

/* Generic Button Styles */
.btn {
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-weight: 600;
    transition: all 0.2s;
    border-radius: 0.5rem;
}

.primary-btn {
    background: linear-gradient(135deg, #6366f1, #a855f7);
    /* Indigo to Purple */
    color: white;
    padding: 1rem 0;
    /* Full width typically */
    font-size: 1.25rem;
    width: 100%;
    box-shadow: 0 4px 0px rgba(79, 70, 229, 0.4);
    /* Chunky bottom shadow like reference */
    border-radius: 12px;
    font-weight: 800;
    text-transform: uppercase;
    margin-bottom: 0.5rem;
}

.primary-btn:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
    box-shadow: 0 6px 0px rgba(79, 70, 229, 0.4);
}

.primary-btn:active {
    transform: translateY(2px);
    box-shadow: 0 0px 0px rgba(79, 70, 229, 0.4);
}

.secondary-btn {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-color);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.small-btn {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    margin-top: 0.5rem;
    width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
}

button#roll-btn:hover {
    filter: brightness(1.1);
}

button#roll-btn:active {
    transform: scale(0.95);
}

button#roll-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    filter: grayscale(1);
}

#player-list {
    list-style: none;
    margin-top: 1rem;
}

.player-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    padding: 0.5rem;
    border-radius: 0.5rem;
    background: rgba(0, 0, 0, 0.2);
}

.player-item.active {
    border: 1px solid var(--primary-color);
    background: rgba(59, 130, 246, 0.1);
}

.player-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #ccc;
}

/* Legend - Now in Header */
#legend {
    display: flex;
    align-items: center;
}

#legend ul {
    list-style: none;
    display: flex;
    gap: 1rem;
    margin: 0;
    padding: 0;
}

#legend li {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.8);
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 4px;
    display: inline-block;
}

@keyframes bounce {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

@keyframes shake {
    0% {
        transform: rotate(0deg);
    }

    25% {
        transform: rotate(5deg);
    }

    50% {
        transform: rotate(0deg);
    }

    75% {
        transform: rotate(-5deg);
    }

    100% {
        transform: rotate(0deg);
    }
}

.shaking {
    animation: shake 0.2s infinite;
}

/* Player Management - Appended */
.hidden {
    display: none !important;
}

#manage-players-ui {
    background: rgba(255, 255, 255, 0.05);
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 10px;
}

/* Custom Scrollbar for lists */
#active-player-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.player-config-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 5px;
}

.player-name-input {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    width: 100px;
}

.remove-player-btn {
    background: #ff4757;
    color: white;
    border: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

/* Animations */
@keyframes bounceAcross {
    0% {
        transform: translate(-200px, -200px) rotate(0deg);
        opacity: 0;
    }

    20% {
        transform: translate(-100px, 0px) rotate(180deg);
        opacity: 1;
    }

    40% {
        transform: translate(0px, -150px) rotate(360deg);
    }

    60% {
        transform: translate(100px, 0px) rotate(540deg);
    }

    80% {
        transform: translate(150px, -100px) rotate(720deg);
    }

    100% {
        transform: translate(200px, -50px) rotate(900deg);
        opacity: 0;
    }
}

/* 3D Dice Styles */
.scene {
    width: 60px;
    height: 60px;
    perspective: 400px;
    margin: 20px auto;
}

.cube {
    width: 100%;
    height: 100%;
    position: relative;
    transform-style: preserve-3d;
    transform: translateZ(-30px);
    transition: transform 1s;
}

.cube__face {
    position: absolute;
    width: 60px;
    height: 60px;
    background: #fdfbff;
    /* White/Lilac */
    border: 2px solid #e0e7ff;
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: inset 0 0 10px rgba(79, 70, 229, 0.1);
}

.cube__face--front {
    transform: rotateY(0deg) translateZ(30px);
}

.cube__face--right {
    transform: rotateY(90deg) translateZ(30px);
}

.cube__face--back {
    transform: rotateY(180deg) translateZ(30px);
}

.cube__face--left {
    transform: rotateY(-90deg) translateZ(30px);
}

.cube__face--top {
    transform: rotateX(90deg) translateZ(30px);
}

.cube__face--bottom {
    transform: rotateX(-90deg) translateZ(30px);
}

/* Dots */
.dot {
    display: block;
    width: 12px;
    height: 12px;
    background: #4f46e5;
    /* Indigo 600 */
    border-radius: 50%;
    position: absolute;
    box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.3);
}

/* Face Layouts */
.cube__face--front .dot-center {}

.cube__face--bottom .dot-top-left {
    top: 12px;
    left: 12px;
}

.cube__face--bottom .dot-bottom-right {
    bottom: 12px;
    right: 12px;
}

.cube__face--top .dot-top-left {
    top: 10px;
    left: 10px;
}

.cube__face--top .dot-center {}

.cube__face--top .dot-bottom-right {
    bottom: 10px;
    right: 10px;
}

.cube__face--left .dot-top-left {
    top: 10px;
    left: 10px;
}

.cube__face--left .dot-top-right {
    top: 10px;
    right: 10px;
}

.cube__face--left .dot-bottom-left {
    bottom: 10px;
    left: 10px;
}

.cube__face--left .dot-bottom-right {
    bottom: 10px;
    right: 10px;
}

.cube__face--right .dot-top-left {
    top: 10px;
    left: 10px;
}

.cube__face--right .dot-top-right {
    top: 10px;
    right: 10px;
}

.cube__face--right .dot-bottom-left {
    bottom: 10px;
    left: 10px;
}

.cube__face--right .dot-bottom-right {
    bottom: 10px;
    right: 10px;
}

.cube__face--right .dot-center {}

.cube__face--back .dot-top-left {
    top: 8px;
    left: 8px;
}

.cube__face--back .dot-top-right {
    top: 8px;
    right: 8px;
}

.cube__face--back .dot-center-left {
    top: 24px;
    left: 8px;
}

.cube__face--back .dot-center-right {
    top: 24px;
    right: 8px;
}

.cube__face--back .dot-bottom-left {
    bottom: 8px;
    left: 8px;
}

.cube__face--back .dot-bottom-right {
    bottom: 8px;
    right: 8px;
}

/* Rotation Classes */
.cube.show-1 {
    transform: translateZ(-30px) rotateY(0deg);
}

.cube.show-6 {
    transform: translateZ(-30px) rotateY(180deg);
}

.cube.show-5 {
    transform: translateZ(-30px) rotateY(-90deg);
}

.cube.show-4 {
    transform: translateZ(-30px) rotateY(90deg);
}

.cube.show-3 {
    transform: translateZ(-30px) rotateX(-90deg);
}

.cube.show-2 {
    transform: translateZ(-30px) rotateX(90deg);
}

/* Animation Classes */
.flying-dice {
    position: fixed;
    z-index: 10000;
    pointer-events: none;
    /* Animation definition */
    animation: flyAcross 1.5s ease-in-out forwards;
}

.flying-dice .cube {
    animation: spinDice 1.5s linear infinite;
}

@keyframes flyAcross {
    0% {
        left: -100px;
        top: 80%;
        transform: scale(0.5);
    }

    50% {
        left: 50%;
        top: 20%;
        transform: scale(1.5);
    }

    100% {
        left: 120%;
        top: 60%;
        transform: scale(0.5);
    }
}

@keyframes spinDice {
    0% {
        transform: rotateX(0) rotateY(0);
    }

    100% {
        transform: rotateX(720deg) rotateY(720deg);
    }
}

.toggle-container {
    display: inline-block;
    margin: 5px;
}

.toggle-container input {
    display: none;
}

.toggle-container input:checked + .btn {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.5);
}

/* Animation Classes Override */
.flying-dice {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    /* Center it explicitly */
    z-index: 10000;
    pointer-events: none;
    /* Pop In/Out Animation */
    animation: popDice 1.5s ease-in-out forwards;
}

.flying-dice .cube {
    animation: spinDice 1.5s linear infinite;
}

@keyframes popDice {
    0% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 0;
    }

    20% {
        transform: translate(-50%, -50%) scale(2.0);
        opacity: 1;
    }

    80% {
        transform: translate(-50%, -50%) scale(2.0);
        opacity: 1;
    }

    100% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 0;
    }
}

@keyframes spinDice {
    0% {
        transform: translateZ(-30px) rotateX(0) rotateY(0);
    }

    100% {
        transform: translateZ(-30px) rotateX(720deg) rotateY(720deg);
    }
}

/* Settings Menu */
.settings-menu summary {
    list-style: none;
    /* Hide default triangle */
    cursor: pointer;
    margin-bottom: 5px;
}

.settings-menu summary::-webkit-details-marker {
    display: none;
}

/* HTML Podium */
#podium-mini {
    display: flex;
    align-items: flex-end;
    gap: 0;
    margin: 0 20px;
}

.p-slot {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    width: 50px;
}

.p-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    margin-bottom: 2px;
    /* Placeholder background */
    background: transparent;
    transition: background 0.3s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.p-block {
    width: 100%;
    text-align: center;
    font-size: 0.8rem;
    font-weight: 700;
    color: rgba(0, 0, 0, 0.7);
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.p-1st .p-block {
    height: 35px;
    background: linear-gradient(to bottom, #FFD700, #C5A000);
}

.p-2nd .p-block {
    height: 25px;
    background: linear-gradient(to bottom, #C0C0C0, #A0A0A0);
}

.p-3rd .p-block {
    height: 15px;
    background: linear-gradient(to bottom, #CD7F32, #8B4513);
}

/* Ensure empty avatars aren't invisible if we want placeholders? 
   Actually, better to leave them transparent until filled. */
