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

:root {
    --primary-color: #6366f1;
    --secondary-color: #8b5cf6;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --light-gray: #f3f4f6;
    --border-gray: #e5e7eb;
    --text-dark: #1f2937;
    --text-light: #6b7280;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
        'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
        sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: var(--text-dark);
    overflow-x: hidden;
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 15px;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    margin-bottom: 15px;
    padding: 0;
    background: transparent;
    border-radius: 0;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 20px;
    height: 50px;
}

/* 로고 버튼 */
.logo-btn {
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    height: 50px;
    transition: all 0.3s ease;
    flex-shrink: 0;
    margin-left: -5px;
}

.logo-btn:hover {
    transform: scale(1.05);
}

.logo-btn:active {
    transform: scale(0.98);
}

#logoCanvas {
    filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.3));
}

/* 기능 탭 */
.feature-tabs {
    display: flex;
    gap: 10px;
    align-items: center;
    flex: 1;
}

.tab-btn {
    padding: 10px 18px;
    background: white;
    color: var(--primary-color);
    border: 2px solid white;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.25s ease;
    white-space: nowrap;
    display: flex;
    gap: 6px;
    align-items: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.tab-label {
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.7;
    font-size: 0.7rem;
}

.tab-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.25);
    color: var(--secondary-color);
}

.tab-btn:active {
    transform: translateY(0);
}

.tab-btn.active {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    border-color: white;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 15px;
    overflow-y: auto;
}

/* 이미지 리스트 섹션 */
.image-list-section {
    background: white;
    border-radius: 12px;
    padding: 15px;
    box-shadow: var(--shadow);
    flex-shrink: 0;
}

.image-list-section h3 {
    font-size: 0.95rem;
    margin-bottom: 10px;
    color: var(--text-dark);
    font-weight: 600;
}

.image-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 10px;
}

.image-item {
    position: relative;
    cursor: pointer;
    border-radius: 6px;
    overflow: hidden;
    border: 2px solid transparent;
    transition: all 0.3s ease;
}

.image-item canvas {
    width: 100%;
    height: 80px;
    display: block;
}

.image-item.active {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px white, 0 0 0 3px var(--primary-color);
}

.image-item:hover {
    transform: scale(1.08);
}

.image-item-index {
    position: absolute;
    top: 3px;
    right: 3px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.75rem;
    font-weight: 600;
}

/* 이미지 정보 - 컴팩트 */
.image-info-compact {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px;
    background: #f9fafb;
    border-radius: 6px;
    min-width: 160px;
}

.info-item-compact {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.info-item-compact .label {
    font-size: 0.75rem;
    color: var(--text-light);
    font-weight: 600;
    text-transform: uppercase;
}

.info-item-compact .value {
    font-size: 0.85rem;
    color: var(--primary-color);
    font-weight: 600;
}

/* 업로드 섹션 */
.upload-section {
    flex-shrink: 0;
}

.upload-box {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: var(--shadow-lg);
    transition: all 0.3s ease;
}

.upload-box:hover {
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.15);
}

.upload-box.dragover {
    background: var(--light-gray);
    border: 2px solid var(--primary-color);
}

.upload-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    gap: 10px;
    padding: 15px;
}

.upload-icon {
    font-size: 2.5rem;
    display: block;
}

.upload-label p {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-dark);
    margin: 0;
}

.upload-label small {
    color: var(--text-light);
    font-size: 0.85rem;
}

/* 이미지 정보 */
.image-info {
    background: white;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 30px;
    box-shadow: var(--shadow);
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}

.info-item {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.info-item .label {
    font-size: 0.85rem;
    color: var(--text-light);
    font-weight: 600;
    text-transform: uppercase;
}

.info-item .value {
    font-size: 1.1rem;
    color: var(--primary-color);
    font-weight: 600;
}

/* 에디터 섹션 */
.editor-section {
    background: white;
    border-radius: 12px;
    padding: 15px;
    box-shadow: var(--shadow-lg);
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.editor-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    height: 100%;
}

@media (max-width: 1200px) {
    .editor-container {
        grid-template-columns: 1fr;
    }
}

/* 미리보기 패널 */
.preview-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow: hidden;
}

.preview-panel h3 {
    font-size: 1rem;
    color: var(--text-dark);
    font-weight: 600;
    margin: 0;
}

.preview-box {
    background: var(--light-gray);
    border: 2px dashed var(--border-gray);
    border-radius: 8px;
    padding: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    position: relative;
    overflow: auto;
    cursor: crosshair;
}

.preview-box.no-crop {
    cursor: default;
}

.canvas-wrapper {
    position: relative;
    display: inline-block;
    overflow: hidden;
    line-height: 0;
}

canvas {
    max-width: 100%;
    max-height: 100%;
    display: block;
    background: white;
    border-radius: 4px;
}

#cropOverlay {
    position: absolute;
    border: 2px solid var(--primary-color);
    background: transparent;
    cursor: move;
    display: none;
    transition: none;
    /* 크롭 영역 바깥을 어둡게 처리하여 잘릴 부분을 표시 */
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.45);
}

#cropOverlay.rectangle {
    border-radius: 0;
}

#cropOverlay.circle {
    border-radius: 50%;
}

.crop-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: var(--primary-color);
    border: 2px solid white;
    border-radius: 50%;
    cursor: pointer;
    display: none;
    box-shadow: 0 0 4px rgba(0,0,0,0.3);
}

.crop-handle.nw { top: -5px; left: -5px; cursor: nwse-resize; }
.crop-handle.ne { top: -5px; right: -5px; cursor: nesw-resize; }
.crop-handle.sw { bottom: -5px; left: -5px; cursor: nesw-resize; }
.crop-handle.se { bottom: -5px; right: -5px; cursor: nwse-resize; }
.crop-handle.n { top: -5px; left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.crop-handle.s { bottom: -5px; left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.crop-handle.w { top: 50%; left: -5px; transform: translateY(-50%); cursor: ew-resize; }
.crop-handle.e { top: 50%; right: -5px; transform: translateY(-50%); cursor: ew-resize; }

#cropOverlay.active .crop-handle {
    display: block;
}

/* 하단 중앙 화살표 버튼 */
.btn-expand-arrow {
    align-self: center;
    flex-shrink: 0;
    margin-top: 8px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: rgba(99, 102, 241, 0.9);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    transition: all 0.25s ease;
    z-index: 10;
}

.btn-expand-arrow:hover {
    background: var(--primary-color);
    transform: scale(1.12);
}

.btn-expand-arrow:active {
    transform: scale(0.95);
}

/* 미리보기 창 확장 모드: 미리보기를 위쪽 전체 폭으로 크게, 컨트롤은 아래로 */
.editor-section.preview-expanded {
    flex: none;
    height: auto;
    overflow: visible;
}

.editor-section.preview-expanded .editor-container {
    grid-template-columns: 1fr;
    height: auto;
}

.editor-section.preview-expanded .preview-panel {
    overflow: visible;
}

.editor-section.preview-expanded .preview-box {
    min-height: 75vh;
    max-height: 80vh;
}

.editor-section.preview-expanded canvas {
    max-height: 72vh;
}

.editor-section.preview-expanded .btn-expand-arrow {
    background: rgba(239, 68, 68, 0.9);
}

.editor-section.preview-expanded .btn-expand-arrow:hover {
    background: var(--danger-color);
}

/* 컨트롤 패널 */
.control-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 8px;
}

.control-panel::-webkit-scrollbar {
    width: 6px;
}

.control-panel::-webkit-scrollbar-track {
    background: var(--light-gray);
    border-radius: 3px;
}

.control-panel::-webkit-scrollbar-thumb {
    background: var(--border-gray);
    border-radius: 3px;
}

.control-panel::-webkit-scrollbar-thumb:hover {
    background: var(--text-light);
}

.control-section {
    padding: 12px;
    background: var(--light-gray);
    border-radius: 6px;
    border-left: 3px solid var(--primary-color);
    flex-shrink: 0;
}

.control-section h3 {
    font-size: 0.9rem;
    margin-bottom: 10px;
    color: var(--text-dark);
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* 접기/펼치기 화살표 */
.control-section h3::after {
    content: '▼';
    font-size: 0.7rem;
    color: var(--primary-color);
    transition: transform 0.3s ease;
}

.control-section.collapsed h3 {
    margin-bottom: 0;
}

.control-section.collapsed h3::after {
    transform: rotate(-90deg);
}

/* 접혔을 때 제목 외 모든 내용 숨김 */
.control-section.collapsed > *:not(h3) {
    display: none !important;
}

/* 압축 예상 용량 */
.compress-estimate {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 10px;
    padding: 10px;
    background: white;
    border-radius: 6px;
    font-size: 0.8rem;
    color: var(--text-light);
}

.compress-estimate strong {
    color: var(--primary-color);
}

.compress-estimate strong.reduced {
    color: var(--success-color);
}

.compress-estimate strong.increased {
    color: var(--danger-color);
}

/* 컨트롤 그룹 */
.control-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 15px;
}

.control-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    color: var(--text-dark);
    font-weight: 500;
}

.control-group input[type="radio"] {
    cursor: pointer;
    accent-color: var(--primary-color);
}

/* 입력 그룹 */
.input-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 8px;
}

.input-group label {
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--text-dark);
}

.input-group input[type="text"],
.input-group input[type="number"] {
    padding: 6px 8px;
    border: 1px solid var(--border-gray);
    border-radius: 4px;
    font-size: 0.85rem;
    transition: all 0.3s ease;
}

.input-group input[type="text"]:focus,
.input-group input[type="number"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.1);
}

/* 체크박스 */
.checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    color: var(--text-dark);
    font-weight: 500;
    margin-bottom: 12px;
}

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

/* Range 입력 */
.range-input {
    display: flex;
    align-items: center;
    gap: 12px;
}

.range-input input[type="range"] {
    flex: 1;
    cursor: pointer;
    accent-color: var(--primary-color);
}

#qualityValue {
    min-width: 45px;
    text-align: right;
    font-weight: 600;
    color: var(--primary-color);
}

/* 버튼 */
.btn-primary {
    width: 100%;
    padding: 14px 24px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: var(--shadow);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 20px 25px -5px rgba(99, 102, 241, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* 작은 텍스트 */
small {
    display: block;
    color: var(--text-light);
    font-size: 0.85rem;
    margin-top: 8px;
}

/* Footer */
footer {
    text-align: center;
    color: white;
    padding: 8px;
    opacity: 0.85;
    font-size: 0.85rem;
    flex-shrink: 0;
}

footer p {
    margin: 0;
}

/* 반응형 */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }

    header {
        padding: 30px 15px;
    }

    header h1 {
        font-size: 1.8rem;
    }

    .upload-box {
        padding: 30px 20px;
    }

    .editor-container {
        gap: 20px;
    }

    .control-panel {
        max-height: none;
    }

    .preview-box {
        min-height: 300px;
    }
}
