* {
    box-sizing: border-box;
    user-select: none;
}

body {
    font-family: 'Segoe UI', Arial, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
}

body.game-active {
    background: #ffffff;
}

@media (min-width: 901px) {
    body {
        overflow: hidden;
    }
}

/* ===== DIFFICULTY SELECTION SCREEN ===== */
#difficulty-screen {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 80vh;
    width: 100%;
}

#difficulty-box {
    background: white;
    border-radius: 20px;
    padding: 40px 50px;
    max-width: 550px;
    width: 100%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    animation: popIn 0.5s ease;
}

@keyframes popIn {
    0% {
        transform: scale(0.8) translateY(-20px);
        opacity: 0;
    }
    100% {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

#difficulty-box h1 {
    margin: 0 0 10px 0;
    color: #2d3748;
    font-size: 36px;
}

#difficulty-box .subtitle {
    color: #718096;
    margin-bottom: 25px;
    font-size: 16px;
}

.hub-link {
    display: inline-block;
    color: #4a6fa5;
    font-weight: bold;
    text-decoration: none;
    margin-bottom: 16px;
}

.hub-link:hover {
    text-decoration: underline;
}

/* ===== INSTRUCTIONS ===== */
#instructions {
    background: #f7fafc;
    border-radius: 12px;
    padding: 15px 20px;
    margin-bottom: 25px;
    text-align: left;
    border: 2px solid #e2e8f0;
    text-shadow: none;
}

#instructions h3 {
    margin: 0 0 10px 0;
    color: #2d3748;
    font-size: 16px;
    text-align: center;
}

#instructions ul {
    margin: 0;
    padding-left: 20px;
    color: #2d3748;
    font-size: 14px;
    line-height: 1.8;
}

#instructions ul li {
    margin-bottom: 4px;
}

#instructions ul li strong {
    color: #2d3748;
}

#instructions ul li em {
    color: #4a5568;
}

#difficulty-box p {
    color: #718096;
    margin: 15px 0 20px 0;
    font-size: 16px;
}

#difficulty-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 25px;
}

.difficulty-btn {
    display: flex;
    align-items: center;
    padding: 15px 20px;
    border: 3px solid #e2e8f0;
    border-radius: 12px;
    background: white;
    cursor: pointer;
    transition: all 0.3s ease;
    gap: 15px;
    width: 100%;
}

.difficulty-btn:hover {
    transform: translateX(5px);
    border-color: #4a6fa5;
    box-shadow: 0 4px 12px rgba(74, 111, 165, 0.2);
}

.difficulty-btn .difficulty-icon {
    font-size: 28px;
}

.difficulty-btn .difficulty-name {
    font-weight: bold;
    font-size: 18px;
    color: #2d3748;
}

.difficulty-btn .difficulty-desc {
    font-size: 14px;
    color: #718096;
    margin-left: auto;
}

.difficulty-btn.easy:hover {
    border-color: #48bb78;
    background: #f0fff4;
}

.difficulty-btn.medium:hover {
    border-color: #ecc94b;
    background: #fffff0;
}

.difficulty-btn.hard:hover {
    border-color: #fc8181;
    background: #fff5f5;
}

#best-times {
    display: flex;
    justify-content: space-around;
    padding-top: 20px;
    border-top: 2px solid #e2e8f0;
}

.best-time-item {
    font-size: 14px;
    color: #4a5568;
}

.best-time-item span {
    font-weight: bold;
    color: #2d3748;
}

/* ===== GAME SCREEN ===== */
#game-screen {
    display: none;
    gap: 30px;
    align-items: flex-start;
    justify-content: center;
    padding: 20px;
    min-height: 80vh;
}

#game-container {
    background: white;
    border-radius: 12px;
    padding: 25px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.15);
    display: inline-block;
    flex-shrink: 0;
}

#game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding: 0 4px;
    width: 100%;
    gap: 15px;
    flex-wrap: wrap;
}

#header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

#header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

#game-header button {
    padding: 6px 14px;
    border: none;
    border-radius: 6px;
    background: #718096;
    color: white;
    font-weight: bold;
    cursor: pointer;
    font-size: 13px;
    transition: background 0.2s;
    white-space: nowrap;
}

#game-header button:hover {
    background: #4a5568;
}

#game-header .hub-link {
    margin-bottom: 0;
    font-size: 13px;
}

#difficulty-label {
    font-weight: bold;
    font-size: 14px;
    color: #4a6fa5;
    padding: 4px 12px;
    background: #ebf4ff;
    border-radius: 20px;
}

#progress-label {
    font-weight: bold;
    font-size: 14px;
    color: #2d7d46;
    padding: 4px 12px;
    background: #f0fff4;
    border-radius: 20px;
    transition: all 0.3s ease;
}

canvas {
    border-radius: 8px;
    border: none;
    cursor: pointer;
    display: block;
    background: #ffffff;
    touch-action: none;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.05);
    width: 100%;
    height: auto;
    max-width: 600px;
}

#controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 15px;
    gap: 10px;
    flex-wrap: wrap;
}

#controls .control-group {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

#controls button {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    background: #4a6fa5;
    color: white;
    font-weight: bold;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
    white-space: nowrap;
}

#controls button:hover {
    background: #3a5a8a;
}

#controls button:disabled {
    background: #cbd5e0;
    cursor: not-allowed;
}

#controls button.undo-btn {
    background: #ecc94b;
    color: #2d3748;
}

#controls button.undo-btn:hover:not(:disabled) {
    background: #d4a830;
}

#controls button.undo-btn:disabled {
    background: #e2e8f0;
}

#info {
    display: flex;
    gap: 20px;
    font-size: 14px;
    color: #333;
    flex-wrap: wrap;
}

#info span {
    font-weight: bold;
    color: #4a6fa5;
}

/* ===== PROGRESS SIDEBAR ===== */
#progress-sidebar {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.15);
    min-width: 220px;
    max-width: 280px;
    max-height: 500px;
    overflow-y: auto;
    position: sticky;
    top: 20px;
    flex-shrink: 0;
}

#progress-sidebar h3 {
    margin: 0 0 15px 0;
    color: #2d3748;
    font-size: 18px;
    text-align: center;
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 10px;
}

#messages-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.progress-message-item {
    padding: 10px 12px;
    border-radius: 8px;
    background: #f7fafc;
    border-left: 4px solid #4a6fa5;
    animation: slideIn 0.3s ease;
    font-size: 14px;
    line-height: 1.4;
    color: #2d3748;
}

.progress-message-item .message-icon {
    margin-right: 6px;
}

.progress-message-item .message-time {
    font-size: 11px;
    color: #a0aec0;
    margin-top: 4px;
    display: block;
}

@keyframes slideIn {
    0% {
        opacity: 0;
        transform: translateX(-20px);
    }
    100% {
        opacity: 1;
        transform: translateX(0);
    }
}

/* ===== WIN OVERLAY ===== */
#win-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: none;
    justify-content: center;
    align-items: flex-start;
    padding-top: 15vh;
    z-index: 100;
}

#win-box {
    background: white;
    border-radius: 16px;
    padding: 30px 40px;
    max-width: 420px;
    text-align: center;
    box-shadow: 0 12px 40px rgba(0,0,0,0.3);
    animation: popIn 0.3s ease;
    margin: 0 20px;
}

#win-box h2 {
    margin: 0 0 10px 0;
    color: #2d7d46;
}

#win-box p {
    margin: 8px 0;
    color: #444;
    font-size: 16px;
}

#win-box .btn-group {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 18px;
}

#win-box .btn-group button {
    padding: 10px 24px;
    border: none;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    font-size: 15px;
}

#win-box .btn-group .play-again {
    background: #4a6fa5;
    color: white;
}

#win-box .btn-group .play-again:hover {
    background: #3a5a8a;
}

#win-box .btn-group .close-btn {
    background: #e74c3c;
    color: white;
}

#win-box .btn-group .close-btn:hover {
    background: #c0392b;
}

.confetti {
    position: fixed;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    pointer-events: none;
    animation: confettiFall linear forwards;
    z-index: 1000;
}

@keyframes confettiFall {
    0% {
        transform: translateY(-10px) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(110vh) rotate(720deg);
        opacity: 0;
    }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
    #game-screen {
        flex-direction: column;
        align-items: center;
        gap: 20px;
    }
    
    #progress-sidebar {
        min-width: unset;
        max-width: 100%;
        width: 100%;
        position: static;
        max-height: 200px;
    }
    
    canvas {
        max-width: 100%;
    }
}

@media (max-width: 600px) {
    #difficulty-box {
        padding: 20px 25px;
        max-height: 95vh;
        overflow-y: auto;
    }
    
    #difficulty-box h1 {
        font-size: 28px;
    }
    
    .difficulty-btn {
        padding: 12px 15px;
    }
    
    .difficulty-btn .difficulty-desc {
        font-size: 12px;
    }
    
    #game-container {
        padding: 15px;
    }

    #game-container canvas {
        height: 220px !important;
    }
    
    #game-header {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    
    #header-left,
    #header-right {
        justify-content: center;
    }
    
    #controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    #controls .control-group {
        justify-content: center;
    }
    
    #info {
        justify-content: center;
        gap: 15px;
        font-size: 13px;
    }
    
    #game-header button,
    #controls button {
        padding: 10px 16px;
        font-size: 14px;
        min-height: 44px;
    }
    
    #win-box {
        padding: 20px;
        margin: 0 15px;
    }
    
    #best-times {
        flex-direction: column;
        gap: 8px;
    }
}

@media (max-width: 400px) {
    #game-container {
        padding: 10px;
    }

    #game-container canvas {
        height: 190px !important;
    }
    
    #info {
        gap: 10px;
        font-size: 12px;
    }
    
    #game-header button,
    #controls button {
        font-size: 12px;
        padding: 8px 12px;
        min-height: 38px;
    }
}

/* Touch-friendly improvements */
@media (pointer: coarse) {
    #controls button,
    #game-header button {
        padding: 12px 20px;
        font-size: 16px;
        min-height: 48px;
    }
    
    .difficulty-btn {
        padding: 16px 20px;
    }
    
    canvas {
        touch-action: none;
    }
}