/* Reset & Base Settings */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
}

body {
    background-color: #1a1a24;
    background-image: 
        radial-gradient(at 50% 0%, rgba(50, 60, 110, 0.3) 0px, transparent 50%),
        radial-gradient(at 0% 100%, rgba(30, 20, 40, 0.5) 0px, transparent 50%),
        linear-gradient(135deg, #111116 0%, #1c1a24 100%);
    font-family: 'Press Start 2P', monospace;
    color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh; /* Fallback */
    height: 100dvh;
    width: 100vw;
    overflow: hidden;
}

/* Game Container - responsive proportional scaling without crop */
#game-container {
    position: relative;
    /* Bulletproof proportional scaling */
    width: min(100vw, calc(100dvh * 4 / 3));
    height: min(100dvh, calc(100vw * 3 / 4));
    max-width: 800px;
    max-height: 600px;
    background-color: #000;
    border: 4px solid #2e2a38;
    border-radius: 8px;
    box-shadow: 
        0 20px 50px rgba(0, 0, 0, 0.8),
        0 0 0 4px #4a455a,
        inset 0 0 20px rgba(0, 0, 0, 0.5);
    overflow: hidden;
}

/* CRT Scanlines and flicker simulation */
.crt-effect::after {
    content: " ";
    display: block;
    position: absolute;
    top: 0; left: 0; bottom: 0; right: 0;
    background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.03), rgba(0, 255, 0, 0.01), rgba(0, 0, 255, 0.03));
    background-size: 100% 4px, 6px 100%;
    pointer-events: none;
    z-index: 100;
    opacity: 0.8;
}

/* Canvas Styling */
canvas {
    image-rendering: -moz-crisp-edges;
    image-rendering: -webkit-crisp-edges;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    width: 100%;
    height: 100%;
    display: block;
}

/* Hud Styling */
#hud {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
    z-index: 10;
    font-size: 11px;
    text-shadow: 2px 2px 0px #000;
}

.hud-row {
    display: flex;
    justify-content: space-between;
    width: 100%;
}

.hud-item {
    background: rgba(0, 0, 0, 0.6);
    padding: 6px 10px;
    border: 2px solid #5a556a;
    border-radius: 4px;
    display: flex;
    align-items: center;
}

#hook-status {
    align-self: flex-start;
    font-size: 9px;
    letter-spacing: 1px;
}

.status-normal {
    color: #8be9fd;
    border-color: #8be9fd !important;
}

.status-sinking {
    color: #ffb86c;
    border-color: #ffb86c !important;
}

.status-hooked {
    color: #ff5555;
    border-color: #ff5555 !important;
    animation: text-pulse 0.4s infinite alternate;
}

/* Overlay & Panels styling (Glassmorphism + Pixel Art style) */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(10, 10, 15, 0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 20;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.overlay.hidden {
    display: none !important;
}

.panel {
    background: rgba(30, 28, 38, 0.95);
    border: 6px double #bd93f9;
    border-radius: 8px;
    padding: 30px;
    width: 80%;
    max-width: 600px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Typography & Titles */
.pixel-title {
    font-size: 26px;
    margin-bottom: 15px;
    letter-spacing: 2px;
    color: #bd93f9;
    text-shadow: 3px 3px 0px #000;
}

.animated-title {
    animation: bounce 2s infinite ease-in-out;
}

.gold-title {
    color: #f1fa8c;
}

.text-green { color: #50fa7b; }
.text-red { color: #ff5555; }

.subtitle {
    font-size: 10px;
    color: #6272a4;
    margin-bottom: 25px;
    letter-spacing: 1px;
}

/* Instructions and Keys */
.instructions {
    text-align: left;
    font-size: 9px;
    line-height: 2;
    color: #f8f8f2;
    background: rgba(0, 0, 0, 0.4);
    padding: 15px;
    border: 2px solid #44475a;
    border-radius: 4px;
    margin-bottom: 25px;
    width: 100%;
}

.instructions p {
    margin-bottom: 8px;
}

.key {
    background: #f8f8f2;
    color: #282a36;
    padding: 2px 6px;
    border-radius: 3px;
    font-weight: bold;
    border-bottom: 3px solid #ccc;
    display: inline-block;
    margin: 0 2px;
}

/* Buttons */
.pixel-btn {
    font-family: 'Press Start 2P', monospace;
    font-size: 14px;
    color: #282a36;
    background: #50fa7b;
    border: 4px solid #fff;
    border-color: #f8f8f2 #6272a4 #6272a4 #f8f8f2;
    padding: 12px 24px;
    cursor: pointer;
    outline: none;
    box-shadow: 0 6px 0 rgba(0,0,0,0.4);
    position: relative;
    transition: all 0.1s ease;
}

.pixel-btn:hover {
    background: #8af7a6;
    transform: translateY(-2px);
    box-shadow: 0 8px 0 rgba(0,0,0,0.4);
}

.pixel-btn:active {
    transform: translateY(4px);
    box-shadow: 0 2px 0 rgba(0,0,0,0.4);
}

/* Reeling overlay */
.overlay-hud {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 90%;
    z-index: 15;
    pointer-events: none;
}

.overlay-hud.hidden {
    display: none !important;
}

.reel-box {
    background: rgba(20, 20, 28, 0.95);
    border: 4px solid #ff5555;
    border-radius: 8px;
    padding: 15px;
    text-align: center;
    box-shadow: 0 8px 20px rgba(0,0,0,0.8);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.reel-title {
    font-size: 12px;
    color: #ff5555;
    text-shadow: 1px 1px 0 #000;
}

.progress-container {
    width: 100%;
}

.progress-label {
    font-size: 7px;
    color: #6272a4;
    text-align: left;
    margin-bottom: 4px;
}

.progress-bar {
    width: 100%;
    height: 18px;
    background: #282a36;
    border: 2px solid #f8f8f2;
    border-radius: 2px;
    overflow: hidden;
    position: relative;
}

.progress-bar div {
    height: 100%;
    background: #50fa7b;
    width: 0%;
    transition: width 0.1s ease;
}

.tension-bar {
    border-color: #ff5555;
}

.tension-bar div {
    background: linear-gradient(90deg, #50fa7b 0%, #f1fa8c 60%, #ff5555 100%);
}

.reel-instructions {
    font-size: 7px;
    color: #ffb86c;
}

/* Shop Panel Styles */
.shop-panel {
    max-width: 650px;
    width: 90%;
    padding: 20px;
}

.shop-intro {
    font-size: 9px;
    color: #6272a4;
    margin-bottom: 10px;
}

.shop-gold {
    font-size: 14px;
    color: #f1fa8c;
    background: rgba(0,0,0,0.4);
    padding: 8px 16px;
    border: 2px solid #f1fa8c;
    border-radius: 4px;
    margin-bottom: 15px;
}

.shop-items {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    max-height: 260px;
    overflow-y: auto;
    padding-right: 5px;
    margin-bottom: 15px;
}

/* Scrollbar for shop */
.shop-items::-webkit-scrollbar {
    width: 8px;
}
.shop-items::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.3);
}
.shop-items::-webkit-scrollbar-thumb {
    background: #bd93f9;
    border-radius: 4px;
}

.shop-item-card {
    display: flex;
    align-items: center;
    background: rgba(0, 0, 0, 0.4);
    border: 2px solid #44475a;
    padding: 8px 12px;
    border-radius: 6px;
    justify-content: space-between;
    width: 100%;
}

.item-icon {
    font-size: 20px;
    margin-right: 15px;
}

.item-info {
    flex-grow: 1;
    text-align: left;
    padding-right: 10px;
}

.item-name {
    font-size: 10px;
    color: #ff79c6;
    margin-bottom: 4px;
}

.item-desc {
    font-size: 7px;
    color: #f8f8f2;
    line-height: 1.4;
}

.buy-btn {
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    color: #282a36;
    background: #ffb86c;
    border: 3px solid #fff;
    border-color: #f8f8f2 #8b6239 #8b6239 #f8f8f2;
    padding: 8px;
    width: 90px;
    height: 44px;
    cursor: pointer;
    outline: none;
    text-align: center;
}

.buy-btn:hover:not(:disabled) {
    background: #ffc98c;
}

.buy-btn:active:not(:disabled) {
    transform: translateY(2px);
    border-color: #8b6239 #f8f8f2 #f8f8f2 #8b6239;
}

.buy-btn:disabled {
    background: #6272a4;
    color: #f8f8f2;
    border-color: #44475a;
    cursor: not-allowed;
}

.level-lbl {
    font-size: 6px;
    display: block;
    margin-top: 3px;
    color: #282a36;
}

.buy-btn:disabled .level-lbl {
    color: #ccc;
}

.shop-footer {
    width: 100%;
    margin-top: 5px;
}

/* Success, Failure, Victory Panels */
.stats-box {
    background: rgba(0, 0, 0, 0.4);
    border: 2px solid #44475a;
    padding: 15px;
    border-radius: 4px;
    margin: 20px 0;
    width: 100%;
    font-size: 10px;
    line-height: 1.8;
}

.success-panel {
    border-color: #50fa7b;
}

.fail-panel {
    border-color: #ff5555;
}

.victory-panel {
    border-color: #f1fa8c;
}

.congrats-text {
    font-size: 10px;
    color: #f1fa8c;
    margin-bottom: 20px;
    animation: text-pulse 0.6s infinite alternate;
}

/* Keyframe animations */
@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-8px);
    }
}

@keyframes text-pulse {
    0% {
        opacity: 0.7;
    }
    100% {
        opacity: 1;
    }
}

.text-flash {
    animation: text-pulse 0.3s infinite alternate;
}

/* Game Logo */
.game-logo {
    display: block;
    margin: 0 auto 12px auto;
    image-rendering: pixelated;
    filter: drop-shadow(0 4px 12px rgba(0,0,0,0.5));
    animation: logoFloat 3s ease-in-out infinite;
}

.game-logo.logo-large {
    max-width: 280px;
    margin-bottom: 8px;
}

.game-logo.logo-small {
    max-width: 120px;
    margin-bottom: 4px;
}

.game-logo.logo-medium {
    max-width: 150px;
    margin-bottom: 8px;
}

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

/* Mobile Controls */
#mobile-controls {
    position: absolute;
    bottom: 20px;
    left: 0;
    right: 0;
    width: 100%;
    height: auto;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    padding: 0 20px;
    box-sizing: border-box;
    z-index: 50;
    pointer-events: none; /* Let container click through, but catch on buttons */
}

#mobile-controls.hidden {
    display: none !important;
}

.d-pad {
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: auto;
    opacity: 0.6;
}

.d-pad-middle {
    display: flex;
    gap: 40px;
}

.mobile-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 3px solid rgba(255, 255, 255, 0.5);
    border-radius: 12px;
    color: white;
    font-size: 24px;
    width: 60px;
    height: 60px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 5px;
    user-select: none;
    -webkit-user-select: none;
    cursor: pointer;
    touch-action: manipulation;
}

.mobile-btn:active {
    background: rgba(255, 255, 255, 0.5);
    transform: scale(0.95);
}

.action-pad {
    pointer-events: auto;
    opacity: 0.8;
}

.mobile-btn.action-btn {
    width: 80px;
    height: 80px;
    font-size: 14px;
    border-radius: 50%;
    font-weight: bold;
    font-family: 'Press Start 2P', monospace;
    text-align: center;
    padding: 10px;
    line-height: 1.4;
    background: rgba(80, 250, 123, 0.3);
    border-color: rgba(80, 250, 123, 0.8);
}

.mobile-btn.action-btn:active {
    background: rgba(80, 250, 123, 0.7);
}

/* On very small screens, shrink the buttons */
@media (max-width: 600px) {
    .mobile-btn {
        width: 50px;
        height: 50px;
        font-size: 20px;
    }
    .d-pad-middle {
        gap: 30px;
    }
    .mobile-btn.action-btn {
        width: 70px;
        height: 70px;
        font-size: 11px;
    }
    #game-container {
        border-width: 4px;
        border-radius: 6px;
    }
}

/* Bulletproof mobile sizing to prevent any scroll or crop */
@media (max-width: 800px), (max-height: 600px) {
    .panel {
        width: 100%;
        height: 100%;
        max-width: none;
        max-height: none;
        border-radius: 0;
        border: none;
        padding: 5%;
        display: flex;
        flex-direction: column;
        justify-content: space-evenly;
        align-items: center;
        overflow: hidden !important;
    }
    
    .panel > * {
        margin: 0 !important;
    }

    .game-logo.logo-large {
        height: 25%;
        width: auto;
        max-width: 90%;
        object-fit: contain;
    }
    
    .pixel-title {
        font-size: 4vh;
    }
    
    .subtitle {
        font-size: 2.5vh;
    }
    
    .instructions {
        font-size: 2.2vh;
        line-height: 1.4;
        padding: 3%;
        width: 90%;
        max-height: 30%;
        overflow-y: auto;
    }
    
    .pixel-btn {
        font-size: 3vh;
        padding: 2vh 4vw;
        width: 80%;
        max-height: 15%;
    }
    
    .shop-items {
        height: 50%;
        width: 100%;
        overflow-y: auto;
    }
    
    .shop-item-card {
        flex-direction: column;
        text-align: center;
        padding: 5px;
        gap: 2px;
    }
    
    .item-icon { margin: 0 !important; }
    .buy-btn { margin-top: 5px !important; width: 100% !important; }
}

/* Pause Button */
.hud-pause-btn {
    font-family: 'Press Start 2P', monospace;
    background: #ffb86c;
    color: #282a36;
    border: 2px solid #f8f8f2;
    padding: 6px 10px;
    font-size: 12px;
    cursor: pointer;
    margin-left: auto;
    border-radius: 4px;
    outline: none;
    line-height: 1;
}

.hud-pause-btn:active {
    background: #ff9933;
}

/* Pause Screen Specific */
.pause-panel {
    border-color: #f1fa8c;
}
.pause-panel .pixel-btn {
    margin-top: 15px;
    width: 80%;
}
