:root {
    --accent: #5b6cf2;
    --btn-bg: rgba(8,8,18,0.7);
    --btn-border: rgba(255,255,255,0.1);
    --text: #dde1f0;
    --text-sub: #7b8299;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
button { outline: none; -webkit-tap-highlight-color: transparent; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', sans-serif;
    background: #000;
    color: #fff;
    overflow: hidden;
    width: 100vw;
    height: 100vh;
    -webkit-user-select: none;
    user-select: none;
    -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ─── Error Screen ──────────────────────────────── */

#error-screen {
    position: fixed;
    inset: 0;
    background: #08080f;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    gap: 14px;
    padding: 36px;
    text-align: center;
}

#error-screen h1 {
    font-size: 16px;
    font-weight: 600;
    color: #ef4444;
    letter-spacing: -0.02em;
}

#error-screen p {
    color: var(--text-sub);
    font-size: 13px;
    line-height: 1.8;
    max-width: 260px;
}

#error-home-btn {
    background: rgba(255,255,255,0.05);
    color: var(--text);
    text-decoration: none;
    padding: 10px 28px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 500;
    border: 1px solid rgba(255,255,255,0.09);
    margin-top: 6px;
    transition: background 0.15s;
}

#error-home-btn:hover { background: rgba(255,255,255,0.09); }

/* ─── Start Screen ──────────────────────────────── */

#start-screen {
    position: fixed;
    inset: 0;
    background: #000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
    gap: 22px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

#start-screen[data-loading="true"] {
    cursor: default;
    pointer-events: none;
}

.start-tap-area {
    position: relative;
    width: 92px;
    height: 92px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.start-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.2);
}

.start-ring::before {
    content: '';
    position: absolute;
    inset: -18px;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.08);
}

.start-ring::after {
    content: '';
    position: absolute;
    inset: -36px;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.04);
}

.start-cam-icon {
    width: 34px;
    height: 34px;
    color: rgba(255,255,255,0.95);
}

.start-label {
    font-size: 19px;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    color: rgba(255,255,255,0.9);
    font-weight: 500;
}

.start-guide {
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: none;
    margin-top: 32px;
    width: 260px;
}

.start-guide-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 15px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: rgba(255,255,255,0.85);
    font-weight: 700;
    width: 100%;
    white-space: nowrap;
}

.start-guide-title::before,
.start-guide-title::after {
    content: '';
    flex: 1;
    height: 1.5px;
    background: rgba(255,255,255,0.55);
}

.start-guide-box {
    width: 100%;
    border: 1.5px solid rgba(255,255,255,0.45);
    border-radius: 10px;
    margin-top: 12px;
    padding: 18px 24px;
    display: flex;
    flex-direction: column;
    gap: 0;
}

.start-guide-box p {
    font-size: 15px;
    color: rgba(255,255,255,0.5);
    letter-spacing: 0.04em;
    font-weight: 300;
    line-height: 2.2;
    text-align: center;
}

#permission-status {
    position: absolute;
    bottom: 52px;
    color: #ef4444;
    font-size: 11px;
    text-align: center;
    padding: 0 40px;
    line-height: 1.8;
}

/* ─── 저장 완료 토스트 ──────────────────────────── */

#save-toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(30,30,40,0.92);
    color: #fff;
    font-size: 14px;
    padding: 10px 22px;
    border-radius: 24px;
    pointer-events: none;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.25s, transform 0.25s;
    white-space: nowrap;
    backdrop-filter: blur(6px);
}

#save-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ─── AI 고지 라벨 ──────────────────────────────── */

#ai-label {
    position: absolute;
    bottom: 14px;
    right: 14px;
    font-size: 11px;
    color: rgba(255,255,255,0.8);
    background: rgba(0,0,0,0.4);
    padding: 3px 8px;
    border-radius: 4px;
    pointer-events: none;
    z-index: 10;
    letter-spacing: 0.01em;
}

/* ─── Loading Screen ────────────────────────────── */

#loading-screen {
    position: fixed;
    inset: 0;
    background: #05050d;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 90;
}

.loading-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    width: 180px;
}

#loading-spinner {
    width: 32px;
    height: 32px;
    border: 2px solid rgba(255,255,255,0.06);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

#loading-text {
    color: var(--text-sub);
    font-size: 12px;
    letter-spacing: 0.04em;
    text-align: center;
}

#loading-bar-wrap {
    width: 100%;
    height: 3px;
    background: rgba(255,255,255,0.07);
    border-radius: 2px;
    overflow: hidden;
}

#loading-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), #818cf8);
    border-radius: 2px;
    transition: width 0.45s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ─── AR Container ──────────────────────────────── */

#ar-container { position: fixed; inset: 0; }

#video-background {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 0;
}

#canvas-container {
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
}

#canvas-container canvas { display: block; width: 100%; height: 100%; }

#touch-area {
    position: absolute;
    inset: 0;
    z-index: 2;
    touch-action: none;
}

/* ─── Watermark ─────────────────────────────────── */

#watermark {
    position: absolute;
    top: 18px;
    left: 16px;
    width: 96px;
    height: auto;
    opacity: 0.72;
    z-index: 9;
    pointer-events: none;
    -webkit-user-select: none;
    user-select: none;
}

/* ─── Instruction ───────────────────────────────── */

#instruction {
    position: absolute;
    top: 48px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    background: rgba(0,0,0,0.48);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    color: rgba(255,255,255,0.65);
    padding: 7px 16px;
    border-radius: 20px;
    font-size: 11px;
    letter-spacing: 0.04em;
    pointer-events: none;
    white-space: nowrap;
    transition: opacity 0.5s;
    border: 1px solid rgba(255,255,255,0.07);
}

#instruction.fade-out { opacity: 0; }

/* ─── File Switch Buttons ───────────────────────── */

#file-switch-btns {
    position: absolute;
    top: 18px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
    display: flex;
    gap: 7px;
}

.file-btn {
    width: 34px;
    height: 34px;
    border-radius: 9px;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: rgba(255,255,255,0.5);
    border: 1px solid rgba(255,255,255,0.1);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.02em;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.file-btn.active {
    background: rgba(91,108,242,0.45);
    border-color: rgba(91,108,242,0.6);
    color: #fff;
}

/* ─── Bottom Controls ───────────────────────────── */

/* Shared base for bottom controls */
#flip-btn,
#capture-btn,
#record-btn {
    position: absolute;
    z-index: 10;
    border-radius: 50%;
    background: var(--btn-bg);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border: 1px solid var(--btn-border);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s;
}

#flip-btn:active { transform: scale(0.9); }
#capture-btn:active { transform: translateX(-50%) scale(0.91); }
#record-btn:active { transform: scale(0.9); }

/* Flip button */
#flip-btn {
    bottom: 30px;
    left: 22px;
    width: 44px;
    height: 44px;
    color: rgba(255,255,255,0.65);
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

/* Photo shutter button — centered, largest */
#capture-btn {
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    width: 64px;
    height: 64px;
    background: rgba(255,255,255,0.9);
    border: 3px solid rgba(255,255,255,0.22);
    box-shadow: 0 0 0 3px rgba(0,0,0,0.3);
}

#capture-btn::before {
    content: '';
    display: block;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: transparent;
    border: 2px solid rgba(0,0,0,0.14);
}

/* Record button — smaller, right of shutter */
#record-btn {
    bottom: 30px;
    left: calc(50% + 48px);
    width: 44px;
    height: 44px;
}

#record-btn::before {
    content: '';
    display: block;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #ff3535;
    transition: border-radius 0.25s cubic-bezier(0.4,0,0.2,1),
                width 0.25s cubic-bezier(0.4,0,0.2,1),
                height 0.25s cubic-bezier(0.4,0,0.2,1);
}

#record-btn.recording::before {
    border-radius: 3px;
    width: 14px;
    height: 14px;
}

#record-btn.recording {
    animation: rec-ring 1s ease-in-out infinite;
}

@keyframes rec-ring {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255,53,53,0.5); }
    50%       { box-shadow: 0 0 0 8px rgba(255,53,53,0); }
}

/* 영상 재생/정지 버튼 — 우상단 */
#play-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 10;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: rgba(8,8,18,0.75);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border: 1px solid rgba(255,255,255,0.18);
    color: rgba(255,255,255,0.92);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.1s, background 0.15s;
}
#play-btn:active { transform: scale(0.88); background: rgba(255,255,255,0.12); }

/* Adjust button + panel — hidden */
#adjust-toggle-btn { display: none !important; }

/* ─── Color Adjust Panel ────────────────────────── */

#color-adjust-panel {
    position: absolute;
    bottom: 74px;
    right: 18px;
    z-index: 10;
    background: rgba(8,8,18,0.92);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 14px;
    padding: 16px 18px;
    width: 248px;
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
}

#panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
}

#panel-header span {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(255,255,255,0.4);
}

#panel-close-btn {
    background: none;
    border: none;
    color: rgba(255,255,255,0.25);
    font-size: 13px;
    cursor: pointer;
    padding: 3px 7px;
    border-radius: 4px;
    transition: color 0.15s;
    line-height: 1;
}

#panel-close-btn:hover { color: rgba(255,255,255,0.65); }

.panel-row { margin-bottom: 10px; }

.panel-row label {
    display: flex;
    justify-content: space-between;
    font-size: 10px;
    color: rgba(255,255,255,0.35);
    margin-bottom: 6px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.panel-row input[type="color"] {
    width: 100%;
    height: 30px;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 5px;
    cursor: pointer;
    background: none;
}

.panel-row input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
}

#save-overlay {
    position: fixed; inset: 0; z-index: 9999;
    background: rgba(0,0,0,0.85);
    backdrop-filter: blur(6px);
    display: flex; align-items: center; justify-content: center;
}
#save-overlay.hidden { display: none; }

#save-box {
    position: relative;
    background: #1a1a2e;
    border-radius: 16px;
    padding: 32px 24px;
    display: flex; flex-direction: column; align-items: center; gap: 16px;
    max-width: 300px; width: 90%; text-align: center;
}

#save-msg {
    color: #fff;
    font-size: 15px;
    white-space: pre-line;
    margin: 0;
}

#save-link, #share-btn {
    display: block;
    width: 100%;
    padding: 13px 0;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    box-sizing: border-box;
}

#save-link {
    background: #5b6cf2;
    color: #fff;
    border: none;
}
#save-link:hover { filter: brightness(1.1); }

#share-btn {
    background: transparent;
    color: #5b6cf2;
    border: 1px solid #5b6cf2;
}
#share-btn:hover { background: rgba(91,108,242,0.1); }

#save-close-btn {
    background: none;
    border: 1px solid rgba(255,255,255,0.2);
    color: rgba(255,255,255,0.6);
    font-size: 13px;
    cursor: pointer;
    padding: 8px 20px;
    border-radius: 8px;
}

#convert-progress { width:100%; display:flex; flex-direction:column; gap:8px; align-items:center; }
#convert-bar-wrap { width:100%; background:rgba(255,255,255,0.1); border-radius:4px; height:6px; overflow:hidden; }
#convert-bar { height:100%; background:#5b6cf2; border-radius:4px; width:0%; transition:width 0.3s; }
#convert-text { color:rgba(255,255,255,0.6); font-size:12px; }
