/* ==========================================
   style.css - 나의 메모장 PWA 스타일시트
   ========================================== */

/* ─── 폰트 정의 ─── */
@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-display: swap;
}

@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: 'Diary';
    src: url('https://gcore.jsdelivr.net/gh/projectnoonnu/noonfonts_220508@1.0/EarlyFontDiary.woff2') format('woff2');
    font-weight: normal;
    font-display: swap;
}

@font-face {
    font-family: 'SchoolSafetyPictureDiary';
    src: url('https://cdn.jsdelivr.net/gh/projectnoonnu/2408-5@1.0/HakgyoansimGeurimilgiTTF-R.woff2') format('woff2');
    font-weight: normal;
    font-display: swap;
}

@font-face {
    font-family: 'PeopleFirstTtobaks';
    src: url('https://cdn.jsdelivr.net/gh/projectnoonnu/2406-2@1.0/PeoplefirstNeatLoudTTF.woff2') format('woff2');
    font-weight: normal;
    font-display: swap;
}

@font-face {
    font-family: 'KccDodamdodam';
    src: url('https://cdn.jsdelivr.net/gh/projectnoonnu/noonfonts_2302@1.0/KCC-DodamdodamR.woff2') format('woff2');
    font-weight: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Cafe24Dongdong';
    src: url('https://cdn.jsdelivr.net/gh/projectnoonnu/noonfonts_twelve@1.1/Cafe24Dongdong.woff') format('woff');
    font-weight: normal;
    font-display: swap;
}


/* ─── CSS 변수 (디자인 토큰) ─── */
:root {
    --primary: #f4a7b9;
    /* 메인 핑크 */
    --primary-dark: #e07a95;
    /* 진한 핑크 (호버) */
    --secondary: #c5a3d6;
    /* 보조 퍼플 */
    --bg: #fdf6f9;
    /* 앱 배경 */
    --surface: #ffffff;
    /* 카드 배경 */
    --text: #4a3f45;
    /* 기본 텍스트 */
    --text-light: #9e8a93;
    /* 보조 텍스트 */
    --border: #f0e4ea;
    /* 테두리 */
    --radius: 14px;
    --shadow: 0 4px 16px rgba(200, 120, 150, 0.12);
    --font-main: 'SchoolSafetyHalfMoon', sans-serif;
    --glass: rgba(255, 255, 255, 0.7);
}

/* ─── 다크 모드 (Pastel Dark) ─── */
[data-theme='dark'] {
    --bg: #2d262b;
    --surface: #3d333a;
    --text: #f5eff2;
    --text-light: #b8a9b0;
    --border: #4a3f45;
    --shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    --glass: rgba(61, 51, 58, 0.8);
}


/* ─── 기본 초기화 ─── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    /* 모바일에서 글자 크기 자동 확대 방지 */
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg);
    color: var(--text);
    min-height: 100vh;
    padding-bottom: 30px;
}

/* 모든 폼 요소에 폰트 강제 상속 */
input,
select,
textarea,
button {
    font-family: inherit !important;
    font-size: 1rem;
}


/* ─── 헤더 & 내비게이션 ─── */
header {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    padding: 16px 20px 12px;
    text-align: center;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 10px rgba(200, 120, 150, 0.25);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

#theme-toggle {
    position: absolute;
    top: 14px;
    right: 16px;
    background: rgba(255, 255, 255, 0.25);
    border: none;
    color: white;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

#theme-toggle:hover {
    background: rgba(255, 255, 255, 0.4);
}

header h1 {
    font-size: 1.4rem;
    font-weight: normal;
    letter-spacing: 0.05em;
    margin-bottom: 10px;
}

nav {
    display: flex;
    justify-content: center;
    gap: 8px;
}

nav button {
    background: rgba(255, 255, 255, 0.22);
    border: 1.5px solid rgba(255, 255, 255, 0.5);
    color: white;
    padding: 6px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.88rem;
    transition: background 0.2s, transform 0.1s;
    box-shadow: none;
}

nav button:hover {
    background: rgba(255, 255, 255, 0.38);
}

nav button.active {
    background: rgba(255, 255, 255, 0.55);
    color: var(--primary-dark);
    font-weight: bold;
}


/* ─── 메인 레이아웃 ─── */
main {
    padding: 20px 16px;
    max-width: 640px;
    margin: 0 auto;
}

/* 섹션 헤더 (제목 + 정렬 버튼 한 행) */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 8px;
}

.section-header h2 {
    font-size: 1.2rem;
    color: var(--text);
    font-weight: normal;
}


/* ─── 정렬 컨트롤 ─── */
.sort-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    color: var(--text-light);
}

.sort-btn {
    padding: 4px 12px !important;
    border-radius: 20px !important;
    font-size: 0.82rem !important;
    border: 1.5px solid var(--border) !important;
    background: var(--surface) !important;
    color: var(--text-light) !important;
    cursor: pointer;
    transition: all 0.2s;
}

.sort-btn.active {
    background: var(--primary) !important;
    color: white !important;
    border-color: var(--primary) !important;
}


/* ─── 폼 컴포넌트 ─── */
.form-group {
    margin-bottom: 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 0.9rem;
    color: var(--text-light);
}

/* 가로 배치 폼 행 (폰트 + 색상 나란히) */
.form-row {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    margin-bottom: 14px;
}

.flex-1 {
    flex: 1;
}

.form-group input[type="text"],
.form-group input[type="date"],
.form-group select {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    outline: none;
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus {
    border-color: var(--primary);
}

/* 색상 선택기 */
input[type="color"] {
    width: 48px;
    height: 42px;
    padding: 2px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    background: var(--surface);
}


/* ─── 배경 선택 팔레트 ─── */
.bg-palette {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 0 4px;
}

/* 배경 선택 썸네일 버튼 */
.bg-thumb {
    width: 52px;
    height: 52px;
    border-radius: 10px;
    border: 2.5px solid transparent;
    background-size: cover;
    background-position: center;
    cursor: pointer;
    transition: transform 0.15s, border-color 0.15s;
    box-shadow: var(--shadow);
}

.bg-thumb:hover {
    transform: scale(1.08);
}

/* 선택된 배경 강조 */
.bg-thumb.selected {
    border-color: var(--primary-dark);
    transform: scale(1.1);
    box-shadow: 0 0 0 3px rgba(244, 167, 185, 0.45);
}


/* ─── 메모 작성 영역 (배경 이미지 + 글 영역) ─── */
.memo-wrapper {
    margin-bottom: 16px;
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

/* 배경 이미지가 적용될 컨테이너 */
.memo-bg-area {
    position: relative;
    width: 100%;
    /* aspect-ratio로 이미지 비율 유지 (세로형 메모지) */
    aspect-ratio: 3 / 4;
    background-color: #f5f0eb;
    /* 배경 이미지 없을 때 기본 색 */
    background-size: 100% 100%;
    background-position: center;
    border-radius: var(--radius);
    transition: background-image 0.3s ease;
}

/* 실제 글씨가 써지는 구역 (JS로 top/left/width/height 조정됨) */
.text-zone {
    position: absolute;
    /* 기본값 (배경 미선택 시 전체 영역) */
    top: 10%;
    left: 10%;
    width: 80%;
    height: 78%;
    overflow-y: auto;
    padding: 4px;
    /* 배경이 복잡한 경우 가독성 보조 (JS에서 opacity 조절 가능) */
}


/* ─── ToDo 아이템 ─── */
.todo-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    background: rgba(255, 255, 255, 0.55);
    border-radius: 8px;
    padding: 6px 8px;
    backdrop-filter: blur(2px);
}

/* 체크박스 커스텀 */
.todo-check {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
    cursor: pointer;
    flex-shrink: 0;
}

/* 할 일 텍스트 입력 */
.todo-text {
    border: none !important;
    background: transparent !important;
    width: 100%;
    font-family: inherit !important;
    font-size: inherit;
    color: inherit;
    outline: none;
    padding: 0;
}

/* 세부 목표 추가 버튼 */
#add-todo-btn {
    margin-top: 8px;
    padding: 5px 12px !important;
    font-size: 0.85rem !important;
    border-radius: 20px !important;
    border: 1.5px dashed var(--primary) !important;
    background: rgba(255, 255, 255, 0.6) !important;
    color: var(--primary-dark) !important;
    cursor: pointer;
    transition: background 0.2s;
}

#add-todo-btn:hover {
    background: rgba(255, 255, 255, 0.85) !important;
}


/* ─── 저장/취소 버튼 ─── */
.action-buttons {
    display: flex;
    gap: 10px;
    margin-top: 4px;
}

.btn-save {
    flex: 1;
    padding: 12px !important;
    background: linear-gradient(135deg, var(--primary), var(--secondary)) !important;
    color: white !important;
    border: none !important;
    border-radius: var(--radius) !important;
    font-size: 1rem !important;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.1s;
    box-shadow: var(--shadow);
}

.btn-save:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

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

.btn-cancel {
    padding: 12px 20px !important;
    background: var(--surface) !important;
    color: var(--text-light) !important;
    border: 1.5px solid var(--border) !important;
    border-radius: var(--radius) !important;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-cancel:hover {
    background: var(--border) !important;
}


/* ─── 홈 화면 메모 카드 목록 ─── */
#memo-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
    gap: 14px;
}

/* 개별 메모 카드 (홈 화면) */
.memo-card {
    position: relative;
    border-radius: var(--radius);
    overflow: hidden;
    aspect-ratio: 3 / 4;
    background-size: 100% 100%;
    background-position: center;
    background-color: var(--surface);
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    border: 2px solid var(--border);
}

.memo-card:hover {
    transform: translateY(-4px) scale(1.02);
    box-shadow: 0 8px 24px rgba(200, 120, 150, 0.22);
}

/* 모든 체크박스가 완료된 카드: 회색 필터 적용 */
.memo-card.card-done {
    filter: grayscale(80%) brightness(0.92);
    opacity: 0.75;
    transition: filter 0.3s, opacity 0.3s, transform 0.2s;
}

/* 완료 카드 호버 시 원래 색상 복원 */
.memo-card.card-done:hover {
    filter: grayscale(0%) brightness(1);
    opacity: 1;
    transform: translateY(-4px) scale(1.02);
    box-shadow: 0 8px 24px rgba(200, 120, 150, 0.22);
}

/* 고정(Pin) 배지 */
.pin-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    background: var(--primary);
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    z-index: 10;
}

/* 완료 뱃지 */
.done-badge {
    display: inline-block;
    font-size: 0.68rem;
    background: rgba(100, 180, 100, 0.85);
    color: white;
    border-radius: 8px;
    padding: 1px 7px;
    margin-bottom: 4px;
    letter-spacing: 0.03em;
}

/* ─── 퀵 액션 메뉴 (우클릭/롱프레스) ─── */
.context-menu {
    position: fixed;
    background: var(--surface);
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
    border: 1px solid var(--border);
    padding: 6px;
    z-index: 1000;
    min-width: 140px;
    display: none;
    animation: menuIn 0.15s ease-out;
}

@keyframes menuIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.context-menu button {
    display: block;
    width: 100%;
    padding: 10px 14px;
    text-align: left;
    background: none;
    border: none;
    color: var(--text);
    font-size: 0.9rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
}

.context-menu button:hover {
    background: var(--border);
}

.context-menu button.danger {
    color: #e07a7a;
}

/* 카드 중앙 제목/날짜 영역 (홈 화면) */
.memo-card-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 15px;
    background: transparent;
}

.memo-card-title {
    font-size: 1.05rem;
    font-weight: bold;
    color: var(--text);
    width: 100%;
    line-height: 1.3;
    /* 긴 제목 처리 */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 8px;
}

.memo-card-deadline {
    font-size: 0.8rem;
    color: var(--text-light);
    margin-top: 4px;
}

/* 빈 상태 안내 */
#empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-light);
}

#empty-state p {
    font-size: 1.1rem;
    margin-bottom: 16px;
}

#empty-state button {
    padding: 10px 24px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.95rem;
}


/* ─── 검색 화면 ─── */
#search-input {
    width: 100%;
    padding: 12px 16px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    outline: none;
    font-size: 1rem;
    transition: border-color 0.2s;
    margin-bottom: 16px;
}

#search-input:focus {
    border-color: var(--primary);
}

/* 검색 결과 카드 */
.search-result-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
    border: 1.5px solid var(--border);
    cursor: pointer;
    transition: transform 0.15s;
}

.search-result-card:hover {
    transform: translateY(-2px);
}

.search-result-title {
    font-size: 1rem;
    font-weight: bold;
    margin-bottom: 4px;
}

.search-result-todos {
    font-size: 0.85rem;
    color: var(--text-light);
    line-height: 1.5;
}

/* 검색어 강조 표시 */
mark {
    background: rgba(244, 167, 185, 0.4);
    color: inherit;
    border-radius: 3px;
}


/* ─── 상세 보기 모달 ─── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(74, 63, 69, 0.45);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-content {
    background: var(--surface);
    border-radius: 20px;
    width: 100%;
    max-width: 480px;
    max-height: 85vh;
    overflow-y: auto;
    padding: 24px;
    position: relative;
    box-shadow: 0 12px 40px rgba(200, 120, 150, 0.25);
    animation: modalIn 0.25s ease;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(10px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-close-btn {
    position: absolute;
    top: 14px;
    right: 16px;
    background: var(--border) !important;
    border: none !important;
    border-radius: 50% !important;
    width: 30px;
    height: 30px;
    padding: 0 !important;
    font-size: 0.9rem !important;
    cursor: pointer;
    color: var(--text-light) !important;
    line-height: 30px;
    text-align: center;
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.btn-edit {
    flex: 1;
    padding: 10px !important;
    background: var(--primary) !important;
    color: white !important;
    border: none !important;
    border-radius: var(--radius) !important;
    cursor: pointer;
}

.btn-delete {
    padding: 10px 16px !important;
    background: var(--surface) !important;
    color: #e07a7a !important;
    border: 1.5px solid #f0c0c0 !important;
    border-radius: var(--radius) !important;
    cursor: pointer;
}

/* 모달 내 배경 미리보기 */
.modal-bg-preview {
    width: 100%;
    aspect-ratio: 3 / 4;
    border-radius: var(--radius);
    background-size: 100% 100%;
    background-position: center;
    position: relative;
    margin-bottom: 16px;
    overflow: hidden;
}

.modal-text-zone {
    position: absolute;
    overflow-y: auto;
    padding: 4px;
}

/* 모달 내 ToDo 아이템 */
.modal-todo-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 8px;
    padding: 5px 8px;
}

.modal-todo-item input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
    flex-shrink: 0;
}

.modal-todo-text {
    font-size: 0.9rem;
}

.modal-todo-text.done {
    text-decoration: line-through;
    opacity: 0.5;
}

/* 모달 메타 정보 */
.modal-meta {
    font-size: 0.8rem;
    color: var(--text-light);
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
}


/* ─── 반응형 ─── */
@media (min-width: 480px) {
    #memo-list {
        grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    }
}

@media (max-width: 360px) {
    nav button {
        padding: 5px 10px;
        font-size: 0.8rem;
    }

    header h1 {
        font-size: 1.2rem;
    }
}