body {
    font-family: 'Segoe UI', sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #eef2f3;
    margin: 0;
    padding: 20px;
    box-sizing: border-box;
}

/* Responsività Generale */
@media (max-width: 600px) {
    body { padding: 10px; }
}

#game-container {
    width: 100%;
    max-width: 1000px;
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    box-sizing: border-box;
    position: relative;
}

#main-menu, #overlay-screen, #reward-screen, #map-screen, #merchant-screen, #dilemma-screen, #match-menu-overlay, #rules-overlay, #deck-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    z-index: 200; background: #eef2f3;
    padding: 20px;
    box-sizing: border-box;
    overflow-y: auto;
}

#overlay-screen, #reward-screen, #map-screen, #merchant-screen, #dilemma-screen, #match-menu-overlay, #rules-overlay, #deck-overlay { 
    background: rgba(0,0,0,0.95); 
    color: white; 
    display: none; 
}

/* Z-Index Hierarchy */
#match-menu-overlay { z-index: 1100; }
#deck-overlay { z-index: 1200; }
#rules-overlay { z-index: 1300; }

/* Overlay Typography */
#overlay-title { font-size: 3rem; margin-bottom: 20px; text-align: center; }
#overlay-recap { font-size: 1.2rem; margin-bottom: 30px; color: #ccc; text-align: center; }
#map-title, #dilemma-title, #reward-screen h2, #merchant-screen h2, #deck-overlay h2, #rules-overlay h2 { 
    margin-bottom: 20px; 
    text-align: center;
}

#map-screen p, #merchant-screen p, #reward-screen p { color: #aaa; margin-top: 20px; text-align: center; }

#dilemma-text {
    max-width: 600px;
    text-align: center;
    margin: 20px 0;
    font-size: 1.2rem;
}

#dilemma-options {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Board & Cells */
#board {
    background: #333;
    padding: 5px;
    border-radius: 5px;
    margin: 60px 0 20px 0;
    width: 100%;
    box-sizing: border-box;
}

.cell {
    height: 15px;
    background: #555;
    position: relative;
    padding: 0;
    border: 1px solid #333;
    vertical-align: bottom; /* Allinea il testo in basso */
}

.cell-number {
    position: absolute;
    bottom: -18px; /* Posiziona il numero sotto la cella */
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.65rem;
    color: #888;
    font-weight: bold;
    pointer-events: none;
}

.cell:nth-child(even) {
    background: #4a4a4a; /* Colore leggermente più scuro per le celle pari */
}

.cell.player1::after, .cell.player1::before {
    left: 20%;
    transform: translateX(-50%);
}

.cell.player1::after { transform: translateX(-50%) scaleX(-1); }

.cell.player2::after, .cell.player2::before {
    left: 80%;
    transform: translateX(-50%);
}

.cell.player1::after, .cell.player2::after {
    content: '🤺';
    position: absolute;
    top: -50px;
    font-size: 40px;
    z-index: 10;
    pointer-events: none;
}

.cell.player1::before, .cell.player2::before {
    position: absolute;
    top: -70px;
    font-size: 12px;
    font-weight: bold;
    z-index: 10;
}

.cell.player1::before { content: 'P1'; color: #1a73e8; }
.cell.player2::before { content: 'P2'; color: #d93025; }

@media (max-width: 600px) {
    .cell.player1::after, .cell.player2::after { font-size: 30px; top: -40px; }
    .cell.player1::before, .cell.player2::before { top: -55px; font-size: 10px; }
    #board { margin-top: 50px; }
}

.cell.active { background: #1a73e8; }
.cell.middle { border: 1px solid #ff9800; box-sizing: border-box; }

/* HUD Information */
#slay-info {
    display: none;
    position: absolute;
    top: 10px;
    left: 10px;
    font-weight: bold;
    color: #d93025;
    font-size: 0.9rem;
}

#active-mod {
    font-size: 0.9rem;
    color: #1a73e8;
    font-weight: bold;
    margin-bottom: 10px;
    text-align: center;
}

#status {
    text-align: center;
    font-size: 1.1rem;
    margin-bottom: 10px;
    font-weight: 600;
}

#distance-info {
    text-align: center;
    font-size: 1.1rem;
    font-weight: bold;
    color: #d93025;
    margin-bottom: 5px;
}

#card-piles {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin-bottom: 15px;
}

.pile {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    cursor: pointer;
    transition: transform 0.1s;
}

.pile:active {
    transform: scale(0.95);
}

.pile-icon {
    font-size: 2rem;
    background: rgba(0,0,0,0.05);
    padding: 10px;
    border-radius: 8px;
    border: 1px solid #ccc;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.pile-count {
    position: absolute;
    bottom: -5px;
    right: -10px;
    background: #1a73e8;
    color: white;
    font-size: 0.8rem;
    font-weight: bold;
    padding: 2px 8px;
    border-radius: 10px;
    border: 2px solid white;
    min-width: 15px;
    text-align: center;
}

#discard-pile .pile-count {
    background: #666;
}

/* Controls */
#controls {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
}

.hand {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
}

.card {
    width: 50px;
    height: 75px;
    background: white;
    border: 2px solid #ccc;
    border-radius: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s;
    user-select: none;
    position: relative;
    color: #333;
    flex-shrink: 0;
}

@media (max-width: 400px) {
    .card { width: 45px; height: 65px; font-size: 18px; }
}

.card.selected {
    border-color: #1a73e8;
    transform: translateY(-8px);
}

.card-badge { font-size: 0.6rem; position: absolute; bottom: 3px; right: 3px; }
.card-def { color: #1a73e8; }
.card-mult { color: #d93025; font-weight: bold; }

/* Score Container */
#score-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    background: rgba(0, 0, 0, 0.8);
    padding: 10px 30px;
    border-radius: 50px;
    margin: 10px auto 20px auto;
    width: fit-content;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    border: 1px solid rgba(255,255,255,0.1);
}

.score-box { font-size: 1.8rem; font-weight: bold; min-width: 80px; text-align: center; }
.score-box.p1 { color: #4dabff; }
.score-box.p2 { color: #ff5252; }
.score-divider { color: #888; font-size: 0.9rem; font-weight: bold; letter-spacing: 2px; }

@media (max-width: 600px) {
    .score-box { font-size: 1.4rem; min-width: 60px; }
    #score-container { padding: 8px 20px; gap: 10px; }
}

/* Buttons */
.btn-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    justify-content: center;
    max-width: 500px;
    margin: 15px auto 0 auto;
}

button {
    padding: 12px 20px;
    font-size: 1rem;
    border: none;
    border-radius: 5px;
    background: #1a73e8;
    color: white;
    cursor: pointer;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

button:disabled {
    background: #ccc !important;
    color: #888 !important;
    cursor: not-allowed;
    opacity: 0.6;
    box-shadow: none !important;
    transform: none !important;
    border: 1px solid #bbb !important;
}

@media (max-width: 600px) {
    .btn-group { max-width: 100%; gap: 8px; }
    button { font-size: 0.9rem; }
}

.menu-btn {
    width: 100%;
    max-width: 280px;
    padding: 12px 20px;
    margin: 8px;
    font-size: 1.1rem;
    border-radius: 8px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
}

.menu-btn.secondary { background: #666; }
.menu-btn.slay-btn { background: #d93025; }
.menu-btn.slay-btn:hover { background: #b0261b; }

@media (max-width: 600px) {
    .menu-btn { max-width: 220px; padding: 10px 15px; font-size: 1rem; margin: 6px; min-height: 44px; }
}

/* Fix per pulsanti specifici */
#btn-open-menu {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    min-height: 44px !important;
    border-radius: 50% !important;
    background: #666;
    padding: 0 !important;
    font-size: 1.2rem;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

#btn-inspect-deck {
    min-height: 44px !important;
    min-width: 44px !important;
    padding: 0 15px !important;
}

#btn-win-match { background-color: #34a853; }
#btn-hit { background-color: #d93025; }

/* Log Area */
#log {
    margin-top: 15px;
    max-height: 100px;
    overflow-y: auto;
    font-size: 0.85rem;
    border-top: 1px solid #eee;
    padding-top: 10px;
    width: 100%;
}

/* Reward Screen */
.reward-container { 
    display: flex; 
    gap: 15px; 
    margin-top: 20px; 
    flex-wrap: wrap; 
    justify-content: center; 
}
.reward-item { 
    background: #fff; color: #333; padding: 15px; border-radius: 10px; 
    cursor: pointer; width: 140px; text-align: center; border: 3px solid transparent;
}
@media (max-width: 600px) {
    .reward-item { width: 100px; padding: 10px; font-size: 0.8rem; }
}
.reward-item.selected { border-color: #1a73e8; }

/* Mappa a Grafo */
#map-nodes-container {
    display: flex;
    flex-direction: column-reverse;
    gap: 60px;
    padding: 40px 20px;
    overflow-y: auto;
    max-height: 70vh;
    width: 100%;
    align-items: center;
    position: relative;
    scroll-behavior: smooth;
    box-sizing: border-box;
}
.map-floor {
    display: flex;
    flex-direction: row;
    gap: 40px;
    justify-content: center;
    z-index: 2;
    min-height: 50px;
    width: 100%;
}
.map-node {
    width: 45px; height: 45px; border-radius: 50%;
    background: #444;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem; cursor: pointer; position: relative;
    border: 3px solid #222; transition: all 0.2s;
    box-shadow: 0 4px 8px rgba(0,0,0,0.5);
    flex-shrink: 0;
}
.map-node.active { border-color: #1a73e8; transform: scale(1.2); box-shadow: 0 0 20px #1a73e8; background: #555; }
.map-node.completed { opacity: 0.4; cursor: default; background: #111; border-color: #34a853; }
.map-node.locked { opacity: 0.3; cursor: not-allowed; grayscale: 100%; }
@media (max-width: 600px) {
    .map-floor { gap: 30px; }
    .map-node { width: 40px; height: 45px; }
    #map-nodes-container { gap: 50px; }
}

#map-svg {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none; z-index: 1;
}
.map-link { stroke: #555; stroke-width: 2; fill: none; }
.map-link.active { stroke: #1a73e8; stroke-width: 3; }

/* Rules & Deck Overlays */
#rules-content {
    max-width: 800px;
    width: 100%;
    height: 96%;
    overflow-y: auto;
    padding: 20px;
    font-size: 0.95rem;
    line-height: 1.5;
    text-align: left;
    border-radius: 10px;
}

#deck-overlay {
    padding: 15px !important;
}

#deck-cards-container {
    padding: 10px !important;
    display: flex;
    flex-wrap: wrap;
    gap: 8px !important;
    justify-content: center;
    max-height: 70vh;
    overflow-y: auto;
    max-width: 1000px;
}

#deck-cards-container .card {
    width: 45px;
    height: 65px;
    font-size: 18px;
    border-width: 1px;
    cursor: default;
}

#deck-cards-container .card-badge {
    font-size: 0.5rem;
}

@media (max-width: 375px) {
    #deck-overlay h2 { font-size: 1.2rem; margin-bottom: 15px; }
    #deck-cards-container { gap: 5px !important; }
    #deck-cards-container .card { width: 40px; height: 58px; font-size: 16px; }
}
