:root {
  --red: #9E1B32;
  --ember: #5C0F1D;
  --brass: #9A7A45;
  --paper: #FAF8F6;
  --ink: #1C1416;
  --cold: #35566A;
  --muted: #6A5C60;
  --line: #E4DCD8;
  --white: #FFFFFF;
  --serif-ko: 'Diphylleia', 'Noto Serif KR', serif;
  --sans: 'Noto Sans KR', system-ui, -apple-system, 'Apple SD Gothic Neo', sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', monospace;
  --wordmark: 'Bodoni Moda', 'Didot', serif;
  --gutter: 16px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
button, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
.num { font-family: var(--mono); font-weight: 500; font-variant-numeric: tabular-nums; }

/* 머리 */
.top {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) var(--gutter) 12px;
  background: var(--red); color: var(--paper);
}
.brand { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.wordmark { font-family: var(--wordmark); font-weight: 600; font-size: 13px; letter-spacing: 0.22em; }
.top h1 { margin: 0; font-family: var(--serif-ko); font-weight: 400; font-size: 24px; line-height: 1.2; }
.meta { margin: 0; font-size: 12px; text-align: right; opacity: 0.92; }
.demo-banner { padding: 8px var(--gutter); background: var(--ink); color: var(--paper); font-size: 13px; }

/* 조작 */
.controls {
  position: sticky; top: 0; z-index: 20;
  display: flex; flex-direction: column; gap: 10px;
  padding: 12px var(--gutter);
  background: var(--paper); border-bottom: 1px solid var(--line);
}
.seg { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--ink); }
.seg button {
  min-height: 40px; border: 0; background: transparent; font-weight: 500;
}
.seg button + button { border-left: 1px solid var(--ink); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 calc(-1 * var(--gutter)); padding: 0 var(--gutter); }
.chips::-webkit-scrollbar { display: none; }
.chips button {
  flex: 0 0 auto; min-height: 36px; padding: 0 12px;
  border: 1px solid var(--line); background: var(--white); font-size: 14px; white-space: nowrap;
}
.chips button[aria-pressed="true"] { border-color: var(--red); background: var(--red); color: var(--paper); }

/* 본문 배치 */
.layout { display: flex; flex-direction: column; }
.map-wrap { position: relative; height: 46vh; min-height: 260px; max-height: 520px; background: #EDE7E3; }
.map { position: absolute; inset: 0; }
.locate {
  position: absolute; right: 12px; bottom: 12px; z-index: 500;
  min-height: 40px; padding: 0 14px; border: 1px solid var(--ink); background: var(--white); font-weight: 500;
}
.map-error { position: absolute; inset: auto 12px 64px 12px; z-index: 500; margin: 0; padding: 10px 12px; background: var(--white); border: 1px solid var(--line); font-size: 13px; }

.list-wrap { padding: 0 var(--gutter) calc(24px + env(safe-area-inset-bottom)); }
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 14px 0 10px; font-size: 14px; }
#count { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sort { flex: 0 0 auto; display: flex; align-items: center; color: var(--muted); font-size: 13px; }
.sort select { min-height: 36px; padding: 0 8px; border: 1px solid var(--line); background: var(--white); border-radius: 0; color: var(--ink); }
.hidden-note { margin: 0 0 8px; font-size: 13px; color: var(--muted); }

.list { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.item { border-bottom: 1px solid var(--line); }
.item button {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; width: 100%;
  padding: 14px 0; border: 0; background: transparent; text-align: left;
}
.item button[aria-current="true"] { box-shadow: inset 3px 0 0 var(--red); padding-left: 10px; }
.item-name { font-weight: 700; font-size: 16px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-dist { font-size: 13px; color: var(--muted); }
.item-sub { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }
.item-temps { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 14px; }
.tt { display: inline-flex; align-items: baseline; gap: 6px; }
.tt-label { font-size: 12px; color: var(--muted); }
.hot { color: var(--red); }
.cold { color: var(--cold); }
.none { color: var(--muted); font-family: var(--sans); font-size: 12px; font-weight: 400; }

.empty { padding: 32px 0; text-align: left; }
.empty h2 { margin: 0 0 8px; font-family: var(--serif-ko); font-weight: 400; font-size: 26px; }
.empty p { margin: 0 0 12px; color: var(--muted); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 16px;
  border: 1px solid var(--ink); background: var(--white); text-decoration: none; font-weight: 500;
}
.btn-primary { background: var(--red); border-color: var(--red); color: var(--paper); }

.foot { margin-top: 24px; font-size: 12px; color: var(--muted); }
.foot p { margin: 0 0 8px; }

/* 지도 표식 */
.pin {
  position: relative; display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 7px; background: var(--white); border: 1.5px solid var(--red);
  font-family: var(--mono); font-weight: 500; font-size: 12px; line-height: 1.3; color: var(--ink);
  white-space: nowrap; transform: translate(-50%, calc(-100% - 7px)); cursor: pointer;
}
.pin::after {
  content: ''; position: absolute; left: 50%; bottom: -7px; width: 0; height: 0; transform: translateX(-50%);
  border-left: 6px solid transparent; border-right: 6px solid transparent; border-top: 7px solid var(--red);
}
.pin.name { font-family: var(--sans); font-weight: 500; }
.pin.sel { background: var(--red); color: var(--paper); z-index: 10; }
.pin.sel .cold, .pin.sel .hot { color: var(--paper); }
.pin .sep { color: var(--muted); }
.pin.sel .sep { color: var(--paper); }
.me { width: 14px; height: 14px; background: var(--cold); border: 3px solid var(--white); box-shadow: 0 0 0 1px var(--cold); transform: translate(-50%, -50%); border-radius: 50%; }
.leaflet-div-icon-reset { background: none; border: 0; }
.leaflet-container { font-family: var(--sans); background: #EDE7E3; }

/* 상세 시트 */
.sheet-backdrop { position: fixed; inset: 0; z-index: 900; background: rgba(28, 20, 22, 0.45); }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000;
  max-height: 88vh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--paper); border-top: 3px solid var(--red);
  padding: 18px var(--gutter) calc(20px + env(safe-area-inset-bottom));
}
.sheet:focus { outline: none; }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.sheet-kicker { font-size: 13px; color: var(--muted); }
.sheet h2 { margin: 2px 0 0; font-family: var(--serif-ko); font-weight: 400; font-size: 28px; line-height: 1.2; }
.close { flex: 0 0 auto; width: 44px; height: 44px; border: 1px solid var(--line); background: var(--white); display: inline-flex; align-items: center; justify-content: center; }
.facts { margin: 12px 0 0; font-size: 14px; }
.facts div { display: flex; gap: 10px; padding: 4px 0; }
.facts dt { flex: 0 0 64px; color: var(--muted); }
.facts dd { margin: 0; min-width: 0; }

.cmp { width: 100%; margin-top: 16px; border-collapse: collapse; table-layout: fixed; background: var(--white); border: 1px solid var(--line); }
.cmp th, .cmp td { padding: 10px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; font-size: 14px; }
.cmp thead th { font-size: 13px; font-weight: 700; background: var(--paper); }
.cmp tbody th { width: 72px; font-weight: 400; color: var(--muted); font-size: 13px; }
.cmp .big { font-size: 22px; line-height: 1.1; }
.cmp .small { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.diff { display: inline-block; margin-left: 4px; padding: 0 4px; border: 1px solid var(--brass); color: var(--brass); font-size: 11px; font-family: var(--sans); font-weight: 500; vertical-align: 2px; }
.src { display: inline-block; padding: 1px 6px; font-size: 12px; font-weight: 500; }
.src-실측 { background: var(--red); color: var(--paper); }
.src-제보 { border: 1px solid var(--ink); }
.src-업장 { border: 1px solid var(--muted); color: var(--muted); }
.stale { display: block; margin-top: 4px; color: var(--brass); font-size: 12px; }
.note { margin: 12px 0 0; font-size: 13px; color: var(--muted); }
.note b { color: var(--ink); font-weight: 500; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 18px; }
.actions .wide { grid-column: 1 / -1; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 1100; transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 10px 14px; background: var(--ink); color: var(--paper); font-size: 14px;
}

@media (min-width: 900px) {
  .top, .controls { padding-left: 24px; padding-right: 24px; }
  .controls { flex-direction: row; align-items: center; }
  .seg { flex: 0 0 280px; }
  .chips { margin: 0; padding: 0; }
  .layout { flex-direction: row-reverse; height: calc(100vh - 140px); }
  .map-wrap { flex: 1 1 auto; height: auto; max-height: none; }
  .list-wrap { flex: 0 0 400px; overflow-y: auto; padding: 0 24px 24px; border-right: 1px solid var(--line); }
  .sheet { left: auto; right: 24px; bottom: 24px; width: 420px; border: 1px solid var(--line); border-top: 3px solid var(--red); }
}

@media (prefers-reduced-motion: no-preference) {
  .sheet:not([hidden]) { animation: up 0.18s ease-out; }
  @keyframes up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
}

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.is-empty .controls, .is-empty .map-wrap, .is-empty .list-head { display: none; }
.is-empty .list { border-top: 0; }

/* 시설 지도 */
.muted { color: var(--muted); }
.dot {
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
  transform: translate(-50%, -50%); cursor: pointer;
}
.dot::after { content: ''; width: 12px; height: 12px; box-sizing: border-box; background: var(--white); border: 2.5px solid var(--red); }
.dot.has::after { background: var(--red); border: 2px solid var(--white); box-shadow: 0 0 0 1px var(--red); }
.cluster {
  min-width: 32px; height: 32px; padding: 0 6px; display: inline-flex; align-items: center; justify-content: center;
  background: var(--red); color: var(--paper); border: 2px solid var(--paper); box-shadow: 0 0 0 1px var(--red);
  font-family: var(--mono); font-weight: 500; font-size: 13px; transform: translate(-50%, -50%);
}
.item-tags { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; }
.tag { padding: 0 6px; border: 1px solid var(--line); background: var(--white); font-size: 12px; line-height: 20px; }
.tag-red { border-color: var(--red); background: var(--red); color: var(--paper); }
.more { width: 100%; margin-top: 12px; }
.ask { margin-top: 16px; padding: 14px; background: var(--white); border: 1px solid var(--line); border-left: 3px solid var(--brass); }
.ask p { margin: 0; font-size: 14px; color: var(--muted); }
.ask .ask-title { margin-bottom: 4px; color: var(--ink); font-weight: 700; }
.src-note { margin: 14px 0 0; font-size: 12px; color: var(--muted); }
.facts .muted { font-size: 12px; }
.seg[hidden], .chips button[hidden] { display: none; }
