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

:root {
    --bg:       #0a0a0a;
    --surface:  #141414;
    --border:   #1e1e1e;
    --text:     #e8e8e8;
    --dim:      #666;
    --accent:   #3b82f6;
    --green:    #22c55e;
    --orange:   #f59e0b;
    --red:      #ef4444;
    --cyan:     #22d3ee;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ── Model Upgrade Banner ──────────────────────── */

.upgrade-banner {
    display: none;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 16px;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.18), rgba(34, 211, 238, 0.10));
    border-bottom: 1px solid rgba(59, 130, 246, 0.35);
    flex-shrink: 0;
    z-index: 11;
}

.upgrade-banner.active { display: flex; }

.upgrade-banner-inner {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.upgrade-banner-title {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 0.01em;
}

.upgrade-banner-body {
    font-size: 0.72rem;
    color: var(--text);
    opacity: 0.85;
    line-height: 1.45;
}

.btn-upgrade-dismiss {
    background: transparent;
    border: none;
    color: var(--dim);
    font-size: 1.3rem;
    line-height: 1;
    padding: 2px 8px;
    cursor: pointer;
    flex-shrink: 0;
    transition: color 0.15s;
}
.btn-upgrade-dismiss:hover { color: var(--text); }

/* ── HUD Bar ──────────────────────────────────── */

.hud {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 10;
    flex-wrap: wrap;
}

.hud-title {
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    margin-right: auto;
}

.chip {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 20px;
    background: rgba(255,255,255,0.06);
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
}

.chip-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}

.chip-dot.gray   { background: #555; }
.chip-dot.orange { background: var(--orange); }
.chip-dot.green  { background: var(--green); animation: pulse 1.5s infinite; }
.chip-dot.red    { background: var(--red); }

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

.chip-fps      { color: var(--green); }
.chip-detected { color: var(--cyan); }
.chip-matched  { color: var(--orange); }
.chip-names    { color: var(--text); max-width: 200px; overflow: hidden; text-overflow: ellipsis; }

/* ── Video Area ──────────────────────────────── */

.video-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    position: relative;
    overflow: hidden;
}

#video-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

#camera-video {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: none;
    transform: scaleX(-1); /* 전면 카메라 미러링 */
}

#overlay-canvas {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scaleX(-1);
    pointer-events: none;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    will-change: transform;
    transform-style: preserve-3d;
}

#camera-video {
    will-change: transform;
}

.placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    color: #444;
    text-align: center;
    padding: 24px;
}

.placeholder svg {
    width: 56px; height: 56px;
    opacity: 0.35;
}

.placeholder-text { font-size: 0.9rem; line-height: 1.5; }
.placeholder-sub  { font-size: 0.75rem; color: #333; }

/* ── Model Progress Bar ──────────────────────── */

.model-progress {
    position: absolute;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    width: 80%;
    max-width: 400px;
    background: rgba(0,0,0,0.8);
    border-radius: 12px;
    padding: 12px 16px;
    display: none;
    flex-direction: column;
    gap: 6px;
    z-index: 20;
    backdrop-filter: blur(8px);
}

.progress-bar-bg {
    width: 100%;
    height: 6px;
    background: rgba(255,255,255,0.1);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.3s;
    width: 0%;
}

.progress-text {
    font-size: 0.7rem;
    color: var(--dim);
    text-align: center;
}

/* ── Control Panel ───────────────────────────── */

.controls {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    flex-wrap: wrap;
}

.controls-row {
    display: flex;
    gap: 8px;
    align-items: center;
    width: 100%;
}

.btn {
    padding: 7px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: rgba(255,255,255,0.06);
    color: var(--text);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn:hover { background: rgba(255,255,255,0.12); }
.btn.active { background: var(--accent); border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); }
.btn.danger { background: var(--red); border-color: var(--red); }

.server-url {
    flex: 1;
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: rgba(255,255,255,0.04);
    color: var(--text);
    font-size: 0.72rem;
    font-family: monospace;
    outline: none;
    min-width: 0;
}
.server-url:focus { border-color: var(--accent); }

/* ── Modal ───────────────────────────────────── */

.modal-backdrop {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.7);
    z-index: 100;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.modal-backdrop.active { display: flex; }

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 24px;
    width: 90%;
    max-width: 420px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal h3 {
    font-size: 1rem;
    margin-bottom: 16px;
}

.modal-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: rgba(255,255,255,0.04);
    color: var(--text);
    font-size: 0.85rem;
    outline: none;
    margin-bottom: 12px;
}
.modal-input:focus { border-color: var(--accent); }

.modal-buttons {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 16px;
}

/* ── Enrollment UI ───────────────────────────── */

.enroll-progress {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--accent);
    text-align: center;
    margin: 8px 0;
}

.enroll-guide {
    display: none;
}

.enroll-message {
    text-align: center;
    font-size: 0.85rem;
    color: var(--dim);
    padding: 8px;
    border-radius: 8px;
    background: rgba(255,255,255,0.04);
    margin-bottom: 12px;
    transition: all 0.3s;
}

.enroll-message.aligned {
    color: var(--green);
    background: rgba(34, 197, 94, 0.1);
}

.pose-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 8px;
    margin-top: 8px;
}

.pose-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 4px;
    border-radius: 10px;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border);
    font-size: 0.7rem;
    transition: all 0.3s;
}

.pose-item.done {
    background: rgba(34, 197, 94, 0.1);
    border-color: var(--green);
}

.pose-icon { font-size: 1.1rem; }
.pose-label { color: var(--dim); font-weight: 600; }
.pose-count { color: var(--text); font-variant-numeric: tabular-nums; }

/* ── Color Picker (공용) ─────────────────────── */

.color-picker-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
}

.color-picker-label {
    font-size: 0.72rem;
    color: var(--dim);
    font-weight: 600;
    letter-spacing: 0.03em;
}

.color-picker {
    display: flex;
    gap: 12px;
    justify-content: center;
    align-items: center;
}

.color-swatch {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.25);
    cursor: pointer;
    padding: 0;
    outline: none;
    transition: transform 0.15s ease-out, border-color 0.15s, box-shadow 0.15s;
}
.color-swatch:hover {
    transform: scale(1.06);
}
.color-swatch.selected {
    transform: scale(1.12);
    border-color: #fff;
    box-shadow: 0 0 14px rgba(255, 255, 255, 0.45);
}
.color-swatch.mini {
    width: 26px;
    height: 26px;
    border-width: 1.5px;
}
.color-swatch.mini.selected {
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.55);
}

/* ── Manage UI ───────────────────────────────── */

.manage-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 8px;
    background: rgba(255,255,255,0.02);
}

.manage-row-main {
    display: flex;
    align-items: center;
    gap: 10px;
}

.color-dot {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 1.5px solid rgba(255, 255, 255, 0.3);
    flex-shrink: 0;
}

.manage-info { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.manage-name { font-size: 0.85rem; font-weight: 600; }
.manage-count { font-size: 0.7rem; color: var(--dim); }
.manage-empty { text-align: center; color: var(--dim); padding: 20px; font-size: 0.85rem; }

.manage-color-picker {
    display: flex;
    gap: 10px;
    justify-content: flex-start;
    padding-left: 32px;
}

.btn-delete {
    padding: 4px 10px;
    border: 1px solid var(--red);
    border-radius: 6px;
    background: transparent;
    color: var(--red);
    font-size: 0.7rem;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-delete:hover { background: var(--red); color: #fff; }

/* ── Responsive ──────────────────────────────── */

@media (max-width: 480px) {
    .hud { padding: 8px 10px; gap: 5px; }
    .hud-title { font-size: 0.78rem; }
    .chip { font-size: 0.65rem; padding: 3px 7px; }
    .controls { padding: 8px 10px; gap: 5px; }
    .btn { padding: 6px 10px; font-size: 0.7rem; }
    .server-url { font-size: 0.65rem; }
}
