* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: system-ui, sans-serif;
    background: #1a0f0a;
    color: #f5f5f5;
}

#game-container {
    width: 100%;
    height: 100%;
    position: relative;
}

#game-canvas {
    width: 100%;
    height: 100%;
    display: block;
    outline: none;
}

/* UI Overlay */
#ui-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.top-bar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: linear-gradient(180deg, rgba(44, 24, 16, 0.95) 0%, rgba(44, 24, 16, 0.8) 100%);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    z-index: 10;
}

.score-container,
.time-container,
.moves-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.label {
    font-size: 14px;
    color: #d4a574;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.value {
    font-size: 18px;
    font-weight: 700;
    color: #f5f5f5;
    min-width: 50px;
    text-align: right;
}

/* Level Menu */
.level-menu {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #2c1810 0%, #1a0f0a 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    z-index: 20;
}

.game-title {
    font-size: 48px;
    font-weight: 800;
    background: linear-gradient(135deg, #d4a574 0%, #f5deb3 50%, #d4a574 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 10px;
    text-shadow: 0 4px 20px rgba(212, 165, 116, 0.3);
    letter-spacing: 4px;
}

.subtitle {
    font-size: 16px;
    color: #d4a574;
    margin-bottom: 40px;
    opacity: 0.9;
    text-align: center;
    max-width: 400px;
    line-height: 1.6;
}

.level-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    margin-bottom: 30px;
    padding: 20px;
    background: rgba(212, 165, 116, 0.1);
    border-radius: 12px;
}

.level-btn {
    width: 80px;
    height: 80px;
    border: 2px solid #d4a574;
    background: rgba(212, 165, 116, 0.2);
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.level-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(212, 165, 116, 0.4) 0%, transparent 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.level-btn:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(212, 165, 116, 0.3);
    border-color: #f5deb3;
}

.level-btn:hover::before {
    opacity: 1;
}

.level-btn.active {
    background: linear-gradient(135deg, #d4a574 0%, #b8956a 100%);
    border-color: #f5deb3;
    transform: scale(1.1);
}

.level-btn:active {
    transform: scale(0.95);
}

.level-btn.locked {
    opacity: 0.5;
    cursor: not-allowed;
}

.level-btn.locked::after {
    content: '🔒';
    position: absolute;
    font-size: 20px;
}

.level-number {
    font-size: 24px;
    font-weight: 700;
    color: #f5deb3;
    position: relative;
    z-index: 1;
}

.level-stars {
    font-size: 12px;
    margin-top: 2px;
    position: relative;
    z-index: 1;
}

.level-stars span {
    color: #d4a574;
    opacity: 0.3;
}

.level-stars span.earned {
    opacity: 1;
}

/* Buttons */
.btn {
    padding: 12px 32px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
    position: relative;
    overflow: hidden;
}

.btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s ease;
}

.btn:hover::before {
    left: 100%;
}

.btn:active {
    transform: scale(0.95);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: linear-gradient(135deg, #d4a574 0%, #b8956a 100%);
    color: #1a0f0a;
}

.btn-primary:hover:not(:disabled) {
    box-shadow: 0 6px 20px rgba(212, 165, 116, 0.4);
    transform: translateY(-2px);
}

.btn-secondary {
    background: rgba(212, 165, 116, 0.2);
    color: #f5deb3;
    border: 2px solid #d4a574;
}

.btn-secondary:hover:not(:disabled) {
    background: rgba(212, 165, 116, 0.4);
    border-color: #f5deb3;
}

.btn-large {
    padding: 16px 48px;
    font-size: 18px;
}

.btn-text {
    position: relative;
    z-index: 1;
}

/* Game Menu */
.game-menu {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(26, 15, 10, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    z-index: 30;
}

.menu-content {
    text-align: center;
    max-width: 400px;
    width: 90%;
}

.menu-title {
    font-size: 36px;
    font-weight: 800;
    color: #d4a574;
    margin-bottom: 30px;
    text-shadow: 0 2px 10px rgba(212, 165, 116, 0.3);
}

.menu-stats {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 30px;
}

.stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: rgba(212, 165, 116, 0.1);
    border-radius: 8px;
    border: 1px solid rgba(212, 165, 116, 0.2);
}

.stat-label {
    font-size: 14px;
    color: #d4a574;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
    color: #f5deb3;
}

.new-record {
    margin-bottom: 20px;
}

.record-badge {
    background: linear-gradient(135deg, #ffd700 0%, #ff8c00 100%);
    color: #1a0f0a;
    padding: 10px 20px;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Level Complete Overlay */
.level-complete {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(26, 15, 10, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    z-index: 25;
}

.overlay-content {
    text-align: center;
    max-width: 450px;
    width: 90%;
}

.checkmark, .crossmark {
    font-size: 80px;
    margin-bottom: 20px;
}

.checkmark {
    color: #4ade80;
    animation: scaleIn 0.5s ease;
}

.crossmark {
    color: #ef4444;
    animation: scaleIn 0.3s ease;
}

@keyframes scaleIn {
    from {
        transform: scale(0);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.overlay-title {
    font-size: 36px;
    font-weight: 800;
    color: #d4a574;
    margin-bottom: 25px;
    text-shadow: 0 2px 10px rgba(212, 165, 116, 0.3);
}

.gameover-text {
    font-size: 16px;
    color: #d4a574;
    margin-bottom: 30px;
    opacity: 0.9;
}

.overlay-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    margin-bottom: 30px;
}

.overlay-stat {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.overlay-stat-label {
    font-size: 11px;
    color: #d4a574;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.overlay-stat-value {
    font-size: 20px;
    font-weight: 700;
    color: #f5deb3;
}

/* Buttons in overlay */
.overlay .menu-buttons {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

.overlay .btn {
    flex: 1;
    min-width: 140px;
}

/* Buttons */
.hint-btn,
.reset-btn,
.pause-btn {
    position: absolute;
    top: 70px;
    right: 20px;
    width: 44px;
    height: 44px;
    border: 2px solid #d4a574;
    background: rgba(212, 165, 116, 0.2);
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    transition: all 0.3s ease;
    z-index: 15;
    color: #f5deb3;
}

.hint-btn:hover,
.reset-btn:hover,
.pause-btn:hover {
    background: rgba(212, 165, 116, 0.4);
    border-color: #f5deb3;
    transform: translateY(-2px);
}

.hint-btn:active,
.reset-btn:active,
.pause-btn:active {
    transform: translateY(0);
}

.hint-btn:disabled,
.reset-btn:disabled,
.pause-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.hint-icon,
.reset-icon,
.pause-icon,
.play-icon {
    width: 20px;
    height: 20px;
    stroke-width: 2;
}

/* Loading Screen */
.loading-screen {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #1a0f0a;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 100;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(212, 165, 116, 0.2);
    border-top-color: #d4a574;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-text {
    font-size: 16px;
    color: #d4a574;
    letter-spacing: 2px;
    animation: pulse 1.5s ease-in-out infinite;
}

/* Overlay */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(26, 15, 10, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    z-index: 40;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.overlay.visible {
    opacity: 1;
    visibility: visible;
}

/* Responsive Design */
@media (max-width: 600px) {
    .top-bar {
        height: 50px;
        padding: 0 10px;
    }

    .label {
        font-size: 11px;
    }

    .value {
        font-size: 14px;
        min-width: 40px;
    }

    .game-title {
        font-size: 32px;
        letter-spacing: 2px;
    }

    .subtitle {
        font-size: 14px;
        padding: 0 20px;
    }

    .level-grid {
        gap: 10px;
        padding: 15px;
    }

    .level-btn {
        width: 65px;
        height: 65px;
    }

    .level-number {
        font-size: 20px;
    }

    .level-stars {
        font-size: 10px;
    }

    .btn-large {
        padding: 14px 32px;
        font-size: 16px;
    }

    .overlay .menu-buttons {
        flex-direction: column;
        width: 100%;
    }

    .overlay .btn {
        width: 100%;
    }

    .hint-btn,
    .reset-btn,
    .pause-btn {
        width: 40px;
        height: 40px;
        top: 60px;
        right: 15px;
    }
}

/* Animation Classes */
.hidden {
    display: none !important;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn 0.5s ease forwards;
}

/* Mobile Touch Feedback */
@media (pointer: coarse) {
    .level-btn,
    .hint-btn,
    .reset-btn,
    .pause-btn {
        min-width: 44px;
        min-height: 44px;
    }
}
