/* Sage Scroll — 종이+먹 editorial.
   레퍼런스: Republic of Letters(생애↔장소), Google Arts&Culture(사료가 주인공),
   Stamen/Carto(지도는 물러나고 데이터가 튐), Hammock(지도 중심·단순 마커). */

:root {
  --paper:     #f4efe4;  /* 앱 배경: 따뜻한 미색 */
  --surface:   #fbf8f1;  /* 패널/카드 */
  --surface-2: #ece3d1;  /* 살짝 깊은 면 */
  --ink:       #211c17;  /* 본문 */
  --ink-soft:  #6d6357;  /* 보조 */
  --ink-faint: #9c9081;  /* 메타 */
  --rule:      #e2d9c6;  /* 가는 선 */
  --rule-soft: #ece4d5;
  --seal:      #b23a2c;  /* 인주 빨강 — 강조 */
  --seal-soft: #c9705f;

  --serif: "Noto Serif KR", Georgia, "Apple SD Gothic Neo", serif;
  --sans:  -apple-system, BlinkMacSystemFont, "Pretendard", "Apple SD Gothic Neo", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  font-family: var(--sans);
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
body { display: flex; flex-direction: column; }

/* ── 상단 바 ── */
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 13px 24px;
  background: var(--surface); border-bottom: 1px solid var(--rule);
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.brand::before {
  content: ""; width: 18px; height: 18px; flex-shrink: 0;
  background: var(--seal); border-radius: 3px;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.35);
}
.brand h1 {
  font-family: var(--serif); font-size: 21px; font-weight: 700;
  margin: 0; letter-spacing: .01em; color: var(--ink);
}
.brand .tag { font-size: 12.5px; color: var(--ink-soft); }

.route-picker { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--ink-faint); }
.route-picker select {
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--rule); border-radius: 6px; padding: 5px 8px; font-size: 12.5px;
}

/* ── 언어 (ko/en) ── */
.lang-ko .en { display: none; }
.lang-en .ko { display: none; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.lang-toggle { display: inline-flex; border: 1px solid var(--rule); border-radius: 999px; overflow: hidden; }
.lang-toggle button {
  font-family: var(--sans); font-size: 11.5px; font-weight: 600; letter-spacing: .04em;
  padding: 5px 12px; border: none; background: transparent; color: var(--ink-faint);
  cursor: pointer; transition: background .15s, color .15s;
}
.lang-toggle button:hover { color: var(--seal); }
.lang-toggle button.on { background: var(--seal); color: #fff; }

/* ── 인물 바 ── */
#person-bar {
  padding: 11px 24px; background: var(--paper);
  border-bottom: 1px solid var(--rule); flex-shrink: 0;
  position: relative;
}

/* ── 인물 검색 (인물 바 우상단) ── */
.nav-search { position: absolute; top: 10px; right: 24px; width: 210px; z-index: 950; }
#person-search {
  width: 100%; font-family: var(--sans); font-size: 13px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--rule); border-radius: 999px;
  padding: 6px 14px; outline: none; transition: border-color .15s;
}
#person-search::placeholder { color: var(--ink-faint); }
#person-search:focus { border-color: var(--seal-soft); }
#search-results {
  position: absolute; top: calc(100% + 6px); right: 0; width: 262px;
  max-height: 330px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--rule); border-radius: 10px;
  box-shadow: 0 14px 30px -18px rgba(33, 28, 23, .5); padding: 5px;
}
#search-results[hidden] { display: none; }
.sr-item {
  display: flex; flex-direction: column; gap: 2px; width: 100%; text-align: left;
  background: transparent; border: none; border-radius: 7px;
  padding: 7px 9px; cursor: pointer;
  font-family: var(--sans); font-size: 13.5px; color: var(--ink);
}
.sr-item:hover { background: var(--surface-2); color: var(--seal); }
.sr-sub { font-size: 11px; color: var(--ink-faint); }
.sr-empty { font-size: 12px; color: var(--ink-faint); padding: 8px 9px; }
@media (max-width: 720px) {
  .nav-search { position: relative; top: auto; right: auto; width: 100%; margin-bottom: 9px; }
  #search-results { width: 100%; }
}
.nav-axis { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 8px; }
.axis-label { flex-shrink: 0; width: 36px; padding-top: 8px; font-family: var(--sans); font-size: 10px; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--ink-faint); }
#region-tabs, #era-tabs, #field-tabs { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; }
#era-tabs button, #field-tabs button { font-size: 12.5px; }
#region-tabs button, #era-tabs button, #field-tabs button {
  font-family: var(--sans); font-size: 13px; font-weight: 600; letter-spacing: .01em;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 13px; border: none; background: transparent; color: var(--ink-soft);
  border-radius: 8px; cursor: pointer; transition: background .15s, color .15s;
}
#region-tabs button:hover, #era-tabs button:hover, #field-tabs button:hover { background: var(--surface-2); color: var(--seal); }
#region-tabs button.on, #era-tabs button.on, #field-tabs button.on { background: var(--seal); color: #fff; }
.rt-count { font-size: 11px; font-weight: 500; color: var(--ink-faint); }
#region-tabs button.on .rt-count, #era-tabs button.on .rt-count, #field-tabs button.on .rt-count { color: rgba(255,255,255,.72); }
.region-hint { font-size: 13px; color: var(--ink-faint); padding: 3px 2px; line-height: 1.5; }
#person-list { display: flex; flex-direction: column; gap: 7px; border-top: 1px solid var(--rule); padding-top: 12px; margin-top: 3px; }
.pgroup { display: flex; align-items: baseline; gap: 13px; }
.pgroup-label {
  flex-shrink: 0; width: 58px; text-align: right; padding-top: 3px;
  font-size: 10.5px; letter-spacing: .06em; color: var(--ink-faint); line-height: 1.3;
}
.pgroup-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.person-chip {
  flex-shrink: 0; background: transparent; color: var(--ink-soft);
  border: 1px solid var(--rule); border-radius: 999px;
  padding: 5px 14px; font-size: 13.5px; font-family: var(--sans);
  cursor: pointer; white-space: nowrap; transition: all .15s ease;
}
.person-chip:hover { border-color: var(--seal-soft); color: var(--seal); }
.person-chip.active { background: var(--seal); border-color: var(--seal); color: #fff; }

/* ── 오늘의 인물 — 매일 KST 자정 기준 자동 로테이션 (app.js) ── */
#today-sage {
  display: flex; align-items: center; gap: 11px;
  padding: 8px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
  flex-shrink: 0; overflow: hidden;
}
#today-sage[hidden] { display: none; }
.ts-label {
  font-family: var(--sans); font-size: 10.5px; font-weight: 700;
  letter-spacing: .09em; text-transform: uppercase; color: var(--seal); flex-shrink: 0;
}
#today-sage-btn {
  font-family: var(--serif); font-size: 14.5px; font-weight: 700;
  background: transparent; color: var(--ink);
  border: 1px solid var(--seal-soft); border-radius: 999px;
  padding: 4px 15px; cursor: pointer; white-space: nowrap; flex-shrink: 0;
  transition: all .15s ease;
}
#today-sage-btn:hover { background: var(--seal); border-color: var(--seal); color: #fff; }
#today-sage-meta {
  font-size: 12.5px; color: var(--ink-soft);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ── 레이아웃 ── */
#layout { display: flex; flex: 1; min-height: 0; position: relative; }
#map { flex: 1; min-width: 0; background: var(--surface-2); }

/* ── 시야 연동 인물 리스트 — 지도 좌상단 오버레이 (줌 컨트롤 아래) ── */
#map-roster {
  position: absolute; left: 12px; top: 92px; z-index: 900;
  width: 186px; max-height: min(54vh, 440px); overflow-y: auto;
  background: rgba(251, 248, 241, .94);
  border: 1px solid var(--rule); border-radius: 10px;
  padding: 9px 9px 7px;
  box-shadow: 0 12px 28px -20px rgba(33, 28, 23, .55);
}
#map-roster[hidden] { display: none; }
.mr-title {
  font-family: var(--sans); font-size: 10px; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase; color: var(--ink-faint);
  padding: 2px 4px 7px;
}
.mr-count { color: var(--seal); }
.mr-item {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  width: 100%; text-align: left;
  font-family: var(--sans); font-size: 13px; color: var(--ink);
  background: transparent; border: none; border-radius: 7px;
  padding: 5px 7px; cursor: pointer; transition: background .12s, color .12s;
}
.mr-item:hover { background: var(--surface-2); color: var(--seal); }
.mr-item.on { background: var(--seal); color: #fff; }
.mr-item.on .mr-life { color: rgba(255,255,255,.75); }
.mr-life { font-size: 10.5px; color: var(--ink-faint); white-space: nowrap; }
.mr-more { font-size: 11px; color: var(--ink-faint); padding: 5px 7px 2px; }
@media (max-width: 720px) { #map-roster { display: none; } }

#panel {
  width: 424px; flex-shrink: 0;
  background: var(--surface); border-left: 1px solid var(--rule);
  overflow-y: auto;
}
.panel-empty { color: var(--ink-soft); font-size: 14.5px; line-height: 1.75; padding: 38px 32px; }
.panel-empty em { color: var(--seal); font-style: normal; }

/* ── 인물 본문 ── */
.person { padding: 32px 32px 56px; }

.person-name {
  font-family: var(--serif); font-size: 33px; font-weight: 700;
  line-height: 1.12; margin: 0; color: var(--ink);
}
.person-verify {
  display: inline-block; vertical-align: middle; margin-left: 10px;
  font-family: var(--sans); font-size: 10.5px; font-weight: 500; letter-spacing: .04em;
  color: var(--ink-faint); border: 1px solid var(--rule);
  border-radius: 999px; padding: 2px 9px; white-space: nowrap;
}
.person-verify.unv { color: var(--seal); border-color: var(--seal-soft); }
.person-en { font-family: var(--serif); font-style: italic; font-size: 14px; color: var(--ink-faint); margin-top: 5px; }
.person-meta { font-size: 13px; color: var(--ink-soft); margin-top: 11px; }
.person-birth { font-size: 12.5px; color: var(--ink-faint); margin-top: 7px; line-height: 1.5; }

/* ── 히어로: 그 사람의 말(사료) ── */
.hero-quote { position: relative; margin: 28px 0 4px; padding-top: 26px; }
.hero-quote::before {
  content: "\201C"; position: absolute; top: 6px; left: -4px;
  font-family: var(--serif); font-size: 58px; line-height: 1;
  color: var(--seal); opacity: .42;
}
.hq-text {
  font-family: var(--serif); font-size: 22px; font-weight: 400;
  line-height: 1.7; color: var(--ink); margin: 0; word-break: keep-all;
}
.hq-trans {
  font-family: var(--sans); font-size: 14px; line-height: 1.6;
  color: var(--ink-soft); font-style: italic; margin: 9px 0 0;
}
.hq-cite {
  display: block; margin-top: 14px; font-family: var(--sans);
  font-style: normal; font-size: 12.5px; color: var(--ink-faint);
}
.hq-cite::before { content: "— "; }

/* ── 섹션 ── */
.seg { margin-top: 32px; padding-top: 22px; border-top: 1px solid var(--rule); }
.seg-title {
  font-family: var(--sans); font-size: 11px; font-weight: 600;
  letter-spacing: .15em; text-transform: uppercase; color: var(--seal);
  margin: 0 0 16px;
}
.seg-title .hint {
  font-weight: 400; letter-spacing: .02em; text-transform: none;
  color: var(--ink-faint); font-size: 11px; margin-left: 8px;
}
.seg-empty { font-size: 13px; color: var(--ink-faint); }

/* ── 생애 연표 ── */
.timeline { list-style: none; margin: 0; padding: 0; }
.tl { position: relative; padding: 0 0 19px 22px; margin-left: 4px; border-left: 1px solid var(--rule); }
.tl:last-child { border-left-color: transparent; padding-bottom: 0; }
.tl::before {
  content: ""; position: absolute; left: -4.5px; top: 6px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ink-faint); border: 2px solid var(--surface);
}
.tl.clickable { cursor: pointer; }
.tl.clickable::before { background: var(--seal); }
.tl-year { font-family: var(--serif); font-size: 13px; font-weight: 600; color: var(--seal); font-variant-numeric: tabular-nums; }
.tl-event { display: block; font-size: 14.5px; line-height: 1.62; color: var(--ink); margin-top: 2px; word-break: keep-all; }
.tl.clickable:hover .tl-event { color: var(--seal); }
.tl-pin { font-size: 12px; }

/* ── 저작 ── */
.work { margin-bottom: 19px; }
.work:last-child { margin-bottom: 0; }
.work-title { font-family: var(--serif); font-size: 16px; font-weight: 600; color: var(--ink); }
.work-year { font-size: 12px; color: var(--ink-faint); margin-left: 7px; }
.work-note { display: block; font-size: 13px; color: var(--ink-soft); line-height: 1.55; margin-top: 3px; }
.work-quote {
  margin: 9px 0 0; padding: 4px 0 4px 15px;
  border-left: 2px solid var(--rule);
  font-family: var(--serif); font-size: 14px; color: var(--ink); line-height: 1.65; word-break: keep-all;
}
.work-quote .wq-trans { display: block; margin-top: 5px; font-family: var(--sans); font-size: 12.5px; color: var(--ink-soft); font-style: italic; }
.work-quote cite { display: block; margin-top: 6px; font-family: var(--sans); font-size: 11.5px; color: var(--ink-faint); font-style: normal; }

/* ── 연고 장소 ── */
.place { margin-bottom: 12px; font-size: 14px; line-height: 1.5; }
.place.clickable { cursor: pointer; }
.place.clickable:hover .place-name { color: var(--seal); }
.place-name { color: var(--ink); }
.place-type { color: var(--ink-faint); font-size: 12px; margin-left: 7px; }

/* ── 출처·신뢰 표시(조용히) ── */
.src-mark {
  font-family: var(--sans); font-size: 11px; color: var(--ink-faint);
  text-decoration: none; border-bottom: 1px dotted var(--rule); margin-left: 7px; white-space: nowrap;
}
.src-mark:hover { color: var(--seal); border-bottom-color: var(--seal-soft); }
.trust-note { font-family: var(--sans); font-size: 11px; color: var(--seal-soft); margin-left: 7px; }

/* ── 상태 바 ── */
#statusbar {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 24px; font-size: 12px; color: var(--ink-soft);
  background: var(--surface); border-top: 1px solid var(--rule); flex-shrink: 0;
}
#statusbar .sep { color: var(--ink-faint); }
#statusbar .grow { flex: 1; }
.foot-note { color: var(--ink-faint); font-style: italic; }

/* ── 지도: 핀 ── */
.scroll-pin {
  width: 13px; height: 13px; border-radius: 50%;
  background: #4a4138; border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px rgba(0,0,0,.12), 0 1px 4px rgba(0,0,0,.28);
  cursor: pointer; transition: transform .12s ease, background .12s ease;
}
.scroll-pin:hover { transform: scale(1.35); }
.scroll-pin.active {
  background: var(--seal); transform: scale(1.4);
  box-shadow: 0 0 0 3px rgba(178,58,44,.22), 0 2px 7px rgba(0,0,0,.32);
}

/* ── 지도: 컨트롤·팝업 테마 ── */
.leaflet-bar { border: none !important; box-shadow: 0 1px 6px rgba(60,50,35,.18); border-radius: 9px; overflow: hidden; }
.leaflet-control-zoom a {
  width: 34px; height: 34px; line-height: 34px; font-size: 19px;
  background: var(--surface); color: var(--ink); border-bottom: 1px solid var(--rule) !important;
}
.leaflet-control-zoom a:hover { background: var(--surface-2); color: var(--seal); }
.leaflet-popup-content-wrapper { background: var(--surface); color: var(--ink); border-radius: 9px; box-shadow: 0 2px 12px rgba(60,50,35,.22); }
.leaflet-popup-content { margin: 11px 14px; font-family: var(--serif); font-size: 13.5px; line-height: 1.4; }
.leaflet-popup-tip { background: var(--surface); }
.leaflet-container { font-family: var(--sans); }
.leaflet-control-attribution { background: rgba(251,248,241,.78) !important; color: var(--ink-faint); font-size: 10.5px; }
.leaflet-control-attribution a { color: var(--ink-soft); }

/* ── 스크롤바 ── */
#panel::-webkit-scrollbar { width: 10px; }
#panel::-webkit-scrollbar-thumb { background: var(--rule); border-radius: 99px; border: 3px solid var(--surface); }

/* ── 반응형 ── */
@media (max-width: 780px) {
  #layout { flex-direction: column; }
  /* column에선 flex-basis(0)가 height를 무시해 지도가 0px로 접힘 — basis를 48vh로 고정 */
  #map { flex: 0 0 48vh; height: 48vh; }
  #panel { width: 100%; border-left: none; border-top: 1px solid var(--rule); }
  .person { padding: 26px 22px 44px; }
  .person-name { font-size: 29px; }
  .hq-text { font-size: 20px; }
}
