* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #000;
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', sans-serif;
}

/* 카메라 비디오 */
#camera {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 1;
}

/* SVG 오버레이 */
#overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    touch-action: none;
}

/* 각도 표시 배지 */
#angle-badge {
    position: fixed;
    top: env(safe-area-inset-top, 20px);
    left: 20px;
    padding: 12px 24px;
    background: rgba(0, 122, 255, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 16px;
    color: white;
    font-size: 32px;
    font-weight: 600;
    z-index: 100;
    box-shadow: 0 4px 20px rgba(0, 122, 255, 0.4);
    display: flex;
    align-items: center;
    gap: 2px;
}

#angle-value {
    font-variant-numeric: tabular-nums;
    min-width: 50px;
    text-align: center;
}

#level-ok {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: #34C759;
    border-radius: 50%;
    font-size: 18px;
    font-weight: bold;
    margin-left: 8px;
    animation: pulse 0.5s ease-out;
}

#level-ok.hidden {
    display: none;
}

@keyframes pulse {
    0% {
        transform: scale(0);
        opacity: 0;
    }

    50% {
        transform: scale(1.2);
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* 카메라 전환 버튼 */
#switch-camera {
    position: fixed;
    top: env(safe-area-inset-top, 20px);
    right: 20px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    transition: transform 0.2s ease, background 0.2s ease;
}

#switch-camera:active {
    transform: scale(0.92);
    background: rgba(255, 255, 255, 1);
}

#switch-camera svg {
    width: 24px;
    height: 24px;
    color: #333;
}

/* 가로/세로 모드 전환 버튼 */
#switch-orientation {
    position: fixed;
    top: calc(env(safe-area-inset-top, 20px) + 60px);
    right: 20px;
    height: 50px;
    padding: 0 16px;
    border-radius: 25px;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    z-index: 100;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    transition: transform 0.2s ease, background 0.2s ease;
}

#switch-orientation:active {
    transform: scale(0.95);
    background: rgba(255, 255, 255, 1);
}

#switch-orientation svg {
    width: 20px;
    height: 20px;
    color: #333;
}

#switch-orientation #orientation-label {
    font-size: 14px;
    font-weight: 600;
    color: #333;
}


/* 기준선 그룹 */
.line-group {
    cursor: pointer;
    pointer-events: all;
}

.line-group line {
    transition: stroke-width 0.15s ease;
    pointer-events: stroke;
}

.line-group circle {
    transition: r 0.15s ease;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
    pointer-events: all;
    cursor: grab;
}

.line-group.active line {
    stroke-width: 0.8;
}

.line-group.active circle {
    r: 3;
    cursor: grabbing;
}

/* 각도기 스타일 */
#protractor-bg {
    filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.15));
}

/* 수평 기준선 (중력) */
#gravity-line-group {
    transition: transform 0.1s ease-out;
}

#gravity-line {
    filter: drop-shadow(0 1px 3px rgba(52, 199, 89, 0.5));
}

#gravity-indicator-left,
#gravity-indicator-right {
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3));
}

/* 권한 요청 화면 */
.permission-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    color: white;
    text-align: center;
    padding: 40px;
}

.permission-overlay h1 {
    font-size: 28px;
    margin-bottom: 16px;
    font-weight: 700;
}

.permission-overlay p {
    font-size: 16px;
    opacity: 0.8;
    margin-bottom: 32px;
    max-width: 300px;
    line-height: 1.5;
}

.permission-overlay button {
    padding: 16px 48px;
    font-size: 18px;
    font-weight: 600;
    background: #007AFF;
    color: white;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 20px rgba(0, 122, 255, 0.4);
}

.permission-overlay button:active {
    transform: scale(0.96);
}

/* 가로/세로 모드 대응 */
@media (orientation: landscape) {
    #angle-badge {
        top: 20px;
        left: max(env(safe-area-inset-left, 20px), 20px);
    }

    #switch-camera {
        top: 20px;
        right: max(env(safe-area-inset-right, 20px), 20px);
    }
}