/* ===========================================
   Wake Up and Win - Timer Styles
   =========================================== */

/* CSS Custom Properties */
:root {
    --color-primary: #E74C5C;
    --color-gold: #D4A84B;
    --color-urgent: #E74C5C;
    --color-warning: #FFEA00;
    --color-text: #FFFFFF;
    --color-bg-overlay: rgba(0, 0, 0, 0.4);
    --color-timer-track: rgba(255, 255, 255, 0.2);
    --color-timer-ring: var(--color-gold);
    
    --timer-size: min(70vw, 70vh, 320px);
    /* Outer gauge thickness */
    --stroke-width: 14;
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Open Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--color-primary);
    background-image: url('logos/background.png');
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    background-repeat: no-repeat;
    color: var(--color-text);
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

/* App Container */
#root {
    display: grid;
    grid-template-rows: auto 1fr auto;
    min-height: 100dvh;
    padding: 16px;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    overflow: visible;
}

/* ===========================================
   Top Bar
   =========================================== */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    gap: 16px;
}

.logo {
    height: 96px;
    width: auto;
    max-width: 280px;
    object-fit: contain;
    filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.3));
}

.icon-btn {
    width: 48px;
    height: 48px;
    border: none;
    background: var(--color-bg-overlay);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-radius: 50%;
    color: var(--color-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, background 0.15s ease;
    font-size: 24px;
    font-weight: 700;
}

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

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

.icon-btn svg {
    width: 24px;
    height: 24px;
}

/* Mute toggle states */
#mute-toggle .icon-muted {
    display: none;
}

#mute-toggle.muted .icon-unmuted {
    display: none;
}

#mute-toggle.muted .icon-muted {
    display: block;
}

/* ===========================================
   Timer Area
   =========================================== */
.timer-area {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    overflow: visible; /* let glow extend beyond timer box */
}

.timer-container {
    position: relative;
    width: var(--timer-size);
    height: var(--timer-size);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.15s ease;
    overflow: visible; /* Allow glow to extend beyond */
}

.timer-container:active {
    transform: scale(0.97);
}

/* Tap hint text below timer */
.tap-hint {
    position: absolute;
    bottom: -40px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 14px;
    font-weight: 500;
    opacity: 0.8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.state-running .tap-hint,
.state-precount .tap-hint {
    opacity: 0.5;
}

/* Inline reset button shown when paused */
.inline-reset {
    position: absolute;
    bottom: -72px;
    left: 50%;
    transform: translateX(-50%);
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    border-radius: 999px;
    border: none;
    background: rgba(0, 0, 0, 0.6);
    color: var(--color-text);
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease, background 0.15s ease;
}

.inline-reset:active {
    transform: translateX(-50%) scale(0.96);
}

.state-paused .inline-reset {
    opacity: 1;
    pointer-events: auto;
}

/* Timer Circle SVG */
#timer-circle {
    position: absolute;
    width: 100%;
    height: 100%;
    left: 0;
    top: 0;
    /* Rotate to start at 12 o'clock, then flip vertically so positive offset drains clockwise */
    transform: rotate(-90deg) scaleY(-1);
    pointer-events: none; /* Allow clicks to pass through */
}

.timer-track,
.timer-progress,
.timer-glow {
    fill: none;
    stroke-width: var(--stroke-width);
    stroke-linecap: round;
}

.timer-track {
    stroke: rgba(255, 255, 255, 0.15);
}

.timer-progress {
    stroke: var(--color-gold);
    stroke-dasharray: 565.48; /* 2 * PI * 90 */
    /* Start full; JS will set negative offset to drain clockwise */
    stroke-dashoffset: 0;
    transition: stroke 0.3s ease;
}

.timer-glow {
    /* Glow disabled per spec */
    stroke: transparent;
    stroke-width: 0;
    opacity: 0;
    stroke-dasharray: 0;
    stroke-dashoffset: 0;
}

/* Timer Display */
.timer-display {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Simple solid inner disk – no inner glow/blur */
    background: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    /* Smaller inner disk so the gauge sits clearly OUTSIDE, not under it */
    width: calc(var(--timer-size) - 46px);
    height: calc(var(--timer-size) - 46px);
    pointer-events: none; /* Allow clicks to pass through to timer-container */
}

.timer-number {
    font-size: clamp(60px, 19.25vw, 130px);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    text-shadow: 0 2px 16px rgba(0, 0, 0, 0.3);
    line-height: 1;
    text-align: center;
    transition: font-size 0.3s ease;
}

/* Launch text styling - READY / GO! in white */
.timer-number.launch-text {
    font-size: clamp(28px, 10vw, 56px);
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.15em;
    text-align: center;
    color: var(--color-text);
    text-shadow: 0 0 30px rgba(255, 255, 255, 0.8), 0 4px 20px rgba(0, 0, 0, 0.4);
}

/* GO! text - bigger and bolder */
.timer-number.launch-text.go-text {
    font-size: clamp(45px, 14vw, 96px);
    letter-spacing: 0.1em;
    text-shadow: 0 0 50px rgba(255, 255, 255, 0.9), 0 0 80px rgba(212, 168, 75, 0.6), 0 4px 20px rgba(0, 0, 0, 0.4);
}

/* TIME'S UP! text - white and bold */
.timer-number.launch-text.times-up-text {
    font-size: clamp(24px, 8vw, 56px);
    letter-spacing: 0.08em;
    color: #ffffff;
    text-shadow: 0 0 40px rgba(255, 255, 255, 0.9), 0 4px 20px rgba(0, 0, 0, 0.5);
}

.precount-number {
    position: absolute;
    font-size: clamp(72px, 20vw, 140px);
    font-weight: 800;
    opacity: 0;
    transform: scale(0.8);
    text-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

/* Timer Halo (for finished state) */
.timer-halo {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 3px solid var(--color-gold);
    opacity: 0;
    transform: scale(1);
    pointer-events: none;
}

/* ===========================================
   Control Area (now just holds the tap hint)
   =========================================== */
.control-area {
    display: none; /* Hidden - interaction is now on the timer */
}

/* Idle state - pulsing ring to invite tap */
@keyframes idle-ring-pulse {
    0%, 100% {
        filter: drop-shadow(0 0 20px rgba(212, 168, 75, 0.4));
    }
    50% {
        filter: drop-shadow(0 0 35px rgba(212, 168, 75, 0.7));
    }
}

.state-idle #timer-circle {
    animation: idle-ring-pulse 2s ease-in-out infinite;
}

/* Precount state - hide timer number, disable button */
.state-precount .timer-number {
    opacity: 0;
}

/* But show launch text (like "Get Ready") during precount */
.state-precount .timer-number.launch-text {
    opacity: 1;
}

.state-precount .control-btn {
    pointer-events: none;
    opacity: 0.7;
}

/* ===========================================
   State-specific styles
   =========================================== */

/* Finished state */
.state-finished .timer-number {
    color: var(--color-gold);
}

/* Flash effect when timer hits zero */
@keyframes zero-flash-bg {
    /* Start dark */
    0%, 100% {
        background: rgba(0, 0, 0, 0.5);
    }
    /* Three white pulses spread across 2.4s */
    8%, 12% {
        background: #ffffff;
    }
    20%, 100% {
        background: rgba(0, 0, 0, 0.5);
    }
    40%, 44% {
        background: #ffffff;
    }
    52%, 100% {
        background: rgba(0, 0, 0, 0.5);
    }
    72%, 76% {
        background: #ffffff;
    }
}

@keyframes zero-flash-text {
    0%, 100% {
        color: #ffffff;
    }
    8%, 12% {
        color: var(--color-urgent);
    }
    20%, 100% {
        color: #ffffff;
    }
    40%, 44% {
        color: var(--color-urgent);
    }
    52%, 100% {
        color: #ffffff;
    }
    72%, 76% {
        color: var(--color-urgent);
    }
}

.zero-flash .timer-display {
    animation: zero-flash-bg 2.4s linear 1;
}

.zero-flash .timer-number {
    animation: zero-flash-text 2.4s linear 1;
}

/* Urgent state (last 5 seconds) - white for contrast against red background */
.urgent .timer-progress,
.urgent .timer-glow {
    stroke: var(--color-text);
}

.urgent .timer-number {
    color: var(--color-text);
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.8), 0 2px 16px rgba(0, 0, 0, 0.3);
    animation: urgent-pulse 0.5s ease-in-out infinite;
}

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

/* Warning state (15-5 seconds) */
.warning .timer-progress,
.warning .timer-glow {
    stroke: var(--color-warning);
}

/* ===========================================
   Intro Screen
   =========================================== */
.intro-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--color-primary);
    background-image: url('logos/background.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
    overflow: hidden;
    /* Start visible */
    opacity: 1;
    display: flex;
}

.intro-screen.hidden {
    opacity: 0;
    pointer-events: none;
    display: none;
}

/* Ensure intro is displayed only when active */
.intro-screen[style*="display: none"] {
    display: none !important;
}

.intro-header {
    flex: 0 0 auto;
    text-align: center;
    padding-top: 8px; /* Match main screen top bar padding (8px) + alignment */
    margin-bottom: 20px;
}

.intro-logo {
    height: 96px; /* Match main screen logo height */
    width: auto;
    max-width: 90%;
    object-fit: contain;
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.3));
}

.intro-content {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 10; /* Above presenters */
}

.intro-buttons {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
    max-width: 320px;
    margin-top: 20px;
}

.intro-btn {
    padding: 16px 24px;
    border-radius: 999px;
    border: none;
    font-family: inherit;
    font-size: 16px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    transition: transform 0.1s ease, filter 0.2s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

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

.intro-btn.primary {
    background: #ffffff;
    color: var(--color-primary);
    font-size: 20px;
}

.intro-btn.secondary {
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: #ffffff;
    border: 2px solid rgba(255, 255, 255, 0.3);
}


.intro-gradient {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 250px; /* Adjustable height for gradient */
    background: linear-gradient(to top, rgba(0,0,0,0.8) 0%, rgba(0,0,0,0.6) 40%, rgba(0,0,0,0) 100%);
    pointer-events: none;
    z-index: 2; /* Above presenters image, below footer text */
}

.intro-footer {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    z-index: 3; /* Text above gradient */
    text-align: center;
    background: transparent;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    padding-left: 16px;
    padding-right: 16px;
    pointer-events: auto;
    /* Match alignment with presenters */
    max-width: 500px;
    margin: 0 auto;
}

.footer-logos {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 24px;
    margin-bottom: 12px;
}

.footer-logo {
    height: 32px;
    width: auto;
    object-fit: contain;
    opacity: 0.9;
}

.footer-logo.heart {
    height: 28px;
}

.footer-logo.big-sky {
    height: 56px;
}

.trademark-text {
    font-size: 10px;
    opacity: 0.7;
    line-height: 1.4;
    max-width: 400px;
    margin: 0 auto;
}

/* ===========================================
   Instructions Modal
   =========================================== */
.instructions-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2000;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1;
}

.instructions-modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background: #ffffff;
    color: #333;
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    border-radius: 20px;
    padding: 0;
    padding-bottom: 24px;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    -webkit-overflow-scrolling: touch;
}

.modal-header {
    position: sticky;
    top: 0;
    z-index: 20;
    background: #ffffff;
    padding: 24px 16px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    margin-bottom: 24px;
}

.modal-close-btn {
    position: absolute;
    top: 50%;
    right: 16px;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.05);
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #333;
    transition: background 0.2s;
    z-index: 10;
}

.modal-close-btn:hover {
    background: rgba(0, 0, 0, 0.1);
}

.modal-content h2 {
    font-size: 28px;
    color: var(--color-primary);
    margin: 0;
    text-align: center;
    font-weight: 800;
    text-transform: uppercase;
    padding: 0 40px; /* Prevent overlap with button */
}

.rules-section {
    padding: 0 24px;
    margin-bottom: 24px;
}

.rules-section h3 {
    font-size: 18px;
    color: var(--color-primary);
    margin-bottom: 8px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 2px solid #eee;
    padding-bottom: 4px;
}

.rules-section p {
    font-size: 15px;
    line-height: 1.6;
    margin-bottom: 8px;
    color: #444;
}

.rules-section p:last-child {
    margin-bottom: 0;
}

/* ===========================================
   Landscape Layout
   =========================================== */
@media (orientation: landscape) and (max-height: 500px) {
    #root {
        grid-template-rows: 1fr;
        grid-template-columns: auto 1fr;
        align-items: center;
        gap: 16px;
    }
    
    .top-bar {
        flex-direction: column;
        justify-content: center;
    }
    
    .logo {
        display: none;
    }
    
    .timer-area {
        grid-column: 2;
    }
    
    .control-area {
        display: none;
    }
    
    :root {
        --timer-size: min(50vw, 70dvh, 280px);
    }
    
    .tap-hint {
        bottom: -32px;
        font-size: 12px;
    }
    
    /* Landscape adjustments for intro */
    .intro-screen {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        justify-content: center;
    }
    
    .intro-header {
        position: absolute;
        top: 16px;
        left: auto;
        right: 20px; /* Align with presenters */
        width: 45%; /* Match presenters width */
        margin: 0;
        padding: 0;
        z-index: 5;
        display: flex;
        justify-content: center;
    }
    
    .intro-logo {
        height: 60px;
    }
    
    .intro-content {
        width: 50%;
        align-items: flex-start;
        padding-left: 60px; /* More space from left edge */
        padding-top: 0;
        padding-bottom: 80px; /* Push buttons up visually */
    }
    
    
    .intro-footer {
        /* Move to right column under presenters */
        left: auto;
        right: 20px;
        width: 45%;
        margin: 0;
        bottom: 0;
        padding-left: 0;
        padding-right: 0;
        background: transparent;
        z-index: 3;
    }
    
    .intro-gradient {
        display: block;
        z-index: 2;
    }
    
    .trademark-text {
        text-shadow: 0 1px 4px rgba(0,0,0,0.8);
        font-size: 9px; /* Slightly smaller for tighter column */
    }
}

/* ===========================================
   Reduced Motion
   =========================================== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .state-idle .control-btn {
        animation: none;
        box-shadow: 
            0 4px 16px rgba(212, 168, 75, 0.4),
            0 0 0 4px rgba(212, 168, 75, 0.2);
    }
}

/* Utilities */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Hide main UI elements during initial intro load */
.initial-load .top-bar,
.initial-load .timer-area,
.initial-load .control-area {
    visibility: hidden;
}
