:root {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --ink: #1a1d21;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #ef4444;
  --brand-ink: #fff;
  --road: #3b82f6;
  --trail: #10b981;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 4px 16px rgba(0, 0, 0, 0.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ---------- header ---------- */
header.nav {
  display: flex; align-items: center; gap: 18px;
  padding: 12px 20px; background: var(--panel);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 600;
}
.logo { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 18px; }
.logo .mark { font-size: 22px; }
.nav .links { display: flex; gap: 16px; margin-left: auto; align-items: center; }
.nav .links a { color: var(--muted); font-size: 14px; font-weight: 600; }
.nav .links a.active, .nav .links a:hover { color: var(--ink); }
.btn-key { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 7px 12px; font-size: 13px; font-weight: 600; }

/* ---------- layout ---------- */
#app { height: calc(100vh - 57px); }
.home { display: grid; grid-template-columns: 420px 1fr; height: 100%; }
.sidebar { overflow-y: auto; border-right: 1px solid var(--line); background: var(--panel); }
#map { height: 100%; }

.sidebar .head { padding: 18px 18px 6px; }
.sidebar h1 { font-size: 20px; margin: 0 0 4px; }
.sidebar h1 b { color: var(--brand); }
.sidebar .sub { color: var(--muted); font-size: 13px; margin: 0 0 12px; }

/* filters */
.filters { padding: 0 18px 12px; border-bottom: 1px solid var(--line); }
.filters .row { margin-bottom: 12px; }
.filters label { font-size: 11px; font-weight: 700; color: var(--muted); letter-spacing: .04em; display: block; margin-bottom: 6px; }
.chips { display: flex; gap: 8px; }
.chip { border: 1px solid var(--line); background: var(--bg); border-radius: 20px; padding: 6px 14px; font-size: 13px; font-weight: 600; color: var(--muted); }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.filters input[type=search] { width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; }
.filters input[type=range] { width: 100%; }
.range-val { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; }

/* course list */
.list { padding: 8px 12px 24px; }
.count { font-size: 12px; color: var(--muted); padding: 8px 6px; }
.card { display: block; border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 10px; background: var(--panel); transition: .15s; }
.card:hover { box-shadow: var(--shadow); transform: translateY(-1px); border-color: #d1d5db; }
.card .t { font-weight: 700; font-size: 15px; margin-bottom: 6px; display: flex; align-items: center; gap: 8px; }
.tag { font-size: 10px; font-weight: 800; padding: 2px 7px; border-radius: 5px; color: #fff; letter-spacing: .03em; }
.tag.road { background: var(--road); } .tag.trail { background: var(--trail); }
.card .meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; }
.card .meta .dot::before { content: "·"; margin-right: 8px; }

/* ---------- detail ---------- */
.detail { max-width: 880px; margin: 0 auto; padding: 24px 20px 60px; overflow-y: auto; height: 100%; }
.detail .back { color: var(--muted); font-size: 13px; font-weight: 600; }
.detail h1 { font-size: 26px; margin: 12px 0 6px; }
.stats { display: flex; gap: 22px; color: var(--muted); font-size: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.stats b { color: var(--ink); }
.detail-map { height: 380px; border-radius: 14px; overflow: hidden; border: 1px solid var(--line); }
.actions { display: flex; gap: 10px; margin: 16px 0; flex-wrap: wrap; }
.actions a, .actions button { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 11px 16px; font-size: 14px; font-weight: 700; }
.actions .primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.actions .run { background: var(--ink); color: #fff; border-color: var(--ink); }
.section { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; margin-top: 16px; }
.section h3 { margin: 0 0 12px; font-size: 15px; }
.elev { width: 100%; height: 160px; }
.info-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.info-grid .k { font-size: 12px; color: var(--muted); }
.info-grid .v { font-size: 16px; font-weight: 700; }
.desc { color: #374151; line-height: 1.7; font-size: 14px; }

/* ---------- run mode (미리 달리기) ---------- */
.run-wrap { position: fixed; inset: 0; z-index: 1500; background: #0b0e12; color: #fff; display: flex; flex-direction: column; }
.run-stage { flex: 1; display: grid; grid-template-columns: 1fr 1fr; min-height: 0; }
.run-stage.single { grid-template-columns: 1fr; }
.run-pane { position: relative; overflow: hidden; }
.run-pane + .run-pane { border-left: 2px solid #000; }
#runmap3d { position: absolute; inset: 0; background: linear-gradient(#9ec4e8 0%, #cfe0ee 45%, #e9eef2 60%); }
.run-vignette { position: absolute; inset: 0; pointer-events: none; z-index: 3;
  box-shadow: inset 0 0 160px 40px rgba(0,0,0,.45); }
#roadview { width: 100%; height: 100%; background: #11151b; }
/* 실사 로드뷰 PIP — 메인 3D 위에 좌하단 작은 박스로 별도 표시 */
.rv-pip { position: absolute; left: 14px; bottom: 14px; z-index: 5;
  width: calc(280px * var(--pip-k, 1)); height: calc(188px * var(--pip-k, 1)); /* +/− 로 뷰포트 크기 조절 */
  border-radius: 12px; overflow: hidden; border: 2px solid rgba(255,255,255,.9);
  box-shadow: 0 8px 28px rgba(0,0,0,.5); background: #11151b; }
.rv-pip-label { position: absolute; top: 7px; left: 9px; z-index: 6; font-size: 11px; font-weight: 700;
  color: #fff; background: rgba(17,21,27,.72); padding: 3px 9px; border-radius: 11px; backdrop-filter: blur(3px); pointer-events: none; }
.rv-pip-size { position: absolute; top: 6px; right: 6px; z-index: 6; display: flex; gap: 4px; }
.rv-pip-size button { width: 26px; height: 26px; border-radius: 7px; background: rgba(17,21,27,.82);
  color: #fff; border: 1px solid rgba(255,255,255,.35); font-size: 17px; font-weight: 700; line-height: 1; cursor: pointer; }
.rv-pip-size button:hover { background: rgba(55,65,81,.95); }
.rv-pip-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  text-align: center; color: #9aa4b2; font-size: 13px; line-height: 1.5; }
/* 토글 켜짐 = 초록(hover 빨강과 구분되게). 켜짐 상태에선 hover도 초록 유지 */
.view-toggle.on, .view-toggle.on:hover { background: rgba(22,163,74,.95); border-color: rgba(255,255,255,.6); }

/* 뒷모습으로 달리는 캐릭터 마커(남/여) — 양팔·양다리가 교차하는 런 사이클 */
.runner { position: relative; width: 44px; height: 64px; --cad: 0.7s; --rs: 1; }
.runner-inner { position: absolute; inset: 0; transform: scale(var(--rs)); transform-origin: 50% 100%; }
/* 머리 위 체력/속도 게이지(헬스바): scaleX(--lvl) 1=100%, <1 줄어듦, >1 초과(내리막 부스트) */
.runner .stamina { position: absolute; left: 50%; top: -14px; margin-left: -19px; width: 38px; height: 8px; z-index: 4;
  background: rgba(0,0,0,.75); border: 1px solid #fff; outline: 1.5px solid #000; border-radius: 4px; overflow: visible; }
.runner .stamina-fill { width: 100%; height: 100%; border-radius: 3px; background: #facc15; transform-origin: left center;
  transform: scaleX(var(--lvl, 1)); transition: transform .14s linear, background .2s; }
.runner .stamina.tired { box-shadow: 0 0 5px 1px rgba(239,68,68,.75); }
.runner .stamina.boost { box-shadow: 0 0 7px 2px rgba(34,197,94,.95); animation: r-boost .5s ease-in-out infinite; }
@keyframes r-boost { 0%,100% { box-shadow: 0 0 7px 2px rgba(34,197,94,.95); } 50% { box-shadow: 0 0 12px 4px rgba(34,197,94,1); } }
/* 게이지 숫자/아이콘 라벨 — 검정 칩(가독성), 게이지와 간격 띄움 */
.runner .stamina-label { position: absolute; left: 50%; top: -34px; transform: translateX(-50%); white-space: nowrap;
  font-size: 10px; font-weight: 800; line-height: 1; color: #facc15; letter-spacing: -.02em; z-index: 5;
  background: rgba(10,12,16,.82); border: 1px solid rgba(255,255,255,.5); border-radius: 5px; padding: 2px 5px;
  text-shadow: 0 1px 1px rgba(0,0,0,.9); box-shadow: 0 1px 3px rgba(0,0,0,.6); }
/* 부스트(내리막) 잔상: 진행 반대(아래)로 초록 실루엣 트레일 */
.runner.boosting .runner-inner svg {
  filter: drop-shadow(0 5px 1px rgba(34,197,94,.5)) drop-shadow(0 11px 2px rgba(34,197,94,.3)) drop-shadow(0 17px 2px rgba(34,197,94,.15)); }
.runner svg { position: absolute; left: 0; bottom: 6px; animation: r-bob var(--cad) ease-in-out infinite; }
.runner .ground-shadow { position: absolute; left: 50%; bottom: 2px; margin-left: -11px; width: 22px; height: 7px; background: rgba(0,0,0,.35); border-radius: 50%; filter: blur(1px); animation: r-shadow var(--cad) ease-in-out infinite; }
.runner .limb { transform-box: fill-box; transform-origin: 50% 0%; }
.runner .leg-a, .runner .arm-b { animation: r-swingF var(--cad) ease-in-out infinite; }
.runner .leg-b, .runner .arm-a { animation: r-swingB var(--cad) ease-in-out infinite; }
@keyframes r-swingF { 0%,100% { transform: rotate(-24deg); } 50% { transform: rotate(24deg); } }
@keyframes r-swingB { 0%,100% { transform: rotate(24deg); } 50% { transform: rotate(-24deg); } }
@keyframes r-bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
@keyframes r-shadow { 0%,100% { transform: scale(1); opacity: .35; } 50% { transform: scale(.72); opacity: .2; } }

/* 러너 마커: 드론 아래 달리는 점 + 펄스 링 */
.run-runner { position: relative; width: 22px; height: 22px; }
.run-runner .dot { position: absolute; inset: 5px; border-radius: 50%; background: #fff;
  border: 3px solid #ef4444; box-shadow: 0 0 10px rgba(239,68,68,.9); }
.run-runner .ring { position: absolute; inset: 0; border-radius: 50%; border: 2px solid #ef4444;
  animation: runpulse 1.4s ease-out infinite; }
@keyframes runpulse { 0% { transform: scale(.6); opacity: .9; } 100% { transform: scale(2.6); opacity: 0; } }
.pane-label { position: absolute; top: 12px; left: 12px; z-index: 5; background: rgba(0,0,0,.55); padding: 5px 12px; border-radius: 20px; font-size: 12px; font-weight: 700; letter-spacing: .03em; }
.view-btns { position: absolute; top: 12px; right: 12px; z-index: 5; display: flex; gap: 8px; }
.view-toggle { background: rgba(17,21,27,.82); color: #fff; border: 1px solid rgba(255,255,255,.18); padding: 7px 13px; border-radius: 20px; font-size: 13px; font-weight: 700; backdrop-filter: blur(4px); }
.view-toggle:hover { background: rgba(55,65,81,.95); } /* 중립 밝기(빨강 X) — 켜짐 초록과 안 헷갈리게 */
.roadview-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 12px; text-align: center; padding: 30px; color: #9aa4b2; }
.roadview-empty button { margin-top: 6px; }

/* 1인칭 시점 마커(화살표) */
.run-marker { font-size: 26px; filter: drop-shadow(0 2px 4px rgba(0,0,0,.6)); }

/* HUD */
.run-hud { background: linear-gradient(#11151b, #0b0e12); border-top: 1px solid #1f2630; padding: 14px 22px 18px; }
.run-title { font-weight: 800; font-size: 16px; margin-bottom: 10px; display: flex; align-items: center; gap: 10px; }
.run-title .spd-cap { font-size: 12px; font-weight: 700; color: #8b97a6; background: #1f2630; padding: 4px 10px; border-radius: 14px; }
.run-title .close { margin-left: auto; background: #1f2630; border: none; color: #fff; border-radius: 8px; padding: 7px 14px; font-weight: 700; }
.run-elev { width: 100%; height: 64px; display: block; margin-bottom: 8px; cursor: pointer; }
.run-metrics .metric .v small { font-size: 12px; font-weight: 600; color: #6b7686; }
.progress { height: 8px; background: #1f2630; border-radius: 6px; overflow: hidden; margin-bottom: 10px; }
.progress .fill { height: 100%; width: 0; background: var(--brand); transition: width .12s linear; }
.run-metrics { display: flex; gap: 28px; align-items: center; }
.metric .k { font-size: 11px; color: #6b7686; font-weight: 700; }
.metric .v { font-size: 20px; font-weight: 800; }
.run-controls { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.run-controls button { background: #1f2630; border: none; color: #fff; border-radius: 8px; padding: 9px 14px; font-weight: 800; font-size: 14px; }
.run-controls button.play { background: var(--brand); }
.run-controls .speed, .run-controls .avatar-sel { display: flex; gap: 4px; }
.run-controls .avatar-sel button { padding: 9px 11px; font-size: 13px; }
.run-controls .avatar-sel button.on { background: var(--trail); }
.run-controls .speed button.on { background: var(--road); }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 2000; display: flex; align-items: center; justify-content: center; }
.modal { background: var(--panel); color: var(--ink); border-radius: 14px; padding: 24px; max-width: 460px; width: 90%; box-shadow: var(--shadow); }
.modal h3 { margin: 0 0 8px; }
.modal p { color: var(--muted); font-size: 14px; line-height: 1.6; }
.modal input { width: 100%; padding: 10px; border: 1px solid var(--line); border-radius: 8px; margin: 10px 0; font-size: 14px; }
.modal .row { display: flex; gap: 8px; justify-content: flex-end; }
.modal .row button { border-radius: 8px; padding: 9px 16px; font-weight: 700; border: 1px solid var(--line); background: var(--bg); }
.modal .row button.primary { background: var(--brand); color: #fff; border-color: var(--brand); }

@media (max-width: 860px) {
  .home { grid-template-columns: 1fr; grid-template-rows: 1fr 320px; }
  .sidebar { order: 2; border-right: none; border-top: 1px solid var(--line); }
  #map { order: 1; }
  /* 로드뷰 있을 때만 위/아래 2칸. 단일(드론뷰만)이면 한 칸이 꽉 차게 */
  .run-stage { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .run-stage.single { grid-template-rows: 1fr; }
  .run-pane + .run-pane { border-left: none; border-top: 2px solid #000; }
}

/* 폰: 드론뷰 HUD를 컴팩트하게 — 모든 버튼이 보이고 지도 영역을 넓게 */
@media (max-width: 600px) {
  .run-hud { padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); }
  .run-title { font-size: 13px; gap: 6px; margin-bottom: 6px; flex-wrap: wrap; }
  .run-title .spd-cap { order: 3; flex-basis: 100%; font-size: 10px; padding: 3px 8px; }
  .run-title .close { margin-left: auto; padding: 5px 11px; font-size: 12px; }
  .run-elev { height: 38px; margin-bottom: 6px; }
  .progress { margin-bottom: 8px; }
  .run-metrics { gap: 8px 10px; flex-wrap: wrap; }
  .run-metrics .metric { flex: 1 0 26%; }
  .run-metrics .metric .k { font-size: 10px; white-space: nowrap; }
  .run-metrics .metric .v { font-size: 15px; }
  .run-metrics .metric .v small { font-size: 10px; }
  .run-controls { margin-left: 0; flex-basis: 100%; flex-wrap: wrap; justify-content: space-between; gap: 6px; margin-top: 6px; }
  .run-controls > button { padding: 8px 12px; font-size: 13px; }
  .run-controls .avatar-sel button, .run-controls .speed button { padding: 7px 9px; font-size: 12px; }
  .view-btns { top: 8px; right: 8px; gap: 6px; }
  .view-toggle { padding: 6px 10px; font-size: 12px; }
  .pane-label { top: 8px; left: 8px; padding: 4px 9px; font-size: 11px; }
  .rv-pip { left: 8px; bottom: 8px; width: calc(168px * var(--pip-k, 1)); height: calc(116px * var(--pip-k, 1)); }
  .runner { --rs: 0.66; }   /* 모바일에서 캐릭터 작게 */
  /* 게이지/라벨은 역-스케일로 원래 크기 유지(가독성) — 위치는 머리 위 그대로 */
  .runner .stamina { transform: scale(calc(1 / var(--rs))); transform-origin: 50% 100%; }
  .runner .stamina-label { top: -46px; transform: translateX(-50%) scale(calc(1 / var(--rs))); transform-origin: 50% 100%; }
}
