:root {
    --primary-color: #6b7280; /* Neutral gray for a sleek look */
    --secondary-color: #10b981; /* Vibrant emerald for accents */
    --background-color: #111827; /* Darker, modern background */
    --text-color: #f3f4f6; /* Light gray for readability */
    --overlay-bg: rgba(17, 24, 39, 0.6); /* Slightly darker overlay for better contrast */
    --accent-color: #3b82f6; /* Blue accent for highlights */
}

body {
    font-family: 'Inter', sans-serif;
    margin: 0;
    padding: 0;
    overflow: hidden;
    background: linear-gradient(135deg, var(--background-color), #1f2937); /* Subtle gradient background */
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    width: 100vw;
    touch-action: manipulation;
}

#app-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

#video-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-radius: 12px; /* Rounded corners for a softer look */
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.3); /* Subtle shadow for depth */
}

video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
    border-radius: 12px;
}

#overlay-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

#timer-display {
    font-weight: 800;
    text-shadow: 0 0 12px rgba(59, 130, 246, 0.8); /* Blue glow for better visibility */
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 10;
    background: linear-gradient(45deg, var(--overlay-bg), rgba(31, 41, 55, 0.7)); /* Gradient overlay */
    padding: 1.2rem 2.5rem;
    border-radius: 1.5rem;
    white-space: nowrap;
    text-align: center;
    font-size: 2.5rem;
    letter-spacing: 1px; /* Improved readability */
    border: 1px solid rgba(59, 130, 246, 0.3); /* Subtle border */
}

#status-message {
    position: absolute;
    top: 1rem;
    left: 50%;
    transform: translateX(-50%);
    font-weight: 600;
    color: var(--text-color);
    z-index: 10;
    background: var(--overlay-bg);
    padding: 0.6rem 1.2rem;
    border-radius: 0.75rem;
    text-align: center;
    width: 90%;
    max-width: 500px;
    font-size: 0.95rem;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2); /* Soft shadow */
    backdrop-filter: blur(4px); /* Subtle blur for modern look */
}

#controls {
    position: absolute;
    bottom: 1.5rem;
    z-index: 10;
    display: flex;
    gap: 1.2rem;
    justify-content: center;
    width: 100%;
    padding: 0 1.2rem;
}

button {
    padding: 0.9rem 2rem;
    font-weight: 600;
    border-radius: 9999px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
    background-image: linear-gradient(90deg, var(--secondary-color), #34d399); /* Vibrant gradient */
    color: white;
    border: none;
    flex-grow: 1;
    max-width: 220px;
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

button:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.25);
    background-image: linear-gradient(90deg, #34d399, var(--secondary-color));
}

button:active {
    transform: translateY(0);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

#sensitivity-slider-container {
    position: absolute;
    bottom: 6rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    background: var(--overlay-bg);
    padding: 1rem 1.8rem;
    border-radius: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-direction: column;
    width: 85%;
    max-width: 520px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(4px);
}

#sensitivity-slider {
    width: 100%;
    -webkit-appearance: none;
    height: 10px;
    border-radius: 6px;
    background: linear-gradient(to right, #e5e7eb, #d1d5db); /* Light gradient track */
    outline: none;
    opacity: 0.85;
    transition: opacity 0.3s ease;
}

#sensitivity-slider:hover {
    opacity: 1;
}

#sensitivity-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--accent-color);
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s ease;
}

#sensitivity-slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

#sensitivity-slider::-moz-range-thumb {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--accent-color);
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s ease;
}

#sensitivity-slider::-moz-range-thumb:hover {
    transform: scale(1.1);
}

.message-box {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(17, 24, 39, 0.85); /* Darker semi-transparent background */
    color: var(--text-color);
    padding: 1.5rem;
    border-radius: 12px;
    z-index: 1000;
    text-align: center;
    box-shadow: 0 0 20px rgba(59, 130, 246, 0.5); /* Blue glow */
    display: none;
    width: 85%;
    max-width: 420px;
    backdrop-filter: blur(6px);
}

.message-box button {
    margin-top: 1rem;
    padding: 0.75rem 1.5rem;
    background-image: linear-gradient(90deg, var(--accent-color), #60a5fa);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    width: auto;
    text-transform: uppercase;
    font-size: 0.9rem;
}

.message-box button:hover {
    background-image: linear-gradient(90deg, #60a5fa, var(--accent-color));
    transform: translateY(-2px);
}

#laps-container {
    position: absolute;
    top: 4.5rem;
    right: 0.75rem;
    z-index: 10;
    background: var(--overlay-bg);
    padding: 0.75rem;
    border-radius: 0.75rem;
    max-height: 40%;
    overflow-y: auto;
    color: var(--text-color);
    width: 140px;
    font-size: 0.85rem;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(4px);
}

#laps-container h3 {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
    text-align: center;
    color: var(--secondary-color);
}

#laps-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

#laps-list li {
    padding: 0.3rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.15);
    font-size: 0.8rem;
    display: flex;
    justify-content: space-between;
    transition: background 0.2s ease;
}

#laps-list li:hover {
    background: rgba(255, 255, 255, 0.05); /* Subtle hover effect */
}

#laps-list li:last-child {
    border-bottom: none;
}

.calibrating-line {
    stroke: #facc15; /* Bright yellow for calibration */
    animation: pulseYellow 0.8s infinite alternate ease-in-out;
}

@keyframes pulseYellow {
    from { stroke: rgba(250, 204, 21, 0.5); }
    to { stroke: rgba(250, 204, 21, 1); }
}

.detection-line-flash {
    animation: lineFlash 0.3s ease-out forwards;
}

@keyframes lineFlash {
    from { stroke: rgba(16, 185, 129, 0.7); } /* Match secondary color */
    to { stroke: #34d399; }
}

/* Media queries for responsive design */
@media (min-width: 640px) {
    #timer-display {
        font-size: 3.5rem;
        padding: 1.2rem 2.5rem;
    }
    
    #status-message {
        font-size: 1.1rem;
        width: auto;
    }
    
    #laps-container {
        width: 160px;
        padding: 1rem;
        right: 1.5rem;
        top: 6.5rem;
    }
    
    #laps-container h3 {
        font-size: 1.1rem;
    }
    
    #laps-list li {
        font-size: 0.9rem;
    }
    
    #sensitivity-slider-container {
        bottom: 7rem;
    }
    
    #controls {
        bottom: 2.5rem;
    }
}

@media (min-width: 768px) {
    #timer-display {
        font-size: 4.5rem;
    }
    
    #laps-container {
        width: 200px;
        top: 8.5rem;
    }
}

@media (max-height: 600px) {
    #timer-display {
        font-size: 2.2rem;
        padding: 0.75rem 1.5rem;
    }
    
    #status-message {
        top: 0.75rem;
        font-size: 0.9rem;
        padding: 0.4rem 1rem;
    }
    
    #sensitivity-slider-container {
        bottom: 4.5rem;
        padding: 0.75rem 1.2rem;
    }
    
    #controls {
        bottom: 1rem;
    }
    
    #laps-container {
        top: 3.5rem;
        max-height: 50%;
    }
}

@media (max-width: 768px) and (orientation: landscape) {
    #timer-display {
        font-size: 2.2rem;
        padding: 0.75rem 1.5rem;
    }
    
    #status-message {
        top: 0.75rem;
        font-size: 0.9rem;
        padding: 0.4rem 1rem;
    }
    
    #sensitivity-slider-container {
        bottom: 4.5rem;
        padding: 0.75rem 1.2rem;
        flex-direction: row;
        width: 75%;
    }
    
    #controls {
        bottom: 1rem;
    }
    
    #laps-container {
        top: 3.5rem;
        right: 0.75rem;
        max-height: 60%;
        width: 130px;
    }
}

/* Additional responsive breakpoints */
@media (max-width: 480px) {
    #timer-display {
        font-size: 2rem;
        padding: 0.8rem 1.5rem;
    }
    #status-message {
        font-size: 0.8rem;
        padding: 0.4rem 0.8rem;
        width: 95%;
    }
    #sensitivity-slider-container {
        bottom: 3rem;
        padding: 0.5rem 1rem;
    }
    #controls {
        bottom: 0.5rem;
        gap: 0.5rem;
    }
    button {
        padding: 0.6rem 1.5rem;
        font-size: 0.9rem;
    }
    #laps-container {
        width: 120px;
        right: 0.5rem;
        top: 2rem;
        font-size: 0.8rem;
    }
    .modal-content {
        padding: 1.5rem;
        width: 95%;
    }
    .modal-buttons {
        flex-direction: column;
        gap: 0.5rem;
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    #timer-display {
        font-size: 3rem;
    }
    #laps-container {
        width: 180px;
    }
}

@media (min-width: 1025px) {
    #timer-display {
        font-size: 5rem;
        padding: 1.5rem 3rem;
    }
    #status-message {
        font-size: 1.2rem;
    }
    #laps-container {
        width: 220px;
        top: 10rem;
    }
}