:root {
    --bg: #121212;
    --panel: #1e1e1e;
    --accent: #007aff;
    --text: #e0e0e0;
    --text-dim: #a0a0a0;
    --border: #333;
    --success: #32d74b;
    --danger: #ff3b30;
    --card-hover: #2c2c2e;
    --white: #ffffff;
    }
    *, *::before, *::after {
    box-sizing: border-box;
    }
    
    body, html { margin: 0; padding: 0; height: 100%; width: 100%;
    background: var(--bg); color: var(--text); font-family: -apple-system,
    sans-serif; overflow: hidden; }
    
    /* Header */
    header { height: 60px;
    background: var(--panel); border-bottom: 1px solid var(--border);
    display: flex; align-items: center; padding: 0 20px;
    }
    .header-links { display: flex; align-items: center; gap: 12px;
    margin-left: auto; font-size: 0.85rem;
    }
    .header-links a { color: var(--accent); text-decoration: none;
    font-weight: 500;
    }
    .header-links a:hover { text-decoration: underline;
    }
    .header-desc { color: #d2d2d2; margin-left: 5px;
    }
    
    main { display: flex; height: calc(100vh - 60px); width: 100%; overflow:
    hidden;
    }
    
    /* Sidebar */
    #sidebar { width: 280px;
    min-width: 0; background: #181818; border-right: 1px solid
    var(--border); display: flex; flex-direction: column;
    }
    .sidebar-header {
    padding: 10px 15px;
    font-weight: bold; font-size: 0.75rem; color: #888;
    border-bottom: 1px solid var(--border); display: flex; align-items:
    center; justify-content: space-between;
    }
    .sidebar-header-left { display: flex; align-items: center; gap: 10px;
    }
    
    #file-list { flex: 1;
    overflow-y: auto; padding: 10px; list-style: none; margin: 0; }
    .sidebar-footer { padding: 15px;
    border-top: 1px solid var(--border); display: flex; flex-direction:
    column; gap: 5px;
    }
    
    .opt-title { font-size: 0.75rem;
    color: #888; font-weight: bold; margin-bottom: 5px; }
    .download-options { display: grid;
    grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 10px;
    font-size: 0.8rem; color: #aaa; border-bottom: 1px solid #2a2a2a;
    padding-bottom: 15px; margin-bottom: 5px;
    }
    .opt-label { display: flex; align-items: center; gap: 6px; cursor:
    pointer;
    }
    .opt-label input { cursor: pointer; accent-color: var(--success);
    }
    
    .file-item { padding: 8px; margin-bottom: 4px; background: #222;
    border-radius: 6px; font-size: 0.75rem;
    cursor: pointer; display: flex; align-items: center; border: 1px solid
    transparent; gap: 10px;
    }
    .file-item:hover { background: #2c2c2e;
    }
    .file-item.active { border-color: var(--accent); background: #1a2635;
    }
    .file-name { flex: 1; overflow: hidden; text-overflow: ellipsis;
    white-space: nowrap; pointer-events: none;
    }
    .delete-btn { color: #555; font-size: 1.1rem; cursor: pointer; padding:
    0 4px;
    }
    .delete-btn:hover { color: var(--danger);
    }
    
    .btn { background: #2c2c2e; color: white; border: 1px solid #3a3a3c;
    padding: 6px 12px; border-radius: 4px; cursor: pointer; font-size:
    0.75rem; font-weight: 600; transition: 0.2s;
    white-space: nowrap;}
    .btn:hover { background: #3a3a3c;
    }
    .btn-add { background: #333; color: var(--accent); border: 1px solid
    #444;
    }
    .btn-add:hover { background: #444; border-color: var(--accent);
    }
    .btn-success { background: var(--success); color: #000; border: none;
    width: 100%; font-size: 0.85rem;
    padding: 10px; }
    .btn-icon { width: 24px; padding: 0; display: flex; align-items:
    center;
    justify-content: center; font-size: 1rem; }
    
    .check-col { display: flex; align-items: center; justify-content:
    center;
    width: 24px; }
    .file-checkbox { cursor: pointer; width: 16px; height: 16px;
    accent-color: var(--accent);
    }
    
    /* Panels */
    .panel { flex: 1;
    display: flex; flex-direction: column; min-width: 0; border-right: 1px
    solid var(--border); padding: 15px; box-sizing: border-box; position:
    relative;
    }
    .panel:last-child { border-right: none;
    }
    .panel-header { height: 35px; display: flex; justify-content:
    space-between; align-items: center; margin-bottom: 10px;
    font-weight: bold; font-size: 0.9rem; }
    .panel-controls { display: flex; align-items: center; gap: 8px;
    }
    
    .viewport { flex: 1; background: #000; border-radius: 8px; overflow:
    hidden; display: flex;
    align-items: center; justify-content: center; border: 1px solid
    var(--border); position: relative;
    background-image: linear-gradient(45deg, #0d0d0d 25%, transparent 25%),
    linear-gradient(-45deg, #0d0d0d 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #0d0d0d 75%),
    linear-gradient(-45deg, transparent 75%, #0d0d0d 75%);
    background-size: 20px 20px; cursor: grab; }
    .viewport:active { cursor: grabbing;
    }
    .viewport.cursor-stamp { cursor: crosshair !important;
    }
    .viewport.cursor-stamp:active { cursor: crosshair !important;
    }
    .viewport.cursor-eraser { cursor: cell !important;
    }
    .viewport.cursor-eraser:active { cursor: cell !important;
    }
    
    .loader-overlay { position: absolute; top: 0; left: 0; width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6); display: none; align-items: center;
    justify-content: center; z-index: 10; border-radius: 8px;
    }
    .spinner { width: 32px; height: 32px; border: 3px solid #333;
    border-top: 3px solid var(--accent); border-radius: 50%; animation:
    spin 0.8s linear infinite;
    }
    @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform:
    rotate(360deg);
    } }
    
    #tiling-preview { aspect-ratio: 1 / 1; max-width: 100%; max-height:
    100%;
    background-repeat: repeat; }
    .zoom-info { position: absolute; bottom: 10px; right: 10px; font-size:
    0.7rem;
    color: #666; pointer-events: none; }
    
    .grid-controls { display: flex;
    align-items: center; gap: 8px; font-size: 0.8rem; }
    #gridVal { color: var(--accent); font-weight: bold;
    min-width: 35px; text-align: right; }
    
    /* Mask Controls */
    .mask-controls { display: flex;
    align-items: center; gap: 5px; background: #2a2a2a; padding: 3px 8px;
    border-radius: 4px; margin-right: 5px; border: 1px solid #444; opacity:
    0.5;
    transition: opacity 0.2s; }
    .mask-controls.active { opacity: 1;
    pointer-events: auto; border-color: var(--border); }
    .mask-label { font-size: 0.7rem; color: #aaa; margin-right: 4px;
    user-select: none; }
    .mask-check { margin-right: 5px; accent-color: var(--accent); cursor:
    pointer;
    }
    
    /* Drag Inputs */
    .drag-input {
    font-size: 0.7rem;
    color: var(--accent); font-weight: bold; margin-right: 10px;
    cursor: ew-resize; user-select: none; min-width: 20px; text-align:
    center;
    }
    .drag-input:hover { text-decoration: underline; filter:
    brightness(1.2);
    }
    
    /* Floating Reset Button */
    .floating-reset { position: absolute;
    top: 10px; right: 10px; z-index: 5; opacity: 0; transition: opacity
    0.2s; box-shadow: 0 2px 5px rgba(0,0,0,0.5);
    }
    .viewport:hover .floating-reset { opacity: 1;
    }
    
    /* Modal Styles - New Design */
    .modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: none;
    align-items: center; justify-content: center; z-index: 2000;
    backdrop-filter: blur(5px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
    }
    .modal-overlay.active {
    display: flex;
    opacity: 1;
    pointer-events: auto;
    }
    
    .modal-content {
        width: 420px;
        min-width: 420px;
        max-width: 420px;
        background: var(--panel);
        border: 1px solid var(--border);
        border-radius: 12px;
        padding: 30px;
        box-shadow: 0 20px 50px rgba(0,0,0,0.5);
        text-align: center;
        position: relative;
        transform: translateY(20px);
        transition: transform 0.4s ease;
        box-sizing: border-box;
        flex-shrink: 0;
    }
    .modal-overlay.active .modal-content {
    transform: translateY(0);
    }
    
    .close-modal {
    position: absolute; top: 12px; right: 12px; background: none; border:
    none;
    color: #555; font-size: 1.2rem; cursor: pointer;
    }
    .close-modal:hover { color: var(--text); }
    
    .modal-header h2 { 
    margin: 0 0 10px 0; 
    font-size: 1.4rem; 
    color: var(--white); 
    letter-spacing: -0.5px;
    }
    
    .modal-header p { 
    margin: 0 0 25px 0; 
    font-size: 0.9rem; 
    color: var(--text-dim); 
    line-height: 1.4; 
    }

    .treat-grid { 
        display: grid; 
        grid-template-columns: 1fr 1fr;
        gap: 12px; 
        margin-bottom: 25px; 
        width: 100%;
    }

    .treat-card {
        background: #252525;
        border: 1px solid var(--border);
        border-radius: 10px;
        padding: 22px 12px;
        cursor: pointer;
        transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
        text-decoration: none;
        display: flex;
        flex-direction: column;
        align-items: center;
        position: relative;
        min-height: 180px;
        width: 100%;
        box-sizing: border-box;
    }    

    .treat-card:hover {
    border-color: var(--accent);
    background: var(--card-hover);
    transform: translateY(-4px);
    box-shadow: 0 8px 16px rgba(0,0,0,0.3);
    }

    .treat-card .icon { 
    font-size: 26px; 
    margin-bottom: 12px; 
    }
    
    .treat-card .price { 
    font-weight: 700; 
    color: var(--white); 
    font-size: 1rem;
    letter-spacing: 0.3px;
    margin-bottom: 2px;
    }

    .treat-card .separator {
    color: var(--text-dim);
    opacity: 0.4;
    font-size: 0.8rem;
    margin-bottom: 2px;
    }

    .treat-card .item-name {
    font-weight: 600;
    color: var(--white);
    font-size: 0.8rem;
    margin-bottom: 10px;
    }
    
    .treat-card .message { 
    font-size: 0.72rem; 
    color: var(--text-dim); 
    line-height: 1.2; 
    font-style: italic;
    word-break: keep-all;
    max-width: 95%;
    }

    .treat-card .tag {
    position: absolute;
    top: -8px;
    background: var(--accent);
    color: white;
    font-size: 0.6rem;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0;
    transform: translateY(4px);
    transition: all 0.2s ease;
    z-index: 10;
    }
    
    .treat-card:hover .tag { 
    opacity: 1; 
    transform: translateY(0);
    }

    .treat-card.popular {
    border-color: rgba(0, 122, 255, 0.5);
    background: #2a2a2a;
    }

    .modal-footer { 
    font-size: 0.75rem; 
    color: #666; 
    border-top: 1px solid var(--border); 
    padding-top: 15px; 
    }

    /* 사이드바를 제외한 나머지 영역을 감싸는 컨테이너 */
.workspace-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg);
}

/* 모드 탭 컨테이너 (왼쪽 정렬) */
.mode-container {
    display: flex;
    padding: 12px 20px 0 20px;
    gap: 8px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

.mode-tab {
    padding: 8px 16px;
    cursor: pointer;
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-weight: 600;
    font-size: 0.8rem;
    border-radius: 6px 6px 0 0;
    transition: all 0.2s ease;
    border: 1px solid transparent;
    border-bottom: none;
    margin-bottom: -1px; /* border-bottom과 겹치게 하여 활성화 표시 */
}

.mode-tab:hover {
    color: var(--text);
    background: var(--panel);
}

.mode-tab.active {
    color: var(--accent);
    background: var(--panel);
    border-color: var(--border);
    border-bottom: 1px solid var(--panel); /* 탭 하단 선 제거 효과 */
}

/* 모드별 컨텐츠 영역 제어 */
.mode-content {
    display: none; /* 기본적으로 숨김 */
    flex: 1;
    width: 100%;
    overflow: hidden;
}

.mode-content.active {
    display: flex; /* 활성화 시 레이아웃 복구 */
}

/* --- Make PBR Textures 전용 디자인 --- */

/* Main split container: 1:2 ratio */
.pbr-split-container {
    display: flex;
    width: 100%;
    height: 100%;
    gap: 15px;
    padding: 15px;
    overflow: hidden;
}

/* Left section: 3D Preview & Controllers (1 part) */
.pbr-left-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 15px;
    min-width: 0;
}

.pbr-3d-viewport {
    flex: 1;
    background: #000;
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background-image: linear-gradient(45deg, #0d0d0d 25%, transparent 25%),
                      linear-gradient(-45deg, #0d0d0d 25%, transparent 25%),
                      linear-gradient(45deg, transparent 75%, #0d0d0d 75%),
                      linear-gradient(-45deg, transparent 75%, #0d0d0d 75%);
    background-size: 20px 20px;
    position: relative;
}

.pbr-3d-preview {
    font-size: 0.9rem;
    color: #444;
    font-weight: 600;
}

.pbr-controllers {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.pbr-control-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.pbr-control-label {
    font-size: 0.75rem;
    color: var(--text-dim);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.pbr-control-slider {
    width: 100%;
    accent-color: var(--accent);
    cursor: pointer;
    height: 6px;
}

.pbr-mesh-buttons {
    display: flex;
    gap: 8px;
}

.pbr-mesh-btn {
    flex: 1;
    padding: 8px 12px;
    font-size: 0.75rem;
    transition: all 0.2s ease;
}

.pbr-mesh-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* Auto-rotate toggle switch */
.pbr-auto-rotate-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.pbr-auto-rotate-label {
    font-size: 0.7rem;
    color: var(--text);
    font-weight: 500;
}

.pbr-switch {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
    cursor: pointer;
}

.pbr-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.pbr-switch-slider {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #333;
    border: 1px solid var(--border);
    border-radius: 20px;
    transition: all 0.3s ease;
}

.pbr-switch-slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 2px;
    bottom: 2px;
    background-color: #666;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.pbr-switch input:checked + .pbr-switch-slider {
    background-color: var(--accent);
    border-color: var(--accent);
}

.pbr-switch input:checked + .pbr-switch-slider:before {
    transform: translateX(16px);
    background-color: white;
}

.pbr-switch:hover .pbr-switch-slider {
    border-color: #555;
}

.pbr-albedo-display {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #222;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px;
    min-height: 60px;
}

.pbr-albedo-thumbnail {
    width: 40px;
    height: 40px;
    background: #1a1a1a;
    border: 1px solid var(--border);
    border-radius: 4px;
    flex-shrink: 0;
    background-size: cover;
    background-position: center;
}

.pbr-albedo-info {
    flex: 1;
    min-width: 0;
}

.pbr-albedo-name {
    font-size: 0.75rem;
    color: var(--text-dim);
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#pbr-canvas {
    width: 100%;
    height: 100%;
    display: block;
    cursor: grab;
}

#pbr-canvas:active {
    cursor: grabbing;
}

/* Right section: PBR Maps (2 parts) */
.pbr-right-section {
    flex: 2;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

.pbr-maps-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    overflow-y: auto;
    padding: 2px;
}

.pbr-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px;
    transition: transform 0.2s ease, border-color 0.2s ease;
    display: flex;
    flex-direction: column;
}

.pbr-card:hover {
    border-color: #444;
}

.pbr-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.pbr-card h4 {
    margin: 0;
    font-size: 0.85rem;
    color: var(--text);
    font-weight: 600;
}

/* Map toggle switches (smaller version) */
.pbr-map-switch {
    position: relative;
    display: inline-block;
    width: 32px;
    height: 18px;
    cursor: pointer;
}

.pbr-map-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.pbr-map-switch-slider {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #333;
    border: 1px solid var(--border);
    border-radius: 18px;
    transition: all 0.3s ease;
}

.pbr-map-switch-slider:before {
    position: absolute;
    content: "";
    height: 12px;
    width: 12px;
    left: 2px;
    bottom: 2px;
    background-color: #666;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.pbr-map-switch input:checked + .pbr-map-switch-slider {
    background-color: var(--accent);
    border-color: var(--accent);
}

.pbr-map-switch input:checked + .pbr-map-switch-slider:before {
    transform: translateX(14px);
    background-color: white;
}

.pbr-map-switch:hover .pbr-map-switch-slider {
    border-color: #555;
}

/* Normal map controls */
.pbr-normal-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

.pbr-flip-y-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.7rem;
    color: var(--text);
    cursor: pointer;
}

.pbr-flip-y-label input[type="checkbox"] {
    cursor: pointer;
    accent-color: var(--accent);
}

/* PBR Map Controls Container */
.pbr-map-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 6px;
}

/* Parameter Row with Draggable Value */
.pbr-param-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 0;
}

.pbr-param-row label {
    font-size: 0.75rem;
    color: var(--text);
    font-weight: 500;
}

.pbr-drag-value {
    font-size: 0.75rem;
    color: var(--accent);
    font-weight: 600;
    min-width: 45px;
    text-align: right;
    padding: 4px 8px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.05);
    cursor: ew-resize;
    user-select: none;
    transition: background 0.2s ease;
}

.pbr-drag-value:hover {
    background: rgba(255, 255, 255, 0.1);
}

.pbr-drag-value:active {
    background: rgba(255, 255, 255, 0.15);
    cursor: ew-resize;
}

/* PBR 슬라이더 커스텀 (기존 스타일 계승) */
.pbr-slider {
    width: 100%;
    margin: 10px 0 20px 0;
    accent-color: var(--accent);
    cursor: pointer;
}

.pbr-preview-box {
    width: 100%;
    aspect-ratio: 1 / 1;
    background: #000;
    border-radius: 6px;
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    color: #444;
    background-image: linear-gradient(45deg, #0d0d0d 25%, transparent 25%),
                      linear-gradient(-45deg, #0d0d0d 25%, transparent 25%),
                      linear-gradient(45deg, transparent 75%, #0d0d0d 75%),
                      linear-gradient(-45deg, transparent 75%, #0d0d0d 75%);
    background-size: 10px 10px;
}

/* 스크롤바 커스텀 (필요 시) */
.pbr-maps-grid::-webkit-scrollbar {
    width: 8px;
}
.pbr-maps-grid::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}