/* ============================================
   StableCam - 水平穩定相機 設計系統
   ============================================ */

/* --- Design Tokens --- */
:root {
    /* Colors */
    --clr-bg: #0a0a0f;
    --clr-surface: #14141f;
    --clr-surface-2: #1e1e2e;
    --clr-surface-3: #2a2a3e;
    --clr-border: rgba(255, 255, 255, 0.08);
    --clr-text: #f0f0f5;
    --clr-text-muted: rgba(255, 255, 255, 0.55);
    --clr-text-dim: rgba(255, 255, 255, 0.3);

    /* Accents */
    --clr-primary: #6366f1;
    --clr-primary-glow: rgba(99, 102, 241, 0.35);
    --clr-accent: #06b6d4;
    --clr-accent-glow: rgba(6, 182, 212, 0.3);
    --clr-success: #22c55e;
    --clr-success-glow: rgba(34, 197, 94, 0.3);
    --clr-danger: #ef4444;
    --clr-danger-glow: rgba(239, 68, 68, 0.4);
    --clr-warning: #f59e0b;

    /* Gradients */
    --grad-primary: linear-gradient(135deg, #6366f1, #06b6d4);
    --grad-danger: linear-gradient(135deg, #ef4444, #f97316);
    --grad-glass: linear-gradient(135deg, rgba(255,255,255,0.08), rgba(255,255,255,0.02));

    /* Typography */
    --font-main: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    /* Spacing */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);

    /* Radii */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-xl: 28px;

    /* Transitions */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* --- Reset & Base --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: var(--font-main);
    background: var(--clr-bg);
    color: var(--clr-text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

/* --- Splash Screen --- */
.splash-screen {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--clr-bg);
    transition: opacity 0.6s var(--ease-out), transform 0.6s var(--ease-out);
}

.splash-screen.fade-out {
    opacity: 0;
    transform: scale(1.05);
    pointer-events: none;
}

.splash-content {
    text-align: center;
    animation: splashFadeIn 0.8s var(--ease-out);
}

.splash-icon {
    width: 80px;
    height: 80px;
    margin: 0 auto 24px;
    animation: splashPulse 2s ease-in-out infinite;
}

.splash-icon svg {
    width: 100%;
    height: 100%;
}

.splash-title {
    font-size: 32px;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: var(--grad-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.splash-subtitle {
    font-size: 14px;
    color: var(--clr-text-muted);
    letter-spacing: 2px;
    text-transform: uppercase;
    margin-bottom: 40px;
}

.splash-loader {
    width: 120px;
    height: 3px;
    background: var(--clr-surface-2);
    border-radius: 3px;
    margin: 0 auto;
    overflow: hidden;
}

.splash-loader-bar {
    width: 0%;
    height: 100%;
    background: var(--grad-primary);
    border-radius: 3px;
    animation: splashLoad 1.5s var(--ease-out) forwards;
}

@keyframes splashFadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes splashPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

@keyframes splashLoad {
    to { width: 100%; }
}

/* --- Permission Screen --- */
.permission-screen {
    position: fixed;
    inset: 0;
    z-index: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--clr-bg);
    padding: 24px;
}

.permission-card {
    max-width: 380px;
    width: 100%;
    background: var(--grad-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-xl);
    padding: 40px 32px;
    text-align: center;
    animation: cardSlideUp 0.6s var(--ease-out);
}

@keyframes cardSlideUp {
    from { opacity: 0; transform: translateY(40px); }
    to { opacity: 1; transform: translateY(0); }
}

.permission-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 24px;
}

.permission-icon svg {
    width: 100%;
    height: 100%;
}

.permission-card h2 {
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 8px;
}

.permission-card p {
    font-size: 14px;
    color: var(--clr-text-muted);
    margin-bottom: 24px;
    line-height: 1.5;
}

.permission-list {
    list-style: none;
    text-align: left;
    margin-bottom: 32px;
}

.permission-list li {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    font-size: 14px;
    color: var(--clr-text-muted);
    border-bottom: 1px solid var(--clr-border);
}

.permission-list li:last-child {
    border-bottom: none;
}

.permission-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.permission-dot.camera { background: var(--clr-primary); }
.permission-dot.gyro { background: var(--clr-accent); }
.permission-dot.mic { background: var(--clr-success); }

.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 14px 28px;
    font-size: 15px;
    font-weight: 600;
    font-family: var(--font-main);
    color: #fff;
    background: var(--grad-primary);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: transform 0.2s var(--ease-spring), box-shadow 0.3s ease;
    box-shadow: 0 4px 20px var(--clr-primary-glow);
}

.btn-primary:active {
    transform: scale(0.97);
}

/* --- Camera Screen --- */
.camera-screen {
    position: fixed;
    inset: 0;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
}

#camera-video {
    display: none;
}

.stable-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* --- Top Bar --- */
.top-bar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: calc(var(--safe-top) + 12px) calc(var(--safe-right) + 16px) 12px calc(var(--safe-left) + 16px);
    background: linear-gradient(to bottom, rgba(0,0,0,0.6) 0%, transparent 100%);
}

.top-bar-left,
.top-bar-right {
    display: flex;
    gap: 8px;
}

.top-bar-center {
    flex: 1;
    display: flex;
    justify-content: center;
}

.icon-btn {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    cursor: pointer;
    color: #fff;
    transition: transform 0.2s var(--ease-spring), background 0.2s ease;
}

.icon-btn:active {
    transform: scale(0.9);
}

.icon-btn svg {
    width: 20px;
    height: 20px;
}

.icon-btn.small {
    width: 36px;
    height: 36px;
}

.icon-btn.small svg {
    width: 16px;
    height: 16px;
}

/* --- Recording Indicator --- */
.recording-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    background: rgba(239, 68, 68, 0.2);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 20px;
    animation: recFadeIn 0.3s var(--ease-out);
}

@keyframes recFadeIn {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

.rec-dot {
    width: 8px;
    height: 8px;
    background: var(--clr-danger);
    border-radius: 50%;
    animation: recBlink 1s ease-in-out infinite;
}

@keyframes recBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.rec-timer {
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 500;
    color: #fff;
    min-width: 44px;
}

/* --- Level Indicator --- */
.level-indicator {
    position: absolute;
    bottom: 180px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 24px;
    transition: opacity 0.3s ease;
}

.level-track {
    position: relative;
    width: 120px;
    height: 24px;
    display: flex;
    align-items: center;
}

.level-marks {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 4px;
}

.mark {
    width: 1px;
    height: 8px;
    background: rgba(255, 255, 255, 0.2);
}

.mark.center {
    height: 14px;
    background: rgba(255, 255, 255, 0.4);
    width: 2px;
}

.level-bubble {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 14px;
    height: 14px;
    background: var(--clr-accent);
    border-radius: 50%;
    box-shadow: 0 0 12px var(--clr-accent-glow);
    transition: left 0.15s var(--ease-out);
}

.level-bubble.level {
    background: var(--clr-success);
    box-shadow: 0 0 12px var(--clr-success-glow);
}

.level-angle {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--clr-text-muted);
    min-width: 38px;
    text-align: center;
}

/* --- Stabilization Badge --- */
.stabilization-badge {
    position: absolute;
    top: calc(var(--safe-top) + 70px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    background: rgba(34, 197, 94, 0.15);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(34, 197, 94, 0.25);
    border-radius: 16px;
    font-size: 12px;
    font-weight: 500;
    color: var(--clr-success);
    transition: all 0.3s var(--ease-out);
}

.stabilization-badge.off {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.12);
    color: var(--clr-text-muted);
}

.stabilization-badge svg {
    opacity: 0.8;
}

/* --- Bottom Bar --- */
.bottom-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 10;
    padding: 20px 24px calc(var(--safe-bottom) + 24px);
    background: linear-gradient(to top, rgba(0,0,0,0.7) 0%, transparent 100%);
}

.bottom-bar-content {
    display: flex;
    align-items: flex-end;
    justify-content: space-around;
    max-width: 360px;
    margin: 0 auto;
}

.control-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.control-label {
    font-size: 11px;
    color: var(--clr-text-muted);
    letter-spacing: 0.5px;
}

/* Toggle Button */
.toggle-btn {
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1.5px solid rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    transition: all 0.3s var(--ease-spring);
}

.toggle-btn svg {
    width: 22px;
    height: 22px;
}

.toggle-btn.active {
    background: rgba(99, 102, 241, 0.25);
    border-color: var(--clr-primary);
    color: var(--clr-primary);
    box-shadow: 0 0 20px var(--clr-primary-glow);
}

.toggle-btn:active {
    transform: scale(0.9);
}

.lens-label {
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: 600;
}

/* Record Button */
.record-btn {
    width: 72px;
    height: 72px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 3px solid rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    cursor: pointer;
    padding: 5px;
    transition: transform 0.2s var(--ease-spring), border-color 0.3s ease;
}

.record-btn-inner {
    width: 100%;
    height: 100%;
    background: var(--clr-danger);
    border-radius: 50%;
    transition: all 0.3s var(--ease-spring);
}

.record-btn:active {
    transform: scale(0.92);
}

.record-btn.recording {
    border-color: var(--clr-danger);
}

.record-btn.recording .record-btn-inner {
    border-radius: 6px;
    width: 28px;
    height: 28px;
    background: var(--clr-danger);
}

/* --- Settings Panel --- */
.settings-panel {
    position: absolute;
    inset: 0;
    z-index: 50;
}

.settings-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.settings-content {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--clr-surface);
    border-top: 1px solid var(--clr-border);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    max-height: 70vh;
    overflow-y: auto;
    padding-bottom: var(--safe-bottom);
    animation: settingsSlideUp 0.4s var(--ease-out);
}

@keyframes settingsSlideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--clr-border);
    position: sticky;
    top: 0;
    background: var(--clr-surface);
    z-index: 1;
}

.settings-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.settings-body {
    padding: 8px 24px 24px;
}

.setting-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 0;
    border-bottom: 1px solid var(--clr-border);
}

.setting-item:last-child {
    border-bottom: none;
}

.setting-item label {
    font-size: 14px;
    font-weight: 500;
}

.setting-item select {
    padding: 8px 12px;
    font-size: 13px;
    font-family: var(--font-main);
    background: var(--clr-surface-2);
    color: var(--clr-text);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-sm);
    outline: none;
    cursor: pointer;
    min-width: 140px;
}

.range-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

.range-value {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--clr-accent);
    min-width: 28px;
    text-align: center;
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100px;
    height: 4px;
    background: var(--clr-surface-3);
    border-radius: 4px;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--grad-primary);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 8px var(--clr-primary-glow);
}

/* Switch */
.switch {
    position: relative;
    width: 48px;
    height: 26px;
    cursor: pointer;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch-slider {
    position: absolute;
    inset: 0;
    background: var(--clr-surface-3);
    border-radius: 26px;
    transition: background 0.3s ease;
}

.switch-slider::before {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.3s var(--ease-spring);
}

.switch input:checked + .switch-slider {
    background: var(--clr-primary);
}

.switch input:checked + .switch-slider::before {
    transform: translateX(22px);
}

/* --- Grid Overlay --- */
.grid-overlay {
    position: absolute;
    inset: 0;
    z-index: 5;
    pointer-events: none;
}

.grid-line {
    position: absolute;
    background: rgba(255, 255, 255, 0.15);
}

.grid-line.h {
    left: 0;
    right: 0;
    height: 1px;
}

.grid-line.v {
    top: 0;
    bottom: 0;
    width: 1px;
}

/* --- Toast --- */
.toast-container {
    position: absolute;
    top: calc(var(--safe-top) + 110px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}

.toast {
    padding: 10px 20px;
    background: rgba(30, 30, 46, 0.9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
    color: var(--clr-text);
    white-space: nowrap;
    animation: toastIn 0.3s var(--ease-out);
}

.toast.toast-out {
    animation: toastOut 0.3s var(--ease-out) forwards;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(-10px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toastOut {
    from { opacity: 1; transform: translateY(0) scale(1); }
    to { opacity: 0; transform: translateY(-10px) scale(0.95); }
}

/* --- Utility --- */
.hidden {
    display: none !important;
}

/* Landscape adjustments */
@media (orientation: landscape) {
    .bottom-bar {
        padding-bottom: calc(var(--safe-bottom) + 12px);
    }

    .level-indicator {
        bottom: 100px;
    }
}

/* Small screens */
@media (max-height: 640px) {
    .level-indicator {
        bottom: 150px;
    }
}
