:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-2: #f0eee8;
  --text: #1f2328;
  --text-2: #5b616b;
  --line: #dedbd2;
  --accent: #1f6f5c;
  --accent-ink: #ffffff;
  --accent-soft: #e2f0eb;
  --older: #7d838c;
  --ok: #1f7a3a;
  --ok-soft: #e3f3e7;
  --busy: #a24b12;
  --busy-soft: #fbeadf;
  --me: #2563eb;
  --radius-s: 8px;
  --radius-m: 12px;
  --radius-l: 20px;
  --shadow: 0 6px 24px rgba(20, 24, 30, 0.12);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171a;
    --surface: #1d2024;
    --surface-2: #262a30;
    --text: #e8e6e1;
    --text-2: #a3a8b0;
    --line: #343941;
    --accent: #5cc3a6;
    --accent-ink: #0d1f1a;
    --accent-soft: #1d3a32;
    --older: #8a909a;
    --ok: #6fd28d;
    --ok-soft: #1c3424;
    --busy: #f0a26d;
    --busy-soft: #3a2619;
    --me: #6b9bff;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #15171a;
  --surface: #1d2024;
  --surface-2: #262a30;
  --text: #e8e6e1;
  --text-2: #a3a8b0;
  --line: #343941;
  --accent: #5cc3a6;
  --accent-ink: #0d1f1a;
  --accent-soft: #1d3a32;
  --older: #8a909a;
  --ok: #6fd28d;
  --ok-soft: #1c3424;
  --busy: #f0a26d;
  --busy-soft: #3a2619;
  --me: #6b9bff;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans KR", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); }
button { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.layout {
  display: grid;
  grid-template-columns: minmax(340px, 400px) 1fr;
  height: 100dvh;
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.panel-head { padding: 16px 16px 12px; border-bottom: 1px solid var(--line); }
.panel-head h1 { margin: 0 0 12px; font-size: 18px; font-weight: 700; display: flex; gap: 8px; align-items: center; }
.panel-head h1 i { color: var(--accent); font-size: 22px; }

.search { display: flex; gap: 8px; }
.search input {
  flex: 1;
  min-width: 0;
  height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.icon-btn {
  width: 48px;
  height: 48px;
  border: 0;
  border-radius: var(--radius-m);
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 20px;
  background: var(--surface-2);
}
.icon-btn.primary { background: var(--accent); color: var(--accent-ink); }

.areas { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 10px; font-size: 13px; color: var(--text-2); }
.areas-label { display: inline-flex; align-items: center; gap: 4px; min-width: 0; }
.chip {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  font-size: 13px;
}
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--text); font-weight: 500; }
.chip.more { border-style: dashed; }

.panel-body { flex: 1; overflow-y: auto; padding: 16px; }
.hint { color: var(--text-2); margin: 0; }

.book { display: grid; grid-template-columns: 72px 1fr; gap: 12px; margin-bottom: 16px; }
.book img, .book .cover-empty {
  width: 72px;
  height: 100px;
  object-fit: cover;
  border-radius: var(--radius-s);
  background: var(--surface-2);
  display: grid;
  place-items: center;
  color: var(--text-2);
  font-size: 28px;
}
.book h2 { margin: 0; font-size: 16px; line-height: 1.35; }
.book .meta { color: var(--text-2); font-size: 13px; margin: 4px 0 0; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--accent-soft);
  color: var(--accent);
}
.badge.older { background: var(--surface-2); color: var(--text-2); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.busy { background: var(--busy-soft); color: var(--busy); }

.editions { grid-column: 1 / -1; margin: 4px 0 0; padding: 0; list-style: none; border: 1px solid var(--line); border-radius: var(--radius-m); overflow: hidden; }
.editions li { display: flex; justify-content: space-between; gap: 8px; padding: 8px 12px; font-size: 13px; border-top: 1px solid var(--line); }
.editions li:first-child { border-top: 0; background: var(--accent-soft); }
.editions .isbn { color: var(--text-2); font-variant-numeric: tabular-nums; }

.alternatives { margin-bottom: 16px; }
.alternatives h3 { font-size: 13px; color: var(--text-2); margin: 0 0 6px; font-weight: 500; }
.alternatives button {
  display: block;
  width: 100%;
  text-align: left;
  min-height: 48px;
  padding: 8px 12px;
  margin-bottom: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  background: var(--surface);
  cursor: pointer;
}
.alternatives button small { color: var(--text-2); display: block; }

.results-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.results-head h2 { margin: 0; font-size: 15px; }

.switch { display: inline-flex; align-items: center; gap: 8px; min-height: 48px; border: 0; background: none; cursor: pointer; font-size: 13px; color: var(--text-2); padding: 0; }
.switch-track { width: 36px; height: 20px; border-radius: 999px; background: var(--line); position: relative; transition: background .15s; }
.switch-thumb { position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch[aria-checked="true"] .switch-track { background: var(--accent); }
.switch[aria-checked="true"] .switch-thumb { transform: translateX(16px); }

.advice {
  border-radius: var(--radius-m);
  padding: 12px 14px;
  margin-bottom: 16px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.advice.relaxed { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.advice.tight, .advice.hard { background: var(--busy-soft); border-color: color-mix(in srgb, var(--busy) 35%, transparent); }
.advice.waiting { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.advice-main { display: flex; gap: 10px; align-items: flex-start; }
.advice-main > i { font-size: 22px; line-height: 1.4; color: var(--text-2); flex: none; }
.advice.relaxed .advice-main > i { color: var(--ok); }
.advice.tight .advice-main > i, .advice.hard .advice-main > i { color: var(--busy); }
.advice.waiting .advice-main > i { color: var(--accent); }
.advice-main p { margin: 0 0 4px; font-weight: 500; }
.advice-main p + p { font-weight: 400; }
.advice-facts { margin: 8px 0 0; padding: 8px 0 0; list-style: none; border-top: 1px solid var(--line); font-size: 13px; }
.advice-facts li + li { margin-top: 2px; }
.advice-note { margin: 6px 0 0; font-size: 12px; color: var(--text-2); }
.advice-call { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 10px; font-size: 13px; }
.advice-call .btn { min-height: 48px; }

.sort { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }

.lib-list { list-style: none; margin: 0; padding: 0; }
.lib {
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  padding: 12px;
  margin-bottom: 8px;
  cursor: pointer;
  background: var(--surface);
}
.lib.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.lib.unlocated { border-style: dashed; }
.lib-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.lib-name { font-weight: 500; }
.lib-dist { color: var(--text-2); font-size: 13px; white-space: nowrap; font-variant-numeric: tabular-nums; display: inline-flex; align-items: center; gap: 4px; }
.lib-addr { color: var(--text-2); font-size: 13px; margin: 2px 0 6px; overflow-wrap: anywhere; }
.lib-status { display: flex; gap: 6px; align-items: baseline; font-size: 13px; margin: 0 0 8px; color: var(--text-2); }
.lib-status i { font-size: 16px; position: relative; top: 2px; }
.lib-status.open { color: var(--ok); font-weight: 500; }
.lib-status.closing { color: var(--busy); font-weight: 500; }
.lib-status small { font-weight: 400; color: var(--text-2); }
.lib-status small.warn { color: var(--busy); }
.loan { margin-top: 8px; font-size: 13px; }
.loan small { display: block; color: var(--text-2); font-size: 12px; margin-top: 2px; }
.loan .badge { white-space: normal; }
.copies { margin: 4px 0 0; padding: 0 0 0 2px; list-style: none; color: var(--text-2); font-size: 12px; overflow-wrap: anywhere; }
.loan-unknown { display: inline-flex; gap: 4px; align-items: baseline; color: var(--text-2); margin-right: 6px; }
.lib-closed { margin-top: 8px; font-size: 12px; color: var(--text-2); overflow-wrap: anywhere; }
.lib-tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.lib-actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  cursor: pointer;
}
.empty { color: var(--text-2); padding: 12px 0; }

.panel-foot { padding: 10px 16px; font-size: 12px; color: var(--text-2); border-top: 1px solid var(--line); }

.map-wrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: var(--surface-2); }
.locate {
  position: absolute;
  right: 16px;
  bottom: 24px;
  z-index: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 48px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
  cursor: pointer;
}
.map-tip {
  position: absolute;
  left: 16px;
  right: 120px;
  bottom: 24px;
  z-index: 500;
  margin: 0;
  font-size: 12px;
  color: var(--text-2);
  pointer-events: none;
}

/* 지도 배경은 흐리게 눌러서 도서관 표시가 먼저 보이게 한다. */
.leaflet-tile-pane { filter: saturate(0.35) contrast(0.95); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) saturate(0.25) brightness(0.8) contrast(0.9); }
}
:root[data-theme="dark"] .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) saturate(0.25) brightness(0.8) contrast(0.9); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--text); border-radius: var(--radius-m); }
.leaflet-popup-content { margin: 12px 14px; font: inherit; font-size: 13px; }
.leaflet-popup-content b { font-size: 14px; }
.me-dot { width: 18px; height: 18px; border-radius: 50%; background: var(--me); border: 3px solid #fff; box-shadow: 0 0 0 6px color-mix(in srgb, var(--me) 25%, transparent); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 1000;
  max-width: calc(100vw - 32px);
  padding: 12px 16px;
  border-radius: var(--radius-m);
  background: var(--text);
  color: var(--bg);
  box-shadow: var(--shadow);
  font-size: 14px;
}

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: 42dvh 1fr; height: auto; min-height: 100dvh; }
  .map-wrap { grid-row: 1; position: sticky; top: 0; height: 42dvh; z-index: 1; }
  .panel { grid-row: 2; border-right: 0; border-top: 1px solid var(--line); border-radius: var(--radius-l) var(--radius-l) 0 0; margin-top: -16px; position: relative; z-index: 2; }
  .panel-body { overflow: visible; }
  .map-tip { display: none; }
  .locate { bottom: 28px; }
}
