/* ===== 전역 스타일 ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans KR', sans-serif;
    background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
    min-height: 100vh;
    color: #333;
}

/* ===== 헤더 영역 ===== */
.header {
    background: rgba(255, 255, 255, 0.95);
    padding: 15px 20px;
    text-align: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.header h1 {
    font-size: 24px;
    color: #c0392b;
    margin-bottom: 8px;
}

.header h1 .subtitle {
    font-size: 12px;
    font-weight: normal;
    color: #888;
    margin-left: 8px;
}

.header .description {
    font-size: 14px;
    color: #666;
}

/* ===== 메인 컨테이너 ===== */
.main-container {
    display: flex;
    gap: 20px;
    padding: 20px;
    max-width: 1400px;
    margin: 0 auto;
}

/* ===== 도구 패널 ===== */
.tool-panel {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 12px;
    padding: 15px;
    width: 220px;
    flex-shrink: 0;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    max-height: calc(100vh - 140px);
    overflow-y: auto;
}

.tool-section {
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 1px solid #e0e0e0;
}

.tool-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.tool-section h3 {
    font-size: 14px;
    color: #555;
    margin-bottom: 10px;
}

/* ===== 버튼 스타일 ===== */
.tool-btn {
    width: 100%;
    padding: 10px 12px;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    background: #e8e8e8;
    color: #333;
    margin-bottom: 6px;
}

.tool-btn:hover {
    background: #d0d0d0;
    transform: translateY(-1px);
}

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

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

.primary-btn {
    background: #4a90e2;
    color: white;
}

.primary-btn:hover {
    background: #357abd;
}

.success-btn {
    background: #27ae60;
    color: white;
}

.success-btn:hover {
    background: #219a52;
}

.warning-btn {
    background: #e74c3c;
    color: white;
}

.warning-btn:hover {
    background: #c0392b;
}

.split-btn.active,
.tool-select.active {
    background: #4a90e2;
    color: white;
}

.split-btn {
    font-size: 11px;
    padding: 8px 10px;
}

/* ===== 대회 저장 버튼 ===== */
.contest-save-btn {
    background: #e74c3c;
    color: white;
    font-weight: bold;
    animation: pulse 2s infinite;
}

.contest-save-btn:hover {
    background: #c0392b;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.4); }
    70% { box-shadow: 0 0 0 6px rgba(231, 76, 60, 0); }
    100% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0); }
}

/* ===== 학생 정보 입력 ===== */
.student-info-section {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 10px;
    padding: 10px;
    background: #fff5f5;
    border-radius: 8px;
    border: 2px solid #e74c3c;
}

.student-info-section input {
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 12px;
}

.student-info-section textarea {
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 12px;
    resize: none;
    font-family: inherit;
}

.student-info-section input:focus,
.student-info-section textarea:focus {
    outline: none;
    border-color: #e74c3c;
}

.student-info-section input::placeholder,
.student-info-section textarea::placeholder {
    color: #999;
}

.char-count {
    font-size: 11px;
    color: #888;
    text-align: right;
    margin-top: -2px;
}

/* ===== 도구 그룹 ===== */
.tool-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.brush-slider-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#brushSizeSlider {
    width: 100%;
    height: 8px;
    border-radius: 4px;
    background: #ddd;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

#brushSizeSlider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #e74c3c;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

#brushSizeSlider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #e74c3c;
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.brush-size-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-size: 14px;
    font-weight: bold;
    color: #555;
}

.brush-preview {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.brush-preview::after {
    content: '';
    display: block;
    border-radius: 50%;
    background: #e74c3c;
}

/* ===== 색상 팔레트 ===== */
.color-palette {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 5px;
    margin-bottom: 10px;
}

.color-swatch {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 4px;
    cursor: pointer;
    border: 2px solid #ddd;
    transition: transform 0.2s ease;
}

.color-swatch:hover {
    transform: scale(1.15);
    z-index: 10;
}

.color-swatch.active {
    border-color: #333;
    box-shadow: 0 0 0 2px white, 0 0 0 4px #333;
}

.custom-picker-wrapper {
    margin-bottom: 10px;
}

.custom-picker-wrapper .tool-btn {
    margin-bottom: 0;
}

.current-color-display {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: #555;
}

#currentColorBox {
    width: 30px;
    height: 20px;
    border-radius: 4px;
    border: 2px solid #333;
    background: #000000;
}

/* ===== 커스텀 색상 선택기 모달 ===== */
.color-picker-modal {
    max-width: 380px;
}

.color-picker-container {
    display: flex;
    gap: 15px;
    margin-bottom: 15px;
    justify-content: center;
}

.color-picker-main {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

#colorGradient {
    display: block;
    cursor: crosshair;
}

.picker-cursor {
    position: absolute;
    width: 16px;
    height: 16px;
    border: 3px solid white;
    border-radius: 50%;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3), 0 2px 4px rgba(0, 0, 0, 0.3);
    pointer-events: none;
    transform: translate(-50%, -50%);
}

.hue-slider-container {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

#hueSlider {
    display: block;
    cursor: pointer;
}

.hue-cursor {
    position: absolute;
    left: -3px;
    width: 36px;
    height: 8px;
    background: transparent;
    border: 3px solid white;
    border-radius: 4px;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3), 0 2px 4px rgba(0, 0, 0, 0.3);
    pointer-events: none;
    transform: translateY(-50%);
}

.color-preview-row {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 15px;
    justify-content: center;
}

.color-preview-box {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    border: 3px solid #333;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.rgb-inputs {
    display: flex;
    gap: 10px;
}

.rgb-input-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.rgb-input-group input {
    width: 55px;
    padding: 8px;
    border: 2px solid #ddd;
    border-radius: 6px;
    text-align: center;
    font-size: 14px;
    font-weight: bold;
}

.rgb-input-group input:focus {
    outline: none;
    border-color: #e74c3c;
}

.rgb-input-group label {
    font-size: 12px;
    font-weight: bold;
    color: #666;
}

/* ===== Undo/Redo 그룹 ===== */
.undo-redo-group {
    display: flex;
    gap: 6px;
}

.undo-redo-group .tool-btn {
    flex: 1;
    margin-bottom: 0;
}

/* ===== 캔버스 영역 ===== */
.canvas-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.canvas-wrapper {
    position: relative;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    transition: transform 0.1s ease;
    touch-action: none;
}

#mainCanvas {
    display: block;
    cursor: crosshair;
}

#gridCanvas {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

#gridCanvas.visible {
    opacity: 1;
}

.split-indicator {
    position: absolute;
    pointer-events: none;
    transition: all 0.3s ease;
    border: 4px dashed #ff6b6b;
    background: transparent;
    box-sizing: border-box;
    opacity: 0;
}

.split-indicator.visible {
    opacity: 1;
}

.split-indicator::after {
    content: 'AI 영역 (수정 불가)';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 107, 107, 0.9);
    color: white;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: bold;
    white-space: nowrap;
}

.canvas-info {
    margin-top: 10px;
    display: flex;
    gap: 20px;
    font-size: 12px;
    color: white;
    background: rgba(0, 0, 0, 0.3);
    padding: 8px 15px;
    border-radius: 20px;
}

/* ===== 모달 스타일 ===== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    padding: 25px;
    border-radius: 12px;
    text-align: center;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.modal-content h3 {
    margin-bottom: 15px;
    color: #333;
}

.modal-content p {
    margin-bottom: 20px;
    color: #666;
}

.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.modal-buttons .tool-btn {
    width: auto;
    padding: 10px 20px;
}

/* ===== 반응형 디자인 ===== */
@media (max-width: 900px) {
    .main-container {
        flex-direction: column;
        padding: 10px;
    }

    .tool-panel {
        width: 100%;
        max-height: none;
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
        gap: 10px;
    }

    .tool-section {
        margin-bottom: 0;
        padding-bottom: 10px;
    }

    .header h1 {
        font-size: 20px;
    }

    .header .description {
        font-size: 12px;
    }
}

@media (max-width: 600px) {
    .tool-panel {
        grid-template-columns: 1fr 1fr;
    }

    .canvas-wrapper {
        width: 100%;
    }

    #mainCanvas {
        width: 100% !important;
        height: auto !important;
    }

    .header h1 {
        font-size: 18px;
    }
}

/* ===== 스크롤바 스타일 ===== */
.tool-panel::-webkit-scrollbar {
    width: 6px;
}

.tool-panel::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.tool-panel::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 3px;
}

.tool-panel::-webkit-scrollbar-thumb:hover {
    background: #555;
}
