/* 폰트 정의 목록 */
@font-face {
    font-family: 'OmuDaye';
    src: url('https://cdn.jsdelivr.net/gh/projectnoonnu/noonfonts_2304-01@1.0/omyu_pretty.woff2') format('woff2');
    font-weight: normal;
    font-display: swap;
}
@font-face {
    font-family: 'HsGlidingSerif';
    src: url('https://cdn.jsdelivr.net/gh/projectnoonnu/2604-1@1.0/HSHwalkongSerif-Regular.woff2') format('woff2');
    font-weight: normal;
    font-display: swap;
}
@font-face {
    font-family: 'Okticon';
    src: url('https://cdn.jsdelivr.net/gh/projectnoonnu/2408@1.0/Ownglyph_okticon-Lt.woff2') format('woff2');
    font-weight: 300;
    font-display: swap;
}
@font-face {
    font-family: 'Okticon';
    src: url('https://cdn.jsdelivr.net/gh/projectnoonnu/2408@1.0/Ownglyph_okticon-Rg.woff2') format('woff2');
    font-weight: 400;
    font-display: swap;
}
@font-face {
    font-family: 'Okticon';
    src: url('https://cdn.jsdelivr.net/gh/projectnoonnu/2408@1.0/Ownglyph_okticon-Bd.woff2') format('woff2');
    font-weight: 700;
    font-display: swap;
}
@font-face {
    font-family: 'KyoboHandwriting2024SeoWooPark';
    src: url('https://cdn.jsdelivr.net/gh/projectnoonnu/2507-1@1.0/KyoboHandwriting2024psw.woff2') format('woff2');
    font-weight: normal;
    font-display: swap;
}
@font-face {
    font-family: 'SchoolSafetyHalfMoon';
    src: url('https://cdn.jsdelivr.net/gh/projectnoonnu/2508-2@1.0/HakgyoansimBandalL.woff2') format('woff2');
    font-weight: normal;
    font-style: normal;
}
@font-face {
    font-family: 'SchoolSafetyRelay';
    src: url('https://cdn.jsdelivr.net/gh/projectnoonnu/2510-1@1.0/HakgyoansimYieodalligiL.woff2') format('woff2');
    font-weight: normal;
    font-display: swap;
}
@font-face {
    font-family: 'Ridibatang';
    src: url('https://cdn.jsdelivr.net/gh/projectnoonnu/noonfonts_twelve@1.0/RIDIBatang.woff') format('woff');
    font-weight: normal;
    font-display: swap;
}

/* CSS 변수 선언 */
:root {
    --primary-color: #fdfdfd;
    --border-color: #b3cde0;
    --hover-color: #f0f7ff;
    --bg-color: #f4f6f8;
}

/* 기본 레이아웃 및 디자인 */
body { 
    /* 학교안심 반달 폰트를 메인으로 적용 */
    font-family: 'SchoolSafetyHalfMoon', sans-serif; 
    padding: 0; 
    background-color: var(--bg-color);
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

input, button, select, textarea {
    font-family: inherit;
}

#app-container {
    max-width: 600px;
    width: 100%;
    background: white;
    padding: 20px;
    border-radius: 16px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
    /* 모바일 환경 대응: 상하 균형을 맞춰 75~80% 높이를 점유하도록 플렉서블 뷰 지원 */
    min-height: 85vh;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: center; /* 내부 콘텐츠도 정중앙에 위치하게 함 */
    margin: 0 auto;
}

#monthly-section {
    display: flex;
    flex-direction: column;
    justify-content: center;
    flex: 1; /* 공간을 꽉 채우고 달력을 중앙에 둠 */
}

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

.month-nav {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
}

.nav-btn {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: #888;
    padding: 5px 10px;
}

.nav-btn:hover {
    color: #333;
}

h2 {
    margin: 0;
    font-size: 24px;
    color: #333;
}

#calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr)); /* 화면을 넘어가지 않고 남은 공간 안테에서만 수축/팽창 하도록 제한 */
    grid-auto-rows: 1fr; /* 모든 열(가로줄)이 동일한 비율의 최고 높이에 맞춰 일정하게 직사각형을 유지하도록 강제동기화 */
    gap: 4px; /* 핸드폰에서 가로로 너무 많은 여백을 차지하지 않도록 갭을 줄임 */
    align-content: start; /* 이 속성을 추가해 데스크탑과 모바일 양쪽에서 먼슬리 칸이 세로로 엿가락처럼 늘어나는 것을 방지 (항상 aspect-ratio 유지) */
    width: 100%;
    box-sizing: border-box;
}

.day-header {
    text-align: center;
    font-weight: bold;
    color: #888;
    padding-bottom: 10px;
}

.backup-tools {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    right: 0;
    display: flex;
    gap: 10px;
}

.backup-tools button, .backup-tools label {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: #888;
    opacity: 0.7;
}

.backup-tools input[type="file"] {
    display: none;
}

.backup-tools button:hover, .backup-tools label:hover {
    opacity: 1;
}

/* 오늘 날짜 하이라이트 */
.today-highlight {
    background-color: #ff6b81 !important; /* 산뜻하고 돋보이는 코랄 레드 */
    color: white !important;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    justify-content: center;
    align-items: center;
    text-shadow: none !important; /* 흰색 글자 테두리 효과가 배경색과 섞여 뭉개지는 현상 완전 차단 */
    box-shadow: 0 2px 6px rgba(255, 107, 129, 0.5);
    z-index: 2;
}

.weekend-sun, .weekend-sat {
    color: #e74c3c !important;
}

/* 점선 칸 디자인 설정. 달력의 각 일을 담당함. */
.date-cell {
    aspect-ratio: 4 / 5; /* 텅 빈 칸일 때도 무조건 위아래가 더 긴 직사각형으로 자리잡게 유지 */
    border: 2px dashed var(--border-color); /* 파스텔 블루 점선 */
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    background: var(--primary-color);
    position: relative;
    padding: 2px;
    box-sizing: border-box;
    width: 100%;
    min-width: 0; /* 글자가 길어도 칸이 가로로 늘어나서 밀어내는 현상 방지 */
}

.date-cell:hover { background: var(--hover-color); }

.date-number {
    position: absolute;
    top: 4px;
    left: 4px;
    font-size: 14px;
    color: #555;
    z-index: 2; /* 이미지 위로 올라오게 설정 */
    font-weight: 900;
    /* 이미지 위에 겹쳤을 때 글자가 묻히지 않도록 선명한 흰색 외곽선(그림자) 효과 추가 */
    text-shadow: 
        -1.5px -1.5px 0 #fff,
         1.5px -1.5px 0 #fff,
        -1.5px  1.5px 0 #fff,
         1.5px  1.5px 0 #fff,
         0px 2px 2px rgba(0,0,0,0.1);
    margin: 0;
}

/* 우표 모양 사진 프레임 */
.stamp-photo {
    width: 100%;
    height: 100%;
    background-color: #eee;
    background-size: cover;
    background-position: center;
    border-radius: 2px;
    /* 가장자리 4면만 완벽하게 깎아주고 절대 안쪽으로 구멍이 침범하지 않도록 제어된 다중 마스크 (기본 버전/상세 창) */
    -webkit-mask: 
        linear-gradient(#000, #000) center/calc(100% - 9px) calc(100% - 9px) no-repeat,
        radial-gradient(circle, transparent 3px, #000 3.5px) left 0 top -5px / 10px 10px repeat-x,
        radial-gradient(circle, transparent 3px, #000 3.5px) left 0 bottom -5px / 10px 10px repeat-x,
        radial-gradient(circle, transparent 3px, #000 3.5px) left -5px top 0 / 10px 10px repeat-y,
        radial-gradient(circle, transparent 3px, #000 3.5px) right -5px top 0 / 10px 10px repeat-y;
    mask: 
        linear-gradient(#000, #000) center/calc(100% - 9px) calc(100% - 9px) no-repeat,
        radial-gradient(circle, transparent 3px, #000 3.5px) left 0 top -5px / 10px 10px repeat-x,
        radial-gradient(circle, transparent 3px, #000 3.5px) left 0 bottom -5px / 10px 10px repeat-x,
        radial-gradient(circle, transparent 3px, #000 3.5px) left -5px top 0 / 10px 10px repeat-y,
        radial-gradient(circle, transparent 3px, #000 3.5px) right -5px top 0 / 10px 10px repeat-y;
}

/* 달력 내 미니 우표 표시용 CSS */
.stamp-mini {
    position: relative;
    /* 글씨가 자리 차지하는 걸 없앴으므로, 우표 자체가 칸 전체(100%)를 꽉 채우도록 설정 */
    width: 100%;
    flex: 1; /* 칸의 상하좌우를 완벽히 덮음 */
    min-height: 0;
    /* 칸 자체의 비율(4:5)을 그대로 따라가므로 빈 공간이 전혀 생기지 않음 */
    aspect-ratio: auto;
    margin: 0;
    z-index: 1; /* 글자보다 뒤에 위치 */
    
    /* 쪼그만한 달력 버전에서는 구멍 펀칭도 작고 예쁘게 오밀조밀하게 다시 맞춰줍니다 */
    -webkit-mask: 
        linear-gradient(#000, #000) center/calc(100% - 6.5px) calc(100% - 6.5px) no-repeat,
        radial-gradient(circle, transparent 2px, #000 2.5px) left 0 top -3.5px / 7px 7px repeat-x,
        radial-gradient(circle, transparent 2px, #000 2.5px) left 0 bottom -3.5px / 7px 7px repeat-x,
        radial-gradient(circle, transparent 2px, #000 2.5px) left -3.5px top 0 / 7px 7px repeat-y,
        radial-gradient(circle, transparent 2px, #000 2.5px) right -3.5px top 0 / 7px 7px repeat-y;
    mask: 
        linear-gradient(#000, #000) center/calc(100% - 6.5px) calc(100% - 6.5px) no-repeat,
        radial-gradient(circle, transparent 2px, #000 2.5px) left 0 top -3.5px / 7px 7px repeat-x,
        radial-gradient(circle, transparent 2px, #000 2.5px) left 0 bottom -3.5px / 7px 7px repeat-x,
        radial-gradient(circle, transparent 2px, #000 2.5px) left -3.5px top 0 / 7px 7px repeat-y,
        radial-gradient(circle, transparent 2px, #000 2.5px) right -3.5px top 0 / 7px 7px repeat-y;
}

/* 주말 빨간색 CSS 처리 */
.weekend-text {
    color: #e74c3c !important;
}

/* 검색 돋보기 버튼용 */
.search-btn {
    width: 100%;
    height: 100%;
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 18px;
    color: #b3cde0;
    opacity: 0.6;
}
.search-btn:hover {
    opacity: 1;
}

/* 부드러운 화면 전환 효과 */
.fade-in {
    animation: fadeIn 0.4s ease forwards;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 작성 화면 내 컨테이너 표시 방식 */
.write-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 20px;
}

.write-container button {
    font-family: inherit;
    padding: 10px;
    border: none;
    border-radius: 8px;
    background-color: #eef2f5;
    cursor: pointer;
    font-size: 16px;
    transition: background 0.2s;
}

.write-container button:hover {
    background-color: #dfe7ed;
}

.write-container button.save-btn, .action-buttons button {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    font-weight: bold;
    margin-bottom: 8px;
    transition: all 0.2s;
}

.action-buttons {
    display: flex;
    flex-direction: column;
    margin-top: 20px;
}

.download-btn {
    background-color: #74b9ff !important;
    color: white !important;
}

.edit-btn {
    background-color: #b3cde0 !important;
    color: white !important;
}

.delete-btn {
    background-color: #ff7675 !important;
    color: white !important;
}

.write-container button.save-btn {
    background-color: #b3cde0;
    color: #fff;
    font-weight: bold;
}

.write-container button.save-btn:hover {
    background-color: #8dafc7;
}

.write-container button.delete-btn {
    color: #e74c3c;
    background-color: #fdf0f0;
}

.write-container button.delete-btn:hover {
    background-color: #fadada;
}

/* 작성화면의 이미지 뷰 컨테이너 */
#stamp-preview-container {
    width: 200px;
    height: 250px;
    margin: 0 auto;
    position: relative;
    padding: 10px;
    background: white;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    display: flex;
    justify-content: center;
    align-items: center;
}

textarea {
    font-family: inherit;
    padding: 15px;
    border: 1px solid #ddd;
    border-radius: 8px;
    resize: none;
    height: 100px;
    font-size: 16px;
}

.controls {
    display: flex;
    gap: 10px;
    align-items: center;
}

select, input[type="color"] {
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-family: inherit;
    font-size: 14px;
}

input[type="color"] {
    width: 40px;
    height: 38px;
    padding: 2px;
    cursor: pointer;
}

.back-btn {
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    padding: 0;
    color: #666;
    margin-bottom: 20px;
    text-align: left;
}
.back-btn:hover {
    color: #000;
}

/* 상세보기 뷰 디자인 */
.view-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 20px;
    align-items: center;
}

#view-stamp-container {
    width: 250px;
    height: 300px;
    margin: 0 auto;
    position: relative;
    padding: 10px;
    background: white;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    display: flex;
    justify-content: center;
    align-items: center;
}

.diary-text-display {
    width: 100%;
    min-height: 80px;
    padding: 15px;
    border-radius: 8px;
    background-color: #fff;
    border: 1px solid #efefef;
    white-space: pre-wrap;
    word-break: break-all;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
    font-size: 16px;
    box-sizing: border-box;
}

.action-buttons {
    display: flex;
    gap: 10px;
    width: 100%;
}

.action-buttons button {
    flex: 1;
    font-family: inherit;
    padding: 10px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    transition: background 0.2s;
}

.action-buttons .edit-btn {
    background-color: #eef2f5;
    color: #333;
}

.action-buttons .edit-btn:hover {
    background-color: #dfe7ed;
}

.action-buttons .delete-btn {
    color: #e74c3c;
    background-color: #fdf0f0;
}

.action-buttons .delete-btn:hover {
    background-color: #fadada;
}

/* 커스텀 파일 버튼 */
.custom-file-upload {
    display: inline-block;
    padding: 10px;
    border: none;
    border-radius: 8px;
    background-color: #eef2f5;
    cursor: pointer;
    font-size: 16px;
    transition: background 0.2s;
    text-align: center;
}
.custom-file-upload:hover {
    background-color: #dfe7ed;
}

/* 검색 모달창 디자인 */
.modal {
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background-color: #fff;
    padding: 20px;
    border-radius: 12px;
    width: 90%;
    max-width: 400px;
    position: relative;
    max-height: 80vh;
    overflow-y: auto;
}

.close-btn {
    position: absolute;
    right: 15px;
    top: 15px;
    font-size: 24px;
    cursor: pointer;
    color: #aaa;
}
.close-btn:hover { color: #000; }

.search-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    margin-top: 20px;
}
.search-controls input {
    flex: 1;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid #ddd;
}
.search-controls button {
    padding: 10px 15px;
    background-color: #b3cde0;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
}

.search-result-item {
    padding: 10px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
}
.search-result-item:hover {
    background-color: #f9f9f9;
}
.search-date {
    font-size: 12px;
    color: #888;
    margin-bottom: 5px;
}
.search-text {
    font-size: 14px;
}