@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700&family=Outfit:wght@400;700&display=swap');

/* Trigger Button & SVG Invader Style - positioned absolute to box */
#interim-contract-box .context-invaders-trigger {
    position: absolute;
    bottom: 1.25rem;
    right: 1.25rem;
    z-index: 30;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0.4rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    color: rgba(255, 255, 255, 0.2);
    opacity: 0.6;
    animation: invader-throb 4s ease-in-out infinite;
}

#interim-contract-box .context-invaders-trigger:hover {
    transform: scale(1.1);
    filter: drop-shadow(0 0 8px rgba(34, 197, 94, 0.8)) !important;
    color: #22c55e !important;
    opacity: 1 !important;
}

@keyframes invader-throb {
    0%, 100% {
        color: rgba(255, 255, 255, 0.2);
        opacity: 0.6;
        filter: drop-shadow(0 0 0 rgba(34, 197, 94, 0));
    }
    50% {
        color: #22c55e;
        opacity: 1;
        filter: drop-shadow(0 0 8px rgba(34, 197, 94, 0.8));
    }
}

#interim-contract-box .context-invaders-trigger svg {
    width: 16px;
    height: auto;
    display: block;
}

/* Dialog Overlay Style - positioned fixed and centered safely in the browser viewport without negative coordinate clipping */
.context-invaders-dialog {
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(24, 24, 27, 0.98);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    border-radius: 16px;
    padding: 1.25rem;
    width: 95vw;
    max-width: 860px;
    height: auto;
    max-height: min(94dvh, 94svh, 94vh, 740px);
    color: #FFFFFF;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.7),
        0 0 40px rgba(59, 131, 246, 0.15);
    font-family: 'Outfit', -apple-system, sans-serif;
    overflow: hidden;
    position: fixed !important;
    inset: 0 !important;
    margin: auto !important;
    box-sizing: border-box !important;
    z-index: 10000;
    opacity: 0;
    pointer-events: none;
    transform: scale(0.96);
    transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1),
        transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    display: none;
    flex-direction: column;
}

.context-invaders-dialog[open] {
    opacity: 1;
    pointer-events: auto;
    transform: scale(1) !important;
    display: flex !important;
}

/* Global Backdrop Lightbox overlay style */
.context-invaders-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(9, 9, 11, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

.context-invaders-backdrop.ci-active {
    opacity: 1;
    pointer-events: auto;
}

.ci-dialog-container {
    position: relative;
    width: 100%;
    height: 100%;
    max-height: 100%;
    min-height: 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-sizing: border-box;
}

/* General Close Button (for registration screen) */
.ci-close-btn {
    position: absolute;
    top: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.7);
    border-radius: 8px;
    width: 34px;
    height: 34px;
    font-size: 1.35rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 100;
    line-height: 1;
    padding: 0;
    touch-action: manipulation;
}

.ci-close-btn:hover {
    background: rgba(225, 70, 70, 0.25);
    border-color: #E14646;
    color: #E14646;
    transform: scale(1.05);
    box-shadow: 0 0 12px rgba(225, 70, 70, 0.4);
}

.ci-close-btn:active {
    transform: scale(0.92);
}

/* Screen Switcher */
.ci-screen {
    display: none;
    width: 100%;
    height: 100%;
    max-height: 100%;
    min-height: 0;
    flex-direction: column;
    align-items: center;
    box-sizing: border-box;
}

.ci-screen.ci-active {
    display: flex;
}

/* Registration screen can scroll if viewport height is compact */
#ci-screen-register {
    justify-content: center;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 0.5rem 0;
    position: relative;
}

/* Game screen layout stays strictly within dialog bounds without scrolling */
#ci-screen-game {
    justify-content: space-between;
    align-items: center;
    overflow: hidden;
    gap: 0.35rem;
}

/* Typography */
.ci-title {
    font-family: 'Orbitron', monospace;
    font-weight: 700;
    font-size: 2.2rem;
    letter-spacing: 3px;
    background: linear-gradient(135deg, #FA7315 0%, #E14646 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.25rem;
    text-align: center;
    filter: drop-shadow(0 0 15px rgba(225, 70, 70, 0.3));
}

.ci-subtitle {
    color: rgba(255, 255, 255, 0.6);
    text-align: center;
    font-size: 0.85rem;
    margin-bottom: 1.25rem;
    max-width: 460px;
}

/* Registration Form Style */
#ci-form-register {
    width: 100%;
    max-width: 420px;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.ci-input-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    position: relative;
    min-width: 0;
    width: 100%;
    box-sizing: border-box;
}

.ci-input-group label {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255, 255, 255, 0.8);
}

.ci-input-group input[type="text"],
.ci-input-group input[type="email"] {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 0.7rem 0.9rem;
    color: #FFFFFF;
    font-family: inherit;
    font-size: 0.95rem;
    outline: none;
    transition: all 0.3s ease;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

.ci-input-group input:focus {
    border-color: #3B83F6;
    background: rgba(59, 131, 246, 0.03);
    box-shadow: 0 0 12px rgba(59, 131, 246, 0.3);
}

.ci-row-cols {
    display: flex;
    gap: 1rem;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

.ci-col-initials {
    width: 100px;
}

.ci-col-initials input {
    text-align: center;
    font-family: 'Orbitron', monospace;
    font-weight: bold;
    letter-spacing: 2px;
}

.ci-col-email {
    flex-grow: 1;
}

/* Checkbox Style */
.ci-checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin-top: 0.5rem;
}

.ci-checkbox-label {
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    user-select: none;
    position: relative;
}

.ci-checkbox-label input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    height: 0;
    width: 0;
}

.ci-checkbox-custom {
    height: 20px;
    width: 20px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 5px;
    margin-right: 12px;
    display: inline-block;
    position: relative;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.ci-checkbox-label:hover input~.ci-checkbox-custom {
    border-color: rgba(255, 255, 255, 0.4);
    background: rgba(255, 255, 255, 0.08);
}

.ci-checkbox-label input:checked~.ci-checkbox-custom {
    background: #3B83F6;
    border-color: #3B83F6;
    box-shadow: 0 0 8px rgba(59, 131, 246, 0.4);
}

.ci-checkbox-custom::after {
    content: "";
    position: absolute;
    display: none;
    left: 6px;
    top: 2px;
    width: 5px;
    height: 10px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.ci-checkbox-label input:checked~.ci-checkbox-custom::after {
    display: block;
}

.ci-checkbox-text {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.7);
}

.ci-checkbox-text a {
    color: #3B83F6;
    text-decoration: none;
    transition: color 0.2s;
}

.ci-checkbox-text a:hover {
    color: #22C55F;
    text-decoration: underline;
}

/* Error messages */
.ci-error-msg {
    color: #E14646;
    font-size: 0.75rem;
    height: 14px;
    margin-top: 2px;
    display: block;
    font-weight: 700;
}

/* Submit Button */
.ci-submit-btn {
    background: linear-gradient(135deg, #FA7315 0%, #E14646 100%);
    border: none;
    color: white;
    padding: 0.8rem;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    font-family: 'Orbitron', sans-serif;
    letter-spacing: 2px;
    margin-top: 0.5rem;
    box-shadow: 0 4px 15px rgba(225, 70, 70, 0.3);
}

.ci-submit-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(225, 70, 70, 0.5), 0 0 10px rgba(250, 115, 21, 0.4);
}

.ci-submit-btn:active {
    transform: translateY(0);
}

/* Game Screen HUD */
.ci-game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 800px;
    padding: 0 0.25rem 0.25rem;
    box-sizing: border-box;
    flex-shrink: 0;
    gap: 0.5rem;
}

.ci-hud-item {
    font-family: 'Orbitron', monospace;
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.85);
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.ci-hud-item span {
    font-weight: bold;
    color: #FFFFFF;
}

#ci-hud-lives {
    color: #E14646;
    letter-spacing: 2px;
    font-size: 0.95rem;
}

.ci-hud-actions {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-shrink: 0;
}

/* Action Buttons (Close & Mute in HUD) */
.ci-mute-btn,
.ci-hud-actions .ci-close-btn {
    position: static !important;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.8);
    border-radius: 8px;
    width: 32px;
    height: 32px;
    font-size: 0.95rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    touch-action: manipulation;
    padding: 0;
    line-height: 1;
    flex-shrink: 0;
}

.ci-mute-btn:hover,
.ci-hud-actions .ci-close-btn:hover {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.4);
    color: #FFFFFF;
    transform: scale(1.05);
}

.ci-hud-actions .ci-close-btn:hover {
    background: rgba(225, 70, 70, 0.25);
    border-color: #E14646;
    color: #E14646;
}

.ci-mute-btn:active,
.ci-hud-actions .ci-close-btn:active {
    transform: scale(0.92);
}

/* Canvas Container */
.ci-canvas-container {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    min-width: 0;
    width: 100%;
    max-width: 800px;
    height: auto;
    aspect-ratio: 4 / 3;
    background: #18181B;
    border: 2px solid #3B83F6;
    border-radius: 12px;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.9), 0 0 25px rgba(59, 131, 246, 0.25);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    margin: 0 auto;
    touch-action: none;
}

.ci-canvas-container canvas {
    max-width: 100%;
    max-height: 100%;
    width: 100%;
    height: 100%;
    aspect-ratio: 4 / 3;
    object-fit: contain;
    display: block;
    image-rendering: pixelated;
    touch-action: none;
}

/* Overlays (Game Over / Leaderboard) */
.ci-canvas-overlay-hidden {
    display: none;
}

.ci-canvas-overlay-visible {
    position: absolute;
    inset: 0;
    background: rgba(24, 24, 27, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    box-sizing: border-box;
    z-index: 10;
    font-family: 'Orbitron', monospace;
    animation: fadeIn 0.3s ease forwards;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

#ci-overlay-title {
    font-family: 'Orbitron', monospace;
    font-size: 1.75rem;
    color: #E14646;
    letter-spacing: 3px;
    margin-top: 0;
    margin-bottom: 0.5rem;
    text-shadow: 0 0 10px rgba(225, 70, 70, 0.4);
}

#ci-overlay-content {
    width: 100%;
    max-width: 540px;
    margin-bottom: 1rem;
    overflow-y: auto;
    max-height: 200px;
}

/* Scoreboard Table */
.ci-leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    color: #FFFFFF;
    font-size: 0.9rem;
}

.ci-leaderboard-table th {
    border-bottom: 2px solid rgba(255, 255, 255, 0.1);
    padding: 0.5rem;
    text-align: left;
    color: #FA7315;
    font-size: 0.85rem;
}

.ci-leaderboard-table td {
    padding: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.ci-leaderboard-table tr:nth-child(1) td {
    color: #FA7315;
    font-weight: bold;
    text-shadow: 0 0 5px rgba(250, 115, 21, 0.3);
}

.ci-leaderboard-table tr:nth-child(2) td,
.ci-leaderboard-table tr:nth-child(3) td {
    color: #22C55F;
    font-weight: bold;
}

.ci-leaderboard-table tr td:nth-child(3) {
    font-weight: bold;
}

.ci-leaderboard-table tr:hover td {
    background: rgba(255, 255, 255, 0.02);
}

.ci-action-btn {
    background: transparent;
    border: 2px solid #22C55F;
    color: #22C55F;
    padding: 0.75rem 2rem;
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    letter-spacing: 2px;
}

.ci-action-btn:hover {
    background: #22C55F;
    color: #18181B;
    box-shadow: 0 0 15px rgba(34, 197, 95, 0.5);
    transform: scale(1.05);
}

/* Virtual D-pad / Buttons for Touch Devices */
.ci-touch-controls {
    display: none;
    width: 100%;
    max-width: 800px;
    justify-content: space-between;
    align-items: center;
    padding-top: 0.35rem;
    gap: 0.75rem;
    box-sizing: border-box;
    flex-shrink: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    touch-action: none;
}

.ci-touch-dpad {
    display: flex;
    gap: 0.6rem;
    align-items: center;
}

.ci-touch-btn {
    background: rgba(255, 255, 255, 0.08);
    border: 2px solid rgba(59, 131, 246, 0.4);
    color: #FFFFFF;
    font-size: 1.5rem;
    width: 58px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    touch-action: manipulation;
    transition: all 0.1s ease;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    flex-shrink: 0;
}

.ci-touch-btn:active {
    background: rgba(59, 131, 246, 0.35);
    border-color: #3B83F6;
    box-shadow: 0 0 15px rgba(59, 131, 246, 0.6);
    transform: scale(0.92);
}

.ci-fire-btn {
    background: radial-gradient(circle, #ff4d4d 0%, #cc0000 100%);
    border: 2px solid rgba(225, 70, 70, 0.6);
    color: #FFFFFF;
    width: 80px;
    height: 52px;
    font-weight: bold;
    font-size: 0.95rem;
    font-family: 'Orbitron', sans-serif;
    letter-spacing: 1px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(225, 70, 70, 0.4);
}

.ci-fire-btn:active {
    background: radial-gradient(circle, #ff1a1a 0%, #990000 100%);
    border-color: #E14646;
    box-shadow: 0 0 20px rgba(225, 70, 70, 0.8);
    transform: scale(0.92);
}

/* Display Touch Controls and scale gracefully on touch devices or compact screens */
@media (max-width: 768px),
(pointer: coarse) {
    body.ci-game-active-body {
        overflow: hidden !important;
        touch-action: none !important;
        overscroll-behavior: none !important;
    }

    .ci-touch-controls {
        display: flex !important;
    }

    .context-invaders-dialog {
        padding: max(0.5rem, env(safe-area-inset-top)) max(0.6rem, env(safe-area-inset-right)) max(0.5rem, env(safe-area-inset-bottom)) max(0.6rem, env(safe-area-inset-left)) !important;
        max-width: min(96vw, 860px) !important;
        width: 95vw !important;
        height: auto !important;
        max-height: min(94dvh, 94svh, 94vh) !important;
        position: fixed !important;
        inset: 0 !important;
        margin: auto !important;
        transform: scale(0.96);
        box-sizing: border-box !important;
        overflow: hidden !important;
    }

    .context-invaders-dialog[open] {
        transform: scale(1) !important;
    }

    .ci-dialog-container {
        width: 100% !important;
        max-width: 100% !important;
        height: 100% !important;
        max-height: 100% !important;
        min-height: 0 !important;
        box-sizing: border-box !important;
    }

    .ci-screen {
        width: 100% !important;
        max-width: 100% !important;
        height: 100% !important;
        max-height: 100% !important;
        min-height: 0 !important;
        box-sizing: border-box !important;
    }

    #ci-screen-register {
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        justify-content: flex-start !important;
        padding-top: 0.25rem !important;
    }

    #ci-screen-game {
        overflow: hidden !important;
        gap: 0.25rem !important;
    }

    #ci-form-register {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        gap: 0.35rem !important;
    }

    .ci-row-cols {
        flex-wrap: wrap !important;
        gap: 0.35rem !important;
    }

    .ci-col-initials {
        width: 85px !important;
    }

    .ci-col-email {
        flex: 1 1 150px !important;
        min-width: 0 !important;
    }

    .ci-title {
        font-size: 1.35rem !important;
        letter-spacing: 2px !important;
        margin-bottom: 0.15rem !important;
    }

    .ci-subtitle {
        font-size: 0.75rem !important;
        margin-bottom: 0.4rem !important;
    }

    .ci-input-group label {
        font-size: 0.7rem !important;
    }

    /* 16px font-size to prevent iOS Safari auto-zoom on input focus */
    .ci-input-group input[type="text"],
    .ci-input-group input[type="email"] {
        padding: 0.5rem 0.65rem !important;
        font-size: 16px !important;
        width: 100% !important;
        min-width: 0 !important;
        box-sizing: border-box !important;
    }

    .ci-submit-btn {
        padding: 0.65rem !important;
        font-size: 0.85rem !important;
        margin-top: 0.2rem !important;
    }

    .ci-game-header {
        padding: 0 0.1rem 0.15rem !important;
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        width: 100% !important;
        box-sizing: border-box !important;
        gap: 0.25rem !important;
        flex-shrink: 0 !important;
    }

    .ci-hud-item {
        font-size: 0.72rem !important;
        letter-spacing: 0.3px !important;
    }

    #ci-hud-lives {
        font-size: 0.8rem !important;
        letter-spacing: 1px !important;
    }

    .ci-hud-actions {
        gap: 0.3rem !important;
    }

    .ci-mute-btn,
    .ci-hud-actions .ci-close-btn,
    .ci-close-btn {
        width: 28px !important;
        height: 28px !important;
        font-size: 0.9rem !important;
        border-radius: 6px !important;
    }

    .ci-canvas-container {
        border-width: 2px !important;
        aspect-ratio: 4 / 3 !important;
        width: 100% !important;
        max-width: 100% !important;
        flex: 1 1 auto !important;
        min-height: 0 !important;
        box-sizing: border-box !important;
    }

    .ci-canvas-container canvas {
        max-width: 100% !important;
        max-height: 100% !important;
        width: 100% !important;
        height: 100% !important;
        aspect-ratio: 4 / 3 !important;
        object-fit: contain !important;
    }

    .ci-touch-controls {
        display: flex !important;
        padding-top: 0.25rem !important;
        gap: 0.5rem !important;
        justify-content: space-between !important;
        align-items: center !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        flex-shrink: 0 !important;
    }

    .ci-touch-dpad {
        gap: 0.4rem !important;
    }

    .ci-touch-btn {
        width: 52px !important;
        height: 48px !important;
        font-size: 1.3rem !important;
        border-radius: 10px !important;
    }

    .ci-fire-btn {
        width: 72px !important;
        height: 48px !important;
        font-size: 0.85rem !important;
        border-radius: 10px !important;
    }

    #ci-overlay-title {
        font-size: 1.2rem !important;
        margin-bottom: 0.25rem !important;
    }

    #ci-overlay-content {
        max-height: 140px !important;
        margin-bottom: 0.5rem !important;
    }

    .ci-leaderboard-table th {
        padding: 0.2rem !important;
        font-size: 0.7rem !important;
    }

    .ci-leaderboard-table td {
        padding: 0.2rem !important;
        font-size: 0.7rem !important;
    }

    .ci-action-btn {
        padding: 0.4rem 1.1rem !important;
        font-size: 0.8rem !important;
    }
}

/* Landscape Mode Optimization on Compact Screens */
@media (orientation: landscape) and (max-height: 500px) {
    .context-invaders-dialog {
        padding: max(0.35rem, env(safe-area-inset-top)) max(0.5rem, env(safe-area-inset-right)) max(0.35rem, env(safe-area-inset-bottom)) max(0.5rem, env(safe-area-inset-left)) !important;
        max-height: 96dvh !important;
    }

    #ci-screen-game {
        gap: 0.15rem !important;
    }

    .ci-game-header {
        padding: 0 0.1rem 0.1rem !important;
    }

    .ci-touch-controls {
        padding-top: 0.15rem !important;
    }

    .ci-touch-btn {
        height: 40px !important;
        width: 48px !important;
        font-size: 1.1rem !important;
    }

    .ci-fire-btn {
        height: 40px !important;
        width: 65px !important;
        font-size: 0.8rem !important;
    }
}

@media (max-width: 380px) {
    .context-invaders-dialog {
        padding: 0.4rem !important;
    }

    .ci-col-initials {
        width: 100% !important;
    }

    .ci-touch-btn {
        width: 44px !important;
        height: 44px !important;
        font-size: 1.15rem !important;
    }

    .ci-fire-btn {
        width: 58px !important;
        height: 44px !important;
        font-size: 0.75rem !important;
    }
}