:root {
    --bg: #0c0e11; --surface: #151920; --surface-hover: #1f2430;
    --text: #f1f5f9; --text-muted: #94a3b8;
    --accent: #8b5cf6; --accent-glow: 0 0 20px rgba(139, 92, 246, 0.4);
    --danger: #ef4444; --success: #10b981;
    --radius: 1.25rem; --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    background: var(--bg); color: var(--text);
    font-family: system-ui, -apple-system, sans-serif;
    display: flex; justify-content: center; align-items: center;
    min-height: 100dvh; overflow: hidden;
    -webkit-tap-highlight-color: transparent;
}

.app-shell {
    width: 100%; max-width: 420px; padding: 1.5rem;
    display: flex; flex-direction: column; gap: 2rem;
}

.header { text-align: center; }
.title { font-size: clamp(1.25rem, 5vw, 1.5rem); font-weight: 800; letter-spacing: -0.02em; display: flex; align-items: center; justify-content: center; gap: 0.5em; color: var(--text); }

.timer-visual {
    position: relative; display: flex; flex-direction: column; align-items: center;
    padding: 1rem 0; user-select: none;
}

.progress-ring { width: 180px; height: 180px; transform: rotate(-90deg); }
.track { fill: none; stroke: var(--surface); stroke-width: 6; }
.fill {
    fill: none; stroke: var(--accent); stroke-width: 6;
    stroke-linecap: round; stroke-dasharray: 339.292; stroke-dashoffset: 339.292;
    transition: stroke-dashoffset 0.1s linear;
}

.time-display {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    text-align: center; font-variant-numeric: tabular-nums;
}
.time-display span { font-size: clamp(2.5rem, 8vw, 3.5rem); font-weight: 800; line-height: 1; letter-spacing: -0.03em; }
.time-display .ms { font-size: 0.5em; color: var(--accent); margin-left: 0.1em; }

.status-badge {
    margin-top: 1rem; font-size: 0.75rem; text-transform: uppercase;
    letter-spacing: 0.1em; color: var(--text-muted); background: var(--surface);
    padding: 0.3em 0.8em; border-radius: 1em; font-weight: 600;
}

.controls {
    display: grid; grid-template-columns: 1fr 2fr 1fr; gap: 1rem;
    padding: 0 0.25rem;
}

.btn {
    border: none; padding: 1.25rem 0.5rem; border-radius: 0.75rem;
    font-size: 1rem; font-weight: 600; cursor: pointer;
    transition: transform var(--transition), background var(--transition), box-shadow var(--transition), opacity 0.2s;
    touch-action: manipulation; user-select: none;
    display: flex; align-items: center; justify-content: center;
    min-height: 56px;
}
.btn:active:not(:disabled) { transform: scale(0.96); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-secondary { background: var(--surface); color: var(--text); }
.btn-secondary:active:not(:disabled) { background: var(--surface-hover); }
.btn-primary {
    background: var(--accent); color: white; box-shadow: var(--accent-glow);
}
.btn-primary:active:not(:disabled) { background: #7c3aed; box-shadow: none; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.laps-container {
    flex: 1; min-height: 120px; overflow-y: auto; padding: 0.5rem;
    scrollbar-width: thin; scrollbar-color: var(--surface) transparent;
}
.lap-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 0.75rem 1rem; margin-bottom: 0.5rem;
    background: var(--surface); border-radius: 0.75rem;
    animation: slideUp 0.3s ease-out;
    font-variant-numeric: tabular-nums;
}
.lap-item .label { color: var(--text-muted); }
.lap-item .label small { margin-left: 0.4em; font-size: 0.9em; }
.lap-item span:not(.label) { font-weight: 600; }
.lap-item .best { color: var(--success); }
.lap-item .worst { color: var(--danger); }

@keyframes slideUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.04); } }
.running .time-display { animation: pulse 2.5s infinite ease-in-out; }
.running .fill { stroke: var(--accent); }

.pause-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.85);
    display: flex; justify-content: center; align-items: center; z-index: 100;
    backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.pause-content { text-align: center; color: white; cursor: pointer; }
.pause-icon { font-size: 4rem; display: block; margin-bottom: 1.25rem; filter: drop-shadow(0 0 15px rgba(255,255,255,0.4)); }
.pause-overlay p { font-size: 1.75rem; font-weight: 800; margin-bottom: 0.5rem; }
.pause-overlay small { color: var(--text-muted); font-size: 0.95rem; }
