* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: Arial, sans-serif;
    background: #1a1a1a;
    color: #fff;
    overflow: hidden;
}

#container {
    width: 100vw;
    height: 100vh;
    position: relative;
}

#canvas3D {
    width: 100%;
    height: 100%;
    display: block;
}

#info-panel,
#legend-panel,
#route-panel,
#routing-table-panel {
    position: absolute;
    background: rgba(0, 0, 0, 0.8);
    padding: 20px;
    border-radius: 8px;
    border: 1px solid #ffff00;
    max-width: 350px;
}

#info-panel,
#legend-panel {
    overflow: hidden;
    transition: max-height 0.45s ease, padding 0.45s ease, background 0.45s ease;
}

#info-panel.collapsed,
#legend-panel.collapsed {
    padding-top: 12px;
    padding-bottom: 12px;
    background: rgba(0, 0, 0, 0.78);
}

.collapsible-header {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0;
    margin: 0;
    background: transparent;
    color: #ffff00;
    border: none;
    border-radius: 0;
    cursor: pointer;
    text-align: left;
}

.collapsible-header:hover {
    background: transparent;
}

.collapsible-header h2 {
    margin-bottom: 0 !important;
}

.collapse-arrow {
    flex: 0 0 auto;
    color: #ffff00;
    font-size: 14px;
    line-height: 1;
    transition: transform 0.35s ease;
}

.collapsible-content {
    max-height: 600px;
    opacity: 1;
    margin-top: 10px;
    overflow: hidden;
    transition: max-height 0.45s ease, opacity 0.30s ease, margin-top 0.45s ease;
}

.collapsed .collapsible-content {
    max-height: 0;
    opacity: 0;
    margin-top: 0;
}


#session-score-overlay {
    position: absolute;
    top: 22%;
    left: 18px;
    transform: none;
    z-index: 20;
    color: rgba(255, 255, 255, 0.9);
    font-size: 13px;
    line-height: 1.55;
    text-shadow: 0 0 6px #000, 0 0 10px #000;
    pointer-events: none;
}

#session-score-overlay strong {
    color: #ffff00;
}

#exercise-progress-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 4px;
    margin-bottom: 10px;
    pointer-events: none;
}

.exercise-progress-cell {
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 5px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    background: rgba(80, 80, 80, 0.36);
    color: rgba(255, 255, 255, 0.56);
    font-size: 10px;
    font-weight: bold;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.7);
    transition: background 0.35s ease, border-color 0.35s ease, box-shadow 0.35s ease, color 0.35s ease, transform 0.35s ease;
}

.exercise-progress-cell.done {
    color: #000000;
    transform: scale(1.04);
}

.exercise-progress-cell.success {
    border-color: #00d66a;
    box-shadow: 0 0 8px rgba(0, 214, 106, 0.7), 0 0 14px rgba(255, 255, 0, 0.22);
}

.exercise-progress-cell.failure {
    border-color: #ff3333;
    box-shadow: 0 0 8px rgba(255, 51, 51, 0.75), 0 0 14px rgba(255, 255, 0, 0.18);
}

#failure-banner {
    position: absolute;
    top: 82px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 25;
    min-width: 360px;
    max-width: min(680px, calc(100vw - 40px));
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid #ff3333;
    background: rgba(80, 0, 0, 0.78);
    color: #ffffff;
    font-size: 14px;
    line-height: 1.45;
    text-align: center;
    box-shadow: 0 0 18px rgba(255, 0, 0, 0.25);
    transition: opacity 0.35s ease, transform 0.35s ease;
}

#failure-banner.hidden-panel {
    opacity: 0;
    transform: translate(-50%, -8px);
    pointer-events: none;
}

#failure-banner.visible-panel {
    opacity: 1;
    transform: translate(-50%, 0);
    pointer-events: auto;
}

.failure-cards {
    display: grid;
    grid-template-columns: repeat(2, minmax(220px, 1fr));
    gap: 10px;
    margin-top: 8px;
    text-align: left;
}

.failure-card {
    padding: 10px 12px;
    border-radius: 7px;
    border: 1px solid #ff3333;
    background: rgba(120, 0, 0, 0.58);
    box-shadow: 0 0 14px rgba(255, 0, 0, 0.28);
    transition: border-color 0.35s ease, background 0.35s ease, box-shadow 0.35s ease;
}

.failure-card.resolved {
    border-color: #00ff66;
    background: rgba(0, 90, 35, 0.58);
    box-shadow: 0 0 16px rgba(0, 255, 102, 0.34);
}

.failure-card.failed {
    border-color: #ff7777;
    background: rgba(120, 0, 0, 0.72);
    box-shadow: 0 0 18px rgba(255, 0, 0, 0.45);
}

.failure-card h3 {
    margin: 0 0 6px;
    font-size: 14px;
    color: #ffffff;
}

.failure-card p {
    margin: 4px 0;
    font-size: 13px;
    line-height: 1.35;
}

.failure-card .failure-status {
    font-weight: bold;
    color: #ffff00;
}

.failure-card.resolved .failure-status {
    color: #9cff9c;
}

.failure-card.failed .failure-status {
    color: #ffb3b3;
}

.solution-hint-card {
    margin: 10px auto 0;
    padding: 10px 14px;
    max-width: 440px;
    border: 1px solid #00ff66;
    border-radius: 8px;
    background: rgba(0, 90, 35, 0.58);
    box-shadow: 0 0 18px rgba(0, 255, 102, 0.42);
    color: #ffffff;
}

.solution-hint-card strong {
    color: #9cff9c;
}

.solution-hint-title {
    margin-bottom: 4px;
    font-weight: bold;
    color: #00ff66;
}

#info-panel,
#legend-panel {
    top: 20px;
}

#info-panel {
    right: 20px;
}

#legend-panel {
    left: 20px;
}

#route-panel {
    left: 20px;
    bottom: 95px;
    width: 520px;
    max-width: calc(100vw - 40px);
    transition: opacity 0.35s ease, transform 0.35s ease;
}

#routing-table-panel {
    right: 20px;
    bottom: 150px;
    width: 390px;
    max-width: calc(100vw - 40px);
    transition: opacity 0.35s ease, transform 0.35s ease;
}

#site-signature {
    position: absolute;
    right: 20px;
    bottom: 20px;
    z-index: 18;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border: 1px solid rgba(255, 255, 0, 0.55);
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.58);
    backdrop-filter: blur(4px);
    color: rgba(255, 255, 255, 0.78);
    font-size: 11px;
    line-height: 1.25;
}

#site-signature img {
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
}

#site-signature a {
    color: #ffff00;
    font-weight: bold;
    font-size: 13px;
    text-decoration: none;
}

#site-signature a:hover {
    color: #abff00;
    text-decoration: underline;
}

#site-signature p {
    margin: 1px 0;
}

#route-panel.hidden-panel,
#routing-table-panel.hidden-panel {
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
}

#route-panel.visible-panel,
#routing-table-panel.visible-panel {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

#info-panel h2,
#legend-panel h2,
#route-panel h2,
#routing-table-panel h2 {
    color: #ffff00;
    margin-bottom: 10px;
    font-size: 16px;
}

#info-panel p,
#legend-panel p {
    margin: 5px 0;
    font-size: 13px;
    line-height: 1.5;
}

#route-panel .close-panel,
#routing-table-panel .close-panel {
    position: absolute;
    top: 8px;
    right: 10px;
    width: 24px;
    height: 24px;
    padding: 0;
    margin: 0;
    border-radius: 50%;
    border: 1px solid #ffff00;
    background: transparent;
    color: #ffff00;
    line-height: 20px;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
}

#route-panel .close-panel:hover,
#routing-table-panel .close-panel:hover {
    background: #ffff00;
    color: #000;
}

.path-row {
    margin-top: 12px;
}

.path-row h3 {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-bottom: 6px;
    font-size: 13px;
    color: #ffffff;
}

.path-color {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.request-color {
    background: #ffff00;
    box-shadow: 0 0 8px #ffff00;
}

.response-color {
    background: #00aaff;
    box-shadow: 0 0 8px #00aaff;
}

.path-list {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 5px;
    min-height: 25px;
    font-size: 13px;
    line-height: 1.4;
}

.path-node {
    display: inline-flex;
    align-items: center;
    padding: 3px 7px;
    border: 1px solid rgba(255, 255, 0, 0.55);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
    transition: color 0.25s ease, border-color 0.25s ease, background 0.25s ease, box-shadow 0.25s ease;
    animation: nodeAppear 0.25s ease both;
}

.path-node.planned {
    color: rgba(255, 255, 255, 0.48);
    border-color: rgba(255, 255, 255, 0.22);
    background: rgba(255, 255, 255, 0.045);
}

.path-node.active-request {
    color: #ffffff;
    border-color: #ffff00;
    background: rgba(255, 255, 0, 0.10);
    box-shadow: 0 0 10px rgba(255, 255, 0, 0.28);
}

.path-node.active-response {
    color: #ffffff;
    border-color: #00aaff;
    background: rgba(0, 170, 255, 0.12);
    box-shadow: 0 0 10px rgba(0, 170, 255, 0.30);
}

.path-arrow {
    color: #ffff00;
    opacity: 0.85;
    animation: nodeAppear 0.25s ease both;
}

.routing-device-title {
    margin: 6px 0 10px;
    color: #abff00;
    font-size: 14px;
    font-weight: bold;
}

.routing-decision-cards {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 8px;
}

.routing-decision-card {
    padding: 12px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.06);
    animation: nodeAppear 0.25s ease both;
}

.routing-decision-card.request-card {
    border: 1px solid #ffff00;
    box-shadow: 0 0 12px rgba(255, 255, 0, 0.18);
}

.routing-decision-card.response-card {
    border: 1px solid #00aaff;
    box-shadow: 0 0 12px rgba(0, 170, 255, 0.22);
}

.routing-decision-card.correction-needed {
    border-color: #ff3333;
    box-shadow: 0 0 18px rgba(255, 0, 0, 0.55);
}

.routing-decision-card.correction-success {
    border-color: #00ff66;
    box-shadow: 0 0 20px rgba(0, 255, 102, 0.65);
}

.routing-decision-card h3 {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-bottom: 8px;
    font-size: 14px;
}

.routing-decision-card.request-card h3 {
    color: #ffff00;
}

.routing-decision-card.response-card h3 {
    color: #00aaff;
}

.routing-field {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin: 5px 0;
    font-size: 13px;
    line-height: 1.35;
}

.routing-field-label {
    color: rgba(255, 255, 255, 0.72);
}

.routing-field-value {
    color: #ffffff;
    font-weight: bold;
    text-align: right;
}

.next-device-value {
    display: inline-block;
    min-width: 28px;
}

.next-device-value.airport-out {
    animation: airportOut 0.26s ease both;
}

.next-device-value.airport-in {
    animation: airportIn 0.38s ease both;
}

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

@keyframes airportIn {
    from { opacity: 0; transform: translateY(-12px); }
    to { opacity: 1; transform: translateY(0); }
}

.routing-decision-sentence {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.16);
    font-size: 12px;
    line-height: 1.4;
    color: rgba(255, 255, 255, 0.88);
}

.routing-correction-control {
    margin-top: 10px;
    padding: 10px;
    border: 1px solid #ff3333;
    border-radius: 7px;
    background: rgba(255, 0, 0, 0.10);
    box-shadow: 0 0 14px rgba(255, 0, 0, 0.35);
}

.routing-correction-control.success {
    border-color: #00ff66;
    background: rgba(0, 255, 102, 0.10);
    box-shadow: 0 0 16px rgba(0, 255, 102, 0.48);
}

.routing-correction-control label {
    display: block;
    margin-bottom: 6px;
    color: #ffffff;
    font-size: 12px;
    font-weight: bold;
}

.routing-correction-control select {
    width: 100%;
    min-height: 34px;
    margin-bottom: 8px;
    padding: 0 8px;
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 5px;
    background: rgba(0, 0, 0, 0.72);
    color: #ffffff;
}

.routing-correction-control button {
    margin: 0;
    padding: 8px 12px;
}

.routing-attempts {
    margin-top: 7px;
    color: #ffff00;
    font-size: 12px;
}

.routing-error-message {
    margin-top: 7px;
    color: #ffaaaa;
    font-size: 12px;
    line-height: 1.35;
}

.routing-help,
.path-help {
    margin-top: 10px;
    font-size: 12px;
    line-height: 1.4;
    color: rgba(255, 255, 255, 0.82);
}

.path-help {
    color: rgba(255, 255, 180, 0.9);
}

@keyframes nodeAppear {
    from {
        opacity: 0;
        transform: translateY(4px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

#info-panel .valid {
    color: #00ff00;
}

#info-panel .invalid {
    color: #ff0000;
}

#controls {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0, 0, 0, 0.8);
    padding: 15px;
    border-radius: 8px;
    border: 1px solid #ffff00;
    white-space: nowrap;
}

#level-control-label {
    color: #ffff00;
    font-size: 13px;
    font-weight: bold;
}

#level-select {
    min-height: 36px;
    padding: 0 12px;
    border: 1px solid rgba(255, 255, 0, 0.65);
    border-radius: 5px;
    color: #ffff00;
    background: rgba(0, 0, 0, 0.65);
    font-size: 13px;
    font-weight: bold;
    cursor: pointer;
}

#level-select:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(255, 255, 0, 0.25);
}

.modal-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(3px);
    z-index: 2000;
    transition: opacity 0.35s ease;
}

.modal-overlay.hidden-modal {
    opacity: 0;
    pointer-events: none;
}

.modal-overlay.visible-modal {
    opacity: 1;
    pointer-events: auto;
}

.modal-card {
    width: min(560px, calc(100vw - 40px));
    padding: 24px;
    border: 1px solid #ffff00;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.86);
    box-shadow: 0 0 30px rgba(255, 255, 0, 0.16);
    color: #ffffff;
    animation: modalAppear 0.35s ease both;
}

.modal-card h2 {
    color: #ffff00;
    margin-bottom: 14px;
    font-size: 20px;
}

.modal-content p,
.modal-content li {
    margin: 9px 0;
    font-size: 14px;
    line-height: 1.55;
}

.modal-content ul {
    margin-left: 20px;
}

.modal-content strong {
    color: #ffff00;
}

.modal-start-button {
    margin-top: 16px;
    margin-left: 0;
}

@keyframes modalAppear {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

button {
    padding: 10px 20px;
    margin: 0 5px;
    background: #ffff00;
    color: #000;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.25s ease, box-shadow 0.25s ease, transform 0.25s ease, opacity 0.25s ease;
}

button:hover {
    background: #abff00;
}

#btn-send-request {
    background: linear-gradient(135deg, #ffff00 0%, #bfff3a 100%);
}

#btn-send-request:hover {
    background: linear-gradient(135deg, #ffff66 0%, #9cff22 100%);
}

#btn-simulate-failure {
    background: linear-gradient(135deg, #ffff00 0%, #ffb327 100%);
}

#btn-simulate-failure:hover {
    background: linear-gradient(135deg, #ffff66 0%, #ff8c18 100%);
}

#btn-reset {
    background: linear-gradient(135deg, #ffe600 0%, #ffcf55 100%);
}

#btn-reset:hover {
    background: linear-gradient(135deg, #fff066 0%, #ffbd2b 100%);
}

#btn-regenerate {
    background: linear-gradient(135deg, #ffff00 0%, #e8ff66 100%);
}

#btn-level-context {
    background: linear-gradient(135deg, #fff57a 0%, #ffff00 100%);
}

#btn-session-report {
    background: linear-gradient(135deg, #ffff00 0%, #d8eeff 100%);
}

button.expected-action:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 0 0 3px rgba(255, 255, 0, 0.38), 0 0 26px rgba(255, 255, 0, 0.95), 0 0 42px rgba(255, 255, 0, 0.28);
    animation: expectedActionPulse 1.35s ease-in-out infinite;
}

#btn-send-request.expected-action:not(:disabled) {
    box-shadow: 0 0 0 3px rgba(185, 255, 50, 0.42), 0 0 28px rgba(150, 255, 40, 1), 0 0 44px rgba(150, 255, 40, 0.32);
}

#btn-simulate-failure.expected-action:not(:disabled) {
    box-shadow: 0 0 0 3px rgba(255, 140, 0, 0.38), 0 0 28px rgba(255, 120, 0, 1), 0 0 44px rgba(255, 100, 0, 0.34);
}

@keyframes expectedActionPulse {
    0%, 100% {
        filter: brightness(1);
    }
    50% {
        filter: brightness(1.14);
    }
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.65;
    animation: none;
    box-shadow: none;
    transform: none;
}

/* Mode compact pour écrans 1080p et fenêtres réduites.
   Cette couche ne modifie pas la logique du simulateur : elle compacte uniquement l'interface. */
body:not(.level-has-exercises) #session-score-overlay {
    display: none;
}

body.failure-active #site-signature {
    opacity: 0;
    transform: translateY(8px);
    pointer-events: none;
}

#site-signature {
    transition: opacity 0.35s ease, transform 0.35s ease;
}

@media (max-width: 1920px), (max-height: 1100px) {
    #info-panel,
    #legend-panel,
    #route-panel,
    #routing-table-panel {
        padding: 12px;
        max-width: 320px;
    }

    #info-panel,
    #legend-panel {
        top: 12px;
    }

    #info-panel {
        right: 12px;
    }

    #legend-panel {
        left: 12px;
    }

    #info-panel h2,
    #legend-panel h2,
    #route-panel h2,
    #routing-table-panel h2 {
        font-size: 15px;
    }

    #info-panel p,
    #legend-panel p {
        font-size: 12px;
        line-height: 1.35;
    }

    #route-panel {
        left: 12px;
        bottom: 100px;
        width: 460px;
        max-width: min(460px, calc(100vw - 40px));
        max-height: 30vh;
        overflow-y: auto;
    }

    #routing-table-panel {
        right: 12px;
        bottom: 122px;
        width: 350px;
        max-width: min(350px, calc(100vw - 40px));
        max-height: 48vh;
        overflow-y: auto;
    }

    #failure-banner {
        top: 64px;
        min-width: 0;
        max-width: min(720px, calc(100vw - 360px));
        max-height: 34vh;
        overflow-y: auto;
        padding: 10px 12px;
        font-size: 12.5px;
    }

    .failure-cards {
        gap: 7px;
    }

    .failure-card {
        padding: 8px 10px;
    }

    .failure-card h3 {
        font-size: 13px;
        margin-bottom: 4px;
    }

    .failure-card p {
        font-size: 12px;
        line-height: 1.25;
    }

    #session-score-overlay {
        left: 12px;
        top: 50%;
        transform: translateY(-50%);
        font-size: 12px;
        line-height: 1.4;
    }

    #exercise-progress-grid {
        grid-template-columns: repeat(4, 18px);
        gap: 3px;
        margin-bottom: 8px;
    }

    .exercise-progress-cell {
        width: 18px;
        height: 18px;
        border-radius: 4px;
        font-size: 8.5px;
    }

    #controls {
        bottom: 10px;
        gap: 5px;
        padding: 9px 10px;
        max-width: calc(100vw - 260px);
    }

    #level-select {
        min-height: 32px;
        padding: 0 8px;
        font-size: 12px;
    }

    #level-control-label {
        font-size: 12px;
    }

    button {
        padding: 8px 12px;
        margin: 0 2px;
        font-size: 12px;
    }

    #site-signature {
        right: 12px;
        bottom: 12px;
        padding: 7px 9px;
        gap: 8px;
        font-size: 10px;
    }

    #site-signature img {
        width: 28px;
        height: 28px;
    }

    #site-signature a {
        font-size: 12px;
    }

    .path-list {
        font-size: 12px;
        gap: 4px;
    }

    .path-node {
        padding: 2px 6px;
    }

    .routing-decision-card {
        padding: 10px;
    }

    .routing-field {
        font-size: 12px;
        gap: 8px;
    }

    .routing-decision-sentence,
    .routing-help,
    .path-help {
        font-size: 11.5px;
    }
}

/* Filet de sécurité pour fenêtres plus étroites que le plein écran 1080p. */
@media (max-width: 1400px) {
    #controls {
        max-width: calc(100vw - 24px);
        flex-wrap: wrap;
        justify-content: center;
    }

    #failure-banner {
        width: calc(100vw - 40px);
        max-width: calc(100vw - 40px);
    }

    .failure-cards {
        grid-template-columns: 1fr;
    }

    #route-panel,
    #routing-table-panel {
        bottom: 132px;
        width: 330px;
        max-width: calc(50vw - 24px);
    }

    #site-signature {
        opacity: 0.72;
    }
}

/* Correctifs ergonomiques 1080p : l'interface devient une surimpression légère
   et laisse davantage respirer la scène. */
@media (max-width: 1920px), (max-height: 1100px) {
    #info-panel,
    #legend-panel {
        background: transparent;
        border: none;
        box-shadow: none;
        backdrop-filter: none;
        padding: 0;
        max-width: 300px;
        text-shadow: 0 0 6px #000, 0 0 12px #000;
    }

    #info-panel.collapsed,
    #legend-panel.collapsed {
        padding: 0;
        background: transparent;
    }

    #info-panel .collapsible-content,
    #legend-panel .collapsible-content {
        margin-top: 6px;
    }

    #info-panel p,
    #legend-panel p {
        color: rgba(255, 255, 255, 0.88);
        text-shadow: 0 0 6px #000, 0 0 12px #000;
    }

    .collapsible-header {
        text-shadow: 0 0 6px #000, 0 0 12px #000;
    }

    #controls {
        width: max-content;
        max-width: min(900px, calc(100vw - 40px));
        justify-content: center;
        align-content: center;
    }

    #route-panel {
        bottom: 118px;
    }

    #routing-table-panel {
        bottom: 112px;
        max-height: calc(100vh - 230px);
    }

    #failure-banner {
        width: fit-content;
        min-width: 0;
        max-width: min(880px, calc(100vw - 520px));
        padding: 9px 12px;
    }

    .failure-cards {
        grid-template-columns: repeat(2, minmax(240px, 1fr));
        width: fit-content;
        max-width: 100%;
        margin-left: auto;
        margin-right: auto;
    }
}

@media (max-width: 1400px) {
    #failure-banner {
        max-width: calc(100vw - 40px);
    }

    .failure-cards {
        grid-template-columns: repeat(2, minmax(210px, 1fr));
    }

    #route-panel,
    #routing-table-panel {
        max-width: calc(50vw - 24px);
    }
}

@media (max-width: 900px) {
    .failure-cards {
        grid-template-columns: 1fr;
    }
}

/* Ajustement 1080p : barre de commandes plus ramassée et panneaux moins remontés. */
@media (max-width: 1920px), (max-height: 1100px) {
    #controls {
        width: fit-content;
        max-width: 560px;
        flex-wrap: wrap;
        justify-content: center;
        align-content: center;
        gap: 6px;
        padding: 9px 11px;
    }

    #route-panel {
        bottom: 92px;
    }

    #routing-table-panel {
        bottom: 92px;
        max-height: calc(100vh - 190px);
    }
}

@media (max-width: 1400px) {
    #controls {
        max-width: min(560px, calc(100vw - 24px));
    }

    #route-panel,
    #routing-table-panel {
        bottom: 108px;
    }
}

/* ═══════════════════════════════════════════════════════════════════
   Section isolée : introduction + préchauffage
   (n'interagit avec le simulateur qu'au démarrage via startIntro() ;
   masque l'UI pendant l'intro et nettoie toujours l'état à la fin)
   ═══════════════════════════════════════════════════════════════════ */
#intro-overlay {
    position: fixed;
    inset: 0;
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at center, rgba(0, 0, 0, 0.45), rgba(0, 0, 0, 0.82));
    transition: opacity 0.6s ease;
    pointer-events: auto;
}

#intro-overlay.intro-hidden {
    opacity: 0;
    pointer-events: none;
}

.intro-logo {
    position: relative;
    width: 170px;
    height: 170px;
}

.intro-arc {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 6px solid transparent;
    box-sizing: border-box;
}

.intro-arc-yellow {
    border-top-color: #FFFF00;
    border-right-color: #FFFF00;
    animation: introSpin 2.2s linear infinite;
}

.intro-arc-lime {
    border-top-color: #ABFF00;
    border-left-color: #ABFF00;
    animation: introSpin 3.1s linear infinite reverse;
}

.intro-logo-img {
    position: absolute;
    inset: 45px;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    opacity: 0.92;
}

@keyframes introSpin {
    to { transform: rotate(360deg); }
}

/* Pendant l'introduction, on masque tous les cadres du simulateur. */
body.intro-mode #info-panel,
body.intro-mode #legend-panel,
body.intro-mode #controls,
body.intro-mode #route-panel,
body.intro-mode #routing-table-panel,
body.intro-mode #session-score-overlay,
body.intro-mode #failure-banner,
body.intro-mode #site-signature,
body.intro-mode #level-context-modal,
body.intro-mode #session-report-modal {
    display: none !important;
}

/* ═══════════════════════════════════════════════════════════════════
   Adaptation 1080p (et moins) — réorganisation des cadres du bas
   - "Cheminement des paquets" : bas à gauche
   - "Table de routage" : bas à droite, intégralement visible (sans défilement)
   - Contrôles centrés, calés dans la zone libre entre les deux cadres
   - Signature en fondu quand la table de routage est affichée
   Bloc en fin de fichier : prime par ordre de source, sans toucher aux
   règles existantes (aucun impact sur le JS ni sur les fonctions).
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 1920px), (max-height: 1100px) {
    /* Contrôles : ancrés en bas, légèrement décalés à droite, et bornés à la
       zone libre restante pour ne jamais chevaucher les cadres latéraux
       (tout en restant sur 2 lignes aux largeurs 1080p). */
    #controls {
        bottom: 12px;
        left: 52%;
        max-width: calc(100vw - 740px);
    }

    /* Bandeau de résolution des pannes : en haut de l'interface (trop bas auparavant). */
    #failure-banner {
        top: 12px;
    }

    /* Cheminement des paquets : bas à gauche */
    #route-panel {
        left: 12px;
        right: auto;
        bottom: 12px;
        width: 360px;
        max-width: calc(100vw - 360px);
    }

    /* Table de routage : bas à droite, intégralement visible sans barre de défilement */
    #routing-table-panel {
        right: 12px;
        left: auto;
        bottom: 12px;
        width: 320px;
        max-width: calc(100vw - 360px);
        max-height: none;
        overflow: visible;
    }

    /* La signature cède la place (en fondu) au cadre Table de routage quand il est ouvert */
    #routing-table-panel.visible-panel ~ #site-signature {
        opacity: 0;
        transform: translateY(8px);
        pointer-events: none;
    }
}

/* ═══════════════════════════════════════════════════════════════════
   Section isolée : Niveau 7 Évaluation (modales + bouton)
   ═════════════════════════════════════════════════════════════════ */
#evaluation-start-modal .modal-card button,
#evaluation-end-modal .modal-card button {
    margin-top: 14px;
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    background: linear-gradient(135deg, #ffff00, #bfff3a);
    color: #000;
    font-weight: bold;
    cursor: pointer;
}

#evaluation-start-modal .modal-card button:hover,
#evaluation-end-modal .modal-card button:hover {
    filter: brightness(1.05);
}

#btn-next-evaluation {
    margin-left: 6px;
}

/* ═══════════════════════════════════════════════════════════════════
   Section isolée : verrou gratuit (minuteur entre exercices)
   ═══════════════════════════════════════════════════════════════ */
.cooldown-visual {
    pointer-events: none;
}
.cooldown-card {
    text-align: center;
}
.cooldown-count {
    font-size: 2.6rem;
    font-weight: bold;
    color: #ffff00;
    margin-top: 10px;
}

/* ═══════════════════════════════════════════════════════════════════
   Section isolée : cadre d'achat (mot de passe pour lever le minuteur)
   ═══════════════════════════════════════════════════════════════ */
.license-card { text-align: center; max-width: 460px; }
.license-free { font-weight: bold; color: #ffff00; margin: 6px 0; }
.license-error { color: #ff5555; font-size: 0.9rem; }
.license-buy { font-size: 0.9rem; }
#license-input {
    display: block;
    margin: 10px auto;
    padding: 8px 10px;
    border-radius: 6px;
    border: 1px solid #888;
    font-size: 1rem;
    width: 80%;
    text-align: center;
}
.license-dismiss {
    margin-top: 12px;
    background: transparent;
    color: #88c0ff;
    border: none;
    text-decoration: underline;
    cursor: pointer;
}

/* ═══════════════════════════════════════════════════════════════════
   « Chemin des paquets » intégralement visible — règle UNIVERSELLE
   ────────────────────────────────────────────────────────────────
   Le cadre héritait d'un max-height: 30vh (≈ 324 px en 1080p) avec
   une barre de défilement verticale.

   Pourquoi universel : une première version limitait la règle à une
   plage de pixels « type 1080p »… mais l'agrandissement d'affichage
   Windows (125 %, 150 % — fréquent sur les PC de salle et les écrans
   haute densité) modifie les dimensions vues par le navigateur, et la
   règle ne se déclenchait jamais. L'architecture ci-dessous étant
   sûre à TOUTES les tailles d'écran, aucune condition n'est requise.

   • Les carrés d'exercices et les mentions d'évaluation remontent en
     haut à gauche, juste sous le titre « Repères matériels » (replié
     par défaut). z-index: auto laisse la légende passer devant quand
     on la déplie — proprement et temporairement (elle se replie seule).
   • Le plafond du cadre, calc(100vh - 470px), garantit que son bord
     supérieur ne remonte JAMAIS au-dessus de y = 458 px, quelle que
     soit la hauteur de la fenêtre : aucun chevauchement possible avec
     les carrés (qui s'arrêtent vers y = 275 px). En 1080p, le cadre
     peut presque doubler (jusqu'à ~610 px) et affiche tout son
     contenu, y compris en mode adresses IP : la barre de défilement
     disparaît. Elle ne réapparaît que comme protection sur fenêtres
     exceptionnellement basses.
   Placé en toute fin de feuille de style : prime par ordre de source
   sur les règles antérieures, sur tous les écrans (4K compris, où le
   cadre était déjà libre — aucun changement visible là-bas).
   ═══════════════════════════════════════════════════════════════════ */
#session-score-overlay {
    top: 95px;
    transform: none;
    z-index: auto;
}

#route-panel {
    /* min(max(...)) : max(470px, ...) garantit un cadre au moins doublé même
       quand le zoom Windows (125-150 %) réduit la hauteur CSS de la fenêtre ;
       le plafond calc(100vh - 330px) interdit le chevauchement avec le bloc
       des 20 carrés (mesuré : il finit vers y ≈ 286 px ; le cadre, ancré à
       12 px du bas, voit son bord haut plafonné à y = 318 px, marge ≥ 30 px). */
    max-height: min(max(470px, calc(100vh - 380px)), calc(100vh - 330px));
    overflow-y: auto;
}

/* Bouton d'achat de la popup « minuteur » : la popup passait en
   pointer-events:none pour laisser traverser les clics, MAIS un style en
   ligne « pointer-events:auto » sur le lien le gardait cliquable même
   quand la popup était INVISIBLE (opacity:0) — un piège cliquable au
   centre de l'écran (cliquer un routeur derrière ouvrait une nouvelle
   page → « le simulateur redémarre »).
   Règle : le lien n'est cliquable QUE quand la popup est réellement
   affichée (classe hidden-modal retirée par startCooldownThen). */
#cooldown-paypal-link {
    pointer-events: none;
}

.cooldown-visual:not(.hidden-modal) #cooldown-paypal-link {
    pointer-events: auto;
}
