/* ========================================
   CSS VARIABLES & BASE RESET
   ======================================== */
:root {
    /* Player Colors - Vibrant gradients */
    --player1-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --player2-gradient: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --player3-gradient: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    --player4-gradient: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);

    /* Player solid colors for text/accents */
    --player1-color: #764ba2;
    --player2-color: #f5576c;
    --player3-color: #00f2fe;
    --player4-color: #43e97b;

    /* UI Colors */
    --bg-dark: #0f0f1a;
    --bg-card: #1a1a2e;
    --text-primary: #ffffff;
    --text-secondary: #a0a0b0;
    --accent: #667eea;

    /* Timing */
    --transition-fast: 150ms;
    --transition-normal: 300ms;
    --transition-slow: 500ms;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
}

/* ========================================
   SCREEN MANAGEMENT
   ======================================== */
.screen {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-normal), visibility var(--transition-normal);
    padding: env(safe-area-inset-top) env(safe-area-inset-right)
             env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.screen.active {
    opacity: 1;
    visibility: visible;
}

/* ========================================
   MENU SCREEN
   ======================================== */
.menu-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.game-title {
    font-size: clamp(3rem, 12vw, 6rem);
    font-weight: 900;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, #667eea, #f5576c, #43e97b);
    background-size: 200% 200%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: gradient-shift 3s ease infinite;
}

.game-title span {
    display: block;
    font-size: 0.6em;
    letter-spacing: 0.2em;
    opacity: 0.8;
}

@keyframes gradient-shift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

.tagline {
    color: var(--text-secondary);
    font-size: 1.1rem;
    margin-bottom: 1rem;
}

/* ========================================
   BUTTONS
   ======================================== */
.btn-primary, .btn-secondary {
    padding: 1rem 2.5rem;
    font-size: 1.25rem;
    font-weight: 600;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.btn-primary {
    background: var(--player1-gradient);
    color: white;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
}

.btn-primary:active {
    transform: scale(0.96);
}

.btn-secondary {
    background: transparent;
    color: var(--text-secondary);
    border: 2px solid var(--text-secondary);
    margin-top: 1rem;
}

.btn-secondary:active {
    transform: scale(0.96);
    opacity: 0.8;
}

/* ========================================
   PLAYER SELECTION SCREEN
   ======================================== */
#screen-players h2,
#screen-rounds h2 {
    font-size: 1.5rem;
    margin-bottom: 2rem;
    color: var(--text-secondary);
}

.player-select-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-bottom: 1rem;
}

.player-btn {
    width: 5rem;
    height: 5rem;
    font-size: 2rem;
    font-weight: 700;
    border-radius: 50%;
    border: none;
    color: white;
    cursor: pointer;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.player-btn:active {
    transform: scale(0.92);
}

.player-btn[data-players="1"] {
    background: var(--player1-gradient);
    box-shadow: 0 4px 15px rgba(118, 75, 162, 0.4);
}
.player-btn[data-players="2"] {
    background: var(--player2-gradient);
    box-shadow: 0 4px 15px rgba(245, 87, 108, 0.4);
}
.player-btn[data-players="3"] {
    background: var(--player3-gradient);
    box-shadow: 0 4px 15px rgba(0, 242, 254, 0.3);
}
.player-btn[data-players="4"] {
    background: var(--player4-gradient);
    box-shadow: 0 4px 15px rgba(67, 233, 123, 0.3);
}

/* ========================================
   ROUND SELECTION SCREEN
   ======================================== */
.round-select {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1rem;
}

.round-btn {
    padding: 1.25rem 3rem;
    font-size: 1.25rem;
    font-weight: 600;
    border: 2px solid var(--accent);
    border-radius: 12px;
    background: transparent;
    color: white;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.round-btn:active {
    background: var(--accent);
    transform: scale(0.96);
}

/* ========================================
   GAME AREA LAYOUTS
   ======================================== */
#screen-game {
    padding: 0;
}

#game-container {
    width: 100%;
    height: 100%;
    display: grid;
    gap: 4px;
    background: var(--bg-dark);
}

/* Layout variations */
#game-container.players-1 {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
}

#game-container.players-2 {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
}

#game-container.players-3 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

#game-container.players-4 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

/* Player zones */
.player-zone {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    transition: filter var(--transition-fast);
}

.player-zone[data-player="1"] { background: var(--player1-gradient); }
.player-zone[data-player="2"] { background: var(--player2-gradient); }
.player-zone[data-player="3"] { background: var(--player3-gradient); }
.player-zone[data-player="4"] { background: var(--player4-gradient); }

/* Player label */
.player-zone::before {
    content: 'P' attr(data-player);
    position: absolute;
    top: 1rem;
    left: 1rem;
    font-size: 1.5rem;
    font-weight: 700;
    opacity: 0.5;
}

/* Rotation for player 1 in 2-player mode (faces opposite direction) */
#game-container.players-2 .player-zone[data-player="1"] {
    transform: rotate(180deg);
}

/* For 3 players, span the third player across the bottom */
#game-container.players-3 .player-zone[data-player="3"] {
    grid-column: span 2;
}

/* Tap feedback */
.player-zone.tapped {
    filter: brightness(0.7);
}

.player-zone.tapped::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.1);
}

.player-zone .tap-time {
    font-size: clamp(2rem, 8vw, 4rem);
    font-weight: 900;
    opacity: 0;
    transition: opacity var(--transition-fast);
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.player-zone.tapped .tap-time {
    opacity: 1;
}

/* ========================================
   COUNTDOWN OVERLAY
   ======================================== */
#countdown-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 10;
}

#countdown-number {
    font-size: clamp(6rem, 30vw, 12rem);
    font-weight: 900;
    color: white;
    text-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
    transition: opacity var(--transition-normal), transform var(--transition-normal);
}

#countdown-number.hidden {
    opacity: 0;
    transform: scale(0.8);
}

#countdown-number.pulse {
    animation: number-pulse 0.3s ease-out;
}

@keyframes number-pulse {
    0% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

/* ========================================
   RESULTS SCREENS
   ======================================== */
#screen-round-results,
#screen-final {
    gap: 1.5rem;
}

#screen-round-results h2 {
    font-size: 1.8rem;
    color: var(--text-secondary);
}

#round-results-list {
    width: 90%;
    max-width: 400px;
}

.result-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    margin: 0.5rem 0;
    border-radius: 12px;
    background: var(--bg-card);
    opacity: 0;
    transform: translateY(10px);
    animation: fade-in-up 0.4s ease-out forwards;
}

.result-item.winner {
    border: 2px solid var(--accent);
    box-shadow: 0 0 20px rgba(102, 126, 234, 0.3);
}

.player-label {
    font-weight: 600;
}

.result-time {
    font-size: 1.4rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.result-time.negative { color: #f5576c; }
.result-time.positive { color: #43e97b; }
.result-time.perfect { color: #ffd700; }
.result-time.no-tap { color: var(--text-secondary); }

#score-summary {
    color: var(--text-secondary);
    font-size: 1.1rem;
    margin-top: 0.5rem;
}

/* ========================================
   FINAL RESULTS SCREEN
   ======================================== */
.winner-announcement {
    text-align: center;
}

.winner-announcement h1 {
    font-size: clamp(2.5rem, 12vw, 5rem);
    background: linear-gradient(135deg, #667eea, #f5576c, #43e97b);
    background-size: 200% 200%;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: gradient-shift 2s ease infinite, winner-glow 1.5s ease-in-out infinite alternate;
}

@keyframes winner-glow {
    from { filter: drop-shadow(0 0 10px rgba(102, 126, 234, 0.5)); }
    to { filter: drop-shadow(0 0 25px rgba(102, 126, 234, 0.8)); }
}

.winner-badge {
    display: inline-block;
    padding: 1rem 2rem;
    font-size: 1.5rem;
    font-weight: 700;
    border-radius: 50px;
    color: white;
    margin-top: 1rem;
}

#final-scores {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin: 1rem 0;
}

.final-score-item {
    display: flex;
    justify-content: space-between;
    gap: 2rem;
    padding: 0.75rem 1.5rem;
    background: var(--bg-card);
    border-radius: 8px;
    min-width: 200px;
}

/* ========================================
   ANIMATIONS
   ======================================== */
@keyframes fade-in-up {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Stagger animation for result items */
.result-item:nth-child(1) { animation-delay: 0s; }
.result-item:nth-child(2) { animation-delay: 0.1s; }
.result-item:nth-child(3) { animation-delay: 0.2s; }
.result-item:nth-child(4) { animation-delay: 0.3s; }
