/* ========== Reset & Base ========== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --accent: #FFD700;
    --accent-glow: rgba(255, 215, 0, 0.4);
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #000;
    color: #fff;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

#app {
    width: 100%;
    height: 100%;
    position: relative;
}

/* ========== Views ========== */
.view {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 1;
}

.view.active {
    opacity: 1;
    pointer-events: auto;
    z-index: 2;
}

/* ========== Camera View ========== */
#camera-view {
    background: #000;
}

/* Top Bar */
.top-bar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: calc(12px + var(--safe-top)) 16px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 10;
    background: linear-gradient(to bottom, rgba(0,0,0,0.5) 0%, transparent 100%);
}

.top-btn {
    width: 44px;
    height: 44px;
    border: none;
    background: rgba(255,255,255,0.15);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 50%;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.top-btn:active {
    transform: scale(0.9);
    background: rgba(255,255,255,0.25);
}

.top-btn.flash-on {
    background: var(--accent);
    color: #000;
}

/* AI Badge */
.ai-badge {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    top: calc(16px + var(--safe-top));
    background: linear-gradient(135deg, rgba(255,215,0,0.2), rgba(255,165,0,0.2));
    border: 1px solid rgba(255,215,0,0.4);
    border-radius: 20px;
    padding: 6px 16px;
    font-size: 13px;
    font-weight: 500;
    color: var(--accent);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    animation: badgePulse 2s ease-in-out infinite;
    z-index: 11;
}

.ai-badge.hidden {
    display: none;
}

@keyframes badgePulse {
    0%, 100% { box-shadow: 0 0 8px var(--accent-glow); }
    50% { box-shadow: 0 0 20px var(--accent-glow); }
}

/* Camera Container */
.camera-container {
    flex: 1;
    position: relative;
    overflow: hidden;
}

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

#filter-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
}

/* ========== Beauty Panel ========== */
.beauty-panel {
    position: absolute;
    bottom: 180px;
    left: 0;
    right: 0;
    padding: 16px 24px;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid rgba(255,255,255,0.1);
    z-index: 5;
    transition: all 0.3s ease;
}

.beauty-panel.hidden {
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
}

.beauty-slider-group {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

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

.beauty-slider-group label {
    font-size: 14px;
    color: rgba(255,255,255,0.8);
    min-width: 40px;
}

.beauty-slider {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    background: rgba(255,255,255,0.2);
    border-radius: 2px;
    outline: none;
}

.beauty-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 0 8px var(--accent-glow);
}

.beauty-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: none;
}

.slider-val {
    font-size: 13px;
    color: var(--accent);
    min-width: 30px;
    text-align: right;
}

/* ========== Bottom Area ========== */
.bottom-area {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding-bottom: calc(12px + var(--safe-bottom));
    background: linear-gradient(to top, rgba(0,0,0,0.8) 0%, rgba(0,0,0,0.4) 60%, transparent 100%);
    z-index: 10;
}

/* Filter Bar */
.filter-bar {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
    scroll-behavior: smooth;
    scroll-snap-type: x mandatory;
}

.filter-bar::-webkit-scrollbar {
    display: none;
}

.filter-item {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    scroll-snap-align: center;
    transition: all 0.2s ease;
}

.filter-item:active {
    transform: scale(0.95);
}

.filter-thumb {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.2);
    object-fit: cover;
    transition: border-color 0.3s ease;
}

.filter-item.active .filter-thumb {
    border-color: var(--accent);
    box-shadow: 0 0 12px var(--accent-glow);
}

.filter-item span {
    font-size: 11px;
    color: rgba(255,255,255,0.6);
    white-space: nowrap;
    transition: color 0.3s ease;
}

.filter-item.active span {
    color: var(--accent);
}

/* Shutter Row */
.shutter-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 40px;
    padding: 8px 0 8px;
}

.side-btn {
    width: 48px;
    height: 48px;
    border: none;
    background: rgba(255,255,255,0.12);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 50%;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.side-btn:active {
    transform: scale(0.9);
    background: rgba(255,255,255,0.25);
}

.side-btn.active {
    background: var(--accent);
    color: #000;
}

/* Shutter Button */
.shutter-btn {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    border: 4px solid rgba(255,255,255,0.9);
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
}

.shutter-inner {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: rgba(255,255,255,0.9);
    transition: all 0.15s ease;
}

.shutter-btn:active .shutter-inner {
    transform: scale(0.85);
    background: rgba(255,255,255,0.7);
}

.shutter-btn.flash {
    animation: shutterFlash 0.3s ease;
}

@keyframes shutterFlash {
    0% { transform: scale(1); }
    50% { transform: scale(0.9); border-color: var(--accent); }
    100% { transform: scale(1); }
}

/* ========== Preview View ========== */
#preview-view {
    background: #000;
    z-index: 20;
}

.preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: calc(12px + var(--safe-top)) 16px 12px;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.preview-title {
    font-size: 17px;
    font-weight: 600;
}

.save-btn {
    width: auto !important;
    padding: 0 16px !important;
    border-radius: 20px !important;
    font-size: 15px;
    font-weight: 500;
    background: var(--accent) !important;
    color: #000 !important;
}

.preview-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    overflow: hidden;
}

#preview-canvas {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
}

/* ========== Loading ========== */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 100;
    transition: opacity 0.3s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255,255,255,0.1);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.loading-overlay p {
    font-size: 14px;
    color: rgba(255,255,255,0.6);
}

/* ========== Utility ========== */
.hidden {
    display: none !important;
}

/* ========== Toast ========== */
.toast {
    position: fixed;
    bottom: calc(100px + var(--safe-bottom));
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(0,0,0,0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: #fff;
    padding: 10px 24px;
    border-radius: 24px;
    font-size: 14px;
    z-index: 200;
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ========== Composition Overlay ========== */
.composition-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 4;
}

/* ========== Composition Menu ========== */
.composition-menu {
    position: absolute;
    top: calc(68px + var(--safe-top));
    right: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 15;
    transition: all 0.3s ease;
    transform-origin: top right;
}

.composition-menu.hidden {
    opacity: 0;
    transform: scale(0.9) translateY(-10px);
    pointer-events: none;
}

.comp-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border: none;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-radius: 12px;
    color: rgba(255, 255, 255, 0.85);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.comp-option:active {
    transform: scale(0.95);
    background: rgba(255, 255, 255, 0.15);
}

.comp-option.active {
    background: rgba(255, 215, 0, 0.2);
    border-color: rgba(255, 215, 0, 0.5);
    color: var(--accent);
}

.comp-option.active svg {
    stroke: var(--accent);
}

.comp-option svg {
    flex-shrink: 0;
}

.comp-close {
    border-color: rgba(255, 80, 80, 0.3);
    color: rgba(255, 80, 80, 0.9);
}

.comp-close:active {
    background: rgba(255, 80, 80, 0.2);
}

/* ========== Composition Button Active State ========== */
#btn-composition.active {
    background: var(--accent);
    color: #000;
}
