:root {
    --bg-color: #0f172a;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
    
    --accent-primary: #3b82f6;
    --accent-secondary: #8b5cf6;
    
    --grid-size: 10;
    --cell-size: 40px;
    
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

:root.light-theme {
    --bg-color: #f1f5f9;
    --text-main: #0f172a;
    --text-muted: #475569;

    --glass-bg: rgba(255, 255, 255, 0.6);
    --glass-border: rgba(255, 255, 255, 0.8);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.05);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Outfit', sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
    position: relative;
}

.background-shapes {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    overflow: hidden;
}

.shape {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.5;
    animation: float 20s infinite alternate;
}

.blob1 {
    top: -10%;
    left: -10%;
    width: 50vw;
    height: 50vw;
    background: radial-gradient(circle, var(--accent-secondary), transparent);
    animation-delay: 0s;
}

.blob2 {
    bottom: -20%;
    right: -10%;
    width: 60vw;
    height: 60vw;
    background: radial-gradient(circle, var(--accent-primary), transparent);
    animation-delay: -5s;
}

.blob3 {
    top: 40%;
    left: 30%;
    width: 40vw;
    height: 40vw;
    background: radial-gradient(circle, #0ea5e9, transparent);
    animation-delay: -10s;
}

@keyframes float {
    0% { transform: translate(0, 0) scale(1); }
    100% { transform: translate(5%, 5%) scale(1.1); }
}

.layout-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    padding: 100px 20px 40px;
    z-index: 1;
}

/* ===== TOP BAR & THEME TOGGLE ===== */
.top-bar {
    position: fixed;
    top: 0;
    left: 0; right: 0;
    z-index: 100;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
}

.back-btn {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(12px);
    border-radius: 14px;
    padding: 10px 20px;
    color: var(--text-main);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    transition: var(--transition);
}

.back-btn:hover {
    transform: translateX(-4px);
    background: rgba(59, 130, 246, 0.15);
}

.top-right-controls {
    display: flex;
    align-items: center;
    gap: 16px;
}

.theme-toggle {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(12px);
    border-radius: 50%;
    width: 48px; height: 48px;
    cursor: pointer;
    display: flex;
    justify-content: center; align-items: center;
    font-size: 1.3rem;
    color: var(--text-main);
    transition: var(--transition);
}

.theme-toggle:hover {
    transform: scale(1.1) rotate(15deg);
}

.icon-sun { display: none; }
.icon-moon { display: block; }
:root.light-theme .icon-sun { display: block; }
:root.light-theme .icon-moon { display: none; }

.app-container {
    display: flex;
    flex-direction: column;
    gap: 24px;
    width: 100%;
    max-width: 500px;
}

.game-header {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}

/* ===== TOP BAR ===== */
.top-bar {
    position: fixed;
    top: 0;
    left: 0; right: 0;
    z-index: 100;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
}

.back-btn {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(12px);
    border-radius: 14px;
    padding: 10px 20px;
    color: var(--text-main);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    transition: var(--transition);
}

.back-btn:hover {
    transform: translateX(-4px);
    background: rgba(59, 130, 246, 0.15);
}

.header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

/* Right side HUD: timer + score */
.hud-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}

.timer-display {
    font-family: 'Rubik', sans-serif;
    font-size: 2.7rem;
    font-weight: 700;
    color: #60a5fa;
    letter-spacing: 0.02em;
    transition: color 0.3s, text-shadow 0.3s;
}

.timer-warning {
    color: #f87171 !important;
    text-shadow: 0 0 12px rgba(248, 113, 113, 0.7);
    animation: timerPulse 0.7s infinite alternate;
}

@keyframes timerPulse {
    from { opacity: 1; }
    to   { opacity: 0.55; }
}

.modal-reason {
    color: #94a3b8;
    font-size: 0.95rem;
    margin: 4px 0 16px;
}

.modal-score-label {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    color: #94a3b8;
    margin-bottom: 4px;
}

.modal-score-value {
    font-family: 'Rubik', sans-serif;
    font-size: 3rem;
    font-weight: 700;
    color: #60a5fa;
    text-shadow: 0 0 20px rgba(96, 165, 250, 0.5);
    margin-bottom: 8px;
}


h1 {
    font-size: 2.5rem;
    font-weight: 800;
    background: linear-gradient(to right, #60a5fa, #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.05em;
}

.score-display {
    font-size: 3rem;
    font-family: 'Rubik', sans-serif;
    font-weight: 700;
    color: var(--accent-primary);
}

.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    box-shadow: var(--glass-shadow);
    padding: 20px;
}

.game-board-container {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.grid {
    position: relative;
    display: grid;
    grid-template-columns: repeat(var(--grid-size), var(--cell-size));
    grid-template-rows: repeat(var(--grid-rows, var(--grid-size)), var(--cell-size));
    gap: 2px;
    background: rgba(0, 0, 0, 0.4);
    border: 2px solid var(--glass-border);
    border-radius: 8px;
    padding: 4px;
}

.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'Rubik', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    color: white;
    transition: background 0.1s;
}

.cell.filled {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    box-shadow: inset 0 0 10px rgba(0,0,0,0.2);
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

/* ── Smoothly animated falling/moving block ────────────────────────────── */
.moving-block {
    position: absolute;
    width: var(--cell-size);
    height: var(--cell-size);
    border-radius: 4px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'Rubik', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    color: white;
    pointer-events: none;
    z-index: 5;

    /* Same gradient as settled blocks but slightly brighter */
    background: linear-gradient(135deg, #60a5fa, #a78bfa);
    box-shadow:
        inset 0 0 10px rgba(0,0,0,0.15),
        0 0 16px rgba(96, 165, 250, 0.5);
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);

    /* The magic: smooth slide between positions */
    transition:
        left 160ms cubic-bezier(0.25, 0.46, 0.45, 0.94),
        top  160ms cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* ── Explosion Animation ─────────────────────────────────── */
.cell.exploding {
    animation: cellExplode 0.45s forwards cubic-bezier(0.36, 0.07, 0.19, 0.97);
    background: linear-gradient(135deg, #ff6b35, #f7c948) !important;
    box-shadow:
        0 0 0 2px #fff,
        0 0 20px 6px rgba(255, 107, 53, 0.9),
        0 0 40px 12px rgba(247, 201, 72, 0.5) !important;
    z-index: 10;
    position: relative;
    pointer-events: none;
}

@keyframes cellExplode {
    0%   { transform: scale(1);    opacity: 1;   filter: brightness(1);   }
    20%  { transform: scale(1.45); opacity: 1;   filter: brightness(2);   }
    50%  { transform: scale(1.2);  opacity: 0.8; filter: brightness(1.5); }
    100% { transform: scale(0);    opacity: 0;   filter: brightness(3);   }
}

/* Legacy class kept for backwards compat */
.explosion-effect {
    display: none;
}

/* ── Level Info Panel (Dynamic) ──────────────────────────────────────────── */
.level-info-panel {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 0;
    overflow: hidden;
    border-top: 3px solid transparent;
    border-image: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary)) 1;
    transition: border-image 0.4s ease;
}


/* Animated content area */
.lip-content {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 18px 20px 20px;
    transition: opacity 0.3s ease, transform 0.35s cubic-bezier(0.4,0,0.2,1);
}

.lip-content.transitioning-out {
    opacity: 0;
    transform: translateY(12px);
    pointer-events: none;
}

.lip-content.transitioning-in {
    opacity: 0;
    transform: translateY(-12px);
}

/* Section labels */
.lip-section-label {
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.18em;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 6px;
}

/* Objective box */
.lip-objective {
    padding: 4px 0 2px;
}

.lip-objective-text {
    font-size: 1.25rem;
    font-weight: 800;
    font-family: 'Rubik', sans-serif;
    line-height: 1.35;
    color: var(--text-main);
    letter-spacing: -0.01em;
    text-align: center;
}

.lip-objective-text strong {
    color: #60a5fa;
    font-weight: 900;
}

/* Divider */
.lip-divider {
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
}

/* Keybinds */
.lip-keybinds {
    display: flex;
    flex-direction: column;
    gap: 9px;
    margin-top: 4px;
}

.lip-keybind-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.lip-keys {
    display: flex;
    gap: 4px;
}

kbd {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    min-width: 34px;
    height: 34px;
    padding: 0 8px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-bottom: 3px solid rgba(255, 255, 255, 0.28);
    border-radius: 7px;
    font-family: 'Rubik', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-main);
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

:root.light-theme kbd {
    background: rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-bottom: 3px solid rgba(0, 0, 0, 0.25);
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.lip-key-desc {
    font-size: 0.95rem;
    color: var(--text-muted);
}

/* Rules */
.lip-rules {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 4px;
}

.lip-rule {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 10px;
    font-size: 1.25rem;
    font-weight: 800;
    font-family: 'Rubik', sans-serif;
    line-height: 1.35;
    color: var(--text-main);
    letter-spacing: -0.01em;
    text-align: center;
}

.lip-rule-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
    margin-top: 0;
}

.lip-rule strong {
    color: #60a5fa;
    font-weight: 900;
}

/* Gradient Text for Header */
.gradient-text {
    background: linear-gradient(135deg, #60a5fa, #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* New unlock badge inside rules */
.lip-new-badge {
    display: inline-block;
    font-size: 0.65rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    background: linear-gradient(135deg, #f59e0b, #ef4444);
    color: white;
    padding: 2px 7px;
    border-radius: 6px;
    vertical-align: middle;
    margin-left: 4px;
    text-transform: uppercase;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    opacity: 1;
    transition: opacity 0.4s ease;
}

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

.modal-content {
    text-align: center;
    padding: 40px;
    max-width: 400px;
    width: 90%;
    transform: scale(1);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal.hidden .modal-content {
    transform: scale(0.8);
}

.btn {
    padding: 12px 24px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    border: none;
    transition: var(--transition);
}

.primary-btn {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
    box-shadow: 0 4px 15px rgba(139, 92, 246, 0.4);
    margin-top: 20px;
}

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

/* ── Generic Hidden Class ────────────────────────────────────────────────── */
.hidden {
    opacity: 0 !important;
    pointer-events: none !important;
    transform: scale(0.8);
}

/* ── Level Announcement ──────────────────────────────────────────────────── */
.level-announcement {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(1);
    font-size: 5rem;
    font-weight: 800;
    color: white;
    text-shadow: 0 0 30px rgba(255, 107, 53, 1), 0 0 60px rgba(247, 201, 72, 0.8);
    background: linear-gradient(to right, #ff6b35, #f7c948);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    z-index: 50;
    pointer-events: none;
    transition: opacity 0.5s ease, transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    white-space: nowrap;
}

/* ── Feature Announcement ────────────────────────────────────────────────── */
.feature-announcement {
    position: absolute;
    top: 30%;
    left: 50%;
    transform: translate(-50%, -50%) scale(1);
    background: rgba(139, 92, 246, 0.9);
    padding: 15px 30px;
    border-radius: 15px;
    border: 2px solid #c084fc;
    box-shadow: 0 0 30px rgba(139, 92, 246, 0.8);
    color: white;
    font-weight: 700;
    text-align: center;
    z-index: 60;
    pointer-events: none;
    transition: opacity 0.5s ease, transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.feature-announcement span {
    font-size: 1.5rem;
    color: #fde047;
}

/* ── Next Block UI ───────────────────────────────────────────────────────── */
.next-block-container {
    position: absolute;
    top: 40px;
    right: -25px;
    transition: opacity 0.4s ease;
    z-index: 20;
}

.next-block-badge {
    width: var(--cell-size);
    height: var(--cell-size);
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    box-shadow: inset 0 0 10px rgba(0,0,0,0.2), 0 4px 16px rgba(0,0,0,0.5);
    border-radius: 4px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-family: 'Rubik', sans-serif;
    font-weight: 700;
    font-size: 1.5rem;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* ── Current Level Badge ─────────────────────────────────────────────────── */
.current-level-badge {
    position: absolute;
    top: -12px;
    right: -12px;
    background: linear-gradient(135deg, #f59e0b, #ef4444);
    color: white;
    padding: 6px 14px;
    border-radius: 20px;
    font-family: 'Rubik', sans-serif;
    font-weight: 800;
    font-size: 0.95rem;
    letter-spacing: 0.05em;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4), 0 0 0 2px var(--bg-color);
    z-index: 20;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), background 0.3s ease;
}

.current-level-badge.pulse {
    transform: scale(1.15);
    background: linear-gradient(135deg, #ef4444, #b91c1c);
}
