/* style.css - Cartoon Tetris styling */

@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;600;700&family=Lilita+One&display=swap');

:root {
    --bg-dark: #1b1736;
    --bg-light: #2c2554;
    --border-color: #1a172e;
    --color-orange: #ff9f1c;
    --color-red: #ff4057;
    --color-yellow: #ffd166;
    --color-green: #06d6a0;
    --color-blue: #118ab2;
    --color-purple: #8338ec;
    --color-pink: #ff007f;
    --btn-shadow: 0 6px 0 var(--border-color);
    --btn-shadow-active: 0 2px 0 var(--border-color);
}

* {
    box-sizing: border-box;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    margin: 0;
    padding: 0;
}

body {
    background: radial-gradient(circle at center, var(--bg-light) 0%, var(--bg-dark) 100%);
    color: #ffffff;
    font-family: 'Fredoka', sans-serif;
    min-height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
}

/* Background animated cartoon clouds */
.bg-decorations {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    z-index: -1;
    pointer-events: none;
    opacity: 0.25;
}

.cloud {
    position: absolute;
    background: #ffffff;
    border-radius: 100px;
    filter: blur(1px);
    animation: floatCloud linear infinite;
}

.cloud::before, .cloud::after {
    content: '';
    position: absolute;
    background: #ffffff;
    border-radius: 50%;
}

.cloud-1 {
    width: 120px;
    height: 40px;
    top: 15%;
    left: -150px;
    animation-duration: 45s;
}
.cloud-1::before { width: 50px; height: 50px; top: -25px; left: 15px; }
.cloud-1::after { width: 70px; height: 70px; top: -40px; left: 45px; }

.cloud-2 {
    width: 180px;
    height: 60px;
    top: 45%;
    left: -200px;
    animation-duration: 60s;
    animation-delay: -20s;
}
.cloud-2::before { width: 70px; height: 70px; top: -35px; left: 25px; }
.cloud-2::after { width: 90px; height: 90px; top: -50px; left: 65px; }

.cloud-3 {
    width: 100px;
    height: 35px;
    top: 75%;
    left: -120px;
    animation-duration: 35s;
    animation-delay: -10s;
}
.cloud-3::before { width: 40px; height: 40px; top: -20px; left: 15px; }
.cloud-3::after { width: 50px; height: 50px; top: -30px; left: 40px; }

@keyframes floatCloud {
    0% { transform: translateX(-200px); }
    100% { transform: translateX(calc(100vw + 200px)); }
}

/* Floating Stars decoration */
.star {
    position: absolute;
    width: 15px;
    height: 15px;
    background: var(--color-yellow);
    clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
    animation: twinkle 3s ease-in-out infinite;
}

.star-1 { top: 10%; right: 15%; animation-delay: 0s; transform: scale(1.2) rotate(15deg); }
.star-2 { top: 60%; left: 10%; animation-delay: 1s; transform: scale(0.8) rotate(-10deg); }
.star-3 { top: 80%; right: 20%; animation-delay: 2s; transform: scale(1) rotate(45deg); }

@keyframes twinkle {
    0%, 100% { opacity: 0.3; transform: scale(0.8) rotate(var(--r, 0deg)); }
    50% { opacity: 1; transform: scale(1.2) rotate(var(--r, 0deg)); }
}

/* Game Title */
.header {
    margin-bottom: 15px;
    text-align: center;
    z-index: 10;
}

.title {
    font-family: 'Lilita One', sans-serif;
    font-size: 3rem;
    color: var(--color-yellow);
    text-shadow: 
        -3px -3px 0 var(--border-color),  
         3px -3px 0 var(--border-color),
        -3px  3px 0 var(--border-color),
         3px  3px 0 var(--border-color),
         0px  8px 0 var(--border-color),
         0px 12px 15px rgba(0,0,0,0.5);
    letter-spacing: 2px;
    animation: titleBounce 2.5s ease-in-out infinite;
}

@keyframes titleBounce {
    0%, 100% { transform: translateY(0) rotate(-2deg); }
    50% { transform: translateY(-5px) rotate(2deg); }
}

/* App container */
.app-container {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    justify-content: center;
    gap: 20px;
    z-index: 10;
    max-width: 95vw;
}

/* Sidebar Panels (Hold / Stats / Next) */
.sidebar {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 15px;
    width: 140px;
}

.sidebar.left {
    align-items: flex-end;
}

.sidebar.right {
    align-items: flex-start;
}

/* Cartoon Panels */
.panel {
    background: #25204c;
    border: 4px solid var(--border-color);
    border-radius: 18px;
    box-shadow: 6px 6px 0 var(--border-color);
    padding: 12px;
    width: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.panel-header {
    font-family: 'Lilita One', sans-serif;
    font-size: 1.2rem;
    color: #ffffff;
    background: var(--color-purple);
    border: 3px solid var(--border-color);
    border-radius: 10px;
    padding: 2px 12px;
    margin-bottom: 8px;
    box-shadow: 0 3px 0 var(--border-color);
    transform: translateY(-20px);
    position: absolute;
    top: 5px;
}

/* Dynamic styling for panel headers */
.panel-hold .panel-header { background: var(--color-orange); }
.panel-next .panel-header { background: var(--color-blue); }
.panel-stats .panel-header { background: var(--color-green); }

.panel-content {
    margin-top: 10px;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Small Canvas inside Hold/Next panels */
.preview-canvas {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    border: 2px dashed rgba(255, 255, 255, 0.2);
    width: 80px;
    height: 80px;
    display: block;
}

/* Stats Display */
.stat-box {
    margin: 5px 0;
    width: 100%;
}

.stat-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #bca0ff;
    text-transform: uppercase;
}

.stat-value {
    font-family: 'Lilita One', sans-serif;
    font-size: 1.8rem;
    color: var(--color-yellow);
    text-shadow: 2px 2px 0 var(--border-color);
}

/* Central Board Area */
.board-wrapper {
    position: relative;
    border: 6px solid var(--border-color);
    border-radius: 24px;
    box-shadow: 0 12px 0 var(--border-color), 0 20px 25px rgba(0,0,0,0.6);
    background: #110f27;
    overflow: hidden;
}

#game-canvas {
    background-color: #0b091c;
    display: block;
    width: 300px;
    height: 600px;
    max-width: 100%;
}

/* Overlay Screen Panels (Start, Pause, Game Over) */
.overlay-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 12, 38, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 20;
    padding: 20px;
    text-align: center;
    backdrop-filter: blur(4px);
    transition: opacity 0.3s ease;
    opacity: 1;
}

.overlay-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.overlay-content {
    background: #2c2554;
    border: 5px solid var(--border-color);
    border-radius: 24px;
    box-shadow: 0 10px 0 var(--border-color);
    padding: 30px 20px;
    width: 90%;
    max-width: 280px;
    display: flex;
    flex-direction: column;
    align-items: center;
    animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes popIn {
    0% { transform: scale(0.6); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.overlay-title {
    font-family: 'Lilita One', sans-serif;
    font-size: 2.2rem;
    color: var(--color-yellow);
    text-shadow: 3px 3px 0 var(--border-color);
    margin-bottom: 20px;
}

.overlay-subtitle {
    font-size: 0.95rem;
    color: #ded9ff;
    margin-bottom: 20px;
    line-height: 1.4;
}

/* Play/Pause Buttons & Action Buttons */
.btn-toon {
    font-family: 'Lilita One', sans-serif;
    font-size: 1.25rem;
    padding: 10px 24px;
    border-radius: 14px;
    border: 3px solid var(--border-color);
    cursor: pointer;
    transition: transform 0.05s, box-shadow 0.05s;
    outline: none;
    text-transform: uppercase;
    letter-spacing: 1px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary {
    background: var(--color-yellow);
    color: var(--border-color);
    box-shadow: var(--btn-shadow);
}

.btn-primary:active {
    transform: translateY(4px);
    box-shadow: var(--btn-shadow-active);
}

.btn-danger {
    background: var(--color-red);
    color: white;
    box-shadow: var(--btn-shadow);
}

.btn-danger:active {
    transform: translateY(4px);
    box-shadow: var(--btn-shadow-active);
}

.btn-green {
    background: var(--color-green);
    color: var(--border-color);
    box-shadow: var(--btn-shadow);
}

.btn-green:active {
    transform: translateY(4px);
    box-shadow: var(--btn-shadow-active);
}

/* Sound Toggles & Small Buttons */
.top-controls {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 12px;
    z-index: 10;
}

.btn-round {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 3px solid var(--border-color);
    background: #25204c;
    color: #ffffff;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 0 var(--border-color);
    transition: transform 0.05s, box-shadow 0.05s;
}

.btn-round:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 var(--border-color);
}

.btn-round.active {
    background: var(--color-green);
    color: var(--border-color);
}

/* Mobile Virtual Controller */
.mobile-controls {
    display: none; /* Show only on mobile screens */
    width: 100%;
    max-width: 320px;
    margin-top: 15px;
    z-index: 10;
}

.btn-ctrl {
    font-family: 'Lilita One', sans-serif;
    font-size: 1.4rem;
    padding: 14px 0;
    border-radius: 16px;
    border: 3px solid var(--border-color);
    background: #2c2554;
    color: white;
    box-shadow: 0 5px 0 var(--border-color);
    text-align: center;
    cursor: pointer;
    transition: transform 0.05s, box-shadow 0.05s;
}

.btn-ctrl:active {
    transform: translateY(3px);
    box-shadow: 0 2px 0 var(--border-color);
    background: var(--color-purple);
}

.btn-ctrl.action-btn {
    background: var(--color-orange);
    color: var(--border-color);
}

.btn-ctrl.action-btn:active {
    background: var(--color-yellow);
}

/* Keyboard instructions for desktop */
.kbd-legend {
    display: block;
    margin-top: 15px;
    font-size: 0.75rem;
    color: #a49fc4;
    text-align: center;
    line-height: 1.5;
}

/* Hamburger Menu Button Style */
.hamburger-btn {
    display: none;
    position: fixed;
    top: 15px;
    right: 15px;
    z-index: 100;
    font-size: 1.4rem;
    background: #25204c;
    border: 3px solid var(--border-color);
    box-shadow: 0 4px 0 var(--border-color);
    cursor: pointer;
    transition: transform 0.05s, box-shadow 0.05s;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    color: white;
    align-items: center;
    justify-content: center;
}

.hamburger-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 var(--border-color);
}

/* Hamburger Drawer Overlay */
.hamburger-drawer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 200;
    display: flex;
    justify-content: flex-end;
    transition: visibility 0.3s;
}

.hamburger-drawer.hidden {
    visibility: hidden;
    pointer-events: none;
}

.drawer-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 12, 38, 0.65);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    opacity: 1;
    transition: opacity 0.3s ease;
}

.hamburger-drawer.hidden .drawer-overlay {
    opacity: 0;
}

.drawer-content {
    position: relative;
    width: 290px;
    height: 100%;
    background: #2c2554;
    border-left: 5px solid var(--border-color);
    padding: 30px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    box-shadow: -8px 0 0 rgba(0,0,0,0.3);
    transform: translateX(0);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    overflow-y: auto;
    z-index: 201;
}

.hamburger-drawer.hidden .drawer-content {
    transform: translateX(100%);
}

.drawer-title {
    font-family: 'Lilita One', sans-serif;
    font-size: 2.2rem;
    color: var(--color-yellow);
    text-shadow: 3px 3px 0 var(--border-color);
    margin-top: 15px;
    margin-bottom: 25px;
    letter-spacing: 1px;
}

.drawer-section {
    width: 100%;
    margin-bottom: 25px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.drawer-label {
    font-size: 0.85rem;
    font-weight: 700;
    color: #bca0ff;
    text-transform: uppercase;
    margin-bottom: 10px;
    letter-spacing: 1px;
}

.audio-controls-row {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    background: var(--color-red) !important;
    color: white !important;
}

/* Switch styling */
.switch-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    cursor: pointer;
    margin-top: 10px;
    user-select: none;
}

.switch-container input {
    display: none;
}

.switch-slider {
    position: relative;
    display: inline-block;
    width: 46px;
    height: 24px;
    background-color: #1a172e;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    transition: background-color 0.2s;
}

.switch-slider::before {
    content: "";
    position: absolute;
    height: 16px;
    width: 16px;
    left: 2px;
    bottom: 2px;
    background-color: var(--color-yellow);
    border: 2px solid var(--border-color);
    border-radius: 50%;
    transition: transform 0.2s;
}

.switch-container input:checked + .switch-slider {
    background-color: var(--color-green);
}

.switch-container input:checked + .switch-slider::before {
    transform: translateX(22px);
    background-color: white;
}

/* Responsive adjustments */
@media (max-width: 640px) {
    body {
        padding: 10px;
        justify-content: flex-start;
    }

    .title {
        display: none; /* Hide header title to maximize vertical area */
    }

    .header {
        display: none; /* Hide record/title bar on top */
    }

    .top-controls {
        display: none; /* Hide top settings controls on mobile since they are in hamburger */
    }

    .hamburger-btn {
        display: flex; /* Show hamburger toggle */
    }

    .app-container {
        flex-direction: column;
        align-items: center;
        gap: 10px;
        margin-top: 10px;
    }

    .sidebar.left, .sidebar.right {
        display: none;
    }

    /* On mobile, combine Hold and Next into a single top bar */
    .mobile-top-stats {
        display: flex;
        justify-content: space-between;
        align-items: center;
        width: 320px;
        max-width: 90vw;
        gap: 12px;
        order: 1;
        margin-bottom: 5px;
        padding-right: 50px; /* Leave space for the hamburger button so they don't overlap! */
    }

    .mobile-top-stats .panel {
        flex-grow: 1;
        padding: 6px;
        height: 68px;
        box-shadow: 4px 4px 0 var(--border-color);
        min-height: unset;
    }

    .mobile-top-stats .panel-header {
        font-size: 0.7rem;
        transform: translateY(-13px);
        padding: 1px 6px;
        border-width: 2px;
        box-shadow: 0 2px 0 var(--border-color);
    }

    .mobile-top-stats .stat-value {
        font-size: 1.1rem;
        margin-top: 6px;
    }

    .mobile-top-stats .preview-canvas {
        width: 36px;
        height: 36px;
        margin-top: 4px;
    }

    .board-wrapper {
        order: 2;
        border-width: 5px;
        border-radius: 18px;
        aspect-ratio: 1 / 2;
        height: min(600px, calc(100vh - 230px), calc((100vw - 40px) * 2));
        width: auto;
    }


    #game-canvas {
        width: 100%;
        height: 100%;
    }

    /* Mobile Controls Gamepad layout - Nintendo Game Boy Style */
    .mobile-controls {
        display: flex;
        justify-content: space-between;
        align-items: flex-end;
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100vw;
        max-width: none;
        height: 175px;
        z-index: 90;
        pointer-events: none;
        order: 3;
        margin-top: 0;
        padding: 0 30px 10px 30px;
        touch-action: none;
    }

    .dpad-container {
        position: relative;
        width: 120px;
        height: 120px;
        pointer-events: auto;
        touch-action: none;
    }

    .actions-container {
        position: relative;
        width: 120px;
        height: 120px;
        pointer-events: auto;
        touch-action: none;
    }

    /* Common Button Base */
    .btn-ctrl {
        position: absolute;
        pointer-events: auto;
        display: flex;
        align-items: center;
        justify-content: center;
        font-family: 'Lilita One', sans-serif;
        border: 3px solid var(--border-color);
        color: #ffffff;
        cursor: pointer;
        transition: transform 0.05s, box-shadow 0.05s, background-color 0.1s;
        touch-action: none;
    }

    .btn-ctrl:active {
        transform: translateY(2px) scale(0.95);
    }

    /* Unified Game Boy D-Pad */
    .dpad-btn {
        width: 40px;
        height: 40px;
        background: #231f42;
        color: #837fa1;
        font-size: 0.95rem;
        box-shadow: none; /* flat unified look */
        z-index: 2;
    }

    .dpad-btn:active {
        background: #121024 !important;
        transform: none; /* keep D-pad centered */
    }

    #btn-rotate {
        left: 40px;
        bottom: 80px;
        border-radius: 8px 8px 0 0;
        border-bottom: none;
    }
    #btn-down {
        left: 40px;
        bottom: 0px;
        border-radius: 0 0 8px 8px;
        border-top: none;
        font-size: 1rem;
    }
    #btn-left {
        left: 0px;
        bottom: 40px;
        border-radius: 8px 0 0 8px;
        border-right: none;
    }
    #btn-right {
        left: 80px;
        bottom: 40px;
        border-radius: 0 8px 8px 0;
        border-left: none;
    }

    .dpad-center {
        position: absolute;
        left: 40px;
        bottom: 40px;
        width: 40px;
        height: 40px;
        background: #231f42;
        border-top: 3px solid #231f42; /* cover internal borders */
        border-bottom: 3px solid #231f42;
        z-index: 1;
        pointer-events: none;
    }

    /* Game Boy Action Buttons Bezel (rotated background oval) */
    .action-bezel {
        position: absolute;
        right: 0px;
        bottom: 15px;
        width: 120px;
        height: 90px;
        background: rgba(26, 23, 46, 0.45);
        border: 4px solid var(--border-color);
        border-radius: 30px;
        transform: rotate(-28deg);
        pointer-events: none;
        z-index: 1;
    }

    /* Game Boy Round Action Buttons (A / B) */
    .action-btn {
        width: 45px;
        height: 45px;
        border-radius: 50%;
        background: #ff4057; /* gameboy dark magenta */
        font-size: 1.3rem;
        box-shadow: 0 4px 0 var(--border-color);
        text-shadow: 1px 1px 0 rgba(0,0,0,0.3);
        z-index: 2;
    }

    .action-btn:active {
        transform: translateY(2px) scale(0.95);
        box-shadow: 0 2px 0 var(--border-color);
        background: #d62037 !important;
    }

    #btn-hold {
        right: 60px;
        bottom: 25px; /* Button B (left/lower) */
    }

    #btn-drop {
        right: 5px;
        bottom: 55px; /* Button A (right/higher) */
    }

    /* Labels below buttons */
    .btn-action-label {
        position: absolute;
        font-family: 'Fredoka', sans-serif;
        font-size: 0.65rem;
        font-weight: 700;
        color: #928db3;
        text-align: center;
        width: 45px;
        z-index: 3;
        letter-spacing: 0.5px;
        pointer-events: none;
    }

    #lbl-hold {
        right: 60px;
        bottom: 2px;
    }

    #lbl-drop {
        right: 5px;
        bottom: 32px;
    }

    .kbd-legend {
        display: none;
    }
}

/* Extra small height screens adjustments */
@media (max-height: 600px) and (max-width: 640px) {
    .board-wrapper {
        height: min(600px, calc(100vh - 175px), calc((100vw - 30px) * 2));
        width: auto;
    }
    
    .mobile-controls {
        height: 140px;
        padding: 0 30px 5px 30px;
    }
    
    .dpad-container {
        width: 102px;
        height: 98px;
    }
    
    .actions-container {
        width: 100px;
        height: 90px;
    }
    
    .btn-ctrl {
        width: 34px;
        height: 34px;
        font-size: 0.85rem;
    }
    
    .dpad-btn {
        width: 34px;
        height: 34px;
        font-size: 0.8rem;
    }
    
    #btn-rotate { left: 34px; bottom: 64px; border-radius: 6px 6px 0 0; }
    #btn-down { left: 34px; bottom: 0px; border-radius: 0 0 6px 6px; }
    #btn-left { left: 0px; bottom: 32px; border-radius: 6px 0 0 6px; }
    #btn-right { left: 68px; bottom: 32px; border-radius: 0 6px 6px 0; }
    
    .dpad-center {
        left: 34px;
        bottom: 32px;
        width: 34px;
        height: 34px;
        border-top: 3px solid #231f42;
        border-bottom: 3px solid #231f42;
    }
    
    .action-bezel {
        right: 0px;
        bottom: 10px;
        width: 100px;
        height: 75px;
        border-radius: 25px;
    }
    
    .action-btn {
        width: 38px;
        height: 38px;
        font-size: 1.1rem;
    }
    
    #btn-hold { right: 50px; bottom: 18px; }
    #btn-drop { right: 6px; bottom: 42px; }
    
    .btn-action-label {
        width: 38px;
        font-size: 0.55rem;
    }
    
    #lbl-hold { right: 50px; bottom: 0px; }
    #lbl-drop { right: 6px; bottom: 24px; }
}

.mobile-top-stats {
    display: none;
}

@media (max-width: 640px) {
    .sidebar.left, .sidebar.right {
        display: none;
    }
    .mobile-top-stats {
        display: flex;
    }
}
