html {
    width: 100%;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

html::-webkit-scrollbar,
body::-webkit-scrollbar,
#app::-webkit-scrollbar,
#game-stage::-webkit-scrollbar,
#ui-layer::-webkit-scrollbar,
#win-screen::-webkit-scrollbar,
#game-over-screen::-webkit-scrollbar,
#settings-modal::-webkit-scrollbar {
    display: none;
}

body {
    background-color: #000;
    /* Body Black */
    color: white;
    font-family: 'Segoe UI', sans-serif;
    margin: 0;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    /* Disable selection */
    width: 100%;
    height: 100%;
    overscroll-behavior: none;
    touch-action: none;
    /* Critical for preventing scroll/zoom */
}

#app {
    position: relative;
    width: 100vw;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #000;
    /* Black bars */
    overflow: hidden;
    /* Ensure nothing accidentally scrolls app */
}

#game-stage {
    position: relative;
    width: 100%;
    height: 100%;
    background-color: #7BCDED;
    overflow: hidden;
}

#game-content {
    position: absolute;
    top: 0;
    left: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: 0 0;
    /* width, height, transform set by JS resizeGame() */
}

#canvas-wrapper {
    position: relative;
    width: 100%;
    flex: 1;
    /* Takes ALL remaining space */
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
    /* Clean touch actions */
    touch-action: none;
    background: transparent;
    z-index: 1;
    /* Below UI layer but above bg */
    min-height: 0;
    /* Crucial for flex nested scrolling prevention */
}

#canvas-wrapper::-webkit-scrollbar {
    display: none;
    /* Chrome/Safari */
}

canvas {
    display: block;
    margin: 0;
    /* flex centering from #canvas-wrapper handles positioning */
    touch-action: none;
    /* Disable browser zooming/panning */
}

/* UI Layer now mainly for overlays */
#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 50;
    /* Above everything */
    display: block;
    /* Not flex, just container */
}

/* HUD now in flow */
#hud {
    pointer-events: auto;
    width: 100%;
    padding: 10px 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    gap: 5px;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(5px);
    box-sizing: border-box;
    z-index: 20;
    position: relative;
    /* Static in flow */
    min-height: 80px;
    border-bottom: 2px solid rgba(255, 255, 255, 0.5);
    flex-shrink: 0;
    /* Don't shrink */
}

#level-display {
    font-size: 24px;
    font-weight: bold;
    color: #394A61;
    /* Darker color */
    text-shadow: none;
    text-align: center;
    z-index: 5;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    box-sizing: border-box;
    padding: 0 60px;
}

#lives-display {
    font-size: 32px;
    display: flex;
    justify-content: center;
    /* Center hearts */
    /* Removed absolute positioning to keep it in flow under level */
}

/* Settings Button - Absolute Positioned */
.icon-btn {
    position: absolute;
    left: 20px;
    top: 50%;
    margin-top: -25px;
    /* Half of height 50px for centering without transform override */

    z-index: 20;

    background: none;
    border: none;
    font-size: 40px;
    cursor: pointer;
    color: white;
    padding: 0;

    /* Square for rotation */
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;

    transition: transform 0.2s;
    outline: none;
}

.icon-btn:hover {
    transform: rotate(90deg);
    background: none;
    box-shadow: none;
}

/* Hearts */
.heart-icon {
    width: 32px;
    height: 32px;
    margin: 0 2px;
    object-fit: contain;
    transition: opacity 0.3s;
}

.heart-icon.empty {
    opacity: 0.3;
    /* Transparent when spent */
    filter: none;
    /* Just simple transparency as requested */
}

/* Modals */
#game-over-screen,
#settings-modal {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.95);
    color: #2c3e50;
    padding: 30px 50px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    pointer-events: auto;
    z-index: 200;
    min-width: 250px;
    max-width: 90%;
    max-height: 90%;
    overflow: hidden;
    box-sizing: border-box;

    /* Scaled by JS */
    will-change: transform;
    transform-origin: center center;
}

#win-screen {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.95);
    color: #2c3e50;
    padding: 10px 15px 15px 15px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    pointer-events: auto;
    z-index: 200;

    width: 90%;
    max-width: 450px;
    height: auto;
    max-height: 80%;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 5px;
    box-sizing: border-box;

    /* Scaled by JS */
    will-change: transform;
    transform-origin: center center;
}

#win-screen h1 {
    margin-top: 10px;
    margin-bottom: 5px;
    flex-shrink: 0;
    font-size: 26px;
}

#next-level-btn {
    margin-top: 10px;
    margin-bottom: 10px;
    padding: 12px 40px;
    font-size: 20px;
    font-weight: bold;
    z-index: 205;
    flex-shrink: 0;
}

.settings-content {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 20px;
    font-weight: bold;
}

.hidden {
    display: none !important;
}

button {
    padding: 10px 20px;
    font-size: 18px;
    cursor: pointer;
    background: #3498db;
    color: white;
    border: none;
    border-radius: 5px;
    transition: background 0.2s;
    margin: 5px;
    width: 100%;
    /* Settings buttons full width */
}

button:hover {
    background: #2980b9;
}

button:disabled,
.img-btn:disabled,
input:disabled {
    pointer-events: none;
    opacity: 0.5;
    filter: grayscale(100%);
}

/* Restore width for controls if needed, but defaults are fine here */
#controls-container button {
    width: auto;
}

#hint-btn {
    font-weight: bold;
    /* Create a black outline using multiple shadows */
    text-shadow:
        -1px -1px 0 #000,
        1px -1px 0 #000,
        -1px 1px 0 #000,
        1px 1px 0 #000;
}

.danger-btn {
    background: #e74c3c;
}

.danger-btn:hover {
    background: #c0392b;
}

.success-btn {
    background: #2ecc71;
}

.success-btn:hover {
    background: #27ae60;
}

/* Controls now in flow */
#controls-container {
    padding: 10px 15px;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(5px);
    pointer-events: auto;
    width: 100%;
    display: flex;
    justify-content: center;
    gap: 40px;
    flex-shrink: 0;
    /* Do not shrink */
    z-index: 20;
    position: relative;
    /* Static in flow */
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    box-sizing: border-box;
}

/* Allow text to wrap or adjust in smaller buttons if needed */
#start-game-btn {
    font-size: 24px;
    padding: 15px 40px;
    border-radius: 30px;
    margin-bottom: 10px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    white-space: nowrap;
    /* Prevent wrap */
    min-width: 200px;
    /* Minimum width */
}

/* Hint Label - handle long text like "+3 Hints (Ad)" */
#hint-label {
    text-align: center;
    white-space: pre-wrap;
    /* Allow wrapping */
    max-width: 120px;
    /* Limit width to prevent overlap */
    line-height: 1.1;
}

#hint-label.small-text {
    font-size: 11px;
    /* Slightly larger than 10px */
}

.control-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: auto;
}

.ui-label {
    font-size: 16px;
    font-weight: bold;
    color: #394A61;
    text-shadow: none;
    /* Clean text */
}



/* Remove PC Absolute overrides to ensure no overlap */
@media (min-width: 601px) {
    #controls-container {
        /* Keep relative flow logic even on PC to prevent overlap */
        gap: 250px;
    }
}

.zoom-control {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 60px;
    /* Match hint button height for alignment */
}

#controls-container>* {
    pointer-events: auto;
}

.zoom-control {
    display: flex;
    align-items: center;
    gap: 15px;
}

.zoom-icon {
    position: absolute;
    right: -10px;
    /* Adjust overlap as needed */
    top: 50%;
    transform: translateY(-50%);
    width: 30px;
    /* Slightly smaller to fit better */
    height: 30px;
    object-fit: contain;
    pointer-events: none;
    /* Pass clicks to slider */
    z-index: 3;
    /* Above input if needed, or below? Input is z-2. Let's start with 3 to be visible */
}

#version-label {
    position: absolute;
    bottom: 10px;
    width: 100%;
    text-align: center;
    opacity: 0.5;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.8);
    pointer-events: none;
    z-index: 60;
}

/* Custom Slider Container */
.zoom-slider-container {
    position: relative;
    width: 200px;
    height: 20px;
}

.zoom-track-empty,
.zoom-track-filled {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    border-radius: 10px;
    pointer-events: none;
}

.zoom-track-empty {
    width: 100%;
    background: url('assets/podlozka_scale_01.png') no-repeat center;
    background-size: 100% 100%;
}

.zoom-track-filled {
    width: 0%;
    background: url('assets/podlozka_scale_02.png') no-repeat left center;
    background-size: 200px 100%;
    /* Matches container width to crop instead of stretch */
}

/* Input (invisible track, visible thumb) */
#zoom-slider {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    outline: none;
    margin: 0;
    cursor: pointer;
    z-index: 2;
    touch-action: pan-x;
}

#zoom-slider::-webkit-slider-runnable-track {
    background: transparent;
}

#zoom-slider::-moz-range-track {
    background: transparent;
}

/* Slider Thumb */
#zoom-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 40px;
    height: 40px;
    background: url('assets/button_scale.png') no-repeat center;
    background-size: contain;
    cursor: pointer;
    border: none;
    margin-top: -8px;
    margin-left: -3px;
}

#zoom-slider::-moz-range-thumb {
    width: 40px;
    height: 40px;
    background: url('assets/button_scale.png') no-repeat center;
    background-size: contain;
    cursor: pointer;
    border: none;
}

/* Hint Button (Image) */
.img-btn {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    width: 60px;
    height: 60px;
    transition: transform 0.1s;
}

.img-btn:active {
    transform: scale(0.95);
}

.img-btn img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Hint Panel */
.hint-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.hint-controls {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    height: 60px;
    /* Match zoom-control height for alignment */
}

#hint-panel-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 60px;
    height: 60px;
}

.hint-panel {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

#hint-count-display {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-top: 14px;
    box-sizing: border-box;
    font-size: 24px;
    font-weight: bold;
    color: white;
    text-align: center;
}

/* #hint-label now uses .ui-label class, no additional styles needed */

/* Adjust label positioning logic in HTML structure if needed, or keep absolute */


#hint-label.small-text {
    font-size: 10px;
}


/* Settings Icon size fix */
.icon-btn img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Hearts */
.heart-icon {
    width: 32px;
    height: 32px;
    margin: 0 2px;
    object-fit: contain;
}

/* Main Menu */
#main-menu-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #2c3e50;
    color: white;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 50;
    padding: 20px;
    box-sizing: border-box;
    pointer-events: auto;
    /* Enable clicks */
    /* Enable clicks */
    overflow: hidden;

    /* Scaled by JS */
    will-change: transform;
    transform-origin: center center;
}

/* Replaced h1 with Rank Container */
#rank-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 20px;
}

#rank-icon {
    font-size: 80px;
    line-height: 1;
    margin-bottom: 10px;
    filter: drop-shadow(0 0 10px rgba(241, 196, 15, 0.5));
}

#rank-name {
    font-size: 32px;
    font-weight: bold;
    color: #f1c40f;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

#leaderboard-container,
#win-leaderboard-container {
    background: rgba(0, 0, 0, 0.2);
    padding: 10px;
    border-radius: 12px;
    width: 100%;
    max-width: 550px;
    margin-bottom: 20px;
    box-sizing: border-box;
    /* Compact mode: No scroll, fits 5 items */
}

/* Scrollbar styles removed as no longer needed for win screen, 
   but kept clean for main menu if it ever grows */

#leaderboard-container h2 {
    margin-top: 0;
    text-align: center;
    color: #f1c40f;
    margin-bottom: 10px;
    /* Reduced */
}

#leaderboard-list,
#win-leaderboard-list {
    list-style: none;
    padding: 0;
    margin: 0;
    width: 100%;
}

.leaderboard-row {
    display: flex;
    align-items: center;
    padding: 5px 10px;
    /* Reduced vertical padding */
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 16px;
    /* Reduced font */
    height: 48px;
    /* Compact Fixed height! */
    box-sizing: border-box;
}

.leaderboard-row.player-row {
    background: rgba(241, 196, 15, 0.2);
    /* Highlight player */
    border: 1px solid #f1c40f;
    border-radius: 8px;
    transform: scale(1.05);
    /* Pop out */
    font-weight: bold;
}

.rank-col {
    width: 60px;
    text-align: right;
    margin-right: 15px;
    color: #7f8c8d;
}

.avatar-col {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    background: #34495e;
    margin-right: 15px;
}

.name-col {
    flex: 1;
    text-align: left;
}

.level-col {
    width: 80px;
    text-align: right;
    color: #3498db;
}

.menu-controls {
    text-align: center;
}

#start-game-btn {
    font-size: 24px;
    padding: 15px 40px;
    border-radius: 30px;
    margin-bottom: 10px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

#menu-level-status {
    font-size: 18px;
    color: #95a5a6;
}

.rank-update {
    font-size: 24px;
    font-weight: bold;
    color: #27ae60;
    margin: 15px 0;
    /* Add logic to animation later if needed */
    animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popIn {
    0% {
        opacity: 0;
        transform: scale(0.5);
    }

    100% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Confetti/Fireworks Effect */
.confetti-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
    z-index: 100;
}

.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    opacity: 0;
    animation: confetti-fall 3s ease-out forwards;
    will-change: transform, opacity;
    transform: translateZ(0);
    backface-visibility: hidden;
}

.confetti.circle {
    border-radius: 50%;
}

.confetti.square {
    border-radius: 2px;
}

.confetti.ribbon {
    width: 4px;
    height: 16px;
    border-radius: 2px;
}

@keyframes confetti-fall {
    0% {
        opacity: 1;
        transform: translateY(0) rotate(0deg) scale(1);
    }

    25% {
        opacity: 1;
    }

    100% {
        opacity: 0;
        transform: translateY(100vh) rotate(720deg) scale(0.5);
    }
}

@keyframes confetti-burst {
    0% {
        opacity: 1;
        transform: translate(0, 0) scale(0);
    }

    20% {
        opacity: 1;
        transform: scale(1);
    }

    100% {
        opacity: 0;
        transform: translateY(80vh) scale(0.3);
    }
}

@media (max-width: 600px) and (orientation: portrait) {
    #hud {
        height: auto;
        min-height: 80px;
        align-items: center;
        /* Center horizontally */
        padding-top: 60px;
        /* Space for settings button if absolute */
        justify-content: center;
        flex-direction: column;
        gap: 5px;
    }

    /* Settings Button stays absolute top-left */
    .icon-btn {
        top: 40px;
        left: 15px;
        margin-top: 0;
        width: 40px;
        height: 40px;
        font-size: 30px;
    }

    #level-display {
        width: 100%;
        font-size: 22px;
        margin-bottom: 5px;
    }

    #controls-container {
        justify-content: flex-start;
        padding-left: 20px;
        gap: 30px;
    }

    #lives-display {
        position: relative;
        /* In flow now */
        right: auto;
        top: auto;
        transform: none;
        justify-content: center;
        width: 100%;
    }

    .heart {
        font-size: 24px;
        /* Slightly smaller hearts */
    }

    #canvas-wrapper {
        width: 100%;
        flex: 1;
        min-height: 0;
        box-sizing: border-box;
    }
}