body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #000;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: #fff;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none; /* Prevents browser zoom/gestures on mobile */
    overscroll-behavior-y: contain; /* Prevents pull to refresh */
}

input, textarea, [contenteditable] {
    user-select: text;
    -webkit-user-select: text;
}

#glCanvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: block;
}

#ui {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 20px;
    box-sizing: border-box;
    z-index: 10;
}

.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    width: 100%;
    flex-wrap: wrap;
    gap: 10px;
}

.right-controls {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    flex-shrink: 0;
}

#teleport-panel {
    background: rgba(106, 13, 173, 0.4);
    padding: 5px 10px;
    border: 1px solid #6a0dad;
    border-radius: 4px;
    pointer-events: auto;
    display: flex;
    flex-direction: column;
}

#teleport-select {
    background: #000;
    color: #fff;
    border: 1px solid #6a0dad;
    padding: 2px;
    font-size: 11px;
    margin-top: 3px;
    max-width: 120px;
}

.middle-layout {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}



.stats {
    display: flex;
    flex-direction: column;
    gap: 6px;
    pointer-events: auto;
    flex: 1;
    min-width: 140px;
}

.stat-item {
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    padding: 6px 10px;
    border-radius: 6px;
    border-left: 3px solid #00f2ff;
    transition: all 0.5s ease;
    width: fit-content;
    max-width: 100%;
    position: relative;
    overflow: hidden;
}

.stat-item.clickable {
    cursor: pointer;
    pointer-events: auto;
}

.hold-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background: #00f2ff;
    width: 0%;
    transition: width 0.1s linear;
}

.toast-msg {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 242, 255, 0.2);
    border: 1px solid #00f2ff;
    padding: 10px 20px;
    border-radius: 20px;
    color: #fff;
    backdrop-filter: blur(10px);
    pointer-events: none;
    z-index: 10000;
    font-size: 14px;
    letter-spacing: 2px;
    animation: fade-up 1.5s forwards;
}

@keyframes fade-up {
    0% { opacity: 0; transform: translate(-50%, -20%); }
    20% { opacity: 1; transform: translate(-50%, -50%); }
    80% { opacity: 1; transform: translate(-50%, -50%); }
    100% { opacity: 0; transform: translate(-50%, -80%); }
}

.stat-item.transcending {
    border-left-color: #ff00ff;
    box-shadow: 0 0 15px rgba(255, 0, 255, 0.3);
}

.stat-item.eternity {
    border-left-color: #ffffff;
    box-shadow: 0 0 25px rgba(255, 255, 255, 0.5);
}

.stat-item.unity {
    border-left-color: #ff3333;
    box-shadow: 0 0 35px rgba(255, 51, 51, 0.6);
}

.stat-item.lenity {
    border-left-color: #00ffaa;
    box-shadow: 0 0 35px rgba(0, 255, 170, 0.6);
}

.stat-item.ultity {
    border-left-color: #ffffff;
    box-shadow: 0 0 45px rgba(255, 255, 255, 0.4);
}

.stat-item.singularity {
    border-left-color: #6a0dad;
    box-shadow: 0 0 55px rgba(106, 13, 173, 0.8), 0 0 20px rgba(255, 0, 0, 0.4);
}

.stat-item.omega {
    border-left-color: #ff4500;
    box-shadow: 0 0 55px rgba(255, 69, 0, 0.8), 0 0 20px rgba(255, 215, 0, 0.6);
}

.stat-item.krinitry {
    border-left-color: #00ff88;
    box-shadow: 0 0 55px rgba(0, 255, 136, 0.8), 0 0 25px rgba(0, 255, 255, 0.6);
}

.stat-item.infinity {
    border-left-color: #ffffff;
    background: linear-gradient(45deg, #ff0000, #ff7f00, #ffff00, #00ff00, #0000ff, #4b0082, #8b00ff);
    background-size: 400% 400%;
    animation: rainbow-bg 5s ease infinite;
    box-shadow: 0 0 100px rgba(255, 255, 255, 0.8);
    color: #fff;
    text-shadow: 0 0 5px #000;
}

@keyframes rainbow-bg {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.upgrades-panel.disabled {
    opacity: 0.2;
    pointer-events: none;
    filter: grayscale(1);
}



.label {
    display: block;
    font-size: 10px;
    letter-spacing: 2px;
    color: #aaa;
    margin-bottom: 2px;
}

#scale-val, #dt-val, #state-val {
    font-family: 'Courier New', Courier, monospace;
    font-size: 18px;
    font-weight: bold;
    white-space: nowrap;
}

#scale-val sup {
    font-size: 0.65em;
    vertical-align: top;
    position: relative;
    top: -0.1em;
    margin-left: 1px;
}

#state-val {
    font-size: 24px;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.8);
}

.controls-overlay {
    position: absolute;
    bottom: 10px;
    left: 0;
    right: 0;
    text-align: center;
    opacity: 0.6;
}

#hint {
    font-size: 14px;
    letter-spacing: 1px;
    animation: pulse 2s infinite ease-in-out;
}

.menu {
    display: flex;
    gap: 4px;
    pointer-events: auto;
    flex-wrap: nowrap;
    justify-content: flex-end;
}

.upgrades-panel {
    display: flex;
    gap: 10px;
    padding: 15px;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(15px);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    pointer-events: auto;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Firefox */
}

.upgrades-panel::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
}

.upgrade-item {
    min-width: 160px;
    background: rgba(255, 255, 255, 0.05);
    padding: 10px;
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.upg-info {
    display: flex;
    flex-direction: column;
}

.upg-name {
    font-size: 12px;
    font-weight: bold;
    color: #00f2ff;
}

.upg-cost {
    font-size: 10px;
    color: #aaa;
}

.buy-btn {
    width: 100%;
    padding: 5px;
    font-size: 10px;
    background: #00f2ff22;
    border-color: #00f2ff44;
}

.buy-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.buy-btn.maxed {
    color: #0f0;
    border-color: #0f0;
}

button {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
    transition: all 0.2s;
    white-space: nowrap;
}

button:hover {
    background: rgba(255, 255, 255, 0.2);
}

@keyframes pulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.8; }
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000; /* Ensure it's above UI */
    pointer-events: auto;
}

.modal-content {
    position: relative;
    background: #111;
    border: 1px solid #333;
    padding: 25px;
    border-radius: 8px;
    max-width: 440px;
    width: 85%;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    gap: 15px;
    box-shadow: 0 0 50px rgba(0, 242, 255, 0.1);
    box-sizing: border-box;
}

.start-content {
    text-align: center;
    align-items: center;
    padding: 40px 25px;
    border: 1px solid #00f2ff44;
    box-shadow: 0 0 60px rgba(0, 242, 255, 0.15);
}

.start-icon {
    width: 120px;
    height: 120px;
    margin-bottom: 10px;
    filter: drop-shadow(0 0 20px rgba(0, 242, 255, 0.4));
    animation: start-pulse 4s infinite ease-in-out;
}

@keyframes start-pulse {
    0%, 100% { transform: scale(1); filter: drop-shadow(0 0 20px rgba(0, 242, 255, 0.4)); }
    50% { transform: scale(1.05); filter: drop-shadow(0 0 35px rgba(0, 242, 255, 0.6)); }
}

.start-content h2 {
    font-size: 32px;
    margin: 0;
    background: linear-gradient(180deg, #fff 0%, #00f2ff 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 8px;
    border-bottom: none;
    padding-bottom: 5px;
}

.start-content p {
    color: #888;
    letter-spacing: 2px;
    margin-top: 0;
}

.start-content button:not(.danger-btn) {
    background: rgba(0, 242, 255, 0.1);
    border-color: rgba(0, 242, 255, 0.4);
    color: #00f2ff;
}

.start-content button:not(.danger-btn):hover {
    background: rgba(0, 242, 255, 0.2);
    border-color: #00f2ff;
}

.modal-content h2 {
    margin: 0;
    color: #00f2ff;
    letter-spacing: 3px;
    text-transform: uppercase;
    font-size: 20px;
    border-bottom: 1px solid #333;
    padding-bottom: 10px;
}

.modal-actions {
    display: flex;
    gap: 15px;
    justify-content: flex-end;
    margin-top: 10px;
}

.modal-actions.start-actions {
    justify-content: center;
    flex-direction: column;
}

.modal-actions.start-actions {
    width: 100%;
    max-width: 250px;
    margin-left: auto;
    margin-right: auto;
}

.modal-actions.start-actions button {
    padding: 14px;
    font-size: 15px;
    letter-spacing: 2px;
    font-weight: bold;
    text-transform: uppercase;
}

.danger-btn {
    background: rgba(255, 51, 51, 0.15) !important;
    border-color: rgba(255, 51, 51, 0.5) !important;
    color: #ff3333 !important;
}

.danger-btn:hover {
    background: rgba(255, 51, 51, 0.3) !important;
}

.modal-content.victory {
    text-align: center;
    border: 2px solid #fff;
    box-shadow: 0 0 100px rgba(255, 255, 255, 0.3);
}

.modal-content.victory h2 {
    color: #fff;
    border-bottom-color: #fff;
    animation: flash 1s infinite alternate;
    font-size: 17px;
    letter-spacing: 1px;
}

@keyframes flash {
    from { opacity: 0.5; text-shadow: 0 0 10px #fff; }
    to { opacity: 1; text-shadow: 0 0 30px #fff, 0 0 50px #fff; }
}

.victory-stats {
    margin: 20px 0;
    font-family: 'Courier New', Courier, monospace;
    font-size: 18px;
    color: #00f2ff;
}

#win-reset-btn {
    background: #fff;
    color: #000;
    font-weight: bold;
    padding: 15px 30px;
}

.close-btn {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    color: #00f2ff;
    font-size: 32px;
    cursor: pointer;
    line-height: 1;
    padding: 5px;
    z-index: 10;
}

.close-btn:hover {
    color: #fff;
    background: none;
}

.help-scroll {
    overflow-y: auto;
    font-size: 14px;
    line-height: 1.6;
    color: #ccc;
    touch-action: pan-y; /* Allow scrolling in help */
}

.help-scroll ul {
    padding-left: 20px;
}

.help-scroll li {
    margin-bottom: 8px;
}

.help-credit {
    font-size: 11px;
    margin-top: 20px;
    color: rgba(255, 255, 255, 0.4);
    text-align: center;
}

.help-credit a {
    color: #00f2ff;
    text-decoration: none;
}

.help-credit a:hover {
    text-decoration: underline;
}

#help-timer {
    align-self: flex-end;
    padding: 10px 25px;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid #00f2ff;
    color: #00f2ff;
    border-radius: 4px;
    font-size: 12px;
    letter-spacing: 1px;
}

@media (max-width: 600px) {
    .stats {
        flex-direction: column;
        gap: 4px;
        min-width: 140px;
    }
    #scale-val, #dt-val, #state-val {
        font-size: 14px;
    }
    .label {
        font-size: 8px;
    }
    #ui {
        padding: 10px;
    }
    .upgrades-panel {
        padding: 10px;
    }
    .upgrade-item {
        min-width: 140px;
    }
    .menu button {
        padding: 4px 6px;
        font-size: 9px;
    }
    .top-bar {
        gap: 5px;
        flex-wrap: nowrap;
    }
}

.app-footer {
    position: relative;
    text-align: center;
    font-size: 10px;
    padding: 5px;
    color: rgba(255, 255, 255, 0.4);
    pointer-events: auto;
}

.app-footer a {
    color: #00f2ff;
    text-decoration: none;
}

.hidden {
    display: none !important;
}