:root {
  --paper: #f5f7f8;
  --surface: #ffffff;
  --ink: #15212c;
  --muted: #5b6874;
  --rule: #dbe2e7;
  --land: #e3e9ed;
  --land-edge: #c9d3da;
  --ring: #6f97bd;
  --route: #b0136e;
  --route-soft: rgba(176, 19, 110, 0.12);
  --focus: #2f6fb0;

  --display: 'Barlow Condensed', 'IBM Plex Sans KR', system-ui, sans-serif;
  --body: 'IBM Plex Sans KR', system-ui, -apple-system, sans-serif;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0f1820;
    --surface: #16222c;
    --ink: #e6edf2;
    --muted: #93a3b1;
    --rule: #263541;
    --land: #1d2b36;
    --land-edge: #2f4150;
    --ring: #5d87ad;
    --route: #f0559f;
    --route-soft: rgba(240, 85, 159, 0.16);
    --focus: #7fb2e5;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.6;
}

a { color: inherit; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---------- 레이아웃: 기본은 가운데 본문 한 단 ---------- */
/* 광고 자리는 <html class="ads-on">일 때만 보임. 그 전에는 공간도 차지하지 않음 */

.page {
  display: grid;
  grid-template-columns: minmax(0, 760px);
  justify-content: center;
  gap: 48px;
  padding: 0 24px;
}

.rail, .ad-slot { display: none; }

.rail { padding-top: 32px; }

.rail .ad-slot {
  position: sticky;
  top: 24px;
}

.ad-tall { width: 160px; min-height: 600px; }
.ad-inline { min-height: 100px; margin: 64px 0 0; }

/* 데스크톱(1200px 이상): 광고 | 본문 | 광고 */
@media (min-width: 1200px) {
  .ads-on .page { grid-template-columns: 160px minmax(0, 760px) 160px; }
  .ads-on .rail, .ads-on .rail .ad-slot { display: block; }
}

/* 그보다 좁으면 양쪽 광고 대신 설명 글 아래 배너 하나 */
@media (max-width: 1199px) {
  .page { padding: 0 16px; }
  .ads-on .ad-inline { display: block; }
}

.main { padding: 24px 0 48px; min-width: 0; }

/* ---------- 상단 ---------- */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 40px;
}

.brand-title { margin: 0; font: inherit; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-weight: 600;
  font-size: 17px;
  letter-spacing: -0.01em;
}

.brand svg { width: 26px; height: 26px; fill: none; stroke: var(--route); stroke-width: 2; }
.brand .dot { fill: var(--route); stroke: none; }

.lang { display: flex; gap: 2px; }

.lang button {
  font: inherit;
  font-size: 13px;
  color: var(--muted);
  background: none;
  border: 0;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.lang button[aria-pressed="true"] { color: var(--ink); background: var(--surface); box-shadow: inset 0 0 0 1px var(--rule); }

/* ---------- 출발/도착 입력 ---------- */

.route {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 8px;
}

.field { position: relative; min-width: 0; }

.field label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 6px 2px;
}

.field input {
  width: 100%;
  font: inherit;
  font-size: 17px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 12px 14px;
}

.field input::placeholder { color: var(--muted); opacity: 0.8; }

.field input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 18%, transparent); }

.swap {
  width: 44px;
  height: 48px;
  display: grid;
  place-items: center;
  background: none;
  border: 0;
  border-radius: 10px;
  color: var(--muted);
  cursor: pointer;
}

.swap:hover { color: var(--ink); background: var(--surface); }
.swap svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.suggest {
  position: absolute;
  z-index: 10;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(21, 33, 44, 0.12);
  max-height: 340px;
  overflow-y: auto;
}

.suggest li {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 4px 10px;
  align-items: baseline;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.suggest li[aria-selected="true"] { background: var(--route-soft); }

.suggest .code { font-family: var(--display); font-weight: 600; font-size: 18px; letter-spacing: 0.02em; }
.suggest .place { font-size: 15px; }
.suggest .sub { grid-column: 2; font-size: 12px; color: var(--muted); margin-top: -4px; }
.suggest .empty { display: block; color: var(--muted); font-size: 14px; cursor: default; }

/* ---------- 결과 ---------- */

.result {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px 32px;
  margin: 48px 0 24px;
}

.readout { min-width: 0; }

.duration {
  margin: 0;
  font-family: var(--display);
  font-weight: 600;
  font-size: clamp(56px, 11vw, 96px);
  line-height: 0.95;
  letter-spacing: -0.01em;
}

.duration .approx {
  display: block;
  font-family: var(--body);
  font-weight: 500;
  font-size: 15px;
  letter-spacing: 0;
  color: var(--muted);
  margin-bottom: 8px;
}

.duration.is-empty { font-size: clamp(40px, 7vw, 56px); }

.route-line { margin: 12px 0 0; color: var(--muted); font-size: 15px; }

.facts { display: flex; flex-wrap: wrap; gap: 12px 32px; margin: 0; }
.facts div { min-width: 0; }
.facts dt { font-size: 13px; color: var(--muted); }
.facts dd { margin: 2px 0 0; font-family: var(--display); font-weight: 500; font-size: 26px; line-height: 1.2; }
.facts dd.note { margin: 0; font-family: var(--body); font-size: 12px; color: var(--muted); }

/* ---------- 지도 ---------- */

.chart { margin: 0 0 40px; }

.map-wrap { position: relative; }

#map { display: block; width: 100%; height: auto; cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; border-radius: 12px; border: 1px solid var(--rule); }
#map.is-dragging { cursor: grabbing; }
#map:focus-visible { outline-offset: 4px; }
#map[data-pointer]:focus { outline: none; }

.map-controls {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.map-controls button {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--rule);
  border-radius: 10px;
  cursor: pointer;
}

.map-controls button:hover { border-color: var(--muted); }
.map-controls svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.map-controls #recenter { color: var(--muted); }
.map-controls #recenter.is-active { color: var(--route); border-color: var(--route); }

#map .ocean { fill: var(--surface); }
#map .rings, #map .ring-labels, #map .route, #map .pins, #map .land { pointer-events: none; }
#map .land { fill: var(--land); stroke: var(--land-edge); stroke-width: 0.6; }
#map .ring { fill: none; stroke: var(--ring); stroke-width: 0.8; stroke-dasharray: 2 4; opacity: 0.7; }
#map .ring.major { stroke-dasharray: none; opacity: 0.45; }
#map .ring-label { fill: var(--ring); font-family: var(--display); font-weight: 500; }
#map .halo { stroke: var(--surface); stroke-width: 4; stroke-linejoin: round; paint-order: stroke; }
#map .spot { cursor: pointer; outline: none; }
#map .spot .hit { fill: transparent; }
#map .spot .dot { fill: var(--muted); opacity: 0.6; }
#map .spot text { fill: var(--muted); }
#map .spot:hover .dot, #map .spot:focus-visible .dot { fill: var(--route); opacity: 1; }
#map .spot:hover text, #map .spot:focus-visible text { fill: var(--route); }
#map .spot:focus-visible .hit { fill: none; stroke: var(--focus); stroke-width: 2; }
#map .route { fill: none; stroke: var(--route); stroke-width: 2.5; stroke-linecap: round; }
#map .pin { fill: var(--route); }
#map .pin-ring { fill: var(--surface); stroke: var(--route); stroke-width: 2.5; }
#map .pin-label { fill: var(--ink); font-family: var(--display); font-weight: 600; }

.chart figcaption { margin-top: 12px; font-size: 13px; color: var(--muted); max-width: 60ch; }

/* ---------- 주요 도시 ---------- */

.popular h2 { font-size: 17px; font-weight: 600; margin: 0 0 12px; }

.popular-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  column-gap: 32px;
}

.popular-list button {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font: inherit;
  color: inherit;
  text-align: left;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--rule);
  padding: 10px 2px;
  cursor: pointer;
}

.popular-list button:hover .city { color: var(--route); }
.popular-list .time { font-family: var(--display); font-weight: 500; font-size: 18px; color: var(--muted); white-space: nowrap; }

/* ---------- 설명 글 ---------- */

/* 두 언어를 모두 HTML에 넣어 두고 지금 언어만 보여 줌 */
html[lang="ko"] .i18n-block:not([lang="ko"]),
html[lang="en"] .i18n-block:not([lang="en"]) { display: none; }

.guide {
  margin-top: 64px;
  padding-top: 40px;
  border-top: 1px solid var(--rule);
  font-size: 15px;
  line-height: 1.75;
}

.guide h2 { font-size: 20px; font-weight: 600; line-height: 1.4; margin: 48px 0 12px; }
.guide h2:first-child { margin-top: 0; }
.guide h3 { font-size: 16px; font-weight: 600; line-height: 1.5; margin: 28px 0 6px; }
.guide p, .guide ul, .guide ol { margin: 0 0 14px; max-width: 64ch; }
.guide ul, .guide ol { padding-left: 1.3em; }
.guide li { margin-bottom: 8px; }
.guide li::marker { color: var(--muted); }
.guide strong { font-weight: 600; }
.guide a { color: var(--route); text-underline-offset: 3px; }
.guide a::after { content: ' →'; }
.guide code { font-size: 0.92em; background: var(--surface); border: 1px solid var(--rule); border-radius: 4px; padding: 1px 5px; overflow-wrap: anywhere; }

.formula {
  font-family: var(--display);
  font-weight: 500;
  font-size: 19px;
  line-height: 1.4;
  padding: 14px 18px;
  background: var(--surface);
  border-left: 3px solid var(--route);
  border-radius: 0 8px 8px 0;
}

.foot { margin-top: 48px; font-size: 13px; color: var(--muted); }
.foot p { margin: 0 0 6px; max-width: 64ch; }
.foot-links { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.foot-more { margin-top: 10px; }

@media (max-width: 560px) {
  .map-controls { right: 8px; bottom: 8px; gap: 4px; }
  .map-controls button { width: 34px; height: 34px; border-radius: 8px; }
  .top { margin-bottom: 28px; }
  .route { grid-template-columns: 1fr; }
  .swap { justify-self: end; height: 32px; margin: -4px 0 -12px; transform: rotate(90deg); }
  .result { margin-top: 36px; }
  .facts { gap: 24px; }
}

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