/* =============================================
   PhotoStrip v3 — "Neon Frost" Design System
   Dark Mode  •  Purple-Pink Gradient  •  Glassmorphism
   ============================================= */

:root {
    --bg-deep:     #080810;
    --bg:          #0f0f1e;
    --bg-card:     rgba(255, 255, 255, 0.04);
    --border-card: rgba(255, 255, 255, 0.08);

    --accent-1:    #8B5CF6;
    --accent-2:    #EC4899;
    --accent-glow: rgba(139, 92, 246, 0.30);
    --accent-glow2:rgba(236, 72, 153, 0.25);

    --text:        #F8FAFC;
    --text-dim:    rgba(255, 255, 255, 0.40);
    --text-mid:    rgba(255, 255, 255, 0.65);
    --success:     #10B981;
    --danger:      #EF4444;

    --radius:      24px;
    --radius-md:   16px;
    --radius-sm:   12px;
    --safe-b:      env(safe-area-inset-bottom, 0px);
}

/* ── Reset ─────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg-deep);
    color: var(--text);
    overflow: hidden;
    height: 100%; width: 100%;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ── App Container ─────────────────────────── */
#app {
    position: relative;
    width: 100%; height: 100%;
    max-width: 480px;
    margin: 0 auto;
    background: var(--bg);
    overflow: hidden;
}

/* ── Panels (state-driven visibility) ──────── */
.panel {
    position: absolute; inset: 0;
    display: flex; flex-direction: column;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.5s cubic-bezier(0.4, 0, 0.2, 1),
                visibility 0.5s cubic-bezier(0.4, 0, 0.2, 1),
                transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateY(12px);
    z-index: 1;
}
.panel.center-panel { justify-content: center; align-items: center; padding: 32px; }

/* ── STATE VISIBILITY RULES ────────────────── */
/* Camera panel */
#app[data-state="idle"]         #panel-camera,
#app[data-state="countdown"]    #panel-camera,
#app[data-state="flash"]        #panel-camera,
#app[data-state="preview-shot"] #panel-camera { opacity:1; visibility:visible; pointer-events:auto; z-index:10; transform:translateY(0); }

/* Camera overlays */
.cam-overlay {
    position: absolute; inset: 0; z-index: 3;
    display: flex; flex-direction: column;
    justify-content: space-between;
    padding: 48px 24px calc(36px + var(--safe-b));
    opacity: 0; visibility: hidden; pointer-events: none;
    transition: opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                visibility 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}
#app[data-state="idle"]         #overlay-idle,
#app[data-state="countdown"]    #overlay-countdown,
#app[data-state="flash"]        #overlay-flash,
#app[data-state="preview-shot"] #overlay-preview { opacity:1; visibility:visible; pointer-events:auto; }

/* Other panels */
#app[data-state="adjust"]     #panel-adjust     { opacity:1; visibility:visible; pointer-events:auto; z-index:10; transform:translateY(0); }
#app[data-state="processing"] #panel-processing { opacity:1; visibility:visible; pointer-events:auto; z-index:10; transform:translateY(0); }
#app[data-state="result"]     #panel-result     { opacity:1; visibility:visible; pointer-events:auto; z-index:10; transform:translateY(0); }
#app[data-state="editor"]     #panel-editor     { opacity:1; visibility:visible; pointer-events:auto; z-index:10; transform:translateY(0); }

/* ── Glass Card ────────────────────────────── */
.glass-card {
    background: var(--bg-card);
    backdrop-filter: blur(24px) saturate(1.2);
    -webkit-backdrop-filter: blur(24px) saturate(1.2);
    border: 1px solid var(--border-card);
    border-radius: var(--radius);
    padding: 24px;
}

/* ── Buttons ───────────────────────────────── */
.btn {
    font-family: 'Inter', system-ui, sans-serif;
    font-weight: 600; font-size: 16px;
    letter-spacing: -0.01em;
    padding: 16px 28px;
    border: none; border-radius: var(--radius-md);
    cursor: pointer;
    display: inline-flex; justify-content: center; align-items: center; gap: 8px;
    width: 100%;
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1),
                box-shadow 0.3s ease,
                filter 0.2s ease;
    position: relative;
    overflow: hidden;
}
.btn:active { transform: scale(0.97); filter: brightness(0.92); }

.btn.gradient {
    background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
    color: #fff;
    box-shadow: 0 4px 24px var(--accent-glow), 0 2px 8px var(--accent-glow2);
}
.btn.gradient::before {
    content: '';
    position: absolute; inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.15), transparent 60%);
    border-radius: inherit;
    pointer-events: none;
}

/* Pulse glow animation for CTA buttons */
.btn.gradient.pulse {
    animation: btn-pulse 2.5s ease-in-out infinite;
}
@keyframes btn-pulse {
    0%, 100% { box-shadow: 0 4px 24px var(--accent-glow), 0 2px 8px var(--accent-glow2); }
    50%      { box-shadow: 0 6px 36px var(--accent-glow), 0 4px 16px var(--accent-glow2); }
}

.btn.outline {
    background: transparent;
    color: var(--text-mid);
    border: 1.5px solid var(--border-card);
}
.btn.outline:active { background: rgba(255,255,255,0.03); }

.btn.small { font-size: 13px; padding: 11px 16px; border-radius: var(--radius-sm); }

/* ── Typography ────────────────────────────── */
h2 { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
p  { font-size: 14px; color: var(--text-dim); line-height: 1.5; }
.brand { font-size: 16px; font-weight: 600; letter-spacing: 0.02em; }
.brand span {
    background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* =============================================
   PANEL: CAMERA
   ============================================= */
#camera-feed {
    position: absolute; inset: 0; z-index: 1;
    width: 100%; height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
    background: #000;
}
.camera-vignette {
    position: absolute; inset: 0; z-index: 2;
    background: radial-gradient(ellipse at center, transparent 40%, rgba(8,8,16,0.65) 100%);
    pointer-events: none;
}

/* Overlay shared layout */
.ov-top    { 
    display: flex; justify-content: center; align-items: center; 
    position: relative; width: 100%;
}
.btn-icon {
    position: absolute; right: 0;
    width: 48px; height: 48px;
    border-radius: 50%;
    background: transparent;
    border: none;
    color: var(--text);
    display: flex; justify-content: center; align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
    touch-action: manipulation;
}
.btn-icon:active { transform: scale(0.9); opacity: 0.6; }

.ov-center { flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; }
.ov-bottom { text-align: center; }

/* ── Idle ──────────────────────────────────── */
.tagline {
    font-size: 20px; font-weight: 600; color: rgba(255,255,255,0.9);
    letter-spacing: -0.01em;
    background: rgba(8,8,16,0.45);
    padding: 12px 28px; border-radius: var(--radius-md);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255,255,255,0.06);
}
.hint {
    margin-top: 16px;
    font-size: 12px;
    font-weight: 400;
    color: rgba(255,255,255,0.35);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

/* ── Countdown ─────────────────────────────── */
#countdown-number {
    font-size: 160px; font-weight: 800; line-height: 1;
    letter-spacing: -0.04em;
    background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text;
    filter: drop-shadow(0 0 40px var(--accent-glow)) drop-shadow(0 0 80px var(--accent-glow2));
    animation: cd-pop 0.5s cubic-bezier(.22, 1, .36, 1) both;
}
@keyframes cd-pop {
    0%   { transform: scale(2.2); opacity: 0; filter: blur(12px) drop-shadow(0 0 40px var(--accent-glow)); }
    50%  { opacity: 1; filter: blur(0) drop-shadow(0 0 40px var(--accent-glow)); }
    80%  { transform: scale(0.96); }
    100% { transform: scale(1); opacity: 1; filter: drop-shadow(0 0 40px var(--accent-glow)) drop-shadow(0 0 80px var(--accent-glow2)); }
}

/* Countdown ring (SVG controlled by JS) */
.countdown-ring-wrap {
    position: relative;
    display: flex; align-items: center; justify-content: center;
}
.countdown-ring {
    position: absolute;
    width: 220px; height: 220px;
}
.countdown-ring circle {
    fill: none;
    stroke-width: 3;
    stroke-linecap: round;
}
.countdown-ring .ring-bg {
    stroke: rgba(255,255,255,0.06);
}
.countdown-ring .ring-fg {
    stroke: url(#ring-gradient);
    stroke-dasharray: 628;
    stroke-dashoffset: 0;
    transform: rotate(-90deg);
    transform-origin: center;
    transition: stroke-dashoffset 1s linear;
}

.pose-label {
    font-size: 13px; font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-mid);
}

/* Pose dots — segmented progress */
.pose-dots { display: flex; gap: 8px; justify-content: center; }
.dot {
    width: 32px; height: 4px; border-radius: 100px;
    background: rgba(255,255,255,0.12);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.dot.active {
    background: linear-gradient(90deg, var(--accent-1), var(--accent-2));
    box-shadow: 0 0 12px var(--accent-glow);
    width: 48px;
}
.dot.done { background: var(--success); }

/* ── Flash ─────────────────────────────────── */
.flash-white {
    background: linear-gradient(135deg, rgba(139,92,246,0.15), rgba(255,255,255,0.95));
    z-index: 50;
    animation: flash-fade 0.3s ease-out both;
}
@keyframes flash-fade {
    0%   { opacity: 1; }
    100% { opacity: 0; }
}

/* ── Preview Shot ──────────────────────────── */
.shot-ok {
    width: 72px; height: 72px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-1), var(--accent-2));
    display: flex; align-items: center; justify-content: center;
    animation: shot-pop 0.45s cubic-bezier(.22, 1, .36, 1) both;
    box-shadow: 0 8px 32px var(--accent-glow);
}
.shot-ok svg {
    width: 36px; height: 36px;
    stroke: #fff; stroke-width: 2.5;
    fill: none; stroke-linecap: round; stroke-linejoin: round;
}
@keyframes shot-pop {
    0%   { transform: scale(0); opacity: 0; }
    60%  { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}
.shot-text {
    font-size: 18px; font-weight: 600; color: rgba(255,255,255,0.85);
    margin-top: 12px;
    letter-spacing: -0.01em;
}

/* =============================================
   PANEL: ADJUST
   ============================================= */
#panel-adjust { background: var(--bg); }
.adjust-header { padding: 24px 24px 0; text-align: center; }

.adjust-body {
    flex: 1; display: flex; flex-direction: column;
    justify-content: center; align-items: center;
    overflow: hidden; padding: 16px;
    gap: 12px; min-height: 0;
}
.adjust-frame {
    flex: 1; width: 100%; position: relative;
}
#adjust-canvas {
    position: absolute; inset: 0;
    width: 100%; height: 100%; object-fit: contain;
    border-radius: var(--radius-sm);
    box-shadow: 0 8px 40px rgba(0,0,0,0.5), 0 0 0 1px rgba(255,255,255,0.05);
    touch-action: none;
    cursor: grab;
}
#adjust-canvas:active { cursor: grabbing; }

.adjust-hint {
    font-size: 12px; color: var(--text-dim);
    text-align: center; line-height: 1.6;
    letter-spacing: 0.02em;
}

.adjust-footer {
    margin: 12px 20px calc(20px + var(--safe-b));
    display: flex; flex-direction: column; gap: 10px;
}

/* =============================================
   PANEL: PROCESSING
   ============================================= */
#panel-processing { background: var(--bg); }
#panel-processing .glass-card { text-align: center; width: 100%; max-width: 340px; }

.spinner {
    width: 52px; height: 52px;
    margin: 0 auto 24px;
    border-radius: 50%;
    background: conic-gradient(from 0deg, transparent, var(--accent-1), var(--accent-2), transparent);
    animation: spin 1s linear infinite;
    position: relative;
}
.spinner::after {
    content: '';
    position: absolute;
    inset: 4px;
    border-radius: 50%;
    background: var(--bg);
}
@keyframes spin { to { transform: rotate(360deg); } }

.progress-track {
    width: 100%; height: 4px;
    background: rgba(255,255,255,0.06);
    border-radius: 100px; margin-top: 24px; overflow: hidden;
}
.progress-fill {
    height: 100%; width: 0%;
    background: linear-gradient(90deg, var(--accent-1), var(--accent-2));
    border-radius: 100px;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 0 12px var(--accent-glow);
}

/* =============================================
   PANEL: RESULT
   ============================================= */
#panel-result { background: var(--bg); }
.result-header { padding: 24px 24px 0; text-align: center; }

.result-body {
    flex: 1; display: flex;
    justify-content: center; align-items: center;
    overflow: hidden; padding: 0 20px;
    min-height: 0;
}
.strip-frame {
    flex: 1; width: 100%; position: relative;
}
#result-canvas {
    position: absolute; inset: 0;
    width: 100%; height: 100%; object-fit: contain;
    border-radius: var(--radius-sm);
    box-shadow: 0 16px 64px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.04);
    animation: result-in 0.7s cubic-bezier(.22, 1, .36, 1) both;
}
@keyframes result-in {
    0%   { transform: scale(0.85) translateY(30px); opacity: 0; filter: blur(8px); }
    100% { transform: scale(1) translateY(0); opacity: 1; filter: blur(0); }
}

.result-footer {
    margin: 16px 20px calc(20px + var(--safe-b));
    display: flex; flex-direction: column; gap: 10px;
}

/* =============================================
   PANEL: EDITOR
   ============================================= */
#panel-editor { background: var(--bg-deep); }
.editor-header {
    padding: 16px 20px;
    background: var(--bg);
    border-bottom: 1px solid var(--border-card);
    display: flex; align-items: center; gap: 12px;
}

.editor-body {
    flex: 1; overflow: auto;
    display: flex; justify-content: center; align-items: flex-start;
    padding: 16px;
    background: repeating-conic-gradient(rgba(255,255,255,0.02) 0% 25%, transparent 0% 50%) 0 0 / 32px 32px;
}
#fabric-wrapper {
    width: 100%;
    display: flex; justify-content: center;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: #0a0a14;
    box-shadow: 0 4px 24px rgba(0,0,0,0.3);
}
#fabric-wrapper canvas { display: block; }

.editor-footer {
    border-radius: var(--radius) var(--radius) 0 0;
    padding-bottom: calc(20px + var(--safe-b));
}
.editor-row { display: flex; gap: 8px; margin-bottom: 8px; }
.editor-row .btn { flex: 1; }

#editor-msg {
    min-height: 22px; margin-top: 6px;
    font-size: 12px; text-align: center; color: var(--success);
    font-weight: 500;
}
.link-back {
    display: block; text-align: center; margin-top: 12px;
    font-size: 13px; font-weight: 500;
    color: var(--text-mid); text-decoration: none;
    transition: color 0.2s;
}
.link-back:hover { color: var(--text); }
