/* ── 책상 & 노트 ─────────────────────────────── */
* { box-sizing: border-box; margin: 0; padding: 0; }

/* 폰 가로/세로 전환 시 글자가 임의로 커지지 않게 */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

/* 더블탭 확대 방지 (탭 반응도 빨라짐) */
body, button, input { touch-action: manipulation; }

:root {
  --paper: #fefdf9;
  --grid: rgba(140, 130, 100, 0.055);
  --ink: #2b2c30;
  --ink-soft: #55565c;
  --hl-yellow: rgba(173, 203, 227, 0.55); /* 파스텔 블루 */
  --hl-green: rgba(207, 198, 227, 0.55); /* 파스텔 라벤더 */
  --line: 26px;
}

body {
  background: #e7e5e1;
  background-image: radial-gradient(circle at 30% 20%, #efedea 0%, #e2e0db 70%);
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 34px 16px 60px;
  font-family: 'Gowun Dodum', sans-serif;
  color: var(--ink);
}

.desk { width: 100%; max-width: 1060px; }

.notebook {
  display: flex;
  background: var(--paper);
  border-radius: 6px 10px 10px 6px;
  box-shadow:
    0 18px 40px rgba(60, 55, 40, 0.35),
    0 4px 10px rgba(60, 55, 40, 0.2);
  position: relative;
  min-height: 640px;
}

/* 페이지 밑에 겹친 종이 느낌 */
.notebook::after {
  content: '';
  position: absolute;
  left: 4px; right: 4px; bottom: -5px;
  height: 10px;
  background: #f8f5ec;
  border-radius: 0 0 10px 10px;
  box-shadow: 0 3px 6px rgba(60,55,40,.25);
  z-index: -1;
}

.page {
  flex: 1;
  padding: 30px 34px 26px;
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: var(--line) var(--line);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.spine {
  width: 26px;
  background:
    linear-gradient(90deg,
      rgba(0,0,0,0.10) 0%, rgba(0,0,0,0.02) 30%,
      rgba(0,0,0,0.16) 50%,
      rgba(0,0,0,0.02) 70%, rgba(0,0,0,0.10) 100%);
}

/* ── 형광펜 ─────────────────────────────────── */
.hl {
  background: linear-gradient(100deg,
    transparent 0%, var(--hl-yellow) 4%,
    var(--hl-yellow) 96%, transparent 100%);
  padding: 0 8px 2px;
  border-radius: 2px;
  color: inherit;
}
.hl.green {
  background: linear-gradient(100deg,
    transparent 0%, var(--hl-green) 4%,
    var(--hl-green) 96%, transparent 100%);
}
/* 날짜 타이틀 요일 색: 평일 회색 / 토 기본(하늘) / 일 분홍 */
.hl.wk {
  background: linear-gradient(100deg,
    transparent 0%, rgba(120, 120, 125, 0.18) 4%,
    rgba(120, 120, 125, 0.18) 96%, transparent 100%);
}
.hl.sun {
  background: linear-gradient(100deg,
    transparent 0%, rgba(238, 180, 195, 0.55) 4%,
    rgba(238, 180, 195, 0.55) 96%, transparent 100%);
}

/* ── 헤더 ───────────────────────────────────── */
.month-header {
  border-top: 2.5px solid var(--ink);
  border-bottom: 2.5px solid var(--ink);
  padding: 6px 2px;
  margin-bottom: calc(var(--line) * 0.8);
}
.month-title {
  font-size: 26px;
  font-weight: bold;
  letter-spacing: 4px;
  color: var(--ink);
}
.section-title { font-size: 23px; font-weight: bold; }
.section-title.small { font-size: 19px; }

/* ── 날짜 내비게이션 ────────────────────────── */
.day-nav {
  display: flex;
  align-items: center;
  justify-content: center; /* ‹ 날짜 › 를 화면 가운데로 */
  gap: 10px;
  margin-bottom: 20px;
  position: relative;
}
.day-title {
  font-size: 23px;
  font-weight: normal;
  width: 9ch; /* 날짜 글자가 바뀌어도 너비 고정 (화살표 안 움직이게) */
  text-align: center;
  white-space: nowrap;
}
.nav-btn, .today-btn {
  font-family: inherit;
  background: none;
  border: 1.5px solid transparent;
  font-size: 20px;
  cursor: pointer;
  color: var(--ink-soft);
  line-height: 1;
  padding: 2px 8px;
  border-radius: 50%;
}
.today-btn {
  font-size: 15px;
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  border: 1.5px solid var(--ink-soft);
  border-radius: 10px 14px 12px 14px / 14px 10px 14px 12px; /* 손으로 그린 테두리 */
  padding: 1px 12px;
}
/* hover 효과는 마우스 환경에서만 (터치 기기는 탭 후 hover가 남아 테두리가 생김) */
@media (hover: hover) {
  .nav-btn:hover { border-color: var(--ink-soft); }
  .today-btn:hover { background: rgba(0,0,0,0.05); }
}

/* ── 이월 배너 ──────────────────────────────── */
.migrate-banner {
  font-size: 15px;
  color: #56677d;
  background: linear-gradient(100deg, transparent, rgba(173,203,227,.3) 6%, rgba(173,203,227,.3) 94%, transparent);
  padding: 2px 10px;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.migrate-banner button {
  font-family: inherit;
  font-size: 15px;
  border: 1.5px dashed #56677d;
  background: none;
  color: #56677d;
  border-radius: 8px;
  padding: 0 8px;
  cursor: pointer;
}
@media (hover: hover) {
  .migrate-banner button:hover { background: rgba(173,203,227,.35); }
}
.migrate-banner .migrate-close {
  border: none;
  margin-left: auto;
  padding: 0 4px;
  font-size: 13px;
  color: #8b97a5;
}
.hidden { display: none !important; }

/* ── 엔트리 목록 ────────────────────────────── */
.entry-list { list-style: none; flex: 0 1 auto; }

.entry {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-height: var(--line);
  font-size: 17px;
  line-height: var(--line);
  position: relative;
}

.entry .bullet {
  width: 24px;
  flex-shrink: 0;
  text-align: center;
  cursor: pointer;
  font-weight: bold;
  font-size: 17px;
  user-select: none;
}
@media (hover: hover) {
  .entry .bullet:hover { transform: scale(1.25); }
}

.entry .text { flex: 1; word-break: break-word; }

/* 드래그 정렬: 터치에서는 불렛이 손잡이 (스크롤과 충돌 방지) */
.entry .bullet { touch-action: none; }
.entry.dragging {
  position: relative;
  z-index: 5;
  background: var(--paper);
  box-shadow: 0 4px 12px rgba(60, 55, 40, 0.2);
}

/* 상태별 표현 */
.entry.done .bullet { color: #1c1c1c; }
.entry.done .text {
  text-decoration: line-through;
  text-decoration-thickness: 2px;
  color: var(--ink-soft);
}
.entry.migrated .text,
.entry.migrated .time { color: #a09b8d; }
.entry.migrated .bullet { color: #a09b8d; }
.entry.cancelled .text {
  text-decoration: line-through;
  text-decoration-style: double;
  color: #b0aa9c;
}
.entry.cancelled .bullet { color: #b0aa9c; }
.entry.note .bullet { font-weight: normal; }

/* 항목 액션 (호버 시) */
.entry .actions {
  display: none;
  gap: 2px;
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  background: var(--paper);
  box-shadow: -8px 0 8px var(--paper);
}
.entry:hover .actions { display: flex; }
.entry .actions button {
  font-family: inherit;
  font-size: 14px;
  border: none;
  background: none;
  color: #85868b;
  cursor: pointer;
  padding: 0 5px;
  border-radius: 4px;
}
@media (hover: hover) {
  .entry .actions button:hover { color: var(--ink); background: rgba(0,0,0,.06); }
}

/* ── 입력 폼 ────────────────────────────────── */
.add-form {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-height: var(--line);
  border-bottom: 1.5px dashed rgba(100, 90, 60, 0.35);
}
/* 할 일 입력폼은 페이지 맨 아래에 (목록이 짧아도 바닥) */
#dailyForm { margin-top: auto; }
.add-form input {
  font-family: inherit;
  font-size: 17px;
  line-height: var(--line); /* 목록 행과 같은 줄 높이 → 입력 후 글자가 안 움직임 */
  height: var(--line);
  background: transparent;
  border: none;
  outline: none;
  color: var(--ink);
}
.add-form input::placeholder { color: #96979c; }
.text-input { flex: 1; }
.type-toggle {
  font-family: inherit;
  width: 24px;
  font-size: 17px;
  font-weight: bold;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--ink);
}
.bullet-fixed { width: 24px; text-align: center; font-size: 17px; font-weight: bold; }

/* ── 오른쪽 페이지 ──────────────────────────── */
.month-header.right { border: none; border-bottom: 2.5px solid var(--ink); padding-bottom: 8px; }
.entry-list.monthly { margin-bottom: 4px; }

.tracker-section { margin-top: calc(var(--line) * 1.2); }
.tracker { margin-top: 8px; padding-bottom: 4px; }

/* 습관 블록: 이름(2줄 병합) + 상단 1~15 / 하단 16~말일 그리드 */
.tg-block {
  display: grid;
  grid-template-columns: 84px repeat(var(--tcols, 16), 1fr);
  grid-template-rows: 24px 24px;
  border-top: 1.2px solid rgba(80, 70, 45, 0.45);
  border-left: 1.2px solid rgba(80, 70, 45, 0.45);
  background: var(--paper);
}
.tg-block + .tg-block { margin-top: 6px; }
.tg-block .r1 { grid-row: 1; }
.tg-block .r2 { grid-row: 2; }

.tg-name {
  grid-column: 1;
  grid-row: 1 / span 2;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 6px;
  font-size: 14px;
  border-right: 1.2px solid rgba(80, 70, 45, 0.45);
  border-bottom: 1.2px solid rgba(80, 70, 45, 0.45);
  position: relative;
  overflow: hidden;
  cursor: grab;
  touch-action: none; /* 드래그 중 화면 스크롤 방지 */
  user-select: none;
}
.tg-corner { cursor: default; touch-action: auto; }
.tg-name-text {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tg-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: var(--ink-soft);
  border-right: 1.2px solid rgba(80, 70, 45, 0.45);
  border-bottom: 1.2px solid rgba(80, 70, 45, 0.45);
  overflow: hidden;
  cursor: pointer;
}
/* 요일 파스텔: 평일 없음 / 토 하늘 / 일 분홍 */
.tg-cell.sat { background: rgba(173, 203, 227, 0.35); }
.tg-cell.sun { background: rgba(238, 180, 195, 0.35); }
/* 체크하면 숫자가 X로 바뀌고 라벤더 하이라이트 */
.tg-cell.checked {
  font-weight: bold;
  color: var(--ink);
  background: var(--hl-green);
}
@media (hover: hover) {
  .tg-cell:hover { background: rgba(0,0,0,.05); }
}
.tg-cell.today-col { box-shadow: inset 0 0 0 2px rgba(140, 168, 200, .8); }

/* 드래그 중인 습관 블록 */
.tg-habit.dragging {
  position: relative;
  z-index: 5;
  box-shadow: 0 6px 16px rgba(60, 55, 40, 0.25);
  cursor: grabbing;
}

/* 삭제 버튼은 이름 위에 겹쳐 표시 (이름을 밀어내 말줄임되지 않게) */
.del-habit {
  border: none; cursor: pointer;
  font-family: inherit; font-size: 12px; color: #b0aa9c;
  padding: 0 4px;
  position: absolute;
  right: 0; top: 0; bottom: 0;
  background: var(--paper);
  box-shadow: -6px 0 6px var(--paper);
  display: none;
}
.tg-name:hover .del-habit { display: block; }
.habit-form { max-width: 320px; }

.page-note {
  margin-top: auto;
  padding-top: var(--line);
  font-size: 15px;
  color: #6e6f75;
  text-align: right;
  line-height: 1.4;
}

/* ── 범례 ───────────────────────────────────── */
.legend {
  margin-top: 0; /* 입력폼(#dailyForm)의 margin-top:auto가 바닥으로 밀어줌 */
  padding-top: var(--line);
  display: flex;
  gap: 16px;
  align-items: baseline;
  font-size: 15px;
  color: var(--ink-soft);
  flex-wrap: wrap;
}
.legend-title {
  border: 1.5px solid var(--ink-soft);
  border-radius: 8px 12px 10px 12px / 12px 8px 12px 10px;
  padding: 0 8px;
  font-size: 14px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
/* 접힌 상태: 제목만 남기고 항목 숨김 */
.legend.collapsed > span:not(.legend-title) { display: none; }
.legend b { font-size: 16px; }
.legend .x { text-decoration: line-through; }

/* ── 로그인 화면 (클라우드 모드) ──────────────── */
.login-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #e7e5e1;
  background-image: radial-gradient(circle at 30% 20%, #efedea 0%, #e2e0db 70%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--paper);
  border-radius: 10px;
  box-shadow: 0 18px 40px rgba(60, 55, 40, 0.25), 0 4px 10px rgba(60, 55, 40, 0.15);
  padding: 44px 36px;
  width: 100%;
  max-width: 340px;
  text-align: center;
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: var(--line) var(--line);
}
.login-title {
  font-size: 22px;
  letter-spacing: 2px;
  margin-bottom: 6px;
}
.login-sub {
  font-size: 14px;
  color: var(--ink-soft);
  margin-bottom: 28px;
}
.login-btn {
  display: block;
  width: 100%;
  font-family: inherit;
  font-size: 15px;
  padding: 12px 0;
  margin-bottom: 10px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  background: rgba(173, 203, 227, 0.5);
  color: var(--ink);
}
.login-btn.kakao { background: rgba(207, 198, 227, 0.5); }

/* ── 데이터 도구 (내보내기/가져오기/로그아웃) ── */
.data-tools {
  display: flex;
  gap: 14px;
  justify-content: flex-end;
  padding: 2px 6px 8px;
}
.data-tools button, .data-tools .import-label {
  font-family: inherit;
  font-size: 12px;
  border: none;
  background: none;
  color: #a9aaae;
  cursor: pointer;
  padding: 2px 0;
}

/* ── 저장 상태 ──────────────────────────────── */
.save-status {
  text-align: right;
  font-size: 14px;
  color: #8a8b90;
  padding: 8px 6px 0;
  min-height: 28px;
}

/* ── 하단 탭바 (모바일 전용) ─────────────────── */
.tab-bar { display: none; }

/* ── 모바일 ─────────────────────────────────── */
@media (max-width: 860px) {
  /* 노치·홈바 영역(safe area)을 피하고, 하단 탭바 자리를 확보 */
  body {
    padding:
      max(12px, env(safe-area-inset-top))
      max(8px, env(safe-area-inset-right))
      calc(64px + env(safe-area-inset-bottom))
      max(8px, env(safe-area-inset-left));
  }

  /* 하단 탭바 */
  .tab-bar {
    display: flex;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    gap: 6px;
    padding: 8px 14px calc(8px + env(safe-area-inset-bottom));
    background: rgba(254, 253, 249, 0.94);
    border-top: 1px solid rgba(0, 0, 0, 0.07);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 10;
  }
  .tab-btn {
    flex: 1;
    font-family: inherit;
    font-size: 15px;
    padding: 9px 0;
    border: none;
    background: none;
    color: var(--ink-soft);
    border-radius: 10px;
    cursor: pointer;
  }
  .tab-btn.active {
    background: rgba(173, 203, 227, 0.45);
    color: var(--ink);
    font-weight: bold;
  }

  /* 탭에 따라 페이지 표시 전환 */
  body[data-view="daily"] .page-right,
  body[data-view="daily"] .spine { display: none; }
  body[data-view="monthly"] .page-left,
  body[data-view="monthly"] .spine { display: none; }

  /* 한눈에 탭: 보기 전용 — 입력창 숨김 (완료/취소/삭제만 가능) */
  body[data-view="all"] .add-form { display: none; }

  /* 오늘 탭: 할 일 입력폼을 화면 하단(탭바 위)에 항상 표시 */
  body[data-view="daily"] #dailyForm {
    position: fixed;
    left: 0; right: 0;
    bottom: calc(52px + env(safe-area-inset-bottom));
    margin: 0;
    padding: 8px 16px;
    background: rgba(254, 253, 249, 0.96);
    border-top: 1px solid rgba(0, 0, 0, 0.07);
    border-bottom: none;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 9;
  }
  /* 고정된 입력폼에 마지막 항목이 가리지 않게 여백 확보 */
  body[data-view="daily"] .page-left { padding-bottom: 72px; }
  /* 손가락으로 누르기 편한 크기로 */
  .nav-btn { padding: 6px 14px; }
  .today-btn { padding: 4px 14px; }
  .entry .bullet { padding: 0 4px; }
  .entry .actions button { font-size: 15px; padding: 4px 8px; }
  .notebook { flex-direction: column; }
  .spine { width: auto; height: 18px;
    background: linear-gradient(180deg,
      rgba(0,0,0,0.10) 0%, rgba(0,0,0,0.02) 30%,
      rgba(0,0,0,0.16) 50%,
      rgba(0,0,0,0.02) 70%, rgba(0,0,0,0.10) 100%);
  }
  .page { padding: 20px 18px 18px; }
  /* 폰: 14px 글자에 편안한 읽기 간격 (클로드 앱 본문 느낌) */
  body { --line: 26px; }
  .month-title { font-size: 14px; letter-spacing: 3px; }
  .day-title { font-size: 15px; }
  .section-title { font-size: 15px; }
  .section-title.small { font-size: 13px; }
  .nav-btn { font-size: 14px; }
  .today-btn { font-size: 12px; }
  /* 입력창과 목록 행은 같은 크기 유지 (입력 후 글자가 안 움직이게)
     확대 자체를 막아놔서(maximum-scale=1) 16px 미만이어도 iOS가 확대하지 않음 */
  .entry { font-size: 14px; }
  .entry .bullet { font-size: 14px; }
  .add-form input { font-size: 14px; }
  .type-toggle, .bullet-fixed { font-size: 14px; }
  .migrate-banner { font-size: 12px; }
  .migrate-banner button { font-size: 12px; }
  .tracker-table th.habit-name { font-size: 12px; }
  .tracker-table th, .tracker-table td { font-size: 12px; }
  .legend { font-size: 12px; }
  .legend b { font-size: 13px; }
  .legend-title { font-size: 11px; }
  .page-note { font-size: 12px; }
  .save-status { font-size: 11px; }
  .tab-btn { font-size: 13px; }
  /* 폰: 액션 버튼 없음 (길게 누르기로 조작) */
  .entry .actions { display: none !important; }
  /* 길게 누를 때 iOS 텍스트 선택/복사 팝업 방지 */
  .entry {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }
}
