@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@600;700&family=Inter:wght@400;500;600&display=swap');

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: #0F172A;
    color: #F1F5F9;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

.header {
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.95) 0%, rgba(15, 23, 42, 0.8) 100%);
    backdrop-filter: blur(10px);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(59, 130, 246, 0.1);
}

.header-left {
    flex: 1;
}

h1 {
    font-family: 'Poppins', sans-serif;
    font-size: 1.75rem;
    font-weight: 700;
    background: linear-gradient(135deg, #3B82F6 0%, #10B981 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.125rem;
}

.subtitle {
    color: #94A3B8;
    font-size: 0.9rem;
    font-weight: 500;
}

.score-display {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(30, 41, 59, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 0.75rem;
    padding: 0.75rem 1rem;
    border: 1px solid rgba(59, 130, 246, 0.3);
    min-width: 120px;
    text-align: center;
    opacity: 0;
    transform: translateY(-10px);
    transition: all 0.3s ease;
    z-index: 15;
}

.score-display.visible {
    opacity: 1;
    transform: translateY(0);
}

.score-value {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, #10B981 0%, #3B82F6 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.score-label {
    color: #94A3B8;
    font-size: 0.625rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 0.125rem;
}

.score-rating {
    font-size: 0.75rem;
    font-weight: 600;
    margin-top: 0.25rem;
}

.score-rating.amazing {
    color: #10B981;
}

.score-rating.very-good {
    color: #3B82F6;
}

.score-rating.good {
    color: #06B6D4;
}

.score-rating.average {
    color: #F59E0B;
}

.score-rating.below-average {
    color: #EF4444;
}

.main-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1.5rem 2rem;
    max-width: 700px;
    margin: 0 auto;
    width: 100%;
}

.instructions-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(15, 23, 42, 0.98);
    backdrop-filter: blur(20px);
    border-radius: 1rem;
    padding: 2rem;
    border: 1px solid rgba(59, 130, 246, 0.3);
    width: 90%;
    max-width: 450px;
    z-index: 20;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translate(-50%, -45%);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
}

.instructions-overlay h2 {
    font-family: 'Poppins', sans-serif;
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: #F1F5F9;
    text-align: center;
}

.instructions-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.instructions-list {
    list-style: none;
    padding-left: 0;
}

.instructions-list li {
    color: #94A3B8;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}

.reaction-guide {
    background: rgba(30, 41, 59, 0.5);
    border-radius: 0.5rem;
    padding: 0.75rem;
}

.reaction-guide h3 {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: #F1F5F9;
}

.reaction-item {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    margin-bottom: 0.25rem;
    color: #94A3B8;
}

.reaction-item strong {
    font-weight: 600;
}

.game-box {
    background: linear-gradient(145deg, rgba(30, 41, 59, 0.95), rgba(15, 23, 42, 0.95));
    backdrop-filter: blur(20px);
    border-radius: 2rem;
    border: 1px solid rgba(59, 130, 246, 0.2);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    width: 100%;
    height: 400px;
    position: relative;
    overflow: hidden;
    transition: all 0.3s ease;
    margin-bottom: 1.5rem;
}

.game-box.idle {
    cursor: pointer;
}

.game-box.idle:hover {
    border-color: rgba(59, 130, 246, 0.4);
    box-shadow: 0 0 30px rgba(59, 130, 246, 0.1);
}

.game-box.waiting {
    border-color: rgba(245, 158, 11, 0.3);
    box-shadow: 0 0 50px rgba(245, 158, 11, 0.1);
}

.game-box.ready {
    border-color: rgba(16, 185, 129, 0.5);
    box-shadow: 0 0 50px rgba(16, 185, 129, 0.2);
    cursor: pointer;
}

.game-box.error {
    border-color: rgba(239, 68, 68, 0.5);
    box-shadow: 0 0 50px rgba(239, 68, 68, 0.2);
}

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

.click-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    cursor: pointer;
    display: none;
}

.click-overlay.active {
    display: block;
}

.error-message {
    position: absolute;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(239, 68, 68, 0.9);
    backdrop-filter: blur(10px);
    border-radius: 0.5rem;
    padding: 0.5rem 1rem;
    color: white;
    font-weight: 500;
    font-size: 0.875rem;
    z-index: 5;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.error-message.visible {
    opacity: 1;
}

.start-hint {
    position: absolute;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    color: rgba(59, 130, 246, 0.8);
    font-weight: 500;
    font-size: 0.875rem;
    text-align: center;
    pointer-events: none;
    z-index: 5;
}

.controls {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-bottom: 1.5rem;
}

button {
    background: linear-gradient(135deg, #3B82F6 0%, #2563EB 100%);
    color: white;
    border: none;
    padding: 0.875rem 1.75rem;
    border-radius: 0.75rem;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

button:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

button.secondary {
    background: rgba(30, 41, 59, 0.9);
    border: 1px solid rgba(59, 130, 246, 0.3);
}

/* Icon button for info */
.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem;
    width: 44px;
    height: 44px;
    border-radius: 0.75rem;
    position: relative;
}

.icon-button svg {
    color: #93C5FD;
}

/* Tooltip */
.icon-button[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: rgba(30, 41, 59, 0.95);
    color: #E2E8F0;
    border: 1px solid rgba(59, 130, 246, 0.3);
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    border-radius: 0.375rem;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
    z-index: 30;
}

.icon-button:hover::after {
    opacity: 1;
}

/* Allow JS to toggle instructions visibility */
.instructions-overlay[hidden] {
    display: none !important;
}

.stats-container {
    background: rgba(30, 41, 59, 0.9);
    backdrop-filter: blur(10px);
    border-radius: 1rem;
    padding: 1.5rem;
    border: 1px solid rgba(59, 130, 246, 0.2);
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2rem;
}

.stat-block {
    text-align: center;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #F1F5F9;
    display: block;
    margin-bottom: 0.25rem;
}

.stat-label {
    color: #94A3B8;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.desktop-only {
    display: inline;
}

@media (max-width: 768px) {
    .desktop-only {
        display: none;
    }
    
    h1 {
        font-size: 1.5rem;
    }
    
    .header {
        padding: 0.75rem 1rem;
    }
    
    .main-container {
        padding: 0.5rem 1rem;
    }
    
    .header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }
    
    .score-display {
        align-self: auto;
        padding: 0.6rem 0.9rem;
        min-width: 100px;
    }
    
    .score-value {
        font-size: 1.25rem;
    }
    
    .game-box {
        height: 350px;
        margin-bottom: 1rem;
    }
    
    .instructions-overlay {
        padding: 1.5rem;
        width: 95%;
    }
    
    .instructions-grid {
        grid-template-columns: 1fr;
    }
    
    .controls {
        margin-bottom: 1rem;
    }
    
    button {
        padding: 0.75rem 1.5rem;
        font-size: 0.9rem;
    }
    
    .stats-container {
        grid-template-columns: repeat(3, 1fr);
        gap: 1rem;
        padding: 1rem;
    }
    
    .score-value {
        font-size: 1.5rem;
    }
    
    .stat-value {
        font-size: 1.25rem;
    }
}

/* Make instructions overlay slightly larger than the canvas on mobile portrait */
@media (max-width: 768px) and (orientation: portrait) {
    .game-box {
        /* Allow overlay to extend beyond the canvas bounds */
        overflow: visible;
    }

    .instructions-overlay {
        /* Slightly wider than the game box/canvas */
        width: 101%;
        max-width: none;
    }
}
