:root {
  --bg: #111418;
  --panel: #1b2027;
  --line: #2c333d;
  --text: #e8ecf1;
  --muted: #8b95a3;
  --accent: #3b8cff;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.3 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  overflow: hidden;
}

button, input { font: inherit; color: inherit; }
button {
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  white-space: nowrap;
  cursor: pointer;
}
button:active { filter: brightness(1.3); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
input:not([type=color]) {
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  min-width: 0;
}
.row { display: flex; gap: 8px; align-items: center; }
.grow { flex: 1; min-width: 0; }
.grow input { width: 100%; }

/* 지도 영역 */
#stage { position: relative; flex: 1; min-height: 0; }
#map { position: absolute; inset: 0; background: #0b0d10; }
/* 그리기 모드에서 한 손가락 드래그를 브라우저가 가로채지 않게 */
#map.leaflet-container { touch-action: none; }
/* 밝은 OSM 타일을 어두운 지도로 뒤집기 */
.leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9) saturate(.35); }
.leaflet-control-attribution { background: rgba(17, 20, 24, .75) !important; color: var(--muted) !important; }
.leaflet-control-attribution a { color: #b8c2cf !important; }
.leaflet-bar a { background: var(--panel) !important; color: var(--text) !important; border-color: var(--line) !important; }

/* 역 */
.stn-icon { background: none; border: none; }
.stn {
  width: 100%; height: 100%;
  border-radius: 50%;
  background: #fff;
  border: 4px solid var(--c);
  position: relative;
}
.stn.xfer { border-color: #1b1f24; box-shadow: 0 0 0 2px #fff; }
.lbl {
  position: absolute; left: 100%; top: 50%;
  transform: translateY(-50%);
  margin-left: 6px;
  font-size: 12px; font-weight: 600;
  white-space: nowrap;
  color: #fff;
  text-shadow: 0 0 3px #000, 0 0 3px #000;
  pointer-events: none;
}
.labels-off .lbl { display: none; }
.stations-off .stn-icon { display: none; }

/* 노선 점 핸들: 터치 영역은 크게, 보이는 점은 작게 */
.handle { background: none; border: none; }
.handle::after {
  content: ""; position: absolute; inset: 8px;
  border-radius: 50%;
  background: #111418; border: 3px solid #fff;
}
.handle.mid::after { inset: 11px; background: rgba(255, 255, 255, .55); border: 2px solid #111418; }
.handle.ext::after {
  content: "+"; inset: 6px;
  display: flex; align-items: center; justify-content: center;
  background: #fff; border-color: #111418; color: #111418;
  font: 700 18px/1 sans-serif;
}
/* 핸들을 끄는 동안 다른 보조 핸들은 숨김 */
.dragging .handle.mid:not(.leaflet-drag-target), .dragging .handle.ext:not(.leaflet-drag-target), .dragging .ext-line { display: none; }

/* 노선 편집 패널 */
#panel {
  position: absolute; left: 8px; right: calc(env(safe-area-inset-right) + 80px); bottom: calc(env(safe-area-inset-bottom) + 8px);
  max-width: 460px; /* 오른쪽 도구 칸은 비워 둠 */
  z-index: 1000;
  padding: 10px;
  display: grid; gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .5);
}
#panel[hidden] { display: none; }
#panel { max-height: 60%; overflow-y: auto; } /* 지도를 너무 가리지 않게 */
.count { min-width: 40px; text-align: center; color: var(--muted); }
#train-more summary { min-height: 44px; display: flex; align-items: center; color: var(--muted); cursor: pointer; }
#train-more > .row + .row, #train-more summary + .row { margin-top: 8px; }
.stepper button { width: 44px; padding: 0; font-size: 20px; }
.stepper output { min-width: 76px; text-align: center; }

/* 재생/배속 버튼 */
/* 상단 바가 없으니 노치(안전 영역)만큼 지도 위 버튼을 내린다 */
#playbar, #filebar { position: absolute; top: calc(env(safe-area-inset-top) + 10px); z-index: 1000; display: flex; gap: 6px; }
#playbar { right: calc(env(safe-area-inset-right) + 10px); }
#filebar { left: calc(env(safe-area-inset-left) + 56px); } /* 줌 버튼 오른쪽 */
#filebar button { background: rgba(27, 32, 39, .92); }
.leaflet-top { top: env(safe-area-inset-top); }
.leaflet-left { left: env(safe-area-inset-left); }
#playbar button { width: 52px; padding: 0; font-weight: 700; background: rgba(27, 32, 39, .92); }
/* 색은 한 줄로 옆으로 밀어서 고르기 (패널 높이를 줄여 지도를 덜 가림) */
#swatches { overflow-x: auto; scrollbar-width: none; }
#swatches::-webkit-scrollbar { display: none; }
#swatches > * { flex: none; }
.swatch, .custom {
  width: 44px; height: 44px; padding: 0;
  border-radius: 50%;
  border: 3px solid transparent;
  background: var(--c);
}
.swatch.on { border-color: #fff; }
.custom {
  position: relative; overflow: hidden; cursor: pointer;
  background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red);
}
.custom input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.seg button { flex: 1; }
.seg button.on, #modes button.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }

#toast {
  position: absolute; top: calc(env(safe-area-inset-top) + 64px); left: 50%; transform: translateX(-50%);
  z-index: 1001;
  padding: 10px 16px;
  border-radius: 10px;
  background: rgba(0, 0, 0, .85);
}

/* 도구: 지도 오른쪽 아래에 세로로 */
#tools {
  position: absolute; z-index: 1000;
  right: calc(env(safe-area-inset-right) + 10px);
  bottom: calc(env(safe-area-inset-bottom) + 10px);
  display: flex; flex-direction: column; align-items: flex-end; gap: 6px;
}
#tools button { background: rgba(27, 32, 39, .92); }
#tools button.primary { background: var(--accent); }
.act { display: none; }
body[data-mode=draw] .act.draw,
body[data-mode=erase] .act.erase,
body[data-mode=move] .act.erase { display: block; }
#modes { display: flex; flex-direction: column; gap: 6px; }
#modes button {
  width: 60px; min-height: 56px; padding: 4px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 12px;
}
#modes b { font-size: 20px; font-weight: normal; }
#tools #modes button.on { background: var(--accent); }
/* 안내문: 지도 왼쪽 아래, 도구 칸과 겹치지 않게 */
#hint {
  position: absolute; z-index: 999; pointer-events: none;
  left: calc(env(safe-area-inset-left) + 10px);
  right: calc(env(safe-area-inset-right) + 84px);
  bottom: calc(env(safe-area-inset-bottom) + 10px);
  color: var(--text); font-size: 12px;
  text-shadow: 0 0 3px #000, 0 0 3px #000;
}
.leaflet-bottom.leaflet-left { bottom: calc(env(safe-area-inset-bottom) + 40px); } /* 출처 표시는 안내문 위 */

/* 역 이름 입력창 */
dialog {
  width: min(360px, calc(100vw - 32px));
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, .55); }
dialog form { display: grid; gap: 12px; }
