/* =============================================================================
   Can't Reach My Beer! — UI Overhaul (DOM-based)
   ============================================================================= */

:root {
    /* Colors */
    --color-primary: #2C1810;
    --color-accent: #8B0000;
    --color-success: #22C55E;
    --color-warning: #F59E0B;
    --color-fail: #EF4444;
    --color-info: #06B6D4;
    --color-text-light: #F1F5F9;
    --color-text-dark: #1E293B;

    /* Glassmorphism */
    --glass-bg: rgba(255, 255, 255, 0.15);
    --glass-border: rgba(255, 255, 255, 0.2);
    --glass-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
    --glass-blur: blur(12px);

    /* Typography */
    --font-heading: 'Fredoka One', cursive;
    --font-body: 'Inter', sans-serif;
}

/* Base UI Layer */
#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* Let clicks pass through to canvas by default */
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    overflow: hidden;
    z-index: 10;
}

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 20;
}

.screen.active {
    opacity: 1;
    pointer-events: all;
}

/* Glass Panel Component */
.glass-panel {
    background: var(--glass-bg);
    box-shadow: var(--glass-shadow);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 2rem;
    text-align: center;
    color: white;
    max-width: 90%;
    transform: translateY(20px);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.screen.active .glass-panel {
    transform: translateY(0);
}

/* Typography & Elements */
h1 {
    font-family: var(--font-heading);
    font-size: 3rem;
    color: #FFD700;
    text-shadow: 2px 2px 0 #8B4513;
    margin-bottom: 0.5rem;
    line-height: 1.1;
}

h2 {
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 1.2rem;
    color: #E2E8F0;
    margin-bottom: 2rem;
}

.btn-primary {
    background: linear-gradient(135deg, #8B5CF6 0%, #06B6D4 100%);
    border: none;
    padding: 1rem 3rem;
    border-radius: 50px;
    font-family: var(--font-body);
    font-weight: 700;
    font-size: 1.2rem;
    color: white;
    cursor: pointer;
    transition: transform 0.1s, box-shadow 0.2s;
    box-shadow: 0 4px 15px rgba(6, 182, 212, 0.4);
    pointer-events: all;
    margin-top: 1rem;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(6, 182, 212, 0.6);
}

.btn-primary:active {
    transform: translateY(1px);
}

/* HUD */
#hud {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    display: none;
    /* hidden in menu */
}

body.state-playing #hud {
    display: block;
}

/* Top Bar */
.hud-top {
    position: absolute;
    top: 1rem;
    left: 1rem;
    right: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.score-board {
    background: rgba(255, 255, 255, 0.95);
    padding: 0.6rem 1.2rem;
    border-radius: 50px;
    border: 2px solid #8B4513;
    font-family: var(--font-body);
    font-weight: 700;
    color: var(--color-primary);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.15);
    display: flex;
    gap: 1.5rem;
    align-items: center;
    font-size: 1rem;
}

.score-board span {
    position: relative;
    display: flex;
    align-items: center;
}

.score-board span:not(:last-child)::after {
    content: '';
    display: block;
    width: 2px;
    height: 14px;
    background: #CBD5E1;
    margin-left: 1.5rem;
    position: absolute;
    right: -0.75rem;
}

/* Sobriety Meter */
/* Sobriety Meter */
.sobriety-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    background: rgba(255, 255, 255, 0.9);
    padding: 10px;
    border-radius: 30px;
    border: 2px solid #8B4513;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

.sobriety-container {
    width: 32px;
    height: 180px;
    background: #E2E8F0;
    border-radius: 16px;
    overflow: hidden;
    position: relative;
    border: 2px solid inset rgba(0, 0, 0, 0.1);
}

.sobriety-fill {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(to top, var(--color-fail), var(--color-warning), var(--color-success));
    transition: height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sobriety-label {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
    font-family: var(--font-body);
    font-weight: 800;
    font-size: 0.7rem;
    color: var(--color-primary);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 5px;
}

/* Combo Display */
.combo-container {
    position: absolute;
    bottom: 20%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.4);
    padding: 1rem 2rem;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    min-width: 300px;
}

.keys-row {
    display: flex;
    gap: 0.5rem;
}

.key-cap {
    min-width: 48px;
    height: 48px;
    padding: 0 10px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1.2rem;
    color: #475569;
    border-bottom: 4px solid #CBD5E1;
    transition: all 0.1s;
}

.key-cap.active {
    background: #FFF;
    border-bottom: 4px solid #8B4513;
    transform: translateY(2px);
    color: var(--color-primary);
}

.key-cap.completed {
    background: #DCFCE7;
    border-bottom-color: #22C55E;
    color: #15803D;
}

.key-cap.current {
    border-color: var(--color-warning);
    box-shadow: 0 0 15px var(--color-warning);
    transform: scale(1.1);
    z-index: 2;
}

.key-cap.failed {
    background: #FEE2E2;
    border-bottom-color: var(--color-fail);
    color: var(--color-fail);
    animation: shake 0.3s;
}

.combo-timer {
    width: 100%;
    height: 8px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    overflow: hidden;
}

.timer-bar {
    width: 100%;
    height: 100%;
    background: var(--color-success);
    transition: width 0.1s linear, background-color 0.3s;
}

/* Progress Bar (Bottom) */
.progress-container {
    position: absolute;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    width: 80%;
    max-width: 500px;

    /* Glass panel for progress bar */
    background: var(--glass-bg);
    backdrop-filter: blur(8px);
    border: 1px solid var(--glass-border);
    padding: 0.8rem 1.5rem;
    border-radius: 20px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.progress-track {
    width: 100%;
    height: 18px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 9px;
    border: 1px solid rgba(255, 255, 255, 0.5);
    overflow: hidden;
    margin-bottom: 0.3rem;
    position: relative;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #F59E0B, #22C55E);
    box-shadow: 0 0 10px rgba(34, 197, 94, 0.5);
    transition: width 0.3s ease-out;
}

.progress-text {
    font-family: var(--font-body);
    font-weight: 700;
    color: white;
    font-size: 0.85rem;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

/* Status Messages (Toast) */
#status-message {
    position: absolute;
    top: 20%;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    background: rgba(15, 23, 42, 0.9);
    padding: 1rem 2rem;
    border-radius: 50px;
    color: white;
    font-family: var(--font-body);
    font-weight: 600;
    opacity: 0;
    transition: all 0.3s;
    pointer-events: none;
    white-space: nowrap;
}

#status-message.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Animations */
@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    75% {
        transform: translateX(5px);
    }
}

@keyframes pulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }

    100% {
        transform: scale(1);
    }
}

/* Responsive */
@media (max-width: 600px) {
    h1 {
        font-size: 2rem;
    }

    .glass-panel {
        padding: 1.5rem;
    }

    .key-cap {
        width: 36px;
        height: 36px;
        font-size: 1rem;
    }

    .hud-top {
        flex-direction: column;
        gap: 1rem;
        align-items: flex-end;
    }

    .score-board {
        width: 100%;
        justify-content: space-between;
        font-size: 0.9rem;
    }
}

/* =============================================================================
   Touch Controls (Override)
   ============================================================================= */

#touchControls {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 95%;
    max-width: 600px;
    z-index: 50;
    pointer-events: auto;

    /* Layout handled by JS grid, but we style the container */
    background: transparent;
    padding: 0;
    border: none;
    display: none;
    /* JS will set display: grid if mobile */
}

/* Ensure it shows up on mobile when JS enables it */
body.mobile #touchControls {
    display: grid !important;
}

.touch-btn {
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    color: white;
    font-family: var(--font-body);
    font-weight: 700;
    font-size: 1.2rem;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    transition: all 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 60px;
    /* Force height */
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

.touch-btn:active,
.touch-btn.touch-active {
    background: rgba(255, 255, 255, 0.4);
    transform: scale(0.95);
    border-color: white;
}

.touch-btn.touch-expected {
    border-color: var(--color-warning);
    background: rgba(245, 158, 11, 0.2);
    box-shadow: 0 0 15px rgba(245, 158, 11, 0.4);
    animation: pulse 1s infinite;
}