/* =============================================================================
   EVM Studio - Persian Blue Theme (Client-Side)
   Primary: #1C39BB  |  Dark BG: #0A1128  |  Card: #111D42  |  Accent: #6C8AFF
   ============================================================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    --primary: #1C39BB;
    --primary-light: #3B5BDB;
    --primary-dark: #152D8C;
    --accent: #6C8AFF;
    --accent-glow: rgba(108, 138, 255, 0.3);
    --bg-dark: #0A1128;
    --bg-card: #111D42;
    --bg-card-hover: #162550;
    --bg-input: #0D1735;
    --border: rgba(108, 138, 255, 0.15);
    --border-active: rgba(108, 138, 255, 0.5);
    --text: #E8ECF4;
    --text-dim: #8892A8;
    --text-muted: #5A6478;
    --success: #34D399;
    --danger: #EF4444;
    --heart: #EF4444;
    --radius: 10px;
    --radius-sm: 6px;
    --glass: rgba(17, 29, 66, 0.7);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-dark);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-dark); }
::-webkit-scrollbar-thumb { background: var(--primary); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary-light); }

/* Header */
.header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 24px;
    background: linear-gradient(135deg, var(--primary-dark), var(--primary));
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 100;
    box-shadow: 0 2px 20px rgba(0,0,0,0.3);
}
.header-left { display: flex; align-items: center; gap: 12px; }
.logo { display: flex; align-items: center; }
.header-title { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.02em; color: #fff; }
.header-subtitle { font-size: 0.75rem; color: rgba(255,255,255,0.6); font-weight: 400; }
.header-right { display: flex; align-items: center; }
.stats { display: flex; align-items: center; gap: 10px; font-size: 0.8rem; color: rgba(255,255,255,0.7); font-variant-numeric: tabular-nums; }
.stat-divider { opacity: 0.3; }
.badge { display: inline-block; padding: 2px 8px; font-size: 0.65rem; font-weight: 600; border-radius: 10px; background: rgba(52,211,153,0.15); color: var(--success); border: 1px solid rgba(52,211,153,0.3); margin-left: 6px; }

/* Main Layout */
.main-layout { display: grid; grid-template-columns: 1fr 340px; gap: 0; height: calc(100vh - 53px); }

/* Video Panel */
.video-panel { display: flex; flex-direction: column; background: #000; position: relative; }
.video-container { flex: 1; display: flex; align-items: center; justify-content: center; position: relative; overflow: hidden; }

#camera-video { display: none; }

#display-canvas { max-width: 100%; max-height: 100%; object-fit: contain; cursor: crosshair; touch-action: none; }
#src-canvas, #out-canvas { display: none; }

.video-overlay {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.7); color: var(--text-dim); font-size: 0.9rem;
    pointer-events: none; opacity: 0; transition: opacity 0.3s;
}
.video-overlay.visible { opacity: 1; }

/* Heartbeat Bar */
.heartbeat-bar {
    display: none; align-items: center; gap: 20px; padding: 12px 20px;
    background: linear-gradient(180deg, rgba(10,17,40,0.95), var(--bg-dark));
    border-top: 1px solid var(--border);
}
.heartbeat-bar.visible { display: flex; }
.bpm-section { display: flex; align-items: center; gap: 10px; min-width: 120px; }
.heart-icon { font-size: 1.8rem; color: var(--heart); animation: heartbeat 1s ease-in-out infinite; }
@keyframes heartbeat {
    0%, 100% { transform: scale(1); }
    14% { transform: scale(1.2); }
    28% { transform: scale(1); }
    42% { transform: scale(1.15); }
    56% { transform: scale(1); }
}
.bpm-readout { display: flex; flex-direction: column; }
.bpm-value { font-size: 2rem; font-weight: 700; color: #fff; line-height: 1; font-variant-numeric: tabular-nums; }
.bpm-label { font-size: 0.7rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; }
.waveform-section { flex: 1; min-width: 200px; }
#waveform-canvas { width: 100%; height: 60px; border-radius: var(--radius-sm); background: rgba(0,0,0,0.3); border: 1px solid var(--border); }
.buffer-section { min-width: 100px; display: flex; flex-direction: column; gap: 4px; }
.buffer-label { font-size: 0.7rem; color: var(--text-dim); }
.buffer-bar-track { height: 4px; background: var(--bg-input); border-radius: 2px; overflow: hidden; }
.buffer-bar-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--primary), var(--accent)); border-radius: 2px; transition: width 0.3s ease; }

/* Sidebar */
.sidebar {
    background: var(--bg-dark); border-left: 1px solid var(--border);
    overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 16px;
}
.control-group {
    background: var(--bg-card); border-radius: var(--radius); padding: 14px;
    border: 1px solid var(--border); backdrop-filter: blur(10px);
}
.group-title { font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); margin-bottom: 10px; }

/* Mode Cards */
.mode-cards { display: flex; gap: 6px; }
.mode-card {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
    padding: 10px 6px; background: var(--bg-input); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text-dim); cursor: pointer;
    transition: all 0.2s; font-family: inherit;
}
.mode-card:hover { background: var(--bg-card-hover); border-color: var(--border-active); color: var(--text); }
.mode-card.active { background: var(--primary-dark); border-color: var(--accent); color: #fff; box-shadow: 0 0 12px var(--accent-glow); }
.mode-icon { font-size: 1.2rem; }
.mode-name { font-size: 0.75rem; font-weight: 600; }
.mode-desc { font-size: 0.6rem; opacity: 0.7; text-align: center; }

/* Select */
.styled-select {
    width: 100%; padding: 8px 12px; background: var(--bg-input);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    color: var(--text); font-family: inherit; font-size: 0.8rem; cursor: pointer;
    outline: none; transition: border-color 0.2s; appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 5l3 3 3-3' stroke='%236C8AFF' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 10px center;
}
.styled-select:focus { border-color: var(--accent); }
.styled-select option { background: var(--bg-card); color: var(--text); }

/* View Toggle */
.view-toggle { display: flex; gap: 4px; background: var(--bg-input); border-radius: var(--radius-sm); padding: 3px; }
.view-btn {
    flex: 1; padding: 6px 8px; border: none; border-radius: 4px; background: transparent;
    color: var(--text-dim); font-family: inherit; font-size: 0.72rem; font-weight: 500;
    cursor: pointer; transition: all 0.2s;
}
.view-btn:hover { color: var(--text); background: rgba(108,138,255,0.1); }
.view-btn.active { background: var(--primary); color: #fff; box-shadow: 0 1px 4px rgba(28,57,187,0.4); }

/* Sliders */
.param-slider { margin-bottom: 12px; }
.param-slider:last-child { margin-bottom: 0; }
.param-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.param-header label { font-size: 0.72rem; color: var(--text-dim); font-weight: 500; }
.param-value { font-size: 0.72rem; color: var(--accent); font-weight: 600; font-variant-numeric: tabular-nums; }
.hz-bpm { font-size: 0.65rem; color: var(--text-muted); font-weight: 400; }

input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 4px; background: var(--bg-input); border-radius: 2px; outline: none; cursor: pointer; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 14px; height: 14px; border-radius: 50%; background: var(--accent); border: 2px solid var(--primary); cursor: pointer; transition: transform 0.15s, box-shadow 0.15s; }
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.2); box-shadow: 0 0 8px var(--accent-glow); }
input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--accent); border: 2px solid var(--primary); cursor: pointer; }

/* IIR Params */
.iir-params { max-height: 0; overflow: hidden; transition: max-height 0.3s ease, margin-top 0.3s ease; margin-top: 0; }
.iir-params.visible { max-height: 150px; margin-top: 10px; }

/* Presets */
.preset-cards { display: flex; flex-direction: column; gap: 6px; }
.preset-card {
    display: flex; align-items: center; gap: 10px; padding: 8px 10px;
    background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius-sm);
    color: var(--text); cursor: pointer; transition: all 0.2s; font-family: inherit; text-align: left;
}
.preset-card:hover { background: var(--bg-card-hover); border-color: var(--border-active); transform: translateX(2px); }
.preset-icon { font-size: 1.3rem; }
.preset-name { font-size: 0.78rem; font-weight: 600; display: block; }
.preset-desc { font-size: 0.65rem; color: var(--text-dim); display: block; }

/* Action Buttons */
.actions-group { display: flex; gap: 8px; background: transparent; border: none; padding: 0; }
.action-btn {
    flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
    padding: 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-family: inherit; font-size: 0.78rem; font-weight: 600; cursor: pointer;
    transition: all 0.2s; text-decoration: none;
}
.reset-btn { background: var(--bg-card); color: var(--text); }
.reset-btn:hover { background: var(--bg-card-hover); border-color: var(--border-active); }
.snapshot-btn { background: var(--primary); color: #fff; border-color: var(--primary-light); }
.snapshot-btn:hover { background: var(--primary-light); box-shadow: 0 2px 8px rgba(28,57,187,0.4); }

/* Shortcuts */
.shortcuts-group { background: transparent; border: none; padding: 0; }
.shortcuts-list { font-size: 0.7rem; color: var(--text-muted); }
kbd { display: inline-block; padding: 1px 5px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 3px; font-family: inherit; font-size: 0.65rem; color: var(--accent); }

/* Snapshot Overlay */
.snapshot-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.8);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000; opacity: 0; pointer-events: none; transition: opacity 0.3s;
}
.snapshot-overlay.visible { opacity: 1; pointer-events: all; }
.snapshot-preview { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; max-width: 90vw; max-height: 90vh; display: flex; flex-direction: column; gap: 12px; }
.snapshot-preview img { max-width: 70vw; max-height: 70vh; object-fit: contain; border-radius: var(--radius-sm); }
.snapshot-actions { display: flex; gap: 8px; justify-content: center; }

/* Responsive */
@media (max-width: 900px) {
    .main-layout { grid-template-columns: 1fr; height: auto; }
    .video-panel { height: 50vh; min-height: 300px; }
    .sidebar { border-left: none; border-top: 1px solid var(--border); max-height: 50vh; }
    .heartbeat-bar { flex-wrap: wrap; }
    .header-subtitle { display: none; }
}
