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

:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --success-color: #22c55e;
    --success-hover: #16a34a;
    --secondary-color: #64748b;
    --secondary-hover: #475569;
    --background-color: #0f172a;
    --surface-color: #1e293b;
    --surface-light: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border-color: #475569;
    --accent-color: #f59e0b;
    --step-active: #6366f1;
    --step-inactive: #334155;
    --step-playing: #22c55e;
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
}

html {
    font-size: 16px;
}

body {
    font-family: var(--font-family);
    background: var(--background-color);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

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

/* Header Styles */
header {
    text-align: center;
    padding: 2rem 1rem;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 2rem;
}

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

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

/* Main Content */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Controls Section */
.controls-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    padding: 1.5rem;
    background: var(--surface-color);
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.control-group label {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

select {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--surface-light);
    color: var(--text-primary);
    font-size: 1rem;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s;
}

select:hover {
    border-color: var(--primary-color);
}

select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

/* Time Signature Control */
.time-signature-control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.time-signature-control select {
    width: 70px;
    text-align: center;
}

.time-sig-divider {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--text-secondary);
}

/* Tempo and Density Controls */
.tempo-control, .density-control {
    display: flex;
    align-items: center;
    gap: 1rem;
}

input[type="range"] {
    flex: 1;
    height: 8px;
    border-radius: 4px;
    background: var(--surface-light);
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    transition: transform 0.2s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    border: none;
}

.tempo-control span, .density-control span {
    min-width: 50px;
    text-align: right;
    font-weight: 600;
    color: var(--primary-color);
}

/* Pattern Section */
.pattern-section {
    padding: 1.5rem;
    background: var(--surface-color);
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.pattern-section h2 {
    font-size: 1.25rem;
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

.pattern-grid {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    justify-content: center;
    margin-bottom: 0.5rem;
}

.pattern-step {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    background: var(--step-inactive);
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pattern-step:hover {
    transform: scale(1.05);
    border-color: var(--primary-color);
}

.pattern-step.active {
    background: var(--step-active);
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.5);
}

.pattern-step.playing {
    background: var(--step-playing);
    box-shadow: 0 0 15px rgba(34, 197, 94, 0.6);
    transform: scale(1.1);
}

.pattern-step.beat-marker {
    border-bottom: 3px solid var(--accent-color);
}

.pattern-labels {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    justify-content: center;
}

.pattern-label {
    width: 40px;
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.pattern-label.beat-start {
    color: var(--accent-color);
    font-weight: 600;
}

/* Actions Section */
.actions-section {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.875rem 1.5rem;
    border-radius: 8px;
    border: none;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

.btn-icon {
    font-size: 1.1rem;
}

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

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

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

.btn-success:hover:not(:disabled) {
    background: var(--success-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(34, 197, 94, 0.4);
}

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

.btn-secondary:hover:not(:disabled) {
    background: var(--secondary-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(100, 116, 139, 0.4);
}

/* Info Section */
.info-section {
    padding: 1rem;
}

.info-card {
    background: var(--surface-color);
    padding: 1.5rem;
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.info-card h3 {
    font-size: 1.1rem;
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

.info-card ol {
    padding-left: 1.25rem;
}

.info-card li {
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

/* Footer */
footer {
    text-align: center;
    padding: 2rem 1rem;
    margin-top: 2rem;
    border-top: 1px solid var(--border-color);
}

footer p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.2s;
}

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

/* Mobile Responsive */
@media (max-width: 768px) {
    header h1 {
        font-size: 1.75rem;
    }

    .subtitle {
        font-size: 0.95rem;
    }

    .controls-section {
        grid-template-columns: 1fr;
        gap: 1rem;
        padding: 1rem;
    }

    .pattern-step {
        width: 32px;
        height: 32px;
    }

    .pattern-label {
        width: 32px;
        font-size: 0.65rem;
    }

    .btn {
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }

    .actions-section {
        flex-direction: column;
        align-items: stretch;
    }

    .btn {
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .app-container {
        padding: 0.5rem;
    }

    header {
        padding: 1.5rem 0.5rem;
    }

    .pattern-step {
        width: 28px;
        height: 28px;
    }

    .pattern-label {
        width: 28px;
    }
}

/* Animation for playing state */
@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

.pattern-step.playing {
    animation: pulse 0.2s ease-in-out;
}

/* Loading state */
.loading {
    position: relative;
    pointer-events: none;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid transparent;
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}
