/* CSS 변수를 이용한 파스텔톤 컬러 정의 및 공통 스타일 설정 */
:root {
    --bg-color: #f7f9fc;
    --card-bg: #ffffff;
    --border-color: #e2e8f0;
    
    /* 파스텔 컬러 톤 */
    --pastel-blue: #a8c8e4;
    --pastel-blue-hover: #91b5d6;
    --pastel-green: #aed9b2;
    --pastel-green-hover: #96c99c;
    --pastel-yellow: #fcebb6;
    --pastel-pink: #ffd3b6;
    --pastel-purple: #dcd3ff;
    
    /* 칠판 컬러 */
    --blackboard-color: #2e4f3f;
    --chalk-color: #fcfcfc;
    
    /* 기본 텍스트 및 효과 */
    --text-color: #2d3748;
    --text-muted: #718096;
    --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --radius-lg: 20px;
    --radius-md: 14px;
    --radius-sm: 8px;
    
    /* 폰트 */
    --font-main: 'Gowun Dodum', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-cute: var(--font-main);
}

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

body {
    font-family: var(--font-main);
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.5;
    height: 100vh;
    overflow: hidden;
}

/* 전체 앱 레이아웃 */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* 좌측 설정 패널 */
.sidebar {
    width: 360px;
    min-width: 360px;
    background-color: var(--card-bg);
    border-right: 2px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 24px;
    box-shadow: var(--shadow-sm);
    z-index: 10;
    overflow-y: auto;
}

.app-header {
    margin-bottom: 20px;
    text-align: center;
}

.app-header h1 {
    font-family: var(--font-cute);
    font-size: 2.2rem;
    color: #4a5568;
    margin-bottom: 4px;
}

.app-header .subtitle {
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* 학급 관리 영역 스타일 */
.class-management-section {
    background-color: #f7fafc;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px;
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.class-controls {
    display: flex;
    gap: 6px;
    width: 100%;
}

#class-selector {
    flex: 1;
    padding: 8px 12px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-family: var(--font-main);
    font-size: 0.95rem;
    outline: none;
    background-color: #ffffff;
    color: #2d3748;
    cursor: pointer;
    transition: border-color 0.2s;
}

#class-selector:focus {
    border-color: var(--pastel-blue);
}

.btn-class-action {
    background: none;
    border: 2px solid var(--border-color);
    background-color: #ffffff;
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-class-action:hover {
    background-color: #edf2f7;
    border-color: #cbd5e0;
}

.btn-class-action:active {
    transform: scale(0.93);
}

.config-section {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 24px;
}

/* 입력 그룹 스타일 */
.input-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.group-title {
    font-family: var(--font-cute);
    font-size: 1.3rem;
    font-weight: bold;
    color: #4a5568;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.count-badge {
    font-size: 0.95rem;
    background-color: var(--pastel-blue);
    color: #2d3748;
    padding: 2px 10px;
    border-radius: 20px;
    font-weight: bold;
}

/* CSV 시트 업로드 영역 */
.sheet-upload-area {
    display: flex;
    gap: 6px;
    margin-bottom: 4px;
    width: 100%;
}

.btn-sheet-action {
    flex: 1.2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 4px;
    font-size: 0.78rem;
    font-weight: bold;
    border: 2px solid var(--border-color);
    background-color: #fafbfc;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
    color: #4a5568;
    text-align: center;
    user-select: none;
    white-space: nowrap;
    letter-spacing: -0.5px;
    overflow: hidden;
}

.btn-sheet-action:hover {
    background-color: #edf2f7;
    border-color: #cbd5e0;
}

.btn-sheet-action:active {
    transform: scale(0.97);
}

.btn-sheet-help {
    flex: 0.8;
    background-color: #f7fafc;
}

textarea {
    width: 100%;
    height: 100px;
    padding: 12px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-family: var(--font-main);
    font-size: 0.95rem;
    resize: none;
    outline: none;
    transition: border-color 0.2s;
    background-color: #fafbfc;
}

textarea:focus {
    border-color: var(--pastel-blue);
    background-color: #ffffff;
}

/* 행/열 그리드 설정 */
.grid-config {
    display: flex;
    gap: 12px;
}

.grid-config .input-group.half {
    flex: 1;
}

.grid-config label {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 600;
}

.grid-config input[type="number"] {
    width: 100%;
    padding: 10px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-family: var(--font-main);
    font-size: 1rem;
    outline: none;
    text-align: center;
    background-color: #fafbfc;
    transition: border-color 0.2s;
}

.grid-config input[type="number"]:focus {
    border-color: var(--pastel-blue);
    background-color: #ffffff;
}

.capacity-info {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-align: right;
    font-weight: bold;
}

/* 옵션 그룹 */
.options-group {
    border-top: 1px dashed var(--border-color);
    padding-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toggle-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.toggle-label {
    font-size: 0.9rem;
    font-weight: bold;
    color: #4a5568;
}

.toggle-switch {
    display: flex;
    background-color: #edf2f7;
    padding: 4px;
    border-radius: 30px;
    position: relative;
    border: 1px solid #e2e8f0;
}

.toggle-switch input[type="radio"] {
    display: none;
}

.toggle-switch .switch-btn {
    padding: 6px 12px;
    font-size: 0.85rem;
    font-weight: bold;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    color: #718096;
}

.toggle-switch input[type="radio"]:checked + .switch-btn {
    background-color: var(--pastel-blue);
    color: #2d3748;
    box-shadow: var(--shadow-sm);
}

/* 버튼 공통 스타일 */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 20px;
    border-radius: var(--radius-lg);
    font-family: var(--font-cute);
    font-size: 1.3rem;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    border: none;
    outline: none;
    user-select: none;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 8px;
}

.btn-primary {
    background-color: var(--pastel-blue);
    color: #2d3748;
    box-shadow: 0 4px 0 #89aac4;
}

.btn-primary:not(:disabled):hover {
    background-color: var(--pastel-blue-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #89aac4;
}

.btn-primary:not(:disabled):active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #89aac4;
}

.btn-secondary {
    background-color: var(--pastel-green);
    color: #2d3748;
    box-shadow: 0 4px 0 #92c096;
}

.btn-secondary:not(:disabled):hover {
    background-color: var(--pastel-green-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 0 #92c096;
}

.btn-secondary:not(:disabled):active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #92c096;
}

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

.sub-buttons .btn {
    flex: 1;
    font-size: 1.1rem;
    padding: 10px 14px;
}

.btn-outline {
    background-color: transparent;
    border: 2px solid var(--border-color);
    color: #4a5568;
}

.btn-outline:not(:disabled):hover {
    background-color: #f7fafc;
    border-color: #cbd5e0;
    transform: translateY(-1px);
}

/* 과거 기록 세션 */
.history-section {
    margin-top: auto;
    border-top: 2px dashed var(--border-color);
    padding-top: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 140px;
}

.history-list {
    list-style: none;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-right: 4px;
}

.history-list::-webkit-scrollbar {
    width: 6px;
}

.history-list::-webkit-scrollbar-thumb {
    background-color: #cbd5e0;
    border-radius: 3px;
}

.empty-history {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-align: center;
    padding: 16px 0;
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background-color: #f7fafc;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
}

.history-item:hover {
    background-color: #edf2f7;
    border-color: #cbd5e0;
}

.history-item-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    overflow: hidden;
}

.history-item-name {
    font-size: 0.9rem;
    font-weight: bold;
    color: #4a5568;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-item-date {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.btn-delete-history {
    background: none;
    border: none;
    color: #e53e3e;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
    margin-left: 8px;
}

.btn-delete-history:hover {
    background-color: #fed7d7;
}

/* 우측 메인 컨텐츠 */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 24px;
    background-color: #f0f4f8;
    overflow: hidden;
    transition: flex-direction 0.3s ease;
}

/* 선생님 시선일 때 칠판 하단 배치용 */
.main-content.view-teacher-mode {
    flex-direction: column-reverse;
}

/* 칠판 영역 */
.blackboard-container {
    display: flex;
    justify-content: center;
    margin-bottom: 24px;
    transition: margin 0.3s ease;
}

.view-teacher-mode .blackboard-container {
    margin-bottom: 0;
    margin-top: 24px;
}

.blackboard {
    width: 60%;
    max-width: 600px;
    height: 60px;
    background-color: var(--blackboard-color);
    border: 8px solid #b58d63;
    border-radius: 6px;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.blackboard::after {
    content: '';
    position: absolute;
    bottom: -12px;
    right: 30px;
    width: 40px;
    height: 6px;
    background-color: #edf2f7;
    border-radius: 2px;
    box-shadow: 1px 1px 2px rgba(0,0,0,0.1);
}

.chalk-text {
    font-family: var(--font-cute);
    font-size: 1.6rem;
    color: var(--chalk-color);
    letter-spacing: 4px;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.4);
}

/* 자리 배치 그리드 영역 */
.grid-outer-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    padding: 10px;
}

.seat-grid {
    display: grid;
    gap: 16px;
    width: 100%;
    height: 100%;
    max-width: 1200px;
    max-height: 700px;
    grid-template-columns: repeat(var(--cols, 6), minmax(0, 1fr));
    grid-template-rows: repeat(var(--rows, 5), minmax(0, 1fr));
}

/* 3D 카드 플립 레이아웃 */
.seat-card {
    background: transparent;
    border: none;
    box-shadow: none;
    perspective: 1000px;
    padding: 0;
    cursor: pointer;
    user-select: none;
    overflow: visible;
}

.seat-card:hover {
    transform: none;
}

/* 카드 실제 플립 컨테이너 */
.card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    transform-style: preserve-3d;
    box-shadow: var(--shadow-sm);
    border-radius: var(--radius-md);
    border: 3px solid transparent;
}

/* 뒤집기 액션 적용 클래스: card-inner가 Y축으로 180도 회전 */
.card-inner.flipped {
    transform: rotateY(180deg);
}

/* 앞면과 뒷면 공통 스타일 */
.card-front, .card-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: var(--radius-md);
    border: 2px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 12px;
}

/* 1. 카드의 뒷면 */
.card-back {
    background-color: #eaf2f8;
    color: #4a5568;
    transform: rotateY(0deg);
    z-index: 2;
}

.card-back-icon {
    font-size: 2.2rem;
    margin-top: 4px;
    animation: floating-subtle 3s ease-in-out infinite alternate;
}

/* 2. 카드의 앞면 */
.card-front {
    background-color: var(--card-bg);
    transform: rotateY(180deg);
    z-index: 1;
}

/* 앞면 폰트 크기 및 색상 */
.student-name {
    font-size: 1.8rem;
    font-weight: bold;
    color: #2d3748;
    word-break: keep-all;
    text-align: center;
    margin-top: 4px;
}

/* 빈자리 카드 앞면 스타일 */
.card-front.empty-seat {
    background-color: rgba(226, 232, 240, 0.4);
    border: 2px dashed #cbd5e0;
}

.card-front.empty-seat .student-name {
    color: #a0aec0;
    font-size: 1.4rem;
    font-weight: 500;
}

/* 파스텔톤 카드 앞면 배경 무작위 포인트 라인 */
.seat-card:nth-child(5n+1) .card-front.student-active { border-top: 6px solid var(--pastel-blue); }
.seat-card:nth-child(5n+2) .card-front.student-active { border-top: 6px solid var(--pastel-green); }
.seat-card:nth-child(5n+3) .card-front.student-active { border-top: 6px solid var(--pastel-yellow); }
.seat-card:nth-child(5n+4) .card-front.student-active { border-top: 6px solid var(--pastel-pink); }
.seat-card:nth-child(5n+5) .card-front.student-active { border-top: 6px solid var(--pastel-purple); }

/* 3. 비밀 지정석 교사 식별용 표식 (Dot) */
.fixed-dot {
    position: absolute;
    bottom: 8px;
    right: 8px;
    width: 3px;
    height: 3px;
    background-color: rgba(113, 128, 150, 0.22);
    border-radius: 50%;
    pointer-events: none;
    z-index: 5;
}

/* 4. 개별 자리 맞바꿈 시 첫 번째 클릭된 카드 강조 스타일 */
.seat-card.selected .card-inner {
    border: 3px solid #4a90e2;
    animation: selected-pulse 0.8s infinite alternate;
}

@keyframes selected-pulse {
    0% {
        transform: translateY(-4px) scale(1.03);
        box-shadow: 0 10px 20px rgba(74, 144, 226, 0.35);
    }
    100% {
        transform: translateY(-1px) scale(0.98);
        box-shadow: 0 4px 6px rgba(74, 144, 226, 0.15);
    }
}

/* 귀여운 둥둥 뜨는 애니메이션 */
@keyframes floating-subtle {
    0% { transform: translateY(0); }
    100% { transform: translateY(-4px); }
}

/* --- 모달 오버레이 --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-overlay.active {
    display: flex;
}

/* 모달 콘텐츠 */
.modal {
    background-color: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 30px;
    width: 400px;
    max-width: 90%;
    box-shadow: var(--shadow-lg);
    border: 3px solid var(--pastel-blue);
    display: flex;
    flex-direction: column;
    gap: 16px;
    animation: modal-pop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modal-pop {
    from {
        transform: scale(0.8);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

.modal h2 {
    font-family: var(--font-cute);
    font-size: 1.8rem;
    color: #2d3748;
}

.modal p {
    font-size: 0.9rem;
    color: var(--text-muted);
    line-height: 1.6;
}

.modal input[type="text"] {
    width: 100%;
    padding: 12px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    font-family: var(--font-main);
    font-size: 1rem;
    outline: none;
}

.modal input[type="text"]:focus {
    border-color: var(--pastel-blue);
}

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

.modal-buttons .btn {
    font-size: 1.1rem;
    padding: 8px 16px;
}

/* 반응형 모바일 또는 화면 비율 조절 */
@media (max-height: 800px) {
    .student-name {
        font-size: 1.4rem;
    }
    .seat-card {
        padding: 0;
    }
}

@media (max-width: 1024px) {
    .app-container {
        flex-direction: column;
        overflow-y: auto;
    }
    .sidebar {
        width: 100%;
        min-width: 100%;
        height: auto;
        overflow-y: visible;
        border-right: none;
        border-bottom: 2px solid var(--border-color);
    }
    .main-content {
        height: auto;
        min-height: 600px;
    }
    .seat-grid {
        max-height: none;
    }
}
