/**
 * BullseyeCam - Stylesheet
 * BullseyeOS Design System
 */

/* ============================================
   CSS VARIABLES
   ============================================ */
:root {
    /* Backgrounds */
    --bg-dark: #0a0a0a;
    --bg-card: #151515;
    --bg-input: #1c1c1c;
    --bg-overlay: rgba(10, 10, 10, 0.9);
    --border-color: #2a2a2a;
    --border-light: #3a3a3a;
    
    /* Primary Colors */
    --primary: #dc2626;
    --primary-hover: #b91c1c;
    --primary-glow: rgba(220, 38, 38, 0.3);
    
    /* Status Colors */
    --success: #22c55e;
    --success-glow: rgba(34, 197, 94, 0.3);
    --warning: #eab308;
    --warning-glow: rgba(234, 179, 8, 0.3);
    --info: #3b82f6;
    --info-glow: rgba(59, 130, 246, 0.3);
    --danger: #ef4444;
    
    /* Text */
    --text-primary: #ffffff;
    --text-secondary: #a1a1a1;
    --text-muted: #6b6b6b;
    
    /* Radii */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    
    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    
    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 400ms ease;
    
    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px var(--primary-glow);
    
    /* Font Families */
    --font-display: 'Bebas Neue', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    
    /* Safe Areas */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ============================================
   RESET & BASE
   ============================================ */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-body);
    background: var(--bg-dark);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
}

img, svg {
    display: block;
    max-width: 100%;
}

button {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    background: none;
    border: none;
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
}

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

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

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

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

/* ============================================
   TYPOGRAPHY
   ============================================ */
h1, h2, h3, h4 {
    font-weight: 600;
    line-height: 1.2;
}

h1 {
    font-size: 1.5rem;
}

h2 {
    font-size: 1.25rem;
}

h3 {
    font-size: 1rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-md);
}

.muted {
    color: var(--text-muted);
}

/* ============================================
   SCREENS
   ============================================ */
.screen {
    position: fixed;
    inset: 0;
    display: none;
    flex-direction: column;
    background: var(--bg-dark);
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
    opacity: 0;
    transform: translateX(20px);
    transition: opacity var(--transition-normal), transform var(--transition-normal);
}

.screen.active {
    display: flex;
    opacity: 1;
    transform: translateX(0);
}

.screen-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md);
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-card);
    min-height: 60px;
}

.screen-header h1 {
    flex: 1;
    text-align: center;
}

.screen-header .spacer {
    width: 40px;
}

/* ============================================
   LOADING SCREEN
   ============================================ */
#screen-loading {
    justify-content: center;
    align-items: center;
    background: radial-gradient(ellipse at center, #1a1a1a 0%, var(--bg-dark) 70%);
}

.loading-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-xl);
    padding: var(--space-lg);
    max-width: 320px;
}

.loading-logo {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-sm);
}

.logo-icon {
    font-size: 4rem;
    animation: pulse 2s ease-in-out infinite;
}

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

.logo-text {
    font-family: var(--font-display);
    font-size: 3rem;
    letter-spacing: 0.05em;
    background: linear-gradient(135deg, var(--text-primary) 0%, var(--primary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.loading-progress {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.progress-bar {
    height: 4px;
    background: var(--bg-input);
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--primary), var(--danger));
    border-radius: 2px;
    transition: width var(--transition-slow);
}

.loading-status {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.loading-steps {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    width: 100%;
}

.step {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
}

.step-icon {
    font-size: 1rem;
}

.step.done .step-icon::before {
    content: '✅';
}

.step.error .step-icon::before {
    content: '❌';
}

/* ============================================
   START SCREEN
   ============================================ */
.logo-small {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-family: var(--font-display);
    font-size: 1.25rem;
    letter-spacing: 0.02em;
}

.start-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: var(--space-lg);
    gap: var(--space-lg);
    overflow-y: auto;
}

.camera-selection h2 {
    margin-bottom: var(--space-xs);
}

.hint {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: var(--space-md);
}

.camera-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.camera-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-lg);
    color: var(--text-muted);
}

.camera-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.camera-item:hover {
    border-color: var(--border-light);
}

.camera-item.selected {
    border-color: var(--primary);
    background: rgba(220, 38, 38, 0.1);
}

.camera-checkbox {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border-light);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.camera-item.selected .camera-checkbox {
    background: var(--primary);
    border-color: var(--primary);
}

.camera-item.selected .camera-checkbox::after {
    content: '✓';
    color: white;
    font-size: 14px;
    font-weight: bold;
}

.camera-name {
    flex: 1;
    font-weight: 500;
}

.camera-type {
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 2px 8px;
    background: var(--bg-input);
    border-radius: 4px;
}

.camera-info {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md);
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.start-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-lg);
    border-top: 1px solid var(--border-color);
}

.version {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

/* ============================================
   BUTTONS
   ============================================ */
.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.icon-btn:hover {
    background: var(--bg-input);
    color: var(--text-primary);
}

.icon-btn:active {
    transform: scale(0.95);
}

.link-btn {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    color: var(--text-secondary);
    font-size: 0.875rem;
    transition: color var(--transition-fast);
}

.link-btn:hover {
    color: var(--text-primary);
}

.btn-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    background: var(--primary);
    color: white;
    font-weight: 600;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    box-shadow: var(--shadow-glow);
}

.btn-primary:active:not(:disabled) {
    transform: scale(0.98);
}

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

.btn-large {
    padding: var(--space-lg) var(--space-xl);
    font-size: 1.25rem;
    border-radius: var(--radius-lg);
}

.btn-large .btn-icon {
    font-size: 1.5rem;
}

.btn-secondary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-weight: 500;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.btn-secondary:hover {
    background: var(--bg-card);
    border-color: var(--border-light);
}

.btn-danger {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    width: 100%;
    padding: var(--space-md);
    background: transparent;
    border: 1px solid var(--danger);
    color: var(--danger);
    font-weight: 500;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.1);
}

.btn-action {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-weight: 500;
    transition: all var(--transition-fast);
}

.btn-action:hover {
    background: var(--bg-input);
}

/* ============================================
   CALIBRATION SCREEN
   ============================================ */
.calibration-view {
    flex: 1;
    position: relative;
    background: #000;
    min-height: 0;
}

.video-container {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.video-container video {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.video-container canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.calib-hint {
    position: absolute;
    bottom: var(--space-md);
    left: 50%;
    transform: translateX(-50%);
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-overlay);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.camera-tabs {
    position: absolute;
    top: var(--space-md);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: var(--space-xs);
    padding: var(--space-xs);
    background: var(--bg-overlay);
    border-radius: var(--radius-sm);
}

.camera-tab {
    padding: var(--space-xs) var(--space-md);
    background: transparent;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.camera-tab.active {
    background: var(--primary);
    color: white;
}

.calibration-controls {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    padding: var(--space-lg);
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
    max-height: 50vh;
    overflow-y: auto;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.control-group.half {
    flex: 1;
}

.control-group label {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.control-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.control-value {
    font-family: var(--font-mono);
    font-size: 0.875rem;
    color: var(--primary);
}

.control-row {
    display: flex;
    gap: var(--space-lg);
}

.calibration-actions {
    display: flex;
    gap: var(--space-md);
    padding: var(--space-md) var(--space-lg);
    border-top: 1px solid var(--border-color);
}

.calibration-actions .btn-secondary {
    flex: 1;
}

.calibration-actions .btn-primary {
    flex: 2;
}

/* ============================================
   GAME SCREEN
   ============================================ */
#screen-game {
    padding: 0;
}

.game-view {
    flex: 1;
    position: relative;
    background: #000;
}

.video-feeds {
    position: absolute;
    inset: 0;
    display: grid;
    gap: 2px;
}

.video-feeds.single {
    grid-template-columns: 1fr;
}

.video-feeds.dual {
    grid-template-columns: 1fr 1fr;
}

.video-feeds.triple {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
}

.video-feeds.triple .video-feed:first-child {
    grid-row: span 2;
}

.video-feed {
    position: relative;
    background: #111;
    overflow: hidden;
}

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

.video-feed canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}

.video-feed-label {
    position: absolute;
    top: var(--space-sm);
    left: var(--space-sm);
    padding: 2px 8px;
    background: var(--bg-overlay);
    border-radius: 4px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.game-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: var(--space-md);
}

.current-throw {
    align-self: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--space-md) var(--space-xl);
    background: var(--bg-overlay);
    border-radius: var(--radius-lg);
    backdrop-filter: blur(8px);
    opacity: 0;
    transform: translateY(-20px);
    transition: all var(--transition-normal);
}

.current-throw.visible {
    opacity: 1;
    transform: translateY(0);
}

.throw-segment {
    font-family: var(--font-display);
    font-size: 2.5rem;
    letter-spacing: 0.05em;
}

.throw-score {
    font-family: var(--font-mono);
    font-size: 1.5rem;
    color: var(--primary);
}

.throw-history {
    display: flex;
    justify-content: center;
    gap: var(--space-sm);
}

.throw-history-item {
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-overlay);
    border-radius: var(--radius-sm);
    backdrop-filter: blur(4px);
    font-family: var(--font-mono);
    font-size: 0.875rem;
}

.game-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-lg);
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
}

.btn-menu {
    width: 48px;
    height: 48px;
}

/* ============================================
   DRAWER
   ============================================ */
.drawer {
    position: fixed;
    inset: 0;
    z-index: 100;
    pointer-events: none;
}

.drawer.open {
    pointer-events: auto;
}

.drawer-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    opacity: 0;
    transition: opacity var(--transition-normal);
}

.drawer.open .drawer-backdrop {
    opacity: 1;
}

.drawer-content {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 80%;
    max-width: 320px;
    background: var(--bg-card);
    transform: translateX(100%);
    transition: transform var(--transition-normal);
    display: flex;
    flex-direction: column;
}

.drawer.open .drawer-content {
    transform: translateX(0);
}

.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--border-color);
    padding-top: calc(var(--space-md) + var(--safe-top));
}

.drawer-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: var(--space-md);
}

.drawer-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    transition: background var(--transition-fast);
}

.drawer-item:hover {
    background: var(--bg-input);
}

.drawer-item.danger {
    color: var(--danger);
    margin-top: auto;
}

.toggle-indicator {
    margin-left: auto;
    font-size: 0.75rem;
    font-family: var(--font-mono);
    color: var(--text-muted);
}

.toggle-indicator.on {
    color: var(--success);
}

/* ============================================
   SETTINGS SCREEN
   ============================================ */
.settings-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
    padding: var(--space-lg);
    overflow-y: auto;
}

.settings-section {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.setting-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    padding: var(--space-md);
    background: var(--bg-card);
    border-radius: var(--radius-md);
}

.setting-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.setting-label {
    font-weight: 500;
}

.setting-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.setting-control {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    min-width: 120px;
}

.setting-control input[type="range"] {
    flex: 1;
}

.setting-value {
    font-family: var(--font-mono);
    font-size: 0.875rem;
    color: var(--primary);
    min-width: 50px;
    text-align: right;
}

/* Toggle Switch */
.toggle {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 28px;
}

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

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--bg-input);
    border-radius: 14px;
    transition: background var(--transition-fast);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background: var(--text-secondary);
    border-radius: 50%;
    transition: all var(--transition-fast);
}

.toggle input:checked + .toggle-slider {
    background: var(--primary);
}

.toggle input:checked + .toggle-slider::before {
    transform: translateX(20px);
    background: white;
}

/* ============================================
   HELP SCREEN
   ============================================ */
.help-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
    padding: var(--space-lg);
    overflow-y: auto;
}

.help-section {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.help-section ol,
.help-section ul {
    padding-left: var(--space-lg);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    color: var(--text-secondary);
}

.help-section li::marker {
    color: var(--primary);
}

.help-section strong {
    color: var(--text-primary);
}

.faq-item {
    padding: var(--space-md);
    background: var(--bg-card);
    border-radius: var(--radius-md);
}

.faq-item h4 {
    font-size: 0.875rem;
    margin-bottom: var(--space-xs);
}

.faq-item p {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* ============================================
   TOAST NOTIFICATIONS
   ============================================ */
.toast-container {
    position: fixed;
    top: calc(var(--space-lg) + var(--safe-top));
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    font-size: 0.875rem;
    pointer-events: auto;
    animation: toastIn 0.3s ease forwards;
}

.toast.success {
    border-color: var(--success);
    background: rgba(34, 197, 94, 0.1);
}

.toast.error {
    border-color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
}

.toast.warning {
    border-color: var(--warning);
    background: rgba(234, 179, 8, 0.1);
}

.toast.out {
    animation: toastOut 0.3s ease forwards;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes toastOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-20px);
    }
}

/* ============================================
   SPINNER
   ============================================ */
.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* ============================================
   RESPONSIVE
   ============================================ */
@media (min-width: 768px) {
    .start-content {
        max-width: 480px;
        margin: 0 auto;
    }
    
    .calibration-controls {
        flex-direction: row;
        flex-wrap: wrap;
        max-height: none;
    }
    
    .calibration-controls .control-group {
        flex: 1;
        min-width: 200px;
    }
    
    .calibration-controls .control-row {
        flex: 1;
        min-width: 420px;
    }
    
    .settings-content {
        max-width: 600px;
        margin: 0 auto;
    }
    
    .help-content {
        max-width: 700px;
        margin: 0 auto;
    }
}

/* ============================================
   DARK MODE ADJUSTMENTS (always dark)
   ============================================ */
@media (prefers-color-scheme: light) {
    /* Keep dark theme */
}

/* ============================================
   REDUCED MOTION
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
