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

/* --- Global Box Sizing --- */
html {
    box-sizing: border-box; /* Set base box-sizing */
}
*, *:before, *:after { /* Inherit box-sizing for all elements */
    box-sizing: inherit;
}
/* --- End Global Box Sizing --- */

html, body {
    margin: 0;
    padding: 0;
}

/* --- Start Screen Overlay Styles --- */
.start-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(10, 16, 24, 1); /* Fully opaque overlay */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.6s cubic-bezier(.4,0,.2,1);
    opacity: 1;
}
.start-overlay.fade-out {
    opacity: 0;
    pointer-events: none;
}
.start-logo {
    width: 340px;
    max-width: 80vw;
    margin-bottom: 32px;
    border-radius: 18px;
    box-shadow: 0 0 32px #00bfff88, 0 0 16px #39ff14aa;
}
.start-subtitle {
    color: #00bfff;
    font-family: 'Fredoka One', 'Segoe UI', Arial, sans-serif;
    font-size: 1.5rem;
    margin-bottom: 36px;
    letter-spacing: 2px;
    text-shadow: 0 0 12px #00bfff, 0 0 4px #39ff14;
}
.start-btn {
    font-family: 'Fredoka One', 'Segoe UI', Arial, sans-serif;
    font-size: 1.3rem;
    color: #fff;
    background: linear-gradient(90deg, #00bfff 0%, #39ff14 100%);
    border: none;
    border-radius: 12px;
    padding: 16px 48px;
    box-shadow: 0 0 18px #00bfff88, 0 0 8px #39ff1488;
    cursor: pointer;
    letter-spacing: 2px;
    transition: background 0.2s, box-shadow 0.2s, transform 0.12s;
}
.start-btn:hover, .start-btn:focus {
    background: linear-gradient(90deg, #39ff14 0%, #00bfff 100%);
    box-shadow: 0 0 32px #00bfffcc, 0 0 16px #39ff14cc;
    transform: scale(1.05);
}
/* --- End Start Screen Overlay Styles --- */

body {
    font-family: 'Poppins', 'Segoe UI', Arial, sans-serif;
    background: #181c20;
    color: #e0e0e0;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

#game-container {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    border-radius: 18px;
    /* box-shadow removed */
    padding: 8px 40px 8px 40px;
    overflow: hidden;
    width: auto;
    margin: 0 auto;
    box-sizing: border-box;
}

@media (max-width: 800px), (pointer: coarse) {
  #game-container {
    width: 98vw;
    height: auto;
    min-height: 0;
    max-width: 100vw;
    padding: 0;
  }
}

#main-content {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 32px;
    width: auto;
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}

@media (max-width: 700px), (pointer: coarse) {
  #game-container {
    flex-direction: column;
    padding: 0;
    width: 100vw;
    max-width: 100vw;
  }
  #main-content {
    flex-direction: column;
    align-items: center;
    width: 100vw;
  }
}

#main-content {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: flex-start;
    gap: 32px;
    width: 100%;
    flex-grow: 1;
    overflow-y: visible;
}

@media (max-width: 700px), (pointer: coarse) {
  #main-content {
    flex-direction: column;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 8px;
    box-sizing: border-box;
    min-height: 0;
  }
}

#sidebar {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 180px;
    max-width: 240px;
    flex-shrink: 0;
    margin-right: 12px;
}

.sidebar-section {
    margin-bottom: 18px;
    display: flex;
    flex-direction: column;
    align-items: center;
}
#sidebar .sidebar-section:last-child {
    margin-bottom: 0;
}

@media (max-width: 700px), (pointer: coarse) {
  #sidebar {
    flex-direction: row;
    justify-content: space-around;
    width: 100%;
    margin: 0 0 0.5vh 0;
    order: -1;
    flex-wrap: wrap;
    min-width: unset;
    max-width: unset;
    margin-right: 0;
    gap: 0.5vh 1vw;
  }
  #sidebar > * {
    margin: 0;
    flex: 1 1 44%;
    text-align: center;
    padding: 0.2vh 0;
  }
}

#next-piece-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 16px;
}

.next-label {
    color: #00bfff;
    font-family: 'Fredoka One', 'Segoe UI', Arial, sans-serif;
    font-size: 1.1rem;
    text-shadow: 0 0 8px #00bfff, 0 0 4px #39ff14;
    letter-spacing: 1px;
    margin-bottom: 4px;
}

#next-piece-canvas {
    background: #181c20;
    border: 2.5px solid #00bfff;
    border-radius: 10px;
    box-shadow: 0 0 12px #00bfff88, 0 0 6px #39ff1488;
    display: block;
    margin-bottom: 8px;
    width: 110px !important;
    height: 110px !important;
    max-width: 110px;
    max-height: 110px;
}

#level {
    font-size: 1.2rem;
    margin: 8px 0 16px 0;
    padding: 6px 18px;
    color: #00bfff;
    background: #181c20;
    border-radius: 8px;
    box-shadow: 0 0 8px #00bfff77;
    font-weight: bold;
    text-align: center;
    letter-spacing: 1px;
    border: 2px solid #00bfff;
}

/* Make canvas background dark to avoid white flash */
#game-board {
    background-color: #181c20;
    aspect-ratio: 10 / 20;
    width: 100%;
    height: auto;
    max-height: 70vh;
    max-width: 350px;
    display: block;
    border: 4px solid #ffb347;
    border-radius: 12px;
    margin: 0;
    /* No static box-shadow here; use .board-glow for dynamic glow */
    box-sizing: border-box;
}

.board-glow {
    box-shadow: 0 0 24px 6px var(--board-glow-color, #ffb34788), 0 0 12px 2px var(--board-glow-color, #ffb34755);
    transition: box-shadow 0.2s;
}


#score {
    font-size: 1rem;
    margin: 8px 0 16px 0;
    padding: 6px 18px;
    color: #00bfff;
    background: #181c20;
    border-radius: 8px;
    box-shadow: 0 0 8px #00bfff77;
    font-weight: bold;
    word-break: break-word;
    text-align: center;
    letter-spacing: 1px;
    border: 2px solid #00bfff;
}

#pause-btn {
    background: #ff00cc;
    color: #fff;
    border: 2px solid #ff00cc;
    border-radius: 8px;
    padding: 10px 28px;
    font-size: 1.1rem;
    font-family: 'Segoe UI', Arial, sans-serif;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 0 12px #ff00cc88;
    transition: background 0.2s, color 0.2s, transform 0.1s;
    margin: 10px 0 0 0;
    letter-spacing: 1px;
    width: 110px;
    min-width: 110px;
    max-width: 110px;
    text-align: center;
}
#pause-btn:hover {
    background: #fff;
    color: #ff00cc;
}

#restart-btn {
    background: #181c20;
    color: #00bfff;
    border: 2px solid #00bfff;
    border-radius: 8px;
    padding: 10px 28px;
    font-size: 1.1rem;
    font-family: 'Segoe UI', Arial, sans-serif;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 0 12px #00bfff44;
    transition: background 0.2s, color 0.2s, transform 0.1s;
    margin: 18px 0 0 0;
}

#restart-btn:hover {
    background: #00bfff;
    color: #181c20;
    transform: scale(1.06);
}

#restart-btn:hover {
    background: #ff6f61;
}

#touch-controls {
    display: none;
    flex-shrink: 0;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    background: rgba(10,16,24,0.93);
    padding: 8px 0;
    z-index: 1001;
    justify-content: center;
    align-items: center;
    gap: 6px;
    box-sizing: border-box;
}

/* --- Responsive Layout for Mobile --- */
@media (max-width: 700px), (pointer: coarse) {
    html, body {
        height: 100vh;
        width: 100vw;
        margin: 0;
        padding: 0;
        overflow: hidden;
        box-sizing: border-box;
    }
    #game-container {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        margin: 0;
        padding: 0;
        overflow: hidden;
        box-sizing: border-box;
        background: #10192a;
    }
    /* Hide ALL title instances on mobile */
    .title-glow, h1, .title-container, .game-title {
        display: none !important;
    }
    
    /* Simple fixed-height top bar for mobile */
    #sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 36px;
        display: flex;
        flex-direction: row;
        justify-content: space-evenly;
        align-items: center;
        padding: 0;
        background: #10192a;
        border-bottom: 1px solid #233240;
        z-index: 10;
    }
    
    /* Make section containers essentially disappear from layout */
    .sidebar-section {
        display: contents; /* This makes the container "disappear" while keeping children */
        padding: 0;
        margin: 0;
        border: none;
        background: transparent;
    }
    
    /* Next piece canvas - compact size */
    #next-piece-canvas {
        width: 22px;
        height: 22px;
        border-radius: 2px;
        border: 1px solid #2a395a;
        background: rgba(0,0,0,0.2);
        margin: 0;
    }
    
    /* Hide Next Piece text label */
    .next-label {
        display: none;
    }
    
    /* Score and level text */
    #score, #level {
        font-size: 11px;
        color: #00bfff;
        white-space: nowrap;
        margin: 0;
        padding: 0;
    }
    
    /* Buttons */
    #restart-btn {
        font-size: 11px;
        height: 22px;
        padding: 0 6px;
        margin: 0;
        white-space: nowrap;
        background: linear-gradient(180deg, #1e3755 0%, #10192a 100%);
        border: 1px solid #2a395a;
        border-radius: 2px;
        color: #00bfff;
    }
    
    /* Hide pause button and its container on mobile */
    #pause-btn, #pause-section {
        display: none;
    }
    
    /* Main content area */
    #main-content {
        position: fixed;
        top: 36px; /* Directly below fixed-height sidebar */
        left: 0;
        width: 100%;
        height: calc(100vh - 36px - 16vw); /* Space between sidebar and touch controls */
        margin: 0;
        padding: 0;
        display: flex;
        justify-content: center;
        align-items: center; /* Center the game board vertically */
    }
    
    /* Game board styling */
    #game-board {
        width: 68vw; /* Reduced by 20% from 85vw */
        aspect-ratio: 10/20;
        height: auto;
        max-height: calc(100vh - 36px - 16vw - 8px); /* Fixed pixel height calculation */
        margin: 0 auto; /* Center horizontally */
        padding: 0;
        border: 2px solid #233240;
        background: #10192a;
    }
    
    /* Touch controls at bottom */
    #touch-controls {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 16vw;
        display: flex !important;
        justify-content: center;
        align-items: center;
        gap: 4px;
        background: rgba(10,16,24,0.93);
        z-index: 10;
        padding: 0;
        border-top: 1px solid #233240;
    }
    
    #touch-controls button {
        width: 15vw !important;
        height: 15vw !important;
        font-size: 5vw !important;
        margin: 0 1vw;
    }

    /* --- Modern Neon Touch Controls --- */
    #touch-controls {
        gap: 2vw;
        padding-bottom: max(2vh, 18px);
        padding-left: min(4vw, 18px);
        padding-right: min(4vw, 18px);
        background: rgba(10,16,24,0.97);
        border-top: 1.5px solid #233240;
        box-shadow: 0 -2px 24px #00bfff33;
    }
    #touch-controls button {
        border: none;
        outline: none;
        border-radius: 12px;
        width: 10vw;
        height: 10vw;
        min-width: 44px;
        min-height: 44px;
        max-width: 64px;
        max-height: 64px;
        margin: 0 0.5vw;
        background: linear-gradient(145deg, rgba(0,191,255,0.22) 0%, rgba(57,255,20,0.18) 100%);
        box-shadow: 0 2px 18px #00bfff55, 0 0 0 4px #39ff1433;
        border: 2.5px solid #00bfff;
        color: #fff;
        font-size: 2.6rem;
        font-family: 'Fredoka One', 'Segoe UI', Arial, sans-serif;
        transition: background 0.16s, box-shadow 0.16s, transform 0.09s;
        display: flex;
        align-items: center;
        justify-content: center;
        position: relative;
        backdrop-filter: blur(3.5px) saturate(1.2);
        -webkit-backdrop-filter: blur(3.5px) saturate(1.2);
        cursor: pointer;
        opacity: 0.96;
    }
    #touch-controls button:active {
        background: linear-gradient(145deg, #00bfff 0%, #39ff14 100%);
        box-shadow: 0 0 24px #39ff14cc, 0 0 12px #00bfffcc;
        color: #10192a;
        transform: scale(0.94);
        opacity: 1;
    }
    #touch-controls button:focus {
        outline: 2.5px solid #ff00cc;
    }
    #btn-touch-pause {
        background: linear-gradient(145deg, #181c20 60%, #00bfff 100%);
        border: 2.5px solid #ff00cc;
        color: #ff00cc;
        font-size: 2.2rem;
        box-shadow: 0 0 16px #ff00cc99, 0 0 8px #00bfff88;
    }
    #btn-touch-pause:active {
        background: linear-gradient(145deg, #ff00cc 0%, #00bfff 100%);
        color: #fff;
        box-shadow: 0 0 32px #ff00cccc, 0 0 12px #00bfffcc;
    }
    #btn-left, #btn-right {
        background: linear-gradient(145deg, #00bfff 0%, #181c20 100%);
        border: 2.5px solid #00bfff;
        color: #00bfff;
    }
    #btn-rotate, #btn-down {
        background: linear-gradient(145deg, #39ff14 0%, #181c20 100%);
        border: 2.5px solid #39ff14;
        color: #39ff14;
    }
    #btn-left:active, #btn-right:active {
        background: linear-gradient(145deg, #00bfff 60%, #39ff14 100%);
        color: #181c20;
    }
    #btn-rotate:active, #btn-down:active {
        background: linear-gradient(145deg, #39ff14 60%, #00bfff 100%);
        color: #181c20;
    }

    /* Make mute buttons smaller on mobile */
    #music-toggle, #sfx-toggle {
        font-size: 0.7rem !important;
        padding: 2px 6px !important;
        min-width: 20px !important;
        min-height: 20px !important;
        max-width: 28px !important;
        max-height: 28px !important;
        border-radius: 5px !important;
        top: 4px !important;
    }
    #music-toggle { right: 8px !important; }
    #sfx-toggle { right: 38px !important; }
}

.title-glow {
    position: absolute;
    top: 32px;
    left: 50%;
    transform: translateX(-50%);
    width: fit-content;
    min-width: unset;
    max-width: 80vw;
    font-size: 2.2rem;
    padding: 2px 14px;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 200;
    pointer-events: none;
    height: auto;
    box-sizing: border-box;
    border: 3px solid #00f0ff;
    border-radius: 18px;
    /* box-shadow removed */
}

#game-container {
    margin-top: 80px;
}


.title-glow h1 {
    font-family: 'Fredoka One', 'Segoe UI', Arial, sans-serif;
    font-size: 2.7rem;
    font-weight: bold;
    background: linear-gradient(90deg, #00f0ff 0%, #39ff14 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin: 0 auto;
    text-align: center;
    letter-spacing: 2.5px;
    /* text-shadow removed */
    transition: all 0.2s;
    pointer-events: auto;
}

h1 {
    all: unset;
}

/* --- Desktop Fullscreen Layout --- */
@media (min-width: 701px) {
    html, body {
        width: 100vw;
        height: 100vh;
        overflow: hidden;
    }
    #game-container {
        height: 100%;
        overflow: hidden;
    }
}

/* Hidden utility */
.hidden {
    display: none !important;
}

/* Get Ready Text */
#get-ready .get-ready-text {
    color: #fff;
    font-family: 'Fredoka One', 'Segoe UI', Arial, sans-serif;
    font-size: 2.5rem;
    letter-spacing: 2px;
    text-shadow: 0 0 12px #00bfff, 0 0 4px #39ff14;
}

/* Ensure get-ready overlay covers the screen */
#get-ready {
    z-index: 9999;
    background: transparent !important; /* Show game beneath */
}
