/* ============================================
   Camera Track - Styles
   iOS Safari Optimized
   ============================================ */

:root {
    /* Colors */
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --accent: #e94560;
    --accent-light: #ff6b6b;
    --text-primary: #ffffff;
    --text-secondary: #a0a0a0;
    --success: #4caf50;
    --warning: #ff9800;
    --error: #f44336;
    
    /* Spacing */
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
    
    /* Sizes */
    --control-height: 70px;
    --settings-max-height: 70vh;
}

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

html, body {
    height: 100%;
    overflow: hidden;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

/* Prevent pull-to-refresh on iOS */
body {
    overscroll-behavior: none;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding-top: var(--safe-area-top);
    padding-bottom: var(--safe-area-bottom);
    padding-left: var(--safe-area-left);
    padding-right: var(--safe-area-right);
}

/* ============================================
   Overlays (Loading / Error)
   ============================================ */

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.overlay.hidden {
    display: none;
}

.loading-content, .error-content {
    text-align: center;
    padding: 2rem;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--bg-tertiary);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

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

#progress-bar {
    width: 200px;
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    margin: 1rem auto 0;
    overflow: hidden;
}

#progress-fill {
    height: 100%;
    width: 0%;
    background: var(--accent);
    transition: width 0.3s ease;
}

.error-content h2 {
    color: var(--error);
    margin-bottom: 1rem;
}

/* Resume Overlay */
.resume-content {
    text-align: center;
    padding: 2rem;
    cursor: pointer;
}

.resume-content:active {
    transform: scale(0.98);
}

.resume-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    animation: pulse 2s ease-in-out infinite;
}

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

.resume-content h2 {
    color: var(--accent);
    margin-bottom: 0.5rem;
    font-size: 1.5rem;
}

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

/* ============================================
   Camera Container
   ============================================ */

#camera-container {
    flex: 1;
    position: relative;
    background: #000;
    overflow: hidden;
}

#camera-video {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

#output-canvas, #overlay-canvas {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

#overlay-canvas {
    pointer-events: none;
}

/* Status Bar */
#status-bar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: linear-gradient(to bottom, rgba(0,0,0,0.7), transparent);
    font-size: 0.75rem;
    z-index: 10;
}

#status-bar span {
    padding: 0.25rem 0.5rem;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 4px;
}

#recording-indicator {
    color: var(--error);
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Tracking Info */
#tracking-info {
    position: absolute;
    bottom: 1rem;
    left: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.75rem;
}

#tracking-info span {
    padding: 0.25rem 0.5rem;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 4px;
}

/* ============================================
   Control Bar
   ============================================ */

#control-bar {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--bg-secondary);
    min-height: var(--control-height);
}

.control-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    width: 60px;
    height: 60px;
    border: none;
    border-radius: 12px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.control-btn:active {
    transform: scale(0.95);
    background: var(--accent);
}

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

.control-btn:disabled:active {
    transform: none;
    background: var(--bg-tertiary);
}

.control-btn.active {
    background: var(--accent);
}

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

.control-btn .label {
    font-size: 0.6rem;
    text-transform: uppercase;
}

.control-btn.hidden {
    display: none;
}

/* ============================================
   Settings Panel (Bottom Sheet)
   ============================================ */

#settings-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 100;
}

#settings-panel.hidden {
    display: none;
}

#settings-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

#settings-sheet {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: var(--settings-max-height);
    background: var(--bg-secondary);
    border-radius: 20px 20px 0 0;
    padding: 1rem;
    padding-bottom: calc(1rem + var(--safe-area-bottom));
    overflow-y: auto;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.sheet-handle {
    width: 40px;
    height: 4px;
    background: var(--text-secondary);
    border-radius: 2px;
    margin: 0 auto 1rem;
}

#settings-sheet h2 {
    text-align: center;
    margin-bottom: 1rem;
    font-size: 1.25rem;
}

/* Settings Sections */
.settings-section {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--bg-tertiary);
}

.settings-section:last-child {
    border-bottom: none;
}

.settings-section h3 {
    font-size: 0.9rem;
    color: var(--accent);
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0;
    min-height: 44px; /* iOS touch target */
}

.setting-row label {
    font-size: 0.9rem;
    flex: 1;
}

/* Form Elements */
select, input[type="range"] {
    background: var(--bg-tertiary);
    border: none;
    border-radius: 8px;
    color: var(--text-primary);
    padding: 0.5rem;
    font-size: 0.9rem;
    min-height: 44px;
}

select {
    min-width: 140px;
    cursor: pointer;
}

input[type="range"] {
    -webkit-appearance: none;
    width: 100px;
    height: 6px;
    padding: 0;
    min-height: auto;
}

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

input[type="checkbox"] {
    -webkit-appearance: none;
    width: 50px;
    height: 28px;
    background: var(--bg-tertiary);
    border-radius: 14px;
    position: relative;
    cursor: pointer;
    transition: background 0.2s ease;
}

input[type="checkbox"]::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 24px;
    height: 24px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s ease;
}

input[type="checkbox"]:checked {
    background: var(--accent);
}

input[type="checkbox"]:checked::after {
    transform: translateX(22px);
}

/* Info Box */
.info-box {
    background: var(--bg-tertiary);
    padding: 0.75rem;
    border-radius: 8px;
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
}

/* Buttons */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    min-height: 44px;
    transition: all 0.2s ease;
}

.btn:active {
    transform: scale(0.98);
}

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

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.settings-footer {
    margin-top: 1rem;
    text-align: center;
}

/* Range value display */
.setting-row input[type="range"] + span {
    min-width: 45px;
    text-align: right;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* ============================================
   Utility Classes
   ============================================ */

.hidden {
    display: none !important;
}

/* ============================================
   Landscape Adjustments
   ============================================ */

@media (orientation: landscape) {
    #control-bar {
        position: absolute;
        right: 0;
        top: 0;
        bottom: 0;
        flex-direction: column;
        width: 80px;
        padding: 0.5rem;
        justify-content: flex-start;
        padding-top: calc(0.5rem + var(--safe-area-top));
    }
    
    #camera-container {
        margin-right: 80px;
    }
    
    #settings-sheet {
        max-height: 100vh;
        max-width: 400px;
        margin: 0 auto;
        border-radius: 20px 20px 0 0;
    }
}

/* ============================================
   Large Screens / Desktop
   ============================================ */

@media (min-width: 768px) {
    .control-btn {
        width: 70px;
        height: 70px;
    }
    
    .control-btn .icon {
        font-size: 1.75rem;
    }
    
    .control-btn .label {
        font-size: 0.7rem;
    }
    
    #status-bar {
        font-size: 0.85rem;
    }
}
