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

:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --primary-active: #4338ca;
    --background: #0f0f1a;
    --surface: #1a1a2e;
    --surface-hover: #252540;
    --text-primary: #ffffff;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --accent: #22d3ee;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --border-radius: 12px;
    --transition: 0.2s ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    line-height: 1.6;
}

.container {
    max-width: 500px;
    margin: 0 auto;
    padding: 20px;
    width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    text-align: center;
    margin-bottom: 30px;
    padding-top: 20px;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-color), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1rem;
}

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.bpm-display {
    background: var(--surface);
    border-radius: var(--border-radius);
    padding: 30px 50px;
    text-align: center;
    margin-bottom: 30px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    transition: transform var(--transition), box-shadow var(--transition);
}

.bpm-display.pulse {
    transform: scale(1.02);
    box-shadow: 0 4px 30px rgba(99, 102, 241, 0.3);
}

.bpm-value {
    font-size: 5rem;
    font-weight: 800;
    display: block;
    line-height: 1;
    color: var(--accent);
}

.bpm-label {
    font-size: 1.25rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 3px;
}

.tap-button {
    width: 200px;
    height: 200px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
    color: var(--text-primary);
    font-size: 1.5rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: transform var(--transition), box-shadow var(--transition);
    box-shadow: 0 8px 30px rgba(99, 102, 241, 0.4);
    margin-bottom: 30px;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.tap-button:hover {
    transform: scale(1.05);
    box-shadow: 0 12px 40px rgba(99, 102, 241, 0.5);
}

.tap-button:active,
.tap-button.active {
    transform: scale(0.95);
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.3);
}

.tap-text {
    font-size: 2rem;
    letter-spacing: 4px;
}

.tap-hint {
    font-size: 0.75rem;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.7);
}

.stats {
    display: flex;
    gap: 40px;
    margin-bottom: 20px;
}

.stat-item {
    text-align: center;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    display: block;
    color: var(--text-primary);
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.reset-button {
    background: var(--surface);
    border: 1px solid var(--text-muted);
    color: var(--text-secondary);
    padding: 12px 30px;
    border-radius: var(--border-radius);
    font-size: 1rem;
    cursor: pointer;
    transition: all var(--transition);
    margin-bottom: 40px;
}

.reset-button:hover {
    background: var(--surface-hover);
    border-color: var(--text-secondary);
    color: var(--text-primary);
}

.history-section {
    width: 100%;
    background: var(--surface);
    border-radius: var(--border-radius);
    padding: 20px;
    margin-bottom: 20px;
}

.history-section h2 {
    font-size: 1.25rem;
    margin-bottom: 15px;
    color: var(--text-primary);
}

.history-list {
    max-height: 200px;
    overflow-y: auto;
    margin-bottom: 15px;
}

.history-list::-webkit-scrollbar {
    width: 6px;
}

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

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

.history-empty {
    color: var(--text-muted);
    text-align: center;
    padding: 20px;
    font-style: italic;
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    background: var(--background);
    border-radius: 8px;
    margin-bottom: 8px;
}

.history-item:last-child {
    margin-bottom: 0;
}

.history-bpm {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent);
}

.history-bpm span {
    font-size: 0.875rem;
    font-weight: 400;
    color: var(--text-muted);
}

.history-time {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.clear-history-button {
    background: transparent;
    border: 1px solid var(--danger);
    color: var(--danger);
    padding: 8px 20px;
    border-radius: 8px;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all var(--transition);
    width: 100%;
}

.clear-history-button:hover {
    background: var(--danger);
    color: var(--text-primary);
}

footer {
    text-align: center;
    padding: 20px;
    margin-top: auto;
    border-top: 1px solid var(--surface);
}

footer p {
    color: var(--text-muted);
    font-size: 0.875rem;
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
    transition: color var(--transition);
}

footer a:hover {
    color: var(--accent);
    text-decoration: underline;
}

/* Mobile responsiveness */
@media (max-width: 480px) {
    .container {
        padding: 15px;
    }

    header h1 {
        font-size: 2rem;
    }

    .bpm-display {
        padding: 20px 40px;
    }

    .bpm-value {
        font-size: 4rem;
    }

    .tap-button {
        width: 160px;
        height: 160px;
    }

    .tap-text {
        font-size: 1.5rem;
    }

    .stats {
        gap: 30px;
    }

    .stat-value {
        font-size: 1.5rem;
    }
}

/* Keyboard focus styles */
.tap-button:focus {
    outline: none;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.5), 0 8px 30px rgba(99, 102, 241, 0.4);
}

.reset-button:focus,
.clear-history-button:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.3);
}

/* Animation for new history items */
@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.history-item {
    animation: slideIn 0.3s ease;
}
