:root {
    color-scheme: dark;
    font-family: "Segoe UI", Roboto, sans-serif;
    --accent-color: #66b2ff;
    --accent-accent: #1c488a;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    background: radial-gradient(circle at top left, #1a2533, #070b12 60%);
    color: #e6edf3;
}

/* ===== TITLE SCREEN ===== */
#title-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100000;
    animation: fadeIn 0.5s ease-in;
    overflow: hidden;
}

#title-background {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle at center, rgba(26, 37, 51, 0.7), rgba(7, 11, 18, 0.9) 70%),
                url('assets/title.png') center center / cover no-repeat;
    filter: blur(0px);
    z-index: 1;
}

#title-screen.fade-out {
    animation: fadeOut 0.5s ease-out forwards;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes fadeOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
    }
}

#title-content {
    position: relative;
    z-index: 2;
    text-align: center;
    animation: slideUp 0.8s ease-out;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
}

@keyframes slideUp {
    from {
        transform: translateY(30px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

#title-logo {
    max-width: 600px;
    width: 80%;
    height: auto;
    filter: drop-shadow(0 0 30px rgba(102, 178, 255, 0.5));
    animation: logoFloat 3s ease-in-out infinite;
}

@keyframes logoFloat {
    0%, 100% {
        transform: translateY(0);
        filter: drop-shadow(0 0 30px rgba(102, 178, 255, 0.5));
    }
    50% {
        transform: translateY(-10px);
        filter: drop-shadow(0 0 40px rgba(102, 178, 255, 0.7));
    }
}

#title-subtitle {
    font-size: 1.2rem;
    margin: 0;
    color: #94a9c9;
    letter-spacing: 0.1em;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.title-button {
    font-size: 1.5rem;
    padding: 1rem 3rem;
    background: linear-gradient(135deg, var(--accent-color) 0%, var(--accent-accent) 100%);
    color: white;
    border: 2px solid rgba(102, 178, 255, 0.6);
    border-radius: 50px;
    cursor: pointer;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    transition: all 0.3s ease;
    box-shadow: 0 4px 20px rgba(102, 178, 255, 0.4);
}

.title-button:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 30px rgba(102, 178, 255, 0.6);
    background: linear-gradient(135deg, #7fc4ff 0%, var(--accent-color) 100%);
}

.title-button:active {
    transform: translateY(-1px);
}

/* ===== LOBBY SCREEN ===== */
#lobby-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle at center, #1a2533, #070b12 70%);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

#lobby-screen.fade-in {
    animation: fadeIn 0.5s ease-in;
}

#lobby-content {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

@media (max-width: 640px) {
    #title-logo {
        max-width: 400px;
        width: 90%;
    }

    #title-subtitle {
        font-size: 1rem;
    }

    .title-button {
        font-size: 1.2rem;
        padding: 0.8rem 2rem;
    }
}

main#game-layout {
    width: 100%;
    max-width: 1600px;
    padding: 28px 34px 40px;
    display: flex;
    flex-direction: column;
    gap: 28px;
}

#board-container { 
    position: relative; 
    min-height: 600px;
    width: 100%;
    background: #050b12; /* Fallback si canvas ne charge pas */
}

#pixi-container {
    width: 100%;
    min-height: 600px;
    display: block;
    position: relative;
    z-index: 1;
}

#pixi-container canvas {
    display: block !important;
    position: relative !important;
    z-index: 1 !important;
}
#modal-root {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    pointer-events: none;
    z-index: 9999;
}

/* ===== HUD 10x2 UNIFORM GRID LAYOUT ===== */
#hud {
    background: rgba(12, 18, 25, 0.88);
    border: 1px solid color-mix(in srgb, var(--accent-color) 45%, transparent);
    border-radius: 20px;
    padding: 10px 12px;
    display: grid;
    grid-template-columns: repeat(10, minmax(0, 1fr));
    grid-template-rows: repeat(2, 110px);
    gap: 8px 10px;
    align-items: stretch;
    max-width: 1500px;
    margin: 0 auto;
    backdrop-filter: blur(16px);
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    box-shadow: 0 0 0 1px rgba(8, 13, 20, 0.6), 0 18px 42px rgba(8, 13, 20, 0.35);
    width: 100%;
}

/* Branding - 2x1 (cols 1-2, row 1) */
#branding {
    grid-column: 1 / span 2;
    grid-row: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    min-width: 0;
    overflow: hidden;
}

#branding h1 {
    margin: 0;
    font-size: 1.1rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    line-height: 1.1;
}

#branding p {
    margin: 0;
    font-size: 0.7rem;
    color: #94a9c9;
    line-height: 1.2;
}

.info-card {
    background: rgba(19, 33, 52, 0.68);
    border: 1px solid color-mix(in srgb, var(--accent-color) 35%, transparent);
    border-radius: 8px;
    padding: 6px 10px;
    display: grid;
    gap: 4px;
    font-size: 0.8rem;
    flex-shrink: 0;
    min-width: 0;
    overflow: hidden;
}

.info-card span:not(.resource-icon) {
    display: block;
    color: #7fa0cc;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.info-card strong {
    font-size: 0.95rem;
}

/* Briefing - 2x1 (cols 1-2, row 2) */
#action-brief {
    grid-column: 1 / span 2;
    grid-row: 2;
    grid-template-rows: min-content 1fr;
    line-height: 1.3;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
    max-width: 100%;
    height: 110px; /* Hauteur fixe pour éviter le reflow */
}

#action-brief strong {
    color: var(--accent-color);
    font-size: 0.8rem;
    flex-shrink: 0;
}

#action-brief p {
    margin: 0;
    font-size: 0.75rem;
    color: #c5d7f1;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 5;
    line-clamp: 5;
    -webkit-box-orient: vertical;
    line-height: 1.3;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
    flex: 1; /* Prend l'espace disponible */
    min-height: 0; /* Permet le shrink */
}

#action-usage {
    font-size: 0.75rem;
    color: #7fa0cc;
}

/* Turn panel - 1x1 (col 3, row 2) */
#turn-panel {
    grid-column: 3;
    grid-row: 2;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: rgba(16, 28, 44, 0.85);
    border-radius: 14px;
    padding: 6px 8px;
    border: 1px solid rgba(102, 178, 255, 0.25);
}

#turn-panel div {
    display: flex;
    justify-content: space-between;
    gap: 6px;
    font-size: 0.75rem;
}

#turn-panel span {
    font-size: 0.65rem;
    letter-spacing: 0.06em;
    color: #7fa0cc;
}

#turn-panel strong {
    font-size: 0.85rem;
    color: #f2f6ff;
}

/* Player 1 Resources - 2x1 (cols 4-5, row 2) */
#blue-resources {
    grid-column: 4 / span 2;
    grid-row: 2;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 4px 6px;
    background: rgba(16, 28, 44, 0.85);
    border-radius: 14px;
    padding: 6px 8px;
    border: 1px solid rgba(102, 178, 255, 0.25);
    transition: opacity 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
    width: 100%; /* Largeur fixe */
    min-width: 0; /* Évite l'expansion */
}

/* Player 2 Resources - 2x1 (cols 6-7, row 2) */
#red-resources {
    grid-column: 6 / span 2;
    grid-row: 2;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, 1fr);
    gap: 4px 6px;
    background: rgba(16, 28, 44, 0.85);
    border-radius: 14px;
    padding: 6px 8px;
    border: 1px solid rgba(255, 107, 107, 0.25);
    transition: opacity 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
    width: 100%; /* Largeur fixe */
    min-width: 0; /* Évite l'expansion */
}

#resource-panel {
    display: contents;
}

.player-resources .player-name {
    grid-column: 1 / -1;
    font-weight: 700;
    font-size: 0.85rem;
    letter-spacing: 0.08em;
    margin-bottom: 4px;
    text-align: center;
}

#blue-resources .player-name {
    color: #66b2ff;
}

#red-resources .player-name {
    color: #ff8787;
}

.player-resources .resource-line {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 6px;
    font-size: 0.9rem;
}

.resource-icon {
    width: 24px;
    height: 24px;
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.resource-icon svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.4));
}

.icon-gold,
.icon-crystal,
.icon-food,
.icon-materials {
    display: inline-block;
    vertical-align: middle;
}

#blue-resources strong,
#red-resources strong {
    font-size: 1rem;
    font-weight: 700;
}

/* Actions - Build, Train, Move each 2x1 */
#actions {
    display: contents;
}

#primary-actions {
    display: contents;
}

/* Build button - 2x1 (cols 3-4, row 1) */
#primary-actions .action-button:nth-child(1) {
    grid-column: 3 / span 2;
    grid-row: 1;
}

/* Train button - 2x1 (cols 5-6, row 1) */
#primary-actions .action-button:nth-child(2) {
    grid-column: 5 / span 2;
    grid-row: 1;
}

/* Move button - 2x1 (cols 7-8, row 1) */
#primary-actions .action-button:nth-child(3) {
    grid-column: 7 / span 2;
    grid-row: 1;
}
.action-button {
    border: 1px solid color-mix(in srgb, var(--accent-color) 25%, transparent);
    border-radius: 14px;
    padding: 10px 12px;
    background: linear-gradient(135deg, rgba(28, 72, 138, 0.4), rgba(15, 27, 44, 0.9));
    color: #e6edf3;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    gap: 6px;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
}

.action-button strong {
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}

.action-button span {
    font-size: 0.78rem;
    color: #c5d7f1;
    letter-spacing: 0.02em;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 4px;
    flex-wrap: nowrap;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}

.action-button:hover {
    background: linear-gradient(135deg, color-mix(in srgb, var(--accent-color) 65%, #21334d), #16253a);
    box-shadow: 0 10px 24px rgba(39, 116, 193, 0.32);
    border-color: color-mix(in srgb, var(--accent-color) 55%, transparent);
}

.action-button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
    transform: none;
    box-shadow: none;
}

[data-action="build"].action-button {
    background: linear-gradient(135deg, #16243a, #1f3050);
}

[data-action="train"].action-button {
    background: linear-gradient(135deg, #1b2238, #283a5f);
}

[data-action="move"].action-button {
    background: linear-gradient(135deg, #1a1f33, #2a3654);
}

[data-action="build"].action-button,
[data-action="train"].action-button,
[data-action="move"].action-button {
    border-color: rgba(102, 178, 255, 0.25);
}

/* End Turn Button - restored to original position */
.end-turn {
    grid-column: 8;
    grid-row: 2;
    border-radius: 999px;
    padding: 8px 12px;
    border: 1px solid color-mix(in srgb, var(--accent-color) 55%, transparent);
    background: color-mix(in srgb, var(--accent-color) 45%, #0c1a2a);
    color: inherit;
    font-weight: 700;
    letter-spacing: 0.05em;
    cursor: pointer;
    font-size: 0.8rem;
    transition: transform 0.18s ease, background 0.2s ease;
    align-self: stretch;
    display: flex;
    align-items: center;
    justify-content: center;
}

.end-turn:hover {
    background: color-mix(in srgb, var(--accent-color) 65%, #0c1a2a);
}

.end-turn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Log header with menu button */
#log-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}

#log-header h2 {
    margin: 0;
}

.menu-btn {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
    font-weight: 700;
    font-size: 0.85rem;
    padding: 8px 12px;
    border: 1px solid rgba(59, 130, 246, 0.5);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.menu-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 3px 10px rgba(59, 130, 246, 0.4);
    background: linear-gradient(135deg, #60a5fa 0%, #3b82f6 100%);
}

/* ===== CANVAS DONUT - 2x2 (cols 9-10, rows 1-2) ===== */
#harvest-actions { 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    grid-column: 9 / span 2; 
    grid-row: 1 / span 2;
    padding: 5px;
}

#harvest-donut-wrapper {
    position: relative;
    width: 100%;
    max-width: 250px;
    aspect-ratio: 1;
}

#harvest-donut-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

#donut-center {
    position: absolute; 
    top: 50%; 
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex; 
    flex-direction: column;
    align-items: center; 
    justify-content: center; 
    pointer-events: none;
    font-weight: 900; 
    font-size: 1.2rem; 
    gap: 4px; 
    color: #d7ecff;
    text-shadow: 0 2px 4px rgba(0,0,0,.8);
}

.crystal-icon { 
    filter: drop-shadow(0 2px 3px rgba(0,0,0,.6)); 
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.crystal-icon svg {
    width: 100%;
    height: 100%;
}

/* Action Options - Row 3, Full Width */
#action-options {
    grid-column: 1 / span 10;
    grid-row: 3;
    display: none;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 10px;
    background: rgba(16, 26, 40, 0.85);
    border-radius: 12px;
    border: 1px solid rgba(102, 178, 255, 0.15);
}

#action-options[data-visible="true"] {
    display: flex;
}

#action-options .option-label {
    width: 100%;
    font-size: 0.9rem;
    color: #a9bedb;
    letter-spacing: 0.03em;
    margin-bottom: 2px;
}

/* Option buttons theme-matched */
.option-button {
    border: 1px solid color-mix(in srgb, var(--accent-color) 30%, transparent);
    background: linear-gradient(135deg, color-mix(in srgb, var(--accent-accent) 40%, #0f1b2c), #0f1b2c);
    color: inherit;
    padding: 10px 14px;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 160px;
    transition: transform 0.18s ease, border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.option-button strong {
    font-size: 0.98rem;
}

.option-button:hover {
    border-color: color-mix(in srgb, var(--accent-color) 55%, transparent);
    background: linear-gradient(135deg, color-mix(in srgb, var(--accent-color) 55%, #16263a), #16263a);
    box-shadow: 0 10px 22px rgba(39, 116, 193, 0.18);
}

.option-button.selected {
    border-color: color-mix(in srgb, var(--accent-color) 70%, white 10%);
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent-color) 30%, transparent);
}

.option-button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
}

.option-button .cost-line {
    display: flex;
    align-items: center;
    gap: 6px;
}

.option-button .cost-chip {
    margin-top: 0;
}

.resource-line {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.05rem;
}

@keyframes goldGlow {
    0%, 100% { 
        box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.3), 0 0 0 rgba(255, 215, 0, 0);
    }
    50% { 
        box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.3), 0 0 12px rgba(255, 215, 0, 0.4);
    }
}

@keyframes crystalShimmer {
    0%, 100% { 
        box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.3), 0 0 0 rgba(135, 206, 235, 0);
    }
    50% { 
        box-shadow: inset 0 0 8px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.3), 0 0 12px rgba(135, 206, 235, 0.5);
    }
}

@keyframes resourcePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.resource-icon.gold:hover {
    animation: goldGlow 1.5s ease-in-out infinite;
}

.resource-icon.crystal:hover {
    animation: crystalShimmer 1.5s ease-in-out infinite;
}

.resource-icon.updated {
    animation: resourcePulse 0.6s ease-in-out;
}

.resource-line {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.05rem;
    padding: 4px 0;
    transition: all 0.2s ease;
}

.resource-line:hover {
    opacity: 0.95;
}

.resource-line strong {
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    transition: color 0.2s ease;
}

.resource-line:hover strong {
    color: var(--accent-color);
}

.cost-line {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
}

.cost-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(15, 23, 32, 0.6);
    border: 1px solid rgba(120, 150, 185, 0.35);
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
}

.cost-chip svg {
    vertical-align: middle;
    margin-right: 2px;
}

.cost-chip.gold {
    color: #ffd700;
}

.cost-chip.crystal {
    color: #87ceeb;
}

.cost-chip.food {
    color: #90ee90;
}

.cost-chip.materials {
    color: #d7ccc8;
}

.cost-note {
    font-size: 0.78rem;
    color: #9eb7d7;
}

.action-button .action-cost {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.82rem;
}

.action-button .action-cost .cost-chip {
    margin-top: 0;
}

.player-resources.active-player {
    border: 2px solid var(--accent-color);
    border-radius: 8px;
    padding: 8px;
    background: rgba(58, 141, 255, 0.05);
    box-shadow: 0 0 8px rgba(58, 141, 255, 0.2);
    animation: activePlayerPulse 2s ease-in-out infinite;
}

@keyframes activePlayerPulse {
    0%, 100% { 
        box-shadow: 0 0 8px rgba(58, 141, 255, 0.2);
    }
    50% { 
        box-shadow: 0 0 12px rgba(58, 141, 255, 0.4);
    }
}

/* Modal styles... (keeping existing modal CSS) */
.modal-backdrop {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    background: rgba(0, 0, 0, 0.6) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    z-index: 10000 !important;
    pointer-events: auto !important;
    width: 100vw !important;
    height: 100vh !important;
}

#exploration-popup {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    background: linear-gradient(135deg, #1a2332 0%, #2d3748 100%) !important;
    border: 3px solid #3a8dff !important;
    border-radius: 16px !important;
    padding: 25px !important;
    text-align: center !important;
    color: white !important;
    font-size: 16px !important;
    font-weight: bold !important;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.8) !important;
    z-index: 10002 !important;
    min-width: 480px !important;
    max-width: 600px !important;
    width: auto !important;
    height: auto !important;
    max-height: 85vh !important;
    overflow-y: auto !important;
    pointer-events: auto !important;
    backdrop-filter: blur(10px) !important;
    -webkit-backdrop-filter: blur(10px) !important;
    box-sizing: border-box !important;
}

#exploration-popup h3 {
    margin: 0 0 15px 0 !important;
    color: #3a8dff !important;
    font-size: 24px !important;
}

#dice-container {
    margin: 15px 0 !important;
}

#dice-container div {
    margin-bottom: 10px !important;
}

#d100-display, #second-dice-display, .d100-display-popup, .second-dice-display-popup {
    font-size: 36px !important;
    font-weight: bold !important;
    min-height: 50px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    color: #87ceeb !important;
}

#second-dice-display, .second-dice-display-popup {
    color: #ffd700 !important;
}

.dice-container-popup {
    margin: 20px 0 !important;
}

.dice-container-popup div {
    margin-bottom: 15px !important;
}

.result-display-popup {
    margin-top: 20px !important;
}

#result-display {
    margin-top: 20px !important;
}

#exploration-popup .result-icon {
    font-size: 32px !important;
    margin-bottom: 15px !important;
}

#exploration-popup .result-message {
    font-size: 20px !important;
    margin-bottom: 10px !important;
}

#exploration-popup .result-rewards {
    font-size: 24px !important;
    font-weight: bold !important;
}

#exploration-popup.popup-entering {
    transform: translate(-50%, -50%) scale(0.8) !important;
    opacity: 0 !important;
    animation: popupEnter 0.3s ease-out forwards !important;
}

@keyframes popupEnter {
    0% {
        transform: translate(-50%, -50%) scale(0.8);
        opacity: 0;
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
}

#exploration-popup.popup-exiting {
    animation: popupExit 0.3s ease-in forwards !important;
}

@keyframes popupExit {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(0.8);
        opacity: 0;
    }
}

.modal-panel {
    min-width: 480px !important;
    max-width: 600px !important;
    width: auto !important;
    height: auto !important;
    max-height: 85vh !important;
    background: #8fb3d9 !important;
    color: #0b121b !important;
    border: 2px solid #1250a6 !important;
    border-radius: 12px !important;
    padding: 20px !important;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.8) !important;
    display: flex !important;
    flex-direction: column !important;
    position: relative !important;
    z-index: 10001 !important;
    box-sizing: border-box !important;
    overflow-y: auto !important;
}

.modal-titlebar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 2px solid #1250a6;
}

.modal-title {
    font-weight: 700 !important;
    color: #1250a6 !important;
    font-size: 18px !important;
}

.modal-close {
    border: 2px solid #1250a6 !important;
    background: #3a8dff !important;
    color: #ffd54a !important;
    border-radius: 8px !important;
    padding: 6px 10px !important;
    cursor: pointer !important;
    font-weight: 700 !important;
    font-size: 16px !important;
    transition: all 0.2s ease !important;
}

.modal-close:hover {
    background: #1250a6 !important;
    transform: scale(1.1) !important;
}

.unit-chip-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 12px 0;
    max-height: 280px;
    overflow: auto;
}

#unit-select-modal .unit-chip {
    text-align: left !important;
    width: 100% !important;
    padding: 12px 16px !important;
    border-radius: 8px !important;
    border: 2px solid rgba(120, 150, 185, 0.35) !important;
    background: #000 !important;
    color: #9aa7b8 !important;
    cursor: pointer !important;
    font-family: inherit !important;
    font-size: 14px !important;
    line-height: 1.4 !important;
    transition: all 0.2s ease !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    margin: 0 !important;
    box-sizing: border-box !important;
}

#unit-select-modal .unit-chip:hover {
    border-color: #3a8dff !important;
    box-shadow: 0 2px 8px rgba(58, 141, 255, 0.3) !important;
}

#unit-select-modal .unit-chip .unit-text { 
    display: flex !important; 
    gap: 8px !important; 
    align-items: baseline !important; 
    flex: 1 !important;
}

#unit-select-modal .unit-chip .unit-name { 
    font-weight: 700 !important; 
    font-size: 16px !important;
}

#unit-select-modal .unit-chip .unit-meta { 
    font-size: 0.85rem !important; 
    color: inherit !important; 
}

#unit-select-modal .unit-chip .unit-check { 
    margin-left: auto !important; 
    opacity: 0.8 !important;
    font-size: 16px !important;
}

#unit-select-modal .unit-chip.selected {
    background: #3a8dff !important;
    border-color: #1250a6 !important;
    color: #ffd54a !important;
    box-shadow: 0 4px 12px rgba(58, 141, 255, 0.4) !important;
}

#unit-select-modal .unit-chip.selected .unit-name,
#unit-select-modal .unit-chip.selected .unit-meta { 
    color: #ffd54a !important; 
}

#unit-select-modal .unit-chip.deselected {
    background: #000 !important;
    color: #9aa7b8 !important;
    border-style: dashed !important;
    opacity: 0.6 !important;
}

.modal-controls {
    display: flex;
    gap: 8px;
    margin-top: 10px;
    justify-content: flex-end;
}

.modal-controls .option-button {
    background: #3a8dff !important;
    color: #ffd54a !important;
    border: 2px solid #1250a6 !important;
    font-weight: 700 !important;
    padding: 8px 16px !important;
    border-radius: 8px !important;
    cursor: pointer !important;
    transition: all 0.2s ease !important;
}

.modal-controls .option-button:hover {
    background: #1250a6 !important;
    transform: translateY(-1px) !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3) !important;
}

.modal-controls .option-button.primary {
    background: #28a745 !important;
    border-color: #1e7e34 !important;
    color: white !important;
}

#combat-modal .units-container {
  display: flex !important;
  gap: 20px !important;
  margin: 20px 0 !important;
  flex: 1 !important;
  min-height: 0 !important;
}

#combat-modal .unit-list {
  flex: 1 !important;
  background: rgba(0, 0, 0, 0.3) !important;
  border-radius: 8px !important;
  padding: 10px !important;
  max-height: 300px !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  border: 1px solid rgba(58, 141, 255, 0.3) !important;
}

#combat-modal .unit-list::-webkit-scrollbar {
  width: 8px !important;
}

#combat-modal .unit-list::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.2) !important;
  border-radius: 4px !important;
}

#combat-modal .unit-list::-webkit-scrollbar-thumb {
  background: rgba(58, 141, 255, 0.6) !important;
  border-radius: 4px !important;
}

#combat-modal .unit-list::-webkit-scrollbar-thumb:hover {
  background: rgba(58, 141, 255, 0.8) !important;
}

#combat-modal .combat-button {
  margin-top: auto !important;
  flex-shrink: 0 !important;
}

/* ===== MOBILE & RESPONSIVE OPTIMIZATIONS ===== */
@media (max-width: 1024px) {
  body {
    overflow-x: hidden;
  }

  main#game-layout {
    padding: 12px;
    gap: 12px;
  }

  /* HUD mobile: passer en layout vertical scrollable */
  #hud {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
    gap: 8px;
    padding: 8px;
    max-height: none;
    overflow-y: auto;
  }

  #branding,
  #turn-panel,
  #resource-panel,
  #action-brief,
  #actions,
  #harvest-actions,
  #action-options,
  #end-turn {
    grid-column: 1 !important;
    grid-row: auto !important;
  }

  #resource-panel {
    display: flex;
    flex-direction: row;
    gap: 12px;
  }

  .player-resources {
    flex: 1;
  }

  #actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }

  .action-button {
    flex: 1 1 calc(33.333% - 8px);
    min-width: 100px;
    padding: 8px;
    font-size: 0.85rem;
  }

  #harvest-donut-wrapper {
    max-width: 200px;
    margin: 0 auto;
  }

  #harvest-donut-canvas {
    width: 200px !important;
    height: 200px !important;
  }

  /* Board mobile: responsive */
  #board-wrapper {
    flex-direction: column;
  }

  #board-container {
    max-width: 100%;
    overflow-x: auto;
    min-height: 400px;
  }

  #pixi-container {
    width: 100%;
    min-height: 400px;
  }

  #pixi-container canvas {
    max-width: 100%;
    width: 100% !important;
    height: auto !important;
    display: block !important;
  }

  #log-panel {
    width: 100%;
    max-height: 200px;
    overflow-y: auto;
  }

  /* Modals mobile */
  .modal-panel {
    width: 95vw !important;
    max-width: 95vw !important;
    max-height: 90vh !important;
    overflow-y: auto;
  }

  #combat-modal {
    width: 95vw !important;
    max-width: 95vw !important;
    flex-direction: column !important;
  }

  #combat-modal .combat-sides {
    flex-direction: column !important;
    gap: 12px !important;
  }

  #combat-modal .combat-side {
    flex: 1 !important;
    max-height: none !important;
  }
}

/* Petits écrans (smartphones en portrait) */
@media (max-width: 640px) {
  main#game-layout {
    padding: 8px;
    gap: 8px;
  }

  #hud {
    padding: 6px;
    gap: 6px;
  }

  .info-card {
    padding: 6px 8px;
    font-size: 0.75rem;
  }

  .action-button {
    padding: 6px;
    font-size: 0.8rem;
  }

  #branding h1 {
    font-size: 1rem;
  }

  #branding p {
    font-size: 0.65rem;
  }

  #helper-text {
    font-size: 0.8rem;
    padding: 8px;
  }

  /* Rendre les boutons des modals plus grands pour le tactile */
  button {
    min-height: 44px;
    touch-action: manipulation;
  }

  .modal-panel button {
    padding: 12px 16px;
    font-size: 1rem;
  }
}

/* Orientation paysage sur mobile */
@media (max-width: 1024px) and (orientation: landscape) {
  #board-wrapper {
    flex-direction: row;
  }

  #board-container {
    flex: 1;
  }

  #log-panel {
    width: 250px;
    max-height: none;
  }
}

/* Support des gestes tactiles */
@media (hover: none) and (pointer: coarse) {
  /* Augmenter les zones tactiles */
  .action-button,
  button,
  .modal-panel button {
    min-height: 48px;
    padding: 12px 16px;
  }

  /* Désactiver les effets hover sur tactile */
  .action-button:hover,
  button:hover {
    transform: none;
  }

  /* Effet de feedback tactile */
  .action-button:active,
  button:active {
    transform: scale(0.95);
    opacity: 0.8;
  }
}

/* ===== RESPONSIVE LAYOUT SYSTEM ===== */

/* Board rotation for portrait mode */
#board-container.rotated-90 {
  transform-origin: center center;
  transition: transform 0.3s ease;
}

/* History panel hidden state */
#board-wrapper.history-hidden #log-panel {
  display: none !important;
}

/* Compact HUD for smaller screens */
#hud.hud-compact {
  grid-template-rows: repeat(2, 90px);
  padding: 8px;
  gap: 6px;
}

#hud.hud-compact .action-button {
  padding: 8px;
  font-size: 0.85rem;
}

#hud.hud-compact .info-card {
  padding: 4px 6px;
  font-size: 0.75rem;
}

/* Layout modes */
main#game-layout.layout-compact {
  padding: 12px;
  gap: 12px;
}

main#game-layout.layout-portrait-rotated {
  padding: 8px;
  gap: 8px;
  flex-direction: row;
  align-items: center;
}

main#game-layout.layout-portrait-rotated #hud {
  writing-mode: horizontal-tb;
  max-width: 100%;
  grid-template-columns: 1fr;
  grid-template-rows: auto;
}

main#game-layout.layout-portrait-rotated #board-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* History toggle button (appears when history can be hidden) */
#history-toggle-btn {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  color: white;
  font-weight: 700;
  font-size: 0.9rem;
  padding: 12px 16px;
  border: 2px solid rgba(59, 130, 246, 0.6);
  border-radius: 50px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
  z-index: 1000;
  display: none; /* Hidden by default, shown by JS when needed */
}

#history-toggle-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(59, 130, 246, 0.6);
  background: linear-gradient(135deg, #60a5fa 0%, #3b82f6 100%);
}

#history-toggle-btn.visible {
  display: block;
}

/* Log panel h2 styling */
#log-panel h2 {
  margin: 0 0 12px 0;
  font-size: 1.1rem;
  color: var(--accent-color);
}

#board-wrapper {
  display: flex;
  gap: 16px;
  align-items: stretch;
  flex: 1;
  min-height: 0;
}

/* Board area contains helper text + board container */
#board-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

/* Helper text positioned above the grid */
#helper-text {
  padding: 12px 16px;
  background: rgba(58, 141, 255, 0.1);
  border-left: 4px solid var(--accent-color);
  font-size: 0.9rem;
  color: #c5d7f1;
  line-height: 1.5;
  border-radius: 4px;
  flex-shrink: 0;
}

/* Board container takes remaining space */
#board-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  min-height: 0;
  background: #050b12;
  border-radius: 8px;
}

#pixi-container {
  max-width: 100%;
  max-height: 100%;
  width: 100%;
  height: 100%;
}

/* Log panel optimized for grid height */
#log-panel {
  background: rgba(12, 18, 25, 0.85);
  border: 1px solid rgba(102, 178, 255, 0.25);
  border-radius: 12px;
  padding: 12px;
  width: 320px;
  min-width: 280px;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#log-header {
  flex-shrink: 0;
}

#log {
  flex: 1;
  overflow-y: auto;
  font-size: 0.85rem;
  line-height: 1.5;
  color: #c5d7f1;
}