/* CSS Variables */
:root {
    --bg-primary: #F0F7FF;
    --bg-secondary: #FFFFFF;
    --text-primary: #2D3748;
    --text-secondary: #718096;
    --accent: #667EEA;
    --accent-hover: #5A67D8;
    --success: #48BB78;
    --warning: #ECC94B;
    --error: #FC8181;
    --overlay: rgba(0, 0, 0, 0.5);

    --felt-color: #0B6623;
    --rail-color: #8B4513;

    --radius-lg: 20px;
    --radius-md: 12px;
    --shadow-soft: 0 4px 6px rgba(0, 0, 0, 0.1);

    --font-main: 'Nunito', sans-serif;
}

[data-theme="dark"] {
    --bg-primary: #1A202C;
    --bg-secondary: #2D3748;
    --text-primary: #F7FAFC;
    --text-secondary: #A0AEC0;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    touch-action: none;
}

body {
    font-family: var(--font-main);
    background: var(--bg-primary);
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

/* === NEW LAYOUT === */
#game-layout {
    display: flex;
    width: 100%;
    height: 100%;
    padding: 20px;
    gap: 20px;
}

#sidebar-left {
    width: 250px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    justify-content: center;
}

#game-center {
    flex: 1;
    display: flex;
    /* Center canvas */
    justify-content: center;
    align-items: center;
    position: relative;
    max-width: 1200px;
    /* Optional max width constraints */
}

#game-canvas {
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    border-radius: var(--radius-lg);
    background-color: var(--felt-color);
    width: 100%;
    /* Will be managed by JS for aspect ratio */
    height: auto;
    max-height: 100%;
}

#sidebar-right {
    width: 80px;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* PANELS */
.panel {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
    padding: 20px;
    text-align: center;
}

/* Score Panel */
.score-panel {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.score-box,
.shots-box {
    display: flex;
    flex-direction: column;
}

.label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 700;
    text-transform: uppercase;
}

#score-display {
    font-size: 2rem;
    font-weight: 900;
    color: var(--accent);
}

#shots-display {
    font-size: 1.5rem;
    font-weight: 700;
}

.stage-info {
    margin: 10px 0;
    border-top: 1px solid #ccc;
    border-bottom: 1px solid #ccc;
    padding: 10px 0;
}

#stage-display {
    display: block;
    font-weight: bold;
    margin-bottom: 5px;
}

/* Controls Panel */
.controls-panel {
    display: flex;
    justify-content: space-around;
    padding: 15px;
}

/* Power Meter Vertical */
.power-meter-vertical {
    background: var(--bg-secondary);
    padding: 10px;
    border-radius: 40px;
    height: 80%;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: var(--shadow-soft);
}

.power-track {
    flex: 1;
    width: 20px;
    background: #CBD5E0;
    border-radius: 10px;
    margin-top: 10px;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: flex-end;
    /* Fill from bottom */
}

#power-fill {
    width: 100%;
    height: 0%;
    /* JS changes this */
    background: linear-gradient(0deg, #48BB78, #ECC94B, #FC8181);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
    border-radius: 10px;
}

.power-label {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

/* BUTTONS */
.icon-btn {
    width: 50px;
    height: 50px;
    font-size: 1.5rem;
    border-radius: 50%;
    background: var(--bg-primary);
    /* Slightly diff from panel */
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: transform 0.1s;
    border: 2px solid transparent;
}

.icon-btn:hover {
    border-color: var(--accent);
    transform: scale(1.1);
}

.icon-btn:active {
    transform: scale(0.95);
}

/* Common Buttons */
.btn-primary,
.btn-secondary,
.btn-tertiary,
.btn-warning,
.btn-danger {
    padding: 15px 30px;
    border-radius: var(--radius-md);
    font-weight: 700;
    margin: 5px 0;
    width: 100%;
    /* Make them full width in vertical stacks */
    border: none;
    cursor: pointer;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-secondary {
    background: #E2E8F0;
    color: #2D3748;
    /* Dark text for light button */
}

[data-theme="dark"] .btn-secondary {
    background: #4A5568;
    color: #F7FAFC;
    /* Light text for dark button */
}

.btn-warning {
    background: var(--warning);
    color: #000;
}

.btn-danger {
    background: var(--error);
    color: white;
}

/* MODALS */
/* MODALS */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--overlay);
    justify-content: center;
    align-items: center;
    z-index: 3000;
    backdrop-filter: blur(5px);
    display: none;
    /* Hidden by default */
}

/* Show modal when active (remove .hidden to show, or add .active) */
.modal:not(.hidden) {
    display: flex;
}

.hidden {
    display: none !important;
}

/* ... existing styles ... */

/* Main Menu Override */
#main-menu {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

/* Landscape Mobile Fixes (Short Screens) */
/* Landscape Mobile Fixes (Side-by-Side Layout) */
@media (max-height: 600px) and (orientation: landscape) {
    #main-menu {
        flex-direction: row !important;
        justify-content: center;
        align-items: center;
        gap: 30px;
        padding: 15px 30px;
        overflow: hidden;
    }

    .logo-container {
        margin-bottom: 0;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        flex-shrink: 0;
    }

    .game-logo {
        font-size: 1.8rem;
        margin-bottom: 5px;
        white-space: nowrap;
    }

    .ball-deco {
        font-size: 4rem;
        margin-top: 0;
    }

    .menu-buttons {
        width: 180px;
        margin-bottom: 0;
        display: flex;
        flex-direction: column;
        justify-content: center;
        gap: 10px;
        flex-shrink: 0;
    }

    .menu-buttons button {
        padding: 10px 15px;
        font-size: 0.9rem;
        width: 100%;
    }

    .menu-footer {
        position: fixed;
        bottom: 8px;
        left: 50%;
        transform: translateX(-50%);
        gap: 15px;
        display: flex;
        flex-direction: row;
    }

    .menu-footer .icon-btn-small {
        width: 40px;
        height: 40px;
        font-size: 1.2rem;
    }

    /* Hide fullscreen button on mobile - it will auto-trigger */
    #btn-fullscreen {
        display: none !important;
    }
}

.menu-footer {
    gap: 15px;
}

.menu-footer .icon-btn-small {
    width: 40px;
    height: 40px;
    font-size: 1.5rem;
}

.hidden {
    display: none !important;
}

.modal-content {
    background: var(--bg-secondary);
    padding: 30px;
    border-radius: var(--radius-lg);
    text-align: center;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
}

.modal-buttons {
    display: flex;
    flex-direction: column;
    /* Ensure vertical stacking for better touch targets */
    gap: 15px;
    /* Add spacing between buttons */
    margin-top: 20px;
}

/* Ensure resume/restart/quit don't touch */
.vertical-stack button {
    margin: 0;
    /* Reset margin, rely on gap */
}

/* Main Menu Override */
/* Main Menu Override */
#main-menu {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.logo-container {
    margin-bottom: 40px;
    animation: float 3s ease-in-out infinite;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.game-logo {
    font-size: 5rem;
    color: var(--accent);
    text-shadow: 4px 4px 0px rgba(0, 0, 0, 0.1);
    margin: 0;
    line-height: 1;
    text-align: center;
}

.ball-deco {
    font-size: 8rem;
    margin-top: 20px;
    filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.2));
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 320px;
    margin-bottom: 40px;
}

.menu-buttons button {
    padding: 20px;
    font-size: 1.3rem;
}

.menu-footer {
    display: flex;
    gap: 25px;
}

.menu-footer .icon-btn-small {
    width: 60px;
    height: 60px;
    font-size: 2rem;
    background: var(--bg-secondary);
    box-shadow: var(--shadow-soft);
    transition: all 0.3s ease;
}

.menu-footer .icon-btn-small:hover {
    transform: scale(1.1);
    background: var(--accent);
    color: white;
}

/* Game Over / Fail Modal Theme */
.fail-theme {
    background: linear-gradient(145deg, #2d1f1f, #1a1212) !important;
    border: 2px solid #e53935;
}

.fail-theme h2 {
    color: #ff6b6b;
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.fail-icon {
    font-size: 4rem;
    margin: 15px 0;
    animation: pulse 1.5s ease-in-out infinite;
}

.fail-theme p {
    color: #ffcdd2;
    font-size: 1.1rem;
    margin: 8px 0;
}

.fail-theme .sub-text {
    color: #ef9a9a;
    font-size: 0.9rem;
}

/* Rotation Warning Overlay */
#rotate-warning {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-primary);
    z-index: 9999;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 20px;
}

.rotate-content h2 {
    color: var(--accent);
    margin: 20px 0;
}

.rotate-icon {
    font-size: 4rem;
    animation: rotate-phone 2s infinite ease-in-out;
}

@keyframes rotate-phone {
    0% {
        transform: rotate(0deg);
    }

    50% {
        transform: rotate(90deg);
    }

    100% {
        transform: rotate(0deg);
    }
}

/* Show only on Portrait Mobile/Tablet */
@media screen and (orientation: portrait) and (max-width: 1024px) {
    #rotate-warning {
        display: flex;
    }

    #game-layout,
    #ui-layer {
        display: none !important;
    }
}

/* Original Responsive Logic */
@media (max-width: 900px) and (orientation: landscape) {
    #game-layout {
        /* Extremely compact sidebar */
        grid-template-columns: 60px 1fr 50px;
        gap: 5px;
        padding: 5px;
    }

    #sidebar-left,
    #sidebar-right {
        padding: 0;
        gap: 5px;
        justify-content: center;
    }

    /* Score Panel Compact */
    .score-panel {
        padding: 2px;
        gap: 4px;
        background: rgba(0, 0, 0, 0.4);
        width: 100%;
    }

    .score-box,
    .shots-box,
    .stage-info {
        padding: 2px;
        margin-bottom: 2px;
        background: rgba(255, 255, 255, 0.05);
        border-radius: 4px;
    }

    /* Tiny Fonts */
    .label {
        font-size: 0.5rem;
        margin-bottom: 0;
    }

    #score-display,
    #balls-display,
    #shots-display,
    #par-display {
        font-size: 0.8rem;
        line-height: 1;
    }

    #stage-display {
        font-size: 0.6rem;
        margin-bottom: 0;
    }

    #stage-stars {
        font-size: 0.6rem;
    }

    /* Tiny Buttons */
    .icon-btn {
        width: 32px;
        height: 32px;
        font-size: 0.9rem;
    }

    .panel {
        background: transparent;
        box-shadow: none;
    }
}

/* MOBILE LANDSCAPE OPTIMIZATION (Moderate & White) */
@media (max-height: 600px),
(max-width: 900px) and (orientation: landscape) {
    #sidebar-left {
        width: 120px !important;
        padding: 0 !important;
        /* Keep background transparent for container */
        background: transparent !important;
        box-shadow: none !important;
    }

    #game-layout {
        /* Sidebar | Table | RightBar */
        grid-template-columns: 125px 1fr 60px !important;
        gap: 5px !important;
        padding: 5px !important;
    }

    /* Restore White Card Look but Compact */
    .panel.score-panel {
        background: rgba(255, 255, 255, 0.95) !important;
        /* White Card */
        border-radius: 8px !important;
        padding: 6px !important;
        gap: 4px !important;
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1) !important;
        width: 100% !important;
    }

    .score-box,
    .shots-box,
    .stage-info {
        padding: 4px !important;
        margin-bottom: 4px !important;
        background: transparent !important;
        /* Remove inner box bg to be clean */
        border-bottom: 1px solid #eee !important;
        border-radius: 0 !important;
    }

    /* Readable Fonts */
    .label {
        font-size: 10px !important;
        color: #666 !important;
        margin-bottom: 1px !important;
        letter-spacing: 0.5px !important;
    }

    #score-display {
        font-size: 22px !important;
        color: #4facfe !important;
        /* Blue Score */
    }

    #balls-display {
        font-size: 22px !important;
        color: #43e97b !important;
        /* Green Balls */
    }

    #shots-display {
        font-size: 16px !important;
        color: #333 !important;
    }

    #stage-display {
        font-size: 12px !important;
        color: #333 !important;
        margin: 2px 0 !important;
    }

    .stars-mini {
        font-size: 10px !important;
    }

    /* Buttons */
    .controls-panel .icon-btn {
        width: 38px !important;
        height: 38px !important;
        font-size: 18px !important;
        margin: 3px 0 !important;
        background: white !important;
        color: #333 !important;
    }
}