/* ==========================================
   THEME PALETTES (Variables)
   ========================================== */
:root {
    /* DEFAULT: LIGHT MODE PROPERTIES */
    --bg-body: #f7f9fa;
    --bg-container: #ffffff;
    --bg-select: #ffffff;
    
    --text-primary: #111111;      /* Large beat numbers */
    --text-muted: #7f8c8d;        /* BPM Labels */
    --text-labels: #a4b0be;       /* Dropdown labels */
    
    --border-ui: #dee2e6;
    --accent-blue: #00a8ff;
    --shadow-intensity: rgba(0, 0, 0, 0.06);
}

@media (prefers-color-scheme: dark) {
    :root {
        /* AUTOMATIC SWITCH: DARK MODE PROPERTIES */
        --bg-body: #0f172a;           /* Deep midnight blue */
        --bg-container: #1e293b;      /* Sleek dark card */
        --bg-select: #0f172a;         /* Dark inputs */
        
        --text-primary: #f8fafc;      /* Crisp white beat numbers */
        --text-muted: #94a3b8;        /* Dimmed silver BPM label */
        --text-labels: #64748b;       /* Muted dropdown labels */
        
        --border-ui: #334155;         /* Subtle metallic dark borders */
        --accent-blue: #38bdf8;        /* Vivid neon blue accents */
        --shadow-intensity: rgba(0, 0, 0, 0.4);
    }
}

/* ==========================================
   YOUR CORE APPLICATIVE STRUCTURAL LAYOUT
   ========================================== */
* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-body);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    padding: 15px;
    transition: background-color 0.3s ease, color 0.3s ease; /* Seamless shifting transition */
}

#metronome-container {
    background: var(--bg-container);
    padding: 24px;
    border-radius: 24px;
    box-shadow: 0 10px 40px var(--shadow-intensity);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    width: 100%;
    max-width: 380px;
    border: 1px solid var(--border-ui); /* Added subtle boundary definition for dark environments */
    transition: background-color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.dropdown-container {
    display: flex;
    width: 100%;
    gap: 12px;
}

.select-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.select-wrapper label {
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    color: var(--text-labels);
    padding-left: 4px;
    transition: color 0.3s ease;
}

select {
    width: 100%;
    padding: 10px;
    font-size: 15px; /* Safely prevents standard layout auto-zooming on iOS */
    border: 2px solid var(--border-ui);
    border-radius: 12px;
    background-color: var(--bg-select);
    color: var(--text-primary);
    outline: none;
    cursor: pointer;
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

.canvas-wrapper {
    position: relative;
    width: 100%;
    max-width: 320px;
    aspect-ratio: 1 / 1;
}

#metronome-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

#center-display {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 6px;
    pointer-events: none;
}

#measure-number {
    font-size: 36px;
    font-weight: 700;
    color: var(--accent-blue);
    transition: color 0.3s ease;
}

#beat-number {
    font-size: 76px;
    font-weight: 900;
    color: var(--text-primary);
    transition: color 0.3s ease;
}

.tempo-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    gap: 15px;
}

#tempo-slider {
    width: 100%;
    height: 10px;
    border-radius: 5px;
    outline: none;
    accent-color: var(--accent-blue);
    transition: accent-color 0.3s ease;
}

.input-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

#tempo-input {
    width: 80px;
    padding: 8px;
    font-size: 20px;
    text-align: center;
    border: 2px solid var(--border-ui);
    border-radius: 10px;
    font-weight: bold;
    background-color: var(--bg-select);
    color: var(--text-primary);
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

.bpm-label {
    font-weight: bold;
    color: var(--text-muted);
    transition: color 0.3s ease;
}

#start-btn {
    width: 100%;
    padding: 16px;
    font-size: 20px;
    font-weight: bold;
    color: white;
    background-color: #2ecc71;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(46, 204, 113, 0.2);
    transition: background-color 0.2s ease, box-shadow 0.2s ease, transform 0.1s ease;
}

#start-btn:active {
    transform: scale(0.98);
}

#start-btn.running {
    background-color: #e74c3c;
    box-shadow: 0 4px 12px rgba(231, 76, 60, 0.2);
}