:root {
  --ink: #f3f5ee; --muted: #b9c2b4; --glass: rgba(18, 26, 21, 0.58); --line: rgba(255, 255, 255, 0.16);
  --accent: #ffb454; --leaf: #b9dc8f;
  --font: "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #10160f; color: var(--ink); font-family: var(--font); -webkit-tap-highlight-color: transparent; }
body { overscroll-behavior: none; touch-action: none; user-select: none; -webkit-user-select: none; }
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
button, select, input { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* loading */
#loading { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: radial-gradient(120% 90% at 50% 10%, #2c4034 0%, #111810 70%); transition: opacity 0.7s ease, visibility 0.7s; }
#loading.done { opacity: 0; visibility: hidden; pointer-events: none; }
.load-card { width: min(420px, 84vw); text-align: center; }
.kicker { margin: 0; font-size: 11px; letter-spacing: 0.28em; color: var(--leaf); }
.load-card h1 { margin: 10px 0 4px; font-size: clamp(44px, 9vw, 68px); font-weight: 700; letter-spacing: -0.03em; }
.load-card h1 span { color: var(--accent); font-weight: 300; margin-left: 4px; }
.sub { margin: 0 0 28px; color: var(--muted); font-size: 15px; }
.load-track { height: 3px; background: rgba(255, 255, 255, 0.14); border-radius: 2px; overflow: hidden; }
#load-bar { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.25s ease; }
#load-text { margin: 12px 0 0; font-size: 12px; color: var(--muted); }

/* hud */
#hud { position: fixed; top: max(12px, env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right)); display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; pointer-events: none; z-index: 10; }
.card { background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px 12px; pointer-events: auto; }
.course-card { width: min(330px, 62vw); }
.course-name { all: unset; cursor: pointer; display: flex; align-items: baseline; gap: 6px; font-size: 17px; font-weight: 650; letter-spacing: -0.01em; }
.course-name i { font-style: normal; font-size: 11px; color: var(--muted); }
.progress { position: relative; height: 4px; margin: 9px 0 6px; background: rgba(255, 255, 255, 0.16); border-radius: 2px; }
#progress-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--accent); border-radius: 2px; }
#progress-marks i { position: absolute; top: -2px; width: 2px; height: 8px; background: rgba(255, 255, 255, 0.7); border-radius: 1px; }
.row { display: flex; justify-content: space-between; gap: 10px; margin: 0; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
#next-wp { text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stats { display: grid; grid-template-columns: repeat(4, auto); justify-content: space-between; gap: 4px 12px; margin: 9px 0 0; }
.stats dt { font-size: 10px; color: var(--muted); letter-spacing: 0.02em; }
.stats dd { margin: 1px 0 0; font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tools { display: flex; align-items: center; gap: 8px; pointer-events: auto; }
.tool { background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; font-size: 13px; cursor: pointer; }
.tool:hover { background: rgba(40, 54, 44, 0.8); }
#compass { position: relative; width: 150px; height: 30px; overflow: hidden; background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border: 1px solid var(--line); border-radius: 999px; }
#compass-strip { position: absolute; top: 0; left: 0; height: 100%; white-space: nowrap; font-size: 11px; line-height: 30px; color: var(--muted); will-change: transform; }
#compass-strip span { display: inline-block; width: 45px; text-align: center; }
#compass-strip span.c { color: var(--ink); font-weight: 700; }
#compass i { position: absolute; left: 50%; top: 0; width: 1px; height: 7px; background: var(--accent); }

#place { position: fixed; top: 22%; left: 50%; transform: translateX(-50%); z-index: 9; text-align: center; pointer-events: none; text-shadow: 0 2px 14px rgba(0, 0, 0, 0.7); animation: place 4.2s ease forwards; }
#place b { display: block; font-size: clamp(26px, 5vw, 40px); font-weight: 650; letter-spacing: 0.04em; }
#place small { font-size: 13px; color: #e6ead9; letter-spacing: 0.12em; }
@keyframes place { 0% { opacity: 0; transform: translate(-50%, 8px); } 12%, 78% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; } }

#labels { position: fixed; inset: 0; pointer-events: none; z-index: 5; overflow: hidden; }
#labels span { position: absolute; left: 0; top: 0; padding: 1px 7px; font-size: 11.5px; white-space: nowrap; color: #fff; text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9), 0 0 2px rgba(0, 0, 0, 0.9); will-change: transform; }
#labels span::after { content: ""; position: absolute; left: 50%; top: 100%; width: 1px; height: 12px; background: rgba(255, 255, 255, 0.7); }
#labels span small { opacity: 0.8; margin-left: 4px; font-size: 10px; }
#labels span.wp { color: var(--accent); font-weight: 600; }

#toast { position: fixed; left: 50%; bottom: 118px; transform: translateX(-50%); margin: 0; z-index: 12; background: var(--glass); backdrop-filter: blur(10px); border: 1px solid var(--line); border-radius: 999px; padding: 8px 16px; font-size: 13px; max-width: 86vw; text-align: center; }

#foot { position: fixed; left: 0; right: 0; bottom: max(14px, env(safe-area-inset-bottom)); z-index: 10; display: grid; justify-items: center; gap: 7px; pointer-events: none; }
#stamina { width: min(220px, 46vw); height: 5px; background: rgba(0, 0, 0, 0.4); border: 1px solid var(--line); border-radius: 3px; overflow: hidden; }
#stamina-fill { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #f0a24a, #b9dc8f); transition: width 0.2s linear; }
#badges { display: flex; gap: 6px; min-height: 22px; }
#badges span { background: var(--glass); border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; font-size: 11px; color: var(--muted); }
#badges #badge-auto { color: var(--accent); border-color: rgba(255, 180, 84, 0.5); }
#hint { margin: 0; font-size: 12px; color: #e3e7da; text-shadow: 0 1px 6px rgba(0, 0, 0, 0.85); text-align: center; padding: 0 12px; transition: opacity 0.6s; }
#hint b { font-weight: 600; background: rgba(0, 0, 0, 0.35); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
#hint.fade { opacity: 0; }

#stick { position: fixed; z-index: 11; width: 124px; height: 124px; margin: -62px 0 0 -62px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, 0.35); background: rgba(255, 255, 255, 0.07); opacity: 0; pointer-events: none; transition: opacity 0.15s; }
#stick.on { opacity: 1; }
#stick-knob { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%; background: rgba(255, 255, 255, 0.45); }
#touch-buttons { position: fixed; right: max(14px, env(safe-area-inset-right)); bottom: max(86px, calc(env(safe-area-inset-bottom) + 72px)); z-index: 11; display: grid; gap: 10px; }
#touch-buttons button { width: 62px; height: 62px; border-radius: 50%; background: var(--glass); border: 1px solid var(--line); font-size: 13px; }
#touch-buttons button.on { background: rgba(255, 180, 84, 0.35); border-color: var(--accent); }
#perf { position: fixed; right: 12px; bottom: 12px; z-index: 12; margin: 0; padding: 6px 9px; font: 11px/1.45 ui-monospace, Menlo, Consolas, monospace; background: rgba(0, 0, 0, 0.55); border-radius: 8px; color: #cfe6b8; pointer-events: none; }

/* dialogs */
dialog { border: 0; padding: 0; background: transparent; color: var(--ink); max-width: none; max-height: none; }
dialog::backdrop { background: rgba(8, 12, 9, 0.55); backdrop-filter: blur(3px); }
#fall-lookouts { margin-top: 14px; flex-wrap: wrap; }
#fall-view { inset: auto 0 max(16px, env(safe-area-inset-bottom)); margin: 0 auto; }
#fall-view::backdrop { background: transparent; backdrop-filter: none; }
#fall-view form { display: flex; align-items: center; flex-wrap: wrap; justify-content: center; gap: 10px; padding: 10px 14px; background: rgba(22, 30, 25, 0.94); border: 1px solid var(--line); border-radius: 12px; }
#fall-view a { color: var(--leaf); }
#fall-view button { min-height: 44px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: #314437; cursor: pointer; }
#fall-view button:hover { background: #415846; }
body:has(#fall-view[open]) :is(#hud, #foot, #gps, #place, #labels, #toast, #touch-buttons) { visibility: hidden; }
.sheet { width: min(420px, 94vw); max-height: 92vh; overflow: auto; background: rgba(22, 30, 25, 0.96); border: 1px solid var(--line); border-radius: 18px; padding: 18px 20px 20px; display: grid; gap: 13px; touch-action: pan-y; user-select: text; }
.sheet.wide { width: min(1120px, 96vw); }
.sheet header { display: flex; justify-content: space-between; align-items: center; }
.sheet h2 { margin: 0; font-size: 20px; }
.sheet h3 { margin: 14px 0 8px; font-size: 13px; color: var(--leaf); letter-spacing: 0.04em; }
.sheet header button { background: none; border: 0; font-size: 18px; cursor: pointer; padding: 6px; }
.sheet label { display: grid; gap: 6px; font-size: 12px; color: var(--muted); }
.sheet label.check { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 13px; }
.sheet select, .sheet input[type=range] { width: 100%; }
.sheet select { background: #26332a; border: 1px solid var(--line); border-radius: 9px; padding: 9px 10px; font-size: 14px; color: var(--ink); }
.sheet output { float: right; color: var(--ink); font-variant-numeric: tabular-nums; }
.sheet input[type=range] { accent-color: var(--accent); }
.note { margin: 0; font-size: 11.5px; line-height: 1.55; color: var(--muted); }
.credits { border-top: 1px solid var(--line); padding-top: 10px; font-size: 10.5px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.actions button { background: #2b382f; border: 1px solid var(--line); border-radius: 10px; padding: 9px 14px; font-size: 13px; cursor: pointer; }
.actions button.primary { background: var(--accent); color: #1c1407; border-color: transparent; font-weight: 600; }
.actions button:disabled { opacity: 0.45; cursor: default; }
.map-layout { display: grid; grid-template-columns: minmax(0, 1.9fr) minmax(220px, 1fr); gap: 20px; }
.map-wrap { border-radius: 12px; overflow: hidden; border: 1px solid var(--line); background: #0d130f; }
#map-canvas { display: block; width: 100%; height: auto; cursor: crosshair; touch-action: none; }
#profile-canvas { display: block; width: 100%; height: auto; margin-top: 10px; border-radius: 10px; background: #1a241d; cursor: crosshair; }
.map-layout .note { margin-top: 8px; }
.map-layout .actions { margin-top: 10px; }
#photos figure { margin: 0 0 12px; }
#photos img { width: 100%; border-radius: 10px; display: block; }
#photos figcaption { font-size: 11px; color: var(--muted); margin-top: 5px; line-height: 1.45; }
#photos a { color: var(--leaf); }
#photos button { margin-top: 6px; font-size: 12px; }

@media (max-width: 760px), (pointer: coarse) {
  #hint { display: none; }
  .stats dd { font-size: 13px; }
  .course-card { padding: 8px 11px 10px; }
  #compass { width: 104px; }
  .map-layout { grid-template-columns: 1fr; }
  #touch-buttons { display: grid; }
}
@media (max-width: 520px) {
  #hud { flex-direction: column; }
  .tools { align-self: flex-end; position: absolute; right: 0; top: 0; }
  .course-card { width: min(250px, 58vw); }
  #compass { display: none; }
  .stats { grid-template-columns: repeat(2, auto); }
}
@media (max-height: 480px) and (orientation: landscape) {
  .stats { display: none; }
  #toast { bottom: 70px; }
}

.pano-wrap { overflow-x: auto; border-radius: 12px; border: 1px solid var(--line); background: #0d130f; touch-action: pan-x; }
#pano-canvas { display: block; height: min(46vh, 420px); width: auto; }
.jump { margin-top: 10px; }
#zoom-ring { position: fixed; inset: 0; z-index: 6; pointer-events: none; box-shadow: inset 0 0 0 9999px rgba(0, 0, 0, 0); transition: box-shadow 0.25s; }
#zoom-ring.on { box-shadow: inset 0 0 160px 60px rgba(0, 0, 0, 0.55); }

#gps { position: fixed; left: max(12px, env(safe-area-inset-left)); bottom: max(14px, env(safe-area-inset-bottom)); z-index: 10; margin: 0; width: 176px; background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; cursor: pointer; }
#gps-canvas { display: block; width: 176px; height: 176px; }
#gps-text { margin: 0; padding: 5px 8px 6px; font-size: 10.5px; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
#touch-buttons { grid-template-columns: repeat(2, auto); }
@media (max-width: 760px), (pointer: coarse) {
  #gps { width: 118px; top: calc(max(12px, env(safe-area-inset-top)) + 132px); bottom: auto; } #gps-canvas { width: 118px; height: 118px; } #gps-text { font-size: 8.5px; padding: 3px 5px; }
  #touch-buttons button { width: 54px; height: 54px; font-size: 12px; }
}
@media (max-height: 480px) and (orientation: landscape) { #gps { top: auto; bottom: 10px; left: 190px; width: 96px; } #gps-canvas { width: 96px; height: 96px; } #gps-text { display: none; } }

.tour-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 18px; }
.tour-list { display: grid; gap: 7px; max-height: 58vh; overflow: auto; padding-right: 4px; touch-action: pan-y; }
.tour-list button { all: unset; cursor: pointer; display: grid; gap: 2px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 11px; background: #232f27; }
.tour-list button:hover { background: #2e3d33; border-color: rgba(255, 180, 84, 0.5); }
.tour-list b { font-size: 14px; font-weight: 600; }
.tour-list small { font-size: 11.5px; line-height: 1.45; color: var(--muted); }
.tour-list i { font-style: normal; font-size: 10px; color: var(--leaf); }
@media (max-width: 760px) { .tour-layout { grid-template-columns: 1fr; } .tour-list { max-height: 34vh; } }

.load-card .subtitle { margin: 0 0 14px; font-size: clamp(20px, 4vw, 28px); font-weight: 300; letter-spacing: 0.42em; padding-left: 0.42em; color: var(--accent); }
.brand { margin: 0 0 6px; display: flex; align-items: baseline; gap: 8px; font-size: 15px; }
.brand b { font-weight: 700; letter-spacing: -0.01em; }
.brand span { color: var(--accent); letter-spacing: 0.22em; font-size: 12px; }

/* ---- sheets: the header (with its close button) stays put while the body scrolls ---- */
.sheet { max-height: min(92vh, 92dvh); overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.sheet > header { position: sticky; top: -18px; z-index: 2; margin: -18px -20px 0; padding: 16px 20px 10px; background: rgba(22, 30, 25, 0.98); border-bottom: 1px solid var(--line); }
.sheet > header button { min-width: 44px; min-height: 44px; border: 1px solid var(--line); border-radius: 12px; background: #2b382f; }
.sheet select, .sheet .actions button { min-height: 44px; font-size: 16px; }
.sheet label.check { min-height: 40px; }
.sheet label.check input { width: 22px; height: 22px; accent-color: var(--accent); }

/* ---- phones ---- */
#gps-close { position: absolute; top: 6px; right: 6px; width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: rgba(18, 26, 21, 0.85); font-size: 15px; }
#gps.mini { left: auto; bottom: auto; right: max(12px, env(safe-area-inset-right)); top: calc(max(12px, env(safe-area-inset-top)) + 50px); width: 68px; height: 68px; border-radius: 50%; }
#gps.mini #gps-canvas { width: 68px; height: 68px; }
#gps.mini #gps-text { display: none; }
#gps.mini.open { width: min(62vw, 250px); height: auto; border-radius: 14px; }
#gps.mini.open #gps-canvas { width: 100%; height: auto; aspect-ratio: 1; }
#gps.mini.open #gps-text { display: block; font-size: 10px; padding: 4px 8px 6px; }
@media (max-width: 760px), (pointer: coarse) {
  dialog { margin: 0; position: fixed; inset: auto 0 0 0; width: 100%; max-width: 100%; }
  .sheet, .sheet.wide { width: 100%; max-height: min(88vh, 88dvh); border-radius: 18px 18px 0 0; border-bottom: 0; padding-bottom: max(20px, env(safe-area-inset-bottom)); }
  .tool { padding: 9px 12px; font-size: 12.5px; min-height: 38px; }
  .tools { gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
  #touch-buttons { right: max(12px, env(safe-area-inset-right)); bottom: max(74px, calc(env(safe-area-inset-bottom) + 64px)); gap: 8px; grid-template-columns: repeat(2, 52px); }
  #touch-buttons button { width: 52px; height: 52px; font-size: 11.5px; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
  #foot { bottom: max(8px, env(safe-area-inset-bottom)); gap: 5px; }
  #badges span { font-size: 10px; padding: 1px 8px; }
  #toast { bottom: auto; top: calc(max(12px, env(safe-area-inset-top)) + 128px); font-size: 12px; }
  .tour-list button { padding: 11px 12px; }
}
@media (max-width: 520px) {
  .course-card { width: min(210px, 54vw); }
  .course-name { font-size: 15px; }
  .stats div:nth-child(n+3) { display: none; }
}
@media (max-height: 480px) and (orientation: landscape) {
  #gps.mini { top: calc(max(10px, env(safe-area-inset-top)) + 46px); left: auto; bottom: auto; width: 60px; height: 60px; }
  #gps.mini #gps-canvas { width: 60px; height: 60px; }
  #gps.mini.open { width: min(38vw, 220px); height: auto; }
  #touch-buttons { bottom: 12px; grid-template-columns: repeat(3, 48px); }
  #touch-buttons button { width: 48px; height: 48px; }
  #foot { justify-items: start; padding-left: 14px; }
  .sheet, .sheet.wide { max-height: 96dvh; }
}
