/* --- Variables globales (Palette stricte extraite de background.png) --- */
:root {
    --card-ratio: 3 / 2; 
    --c-purple: #623687;       
    --c-light-yellow: #fceea7; 
    --c-orange: #e68d18;       
    --c-white: #ffffff;        
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-image: url('../images/ui/background.png');
    background-repeat: repeat;
    background-color: var(--c-light-yellow); 
    color: var(--c-purple);
    margin: 0;
    padding: 10px 20px; 
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

#setup-screen, #game-screen, #workshop-screen, #score-screen {
    width: 100%;
    max-width: 750px;
    margin: 0 auto;
}

header {
    width: 100%;
    margin-bottom: 20px;
}

.header-top-bar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    width: 100%;
    max-width: 750px; 
    box-sizing: border-box;
    margin: 0 auto;
}

.header-flags {
    display: flex;
    gap: 10px;
    justify-content: flex-start; 
}

.header-logo {
    display: flex;
    justify-content: center;
    align-items: center;
}

.header-rules-btn {
    display: flex;
    justify-content: flex-end; 
}

header img {
    max-height: 80px !important; 
}

.lang-flag {
    width: 40px;
    height: 40px;
    cursor: pointer;
    border: 2px solid var(--c-purple);
    border-radius: 50%;
    background-color: var(--c-white);
    transition: transform 0.2s, box-shadow 0.2s;
    object-fit: contain; 
    padding: 2px; 
    box-sizing: border-box;
}
.lang-flag:hover { 
    transform: scale(1.15); 
    box-shadow: 0 4px 8px rgba(98, 54, 135, 0.4);
}

.btn-rules {
    cursor: pointer;
    font-size: 26px;
    color: var(--c-purple);
    font-weight: bold;
    background: var(--c-white);
    border: 3px solid var(--c-orange);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(98, 54, 135, 0.3);
    transition: background-color 0.2s, color 0.2s, transform 0.2s;
}
.btn-rules:hover {
    background: var(--c-orange);
    color: var(--c-white);
    transform: scale(1.1);
}

h1, h2, h3, h4 {
    color: var(--c-purple);
}

.btn {
    padding: 10px 20px;
    font-size: 16px;
    cursor: pointer;
    background-color: var(--c-purple);
    color: var(--c-white);
    border: 2px solid var(--c-purple);
    border-radius: 5px;
    font-weight: bold;
    transition: 0.2s;
}

.btn:hover {
    background-color: var(--c-orange);
    border-color: var(--c-orange);
    color: var(--c-white);
}

.grid-7x7 {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 8px; 
    width: 100%;
    background-color: rgba(255, 255, 255, 0.85);
    padding: 12px;
    border-radius: 8px;
    border: 3px solid var(--c-purple);
    box-shadow: 0 4px 15px rgba(98, 54, 135, 0.2);
    box-sizing: border-box;
}

.cell {
    aspect-ratio: var(--card-ratio);
    border-radius: 6px;
    position: relative; 
    background-color: rgba(255, 255, 255, 0.5);
    border: 1px dashed rgba(98, 54, 135, 0.3);
    min-width: 0;
    min-height: 0; 
}

.card {
    width: 100%; 
    height: 100%;
    cursor: pointer;
    transition: transform 0.2s, z-index 0.2s;
    border-radius: 6px;
    box-shadow: 0 2px 4px rgba(98, 54, 135, 0.3);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    background-color: var(--c-white);
}

.card:hover {
    transform: scale(1.05);
    z-index: 10;
}

.card-img {
    width: auto;
    height: 150%;
    object-fit: contain;
    transform: rotate(90deg);
}

.card.bonus .card-img {
    transform: rotate(-90deg);
}

.character-token {
    width: 100%; 
    height: 100%;
    z-index: 5;
    display: flex;
    justify-content: center;
    align-items: center;
    animation: dropIn 0.3s ease-out;
}

.character-token img {
    width: auto;
    height: 150%; 
    object-fit: contain; 
    filter: drop-shadow(0 4px 6px rgba(98, 54, 135, 0.6));
    transform: rotate(90deg); 
}

.panel {
    background: var(--c-white);
    width: 100%;
    box-sizing: border-box;
    padding: 20px 30px;
    border-radius: 8px;
    border: 4px solid var(--c-purple);
    box-shadow: 0 6px 12px rgba(0,0,0,0.15);
    text-align: left;
}

.panel h2 {
    text-align: center;
    margin-top: 0;
}

.setup-group {
    margin-bottom: 20px;
    text-align: center;
}

.setup-group select, .setup-group input[type="checkbox"] {
    padding: 8px;
    font-size: 16px;
    border-radius: 4px;
    border: 2px solid var(--c-purple);
    color: var(--c-purple);
    font-weight: bold;
    cursor: pointer;
}

.player-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--c-light-yellow);
    padding: 10px;
    margin-bottom: 10px;
    border-radius: 6px;
    border-left: 5px solid var(--c-orange);
    color: var(--c-purple);
}

.player-row strong {
    color: var(--c-purple);
}

.player-row select {
    padding: 6px;
    border: 1px solid var(--c-purple);
    color: var(--c-purple);
}

.player-char-display {
    display: flex;
    align-items: center;
    gap: 15px;
}

.btn-large {
    display: block;
    width: 100%;
    padding: 15px;
    font-size: 18px;
    margin-top: 20px;
    background-color: var(--c-orange);
    border-color: var(--c-orange);
}

.btn-large:hover {
    background-color: var(--c-purple);
    border-color: var(--c-purple);
}

.game-header {
    position: relative;
    margin: 0 auto 15px auto;
    background: var(--c-white);
    padding: 10px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(98, 54, 135, 0.2);
    border-bottom: 5px solid var(--c-orange);
    border-top: 2px solid var(--c-purple);
    border-left: 2px solid var(--c-purple);
    border-right: 2px solid var(--c-purple);
    width: 100%;
    height: 100px; 
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    animation: slideDown 0.4s ease-out;
}

@keyframes slideDown {
    from { transform: translateY(-50px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.header-left {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start; 
    text-align: left;
}

.header-left h2 {
    margin: 0 0 5px 0;
    font-size: 20px;
}

.header-left p {
    margin: 0;
    color: var(--c-purple);
    opacity: 0.85;
    font-size: 14px;
}

.header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
}

.btn-inventory {
    background-color: var(--c-purple);
    color: var(--c-white);
    border: 2px solid var(--c-purple);
    padding: 8px 15px;
    border-radius: 5px;
    font-weight: bold;
    cursor: pointer;
    white-space: nowrap;
    box-shadow: 0 2px 4px rgba(98, 54, 135, 0.3);
    transition: 0.2s;
}

.btn-inventory:hover {
    background-color: var(--c-orange);
    border-color: var(--c-orange);
}

.header-right {
    background-color: var(--c-light-yellow);
    padding: 8px 12px;
    border-radius: 5px;
    border: 2px solid var(--c-orange);
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    box-shadow: 0 2px 5px rgba(98, 54, 135, 0.2);
    text-align: left;
}

.btn-warning {
    padding: 6px 12px;
    background: var(--c-orange);
    color: var(--c-white);
    border: none;
    border-radius: 4px;
    font-weight: bold;
    cursor: pointer;
    white-space: nowrap;
    box-shadow: 0 2px 4px rgba(98, 54, 135, 0.3);
    transition: background-color 0.2s;
}

.btn-warning:hover {
    background: var(--c-purple);
}

.card.playable {
    outline: 4px solid var(--c-orange);
    outline-offset: -4px;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { outline-color: var(--c-orange); }
    50% { outline-color: transparent; }
    100% { outline-color: var(--c-orange); }
}

@media (max-width: 700px) {
    .header-top-bar {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    .header-flags, .header-rules-btn {
        justify-content: center;
        padding: 0;
    }
    .game-header {
        height: auto; 
        min-height: 100px;
        flex-direction: column;
        align-items: center;
        padding: 10px;
        gap: 10px;
    }
    .header-left {
        align-items: center;
        text-align: center;
    }
    .header-actions {
        flex-direction: column;
        width: 100%;
    }
    .header-right {
        width: 100%;
        box-sizing: border-box;
        flex-direction: column;
        text-align: center;
    }
    .player-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    .player-char-display {
        width: 100%;
        justify-content: space-between;
    }
}

.custom-modal {
    position: fixed;
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%;
    background: rgba(98, 54, 135, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.custom-modal-content {
    background: var(--c-white);
    padding: 30px 40px;
    border-radius: 8px;
    border: 5px solid var(--c-orange);
    text-align: center;
    max-width: 450px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    color: var(--c-purple);
    font-size: 1.1rem;
}

.custom-modal-buttons {
    margin-top: 25px;
    display: flex;
    justify-content: center;
    gap: 15px;
}

.btn-cancel {
    background-color: var(--c-light-yellow);
    color: var(--c-purple);
    border-color: var(--c-purple);
}

.btn-cancel:hover {
    background-color: #ebd779;
    color: var(--c-purple);
}

.inventory-modal-overlay {
    position: fixed;
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%;
    background: rgba(255, 255, 255, 0.75); 
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
}

.inventory-modal-content {
    background: rgba(255, 255, 255, 0.95);
    padding: 25px 40px;
    border-radius: 12px;
    border: 4px solid var(--c-purple);
    text-align: center;
    max-width: 80%;
    max-height: 80vh;
    box-shadow: 0 15px 40px rgba(98, 54, 135, 0.3);
    display: flex;
    flex-direction: column;
}

.inventory-modal-cards {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-top: 15px;
    margin-bottom: 25px;
    overflow-y: auto;
    padding: 10px;
}

.inventory-modal-cards img {
    width: 70px;
    height: 105px;
    border-radius: 4px;
    box-shadow: 0 3px 6px rgba(98, 54, 135, 0.3);
    object-fit: contain;
    border: 1px solid var(--c-purple);
}

.rules-modal-overlay {
    position: fixed;
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%;
    background: rgba(98, 54, 135, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
}

.rules-modal-wrapper {
    position: relative;
    max-width: 800px;
    width: 90%;
}

.rules-modal-content {
    background: var(--c-light-yellow);
    padding: 30px 40px;
    border-radius: 12px;
    border: 4px solid var(--c-orange);
    max-height: 85vh;
    overflow-y: auto;
    text-align: left;
    box-shadow: 0 15px 40px rgba(0,0,0,0.5);
    color: var(--c-purple);
    line-height: 1.5;
}

.char-selection-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    margin-top: 20px;
}

.char-select-item {
    cursor: pointer;
    border: 3px solid transparent;
    border-radius: 8px;
    padding: 10px;
    background: var(--c-white);
    box-shadow: 0 2px 5px rgba(98, 54, 135, 0.2);
    transition: transform 0.2s, border-color 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.char-select-item:hover {
    transform: scale(1.05);
    border-color: var(--c-orange);
}

.char-select-item.current-char {
    border-color: var(--c-purple);
    background: var(--c-light-yellow);
    cursor: default;
}

.char-select-item.current-char:hover {
    transform: none;
}

.char-select-item-wrapper {
    width: 90px;
    height: 60px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.char-select-item img {
    height: 90px;
    transform: rotate(90deg);
    object-fit: contain;
    filter: drop-shadow(0 4px 6px rgba(0,0,0,0.3));
    border-radius: 4px;
}

.char-select-item span {
    font-size: 0.85rem;
    color: var(--c-purple);
    font-weight: bold;
    line-height: 1.2;
    text-align: center;
}

@media (max-width: 500px) {
    .char-selection-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.close-modal-x {
    position: absolute;
    top: -15px;
    right: -15px;
    width: 40px;
    height: 40px;
    background-color: var(--c-orange);
    color: var(--c-white);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 20px;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
    border: 3px solid var(--c-white);
    z-index: 10001;
    transition: transform 0.2s, background-color 0.2s;
}

.close-modal-x:hover {
    transform: scale(1.1);
    background-color: var(--c-purple);
}

.rules-modal-content h2, .rules-modal-content h3 {
    color: var(--c-purple);
    border-bottom: 2px solid var(--c-orange);
    padding-bottom: 5px;
    margin-top: 20px;
}

.rules-bonus-row {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
    background: var(--c-white);
    padding: 10px;
    border-radius: 8px;
    border: 1px dashed var(--c-orange);
}

.rules-bonus-img {
    height: 120px;
    margin-right: 15px;
    border-radius: 4px;
    border: 1px solid var(--c-purple);
    box-shadow: 0 2px 4px rgba(98, 54, 135, 0.3);
}

.workshop-panel {
    max-width: 1100px;
    margin: 0 auto;
}

.workshop-layout {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
}

.workshop-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.workshop-region {
    background: var(--c-white);
    border: 2px solid var(--c-purple);
    padding: 15px;
    border-radius: 8px;
    box-shadow: inset 0 1px 3px rgba(98, 54, 135, 0.1);
}

.workshop-region h3 {
    margin-top: 0;
    color: var(--c-purple);
    border-bottom: 2px solid var(--c-light-yellow);
    padding-bottom: 5px;
    font-size: 1.2rem;
}

.workshop-region h4 {
    margin: 10px 0 5px 0;
    font-size: 1rem;
    color: var(--c-purple);
    opacity: 0.9;
}

.slots-container {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
    justify-content: center;
    align-items: center;
}

.horizontal-robot {
    border: 2px solid var(--c-purple);
    padding: 10px;
    border-radius: 8px;
    background: var(--c-light-yellow);
}

.slot {
    width: 100px;
    height: 150px;
    border: 2px dashed var(--c-purple);
    border-radius: 6px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--c-purple);
    background: var(--c-white);
    transition: 0.2s;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.slot:hover:not(.disabled-diagonal) {
    border-color: var(--c-orange);
    background-color: var(--c-light-yellow);
    color: var(--c-orange);
}

.slot.filled {
    border: 2px solid var(--c-orange);
    background: transparent;
    color: transparent; 
}

.disabled-diagonal {
    position: relative;
    background-image: linear-gradient(45deg, rgba(98, 54, 135, 0.1) 25%, transparent 25%), 
                      linear-gradient(-45deg, rgba(98, 54, 135, 0.1) 25%, transparent 25%),
                      linear-gradient(45deg, transparent 75%, rgba(98, 54, 135, 0.1) 75%),
                      linear-gradient(-45deg, transparent 75%, rgba(98, 54, 135, 0.1) 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    background-color: var(--c-white);
    border-color: rgba(98, 54, 135, 0.3);
    color: rgba(98, 54, 135, 0.3);
    cursor: not-allowed;
}

.automatic-region.active {
    background-image: none; 
    background-color: var(--c-white);
    border-color: var(--c-orange);
}

.allies-list, .active-bonuses-list {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
    min-height: 50px;
}

.slotted-card {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 4px;
}

.inventory-region {
    background: var(--c-light-yellow);
}

.inventory-sorted-containers {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    justify-content: center;
}

.inventory-category {
    background: var(--c-white);
    border-radius: 6px;
    padding: 10px;
    border: 2px solid var(--c-purple);
    min-width: 150px;
}

.inventory-category h4 {
    text-align: center;
    margin-top: 0;
    color: var(--c-purple);
    border-bottom: 2px solid var(--c-light-yellow);
}

.inventory-grid {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    min-height: 50px;
    justify-content: center;
}

.inventory-card {
    width: 60px; 
    height: 90px;
    cursor: pointer;
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(98, 54, 135, 0.3);
    object-fit: contain;
    background: var(--c-white);
    border: 1px solid var(--c-purple);
}

.small-text-italic {
    font-size: 0.85rem;
    color: var(--c-purple);
    opacity: 0.8;
    font-style: italic;
    margin-top: -5px;
    text-align: center;
}

.btn-validate {
    background-color: var(--c-orange); 
    border-color: var(--c-orange);
    margin-top: 30px;
}

.btn-validate:hover {
    background-color: var(--c-purple);
    border-color: var(--c-purple);
}

.vertical-robot {
    display: flex;
    flex-direction: column; 
    gap: 8px;
    border: 2px solid var(--c-purple);
    padding: 15px;
    border-radius: 8px;
    background: var(--c-light-yellow);
    align-items: center;
    width: fit-content;
    margin: 0 auto;
}

.bonus-active-card {
    width: 100px;
    height: 150px;
    border-radius: 6px;
    box-shadow: 0 4px 8px rgba(98, 54, 135, 0.4);
    object-fit: contain;
    transition: transform 0.2s;
    border: 1px solid var(--c-purple);
}

.bonus-active-card:hover {
    transform: scale(1.05);
}

.part-slot {
    width: 140px !important;
    height: 94px !important;
}

.part-slot .slotted-card {
    width: 94px !important;
    height: 140px !important;
    transform: rotate(90deg);
}

.automatic-ally {
    gap: 25px !important; 
}

.automatic-ally .slotted-card {
    width: 60px;
    height: 90px;
    transform: rotate(90deg);
}

/* NOUVEAU : Design translucide du pop-up de conseil pour voir la grille en dessous */
.smart-hint-popup {
    position: absolute;
    z-index: 10000;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(3px);
    border: 3px solid var(--c-purple);
    border-radius: 8px;
    padding: 15px;
    width: 320px;
    box-shadow: 0 15px 35px rgba(0,0,0,0.4);
    animation: popIn 0.3s ease-out forwards;
}

@keyframes popIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

.hint-highlight {
    outline: 4px solid var(--c-orange);
    outline-offset: -4px;
    animation: hintPulse 1.5s infinite;
}

@keyframes hintPulse {
    0% { outline-color: var(--c-orange); transform: scale(1); }
    50% { outline-color: var(--c-purple); transform: scale(1.05); }
    100% { outline-color: var(--c-orange); transform: scale(1); }
}
/* Keep contextual advice inside narrow viewports. */
@media (max-width: 700px) {
    .smart-hint-popup {
        position: fixed !important;
        left: 50% !important;
        top: 50% !important;
        translate: -50% -50%;
        width: min(320px, calc(100vw - 32px));
        max-height: calc(100vh - 32px);
        overflow: auto;
        box-sizing: border-box;
        animation: none;
    }
}

