/**
 * Glassmorphism Theme Styles
 * 모듈화된 CSS 파일 - 분모파일에서 링크하여 사용
 */

/* ===== CSS Variables ===== */
:root {
    --glass-bg: rgba(15, 17, 21, 0.75);
    --glass-bg-light: rgba(26, 29, 36, 0.85);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-border-active: rgba(255, 107, 0, 0.6);
    --primary: #FF6B00;
    --accent-cyan: #00d2ff;
    --bg-dark: #0f1115;
    --text-main: #ffffff;
    --text-gray: #8A8F9E;
    --control-bg: rgba(26, 29, 36, 0.8);
    --control-text: #ffffff;
    --control-option-bg: #1a1d24;
    --control-hover-bg: rgba(255, 255, 255, 0.1);
    --control-hover-border: rgba(255, 255, 255, 0.2);
}

/* Light Theme */
:root[data-theme="light"] {
    --glass-bg: rgba(245, 246, 248, 0.95);
    --glass-bg-light: rgba(255, 255, 255, 0.95);
    --glass-border: rgba(0, 0, 0, 0.08);
    --glass-border-active: rgba(255, 107, 0, 0.4);
    --primary: #FF6B00;
    --accent-cyan: #0099cc;
    --bg-dark: #F5F6F8;
    --text-main: #1a1a1a;
    --text-gray: #666666;
    --control-bg: #ffffff;
    --control-text: #1a1a1a;
    --control-option-bg: #ffffff;
    --control-hover-bg: #e9edf2;
    --control-hover-border: rgba(15, 23, 42, 0.18);
}

/* High Contrast Theme */
:root[data-theme="contrast"] {
    --glass-bg: rgba(0, 0, 0, 0.95);
    --glass-bg-light: rgba(20, 20, 20, 0.98);
    --glass-border: rgba(255, 255, 255, 0.2);
    --glass-border-active: rgba(255, 255, 0, 0.8);
    --primary: #FFFF00;
    --accent-cyan: #00FFFF;
    --bg-dark: #000000;
    --text-main: #FFFFFF;
    --text-gray: #CCCCCC;
    --control-bg: #000000;
    --control-text: #FFFFFF;
    --control-option-bg: #000000;
    --control-hover-bg: #242424;
    --control-hover-border: #FFFFFF;
}

/* 고정 다크 편집기/카탈로그는 앱의 라이트 테마와 독립된 컨트롤 팔레트를 사용한다. */
.assembly-design-panel,
.ade-standard-library,
.ade-canvas-tools,
.ade-view-navigation,
.ade-transform-hud,
.adc-overlay,
.ahcb-overlay,
.fcat-overlay,
#fittingManagePanel {
    --glass-bg-light: rgba(26, 29, 36, 0.92);
    --glass-border: rgba(255, 255, 255, 0.12);
    --text-main: #ffffff;
    --text-gray: #9fb2ba;
    --control-bg: #0b1116;
    --control-text: #eef7f9;
    --control-option-bg: #10171d;
    --control-hover-bg: #1c3337;
    --control-hover-border: #72d8ca;
    --accent-cyan: #62cfc1;
    color-scheme: dark;
}

/* 전역 button !important가 고정 다크 카탈로그의 의미 상태를 지우지 않도록 복원한다. */
.fcat-overlay .fcat-tool.primary {
    background: rgba(255, 107, 0, 0.15) !important;
    border-color: #FF6B00 !important;
    color: #ffc07a !important;
}
.fcat-overlay .fcat-tool.primary:hover {
    background: rgba(255, 107, 0, 0.26) !important;
    border-color: #ff9b52 !important;
    color: #ffe0bd !important;
}
.fcat-overlay .fcat-tool:disabled,
.fcat-overlay .fcat-tool:disabled:hover {
    background: #1c2130 !important;
    border-color: #3b4052 !important;
    color: #dce3f1 !important;
    pointer-events: none;
}
.fcat-overlay .fcat-chip.active {
    background: #FF6B00 !important;
    border-color: #FF6B00 !important;
    color: #17110b !important;
}
.fcat-overlay .fcat-chip.active:hover {
    background: #ff8126 !important;
    color: #17110b !important;
}
.fcat-overlay .fcat-fav.active {
    background: rgba(5, 6, 12, 0.88) !important;
    border-color: rgba(255, 216, 77, 0.62) !important;
    color: #ffd84d !important;
}
.fcat-overlay .fcat-fav.active:hover {
    background: #29240f !important;
    border-color: #ffd84d !important;
    color: #fff0a3 !important;
}
.fcat-overlay .fcat-card-action.delete {
    background: rgba(5, 6, 12, 0.88) !important;
    border-color: rgba(255, 154, 152, 0.36) !important;
    color: #ff9a98 !important;
}
.fcat-overlay .fcat-card-action.delete:hover {
    background: #35191d !important;
    border-color: #ff9a98 !important;
    color: #ffd2d0 !important;
}
.fcat-overlay .fcat-pick-card.selected {
    background: rgba(255, 107, 0, 0.12) !important;
    border-color: #FF6B00 !important;
    color: #dfe3ee !important;
}
.fcat-overlay .fcat-pick-card.selected:hover {
    background: rgba(255, 107, 0, 0.2) !important;
}
.fcat-overlay .fcat-pick-card.selected .fcat-pick-check {
    color: #17110b !important;
}
#fittingManagePanel .fmp-view-btn.active,
#fittingManagePanel .fmp-view-btn.active:hover {
    background: #FF7A1A !important;
    border-color: #ff9d59 !important;
    color: #17110b !important;
}
#fittingManagePanel .fmp-fav-btn.active {
    background: rgba(255, 235, 59, 0.18) !important;
    border-color: #FFEB3B !important;
    color: #FFEB3B !important;
}
#fittingManagePanel .fmp-fav-btn.active:hover {
    background: rgba(255, 235, 59, 0.28) !important;
    border-color: #fff176 !important;
    color: #fff176 !important;
}
#fittingManagePanel .fmp-tb-btn.danger:hover {
    background: rgba(244, 67, 54, 0.18) !important;
    border-color: rgba(244, 67, 54, 0.72) !important;
    color: #ffd6d3 !important;
}
#fittingManagePanel .fmp-tb-btn.placeholder,
#fittingManagePanel .fmp-tb-btn.placeholder:hover {
    background: rgba(255, 255, 255, 0.06) !important;
    border-color: rgba(255, 255, 255, 0.1) !important;
    color: #ffffff !important;
    pointer-events: none;
}

/* ===== Base Overrides ===== */
html,
body {
    background-color: var(--bg-dark) !important;
    color: var(--text-main) !important;
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, sans-serif !important;
}

/* ===== 모바일 텍스트 선택 / 탭 하이라이트 차단 ===== */
/* 모바일에서 라벨/버튼/패널 텍스트를 길게 누르면 파란 selection box 가
   생기는 문제 차단. * 셀렉터는 specificity 0 이라 인라인 style/특정 규칙에
   밀려서 !important 강제. ::selection 은 폴백 (혹시 selection 이 일어나도
   하이라이트 색을 투명하게 만들어 시각적으로 표시 안 됨). */
* {
    user-select: none !important;
    -webkit-user-select: none !important;
    -webkit-tap-highlight-color: transparent !important;
    -webkit-touch-callout: none !important;
}
input,
textarea,
[contenteditable="true"],
[contenteditable=""] {
    user-select: text !important;
    -webkit-user-select: text !important;
    -webkit-touch-callout: default !important;
}
::selection { background: transparent; }
::-moz-selection { background: transparent; }

/* ===== Tabs ===== */
#tabs {
    background: var(--glass-bg) !important;
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    color: var(--text-main) !important;
    border-bottom: 1px solid var(--glass-border);
}

.tab {
    transition: background 0.2s, color 0.2s;
}

.tab:hover {
    background: rgba(255, 255, 255, 0.05);
}

.tab.active {
    background: rgba(255, 107, 0, 0.2) !important;
    color: var(--primary) !important;
    border-bottom: 2px solid var(--primary);
}

/* ===== Panels ===== */
.panel {
    background: var(--glass-bg) !important;
    -webkit-backdrop-filter: blur(16px);
    backdrop-filter: blur(16px);
    border-right: 1px solid var(--glass-border);
    color: var(--text-main) !important;
}

/* Panel 내부 라벨 색상 */
.panel label {
    color: var(--text-gray);
}

/* ===== Canvas (Fullscreen Background) ===== */
#canvas3d {
    left: 0 !important;
    background: var(--bg-dark) !important;
}

/* ===== Buttons ===== */
button,
.btn {
    background: var(--control-bg) !important;
    border: 1px solid var(--glass-border) !important;
    color: var(--control-text) !important;
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s ease;
}

button:hover,
.btn:hover {
    background: var(--control-hover-bg) !important;
    border-color: var(--control-hover-border) !important;
}

button:active,
.btn:active {
    transform: scale(0.97);
}

/* Primary Buttons (Pink/Orange) */
button[style*="background:#e91e63"],
button[style*="background: #e91e63"],
#modeBtn {
    background: var(--primary) !important;
    border-color: var(--primary) !important;
    color: #000 !important;
}

/* Success Buttons (Green) */
button[style*="background:#4CAF50"],
button[style*="background: #4CAF50"] {
    background: #4CAF50 !important;
    border: 1px solid rgba(76, 175, 80, 0.5) !important;
}

/* Warning Buttons (Orange) */
button[style*="background:#FF9800"],
button[style*="background: #FF9800"] {
    background: #FF9800 !important;
    border: 1px solid rgba(255, 152, 0, 0.5) !important;
    color: #000 !important;
}

/* ===== Inputs & Selects ===== */
select,
input[type="text"],
input[type="number"] {
    background: var(--control-bg) !important;
    border: 1px solid var(--glass-border) !important;
    color: var(--control-text) !important;
    -webkit-text-fill-color: var(--control-text) !important;
    padding: 6px 10px;
    border-radius: 6px;
    outline: none;
    transition: border-color 0.2s;
}

select:focus,
input[type="text"]:focus,
input[type="number"]:focus {
    border-color: var(--accent-cyan) !important;
}

/* 입력 행의 number 입력 — 스핀버튼 제거 + 패딩 축소 (가로폭 절약).
   .pipe-row 안 + 행에 추가되는 보조 입력(extraAngleInput, bulgeCountInput 등) 포함.
   다른 화면의 number 입력은 영향 없음. */
.pipe-row input[type="number"]::-webkit-inner-spin-button,
.pipe-row input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
}
.pipe-row input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
    /* 전역 padding 6px 10px → 3px 5px 로 축소. 각 입력 가로폭 ~10px 절약 */
    padding: 3px 5px !important;
}

/* 피팅 드롭다운 — 폰트/패딩 축소 + 옵션 텍스트 줄여 더 많은 글자 표시.
   글로벌 select 스타일이 !important 라 같이 !important. width 는 inline style 180px. */
.fittingTypeSelect {
    font-size: 0.78rem !important;
    padding: 3px 4px !important;
}
.fittingTypeSelect option {
    font-size: 0.78rem;
}

/* 라인 컨트롤 — "라인 [현재] / [총]" 분수형 한 덩어리.
   글로벌 select padding 6px 10px → 2px 6px 로 축소, 폭도 50px 로 좁힘. */
.line-control-group {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 7px;
    background: rgba(0, 0, 0, 0.18);
}
.line-control-label {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.78rem;
    font-weight: 600;
    margin-right: 2px;
    letter-spacing: 0.02em;
    user-select: none;
}
.line-control-sep {
    color: rgba(255, 255, 255, 0.4);
    font-weight: bold;
    font-size: 0.9rem;
    line-height: 1;
    user-select: none;
}
.line-control-select {
    width: 50px;
    font-size: 0.85rem !important;
    padding: 2px 4px !important;
    text-align: center;
    text-align-last: center;
}

/* 엘보 행의 각도/R 입력 wrapper — 단위 라벨(°/R) 부착 + 모드별 visibility.
   wrapper position:relative + 라벨 position:absolute → 행 높이 contribution 없음. */
.pipe-input-wrap {
    display: inline-flex;
    align-items: center;
    gap: 0;
    flex-shrink: 0;
    position: relative;
    overflow: visible;
}
/* 각도의 ° — R 라벨과 동일 floating 패턴, 위치만 우측 상단 (R 는 중앙 상단) */
.pipe-unit-suffix {
    position: absolute;
    top: -6px;
    right: 2px;
    padding: 0 3px;
    color: rgba(255, 200, 120, 0.95);
    font-size: 0.6rem;
    font-weight: bold;
    line-height: 1;
    background: #1a1d24;
    border-radius: 2px;
    pointer-events: none;
    user-select: none;
    z-index: 1;
}
/* R 은 input 위쪽에 떠 있는 floating label — 행 높이 영향 X. input border 위에
   row 배경색으로 깎아내듯 올라타게 (Material Design 패턴). */
.pipe-unit-prefix {
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
    padding: 0 3px;
    color: rgba(255, 200, 120, 0.95);
    font-size: 0.6rem;
    font-weight: bold;
    line-height: 1;
    user-select: none;
    pointer-events: none;
    background: #1a1d24;
    border-radius: 2px;
    z-index: 1;
}

/* 모드별 visibility — JS 의 display 직접 조작과 무관하게 CSS 가 wrapper 최종 결정.
   엘보 모드에서만 angle/R wrapper 표시. */
.pipe-row .pipe-angle-wrap,
.pipe-row .pipe-radius-wrap,
.pipe-row .pipe-sb-wrap,
.pipe-row .pipe-length-wrap,
.pipe-row .pipe-segment-length-wrap {
    display: none;
}
.pipe-row[data-mode="elbow"] .pipe-angle-wrap,
.pipe-row[data-mode="elbow"] .pipe-radius-wrap,
.pipe-row[data-mode="elbow"] .pipe-sb-wrap {
    display: inline-flex;
}
.pipe-row[data-mode="pipe"] .pipe-length-wrap,
.pipe-row[data-mode="pipe"] .pipe-segment-length-wrap {
    display: inline-flex;
}

/* 단관 모드의 마지막 입력 기준 표시. 실제 렌더 길이 정본은 항상 pipeLengthInput이며,
   주황 강조된 필드만 다음 주변 형상 변경 때 보존된다. */
.pipe-length-wrap .pipe-unit-prefix,
.pipe-segment-length-wrap .pipe-unit-prefix {
    color: rgba(190, 198, 210, 0.8);
    white-space: nowrap;
}
.pipe-length-wrap.is-length-basis .pipe-unit-prefix,
.pipe-segment-length-wrap.is-length-basis .pipe-unit-prefix {
    color: rgba(255, 190, 92, 1);
}
.pipe-length-wrap.is-length-basis input,
.pipe-segment-length-wrap.is-length-basis input {
    border-color: rgba(255, 172, 55, 0.9) !important;
    box-shadow: 0 0 0 1px rgba(255, 172, 55, 0.18);
}
.pipeSegmentLengthInput.is-invalid {
    border-color: #ef5350 !important;
    box-shadow: 0 0 0 1px rgba(239, 83, 80, 0.3);
}

/* Roll 버튼 — 위에 floating "Roll"/"회전" 라벨 부착. R 라벨과 동일 패턴.
   라벨이 버튼 자식이라 버튼 hide 시 자동 hide. */
.addExtraAngleBtn .ea-floating-label {
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    padding: 0 3px;
    color: rgba(255, 200, 120, 0.95);
    font-size: 0.55rem;
    font-weight: bold;
    line-height: 1;
    background: #1a1d24;
    border-radius: 2px;
    pointer-events: none;
    user-select: none;
    white-space: nowrap;
}
.addExtraAngleBtn .ea-btn-sign {
    display: inline-block;
    line-height: 1;
}

/* 2줄 layout 구조: .pipe-row 안에 .pipe-row-inner (line 1, nowrap+scroll) + EA (line 2).
   has-extra-angle 시 row 가 flex column 으로 전환 → main item 들과 EA 가 vertical stack. */
.pipe-row > .pipe-row-inner {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    flex: 1 1 100%;
    min-width: 0;
    overflow-x: auto;
    overscroll-behavior-x: contain;
}
.pipe-row.has-extra-angle {
    flex-direction: column;
    align-items: stretch;
    flex-wrap: nowrap;
}
.pipe-row.has-extra-angle .extraAnglesContainer {
    /* extraAnglesContainer 의 inline style flex-direction:column 을 row 로 강제 override */
    display: flex !important;
    flex-direction: row !important;
    align-items: center;
    gap: 8px;
    margin-top: 2px !important;
    padding: 1px 4px 0;
}
.ea-row-label {
    color: #00c853;
    font-weight: bold;
    font-size: 0.85rem;
    flex-shrink: 0;
    user-select: none;
    line-height: 1.2;
}
.ea-row-hint {
    color: rgba(255, 255, 255, 0.55);
    font-size: 0.75rem;
    flex-shrink: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    line-height: 1.2;
}
/* extraAngleInput — 2번째 줄 inline 정렬, 폰트는 본 입력 가독성 우선 (원래 0.9rem 유지) */
.pipe-row.has-extra-angle .extraAngleInput {
    margin-right: 0 !important;
}
.pipe-row.has-extra-angle .extraAngleInput::placeholder {
    font-size: 0.7rem;
    opacity: 0.45;
}
/* 회전 input wrapper — 우측 상단 초록 ° 부착 (각도 입력 ° 와 동일 floating 패턴) */
.ea-input-wrap {
    position: relative;
    display: inline-flex;
    flex-shrink: 0;
}
.ea-deg-sign {
    position: absolute;
    top: -6px;
    right: 2px;
    padding: 0 3px;
    color: #00c853;
    background: #1a1d24;
    font-size: 0.6rem;
    font-weight: bold;
    line-height: 1;
    border-radius: 2px;
    pointer-events: none;
    user-select: none;
    z-index: 1;
}

select option {
    background: var(--control-option-bg);
    color: var(--control-text);
}

/* ===== Custom Scrollbar ===== */
.panel::-webkit-scrollbar {
    width: 6px;
}

.panel::-webkit-scrollbar-track {
    background: transparent;
}

.panel::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 3px;
}

.panel::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* ===== Mobile Responsive ===== */
@media (max-width: 600px) {
    .panel {
        background: var(--glass-bg) !important;
        -webkit-backdrop-filter: blur(16px);
        backdrop-filter: blur(16px);
    }
}

/* ===== Hybrid Button Base Styles ===== */
.hybrid-btn {
    position: relative;
    background-color: var(--glass-bg-light);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    cursor: pointer;
    transition: transform 0.1s, background-color 0.2s, border-color 0.2s;
    overflow: hidden;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.hybrid-btn.active {
    border-color: var(--primary);
    background-color: rgba(255, 107, 0, 0.15);
    transform: scale(0.96);
}

.hybrid-btn .dog-ear {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 0 0 16px 16px;
    border-color: transparent transparent var(--glass-border) transparent;
    pointer-events: none;
}

.hybrid-btn.active .dog-ear {
    border-color: transparent transparent var(--primary) transparent;
}

/* ===== Bottom Sheet (for Hybrid Button Menu) ===== */
.bottom-sheet-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 9998;
    opacity: 0;
    visibility: hidden;
    transition: 0.3s;
}

.bottom-sheet-overlay.show {
    opacity: 1;
    visibility: visible;
}

.bottom-sheet {
    position: fixed;
    bottom: -100%;
    left: 0;
    right: 0;
    background: var(--glass-bg);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    border-radius: 20px 20px 0 0;
    padding: 20px;
    z-index: 9999;
    transition: 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
    border-top: 1px solid var(--primary);
}

.bottom-sheet.show {
    bottom: 0;
}

.bottom-sheet .menu-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 16px;
    border-radius: 12px;
    margin-bottom: 8px;
    background: rgba(30, 34, 41, 0.8);
    font-size: 16px;
    font-weight: 500;
    color: var(--text-main);
    cursor: pointer;
    transition: background 0.2s;
}

.bottom-sheet .menu-item:hover {
    background: rgba(255, 107, 0, 0.2);
}

.bottom-sheet .menu-item:active {
    background: var(--primary);
    color: #000;
}

/* ===== Pipe Row Hybrid Button Override ===== */
.pipe-row .hybrid-btn {
    border-radius: 8px;
    min-width: 48px;
    max-width: 56px;
    height: 41px;
    gap: 2px;
    padding: 0 4px;
    font-size: 0.65rem;
}

.pipe-row .hybrid-btn .dog-ear {
    border-width: 0 0 10px 10px;
}

.pipe-row .hybrid-btn .btn-icon {
    font-size: 14px;
}

.pipe-row .hybrid-btn .btn-text {
    font-size: 0.65rem;
    white-space: nowrap;
}

/* ===== Glassmorphism 모달/팝업 스타일 ===== */
.glass-modal {
    background: var(--glass-bg) !important;
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    color: var(--text-main) !important;
}

.glass-modal h3,
.glass-modal h4,
.glass-modal label,
.glass-modal span {
    color: var(--text-main) !important;
}

.glass-modal input,
.glass-modal select {
    background: var(--control-bg) !important;
    border: 1px solid var(--glass-border) !important;
    color: var(--control-text) !important;
    -webkit-text-fill-color: var(--control-text) !important;
}

.glass-modal button {
    background: var(--glass-bg-light) !important;
    border: 1px solid var(--glass-border) !important;
    color: var(--text-main) !important;
}

.glass-modal button:hover {
    background: var(--control-hover-bg) !important;
    border-color: var(--control-hover-border) !important;
}

.glass-modal button.primary,
.glass-modal button[style*="background:#4CAF50"],
.glass-modal button[style*="background: #4CAF50"] {
    background: var(--primary) !important;
    border-color: var(--primary) !important;
    color: #000 !important;
}

/* ===== 그래픽 품질 설정 모달 ===== */
.graphics-settings-overlay {
    position: fixed;
    inset: 0;
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    padding:
        max(12px, env(safe-area-inset-top))
        max(12px, env(safe-area-inset-right))
        max(12px, env(safe-area-inset-bottom))
        max(12px, env(safe-area-inset-left));
    background: rgba(2, 4, 8, 0.62);
    /* Editor standard-library companions use the 10008-10012 range. Keep
       settings above those detached windows in both normal and fullscreen UI. */
    z-index: 20050;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: graphics-settings-overlay-in 120ms ease-out;
}

.graphics-settings-modal {
    display: flex;
    flex-direction: column;
    width: min(420px, 100%);
    max-height: min(84dvh, 760px);
    box-sizing: border-box;
    overflow: hidden;
    background: rgba(15, 17, 21, 0.96);
    -webkit-backdrop-filter: blur(24px);
    backdrop-filter: blur(24px);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    padding: 0;
    min-width: 0;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
    animation: graphics-settings-modal-in 160ms ease-out;
}

.graphics-settings-header {
    position: relative;
    z-index: 2;
    display: grid;
    place-items: center;
    min-height: 54px;
    flex: 0 0 auto;
    padding: 0 58px;
    background: rgba(15, 17, 21, 0.98);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.graphics-settings-title {
    margin: 0;
    color: #fff;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.2;
}

.graphics-settings-close {
    position: absolute;
    top: 50%;
    right: 12px;
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    padding: 0;
    transform: translateY(-50%);
    color: rgba(255, 255, 255, 0.72);
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 7px;
    cursor: pointer;
    transition: color 140ms ease, background 140ms ease, border-color 140ms ease;
}

.graphics-settings-close .material-icons-round {
    display: block;
    width: 20px;
    height: 20px;
    overflow: hidden;
    font-size: 20px;
    line-height: 20px;
}

.graphics-settings-close:hover,
.graphics-settings-close:focus-visible {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    outline: none;
}

.graphics-settings-close:active {
    transform: translateY(-50%);
}

.graphics-settings-body {
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 8px 12px 12px;
    /* Firefox 스크롤바 */
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.2) transparent;
}
/* Webkit (Chrome/Safari/Edge) 스크롤바 — 글래스모피즘 톤에 맞춘 얇은 반투명 */
.graphics-settings-body::-webkit-scrollbar {
    width: 8px;
}
.graphics-settings-body::-webkit-scrollbar-track {
    background: rgba(255,255,255,0.03);
    border-radius: 4px;
    margin: 8px 0;
}
.graphics-settings-body::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.18);
    border-radius: 4px;
    transition: background 0.15s;
}
.graphics-settings-body::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.32);
}
.graphics-settings-body::-webkit-scrollbar-thumb:active {
    background: rgba(255,193,7,0.55);
}

@keyframes graphics-settings-overlay-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes graphics-settings-modal-in {
    from { opacity: 0; transform: translateY(6px) scale(0.99); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.graphics-quality-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 14px 18px;
    background: rgba(255, 255, 255, 0.05);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    color: #fff;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 70px;
}

.graphics-quality-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.graphics-quality-btn.active {
    background: rgba(255, 107, 0, 0.15);
    border-color: #FF6B00;
    box-shadow: 0 0 12px rgba(255, 107, 0, 0.3);
}

.graphics-quality-btn .gq-icon {
    font-size: 1.4rem;
}

.graphics-quality-btn .gq-label {
    font-size: 1.1rem;
    font-weight: 700;
}

.graphics-quality-btn .gq-desc {
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.5);
}

.graphics-quality-btn.active .gq-desc {
    color: rgba(255, 107, 0, 0.8);
}

/* ===== Settings 아코디언 카테고리 ===== */
.settings-category {
    margin-top: 6px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.015);
    transition: border-color 140ms ease, background 140ms ease;
}

.settings-category-header {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 44px;
    box-sizing: border-box;
    padding: 0 12px;
    text-align: left;
    background: rgba(255, 255, 255, 0.025);
    border: 0;
    cursor: pointer;
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.7);
    font-weight: 600;
    font-family: inherit;
    user-select: none;
    transition: background 140ms ease, color 140ms ease;
}

.settings-category-header:hover,
.settings-category-header:focus-visible {
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.92);
    outline: none;
}

.settings-category-header.open {
    color: #fff;
    background: rgba(255, 107, 0, 0.08);
}

.settings-category-header.open + .settings-category-content {
    background: rgba(0, 0, 0, 0.08);
}

.settings-category-icon {
    width: 20px;
    height: 20px;
    flex: 0 0 20px;
    overflow: hidden;
    color: rgba(255, 255, 255, 0.5);
    font-size: 18px;
    line-height: 20px;
    text-align: center;
    white-space: nowrap;
}

.settings-category-header.open .settings-category-icon {
    color: #ff8a36;
}

.settings-category-title {
    min-width: 0;
    flex: 1 1 auto;
}

.settings-category-header .settings-arrow {
    flex: 0 0 auto;
    font-size: 18px;
    transition: transform 160ms ease;
    color: rgba(255, 255, 255, 0.4);
}

.settings-category-header.open .settings-arrow {
    transform: rotate(90deg);
    color: rgba(255, 255, 255, 0.76);
}

.settings-category-content {
    padding: 10px 12px 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.settings-subgroup + .settings-subgroup {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.settings-subgroup-title {
    display: flex;
    align-items: center;
    gap: 7px;
    min-height: 24px;
    margin-bottom: 7px;
    color: rgba(255, 255, 255, 0.56);
    font-size: 0.72rem;
    font-weight: 700;
}

.settings-subgroup-title .material-icons-round {
    width: 17px;
    height: 17px;
    overflow: hidden;
    color: rgba(255, 138, 54, 0.82);
    font-size: 16px;
    line-height: 17px;
}

.settings-subgroup-body {
    display: grid;
    gap: 6px;
}

.settings-control-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 44px;
    box-sizing: border-box;
    margin: 0;
    padding: 0 10px;
    border: 1px solid rgba(255, 255, 255, 0.075);
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.035);
}

.settings-control-row.settings-nested-row {
    min-height: 40px;
    margin-left: 10px;
    background: rgba(255, 255, 255, 0.02);
}

.settings-control-label {
    display: flex;
    align-items: center;
    min-width: 0;
    gap: 8px;
}

.settings-control-label > span:last-child {
    min-width: 0;
    overflow-wrap: anywhere;
}

.settings-choice-block,
.settings-field-block,
.settings-slider-block {
    box-sizing: border-box;
    margin: 0;
    padding: 9px 10px;
    border: 1px solid rgba(255, 255, 255, 0.075);
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.025);
}

.settings-field-label {
    margin: 0 0 7px;
    color: rgba(255, 255, 255, 0.66);
    font-size: 0.72rem;
    font-weight: 650;
    text-align: left;
}

.settings-choice-grid,
.settings-quality-grid {
    display: grid;
    gap: 6px;
}

.settings-theme-grid,
.settings-quality-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.settings-finish-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.settings-choice-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    min-width: 0;
    min-height: 34px;
    box-sizing: border-box;
    padding: 6px 7px !important;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    border-radius: 6px !important;
    background: rgba(255, 255, 255, 0.045) !important;
    color: rgba(255, 255, 255, 0.68) !important;
    font-size: 0.7rem;
    font-weight: 550;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.settings-choice-button .material-icons-round {
    flex: 0 0 auto;
    font-size: 15px;
}

.settings-choice-button:hover {
    background: rgba(255, 255, 255, 0.08) !important;
}

.settings-choice-button.active {
    border-color: rgba(255, 138, 54, 0.7) !important;
    background: rgba(255, 107, 0, 0.14) !important;
    color: #ffad72 !important;
}

.settings-finish-choice {
    justify-content: flex-start;
}

.settings-quality-grid .graphics-quality-btn {
    min-width: 0;
    min-height: 84px;
    box-sizing: border-box;
    gap: 3px;
    padding: 9px 4px !important;
    border: 1px solid rgba(255, 255, 255, 0.1) !important;
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.04) !important;
}

.settings-quality-grid .graphics-quality-btn.active {
    border-color: rgba(255, 138, 54, 0.72) !important;
    background: rgba(255, 107, 0, 0.14) !important;
}

.settings-quality-grid .graphics-quality-btn .gq-label {
    font-size: 0.95rem;
}

.settings-quality-grid .graphics-quality-btn .gq-desc {
    max-width: 100%;
    overflow: hidden;
    font-size: 0.58rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.settings-inline-note {
    margin: 0;
    color: rgba(255, 255, 255, 0.34);
    font-size: 0.62rem;
    text-align: center;
}

.settings-dependent-panel {
    --settings-accent: rgba(255, 255, 255, 0.45);
    display: block;
    box-sizing: border-box;
    margin: 0 0 2px 10px;
    padding: 9px 10px;
    border: 1px solid rgba(255, 255, 255, 0.055);
    border-left: 2px solid var(--settings-accent);
    border-radius: 0 7px 7px 0;
    background: rgba(255, 255, 255, 0.018);
}

.settings-slider-stack,
.settings-slider-block {
    --settings-accent: rgba(255, 255, 255, 0.5);
}

.settings-slider-block {
    border-left: 2px solid var(--settings-accent);
}

.settings-slider-label {
    margin: 0 0 5px;
    color: var(--settings-accent);
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 1.35;
    text-align: left;
}

.settings-slider-divider {
    margin-top: 9px;
    padding-top: 9px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.graphics-settings-modal .settings-range {
    display: block;
    width: 100%;
    margin: 0;
    accent-color: var(--settings-accent);
    cursor: pointer;
}

.settings-label-preview {
    min-height: 22px;
    margin: 5px 0 1px;
    text-align: center;
}

.settings-range-hint {
    display: flex;
    justify-content: space-between;
    margin-top: 3px;
    color: rgba(255, 255, 255, 0.28);
    font-size: 0.58rem;
    line-height: 1;
}

@media (max-width: 600px) {
    .graphics-settings-overlay {
        padding:
            max(8px, env(safe-area-inset-top))
            max(8px, env(safe-area-inset-right))
            max(8px, env(safe-area-inset-bottom))
            max(8px, env(safe-area-inset-left));
    }

    .graphics-settings-modal {
        width: 100%;
        max-height: calc(100dvh - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    }

    .graphics-settings-header {
        min-height: 52px;
    }

    .graphics-settings-close {
        right: 10px;
        width: 36px;
        height: 36px;
    }

    .graphics-settings-body {
        padding: 6px 8px 10px;
    }

    .settings-category-header {
        min-height: 46px;
    }

    .settings-category-content {
        padding: 9px 10px 11px;
    }

    .settings-control-row {
        min-height: 46px;
    }

    .settings-choice-button {
        min-height: 36px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .graphics-settings-overlay,
    .graphics-settings-modal {
        animation: none;
    }

    .graphics-settings-close,
    .settings-category,
    .settings-category-header,
    .settings-category-header .settings-arrow {
        transition: none;
    }
}

/* ===== 나침반 (Compass) 스타일 ===== */
#compass-container {
    position: fixed;
    bottom: 60px;
    right: 16px;
    width: 70px;
    height: 70px;
    z-index: 1002;
    background: var(--glass-bg);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 50%;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
}

#compass-container:active {
    cursor: grabbing;
}

#compass-ring {
    position: absolute;
    width: 60px;
    height: 60px;
    border: 2px solid rgba(255, 255, 255, 0.15);
    border-radius: 50%;
}

#compass-needle {
    position: absolute;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease-out;
}

#compass-needle .compass-n {
    position: absolute;
    top: 8px;
    font-size: 12px;
    font-weight: bold;
    color: #ff4444;
    text-shadow: 0 0 4px rgba(255, 68, 68, 0.5);
}

#compass-needle .compass-s {
    position: absolute;
    bottom: 8px;
    font-size: 10px;
    font-weight: bold;
    color: rgba(255, 255, 255, 0.5);
}

#compass-needle .compass-arrow {
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 20px solid #ff4444;
    position: absolute;
    top: 18px;
    filter: drop-shadow(0 0 3px rgba(255, 68, 68, 0.6));
}

#compass-needle .compass-arrow::after {
    content: '';
    position: absolute;
    top: 20px;
    left: -6px;
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 20px solid rgba(255, 255, 255, 0.3);
}

#compass-directions {
    position: absolute;
    width: 100%;
    height: 100%;
    font-size: 8px;
    color: var(--text-gray);
    pointer-events: none;
}

#compass-directions .dir-n {
    position: absolute;
    top: -2px;
    left: 50%;
    transform: translateX(-50%);
}

#compass-directions .dir-s {
    position: absolute;
    bottom: -2px;
    left: 50%;
    transform: translateX(-50%);
}

#compass-directions .dir-e {
    position: absolute;
    right: 0px;
    top: 50%;
    transform: translateY(-50%);
}

#compass-directions .dir-w {
    position: absolute;
    left: 2px;
    top: 50%;
    transform: translateY(-50%);
}

/* ===== 되돌리기 버튼 (body 직속, position:fixed) ===== */
#undo-btn {
    position: fixed;
    bottom: 16px;
    left: 16px;
    width: 50px;
    height: 50px;
    z-index: 10000;
    background: rgba(17, 24, 39, 0.94) !important;
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 193, 7, 0.58) !important;
    border-radius: 50%;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    color: #ffd166 !important;
    font-size: 24px;
    padding: 0;
    transition: opacity 0.2s;
}

#undo-btn:active {
    background: rgba(31, 41, 55, 0.98) !important;
    cursor: grabbing;
}

#undo-btn.disabled {
    opacity: 0.3;
    cursor: default;
}

/* 조립품 편집 중에는 좌측 하단 저장 버튼을 가리지 않고 3D 캔버스에 둔다. */
body.assembly-design-editor-active #undo-btn {
    left: calc(var(--panel-width, 300px) + 18px) !important;
    top: 150px !important;
    bottom: auto !important;
}

@media (max-width: 600px) {
    #undo-btn {
        width: 42px;
        height: 42px;
        bottom: 12px;
        left: 12px;
        font-size: 20px;
    }

    body.assembly-design-editor-active #undo-btn {
        left: 10px !important;
        top: 88px !important;
        bottom: auto !important;
    }
}

/* 모바일 대응 */
@media (max-width: 600px) {
    #compass-container {
        width: 55px;
        height: 55px;
        bottom: 50px;
        right: 10px;
    }

    #compass-ring {
        width: 48px;
        height: 48px;
    }

    #compass-needle .compass-n {
        font-size: 10px;
        top: 6px;
    }

    #compass-needle .compass-s {
        font-size: 8px;
        bottom: 6px;
    }

    #compass-needle .compass-arrow {
        border-left: 5px solid transparent;
        border-right: 5px solid transparent;
        border-bottom: 16px solid #ff4444;
        top: 14px;
    }

    #compass-needle .compass-arrow::after {
        top: 16px;
        left: -5px;
        border-left: 5px solid transparent;
        border-right: 5px solid transparent;
        border-top: 16px solid rgba(255, 255, 255, 0.3);
    }

    #compass-directions {
        font-size: 7px;
    }
}

/* ========================================
   CSS Fullscreen fallback (iOS)
   ======================================== */
body.css-fullscreen .panel,
body.css-fullscreen #top-toolbar {
    display: none !important;
}
body.css-fullscreen #canvas3d {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    z-index: 9999;
}
body.css-fullscreen #canvas-top-btns {
    z-index: 10001 !important;
    position: fixed !important;
    top: calc(16px + env(safe-area-inset-top, 0px)) !important;
    right: 16px !important;
}
body.css-fullscreen #canvas3d > label {
    z-index: 10001 !important;
    position: fixed !important;
}
body.css-fullscreen #canvas3d > label[style*="top:46px"],
body.css-fullscreen #canvas3d > label[style*="top: 46px"] {
    top: calc(46px + env(safe-area-inset-top, 0px)) !important;
}
body.css-fullscreen #canvas3d > label[style*="top:76px"],
body.css-fullscreen #canvas3d > label[style*="top: 76px"] {
    top: calc(76px + env(safe-area-inset-top, 0px)) !important;
}
body.css-fullscreen #canvas3d > label[style*="top:106px"],
body.css-fullscreen #canvas3d > label[style*="top: 106px"] {
    top: calc(106px + env(safe-area-inset-top, 0px)) !important;
}
body.css-fullscreen #canvas3d > label[style*="top:136px"],
body.css-fullscreen #canvas3d > label[style*="top: 136px"] {
    top: calc(136px + env(safe-area-inset-top, 0px)) !important;
}

/* ========================================
   Pipe Row Highlight (3D 더블클릭 → 입력행)
   ======================================== */
.pipe-row-highlight {
  animation: pipeRowHighlight 3s ease;
}
@keyframes pipeRowHighlight {
  0% { background: rgba(255, 107, 0, 0.5); box-shadow: 0 0 12px rgba(255, 107, 0, 0.4); }
  100% { background: transparent; box-shadow: none; }
}
