:root {
    --bg-color: #121212;
    --text-color: #ffffff;
    --primary: #6200ea;
    --primary-hover: #7c4dff;
    --tile-bg: #2c2c2c;
    --tile-drink: #d32f2f;
    --tile-give: #388e3c;
    --tile-action: #fbc02d;
    --tile-bonus: #8e24aa;
    --board-size: 2000px;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; }

body { background-color: var(--bg-color); color: var(--text-color); overflow: hidden; touch-action: manipulation; }

.screen { display: none; width: 100vw; height: 100vh; flex-direction: column; align-items: center; justify-content: center; }
.screen.active { display: flex; }

/* Setup Screen */
#setup-screen input { margin: 5px; padding: 10px; border-radius: 5px; border: none; font-size: 16px; }
button { padding: 12px 24px; margin: 10px; border: none; border-radius: 8px; background-color: var(--primary); color: white; font-size: 18px; cursor: pointer; transition: 0.2s; }
button:hover { background-color: var(--primary-hover); }
.primary-btn { font-weight: bold; font-size: 22px; margin-top: 20px; }

.player-row {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    gap: 5px;
}

.player-name {
    padding: 10px;
    border-radius: 5px;
    border: none;
    font-size: 16px;
    width: 150px;
}

.player-token-select {
    padding: 10px;
    border-radius: 5px;
    border: none;
    font-size: 16px;
    background: var(--tile-bg);
    color: white;
    cursor: pointer;
}

.remove-player-btn {
    background-color: #d32f2f;
    padding: 10px 15px;
    margin: 0;
}
.remove-player-btn:hover {
    background-color: #b71c1c;
}
/* Game UI */
#ui-top { position: absolute; top: 20px; z-index: 10; background: rgba(0,0,0,0.7); padding: 10px 30px; border-radius: 20px; }
#ui-bottom { position: absolute; bottom: 30px; z-index: 10; display: flex; flex-direction: column; align-items: center; }
#dice-result { font-size: 32px; font-weight: bold; margin-top: 10px; text-shadow: 2px 2px 4px #000; }

/* Camera & Board */
#camera-container { 
    width: 100vw; 
    height: 100vh; 
    overflow: hidden; 
    position: relative; 
    touch-action: none; /* Estää selaimen oman zoomaamisen sormilla */
    cursor: grab; /* Näyttää hiirelle tarttumis-ikonin */
}
#camera-container:active {
    cursor: grabbing;
}

#board { 
    position: absolute; 
    transform-origin: top left;
    /* Poistetaan kiinteä transition tästä, hoidamme sen JS:llä jotta raahaaminen on viiveetöntä */
}

/* Tiles */
.tile { 
    position: absolute; width: 75px; height: 75px; border-radius: 12px; 
    display: flex; align-items: center; justify-content: center; text-align: center;
    font-size: 11px; font-weight: bold; box-shadow: 0 4px 6px rgba(0,0,0,0.5);
    border: 2px solid rgba(255,255,255,0.2); padding: 5px; z-index: 10;
}
.tile.type-normal { background-color: var(--tile-bg); }
.tile.type-drink { background-color: var(--tile-drink); }
.tile.type-give { background-color: var(--tile-give); }
.tile.type-action { background-color: var(--tile-action); color: #000; }
.tile.type-bonus { background-color: var(--tile-bonus); }
.tile.type-return { background-color: #000000; color: #ff0000; border: 2px solid #ff0000; }
.tile.type-portal-forward { background-color: #00e676; color: #000; }
.tile.type-portal-backward { background-color: #ff3d00; color: #fff; }
/* Reittiviiva ruutujen takana */
#path-layer {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 0;
    pointer-events: none;
    overflow: visible; /* Varmistaa ettei viiva katkea reunoilla */
}
/* Players */
.player-token { 
    position: absolute; width: 40px; height: 40px; border-radius: 50%; border: 3px solid white;
    box-shadow: 0 4px 10px rgba(0,0,0,0.8); 
    z-index: 100; /* Tämä pitää huolen, että nappula on AINA laattojen ja viivojen yläpuolella */
    transition: top 0.4s ease-in-out, left 0.4s ease-in-out; 
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; /* Emojin koko */
    background-color: #333; /* Oletustausta jos väri puuttuu */
}

/* Modal */
#modal { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0,0,0,0.8); z-index: 100; display: flex; align-items: center; justify-content: center; }
#modal.hidden { display: none; }
.modal-content { background: var(--tile-bg); padding: 30px; border-radius: 15px; text-align: center; max-width: 90%; width: 400px; }
.modal-content h3 { margin-bottom: 15px; font-size: 24px; }
.modal-content p { margin-bottom: 20px; font-size: 18px; }

/* --- 3D NOPPA --- */
#dice-container {
    position: fixed;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    z-index: 500;
    perspective: 1200px; /* Luo 3D-syvyyden */
    pointer-events: none;
}

#dice-container.hidden {
    display: none;
}

#dice {
    position: absolute;
    width: 80px;
    height: 80px;
    top: -40px;
    left: -40px;
    transform-style: preserve-3d;
    /* Animaatio määritetään JS:n puolella */
}

.face {
    position: absolute;
    width: 80px;
    height: 80px;
    background: #ffffff;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    box-shadow: inset 0 0 15px rgba(0,0,0,0.1), 0 0 5px rgba(0,0,0,0.3);
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    padding: 10px;
}

.dot {
    width: 14px;
    height: 14px;
    background: #1a1a1a;
    border-radius: 50%;
    justify-self: center;
    align-self: center;
}

/* Nopan sivujen asettelu 3D-tilaan */
.front  { transform: rotateY(0deg) translateZ(40px); }
.back   { transform: rotateY(180deg) translateZ(40px); }
.right  { transform: rotateY(90deg) translateZ(40px); }
.left   { transform: rotateY(-90deg) translateZ(40px); }
.top    { transform: rotateX(90deg) translateZ(40px); }
.bottom { transform: rotateX(-90deg) translateZ(40px); }

/* Pisteiden sijainnit */
.d-top-left { grid-area: 1 / 1; }
.d-top-right { grid-area: 1 / 3; }
.d-middle-left { grid-area: 2 / 1; }
.d-center { grid-area: 2 / 2; }
.d-middle-right { grid-area: 2 / 3; }
.d-bottom-left { grid-area: 3 / 1; }
.d-bottom-right { grid-area: 3 / 3; }

/* Pikkutuhma-laatan tyyli */
.tile.type-naughty { 
    background-color: #ff4081; /* Pinkki */
    color: #ffffff; 
    border: 2px solid #c51162; 
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}