:root {
  --off-campus: #f5f3ee;
  --ink: #2b2a27;
  --quiet: #6e6a62;
  --faint: #928d84;
  --line: #ded9ce;
  --hair: #ece8e0;
  --panel: #ffffff;
  --sunken: #f7f5f0;
  --shortcut: #e11d48;
  --spot: #2563eb;
  --danger: #b91c1c;
  --panel-w: 352px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }

body {
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', Pretendard,
    'Noto Sans KR', 'Malgun Gothic', sans-serif;
  color: var(--ink);
  background: var(--off-campus);
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

#map { position: absolute; inset: 0; }
#map.drawing { cursor: crosshair; }

h1, h2, h3 { margin: 0; letter-spacing: -0.015em; }
[hidden] { display: none !important; }

/* ───────── 버튼 ───────── */

.btn {
  font: inherit;
  font-weight: 550;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

.btn:hover:not(:disabled) { background: var(--sunken); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fbfaf7; }
.btn.primary:hover:not(:disabled) { background: #43413c; border-color: #43413c; }
.btn.danger { color: var(--danger); border-color: #e7c9c9; }
.btn.small { padding: 5px 10px; font-size: 12.5px; }
.btn.wide { width: 100%; }
.btn[aria-pressed="false"] { color: var(--faint); }

/* ───────── 상단 바 ───────── */

.topbar {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top, 0px));
  left: 12px;
  right: calc(var(--panel-w) + 24px);
  z-index: 6;
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}

.brand {
  pointer-events: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 14px;
  box-shadow: 0 1px 3px rgb(0 0 0 / 8%);
}

.brand h1 { font-size: 15px; font-weight: 680; }
.brand p { margin: 1px 0 0; font-size: 11.5px; color: var(--quiet); }
.topbar .btn { pointer-events: auto; box-shadow: 0 1px 3px rgb(0 0 0 / 10%); }

/* ───────── 패널 ───────── */

.panel {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top, 0px));
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  width: var(--panel-w);
  z-index: 7;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 2px 12px rgb(0 0 0 / 10%);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.grabber { display: none; }

.view {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.view[data-view="detail"],
.view[data-view="building"],
.view[data-view="register"] { padding: 14px 16px 20px; gap: 10px; }

.view h2 { font-size: 17px; font-weight: 680; }

.back {
  align-self: flex-start;
  border: 0;
  background: none;
  font: inherit;
  font-size: 12.5px;
  color: var(--quiet);
  cursor: pointer;
  padding: 2px 0;
}

.back:hover { color: var(--ink); }

.section-label {
  font-size: 11.5px;
  font-weight: 650;
  color: var(--quiet);
  letter-spacing: 0.02em;
  margin-top: 6px;
}

/* ───────── 필터 ───────── */

.filters { padding: 12px 14px 0; display: grid; gap: 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  font: inherit;
  font-size: 12.5px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--quiet);
  border-radius: 999px;
  padding: 4px 11px;
  cursor: pointer;
}

.chip:hover { background: var(--sunken); }
.chip.is-on { background: var(--ink); border-color: var(--ink); color: #fbfaf7; }
.chips.tags .chip { font-size: 12px; padding: 3px 10px; }
.chips.readonly .chip { cursor: default; background: var(--sunken); color: var(--quiet); }

.listbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--hair);
  font-size: 12px;
  color: var(--quiet);
}

.listbar #list-count { font-weight: 600; color: var(--ink); }
.toggle { display: flex; align-items: center; gap: 4px; cursor: pointer; margin-left: auto; }
.toggle input { margin: 0; }

#sort {
  font: inherit;
  font-size: 12px;
  color: var(--quiet);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px 4px;
  background: var(--panel);
}

/* ───────── 카드 ───────── */

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

.card {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--hair);
  padding: 11px 14px 11px 18px;
  cursor: pointer;
  position: relative;
}

.card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 4px;
  background: var(--spot);
}

.card[data-kind="shortcut"]::before { background: var(--shortcut); }
.card:hover, .card.is-active { background: var(--sunken); }
.card-title { font-weight: 620; font-size: 13.5px; }
.card-meta { font-size: 11.5px; color: var(--quiet); margin-top: 2px; }

.empty { padding: 22px 16px; text-align: center; color: var(--quiet); font-size: 13px; }
.empty-title { font-weight: 620; color: var(--ink); margin: 0 0 4px; }
.empty p { margin: 0 0 14px; }
.empty-inline { font-size: 12.5px; color: var(--quiet); padding: 4px 0; margin: 0; }

/* ───────── 상세 ───────── */

.meta { margin: 0; font-size: 12px; color: var(--quiet); }
.body { margin: 0; white-space: pre-wrap; font-size: 13.5px; }
.body:empty { display: none; }

.place-note {
  margin: 0;
  font-size: 13px;
  background: var(--sunken);
  border-left: 3px solid var(--spot);
  border-radius: 0 6px 6px 0;
  padding: 8px 11px;
}

.gallery { display: grid; gap: 8px; }
.gallery:empty { display: none; }

.gallery figure { margin: 0; }
.gallery img, .gallery video {
  width: 100%;
  border-radius: 8px;
  display: block;
  background: var(--sunken);
}

.gallery figcaption { font-size: 11px; color: var(--faint); margin-top: 3px; }

.actions { display: flex; gap: 8px; margin-top: 4px; }
.fineprint { font-size: 11.5px; color: var(--faint); margin: 0; }

/* ───────── 등록 ───────── */

.mode {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  margin-bottom: 8px;
}

.mode:hover { background: var(--sunken); border-color: var(--faint); }
.mode strong { display: block; font-size: 14px; font-weight: 650; }
.mode span { display: block; font-size: 12px; color: var(--quiet); margin-top: 2px; }

.hint { margin: 0; font-size: 13px; color: var(--quiet); }

.picked {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  background: var(--sunken);
  border-radius: 8px;
  padding: 10px 12px;
}

.form { gap: 12px; }
.field { display: grid; gap: 4px; border: 0; padding: 0; margin: 0; }
.field > span { font-size: 12px; font-weight: 600; color: var(--quiet); }
.field em { font-style: normal; font-weight: 400; color: var(--faint); }

.field input[type="text"],
.field input[type="number"],
.field textarea {
  font: inherit;
  font-size: 13.5px;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--panel);
  width: 100%;
  resize: vertical;
}

.field input:focus, .field textarea:focus {
  outline: 2px solid #c9d6f0;
  outline-offset: -1px;
  border-color: var(--spot);
}

.field input[type="file"] { font-size: 12px; color: var(--quiet); }

.thumbs { list-style: none; margin: 0; padding: 0; display: flex; gap: 6px; flex-wrap: wrap; }
.thumbs:empty { display: none; }

.thumbs li { position: relative; }
.thumbs img, .thumbs .vid {
  width: 64px; height: 64px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--sunken);
  display: grid;
  place-items: center;
  font-size: 10px;
  color: var(--quiet);
}

.thumbs button {
  position: absolute;
  top: -5px; right: -5px;
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  color: var(--quiet);
  padding: 0;
}

.dup {
  border: 1px solid #e8d8a8;
  background: #fdf8ea;
  border-radius: 8px;
  padding: 10px 12px;
}

.dup-title { margin: 0 0 6px; font-size: 13px; font-weight: 650; }
.dup .cards .card { border-bottom: 0; padding: 7px 10px 7px 14px; border-radius: 6px; }
.dup .fineprint { margin-top: 6px; }

.form-error { margin: 0; font-size: 12.5px; color: var(--danger); }

/* ───────── 그리기 바 ───────── */

.drawbar {
  position: absolute;
  left: 50%;
  /* 출처 표기 줄 위로 띄운다 */
  bottom: calc(52px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 8;
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 12px;
  box-shadow: 0 2px 10px rgb(0 0 0 / 14%);
  font-size: 12.5px;
  max-width: calc(100vw - 24px);
}

.drawbar-actions { display: flex; gap: 6px; }
#draw-status { color: var(--quiet); white-space: nowrap; }

/* ───────── 범례 · 출처 ───────── */

.legend {
  position: absolute;
  left: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  z-index: 5;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: 0 1px 3px rgb(0 0 0 / 8%);
}

.legend h2 { font-size: 11.5px; font-weight: 650; color: var(--quiet); margin-bottom: 8px; }
.legend ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.legend li { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.legend li.sep { margin-top: 4px; padding-top: 8px; border-top: 1px solid var(--hair); }

.swatch { width: 22px; height: 12px; border-radius: 3px; flex: none; border: 1px solid rgb(0 0 0 / 12%); }
.swatch.line { height: 0; border: none; border-top-width: 3px; border-top-style: solid; border-radius: 0; }
.swatch.dashed { border-top-style: dashed; }
.swatch.dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgb(0 0 0 / 15%); }

.attribution {
  position: absolute;
  right: calc(var(--panel-w) + 24px);
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  z-index: 5;
  font-size: 11px;
  color: var(--quiet);
  background: rgb(255 255 255 / 85%);
  border-radius: 6px;
  padding: 3px 8px;
  margin: 0;
}

.attribution a { color: inherit; }

/* ───────── 버스 노선 ───────── */

.routes { display: flex; flex-wrap: wrap; gap: 6px; }

.route {
  font-size: 12.5px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  color: #0f766e;
  background: #e6f4f1;
  border: 1px solid #b8ddd6;
  border-radius: 6px;
  padding: 3px 9px;
}

.swatch.dot.bus { background: #0f766e; }

/* ───────── 건물 이름 라벨 ───────── */

.labels { position: absolute; inset: 0; z-index: 3; pointer-events: none; }

.label.bus {
  color: #0b5d56;
  font-size: 10.5px;
  font-weight: 600;
  text-shadow: 0 0 3px #fff, 0 0 2px #fff;
  transform: translate(-50%, 4px);
}

.label {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
  color: #f4f1ea;
  text-shadow: 0 1px 2px rgb(0 0 0 / 55%);
  white-space: nowrap;
  letter-spacing: -0.01em;
}

/* ───────── 좁은 화면: 패널을 하단 시트로 ───────── */

@media (max-width: 720px) {
  :root { --panel-w: auto; }

  .topbar { right: 12px; }
  .legend { display: none; }
  .attribution { right: 12px; bottom: auto; top: calc(66px + env(safe-area-inset-top, 0px)); }

  .panel {
    top: auto;
    left: 12px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    width: auto;
    max-height: 62vh;
    padding-top: 6px;
  }

  .panel.collapsed { max-height: 46px; }
  .panel.collapsed .view { visibility: hidden; }

  .grabber {
    display: block;
    width: 44px;
    height: 5px;
    border: 0;
    border-radius: 3px;
    background: var(--line);
    margin: 4px auto 6px;
    padding: 0;
    cursor: pointer;
    flex: none;
  }

  .drawbar { bottom: auto; top: calc(72px + env(safe-area-inset-top, 0px)); flex-wrap: wrap; justify-content: center; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
