:root {
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --secondary-color: #6b7280;
    --secondary-hover: #4b5563;
    --accent-color: #10b981;
    --accent-hover: #059669;
    --danger-color: #ef4444;
    --danger-hover: #dc2626;
    --background: #ffffff;
    --surface: #f8fafc;
    --surface-elevated: #ffffff;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --border: #e5e7eb;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    --gradient-primary: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --gradient-accent: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

[data-theme="dark"] {
    --primary-color: #60a5fa;
    --primary-hover: #3b82f6;
    --secondary-color: #6b7280;
    --secondary-hover: #9ca3af;
    --accent-color: #34d399;
    --accent-hover: #10b981;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-elevated: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;
    --border: #334155;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.4);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    transition: all 0.3s ease;
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 3rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--primary-color);
}

.logo svg {
    color: var(--primary-color);
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.theme-toggle {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 50px;
    padding: 0.5rem;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle:hover {
    background: var(--surface-elevated);
    transform: scale(1.05);
}

.theme-toggle svg {
    position: absolute;
    transition: all 0.3s ease;
    color: var(--text-secondary);
}

.moon-icon {
    opacity: 0;
    transform: rotate(90deg);
}

[data-theme="dark"] .sun-icon {
    opacity: 0;
    transform: rotate(-90deg);
}

[data-theme="dark"] .moon-icon {
    opacity: 1;
    transform: rotate(0deg);
}

/* Main Content */
.main-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3rem;
    flex: 1;
    align-items: start;
}

.stopwatch-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2rem;
}

/* Progress Ring */
.progress-ring {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.progress-svg {
    transform: rotate(-90deg);
    filter: drop-shadow(var(--shadow));
}

.progress-background {
    fill: none;
    stroke: var(--border);
    stroke-width: 8;
}

.progress-bar {
    fill: none;
    stroke: var(--primary-color);
    stroke-width: 8;
    stroke-linecap: round;
    stroke-dasharray: 879.646; /* 2 * π * 140 */
    stroke-dashoffset: 879.646;
    transition: stroke-dashoffset 0.1s ease;
    filter: drop-shadow(0 0 8px rgba(59, 130, 246, 0.3));
}

.time-display {
    position: absolute;
    text-align: center;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.main-time {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
}

.milliseconds {
    font-size: 1.25rem;
    color: var(--text-secondary);
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    margin-top: -0.25rem;
}

/* Controls */
.controls {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.875rem 1.5rem;
    border: none;
    border-radius: 50px;
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    min-width: 120px;
    justify-content: center;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

.btn:not(:disabled):hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn:not(:disabled):active {
    transform: translateY(0);
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:not(:disabled):hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--surface);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-secondary:not(:disabled):hover {
    background: var(--surface-elevated);
    color: var(--text-primary);
}

.btn-accent {
    background: var(--accent-color);
    color: white;
}

.btn-accent:not(:disabled):hover {
    background: var(--accent-hover);
}

.btn svg {
    transition: all 0.3s ease;
}

.btn-primary .pause-icon {
    display: none;
}

.btn-primary.running .play-icon {
    display: none;
}

.btn-primary.running .pause-icon {
    display: block;
}

/* Statistics */
.stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    width: 100%;
    max-width: 400px;
}

.stat-item {
    background: var(--surface);
    padding: 1rem;
    border-radius: 12px;
    text-align: center;
    border: 1px solid var(--border);
    transition: all 0.3s ease;
}

.stat-item:hover {
    background: var(--surface-elevated);
    transform: translateY(-2px);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
}

.stat-value {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

/* Lap Times */
.lap-times-container {
    background: var(--surface);
    border-radius: 16px;
    padding: 1.5rem;
    border: 1px solid var(--border);
    height: fit-content;
    max-height: 600px;
    display: flex;
    flex-direction: column;
}

.lap-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.lap-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
}

.clear-laps {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 8px;
    transition: all 0.3s ease;
    font-size: 0.875rem;
}

.clear-laps:hover {
    background: var(--surface-elevated);
    color: var(--danger-color);
}

.lap-list {
    flex: 1;
    overflow-y: auto;
    max-height: 500px;
}

.no-laps {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem;
    font-style: italic;
}

.lap-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    border-radius: 8px;
    margin-bottom: 0.5rem;
    background: var(--background);
    border: 1px solid var(--border);
    transition: all 0.3s ease;
    animation: slideIn 0.3s ease;
}

.lap-item:hover {
    background: var(--surface-elevated);
    transform: translateX(4px);
}

.lap-item.best {
    border-color: var(--accent-color);
    background: rgba(16, 185, 129, 0.05);
}

.lap-item.worst {
    border-color: var(--danger-color);
    background: rgba(239, 68, 68, 0.05);
}

.lap-number {
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 60px;
}

.lap-time {
    font-variant-numeric: tabular-nums;
    font-weight: 500;
    color: var(--text-primary);
}

.lap-diff {
    font-size: 0.875rem;
    font-weight: 500;
    min-width: 80px;
    text-align: right;
}

.lap-diff.faster {
    color: var(--accent-color);
}

.lap-diff.slower {
    color: var(--danger-color);
}

/* Keyboard Shortcuts */
.shortcuts {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border);
}

.shortcut-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-muted);
    font-size: 0.875rem;
}

kbd {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Animations */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

.btn-primary.running {
    animation: pulse 2s infinite;
}

/* Custom Scrollbar */
.lap-list::-webkit-scrollbar {
    width: 6px;
}

.lap-list::-webkit-scrollbar-track {
    background: var(--surface);
    border-radius: 3px;
}

.lap-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.lap-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Responsive Design */
@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
        gap: 2rem;
    }
    
    .lap-times-container {
        order: -1;
        max-height: 300px;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 1rem;
    }
    
    .header {
        margin-bottom: 2rem;
    }
    
    .logo h1 {
        font-size: 1.25rem;
    }
    
    .main-time {
        font-size: 2rem;
    }
    
    .milliseconds {
        font-size: 1rem;
    }
    
    .controls {
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .btn {
        min-width: 100px;
        padding: 0.75rem 1.25rem;
    }
    
    .stats {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
    
    .shortcuts {
        flex-wrap: wrap;
        gap: 1rem;
    }
    
    .progress-svg {
        width: 280px;
        height: 280px;
    }
    
    .progress-background,
    .progress-bar {
        r: 120;
    }
}

@media (max-width: 480px) {
    .main-time {
        font-size: 1.75rem;
    }
    
    .controls {
        gap: 0.5rem;
    }
    
    .btn {
        min-width: 80px;
        padding: 0.625rem 1rem;
        font-size: 0.8rem;
    }
    
    .progress-svg {
        width: 240px;
        height: 240px;
    }
    
    .progress-background,
    .progress-bar {
        r: 100;
    }
}