html, body {
    touch-action: pan-x pan-y;
    -webkit-user-select: none;
    -ms-user-select: none;
    user-select: none;
    overscroll-behavior: none; /* prevent pull-to-refresh */
}

/* Allow selection inside inputs/textareas */
input, textarea {
    -webkit-user-select: text;
    user-select: text;
}

/* Modal styles */
#app-modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    pointer-events: none;
}
#app-modal.hidden { display: none; pointer-events: none; }
#app-modal .modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.6);
}
#app-modal .modal-content {
    position: relative;
    background: #000;
    color: #fff;
    border-radius: 8px;
    padding: 18px;
    max-width: 90%;
    width: 360px;
    pointer-events: auto;
    text-align: center;
    box-shadow: 0 8px 30px rgba(0,0,0,0.5);
}
#app-modal .modal-actions { margin-top: 12px; }
#app-modal button#modal-close {
    background: #2196F3;
    border: none;
    color: white;
    padding: 8px 14px;
    border-radius: 6px;
}

/* Footer */
#app-footer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 6px;
    text-align: center;
    font-size: 0.9em;
    color: #ffffff;
    pointer-events: auto;
    z-index: 2500;
}
#app-footer a {
    color: #ffffff;
    text-decoration: underline;
}

body {
    margin: 0;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}

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

#game-canvas {
    display: block;
}

#ui {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    color: white;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5);
}

#score {
    font-size: 4em;
    margin-top: 20px;
    display: none;
}

#perfect-streak {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -150px);
    font-size: 1.8em; /* reduced size */
    font-weight: bold;
    color: #ffd700;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.7);
    opacity: 0;
    transition: opacity 0.5s, transform 0.5s;
    pointer-events: none;
    z-index: 10;
}

#perfect-streak.visible {
    opacity: 1;
    transform: translate(-50%, -200px);
}

#perfect-streak.hidden {
    display: none;
}

#instructions {
    font-size: 1.5em;
    position: absolute;
    bottom: 20%;
    opacity: 1;
    transition: opacity 0.5s;
}

#instructions.hidden {
    opacity: 0;
}

#game-over {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(0, 0, 0, 0.7);
    padding: 20px 40px;
    border-radius: 10px;
    text-align: center;
    pointer-events: auto;
    max-width: 90%;
}

#game-over.hidden {
    display: none;
}

#game-over h2 {
    margin-top: 0;
}

#replay-controls {
    margin: 15px 0;
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

#replay-controls.hidden {
    display: none;
}

#replay-controls button,
#restart-button,
#submit-score-button {
    font-size: 1.2em;
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    background-color: #4CAF50;
    color: white;
    pointer-events: auto;
}

#submit-score-button {
    background-color: #ff9800;
    margin-bottom: 15px;
}
#submit-score-button:hover {
    background-color: #f57c00;
}

#replay-controls button:hover,
#restart-button:hover {
    background-color: #45a049;
}

#restart-button {
    background-color: #2196F3;
}

#restart-button:hover {
    background-color: #45a049;
}

#replay-button {
    background-color: #2196F3;
}

#replay-button:hover {
    background-color: #0b7dda;
}

#replay-viewer {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(0, 0, 0, 0.9);
    padding: 20px;
    border-radius: 10px;
    text-align: center;
    pointer-events: auto;
    max-width: 90%;
    z-index: 1000;
}

#replay-viewer.hidden {
    display: none;
}

#replay-video {
    width: 100%;
    max-height: 70vh;
    border-radius: 5px;
    margin-bottom: 15px;
}

#replay-controls-bottom {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

#replay-controls-bottom button {
    font-size: 1em;
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    background-color: #4CAF50;
    color: white;
}

#replay-controls-bottom button:hover {
    background-color: #45a049;
}

#close-replay {
    background-color: #f44336;
}

#close-replay:hover {
    background-color: #da190b;
}

#download-replay {
    background-color: #2196F3;
}

#download-replay:hover {
    background-color: #0b7dda;
}

#leaderboard-button.uploading {
    animation: pulse 1.5s ease-in-out infinite;
}

#leaderboard-button.upload-complete {
    animation: bounce 0.5s ease-in-out;
}

#loading-overlay {
    position: fixed;
    inset: 0;
    background: #000;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    pointer-events: all;
}

.loader-content {
    text-align: center;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 6px solid rgba(255,255,255,0.12);
    border-top-color: #ffffff;
    border-radius: 50%;
    margin: 0 auto 12px;
    animation: spin 1s linear infinite;
}

.loading-text {
    font-size: 1.1em;
    letter-spacing: 0.02em;
}

#loading-overlay.hidden {
    display: none;
}

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

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.1);
        opacity: 0.8;
    }
}

@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
}

/* Settings icon button */
#settings-button {
    position: fixed;
    bottom: 40px; /* sits just above footer */
    right: 12px;
    width: 44px;
    height: 44px;
    border-radius: 10px;
    border: none;
    background: #111;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 18px rgba(0,0,0,0.45);
    cursor: pointer;
    z-index: 2600;
    pointer-events: auto;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23ffffff"><path d="M19.14,12.94c0.04-0.31,0.06-0.63,0.06-0.94s-0.02-0.63-0.06-0.94l2.03-1.58c0.18-0.14,0.23-0.39,0.12-0.58l-1.92-3.32c-0.11-0.19-0.34-0.26-0.54-0.19l-2.39,0.96c-0.5-0.38-1.04-0.7-1.64-0.94L14.5,2.81c-0.03-0.21-0.21-0.37-0.42-0.37h-3.16c-0.21,0-0.39,0.16-0.42,0.37L9.01,5.36c-0.6,0.24-1.14,0.56-1.64,0.94L5,5.34c-0.2-0.08-0.43,0-0.54,0.19L2.54,8.85c-0.11,0.19-0.06,0.44,0.12,0.58l2.03,1.58C4.65,11.37,4.63,11.69,4.63,12s0.02,0.63,0.06,0.94L2.66,14.52c-0.18,0.14-0.23,0.39-0.12,0.58l1.92,3.32c0.11,0.19,0.34,0.26,0.54,0.19l2.39-0.96c0.5,0.38,1.04,0.7,1.64,0.94l0.44,2.55c0.03,0.21,0.21,0.37,0.42,0.37h3.16c0.21,0,0.39-0.16,0.42-0.37l0.44-2.55c0.6-0.24,1.14-0.56,1.64-0.94l2.39,0.96c0.2,0.08,0.43,0,0.54-0.19l1.92-3.32c0.11-0.19,0.06-0.44-0.12-0.58L19.14,12.94z M12,15.5c-1.93,0-3.5-1.57-3.5-3.5S10.07,8.5,12,8.5s3.5,1.57,3.5,3.5S13.93,15.5,12,15.5z"/></svg>');
    background-repeat: no-repeat;
    background-position: center;
    background-size: 60%;
}

#settings-button:active { transform: translateY(1px); }

/* Floating restart button (always visible) */
#restart-fixed {
    position: fixed;
    bottom: 40px;
    left: 12px; /* opposite side to settings button */
    width: 48px;
    height: 48px;
    border-radius: 12px;
    border: none;
    background: #ff5252;
    color: white;
    display: none; /* hidden by default; shown only when viewing tower */
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    box-shadow: 0 8px 24px rgba(0,0,0,0.45);
    cursor: pointer;
    z-index: 2600;
    pointer-events: auto;
}
#restart-fixed:hover { transform: translateY(-2px); }
#restart-fixed:active { transform: translateY(1px); }

/* Save image floating button (above restart) */
#save-image-fixed {
    position: fixed;
    bottom: 100px;
    left: 12px;
    width: 48px;
    height: 48px;
    border-radius: 12px;
    border: none;
    background: #4CAF50;
    color: white;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    box-shadow: 0 8px 24px rgba(0,0,0,0.45);
    cursor: pointer;
    z-index: 2600;
    pointer-events: auto;
}
#save-image-fixed:hover { transform: translateY(-2px); }
#save-image-fixed:active { transform: translateY(1px); }

#tower-viewer {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.95);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    pointer-events: auto;
    flex-direction: column;
}
#tower-viewer.hidden { display: none; }
#tower-viewer #tower-controls {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 3200;
    display: flex;
    gap: 8px;
    align-items: center;
}
#tower-viewer #tower-controls button {
    padding: 10px 14px;
    background: #2196F3;
    color: #fff;
    border: none;
    border-radius: 10px;
    box-shadow: 0 6px 18px rgba(0,0,0,0.45);
    font-size: 1rem;
}
#tower-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* Make sure the inline music toggle has consistent center alignment and spacing in case CSS is preferred */
#music-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    cursor: pointer;
    padding: 10px 8px;
    border-radius: 8px;
}
#music-button {
    min-width: 72px;
    padding: 8px 12px;
    border-radius: 10px;
    border: none;
    color: #fff;
}