* { box-sizing: border-box; }

:root {
    --bg: #000;
    --fg: #fff;
    --modal-bg: #111;
    --modal-fg: #fff;
    --toggle-bg: rgba(255, 255, 255, 0.12);
    --toggle-border: rgba(255, 255, 255, 0.25);
}

body.light {
    --bg: #4690d8;
    --fg: #111;
    --modal-bg: #fff;
    --modal-fg: #111;
    --toggle-bg: rgba(0, 0, 0, 0.08);
    --toggle-border: rgba(0, 0, 0, 0.2);
}

body.light {
    background-image:
        url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='820' height='560' viewBox='0 0 820 560'%3E%3Cg fill='%23ffffff'%3E%3Cg opacity='0.95'%3E%3Cellipse cx='110' cy='90' rx='62' ry='22'/%3E%3Cellipse cx='150' cy='72' rx='42' ry='26'/%3E%3Cellipse cx='80' cy='74' rx='34' ry='20'/%3E%3Cellipse cx='185' cy='84' rx='30' ry='18'/%3E%3C/g%3E%3Cg opacity='0.85'%3E%3Cellipse cx='560' cy='210' rx='80' ry='26'/%3E%3Cellipse cx='610' cy='188' rx='52' ry='30'/%3E%3Cellipse cx='520' cy='190' rx='42' ry='24'/%3E%3Cellipse cx='655' cy='200' rx='28' ry='17'/%3E%3C/g%3E%3Cg opacity='0.9'%3E%3Cellipse cx='300' cy='430' rx='58' ry='20'/%3E%3Cellipse cx='335' cy='414' rx='38' ry='23'/%3E%3Cellipse cx='268' cy='418' rx='30' ry='17'/%3E%3C/g%3E%3Cg opacity='0.75'%3E%3Cellipse cx='730' cy='460' rx='44' ry='15'/%3E%3Cellipse cx='755' cy='450' rx='28' ry='17'/%3E%3Cellipse cx='708' cy='451' rx='22' ry='13'/%3E%3C/g%3E%3Cg opacity='0.8'%3E%3Cellipse cx='40' cy='300' rx='34' ry='12'/%3E%3Cellipse cx='62' cy='292' rx='24' ry='14'/%3E%3Cellipse cx='22' cy='293' rx='18' ry='10'/%3E%3C/g%3E%3Cg opacity='0.7'%3E%3Cellipse cx='420' cy='30' rx='30' ry='10'/%3E%3Cellipse cx='440' cy='22' rx='18' ry='12'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E"),
        linear-gradient(180deg, #3d8fd4 0%, #9ed1f5 100%);
    background-repeat: repeat, no-repeat;
    background-size: 820px 560px, 100% 100%;
    background-attachment: fixed, fixed;
}

body.light #gameContainer,
body.light #gameCanvas {
    background-color: transparent;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: var(--bg);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--fg);
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
    touch-action: none;
}

#gameContainer {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    /* Honor iOS safe areas so we never get unexpected gutters */
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#gameCanvas {
    display: block;
    background-color: var(--bg);
    /* No border — width/height set via JS */
    image-rendering: -webkit-optimize-contrast;
}

#themeToggle {
    position: absolute;
    top: calc(env(safe-area-inset-top) + 12px);
    right: calc(env(safe-area-inset-right) + 12px);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--toggle-border);
    background-color: var(--toggle-bg);
    color: var(--fg);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-appearance: none;
    appearance: none;
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    padding: 0;
}

#themeToggle:active { transform: scale(0.92); }

#welcomeScreen {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    object-fit: contain;
    cursor: pointer;
    z-index: 10;
    display: none;
    pointer-events: auto;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 100;
    background-color: rgba(0, 0, 0, 0.7);
    align-items: center;
    justify-content: center;
    padding: 24px;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

.modal.show { display: flex; }

.modal-content {
    background-color: var(--modal-bg);
    color: var(--modal-fg);
    padding: 28px 24px;
    border-radius: 16px;
    max-width: 360px;
    width: 100%;
    text-align: center;
    position: relative;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
}

.close {
    color: #888;
    position: absolute;
    top: 10px;
    right: 16px;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
}

.close:hover,
.close:focus {
    color: #fff;
    text-decoration: none;
}

#gameOverText {
    font-size: 18px;
    margin: 8px 0 24px;
    line-height: 1.4;
}

#playAgainBtn,
.contact-btn {
    display: inline-block;
    padding: 14px 26px;
    margin: 6px;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    color: #fff;
    font-weight: 700;
    font-size: 16px;
    text-decoration: none;
    -webkit-appearance: none;
    appearance: none;
}

#playAgainBtn {
    background-color: #e53935;
    padding: 16px 32px;
    font-size: 18px;
}

#playAgainBtn:active { background-color: #c62828; }

.contact-btn {
    background-color: #008CBA;
}

.contact-btn:active { background-color: #006e94; }
