/* =================================
   VARIABLES & RESET
================================= */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #246fe5;
    --dark: #16233c;
    --board: #f7f9fc;
    --dot: #cbd2dc;
    --danger: #ef4d5d;
    --success: #20a566;
}

body {
    font-family: Inter, Arial, sans-serif;
    min-height: 100vh;
    background: linear-gradient(135deg, #eef3f9, #e4eaf2);
    color: var(--dark);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden; /* Prevent scroll on mobile */
}

/* =================================
   APP LAYOUT
================================= */
.game-app {
    width: 100%;
    max-width: 650px;
    height: 100dvh;
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
}

/* =================================
   HEADER
================================= */
.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 28px;
}

.icon-btn {
    width: 48px;
    height: 48px;
    border: 0;
    border-radius: 16px;
    background: white;
    color: var(--primary);
    font-size: 26px;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(30, 50, 80, .10);
    transition: transform 0.2s;
}

.icon-btn:active {
    transform: scale(0.95);
}

.level-info { text-align: center; }
.level-label {
    display: block;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 2px;
    color: #8994a5;
}
.level-info h1 {
    font-size: 30px;
    margin-top: 2px;
}

.moves-box {
    min-width: 48px;
    height: 48px;
    border-radius: 16px;
    background: white;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 20px rgba(30, 50, 80, .10);
}
.moves-box span { font-size: 8px; font-weight: 700; color: #8b96a6; }
.moves-box strong { font-size: 16px; color: var(--primary); }

/* =================================
   FOOTER
================================= */
.game-footer {
    margin-top: auto;
    padding-top: 30px;
    display: flex;
    justify-content: center;
    gap: 18px;
}

.round-action {
    min-width: 110px;
    border: 0;
    border-radius: 18px;
    background: white;
    padding: 13px 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    color: var(--dark);
    font-weight: 600;
    box-shadow: 0 8px 20px rgba(30, 50, 80, .10);
    transition: transform 0.2s;
}
.round-action:active { transform: scale(0.95); }
.action-icon { font-size: 19px; }

/* =================================
   MODALS
================================= */
.success-popup {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(16, 28, 50, .45);
    backdrop-filter: blur(5px);
}
.success-popup.show { display: flex; }

.success-box {
    width: 100%;
    max-width: 360px;
    padding: 36px 30px;
    border-radius: 30px;
    text-align: center;
    background: white;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
}
.success-icon {
    width: 72px; height: 72px;
    margin: 0 auto 20px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    background: #e6f7ee; color: var(--success); font-size: 36px; font-weight: bold;
}
.success-box h2 { font-size: 27px; margin-bottom: 10px; }
.success-box p { color: #7d8797; margin-bottom: 25px; }

.primary-btn {
    width: 100%;
    border: 0; border-radius: 16px;
    padding: 16px; background: var(--primary);
    color: white; font-size: 18px; font-weight: bold;
    cursor: pointer; box-shadow: 0 8px 20px rgba(36, 111, 229, .3);
    transition: transform 0.2s;
}
.primary-btn:active { transform: scale(0.98); }

/* Difficulty Badge */
.difficulty-badge {
    font-size: 0.75rem;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 12px;
    margin-left: 10px;
    text-transform: uppercase;
    display: inline-block;
    vertical-align: middle;
}

.diff-easy {
    background: #e0f8e0;
    color: #2e8b57;
}

.diff-medium {
    background: #fff0d4;
    color: #d97706;
}

.diff-hard {
    background: #ffe4e1;
    color: #dc143c;
}

/* Screens */
.screen {
    display: none;
    flex-direction: column;
    height: 100%;
    width: 100%;
}
.screen.active {
    display: flex;
}
.hidden {
    display: none !important;
}

/* Level Grid */
.level-grid-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}
.level-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    gap: 15px;
}
.level-btn {
    aspect-ratio: 1;
    border-radius: 16px;
    border: none;
    background: white;
    color: var(--primary);
    font-size: 20px;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.level-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(0,0,0,0.1);
}
.level-btn:active:not(:disabled) {
    transform: translateY(0);
}
.level-btn:disabled {
    background: #e2e8f0;
    color: #94a3b8;
    cursor: not-allowed;
    box-shadow: none;
}

/* Category Select */
.category-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 20px;
    justify-content: center;
    flex: 1;
}
.category-btn {
    border-radius: 16px;
    border: none;
    padding: 30px 20px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    transition: transform 0.2s, box-shadow 0.2s;
    text-align: center;
}
.category-btn h2 {
    margin: 0;
    font-size: 24px;
    font-weight: 800;
}
.category-btn p {
    margin: 5px 0 0 0;
    font-size: 16px;
    opacity: 0.8;
}
.category-btn:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
}
.category-btn:active {
    transform: translateY(0);
}

/* =================================
   LOADER
================================= */
.game-loader {
    position: absolute;
    inset: 0;
    z-index: 1000;
    background: linear-gradient(135deg, #eef3f9, #e4eaf2);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.5s, visibility 0.5s;
}
.game-loader.hidden {
    opacity: 0;
    visibility: hidden;
}
.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid rgba(36, 111, 229, 0.2);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}
.game-loader h2 {
    color: var(--dark);
    font-size: 24px;
    font-weight: 900;
    letter-spacing: 2px;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}
