/* ==========================================================
   Travel Diary — 종이 질감의 여행 다이어리
   ========================================================== */
:root {
  --paper: #ecebe7;
  --paper-2: #f5f4f0;
  --ink: #171717;
  --ink-2: #3f3f3d;
  --muted: #5f5f5b;
  --line: #262626;
  --hair: #d3d1cb;
  --hair-dark: #b0aea7;
  --red: #b23a2a;
  --serif: "Playfair Display", "Times New Roman", Georgia, serif;
  --serif-kr: "Noto Serif KR", "Batang", "Apple Myungjo", serif;   /* 한글 제목용 명조체 */
  --sans: "Noto Sans KR", "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  --nav-h: 56px;
  --maxw: 1240px;
  --side-w: 180px;
}

*, *::before, *::after { box-sizing: border-box; }
html { background: var(--paper); scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font: 400 15px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
}
/* 종이 그레인 */
body::before {
  content: "";
  position: fixed; inset: 0; z-index: -1;
  pointer-events: none; opacity: .55;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.12 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
[hidden] { display: none !important; }
button { font-family: inherit; }
img { display: block; }
h1, h2, h3, p { margin: 0; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* ---------- 내비게이션 ---------- */
.nav {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 16px;
  min-height: var(--nav-h); padding: 0 24px;
  background: rgba(236, 235, 231, .86);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--hair);
}
.nav-brand {
  font: 500 14px var(--serif); letter-spacing: .16em; text-transform: uppercase;
  color: var(--ink); text-decoration: none; white-space: nowrap;
}
/* 여행 페이지 → 홈(여행 목록) */
.nav-home {
  display: inline-flex; align-items: center; gap: 2px;
  margin-left: -8px; padding: 5px 10px 5px 4px; border-radius: 999px;
  font: 500 13px/1.4 var(--sans); color: var(--ink-2); text-decoration: none; white-space: nowrap;
  transition: background .15s, color .15s;
}
.nav-home:hover { background: var(--hair); color: var(--ink); }
.nav-home svg { width: 16px; height: 16px; flex: none; }
.nav-days { display: flex; gap: 2px; margin: 0 auto; }
.nav-days a {
  font: 400 12px/1.4 var(--serif); letter-spacing: .12em;
  padding: 6px 11px; border-radius: 999px;
  color: var(--ink-2); text-decoration: none; white-space: nowrap;
  transition: background .15s, color .15s;
}
.nav-days a:hover { background: var(--hair); }
.nav-days a.is-active { background: var(--ink); color: var(--paper); }

/* ---------- 버튼 ---------- */
.btn {
  display: inline-block; padding: 6px 13px;
  border: 1px solid var(--ink); border-radius: 999px;
  background: transparent; color: var(--ink);
  font: 500 12px/1.4 var(--sans); cursor: pointer; white-space: nowrap;
  transition: background .15s, color .15s, border-color .15s;
}
.btn:hover { background: var(--ink); color: var(--paper); }
.btn:disabled { opacity: .35; cursor: default; }
.btn:disabled:hover { background: transparent; color: inherit; }
.btn-ghost { border-color: var(--hair-dark); color: var(--ink-2); }
.btn-dark { border-color: rgba(255, 255, 255, .35); color: #fff; }
.btn-dark:hover { background: #fff; color: #111; }
.btn-dark:disabled:hover { color: #fff; }
.btn-danger { color: #ff9a94; border-color: rgba(255, 120, 110, .5); }
.btn-danger:hover { background: #d94a3d; border-color: #d94a3d; color: #fff; }

/* ---------- 표지 ---------- */
.hero {
  position: relative; max-width: var(--maxw); margin: 0 auto;
  padding: 64px 40px 44px;
}
.eyebrow {
  margin-bottom: 8px;
  font: 400 12px var(--serif); letter-spacing: .28em; text-transform: uppercase; color: var(--muted);
}
.hero-title {
  font: 500 clamp(40px, 11vw, 132px)/1.05 "Playfair Display", var(--serif-kr);   /* 영문은 Playfair, 한글은 Noto Serif KR */
  letter-spacing: .02em; white-space: nowrap;   /* 긴 제목은 app.js fitTitle() 이 폭에 맞춰 줄인다 */
}.hero-period { margin-top: 16px; font: 400 20px var(--serif); letter-spacing: .04em; }
.seal {
  position: absolute; top: 72px; right: 44px;
  width: 56px; height: 78px;
  border: 2px solid var(--red); border-radius: 3px; color: var(--red);
  display: grid; place-items: center; writing-mode: vertical-rl;
  font: 700 22px/1 "Yu Mincho", "Hiragino Mincho ProN", "Noto Serif JP", "Noto Serif KR", "Batang", serif;
  letter-spacing: .12em; transform: rotate(-7deg); opacity: .8; mix-blend-mode: multiply;
  user-select: none;
}

/* ---------- 지도 ---------- */
.map-wrap { margin-top: 30px; }
.map-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin-bottom: 10px;
}
.map-tabs { display: flex; gap: 2px; flex-wrap: wrap; }
.map-tabs button {
  font: 400 12px/1.4 var(--serif); letter-spacing: .12em; padding: 5px 11px;
  border: 0; border-radius: 999px; background: transparent; color: var(--ink-2); cursor: pointer;
  transition: background .15s, color .15s;
}
.map-tabs button:hover { background: var(--hair); }
.map-tabs button.is-active { background: var(--ink); color: var(--paper); }
.map {
  position: relative; z-index: 0; aspect-ratio: 21 / 9;
  border: 1px solid var(--hair); background: var(--paper-2); overflow: hidden;
}
.map.leaflet-container { background: var(--paper-2); font-family: var(--sans); }
.map-fallback { position: absolute; inset: 0; display: grid; place-items: center; font-size: 13px; color: var(--muted); }
.map-hint {
  position: absolute; left: 50%; bottom: 12px; z-index: 1000; transform: translateX(-50%);
  padding: 5px 12px; border-radius: 999px; background: rgba(23, 23, 23, .78); color: var(--paper);
  font-size: 11px; white-space: nowrap; pointer-events: none;
}
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.map .leaflet-tile-pane { filter: grayscale(.55) sepia(.28) saturate(.75) brightness(1.04) contrast(.92); }
.map .leaflet-control-attribution { font: 400 10px var(--sans); background: rgba(245, 244, 240, .85); color: var(--muted); }
.map .leaflet-control-attribution a { color: var(--ink-2); }
.map .leaflet-bar { border: 1px solid var(--hair-dark); box-shadow: none; }
.map .leaflet-bar a { background: var(--paper-2); color: var(--ink); border-bottom-color: var(--hair); }
.map .leaflet-bar a:hover { background: var(--paper); }
.pin { background: none; border: 0; }
.pin-dot {
  display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  background: var(--ink); color: var(--paper); font: 500 11px/1 var(--serif);
  border: 2px solid var(--paper-2); box-shadow: 0 1px 4px rgba(0, 0, 0, .35); transition: transform .15s;
}
.pin-dot.has-content { background: var(--red); }
.pin-dot.is-multi { font-size: 9px; letter-spacing: -.02em; }
.map .leaflet-popup-scrolled { overscroll-behavior: contain; }
.leaflet-marker-icon:hover .pin-dot { transform: scale(1.15); }
.map .leaflet-popup-content-wrapper {
  border-radius: 4px; background: var(--paper-2); color: var(--ink); box-shadow: 0 6px 20px rgba(0, 0, 0, .18);
}
.map .leaflet-popup-tip { background: var(--paper-2); }
.map .leaflet-popup-content { margin: 12px 14px; font: 400 13px/1.5 var(--sans); }
.pop { display: grid; gap: 10px; min-width: 150px; }
.pop-item { display: grid; gap: 3px; }
.pop-item + .pop-item { border-top: 1px solid var(--hair); padding-top: 10px; }
.pop-day { font: 400 10px var(--serif); letter-spacing: .18em; color: var(--muted); }
.pop-name { font: 500 15px/1.3 var(--sans); }
.pop-en { font: 400 10px var(--serif); letter-spacing: .14em; color: var(--muted); }
.pop-thumb { width: 100%; aspect-ratio: 3 / 2; object-fit: cover; margin-top: 4px; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .15); }
.pop-meta { font-size: 11px; color: var(--muted); }
.pop-approx { font-size: 10px; color: var(--red); }
.pop-link {
  justify-self: start; margin-top: 2px; padding: 0; border: 0; background: none;
  color: var(--ink); font: 500 12px var(--sans); text-decoration: underline; text-underline-offset: 3px; cursor: pointer;
}
.btn-icon {
  border: 0; background: none; padding: 2px 4px; color: var(--muted); cursor: pointer; line-height: 0; align-self: center;
}
.btn-icon:hover { color: var(--ink); }
.btn-icon svg { width: 16px; height: 16px; }

/* ---------- 하루 섹션 ---------- */
#days { max-width: var(--maxw); margin: 0 auto; padding-bottom: 64px; }
.day {
  display: grid; grid-template-columns: var(--side-w) 1fr;
  border-top: 1px solid var(--line);
  scroll-margin-top: var(--nav-h);
}
.day:last-of-type { border-bottom: 1px solid var(--line); }
.day-side { border-right: 1px solid var(--line); }
.day-side-inner { position: sticky; top: var(--nav-h); padding: 56px 0 0; }
.day-badge {
  display: block; width: 132px; height: 58px; margin: 0 auto;
  border-radius: 50%; background: var(--ink); color: var(--paper);
  font: 400 21px/58px var(--serif); text-align: center; letter-spacing: .06em;
}
.day-date {
  margin-top: 44px; border-top: 1px solid var(--line);
  padding: 10px 0 18px 22px; font: 400 21px/1.2 var(--serif); letter-spacing: .02em;
}
.day-main { min-width: 0; padding: 26px 40px 56px 44px; }

/* 타임라인 (동선): 장소마다 같은 폭의 칸을 주고 점은 칸 가운데, 이동시간은 칸 경계에 둔다.
   데스크톱에서는 하루 일정이 한 줄에 다 들어가고(긴 이름은 두 줄), 좁은 화면에서만 가로로 스크롤된다. */
.timeline {
  display: flex; height: 112px; padding: 0 8px;
  overflow-x: auto; overflow-y: hidden; scrollbar-width: thin;
}
.tl-stop { position: relative; flex: 1 1 0; min-width: 0; }
.tl-stop::before {
  content: ""; position: absolute; left: 50%; right: -50%; top: 56px; height: 1px; background: var(--line);
}
.tl-stop.is-last::before { display: none; }
.tl-dot {
  position: absolute; left: 50%; top: 56px; z-index: 1;
  width: 14px; height: 14px; border: 1.5px solid var(--line); border-radius: 50%;
  background: var(--paper); transform: translate(-50%, -50%); transition: background .25s;
}
.tl-stop.has-content .tl-dot { background: var(--ink); }
.tl-label {
  position: absolute; left: 50%; bottom: 60px; transform: translateX(-50%);   /* 선(56px) 바로 위에 아래쪽을 맞춘다 */
  width: max-content; max-width: calc(100% - 4px); white-space: normal; word-break: keep-all; text-align: center;
  border: 0; background: none; padding: 2px 2px;
  font: 500 14px/1.25 var(--sans); color: var(--ink); cursor: pointer;
}
.tl-label:hover { text-decoration: underline; text-underline-offset: 5px; }
.tl-label.is-tight { overflow-wrap: anywhere; }   /* app.js fitLabels: 줄여도 칸을 넘는 긴 이름 */
.tl-transit {
  position: absolute; left: 100%; top: 68px; transform: translateX(-50%);
  white-space: nowrap; font-size: 11px; color: var(--muted); letter-spacing: .01em;
}

/* 하루 메모 */
.day-memo {
  margin-top: 22px; padding: 12px 18px 4px;
  border: 1px solid var(--hair); background: var(--paper-2);
}
.memo-label { font: 400 11px var(--serif); letter-spacing: .18em; color: var(--muted); }

/* 장소 카드 */
.stops { margin-top: 26px; }
.stop {
  position: relative; background: var(--paper-2); border: 1px solid var(--hair);
  padding: 18px 22px 8px;
  scroll-margin-top: calc(var(--nav-h) + 16px);
}
.stop.is-dragover { outline: 1.5px dashed var(--ink); outline-offset: 3px; }
.stop-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.stop-idx { font: 400 13px var(--serif); color: var(--muted); letter-spacing: .05em; }
.stop-titles { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; flex: 1; min-width: 0; }
.stop-name { font: 500 19px/1.3 var(--sans); }
.stop-en { font: 400 11px var(--serif); letter-spacing: .16em; color: var(--muted); }
.stop-time {
  width: 64px; border: 0; border-bottom: 1px solid var(--hair-dark); background: transparent;
  font: 400 13px var(--serif); letter-spacing: .08em; text-align: center; padding: 2px 0; color: var(--ink-2);
}
.stop-time:focus { outline: 0; border-bottom-color: var(--ink); }
.stop-time::placeholder { color: #b5b3ad; }

/* 카드 사이 이동 표시 */
.transit {
  display: flex; align-items: center; gap: 12px;
  padding: 6px 0 6px 30px; font-size: 11px; color: var(--muted);
}
.transit::before { content: ""; width: 0; height: 26px; border-left: 1px dashed var(--hair-dark); }

/* 사진 */
.photos { margin: 16px 0 6px; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(148px, 1fr)); gap: 8px; }
.photo {
  position: relative; margin: 0; aspect-ratio: 1; overflow: hidden;
  background: var(--hair); cursor: zoom-in;
  border: 3px solid #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .12);
}
.photo img { width: 100%; height: 100%; object-fit: cover; transition: transform .35s ease; }
.photo:hover img { transform: scale(1.03); }
.photo-cap {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 18px 8px 6px;
  font-size: 11px; color: #fff; background: linear-gradient(transparent, rgba(0, 0, 0, .55));
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.photo-add {
  aspect-ratio: 1; border: 1px dashed var(--hair-dark); background: transparent;
  color: var(--muted); font: 300 28px/1 var(--sans); cursor: pointer; transition: border-color .15s, color .15s;
}
.photo-add:hover { border-color: var(--ink); color: var(--ink); }
.dropzone {
  display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%;
  padding: 24px 16px; border: 1px dashed var(--hair-dark); background: transparent;
  color: var(--muted); font-size: 13px; cursor: pointer; transition: border-color .15s, color .15s;
}
.dropzone:hover { border-color: var(--ink); color: var(--ink); }
.dropzone svg { width: 20px; height: 20px; flex: none; }

/* 기록 */
.note-wrap { position: relative; padding-bottom: 18px; }
.note {
  display: block; width: 100%; min-height: 42px;
  border: 0; border-bottom: 1px solid var(--hair-dark); background: transparent;
  font: 300 15px/1.85 var(--sans); color: var(--ink); padding: 8px 0 6px;
  resize: none; overflow: hidden;
}
.note:focus { outline: 0; border-bottom-color: var(--ink); }
.note::placeholder { color: #a6a49e; }
.save-state {
  position: absolute; right: 0; bottom: 2px;
  font: 400 10px var(--serif); letter-spacing: .14em; color: var(--muted);
  opacity: 0; transition: opacity .25s;
}
.save-state.is-visible { opacity: 1; }

/* ---------- 푸터 ---------- */

/* ---------- 사진 보기 ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(12, 12, 12, .94);
  display: grid; grid-template-rows: 1fr auto;
}
.lb-figure { margin: 0; display: grid; place-items: center; padding: 56px 72px 12px; min-height: 0; }
.lb-figure img {
  max-width: 100%; max-height: calc(100vh - 200px); object-fit: contain;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .5);
}
.lb-close {
  position: absolute; top: 12px; right: 16px; width: 44px; height: 44px;
  border: 0; background: transparent; color: #fff; font-size: 32px; line-height: 1; cursor: pointer;
}
.lb-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 52px; height: 80px; border: 0; background: transparent;
  color: rgba(255, 255, 255, .75); font-size: 46px; line-height: 1; cursor: pointer;
}
.lb-nav:hover { color: #fff; }
.lb-nav:disabled { opacity: .2; cursor: default; }
.lb-prev { left: 12px; }
.lb-next { right: 12px; }
.lb-bar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 12px 24px 18px; color: #fff; }
.lb-meta { display: flex; gap: 10px; align-items: baseline; }
.lb-title { font: 500 14px var(--sans); }
.lb-count { font: 400 12px var(--serif); letter-spacing: .1em; color: rgba(255, 255, 255, .6); }
.lb-caption {
  flex: 1; min-width: 200px; border: 0; border-bottom: 1px solid rgba(255, 255, 255, .3);
  background: transparent; color: #fff; font: 300 14px var(--sans); padding: 6px 0;
}
.lb-caption:focus { outline: 0; border-bottom-color: #fff; }
.lb-caption::placeholder { color: rgba(255, 255, 255, .45); }
.lb-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- 토스트 ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 200;
  padding: 10px 18px; border-radius: 999px; background: var(--ink); color: var(--paper);
  font-size: 13px; box-shadow: 0 6px 24px rgba(0, 0, 0, .2); max-width: calc(100vw - 32px);
}

/* ---------- 모바일 ---------- */
@media (max-width: 760px) {
  :root { --nav-h: 88px; }
  .nav { flex-wrap: wrap; gap: 6px 10px; padding: 8px 12px; }
  .nav-days { order: 3; width: 100%; justify-content: center; margin: 0; overflow-x: auto; }
  .hero { padding: 40px 16px 28px; }
  .hero-period { font-size: 17px; }
  .seal { right: 16px; top: 44px; width: 44px; height: 60px; font-size: 17px; }
  .map-wrap { margin-top: 22px; }
  .map-head { gap: 8px; }
  .map-tabs { width: 100%; gap: 4px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .map-tabs button { padding: 5px 7px; font-size: 11px; letter-spacing: .06em; }
  .map { aspect-ratio: 4 / 3; }
  .pop-thumb { max-height: 64px; }
  .day { grid-template-columns: 1fr; }
  .day-side { border-right: 0; }
  .day-side-inner {
    position: static; display: flex; align-items: center; justify-content: space-between;
    padding: 18px 16px 0;
  }
  .day-badge { margin: 0; width: 110px; height: 48px; font-size: 18px; line-height: 48px; }
  .day-date { margin: 0; border: 0; padding: 0; font-size: 18px; }
  .day-main { padding: 12px 16px 36px; }
  .timeline { padding: 0 4px; }
  .tl-stop { min-width: 112px; }
  /* 좁은 화면: ㄹ자 두 줄로 접는다 (app.js layoutTimelines 가 칸 위치와 is-wrapped / row-end / row-rev 를 정한다) */
  .timeline.is-wrapped { display: grid; height: auto; overflow: visible; padding-right: 20px; }
  .timeline.is-wrapped .tl-stop { min-width: 0; height: 112px; }
  /* 첫째 줄 끝 → 바로 아래 둘째 줄 첫 장소: 오른쪽 여백으로 둥글게 꺾이는 U자 선 (이름과 겹치지 않도록 칸 밖으로) */
  .timeline.is-wrapped .tl-stop.row-end::before {
    left: 50%; right: -16px; top: 56px; height: 113px;
    background: none; border: 1px solid var(--line); border-left: 0; border-radius: 0 28px 28px 0;
  }
  .timeline.is-wrapped .tl-stop.row-end .tl-transit { left: auto; right: -10px; top: 98px; transform: translateY(-50%); }   /* 둘째 줄 이름(위로 자람)과 떨어지게 위쪽에 */
  /* 둘째 줄은 오른쪽 → 왼쪽: 선과 이동시간을 왼쪽 이웃 쪽에 둔다 */
  .timeline.is-wrapped .tl-stop.row-rev::before { left: -50%; right: 50%; }
  .timeline.is-wrapped .tl-stop.row-rev .tl-transit { left: 0; }
  .timeline.is-wrapped .tl-label { font-size: 13px; }
  .stop { padding: 14px 14px 6px; }
  .stop-name { font-size: 17px; }
  .photo-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 6px; }
  .lb-figure { padding: 52px 10px 8px; }
  .lb-figure img { max-height: calc(100vh - 230px); }
  .lb-nav { display: none; }
  .lb-bar { padding: 10px 14px 16px; }
  #days { padding-bottom: 44px; }
}

/* ---------- 인쇄 ---------- */
@media print {
  .nav, .btn, .btn-icon, .dropzone, .photo-add, .lightbox, .toast, .save-state, .map-head, .map-hint, .leaflet-control-zoom { display: none !important; }
  body::before { display: none; }
  html, body { background: #fff; }
  .day { break-before: page; }
  .stop, .photo { break-inside: avoid; }
  .day-side-inner { position: static; }
  .note { border-bottom-color: transparent; }
  .timeline { overflow: visible; }
}

/* 저장 실패 표시 */
.save-state.is-error { color: var(--red); }
