body {
    font-family: sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f0f0f0;
    color: #333;
}

#game-container {
    display: flex;
    flex-wrap: wrap;
    gap: 24px;
    justify-content: center;
    align-items: flex-start;
    padding: 20px;
    box-sizing: border-box;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
}

#game-board-container {
    position: relative;
    flex: 1 1 360px;
    width: 100%;
    display: flex;
    justify-content: center;
    padding: 0 10px;
    box-sizing: border-box;
}

#game-board {
    position: relative;
    width: 100%;
    max-width: 800px;
    aspect-ratio: 800 / 750;
    background-image: url('carte.png');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    border: 2px solid #333;
    border-radius: 8px;
    overflow: hidden;
    box-sizing: border-box;
    margin: 0 auto;
}

#ui-panel {
    flex: 0 1 360px;
    max-width: 380px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 18px;
    box-sizing: border-box;
    background: linear-gradient(135deg, rgba(253,245,230,0.95) 0%, rgba(245,222,179,0.92) 100%);
    padding: 22px;
    border-radius: 16px;
    border: 2px solid #8B4513;
    box-shadow: 0 12px 30px rgba(0,0,0,0.25);
}

#ui-panel h3 {
    font-family: 'Cinzel', serif;
    font-size: 1.3em;
    margin: 0;
    color: #5a3921;
    text-align: center;
}

#ui-panel button {
    width: 100%;
    background-color: #8B4513;
    color: #FDF5E6;
    border: 1px solid #5a3210;
    padding: 14px 24px;
    font-size: 1.05em;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.25s ease, transform 0.2s;
    font-family: 'Cinzel', serif;
    letter-spacing: 0.5px;
}

#ui-panel button:hover {
    background-color: #A0522D;
    transform: translateY(-2px);
}

#ui-panel button:disabled {
    background-color: #c9b09a;
    color: rgba(74, 56, 40, 0.6);
    border-color: rgba(90, 50, 16, 0.4);
    cursor: not-allowed;
    transform: none;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.12);
}

#player-info {
    background: rgba(255, 255, 255, 0.75);
    border-radius: 10px;
    padding: 18px;
    box-sizing: border-box;
    border: 1px solid rgba(139,69,19,0.25);
    box-shadow: inset 0 2px 6px rgba(0,0,0,0.08);
}

#player-info h2 {
    margin: 0 0 10px;
    font-family: 'Cinzel', serif;
    color: #3c2413;
}

#player-info p {
    margin: 6px 0;
    font-size: 0.95em;
    color: #4a3828;
}

#teacher-summary {
    display: none;
    margin-top: 8px;
}

#teacher-summary h3 {
    margin: 0 0 14px;
    text-align: center;
    font-size: 1.2em;
    color: #4a2d17;
}

#teacher-summary-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 420px;
    overflow-y: auto;
    padding-right: 6px;
}

.teacher-summary-card {
    background: linear-gradient(135deg, rgba(255,250,240,0.95) 0%, rgba(251,236,200,0.92) 100%);
    border-radius: 12px;
    padding: 14px;
    box-shadow: 0 6px 18px rgba(0,0,0,0.18);
    border-left: 6px solid #8B4513;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px 12px;
    font-size: 0.95em;
}

.teacher-summary-card header {
    grid-column: 1 / -1;
    font-weight: bold;
    font-size: 1.1em;
    font-family: 'Cinzel', serif;
    color: #3b2412;
}

.teacher-summary-card .destination {
    grid-column: 1 / -1;
    font-style: italic;
    color: #5b473d;
}

.teacher-summary-card .metric-label {
    font-weight: 600;
}

.teacher-summary-card .metric-value {
    text-align: right;
}

/* Card Flip Styles */
#destination-card-container {
    perspective: 1000px;
    display: flex;
    justify-content: center;
    padding: 8px 0 12px;
}

#destination-card {
    width: min(400px, 100%);
    aspect-ratio: 8 / 5;
    position: relative;
    transform-style: preserve-3d;
    transition: transform 0.6s;
    cursor: pointer;
    margin: 0 auto;
}

#destination-card.is-flipped {
    transform: rotateY(180deg);
}

.card-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

.card-front {
    background-image: url('cartedejeu1.png');
    color: #4a3e3a;
    font-weight: bold;
    font-size: 10px;
    font-family: 'Courier New', Courier, monospace;
    transform: rotateY(180deg);
}

.card-back {
    background-image: url('versocarte.png');
}

.city-1 {
    position: absolute;
    top: 45%;
    left: 40%;
    transform: translate(-50%, -50%);
    width: 25%;
    text-align: center;
}

.city-2 {
    position: absolute;
    top: 45%;
    left: 60%;
    transform: translate(-50%, -50%);
    width: 25%;
    text-align: center;
}

.points {
    display: none;
}

#ui-panel h2, #ui-panel h3 { margin-top: 0; }

#log-list {
    list-style-type: none;
    padding: 0;
    height: 200px;
    overflow-y: auto;
    border: 1px solid #eee;
}

#log-list li { padding: 2px 5px; font-size: 0.9em; }

.city {
    position: absolute;
    width: 15px;
    height: 15px;
    background-color: white;
    border: 2px solid black;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    z-index: 10;
}

.city-label {
    position: absolute;
    background: rgba(0,0,0,0.5);
    color: white;
    padding: 2px 5px;
    border-radius: 3px;
    font-size: 12px;
    white-space: nowrap;
    user-select: none;
    z-index: 11;
}

.route-segment {
    position: absolute;
    width: 18px;
    height: 10px;
    border: 1px solid #333;
    z-index: 5;
    cursor: pointer;
}

.route-segment:hover {
    border: 2px solid yellow;
}

.route-segment.gray { background-color: #aaa; }
.route-segment.red { background-color: #d9534f; }
.route-segment.green { background-color: #5cb85c; }
.route-segment.blue { background-color: #428bca; }
.route-segment.yellow { background-color: #f0ad4e; }
.route-segment.orange { background-color: #f0ad4e; }

.player1 .route-segment { box-shadow: 0 0 5px 3px cyan; }
.player2 .route-segment { box-shadow: 0 0 5px 3px magenta; }
.player3 .route-segment { box-shadow: 0 0 5px 3px gold; }
.player4 .route-segment { box-shadow: 0 0 5px 3px #66ff66; }
.player5 .route-segment { box-shadow: 0 0 5px 3px #ff8c00; }
.player6 .route-segment { box-shadow: 0 0 5px 3px #a889ff; }

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    padding: 20px;
    border-radius: 5px;
    width: 90%;
    max-width: 600px;
    text-align: center;
}

#score-summary table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
}

#score-summary th, #score-summary td {
    border: 1px solid #ddd;
    padding: 8px;
}

#score-summary th {
    background-color: #f2f2f2;
}

/* Home Page Styles */
body.home {
    background-color: #F5F5DC; /* Parchment */
    background-image: linear-gradient(rgba(255,255,255,0.1) 2px, transparent 2px), linear-gradient(90deg, rgba(255,255,255,0.1) 2px, transparent 2px), 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: 100px 100px, 100px 100px, 20px 20px, 20px 20px;
    background-position: -2px -2px, -2px -2px, -1px -1px, -1px -1px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 0;
}

.home-container {
    text-align: center;
    background-color: rgba(253, 245, 230, 0.8); /* Creamy white with transparency */
    padding: 40px;
    border-radius: 10px;
    box-shadow: 0 10px 20px rgba(0,0,0,0.2);
    border: 2px solid #8B4513; /* Warm brown border */
    width: min(90vw, 640px);
    margin: 20px auto;
    box-sizing: border-box;
}

.home-container h1 {
    font-family: 'Cinzel', serif;
    font-size: 4em;
    color: #2c3e50; /* Deep blue */
    margin-bottom: 30px;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
}

.home-logo {
    width: min(220px, 60%);
    max-width: 100%;
    margin: 0 auto 24px;
    display: block;
}

.home-name-entry {
    margin: 0 auto 20px;
    max-width: 320px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    text-align: left;
}

.home-name-entry label {
    font-family: 'Cinzel', serif;
    font-size: 1.1em;
    color: #4a2c16;
}

.home-name-entry input {
    padding: 10px 12px;
    border-radius: 6px;
    border: 1px solid rgba(139,69,19,0.4);
    font-size: 1em;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.1);
}

#home-container p {
    font-size: 1.1em;
    margin: 20px 0 30px;
    color: #4a3e3a;
}

#home-actions {
    display: flex;
    gap: 20px;
    justify-content: center;
    flex-wrap: wrap;
}

#player-section {
    margin-top: 20px;
}

.home-btn {
    background-color: #8B4513; /* Warm brown */
    color: #FDF5E6; /* Creamy white */
    border: none;
    padding: 15px 30px;
    font-size: 1.2em;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s, transform 0.3s;
    margin: 10px;
    display: inline-block;
}

.home-btn:hover {
    background-color: #A0522D; /* Lighter brown */
    transform: translateY(-2px);
}

#name-container {
    display: none;
    min-height: 100vh;
    width: 100%;
    padding: 40px 20px;
    box-sizing: border-box;
    background-color: #F5F5DC;
    background-image: linear-gradient(rgba(255,255,255,0.1) 2px, transparent 2px), linear-gradient(90deg, rgba(255,255,255,0.1) 2px, transparent 2px), 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: 100px 100px, 100px 100px, 20px 20px, 20px 20px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.join-card {
    width: min(420px, 90vw);
    background: linear-gradient(145deg, rgba(255,248,235,0.98) 0%, rgba(250,232,197,0.95) 100%);
    border: 3px solid #8B4513;
    border-radius: 16px;
    box-shadow: 0 18px 38px rgba(0,0,0,0.28), inset 0 3px 8px rgba(255,255,255,0.35);
    position: relative;
    padding: 32px 28px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.join-card::before {
    content: "";
    position: absolute;
    inset: 10px;
    border: 1px dashed rgba(139,69,19,0.45);
    border-radius: 12px;
    pointer-events: none;
}

.join-card h2 {
    margin: 0;
    font-family: 'Cinzel', serif;
    font-size: 2em;
    color: #3c2413;
}

.join-card p {
    margin: 0;
    font-size: 1em;
    color: #4a3828;
}

.join-card input {
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid rgba(139,69,19,0.35);
    font-size: 1.05em;
    box-shadow: inset 0 3px 6px rgba(0,0,0,0.12);
    background: rgba(255,255,255,0.9);
}

.join-card input:focus {
    outline: 2px solid rgba(160,82,45,0.6);
    outline-offset: 2px;
}

.join-card .home-btn {
    margin-top: 6px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

#card-selection-container {
    display: none;
    width: calc(100vw - 40px);
    max-width: 1200px;
    height: calc(100vh - 60px);
    box-sizing: border-box;
    padding: 24px;
    gap: 24px;
    overflow: hidden;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
}

#card-selection-message {
    margin-bottom: 20px;
    font-size: 1.1em;
    text-align: center;
    width: 100%;
    min-height: 1.2em;
}

#card-selection-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    grid-auto-rows: auto;
    gap: 16px;
    justify-items: center;
    justify-content: center;
    width: 100%;
    flex: 1;
    align-content: center;
    transform-origin: top center;
    transition: transform 0.2s ease;
}

#card-selection-container.grid-scaled {
    overflow: hidden;
}

#card-selection-container.grid-scaled #card-selection-grid {
    align-self: center;
}

.selection-card {
    width: 100%;
    max-width: 160px;
    aspect-ratio: 16 / 10;
    border: 2px solid transparent;
    border-radius: 8px;
    background-image: url('versocarte.png');
    background-size: cover;
    background-position: center;
    background-color: #F5F5DC;
    position: relative;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2em;
    font-weight: bold;
    color: #4a3e3a;
    outline: none;
}

.selection-card:hover:not(.is-taken):not(.is-mine) {
    transform: translateY(-4px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.25);
}

.selection-card.is-taken {
    cursor: default;
    opacity: 0.7;
}

.selection-card.is-mine {
    cursor: default;
}

.selection-card.show-front {
    background-image: url('cartedejeu1.png');
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9em;
    color: #4a3e3a;
}

.selection-card .card-placeholder {
    background: rgba(255, 255, 255, 0.85);
    padding: 6px 12px;
    border-radius: 6px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.selection-card .card-content {
    width: 100%;
    height: 100%;
    position: relative;
    padding: 18px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.selection-card .card-city {
    font-weight: bold;
    margin: 4px 0;
    text-transform: uppercase;
    font-size: 0.8em;
}

.selection-card .card-points {
    position: absolute;
    bottom: 8px;
    width: 100%;
    text-align: center;
    font-weight: bold;
    font-size: 0.8em;
}

@media (max-width: 1024px) {
    #game-container {
        gap: 20px;
        padding: 16px;
    }
}

@media (max-width: 768px) {
    #game-container {
        flex-direction: column;
        align-items: center;
    }
    #ui-panel {
        order: 2;
        max-width: none;
    }
    #game-board-container {
        order: 1;
    }
    #destination-card-container {
        display: flex;
        justify-content: center;
    }
    #destination-card {
        width: min(90vw, 360px);
    }
    #teacher-summary-grid {
        max-height: 320px;
    }
}

@media (max-width: 600px) {
    body.home {
        padding: 0;
    }
    .home-container {
        padding: 28px;
        margin: 16px auto;
    }
    .home-logo {
        width: min(240px, 70%);
        margin-bottom: 20px;
    }
    .home-name-entry {
        max-width: 100%;
    }
    #ui-panel {
        padding: 12px;
        border-radius: 10px;
    }
    #card-selection-container {
        padding: 16px;
        gap: 16px;
        height: calc(100vh - 40px);
    }
    #card-selection-grid {
        gap: 12px;
    }
    .selection-card {
        max-width: min(48vw, 150px);
    }
    #teacher-summary-grid {
        max-height: 260px;
    }
}

@media (max-width: 480px) {
    #game-container {
        padding: 12px;
        gap: 16px;
    }
    #ui-panel {
        padding: 10px;
    }
    #home-actions {
        flex-direction: column;
    }
    .home-btn {
        width: 100%;
    }
    .home-container h1 {
        font-size: 2.6em;
    }
    .home-logo {
        width: min(200px, 70%);
    }
    .home-name-entry input {
        width: 100%;
    }
    #card-selection-container {
        gap: 12px;
    }
    .selection-card {
        max-width: min(60vw, 150px);
        font-size: 1.1em;
    }
    .selection-card .card-content {
        padding: 12px;
    }
    .selection-card .card-city {
        font-size: 0.72em;
    }
    .teacher-summary-card {
        grid-template-columns: 1fr;
    }
    #teacher-summary-grid {
        max-height: 220px;
    }
}
#turn-legend {
    margin: 0;
    padding: 12px 14px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.65);
    border: 1px dashed rgba(139,69,19,0.4);
    font-size: 0.92em;
    color: #4a3828;
    display: none;
}

#turn-legend ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

#turn-legend strong {
    display: block;
    text-align: center;
    margin-bottom: 6px;
    font-family: 'Cinzel', serif;
    color: #3b2412;
}

#turn-legend li {
    display: flex;
    align-items: center;
    gap: 6px;
}

.legend-color {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.25);
    border: 1px solid rgba(0,0,0,0.15);
}
#turn-legend {
    margin: 0;
    padding: 12px 14px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.65);
    border: 1px dashed rgba(139,69,19,0.4);
    font-size: 0.92em;
    color: #4a3828;
    display: none;
}

#turn-legend ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

#turn-legend li {
    display: flex;
    align-items: center;
    gap: 6px;
}

.legend-color {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.25);
    border: 1px solid rgba(0,0,0,0.15);
}
