:root {
  --bg: #0f172a;
  --card: #1e293b;
  --line: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --good: #4ade80;
  --bad: #f87171;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  padding: env(safe-area-inset-top) 16px calc(24px + env(safe-area-inset-bottom));
}
button { font-family: inherit; cursor: pointer; }

/* ---------- 헤더 ---------- */
header { padding: 16px 0 4px; }
.title-row { display: flex; align-items: center; gap: 8px; }
h1 { margin: 0; font-size: 22px; flex: 1; }
h2 { font-size: 17px; margin: 0; }
.sub { color: var(--muted); font-size: 12px; margin: 4px 0 8px; }
.hint { color: var(--muted); font-size: 13px; margin: 8px 0; line-height: 1.5; }
.hint a, .mode a { color: var(--accent); }

/* ---------- 공통 버튼 ---------- */
.icon-btn { background: none; border: 0; color: var(--text); font-size: 18px; padding: 6px 8px; flex: none; }
.primary {
  background: var(--accent); color: #0f172a; border: 0; border-radius: 10px;
  padding: 10px 16px; font-weight: 700; font-size: 15px;
}
.pill {
  background: var(--accent); color: #0f172a; border: 0; border-radius: 999px;
  padding: 6px 12px; font-weight: 700; font-size: 13px;
}
.text-btn { background: none; border: 0; color: var(--accent); font-size: 14px; padding: 6px 0; }
.text-btn.small { color: var(--muted); font-size: 12px; text-decoration: underline; }

/* ---------- 입장 코드 ---------- */
.gate { margin-top: 24px; }
.search { display: flex; gap: 8px; align-items: center; }
.gate input {
  flex: 1; min-width: 0; font-size: 16px; padding: 12px 14px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--text);
}

/* ---------- 출발/경유/목적지 카드 ---------- */
.route-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  margin-top: 8px; overflow: hidden;
}
.route-card .row {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: none; border: 0; color: var(--text); text-align: left;
  padding: 10px 8px 10px 14px; font-size: 15px; min-height: 48px;
}
.route-card .row + .row, .route-card .via li, .route-card .via + .row { border-top: 1px solid var(--line); }
.route-card .value { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.route-card input {
  flex: 1; min-width: 0; font-size: 16px; background: none; border: 0; color: var(--text); padding: 4px 0;
}
.route-card input:focus { outline: none; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot.start { background: var(--good); }
.dot.via { background: var(--muted); }
.dot.end { background: var(--bad); }

.via { list-style: none; padding: 0; margin: 0; }
.via li { display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 14px; font-size: 15px; min-height: 44px; }
.via .value { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.via button { background: none; border: 0; color: var(--muted); font-size: 15px; padding: 6px 8px; }

.route-tools { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 32px; }
.mode { color: var(--accent); font-size: 13px; margin: 0; }
.route-tools .text-btn { margin-left: auto; }

/* ---------- 집·회사·즐겨찾기 칩 (한 줄, 가로 스크롤) ---------- */
.chips {
  display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 8px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { display: none; }
.chips-inline { display: contents; }
.chip {
  flex: none; white-space: nowrap;
  background: var(--card); color: var(--text); border: 1px solid var(--line);
  border-radius: 999px; padding: 8px 14px; font-size: 14px;
}
.chip.empty { border-style: dashed; color: var(--muted); }
.chip.editing { border-style: dashed; color: var(--accent); }
.chip.ghost { background: none; color: var(--muted); }

/* ---------- 도착 기록 ---------- */
.trip {
  background: #1e3a5f; border: 1px solid var(--accent); border-radius: 14px;
  padding: 12px 14px 4px; margin: 4px 0 8px; font-size: 14px; line-height: 1.5;
}
.trip .hint { margin: 0; font-size: 12px; }
.trip-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.trip-row label { color: var(--muted); font-size: 13px; }
.trip-row input {
  font-size: 16px; padding: 6px 8px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
}

/* ---------- 검색 결과 / 최근 ---------- */
.places { list-style: none; padding: 0; margin: 0; }
.places li { padding: 11px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.places .name { font-size: 15px; }
.places .addr { color: var(--muted); font-size: 12px; margin-top: 2px; }
.section-label { color: var(--muted); font-size: 12px; margin: 12px 0 0; }

/* ---------- 비교 결과 ---------- */
#resultBox { margin-top: 4px; }
.dest-head { display: flex; align-items: center; gap: 2px; margin-bottom: 8px; }
.dest-head h2 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.star { color: #facc15; font-size: 22px; }

.results { list-style: none; padding: 0; margin: 0; }
.results li {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 14px; margin-bottom: 8px;
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: center;
}
.results li.first { border-color: var(--good); }
.results .who { font-weight: 700; font-size: 15px; }
.results .rank { color: var(--good); margin-right: 6px; }
.results .time { font-size: 22px; font-weight: 800; }
.results .diff { color: var(--bad); font-size: 13px; margin-left: 6px; font-weight: 600; }
.results .meta { color: var(--muted); font-size: 12px; grid-column: 1; }
.results .corr { color: var(--accent); }
.results .opt { color: #facc15; }
.results .go { grid-row: 1 / span 4; grid-column: 2; }
.results li.error { color: var(--muted); display: block; font-size: 13px; }

.others { display: flex; justify-content: flex-end; }
.others a { color: var(--muted); font-size: 13px; text-decoration: none; padding: 6px 0; }

.status { color: var(--muted); text-align: center; font-size: 13px; min-height: 18px; }

/* ---------- 전체 화면 시트 (내 기록 / 지도) ---------- */
.sheet { position: fixed; inset: 0; z-index: 10; background: var(--bg); display: flex; flex-direction: column; }
.sheet-top {
  display: flex; align-items: center; gap: 8px; font-weight: 700;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
}
.sheet-body { padding: 8px 16px; overflow-y: auto; }
.sheet-body table { width: 100%; border-collapse: collapse; font-size: 14px; }
.sheet-body th, .sheet-body td { text-align: left; padding: 10px 4px; border-bottom: 1px solid var(--line); }
.sheet-body th { color: var(--muted); font-weight: 400; font-size: 12px; }

.map-wrap { flex: 1; position: relative; }
.map { position: absolute; inset: 0; }
/* 핀 끝이 지도 정중앙(= 선택 좌표)에 오도록 */
.map-pin {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -100%);
  font-size: 36px; line-height: 1; pointer-events: none; z-index: 2;
}
.map-here {
  position: absolute; right: 12px; bottom: 12px; z-index: 3;
  width: 48px; height: 48px; border-radius: 50%; border: 1px solid #cbd5e1;
  background: #fff; color: #2563eb; font-size: 24px; line-height: 1;
  box-shadow: 0 2px 6px rgba(0, 0, 0, .3);
}
.map-here.loading { opacity: .5; }
.me-dot {
  width: 16px; height: 16px; border-radius: 50%; background: #2563eb;
  border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(37, 99, 235, .25);
}
.map-bottom {
  display: flex; gap: 10px; align-items: center;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: var(--card);
}
.map-addr { flex: 1; min-width: 0; font-size: 14px; }
