:root { 
    --primary: #4a90e2; 
    --bg-panel: #ffffff; 
    --border: #ddd; 
    --accent-red: #ff4757;
    --code-bg: #282c34;
}

body { 
    font-family: 'Segoe UI', sans-serif; 
    padding: 20px; 
    background-color: #f4f6f8; 
    user-select: none; 
    margin: 0; 
    box-sizing: border-box;
    height: 100vh;
    overflow: hidden; 
}

/* ============================
   1. 메인 레이아웃 (Grid/Flex)
   ============================ */
.main-container { 
    display: flex; 
    gap: 20px; 
    max-width: 1600px; 
    margin: 0 auto; 
    height: calc(100vh - 40px); 
    flex-wrap: nowrap; 
}

/* ============================
   2. 사이드바 (도구 상자)
   ============================ */
.sidebar { 
    width: 320px; 
    min-width: 300px;
    background: var(--bg-panel); 
    padding: 20px; 
    border-radius: 12px; 
    box-shadow: 0 4px 15px rgba(0,0,0,0.08); 
    display: flex; 
    flex-direction: column; 
    gap: 15px; 
    flex-shrink: 0;
    
    transition: width 0.3s ease, padding 0.3s ease, margin 0.3s ease, opacity 0.3s;
    overflow-y: auto; 
    overflow-x: hidden;
    white-space: nowrap;
}

.sidebar h3 { margin: 0 0 10px 0; color: #333; }

.seo-copy {
    margin-top: 10px;
    padding: 10px;
    border: 1px solid #eceff4;
    border-radius: 8px;
    background: #fafbfd;
    white-space: normal;
}

.seo-copy h1 {
    font-size: 13px;
    line-height: 1.4;
    margin: 0 0 6px;
    color: #222;
}

.seo-copy p {
    margin: 0 0 6px;
    font-size: 12px;
    line-height: 1.45;
    color: #586072;
}

/* 사이드바 접기 상태 */
.sidebar.collapsed {
    width: 0 !important;
    min-width: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    opacity: 0;
    overflow: hidden;
}

/* 툴 버튼 및 입력창 스타일 */
.btn-tool { 
    padding: 12px; border: 1px solid var(--border); background: #f9f9f9; 
    border-radius: 8px; cursor: pointer; transition: 0.2s; 
    display: flex; align-items: center; justify-content: center; 
    font-weight: 600; font-size: 14px; color: #555;
}
.btn-tool:hover { background: #eef5ff; border-color: var(--primary); }
.btn-tool.active { 
    background: var(--primary); color: white; border-color: var(--primary); 
    box-shadow: 0 2px 5px rgba(74, 144, 226, 0.3);
}

.btn-sub {
    padding: 8px; border: 1px solid #ccc; background: #fff; 
    border-radius: 6px; cursor: pointer; font-size: 12px; font-weight: 500;
}
.btn-sub:hover { background: #fff; border-color: var(--primary); color: var(--primary); }
.btn-sub.active { background: var(--primary); color: white; border-color: var(--primary); }

.properties-panel { display: flex; flex-direction: column; gap: 15px; margin-top: 10px; }
.control-row { display: flex; flex-direction: column; gap: 8px; }
.control-row label { 
    font-size: 13px; color: #444; font-weight: 600; 
    display: flex; justify-content: space-between; align-items: center; 
}
.input-group { display: flex; gap: 8px; align-items: center; }

input[type="range"] { width: 100%; cursor: pointer; accent-color: var(--primary); }
input[type="color"] { width: 40px; height: 35px; border: none; padding: 0; background: none; cursor: pointer; border-radius: 4px; }
input[type="text"], select { padding: 8px; border: 1px solid #ccc; border-radius: 6px; width: 100%; font-size: 13px; box-sizing: border-box; }

.action-btn { 
    background: #fff; border: 1px solid #ccc; padding: 10px; 
    border-radius: 6px; cursor: pointer; font-size: 13px; 
    width: 100%; transition: 0.2s; font-weight: 500;
}
.action-btn:hover { background: #f5f5f5; border-color: #bbb; }
.action-btn.primary { background: var(--primary); color: white; border: none; font-weight: bold; box-shadow: 0 4px 6px rgba(74, 144, 226, 0.2); }
.action-btn.primary:disabled { background: #ccc; cursor: not-allowed; box-shadow: none; }

/* ============================
   3. 캔버스 영역 & 상단 툴바
   ============================ */
.canvas-area {
    display: flex; flex-direction: column; position: relative;
    flex: 1; min-width: 0; min-height: 0; overflow: hidden;
}

#svg-wrapper { 
    box-shadow: 0 10px 30px rgba(0,0,0,0.15); 
    background-color: white; 
    height: 100%; 
    touch-action: none; 
    /* width가 없으면 flex 부모에 의해 자동 조절되지만, 확실하게 100% 줍니다 */
    width: 100%; 
    overflow: hidden; /* 스크롤바 방지 */
}

/* ▼▼▼ [수정/추가] SVG가 부모 크기를 꽉 채우도록 설정 ▼▼▼ */
#mainSvg {
    width: 100%;
    height: 100%;
    display: block; /* 하단 미세 공백 제거 */
}
/* [style.css] 3. 캔버스 영역 섹션 내부에 추가 */

.preview-line {
    stroke: #ff4757;       /* 빨간색 (var(--accent-red)) */
    stroke-width: 1.5px;
    stroke-dasharray: 4 4; /* 점선 효과 */
    pointer-events: none;  /* 마우스 이벤트가 선에 가려지지 않도록 설정 */
    display: none;         /* 기본적으로 숨김 (그리기 할 때만 JS가 block으로 변경) */
}

/* 상단 툴바 */
.top-bar {
    height: auto; min-height: 50px; flex-wrap: wrap;
    padding: 8px 15px; gap: 8px;
    background: #ffffff; border-bottom: 1px solid #ddd;
    display: flex; align-items: center; border-radius: 12px 12px 0 0;
    flex-shrink: 0; z-index: 100;
    overflow: visible; white-space: normal;
}

.btn-icon {
    background: transparent; border: 1px solid transparent; border-radius: 4px;
    width: 32px; height: 32px; cursor: pointer; font-size: 16px;
    display: flex; align-items: center; justify-content: center; transition: 0.2s;
}
.btn-icon:hover { background-color: #f0f0f0; border-color: #ddd; }
.btn-icon.active { background-color: var(--primary); color: white; }

.v-divider { width: 1px; height: 24px; background-color: #ddd; margin: 0 8px; }

/* 드롭다운 메뉴 */
.dropdown-container { position: relative; display: inline-block; }
.dropdown-menu {
    display: none; position: absolute; top: 100%; left: 0; margin-top: 5px;
    background: white; border: 1px solid #ddd; border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15); z-index: 1000;
    min-width: 100px; flex-direction: column; padding: 5px;
}
.dropdown-menu.show { display: flex; }
.dropdown-menu .btn-sub { text-align: left; border: none; background: none; width: 100%; padding: 8px 12px; }

/* ============================
   4. 코드 뷰어 영역 (PC 기본)
   ============================ */
.code-area { 
    width: 320px; 
    min-width: 280px; 
    display: flex; 
    flex-direction: column; 
    flex-shrink: 0; 
    min-height: 0;

    /* 겉만 둥글게 처리하고 배경은 투명하게 (헤더와 바디가 나뉘므로) */
    background: transparent; 
    
    /* 애니메이션 설정 */
    transition: width 0.3s ease, min-width 0.3s ease, transform 0.3s ease, opacity 0.3s ease;
    overflow: hidden; 
}
.code-area.collapsed {
    width: 0 !important;
    min-width: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    opacity: 0;
    border: none;
}

/* ▼▼▼ [디자인 변경] 하얀색 탭 스타일 헤더 ▼▼▼ */
.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    
    /* 배경을 하얀색으로 설정하여 탭 느낌 주기 */
    background: #ffffff; 
    border: 1px solid #ddd;
    border-bottom: 1px solid #eee; /* 하단 구분선 */
    border-radius: 12px 12px 0 0; /* 위쪽만 둥글게 */
    
    flex-shrink: 0;
    min-height: 45px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.03); /* 살짝 그림자 */
    z-index: 2; /* 뷰어보다 위에 보이게 */
}

/* 제목 색상 (하얀 배경이니 어둡게) */
.code-header h3 {
    color: #333 !important;
    font-size: 14px;
    margin: 0;
    font-weight: 700;
}

/* 버튼 그룹 */
.code-controls { display: flex; gap: 6px; }

/* 버튼 스타일 (밝은 테마에 맞게) */
.code-controls .action-btn {
    padding: 5px 10px;
    font-size: 12px;
    background: #f0f2f5; /* 연한 회색 */
    color: #555;
    border: 1px solid #dcdfe6;
    border-radius: 6px;
    width: auto;
    font-weight: 600;
}
.code-controls .action-btn:hover {
    background: #e6e8eb;
    color: #333;
    border-color: #c0c4cc;
}

/* 코드 뷰어 본문 (검은색 유지) */
.code-view { 
    flex: 1; padding: 15px; 
    background: var(--code-bg); /* 어두운 배경 */
    color: #abb2bf; 
    
    /* 아래쪽만 둥글게 */
    border-radius: 0 0 12px 12px; 
    
    overflow-y: auto; font-family: 'Consolas', monospace; font-size: 12px; 
    line-height: 1.6; white-space: pre-wrap; word-break: break-all;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}

/* 변형 핸들 (캔버스 내부) */
#handleResize { stroke-width: 1.5px; transition: fill 0.2s; }
#handleResize:hover { fill: #4a90e2; }
#handleRotate:hover { fill: #ff4757; }

/* 도움말 모달 스타일 */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.5); display: none;
    justify-content: center; align-items: center; z-index: 2000; backdrop-filter: blur(2px);
}
.modal-overlay.show { display: flex; }
.modal-window {
    background: white; width: 600px; max-width: 90%; max-height: 85vh;
    border-radius: 12px; box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    display: flex; flex-direction: column; overflow: hidden; animation: popIn 0.3s ease;
}
@keyframes popIn { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: scale(1); } }
.modal-header { padding: 15px 20px; border-bottom: 1px solid #eee; display: flex; justify-content: space-between; align-items: center; background: #f8f9fa; }
.btn-close { background: none; border: none; font-size: 24px; cursor: pointer; color: #999; }
.modal-content { padding: 20px; overflow-y: auto; }
.modal-footer { padding: 10px 20px; border-top: 1px solid #eee; text-align: right; background: #f8f9fa; }
.shortcut-table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 13px; }
.shortcut-table th { background: #eee; padding: 8px; text-align: left; }
.shortcut-table td { border-bottom: 1px solid #f0f0f0; padding: 8px; }
kbd { background-color: #f7f7f7; border: 1px solid #ccc; border-radius: 3px; padding: 2px 6px; font-weight: bold; color: #333; }
.help-section h3 { border-bottom: 2px solid var(--primary); display: inline-block; padding-bottom: 5px; color: var(--primary); }

/* =========================================================
   [반응형] 모바일/태블릿 설정 (1000px 이하)
   ========================================================= */

/* 1. PC 화면 기본 설정 */
.btn-close-code { display: none; } /* PC에선 닫기 버튼 숨김 */
.code-header {
    display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px;
}
.code-controls { display: flex; gap: 5px; }
/* =========================================================
   [반응형] 모바일/태블릿 설정 (1000px 이하)
   ========================================================= */

@media (max-width: 1000px) {
    /* 레이아웃 겹침 모드 */
    .main-container { display: block; position: relative; overflow: hidden; }
    
    /* 캔버스 꽉 채우기 */
    .canvas-area { width: 100% !important; height: 100% !important; position: absolute; top: 0; left: 0; z-index: 1; }

    /* 모바일 툴바는 한 줄 가로 스크롤로 유지 */
    .top-bar {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
        padding: 6px 10px;
        gap: 6px;
    }
    .top-bar .v-divider {
        margin: 0 4px;
        height: 20px;
        flex: 0 0 auto;
    }
    .dropdown-container { flex: 0 0 auto; }

    /* 터치 타겟 확대 (권장 최소 44x44) */
    .btn-icon {
        width: 44px;
        height: 44px;
        font-size: 18px;
        flex: 0 0 auto;
    }
    .btn-tool {
        min-height: 44px;
    }
    
    /* 1. 왼쪽 사이드바 (기존 유지) */
    .sidebar {
        position: absolute;
        top: var(--mobile-top-offset, 50px);
        left: 0;
        bottom: 0;
        width: min(82vw, 320px) !important;
        z-index: 1002; box-shadow: 2px 0 15px rgba(0,0,0,0.2); border-right: 1px solid #ddd;
        transition: transform 0.3s ease; display: flex !important; height: auto !important;
        transform: translateX(0); opacity: 1 !important; padding: 20px !important;
    }
    .sidebar.collapsed { transform: translateX(-100%); } /* 왼쪽으로 숨김 */
    .sidebar:not(.collapsed) { background-color: rgba(255, 255, 255, 0.95); backdrop-filter: blur(5px); }

    /* ▼▼▼ 2. [수정됨] 오른쪽 코드창 (모바일 오버레이) ▼▼▼ */
    .code-area {
        position: absolute; 
        top: var(--mobile-top-offset, 50px);
        right: 0;   /* 오른쪽에 붙임 */
        bottom: 0; 
        
        /* 모바일에서는 너비 고정 */
        width: min(92vw, 340px) !important; 
        min-width: min(92vw, 340px) !important; 
        
        z-index: 1003; /* 사이드바보다 위에 */
        box-shadow: -2px 0 15px rgba(0,0,0,0.2); /* 그림자 방향 반대 */
        
        /* 애니메이션은 transform 사용 */
        transition: transform 0.3s ease !important; 
        transform: translateX(0); /* 기본: 보임 */
        opacity: 1 !important;
        border: none;
        
        /* 배경 처리 (헤더 둥글기 때문에 배경 필요) */
        background: transparent;
        pointer-events: auto;
    }

    /* 닫혔을 때 (모바일) - 오른쪽으로 슬라이드 아웃 */
    .code-area.collapsed {
        transform: translateX(105%); /* 오른쪽 화면 밖으로 이동 */
        
        /* PC용 스타일(width: 0)을 무력화해야 함 */
        width: min(92vw, 340px) !important; 
        min-width: min(92vw, 340px) !important;
        opacity: 1 !important; 
        display: flex !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    /* 닫기(X) 버튼 보이기 */
    .btn-close-code { display: block; }
}

/* 3. PC 전용 (1001px 이상) */
@media (min-width: 1001px) {
    /* 기존의 display: none !important; 는 애니메이션을 막으므로 제거됨 */
    /* .code-area.collapsed { display: none !important; }  <-- 이거 삭제됨 */
    
    .code-area {
        /* PC에서는 오른쪽 보더나 그림자 처리를 위해 필요시 추가 스타일 */
        border-left: 1px solid var(--border);
    }
}

/* 저작권 표시 (Footer) */
.app-footer {
    margin-top: auto; padding: 20px 0 5px 0;
    border-top: 1px solid #eee; text-align: center; color: #aaa; font-size: 11px;
}

/* --- [추가] 코드창 강조 효과 (선택/마우스오버) --- */
.code-line {
    padding: 2px 5px;
    border-radius: 2px;
    transition: background-color 0.1s;
    cursor: pointer; /* 코드 클릭 시 역으로 선택 가능 */
}

/* 강조 스타일 (공통) */
.code-line.highlight {
    background-color: rgba(74, 144, 226, 0.2); /* 파란색 틴트 */
    border-left: 3px solid var(--primary);
    font-weight: bold;
}

/* 모바일(어두운 배경)에서는 글자색 밝게 */
@media (max-width: 1000px) {
    .code-line.highlight {
        background-color: rgba(255, 255, 255, 0.15);
        color: #fff;
    }
}

/* [수정] 선 스타일 메뉴의 옵션이 항상 보이도록 강제 설정 */
#strokeSubMenu .btn-sub {
    display: block !important; /* 무조건 보이게 함 */
    color: #333;               /* 기본 글자색 */
}

/* 선택된 항목(active)은 파란 배경에 흰 글씨 */
#strokeSubMenu .btn-sub.active {
    display: block !important; /* 선택돼도 사라지지 않게 함 */
    background-color: var(--primary) !important;
    color: white !important;
}

/* =========================================================
   [긴급 수정] 드롭다운 메뉴 시인성 및 호버 효과 복구
   ========================================================= */

/* 1. 도형 및 모든 드롭다운의 '선택된 항목(Active)' 텍스트 보임 처리 */
/* 배경색이 확실하게 들어가도록 !important 강제 적용 */
.dropdown-menu .btn-sub.active {
    background-color: var(--primary) !important;  /* 진한 파란색 배경 */
    color: #ffffff !important;                    /* 흰색 글자 (배경과 대비되어 잘 보임) */
    border-color: var(--primary) !important;
}

/* 2. 선 스타일(실선/점선) 메뉴 마우스 오버(Hover) 효과 적용 */
/* 지난번 추가한 ID(#strokeSubMenu) 설정이 호버 효과를 덮어쓰지 못하게 재정의 */
#strokeSubMenu .btn-sub:hover {
    background-color: #ffffff !important;         /* 배경은 흰색 유지 */
    color: var(--primary) !important;             /* 글자를 파란색으로 (도형 메뉴와 동일) */
    border-color: var(--primary) !important;      /* 테두리 파란색 */
    cursor: pointer;
}

/* 3. 선 스타일 메뉴 기본 텍스트 색상 정리 */
#strokeSubMenu .btn-sub {
    color: #333; /* 평소에는 검은색 (호버 시 파란색으로 변함) */
}

/* [style.css] 색상 팔레트 스타일 */
.palette-container {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 5px;
}
.color-swatch {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    cursor: pointer;
    border: 1px solid #ddd;
    transition: transform 0.1s, border-color 0.1s;
}
.color-swatch:hover {
    transform: scale(1.2);
    border-color: #999;
    z-index: 1;
}

/* [style.css] 맨 아래 추가 */

/* --- 후원 및 피드백 영역 --- */
.support-area {
    margin-top: auto; /* 사이드바 맨 아래로 밀어내기 */
    padding: 15px 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-top: 1px solid #eee;
}

.btn-support {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px;
    border-radius: 8px;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    transition: transform 0.2s, box-shadow 0.2s;
}

.btn-support:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

/* 커피 후원 버튼 (노란색 계열) */
.btn-support.coffee {
    background-color: #FFDD00;
    color: #000;
    border: 1px solid #F0D000;
}

/* 피드백 버튼 (회색 계열) */
.btn-support.feedback {
    background-color: #f1f3f5;
    color: #555;
    border: 1px solid #e9ecef;
}
.btn-support.feedback:hover {
    background-color: #e9ecef;
    color: #333;
}

.mobile-dock,
.mobile-quick-panel {
    display: none;
}

@media (max-width: 1000px) {
    .mobile-dock {
        position: fixed;
        left: 10px;
        right: 10px;
        bottom: calc(8px + env(safe-area-inset-bottom));
        z-index: 1500;
        display: grid;
        grid-template-columns: repeat(6, minmax(0, 1fr));
        gap: 6px;
        padding: 8px;
        border-radius: 14px;
        border: 1px solid #d9e1ec;
        background: rgba(255, 255, 255, 0.96);
        backdrop-filter: blur(10px);
        box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    }

    .mobile-dock-btn {
        min-height: 48px;
        border: 1px solid #dce4ee;
        background: #f7f9fc;
        border-radius: 10px;
        font-size: 16px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        color: #304055;
    }

    .mobile-dock-btn span {
        font-size: 10px;
        font-weight: 700;
        letter-spacing: 0.2px;
    }

    .mobile-dock-btn.active {
        background: var(--primary);
        color: #fff;
        border-color: var(--primary);
    }

    .mobile-quick-panel {
        position: fixed;
        right: 10px;
        bottom: calc(70px + env(safe-area-inset-bottom));
        z-index: 1501;
        padding: 8px;
        border-radius: 12px;
        background: rgba(255, 255, 255, 0.97);
        border: 1px solid #d9e1ec;
        box-shadow: 0 8px 20px rgba(0, 0, 0, 0.14);
        min-width: 160px;
    }

    .mobile-quick-panel.show {
        display: flex;
        flex-direction: column;
        gap: 6px;
    }

    .mobile-quick-btn {
        min-height: 40px;
        border: 1px solid #dce4ee;
        border-radius: 8px;
        background: #f7f9fc;
        color: #2f3f55;
        font-weight: 700;
        font-size: 13px;
    }

    .canvas-area {
        padding-bottom: calc(82px + env(safe-area-inset-bottom));
        box-sizing: border-box;
    }

    #svg-wrapper {
        height: calc(100% - 82px);
    }
}
