body,
html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    touch-action: none;
    /* Prevent zoom/scroll on mobile */
    background: #88b1cc;
    /* Solid Color Performance Fix */
}

/* Loading Screen */
#loading-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #111;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: white;
}

.loader {
    border: 5px solid #333;
    border-top: 5px solid #ff4444;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}


#main-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100svh;
    padding-top: calc(env(safe-area-inset-top));
    padding-bottom: calc(env(safe-area-inset-bottom));
    box-sizing: border-box;
    overflow: hidden;
}

#game-container {
    position: relative;
    width: 380px !important;
    height: 680px !important;
    flex-shrink: 0;
    /* Prevents flexbox from squeezing its physical bounds */
    transform-origin: center center;
    display: flex;
    justify-content: center;
    align-items: center;
}

canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
    object-fit: contain;
}

#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

#score-board {
    position: absolute;
    top: 10px;
    left: 12px;
    color: white;
    font-size: 18px;
    font-weight: bold;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.6);
    z-index: 5;
}

.top-controls {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 8px;
    z-index: 5;
}

#retry-btn-top,
#settings-btn {
    width: 40px;
    height: 40px;
    background: transparent;
    border: 2px solid white;
    border-radius: 50%;
    color: white;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s;
    backdrop-filter: blur(2px);
    pointer-events: auto;
    /* Ensure buttons are clickable */
}

#retry-btn-top:hover,
#settings-btn:hover {
    background: white;
    color: #333;
    transform: rotate(90deg);
}

#settings-btn {
    font-size: 18px;
}

/* Settings Modal */
#settings-modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(136, 177, 204, 0.5);
    z-index: 20;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(10px);
}

.modal-content {
    background: rgba(255, 255, 255, 0.9);
    padding: 20px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.5);
    text-align: center;
    color: #334e68;
    width: 80%;
    max-width: 280px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1);
}

.modal-content h2 {
    margin-top: 0;
    margin-bottom: 15px;
    font-size: 20px;
}

.setting-item {
    margin: 15px 0;
}

.setting-item label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: bold;
}

.toggle-setting {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 10px;
}

.toggle-setting label {
    margin-bottom: 0;
}

.toggle-setting input[type="checkbox"] {
    -webkit-appearance: none;
    appearance: none;
    width: 40px;
    height: 20px;
    background: rgba(136, 177, 204, 0.2);
    border-radius: 20px;
    position: relative;
    cursor: pointer;
    transition: background 0.3s;
    outline: none;
}

.toggle-setting input[type="checkbox"]::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: transform 0.3s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.toggle-setting input[type="checkbox"]:checked {
    background: #88b1cc;
}

.toggle-setting input[type="checkbox"]:checked::before {
    transform: translateX(20px);
}

.setting-item input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 8px;
    background: rgba(136, 177, 204, 0.2);
    border-radius: 10px;
    outline: none;
    cursor: pointer;
}

.setting-item input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: #88b1cc;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    border: 2px solid white;
}

.setting-item input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: #88b1cc;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
    border: 2px solid white;
}

#close-settings {
    margin-top: 15px;
    padding: 8px 25px;
    background: #88b1cc;
    color: white;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    font-weight: bold;
    font-size: 14px;
    box-shadow: 0 4px 10px rgba(136, 177, 204, 0.3);
    transition: all 0.2s;
}

#close-settings:hover {
    background: #739ab4;
    transform: scale(1.05);
}

/* Removed GO Button styling or hidden it */
#go-btn {
    display: none !important;
}

/* Utility to hide elements forcefully */
.hidden {
    display: none !important;
}

/* Header (Game Over + Score) */
#game-header {
    position: absolute;
    top: 20px;
    left: 0;
    width: 100%;
    text-align: center;
    animation: fadeIn 0.5s;
    z-index: 15;
    pointer-events: none;
}

#game-header h1 {
    font-size: 42px;
    margin: 0 0 5px 0;
    color: #ff4444;
    -webkit-text-stroke: 2px white;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

#game-header p {
    font-size: 28px;
    margin: 0;
    font-weight: bold;
    color: white;
    text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.8);
}

/* Footer (Buttons) */
#game-footer {
    position: absolute;
    bottom: 20px;
    top: auto;
    left: 0;
    width: 100%;
    animation: fadeIn 0.5s;
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
    z-index: 15;
}

#game-footer button {
    padding: 8px 16px;
    font-size: 15px;
    cursor: pointer;
    border-radius: 20px;
    border: 2px solid white;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    font-weight: bold;
    backdrop-filter: blur(5px);
    transition: all 0.2s;
    text-shadow: 1px 1px 2px black;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

#game-footer button:hover {
    background: white;
    color: #333;
    transform: scale(1.05);
    text-shadow: none;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}


/* Next Balls Preview UI */
#next-preview-container {
    position: absolute;
    top: 55px;
    right: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    color: white;
    font-size: 11px;
    font-weight: bold;
    text-shadow: 1px 1px 2px black;
    z-index: 5;
    background: rgba(0, 0, 0, 0.4);
    padding: 8px 10px;
    border-radius: 12px;
    backdrop-filter: blur(3px);
}

.preview-slot {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background-size: cover;
    background-position: center;
    border: 2px solid rgba(255, 255, 255, 0.5);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

.preview-arrow {
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
}

/* Support Links (Game Over Screen) */
.support-links-mini {
    width: 100%;
    margin-top: 15px;
    display: flex;
    justify-content: center;
    gap: 20px;
}

.support-links-mini a {
    color: rgba(255, 255, 255, 0.6);
    font-size: 12px;
    text-decoration: underline;
    transition: color 0.2s;
}

.support-links-mini a:hover {
    color: white;
}

/* Settings Support Section */
.support-section {
    margin-top: 15px;
    padding-top: 10px;
    border-top: 1px solid rgba(136, 177, 204, 0.2);
}

.support-section p {
    font-size: 12px;
    color: #627d98;
    margin-bottom: 8px;
}

.support-btns {
    display: flex;
    flex-direction: row;
    gap: 8px;
}

.support-btn {
    flex: 1;
    background: rgba(136, 177, 204, 0.1);
    color: #334e68;
    padding: 8px;
    border-radius: 10px;
    text-decoration: none;
    font-size: 13px;
    transition: all 0.2s;
    border: 1px solid rgba(136, 177, 204, 0.2);
}

.support-btn:hover {
    background: rgba(136, 177, 204, 0.2);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

/* In-Game Modals (CM/ED) */
.game-modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 100;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(3px);
    animation: backdropFadeIn 0.3s ease-out;
}

@keyframes backdropFadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal-box {
    aspect-ratio: 30 / 36;
    width: 90%;
    max-width: 300px;
    height: auto;
    max-height: 80svh;
    background-size: cover;
    background-position: center;
    border-radius: 12px;
    position: relative;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    border: 3px solid #fff;
    overflow: hidden;
    animation: modalPopIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.ed-box {
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    background-color: rgb(255, 188, 180);
    /* Pinkish background to fill gaps */
}

@keyframes modalPopIn {
    0% {
        transform: scale(0);
        opacity: 0;
    }

    70% {
        transform: scale(1.2);
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.close-modal-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    background: rgba(0, 0, 0, 0.5);
    /* Semi-transparent black for visibility */
    color: #fff;
    border: 1px solid #fff;
    border-radius: 50%;
    cursor: pointer;
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 14px;
    z-index: 10;
    transition: background 0.2s;
}

.close-modal-btn:hover {
    background: rgba(0, 0, 0, 0.8);
}

/* Specific style for ED Window where transparency looks good */
.ed-box .close-modal-btn {
    background: transparent;
}

.ed-box .close-modal-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.cm-content {
    position: absolute;
    bottom: 20px;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: center;
}

.blue-capsule-btn {
    display: inline-block;
    background: #007bff;
    color: white;
    padding: 8px 30px;
    border-radius: 50px;
    text-decoration: none;
    font-weight: bold;
    font-size: 16px;
    box-shadow: 0 4px 10px rgba(0, 123, 255, 0.4);
    transition: transform 0.2s;
}

.blue-capsule-btn:hover {
    transform: scale(1.05);
}