/* 러닝 3D 재생 (route3d.php) — 지도 위 오버레이라 항상 어두운 판을 쓴다 (실사 지도는 테마와 무관) */
:root {
  --r3-bg: #0b0d09;
  --r3-ink: #ffffff;
  --r3-muted: rgba(255, 255, 255, 0.72);
  --r3-lime: #C6FF34;
  --r3-lime-ink: #0b1a00;
  --r3-scrim: rgba(8, 10, 6, 0.78);
  --r3-safe-top: env(safe-area-inset-top, 0px);
  --r3-safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--r3-bg);
  color: var(--r3-ink);
  font: 14px/1.35 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", system-ui, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

.r3-map { position: fixed; inset: 0; }
.r3-map gmp-map-3d { display: block; width: 100%; height: 100%; }

/* ── 위 카드 ── */
.r3-top {
  position: fixed; left: 0; right: 0; top: 0; z-index: 5;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: calc(var(--r3-safe-top) + 14px) 16px 28px;
  background: linear-gradient(to bottom, var(--r3-scrim), rgba(8, 10, 6, 0.45) 65%, transparent);
  pointer-events: none;
}
.r3-who { display: flex; align-items: center; gap: 12px; min-width: 0; }
.r3-avatar {
  flex: none; width: 52px; height: 52px; border-radius: 50%;
  object-fit: cover; border: 2px solid rgba(255, 255, 255, 0.9); background: #2a2e23;
}
.r3-avatar--blank {
  display: block;
  background: #2a2e23 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%239aa08e'%3E%3Cpath d='M12 12a5 5 0 1 0 0-10 5 5 0 0 0 0 10Zm0 2c-4.4 0-8 2.2-8 5v3h16v-3c0-2.8-3.6-5-8-5Z'/%3E%3C/svg%3E") center 60% / 62% no-repeat;
}
.r3-who-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.r3-name { font-size: 17px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r3-line {
  display: flex; align-items: flex-start; gap: 6px; font-size: 13px; color: var(--r3-ink);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}
/* 일시 · 시도명은 폭이 좁으면 두 줄까지 (시도명이 잘려 '서울'만 보이던 문제) */
.r3-line-text {
  min-width: 0; word-break: keep-all; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.r3-line--muted { color: var(--r3-muted); }
.r3-line--hr .r3-ico { color: #FF5A5F; }
.r3-ico { flex: none; width: 16px; height: 16px; margin-top: 1px; fill: currentColor; }
/*
 * 워드마크 — 시계 방향 90° 로 세워 오른쪽 끝에 (사진 재생과 같은 크기: 폰 화면 기준 길이 113 · 글자 높이 ≈ 10, 2026-10-15)
 * 회전 전 왼쪽 위를 축으로 돌리고 자기 폭만큼 오른쪽으로 민다 → 오른쪽 여백 안쪽에 세로로 선다. 윗선 = 프로필 윗선.
 */
.r3-logo {
  position: absolute; top: calc(var(--r3-safe-top) + 14px); right: 16px; width: 113px; height: auto;
  transform-origin: top left; transform: translateX(100%) rotate(90deg);
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.6));
}
/* 세운 로고 자리만큼 글자 영역을 비운다 */
.r3-who { margin-right: 22px; }
.is-app .r3-who { margin-right: 0; }

/* ── 아래 판 ── */
.r3-bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  padding: 36px 16px calc(var(--r3-safe-bottom) + 14px);
  background: linear-gradient(to top, var(--r3-scrim) 0%, rgba(8, 10, 6, 0.6) 70%, transparent);
}
.r3-graph-wrap { position: relative; height: 92px; margin-right: 58px; touch-action: none; cursor: pointer; }
.r3-graph { display: block; width: 100%; height: 100%; overflow: visible; }
.r3-graph:focus-visible { outline: 2px solid var(--r3-lime); outline-offset: 4px; border-radius: 4px; }
.r3-graph--flat { height: 24px; margin-top: 68px; }
.r3-cursor-dot {
  position: absolute; left: 0; top: 50%; width: 12px; height: 12px; border-radius: 50%;
  background: var(--r3-lime); border: 2px solid #fff; transform: translate(-50%, -50%);
  box-shadow: 0 0 8px rgba(198, 255, 52, 0.6); pointer-events: none;
}
.r3-alt {
  position: absolute; right: -58px; top: 0; bottom: 0; width: 52px;
  display: flex; flex-direction: column; justify-content: space-between; align-items: flex-end;
  font-size: 12px; color: var(--r3-muted); pointer-events: none;
  border-right: 1.5px solid rgba(255, 255, 255, 0.7); padding-right: 6px;
}
.r3-alt-label { text-align: right; line-height: 1.2; }
.r3-alt-label b { display: block; color: var(--r3-ink); font-weight: 600; }

.r3-stats { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-top: 14px; }
.r3-stat { display: flex; flex-direction: column; min-width: 0; }
.r3-stat:nth-child(2) { align-items: center; }
.r3-stat:nth-child(3) { align-items: flex-end; }
.r3-stat b {
  font-size: 26px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums;
  white-space: nowrap; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}
.r3-stat b small { font-size: 13px; font-weight: 600; color: var(--r3-muted); letter-spacing: 0; }
.r3-stat span { font-size: 12px; color: var(--r3-muted); margin-top: 2px; }

/* 고도 눈금(오른쪽)과 겹치지 않게 판 위로 띄운다 */
.r3-play {
  position: absolute; right: 16px; top: -30px;
  width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: var(--r3-lime); color: var(--r3-lime-ink);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
}
.r3-play svg { width: 22px; height: 22px; fill: currentColor; }
.r3-play:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }

.r3-cta {
  display: inline-block; color: var(--r3-lime-ink); background: var(--r3-lime);
  border-radius: 999px; padding: 9px 16px; font-weight: 700; font-size: 13px; text-decoration: none;
}
.r3-cta--bar { display: block; text-align: center; margin-top: 12px; }

.r3-error {
  position: fixed; left: 16px; right: 16px; top: 45%; z-index: 6;
  background: var(--r3-scrim); border-radius: 12px; padding: 14px 16px; text-align: center; font-size: 14px;
}

.r3-empty {
  min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; padding: 24px 16px; text-align: center; color: var(--r3-muted);
}
.r3-empty-logo { width: 160px; height: auto; }

@media (min-width: 900px) {
  .r3-top, .r3-bottom { padding-left: 32px; padding-right: 32px; }
  .r3-logo { right: 32px; }
  .r3-bottom { max-width: 760px; margin: 0 auto; border-radius: 16px 16px 0 0; }
  .r3-play { right: 32px; }
}
@media (max-width: 360px) {
  .r3-stat b { font-size: 21px; }
  .r3-logo { width: 104px; }
}

/* ── 공유 영상 만들기 (route3d-video.php) ── */
.r3v { overflow: auto; }
.r3v-main {
  min-height: 100%; display: flex; flex-direction: column; align-items: center; gap: 16px;
  padding: calc(var(--r3-safe-top) + 16px) 16px calc(var(--r3-safe-bottom) + 20px);
}
/* 미리보기 — 화면 높이에 맞춰 9:16 으로 줄인다 */
.r3v-canvas {
  width: auto; height: min(62vh, calc((100vw - 32px) * 16 / 9));
  aspect-ratio: 9 / 16; max-width: 100%;
  border-radius: 14px; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5); background: #0b0d09;
}
.r3v-status { width: 100%; max-width: 360px; text-align: center; }
.r3v-status p { margin: 0 0 10px; font-size: 15px; font-weight: 600; }
.r3v-bar { height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.15); overflow: hidden; }
.r3v-bar i { display: block; height: 100%; width: 0; background: var(--r3-lime); transition: width 0.2s linear; }
.r3v-actions { display: flex; gap: 10px; justify-content: center; margin-top: 16px; }
.r3v-actions .r3-cta { border: 0; cursor: pointer; font: inherit; font-weight: 700; }
/* 앱 안에서는 진행 상태·버튼을 앱이 그린다 (Route3DVideoModal) — 미리보기만 남긴다 */
.is-app .r3v-status { display: none; }
/* 대회 코스 3D 를 앱 WebView 로 열었을 때 — 사이트 이동 링크·앱 설치 판은 의미가 없다 */
.is-app .r3-course-nav, .is-app .r3-applayer { display: none !important; }
/* 앱 안에서는 상단 우측 워드마크도 뺀다 — 앱 자체가 랭킹크루라 중복 (2026-10-15 사용자 요청, 기록 3D·코스 3D 공통) */
.is-app .r3-logo { display: none; }
.is-app .r3v-main { justify-content: center; padding: 0; }
/* 앱 미리보기는 테두리·여백 없이 영역을 꽉 채운다 (둥근 카드에 갇혀 작아 보였다) */
.is-app .r3v-canvas {
  height: min(100vh, calc(100vw * 16 / 9)); max-width: 100vw;
  border-radius: 0; box-shadow: none;
}

/* ── MapLibre (Esri 위성 / 벡터) ── */
.r3-mlbox { position: absolute !important; inset: 0; }
.r3-mk { line-height: 0; cursor: default; }
.r3-mk svg { display: block; }
/* 출처 표기가 아래 판에 가리지 않게 판 위로 올린다 (출처는 화면에 보여야 한다) */
.r3-map .maplibregl-ctrl-bottom-right { bottom: calc(var(--r3-safe-bottom) + 250px); }
body:not(.is-app) .r3-map .maplibregl-ctrl-bottom-right { bottom: calc(var(--r3-safe-bottom) + 300px); }
/* 영상용 지도 — 화면에는 보이지 않게 그리고(1080×1920), 캔버스로 떠서 미리보기에 합성한다 */
.r3v-mapbox {
  position: fixed; left: 0; top: 0; width: 540px; height: 960px;
  opacity: 0; pointer-events: none; z-index: -1;
}

/* ── 대회 코스 3D (marathon-course.php) ── */
.r3-course .r3-name { margin: 0; font-size: 17px; line-height: 1.3; white-space: normal;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.r3-avatar--poster { border-radius: 10px; object-fit: cover; }
/* 누르기 전 시작 버튼 — 지도 자리 가운데 */
.r3-start {
  position: fixed; left: 50%; top: 44%; transform: translate(-50%, -50%); z-index: 6;
  display: flex; align-items: center; gap: 12px; padding: 14px 22px 14px 16px;
  border: 0; border-radius: 999px; cursor: pointer; font: inherit;
  background: var(--r3-lime); color: var(--r3-lime-ink); box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
}
.r3-start svg { width: 34px; height: 34px; fill: currentColor; flex: none; }
.r3-start span { display: flex; flex-direction: column; align-items: flex-start; text-align: left; }
.r3-start b { font-size: 17px; font-weight: 800; }
.r3-start small { font-size: 12px; opacity: 0.8; }
.r3-start:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
.r3-start[hidden] { display: none; }
/* 지도를 불러오기 전 바탕 — 검은 화면 대신 옅은 격자 */
.r3-course .r3-map {
  background:
    radial-gradient(ellipse at 50% 45%, rgba(198, 255, 52, 0.08), transparent 60%),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.04) 0 1px, transparent 1px 48px),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.04) 0 1px, transparent 1px 48px),
    var(--r3-bg);
}
.r3-course-nav { display: flex; gap: 8px; margin-top: 12px; }
.r3-course-nav a {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  padding: 10px 12px; border-radius: 999px; font-size: 13px; font-weight: 700; text-decoration: none;
  color: var(--r3-ink); background: rgba(255, 255, 255, 0.14);
}
.r3-course-nav a:last-child { background: var(--r3-lime); color: var(--r3-lime-ink); }
.r3-course-nav svg { width: 16px; height: 16px; fill: currentColor; }
.r3-source { margin: 8px 0 0; font-size: 11px; color: var(--r3-muted); text-align: center; }
/* 시작 전에는 재생 버튼을 숨긴다 — '3D 코스 보기'와 같이 보이면 둘 중 무엇을 누를지 헷갈린다 */
.r3-start:not([hidden]) ~ .r3-bottom .r3-play { display: none; }
/* 포스터가 없을 때 — 사람 모양 대신 경로 아이콘 */
.r3-course .r3-avatar--blank {
  border-radius: 10px;
  background: #2a2e23 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23C6FF34'%3E%3Cpath d='M4 15V8.5a4.5 4.5 0 0 1 9 0v7a2.5 2.5 0 0 0 5 0V8.8a3 3 0 1 1 2 0v6.7a4.5 4.5 0 0 1-9 0v-7a2.5 2.5 0 0 0-5 0V15h3l-4 5-4-5h3Z'/%3E%3C/svg%3E") center / 56% no-repeat;
}

/* 속도 범례 — 아래 판 왼쪽 위 (속도 버튼은 오른쪽) */
.r3-legend {
  position: absolute; left: 16px; top: 8px; display: flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 600; color: var(--r3-muted); text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); pointer-events: none;
}
.r3-legend i { display: block; width: 64px; height: 4px; border-radius: 2px; }
@media (min-width: 900px) { .r3-legend { left: 32px; } }

/* 재생 속도 버튼 (0.5× · 1× · 2×) — 재생 버튼과 같은 줄 왼쪽 */
.r3-speed {
  position: absolute; right: 72px; top: -22px; display: flex; gap: 2px; padding: 3px;
  border-radius: 999px; background: rgba(8, 10, 6, 0.72); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}
.r3-speed button {
  border: 0; border-radius: 999px; padding: 6px 10px; min-width: 40px; cursor: pointer;
  font: inherit; font-size: 13px; font-weight: 700; color: var(--r3-muted); background: transparent;
}
.r3-speed button[aria-pressed="true"] { background: var(--r3-lime); color: var(--r3-lime-ink); }
.r3-speed button:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }
/* 대회 코스: 시작 전에는 속도 버튼도 숨긴다 */
.r3-start:not([hidden]) ~ .r3-bottom .r3-speed { display: none; }
@media (min-width: 900px) { .r3-speed { right: 88px; } }

/* ── 도착 후 앱 다운로드 판 (marathon-course.php) — 아래 고도 판(.r3-bottom)과 같은 모양으로 그 위를 덮는다 ── */
.r3-applayer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 7;
  /* 위 52px(닫기 버튼 자리) · 아래 32px — 내용은 가운데 (아래로 붙이면 버튼 밑 여백이 없고 닫기 버튼과 사이가 너무 떴다) */
  padding: 52px 16px calc(var(--r3-safe-bottom) + 32px);
  /*
   * 단색 시트 + 둥근 위 모서리 — 아래 고도 판을 완전히 가린다(반투명이면 그래프·숫자가 비쳤다).
   * 위를 흐리게 했더니 닫기 버튼이 판과 지도 사이에 반쯤 걸쳐 어색했다 → 경계를 분명하게.
   */
  background: #0b0d09;
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.45);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  text-align: center; box-sizing: border-box;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  transform: translateY(100%); transition: transform .25s ease-out;
}
.r3-applayer.is-open { transform: translateY(0); }
.r3-applayer[hidden] { display: none; }
.r3-applayer-logo { width: 132px; height: auto; margin-bottom: 12px; }
.r3-applayer h2 { margin: 0 0 6px; font-size: 18px; font-weight: 800; line-height: 1.35; }
.r3-applayer p { margin: 0 auto 16px; max-width: 360px; font-size: 13px; color: var(--r3-muted); line-height: 1.5; }
.r3-applayer-stores { display: flex; gap: 10px; justify-content: center; width: 100%; }
.r3-store {
  flex: 1; max-width: 180px; display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 14px; border-radius: 12px; text-decoration: none;
  background: #000; color: #fff; border: 1px solid rgba(255, 255, 255, 0.35);
}
.r3-store:first-child { background: var(--r3-lime); color: var(--r3-lime-ink); border-color: var(--r3-lime); }
.r3-store svg { width: 24px; height: 24px; fill: currentColor; flex: none; }
.r3-store span { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.1; }
.r3-store small { font-size: 10px; opacity: 0.8; }
.r3-store b { font-size: 16px; font-weight: 800; }
.r3-applayer-close {
  /* 왼쪽 위 — 오른쪽에 두면 바로 위의 다시 재생 버튼과 붙어 잘못 누르기 쉽다 */
  position: absolute; left: 14px; top: 14px; width: 34px; height: 34px; border: 0; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer; background: rgba(255, 255, 255, 0.14); color: #fff;
}
.r3-applayer-close svg { width: 20px; height: 20px; fill: currentColor; }
.r3-applayer-close:focus-visible, .r3-store:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
@media (min-width: 900px) { .r3-applayer { max-width: 760px; margin: 0 auto; } }
