/* ============================================================
   Baseball Hit Auto-Capture System
   Standalone dark-theme stylesheet
   ============================================================ */

/* --- CSS Custom Properties --- */
:root {
    --bg-void: #06060f;
    --bg-surface: #0c0c1a;
    --bg-card: #12122a;
    --bg-input: #1a1a35;
    --border: rgba(255, 255, 255, 0.08);
    --border-active: rgba(0, 212, 255, 0.4);

    --text-primary: #e8e8f0;
    --text-secondary: #8888aa;
    --text-muted: #555570;

    --accent-cyan: #00d4ff;
    --accent-green: #00ff88;
    --accent-red: #ff3355;
    --accent-amber: #ffaa00;
    --accent-magenta: #ff00ff;
    --accent-blue: #3388ff;

    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;

    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);

    --z-video: 1;
    --z-overlay: 10;
    --z-controls: 100;
    --z-drawer: 200;
    --z-modal: 300;
    --z-toast: 400;
}

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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: var(--font-sans);
    background: var(--bg-void);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

/* --- Main Container --- */
.capture-app {
    position: relative;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* --- Video Feed --- */
.video-container {
    position: absolute;
    inset: 0;
    z-index: var(--z-video);
    background: #000;
}

.video-feed {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.pose-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: var(--z-overlay);
    pointer-events: none;
}

/* --- Top Status Bar --- */
.status-bar {
    position: relative;
    z-index: var(--z-controls);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: rgba(6, 6, 15, 0.7);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    min-height: 48px;
    gap: 8px;
}

.status-left,
.status-center,
.status-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-left { flex: 0 0 auto; }
.status-center { flex: 1 1 auto; justify-content: center; }
.status-right { flex: 0 0 auto; }

.state-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    font-family: var(--font-mono);
    white-space: nowrap;
}

.state-badge .pulse-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.state-badge[data-state="idle"] {
    background: rgba(85, 85, 112, 0.3);
    color: var(--text-secondary);
}
.state-badge[data-state="idle"] .pulse-dot {
    background: var(--text-muted);
}

.state-badge[data-state="listening"] {
    background: rgba(0, 212, 255, 0.15);
    color: var(--accent-cyan);
}
.state-badge[data-state="listening"] .pulse-dot {
    background: var(--accent-cyan);
    animation: pulse 1.5s ease-in-out infinite;
}

.state-badge[data-state="triggered"] {
    background: rgba(255, 170, 0, 0.2);
    color: var(--accent-amber);
}
.state-badge[data-state="triggered"] .pulse-dot {
    background: var(--accent-amber);
    animation: pulse 0.4s ease-in-out infinite;
}

.state-badge[data-state="recording"] {
    background: rgba(255, 51, 85, 0.2);
    color: var(--accent-red);
}
.state-badge[data-state="recording"] .pulse-dot {
    background: var(--accent-red);
    animation: pulse 0.6s ease-in-out infinite;
}

.state-badge[data-state="processing"] {
    background: rgba(255, 0, 255, 0.15);
    color: var(--accent-magenta);
}
.state-badge[data-state="processing"] .pulse-dot {
    background: var(--accent-magenta);
    animation: spin 1s linear infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(0.7); }
}

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

.detection-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-family: var(--font-mono);
    background: rgba(0, 255, 136, 0.1);
    color: var(--accent-green);
    white-space: nowrap;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.detection-badge.active { opacity: 1; }

.buffer-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 10px;
    font-family: var(--font-mono);
    color: var(--text-muted);
}

.buffer-bar {
    width: 50px;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.08);
    overflow: hidden;
}

.buffer-fill {
    height: 100%;
    border-radius: 2px;
    background: var(--accent-cyan);
    transition: width var(--transition-fast);
}

/* --- Clip count in status bar --- */
.clip-count-status {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    font-family: var(--font-mono);
    color: var(--accent-cyan);
    background: rgba(0, 212, 255, 0.08);
    border: 1px solid rgba(0, 212, 255, 0.2);
    border-radius: 10px;
    padding: 2px 8px;
    margin-right: 6px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.clip-count-status:hover {
    background: rgba(0, 212, 255, 0.15);
}

.clip-count-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-cyan);
}

/* --- Battery Indicator --- */
.battery-indicator {
    font-size: 10px;
    font-family: var(--font-mono);
    color: var(--text-muted);
}

.battery-indicator.low { color: var(--accent-red); }

/* --- Audio Level Meter (left edge) --- */
.audio-meter {
    position: absolute;
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
    z-index: var(--z-controls);
    width: 8px;
    height: 200px;
    border-radius: 4px;
    background: rgba(6, 6, 15, 0.6);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    overflow: visible;
    display: flex;
    flex-direction: column-reverse;
}

.audio-meter-fill {
    width: 100%;
    border-radius: 4px;
    transition: height 50ms linear;
    background: linear-gradient(to top, var(--accent-green), var(--accent-amber), var(--accent-red));
}

.audio-meter-threshold {
    position: absolute;
    left: -4px;
    right: -4px;
    height: 2px;
    background: var(--accent-red);
    pointer-events: none;
    box-shadow: 0 0 6px var(--accent-red);
}

.audio-meter-threshold::after {
    content: 'THR';
    position: absolute;
    left: 14px;
    top: -6px;
    font-size: 8px;
    font-family: var(--font-mono);
    color: var(--accent-red);
    letter-spacing: 1px;
}

/* --- Control Drawer (bottom sheet) --- */
.drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: calc(var(--z-drawer) - 1);
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-normal);
}

.drawer-backdrop.active {
    opacity: 1;
    pointer-events: auto;
}

/* --- Control Drawer (single panel) --- */
.control-drawer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: var(--z-drawer);
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    transition: transform var(--transition-slow);
    max-height: 80vh;
    max-height: 80dvh;
    display: flex;
    flex-direction: column;
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

/* Collapsed: only show handle + quick-actions (hide tabs & content) */
.control-drawer .drawer-tabs,
.control-drawer .drawer-content {
    display: none;
}

/* Expanded: show everything */
.control-drawer.expanded .drawer-tabs {
    display: flex;
}
.control-drawer.expanded .drawer-content {
    display: block;
}

/* Quick-actions always visible inside the drawer */
.quick-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 0 16px 12px;
    flex-shrink: 0;
}

.drawer-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    cursor: grab;
    flex-shrink: 0;
}

.drawer-handle-bar {
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.2);
    transition: background var(--transition-fast);
}

.drawer-handle:hover .drawer-handle-bar {
    background: rgba(255, 255, 255, 0.4);
}

.drawer-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    padding: 0 12px;
    flex-shrink: 0;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.drawer-tabs::-webkit-scrollbar { display: none; }

.drawer-tab {
    padding: 8px 14px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--transition-fast);
    font-family: var(--font-sans);
}

.drawer-tab:hover { color: var(--text-secondary); }
.drawer-tab.active {
    color: var(--accent-cyan);
    border-bottom-color: var(--accent-cyan);
}

.drawer-content {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 16px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.drawer-content::-webkit-scrollbar { width: 4px; }
.drawer-content::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1);
    border-radius: 2px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* quick-actions styles are now above .control-drawer */

/* --- Quick-action buttons --- */
.quick-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: 18px;
    position: relative;
}

.quick-btn:hover {
    border-color: var(--border-active);
    background: var(--bg-input);
}

.quick-btn.active {
    background: rgba(0, 212, 255, 0.15);
    border-color: var(--accent-cyan);
    color: var(--accent-cyan);
}

.quick-btn.danger {
    background: rgba(255, 51, 85, 0.15);
    border-color: var(--accent-red);
    color: var(--accent-red);
}

.quick-btn.trigger {
    width: 56px;
    height: 56px;
    font-size: 22px;
    background: rgba(255, 51, 85, 0.2);
    border-color: var(--accent-red);
    color: var(--accent-red);
    position: relative;
}

.quick-btn.trigger::after {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    border: 2px solid var(--accent-red);
    opacity: 0;
    animation: trigger-ring 2s ease-out infinite;
}

@keyframes trigger-ring {
    0% { transform: scale(1); opacity: 0.6; }
    100% { transform: scale(1.4); opacity: 0; }
}

/* --- Form Controls --- */
.control-group {
    margin-bottom: 16px;
}

.control-group:last-child { margin-bottom: 0; }

.control-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
}

.control-label .value {
    font-family: var(--font-mono);
    color: var(--accent-cyan);
    font-size: 11px;
}

.control-sublabel {
    font-size: 10px;
    color: var(--text-muted);
    margin-bottom: 4px;
    line-height: 1.4;
}

/* Range slider */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--bg-input);
    outline: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent-cyan);
    border: 2px solid var(--bg-surface);
    box-shadow: 0 0 8px rgba(0, 212, 255, 0.3);
    cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent-cyan);
    border: 2px solid var(--bg-surface);
    box-shadow: 0 0 8px rgba(0, 212, 255, 0.3);
    cursor: pointer;
}

/* Select */
.control-select {
    width: 100%;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 13px;
    outline: none;
    cursor: pointer;
    transition: border-color var(--transition-fast);
}

.control-select:focus { border-color: var(--border-active); }

/* Text input */
.control-input {
    width: 100%;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 12px;
    outline: none;
    transition: border-color var(--transition-fast);
}

.control-input:focus { border-color: var(--border-active); }
.control-input::placeholder { color: var(--text-muted); }

/* Toggle switch */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 0;
}

.toggle-row .toggle-label {
    font-size: 13px;
    color: var(--text-primary);
}

.toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-track {
    position: absolute;
    inset: 0;
    border-radius: 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.toggle-track::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: all var(--transition-fast);
}

.toggle-switch input:checked + .toggle-track {
    background: rgba(0, 212, 255, 0.2);
    border-color: var(--accent-cyan);
}

.toggle-switch input:checked + .toggle-track::after {
    transform: translateX(20px);
    background: var(--accent-cyan);
}

/* Button */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.btn:hover {
    border-color: var(--border-active);
    background: var(--bg-input);
}

.btn-primary {
    background: rgba(0, 212, 255, 0.15);
    border-color: var(--accent-cyan);
    color: var(--accent-cyan);
}

.btn-primary:hover {
    background: rgba(0, 212, 255, 0.25);
}

.btn-danger {
    background: rgba(255, 51, 85, 0.1);
    border-color: rgba(255, 51, 85, 0.3);
    color: var(--accent-red);
}

.btn-danger:hover {
    background: rgba(255, 51, 85, 0.2);
}

.btn-sm {
    padding: 5px 10px;
    font-size: 11px;
}

.btn-block {
    width: 100%;
}

.btn-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* --- Section header in panels --- */
.panel-section {
    margin-bottom: 20px;
}

.panel-section-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-muted);
    margin-bottom: 12px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}

/* --- Clip Gallery (inline in Clips tab) --- */
.clips-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.clips-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.clips-header-right {
    flex-shrink: 0;
}

.clip-count-inline {
    font-size: 14px;
    font-weight: 700;
}

.clip-gallery-inline {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 10px;
    min-height: 60px;
}

.clip-gallery-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 24px 16px;
    color: var(--text-muted);
    font-size: 12px;
}

.clip-card {
    flex-shrink: 0;
    width: 100%;
    border-radius: var(--radius-md);
    background: var(--bg-card);
    border: 1px solid var(--border);
    overflow: hidden;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.clip-card:hover {
    border-color: var(--border-active);
    transform: translateY(-2px);
}

.clip-card-thumb {
    width: 100%;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    background: var(--bg-void);
    display: block;
}

.clip-card-info {
    padding: 4px 6px;
}

.clip-card-time {
    font-size: 9px;
    font-family: var(--font-mono);
    color: var(--text-muted);
}

.clip-card-duration {
    font-size: 10px;
    font-family: var(--font-mono);
    color: var(--accent-cyan);
}

.clip-card-actions {
    display: flex;
    gap: 2px;
    padding: 2px 4px 4px;
}

.clip-action-btn {
    flex: 1;
    padding: 4px;
    border: none;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-muted);
    border-radius: 3px;
    cursor: pointer;
    font-size: 12px;
    transition: all var(--transition-fast);
    text-align: center;
}

.clip-action-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    color: var(--text-primary);
}

.clip-action-btn.download {
    color: var(--accent-green);
    font-weight: 700;
}
.clip-action-btn.download:hover {
    background: rgba(0, 255, 136, 0.15);
    color: var(--accent-green);
}
.clip-action-btn.delete:hover { color: var(--accent-red); }

/* --- Clip Preview Modal --- */
.clip-preview-modal {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.85);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
}

.clip-preview-modal.active { display: flex; }

.clip-preview-container {
    width: 90%;
    max-width: 640px;
    border-radius: var(--radius-lg);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    overflow: hidden;
}

.clip-preview-video {
    width: 100%;
    max-height: 60vh;
    background: #000;
}

.clip-preview-actions {
    display: flex;
    gap: 8px;
    padding: 12px;
    justify-content: flex-end;
}

/* --- Event Log --- */
.event-log {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-void);
    font-family: var(--font-mono);
    font-size: 11px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.event-log-entry {
    padding: 4px 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    display: flex;
    gap: 8px;
    align-items: baseline;
}

.event-log-entry:last-child { border-bottom: none; }

.event-log-time {
    color: var(--text-muted);
    flex-shrink: 0;
    font-size: 10px;
}

.event-log-type {
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    flex-shrink: 0;
}

.event-log-type.trigger {
    background: rgba(255, 51, 85, 0.2);
    color: var(--accent-red);
}

.event-log-type.detection {
    background: rgba(0, 255, 136, 0.15);
    color: var(--accent-green);
}

.event-log-type.pose {
    background: rgba(255, 0, 255, 0.15);
    color: var(--accent-magenta);
}

.event-log-type.info {
    background: rgba(0, 212, 255, 0.15);
    color: var(--accent-cyan);
}

.event-log-type.error {
    background: rgba(255, 51, 85, 0.2);
    color: var(--accent-red);
}

.event-log-msg {
    color: var(--text-secondary);
    word-break: break-word;
}

/* --- Spectrogram Mini-View --- */
.spectrogram-container {
    width: 100%;
    height: 80px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-void);
    overflow: hidden;
}

.spectrogram-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* --- Orientation Warning Overlay --- */
.orientation-warning {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    background: var(--bg-void);
    color: var(--text-primary);
    text-align: center;
    padding: 32px;
}

.orientation-warning .rotate-icon {
    font-size: 48px;
    animation: rotate-hint 2s ease-in-out infinite;
}

@keyframes rotate-hint {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(90deg); }
}

.orientation-warning h2 {
    font-size: 18px;
    font-weight: 700;
}

.orientation-warning p {
    font-size: 13px;
    color: var(--text-secondary);
    max-width: 280px;
}

.orientation-warning .dismiss-btn {
    margin-top: 8px;
}

/* Show orientation warning only in portrait on mobile */
@media (orientation: portrait) and (max-width: 768px) {
    .orientation-warning.enabled {
        display: flex;
    }
}

/* --- Toast Notifications --- */
.toast-container {
    position: fixed;
    top: 60px;
    right: 12px;
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    border: 1px solid var(--border);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    font-size: 12px;
    color: var(--text-primary);
    pointer-events: auto;
    animation: toast-in 300ms ease forwards;
    max-width: 300px;
}

.toast.success { border-color: var(--accent-green); }
.toast.error { border-color: var(--accent-red); }
.toast.warning { border-color: var(--accent-amber); }

.toast.removing {
    animation: toast-out 200ms ease forwards;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateX(30px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes toast-out {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(30px); }
}

/* --- Permission Request Screen --- */
.permission-screen {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 24px;
    background: var(--bg-void);
    text-align: center;
    padding: 32px;
}

.permission-screen h1 {
    font-size: 26px;
    font-weight: 900;
    letter-spacing: -0.5px;
    color: var(--text-primary);
}

.permission-creator {
    font-size: 12px;
    font-family: var(--font-mono);
    color: var(--text-muted);
    letter-spacing: 1px;
    text-transform: uppercase;
}

.permission-screen p {
    font-size: 14px;
    color: var(--text-secondary);
    max-width: 360px;
    line-height: 1.6;
}

.permission-features {
    display: flex;
    gap: 24px;
    margin: 16px 0;
}

.permission-feature {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

.permission-feature .icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--bg-card);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

/* --- Responsive --- */
@media (min-width: 769px) {
    .control-drawer {
        max-width: 420px;
        left: auto;
        right: 16px;
        bottom: 16px;
        border-radius: var(--radius-lg);
        max-height: 70vh;
        padding-bottom: 0;
    }

    .audio-meter {
        height: 300px;
    }

    .clip-gallery-inline {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }
}

@media (max-width: 480px) {
    .status-bar {
        padding: 6px 8px;
        min-height: 40px;
    }

    .state-badge { font-size: 10px; padding: 3px 8px; }
    .buffer-bar { width: 36px; }

    .clip-gallery-inline {
        grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
        gap: 8px;
    }

    .quick-actions {
        gap: 10px;
        padding: 0 12px 8px;
    }

    .quick-btn {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }

    .quick-btn.trigger {
        width: 50px;
        height: 50px;
        font-size: 20px;
    }

    .drawer-tab {
        padding: 6px 10px;
        font-size: 11px;
    }

    .drawer-content {
        padding: 12px;
    }
}

/* --- Utility --- */
.hidden { display: none !important; }
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}

.mono { font-family: var(--font-mono); }
.text-cyan { color: var(--accent-cyan); }
.text-green { color: var(--accent-green); }
.text-red { color: var(--accent-red); }
.text-amber { color: var(--accent-amber); }
.text-muted { color: var(--text-muted); }

/* --- Loading Spinner --- */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--accent-cyan);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* --- Model Status --- */
.model-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-family: var(--font-mono);
}

.model-status.not-loaded {
    background: rgba(85, 85, 112, 0.2);
    color: var(--text-muted);
}

.model-status.loading {
    background: rgba(255, 170, 0, 0.15);
    color: var(--accent-amber);
}

.model-status.loaded {
    background: rgba(0, 255, 136, 0.1);
    color: var(--accent-green);
}

.model-status.error {
    background: rgba(255, 51, 85, 0.15);
    color: var(--accent-red);
}

/* --- Pose Keypoint Debug Overlay --- */
.pose-debug {
    position: absolute;
    top: 56px;
    right: 8px;
    z-index: var(--z-controls);
    width: 200px;
    max-height: 300px;
    overflow-y: auto;
    background: rgba(6, 6, 15, 0.8);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px;
    font-family: var(--font-mono);
    font-size: 9px;
    color: var(--text-muted);
    pointer-events: none;
    display: none;
}

.pose-debug.active { display: block; }

.pose-debug-entry {
    display: flex;
    justify-content: space-between;
    padding: 1px 0;
}

.pose-debug-entry .kp-name { color: var(--accent-magenta); }
.pose-debug-entry .kp-conf { color: var(--accent-green); }

/* --- Running Detection Indicator --- */
.runner-indicator {
    position: absolute;
    top: 56px;
    left: 50%;
    transform: translateX(-50%);
    z-index: var(--z-controls);
    display: none;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 20px;
    background: rgba(0, 255, 136, 0.15);
    border: 1px solid rgba(0, 255, 136, 0.3);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 700;
    color: var(--accent-green);
}

.runner-indicator.active { display: flex; }

/* --- Base Zone Calibration --- */
.base-zone-overlay {
    position: absolute;
    inset: 0;
    z-index: calc(var(--z-overlay) + 5);
    pointer-events: none;
    display: none;
}

.base-zone-overlay.active {
    display: block;
    pointer-events: auto;
}

.base-zone-marker {
    position: absolute;
    width: 30px;
    height: 30px;
    border: 2px solid var(--accent-amber);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 170, 0, 0.2);
    cursor: move;
    touch-action: none;
}

.base-zone-marker::after {
    content: attr(data-label);
    position: absolute;
    top: -18px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    font-family: var(--font-mono);
    font-weight: 700;
    color: var(--accent-amber);
    white-space: nowrap;
}
