:root {
  --bg: #fbf8f2;
  --surface: #ffffff;
  --surface-alt: #f4ede1;
  --text: #222222;
  --text-muted: #5f574f;
  --accent: #7a4b1e;
  --accent-strong: #5e3712;
  --accent-soft: #f1e5d6;
  --border: #e2d8ca;
  --shadow: 0 6px 24px rgba(34, 24, 14, 0.14);
  --tip-bg: #fdf3e2;
  --tip-border: #d49b4b;
  --verse-bg: #f6efe4;
  --topbar-h: 58px;
  --radius: 12px;
  --font-sans: "Noto Sans KR", "Apple SD Gothic Neo", sans-serif;
  --font-serif: "Noto Serif KR", serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #181614;
    --surface: #221f1c;
    --surface-alt: #2b2723;
    --text: #ece7df;
    --text-muted: #b0a79b;
    --accent: #d49b5c;
    --accent-strong: #e3b27a;
    --accent-soft: #382c20;
    --border: #3a342e;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
    --tip-bg: #2e261c;
    --tip-border: #a67434;
    --verse-bg: #29241e;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 17px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

.hidden {
  display: none !important;
}

/* Top bar */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1100;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
}

.topbar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--topbar-h);
  padding: 6px 12px;
}

.app-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
  flex-shrink: 0;
}

.search-wrap {
  position: relative;
  flex: 1 1 180px;
  min-width: 110px;
}

.search-input {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
}

.search-input:focus {
  border-color: var(--accent);
}

.search-results {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 1200;
}

.search-item {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.search-item:last-child {
  border-bottom: 0;
}

.search-item:hover,
.search-item:focus-visible {
  background: var(--surface-alt);
}

.search-item-title {
  font-weight: 600;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.search-item-region {
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 500;
  flex-shrink: 0;
}

.search-item-match {
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.top-btn {
  min-height: 44px;
  min-width: 44px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-alt);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.top-btn:hover,
.top-btn:focus-visible {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.icon-btn {
  padding: 0 10px;
  font-size: 1.15rem;
}

@media (max-width: 640px) {
  .topbar-row {
    flex-wrap: wrap;
    padding: 6px 10px;
  }

  .app-title {
    font-size: 1rem;
  }

  .search-wrap {
    order: 3;
    flex: 1 0 100%;
  }

  .topbar-actions {
    margin-left: auto;
  }

  .top-btn {
    padding: 0 10px;
    font-size: 0.85rem;
  }
}

/* Main & Map */
.main {
  position: relative;
  width: 100%;
  height: 100%;
}

.map {
  width: 100%;
  height: 100%;
  background: var(--surface-alt);
}

.leaflet-top {
  top: calc(var(--topbar-h) + env(safe-area-inset-top) + 8px);
}

@media (max-width: 640px) {
  .leaflet-top {
    top: calc(108px + env(safe-area-inset-top) + 8px);
  }
}

.leaflet-tooltip.lbl {
  background: rgba(255, 255, 255, 0.92);
  color: #222;
  border: 1px solid rgba(122, 75, 30, 0.35);
  border-radius: 6px;
  padding: 2px 6px;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
  white-space: nowrap;
}

.leaflet-tooltip.lbl::before {
  display: none;
}

@media (prefers-color-scheme: dark) {
  .leaflet-tooltip.lbl {
    background: rgba(34, 31, 28, 0.92);
    color: #ece7df;
    border-color: rgba(212, 155, 92, 0.45);
  }
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 1500;
  max-width: min(90vw, 420px);
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(34, 31, 28, 0.92);
  color: #fff;
  font-size: 0.92rem;
  text-align: center;
  box-shadow: var(--shadow);
}

/* Backdrop */
.panel-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1150;
  background: rgba(0, 0, 0, 0.35);
}

/* Close button */
.close-btn {
  min-width: 44px;
  min-height: 44px;
  border: 0;
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--text);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.close-btn:hover {
  background: var(--accent-soft);
}

/* Side panel (목록 / 가까운 성지 / 설정) */
.side-panel {
  position: fixed;
  top: calc(var(--topbar-h) + env(safe-area-inset-top));
  left: 0;
  bottom: 0;
  width: min(100vw, 420px);
  z-index: 1250;
  background: var(--bg);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
  transition: transform 0.22s ease;
}

@media (max-width: 640px) {
  .side-panel {
    top: calc(108px + env(safe-area-inset-top));
    width: 100vw;
    border-right: 0;
  }
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.panel-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
}

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  overscroll-behavior: contain;
}

/* List / Nearby / Settings styles */
.region-block {
  margin-bottom: 22px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.region-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.region-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.region-name {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 700;
}

.region-en {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.region-intro summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.92rem;
}

.region-intro p {
  margin: 6px 0 10px;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.area-heading {
  margin: 12px 0 6px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent);
}

.site-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.site-list-btn {
  width: 100%;
  min-height: 44px;
  padding: 9px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.site-list-btn:hover {
  background: var(--surface-alt);
}

.site-list-name {
  font-weight: 600;
}

.site-list-sub {
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Settings */
.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.settings-card h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.settings-stat {
  margin: 4px 0;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.primary-btn,
.secondary-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  border: 1px solid transparent;
}

.primary-btn {
  background: var(--accent);
  color: #fff;
}

.primary-btn:hover {
  background: var(--accent-strong);
}

.primary-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.secondary-btn {
  background: var(--surface-alt);
  border-color: var(--border);
  color: var(--text);
}

.secondary-btn:hover {
  background: var(--accent-soft);
}

.full-btn {
  width: 100%;
  margin-top: 10px;
}

.progress-wrap {
  margin-top: 12px;
}

.progress-bar-bg {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: var(--surface-alt);
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.15s linear;
}

.progress-text {
  margin: 6px 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.credits-note {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-top: 12px;
}

/* Detail panel */
.detail-panel {
  position: fixed;
  z-index: 1200;
  background: var(--bg);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  transition: transform 0.24s ease;
}

/* Desktop: right-side panel 460px wide */
@media (min-width: 800px) {
  .detail-panel {
    top: calc(var(--topbar-h) + env(safe-area-inset-top));
    right: 0;
    bottom: 0;
    width: 460px;
    border-left: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .drag-handle {
    display: none;
  }
}

/* Mobile: bottom sheet ~92% screen height */
@media (max-width: 799px) {
  .detail-panel {
    left: 0;
    right: 0;
    bottom: 0;
    height: 92vh;
    height: 92dvh;
    border-top-left-radius: 18px;
    border-top-right-radius: 18px;
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
  }

  .drag-handle {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px 0 4px;
    cursor: grab;
    touch-action: none;
  }

  .drag-bar {
    width: 42px;
    height: 5px;
    border-radius: 999px;
    background: var(--border);
  }
}

.detail-close {
  position: absolute;
  top: 10px;
  right: 12px;
  z-index: 10;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 0 0 28px;
  overscroll-behavior: contain;
}

.hero-figure {
  margin: 0;
  background: var(--surface-alt);
}

.hero-img {
  display: block;
  width: 100%;
  max-height: 260px;
  object-fit: cover;
  cursor: pointer;
}

.hero-caption {
  padding: 6px 16px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.detail-inner {
  padding: 16px 18px 0;
}

.detail-title {
  margin: 0;
  font-size: 1.55rem;
  line-height: 1.3;
  font-weight: 800;
  padding-right: 48px;
}

.detail-en {
  margin: 4px 0 10px;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.region-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.85rem;
  font-weight: 600;
}

.detail-refs {
  margin: 0 0 14px;
  font-size: 0.92rem;
  color: var(--accent);
  font-weight: 600;
}

.verse-card {
  background: var(--verse-bg);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 12px 14px;
  margin: 14px 0;
}

.verse-quote {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.05rem;
  line-height: 1.7;
}

.verse-ref {
  margin: 6px 0 0;
  font-size: 0.88rem;
  color: var(--text-muted);
  text-align: right;
  font-weight: 600;
}

.look-block p {
  margin: 0 0 10px;
}

.tip-box {
  background: var(--tip-bg);
  border: 1px solid var(--tip-border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin: 14px 0;
  font-size: 0.95rem;
}

.tip-label {
  display: block;
  font-weight: 700;
  color: var(--accent-strong);
  margin-bottom: 4px;
}

.section-heading {
  margin: 24px 0 12px;
  font-size: 1.15rem;
  font-weight: 700;
  border-bottom: 2px solid var(--accent-soft);
  padding-bottom: 4px;
}

/* Points */
.point-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}

.point-header {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 8px;
}

.point-no {
  min-width: 28px;
  height: 28px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.point-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.4;
}

.point-en {
  margin: 2px 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.point-refs {
  margin: 4px 0 8px;
  font-size: 0.86rem;
  color: var(--accent);
  font-weight: 600;
}

.point-text p {
  margin: 0 0 8px;
}

.photo-strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 6px 0 2px;
  scroll-snap-type: x proximity;
}

.photo-thumb-fig {
  margin: 0;
  flex: 0 0 180px;
  scroll-snap-align: start;
}

.photo-thumb-img {
  display: block;
  width: 180px;
  height: 126px;
  object-fit: cover;
  border-radius: 8px;
  cursor: pointer;
  background: var(--surface-alt);
}

.photo-thumb-cap {
  margin-top: 4px;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--text-muted);
}

/* Collapsible details */
.detail-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  margin-bottom: 10px;
  overflow: hidden;
}

.detail-section summary {
  min-height: 44px;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.detail-section summary::-webkit-details-marker {
  display: none;
}

.detail-section summary::after {
  content: "+";
  font-size: 1.2rem;
  color: var(--accent);
}

.detail-section[open] summary::after {
  content: "−";
}

.detail-section-content {
  padding: 0 14px 14px;
  border-top: 1px solid var(--border);
}

.detail-section-content p {
  margin: 10px 0 0;
}

.bible-entry {
  margin-top: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.bible-entry:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.bible-ref {
  font-weight: 700;
  color: var(--accent);
}

.bible-quote {
  margin: 4px 0;
  font-family: var(--font-serif);
}

.bible-note {
  margin: 4px 0 0;
  font-size: 0.92rem;
  color: var(--text-muted);
}

.names-dl {
  margin: 10px 0 0;
}

.names-dl dt {
  font-weight: 700;
  margin-top: 10px;
}

.names-dl dd {
  margin: 2px 0 0 0;
  color: var(--text-muted);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
  font-size: 0.9rem;
}

.data-table th,
.data-table td {
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.data-table th {
  font-weight: 700;
  color: var(--accent);
}

.check-list {
  margin: 10px 0 0;
  padding-left: 20px;
}

.check-list li {
  margin-bottom: 6px;
}

.src-list {
  margin: 10px 0 0;
  padding-left: 18px;
  font-size: 0.84rem;
  line-height: 1.55;
  color: var(--text-muted);
}

.detail-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.detail-actions .primary-btn,
.detail-actions .secondary-btn {
  flex: 1;
}

/* Photo Viewer */
.photo-viewer {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(10, 10, 10, 0.95);
  color: #f5f5f5;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.pv-close {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top));
  right: calc(12px + env(safe-area-inset-right));
  z-index: 10;
  min-width: 44px;
  min-height: 44px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-size: 1.6rem;
  cursor: pointer;
}

.pv-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  min-width: 44px;
  min-height: 56px;
  border: 0;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 2rem;
  cursor: pointer;
}

.pv-prev {
  left: 10px;
}

.pv-next {
  right: 10px;
}

.pv-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 56px 16px 12px;
  overflow: hidden;
  touch-action: pan-y;
}

.pv-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 4px;
}

.pv-footer {
  padding: 10px 18px 16px;
  text-align: center;
  background: rgba(0, 0, 0, 0.5);
}

.pv-caption {
  margin: 0 0 4px;
  font-size: 0.95rem;
}

.pv-credit {
  margin: 0;
  font-size: 0.8rem;
  color: #ccc;
}

.pv-credit a {
  color: #f0c38e;
}
