/* 반딧불 밤 산책: 남색 밤안개 위에 등불빛 카드 */
:root {
  --paper: #19203d;          /* 바탕(밤) */
  --paper-hi: #232c55;       /* 카드 */
  --ink: #fff3dc;            /* 글자·선 (달빛 크림) */
  --ink-soft: #b7b2d6;
  --line: rgba(255, 220, 150, 0.32);
  --yellow: #ffd36e;         /* 반딧불 빛 */
  --pink: #f29e8e;
  --plum: #4a3b5c;           /* 캐릭터 외곽선 */
  --shadow: 0 8px 24px rgba(5, 8, 25, 0.45);
  --glow: 0 0 0 1px rgba(255, 211, 110, 0.18), 0 0 22px rgba(255, 211, 110, 0.16);
  --font-hand: 'Gaegu', 'Gowun Dodum', cursive;
  --font-body: 'Gowun Dodum', system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--paper); color: var(--ink); font-family: var(--font-body); word-break: keep-all; }
.only-narrow { display: none; }
/* 안개 레이어가 붙기 전에는 맨 지도가 비치지 않게 숨겼다가 밤안개와 함께 드러낸다 */
#map { position: absolute; inset: 0; opacity: 0; transition: opacity 0.5s ease; }
body.ready #map { opacity: 1; }
.maplibregl-canvas { outline: none; cursor: crosshair; }
.maplibregl-ctrl-attrib { background: rgba(25, 32, 61, 0.8) !important; color: var(--ink-soft) !important; font-size: 10px; }
.maplibregl-ctrl-attrib a { color: var(--ink) !important; }
.maplibregl-ctrl-attrib-button { filter: invert(1); }

/* 시작 시 UI가 살짝 떠오르며 등장 */
.card, .dock, .hint { opacity: 0; transform: translateY(8px); transition: opacity 0.6s ease, transform 0.6s cubic-bezier(.2,1.4,.4,1); }
body.ready .card, body.ready .dock, body.ready .hint { opacity: 1; transform: none; }
body.ready .stats { transition-delay: 0.12s; }
body.ready .dock { transition-delay: 0.24s; }
body.ready .hint { transition-delay: 0.5s; }

.card {
  position: absolute;
  background: rgba(35, 44, 85, 0.88);
  border: 1.5px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow), var(--glow);
  backdrop-filter: blur(6px);
}

.title-card {
  top: 16px; left: 16px;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px 8px 10px;
}
.logo { width: 44px; height: 44px; animation: float 4s ease-in-out infinite; }
.logo svg { width: 100%; height: 100%; overflow: visible; }
.title-card h1 { margin: 0; font-family: var(--font-hand); font-size: 30px; line-height: 0.9; letter-spacing: 0.5px; color: var(--yellow); }
.title-card p { margin: 2px 0 0; font-size: 12px; color: var(--ink-soft); }

.stats {
  top: 16px; right: 16px;
  display: flex; gap: 4px;
  padding: 8px 6px;
}
.stat { display: grid; grid-template-columns: auto auto; align-items: baseline; column-gap: 2px; padding: 0 10px; min-width: 70px; }
.stat + .stat { border-left: 1.5px dashed rgba(255, 243, 220, 0.18); }
.stat .v { font-family: var(--font-hand); font-weight: 700; font-size: 26px; line-height: 1; font-variant-numeric: tabular-nums; }
.stat .u { font-size: 11px; color: var(--ink-soft); }
.stat .k { grid-column: 1 / -1; font-size: 11px; color: var(--ink-soft); margin-top: 2px; }

.dock {
  position: absolute; left: 0; right: 0; bottom: 52px;
  display: flex; justify-content: center; gap: 10px;
  pointer-events: none;
}

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px 9px 12px;
  background: rgba(35, 44, 85, 0.92);
  color: var(--ink);
  border: 1.5px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow);
  font-family: var(--font-hand); font-size: 20px; font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  pointer-events: auto;
  transition: transform 0.12s ease, box-shadow 0.2s ease, background 0.2s, color 0.2s;
}
.btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow), var(--glow); }
.btn:active { transform: translateY(1px) scale(0.98); }
.btn.on { background: var(--yellow); color: #3a2c14; border-color: transparent; box-shadow: var(--shadow), 0 0 18px rgba(255, 211, 110, 0.55); }
.btn:focus-visible { outline: 2px dashed var(--yellow); outline-offset: 3px; }

.follow { position: absolute; right: 16px; bottom: 52px; }

.hint {
  position: absolute; left: 50%; bottom: 14px; translate: -50% 0;
  font-size: 12px; color: var(--ink-soft); white-space: nowrap;
}
kbd {
  display: inline-block; min-width: 18px; padding: 0 4px; margin: 0 1px;
  border: 1.5px solid var(--ink-soft); border-radius: 5px; border-bottom-width: 3px;
  font-family: var(--font-body); font-size: 11px; text-align: center; background: var(--paper-hi); color: var(--ink);
}

#toast {
  position: absolute; left: 50%; top: 92px;
  translate: -50% 0;
  padding: 8px 18px;
  background: var(--ink); color: #2a2440;
  border-radius: 999px;
  box-shadow: 0 0 24px rgba(255, 220, 150, 0.35);
  font-size: 14px;
  opacity: 0; transform: translateY(-8px) scale(0.96);
  transition: opacity 0.3s, transform 0.4s cubic-bezier(.2,1.6,.4,1);
  pointer-events: none; white-space: nowrap;
}
#toast.show { opacity: 1; transform: none; }

#fatal {
  position: absolute; inset: auto 16px 50% 16px;
  padding: 16px; text-align: center;
  background: var(--paper-hi); border: 1.5px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
}

/* ---- 캐릭터: 반딧불 '반디' ---- */
.hero { width: 44px; height: 52px; pointer-events: none; }
.hero-light {
  position: absolute; left: 50%; bottom: -10px; width: 64px; height: 24px; translate: -50% 0;
  border-radius: 50%; background: radial-gradient(closest-side, rgba(255, 214, 120, 0.55), rgba(255, 214, 120, 0));
  animation: light 2.4s ease-in-out infinite;
}
.hero-body {
  position: absolute; left: 8px; bottom: 6px; width: 28px; height: 26px;
  transform-origin: 50% 100%;
  animation: hover 2.4s ease-in-out infinite;
}
.hero-lamp {
  position: absolute; right: -7px; bottom: -3px; width: 15px; height: 15px; border-radius: 50%;
  background: radial-gradient(circle at 40% 40%, #fffbe0, #ffe27a 60%, #f5c64a);
  border: 1.8px solid var(--plum);
  box-shadow: 0 0 10px 3px rgba(255, 226, 122, 0.75), 0 0 26px 8px rgba(255, 211, 110, 0.35);
  animation: lamp 2.4s ease-in-out infinite;
}
.hero .wing {
  position: absolute; top: -9px; width: 15px; height: 10px; border-radius: 50%;
  background: rgba(221, 230, 255, 0.82); border: 1.5px solid var(--plum);
  animation: flap 0.9s ease-in-out infinite;
}
.hero .wing.l { left: -6px; transform-origin: 100% 100%; --tilt: -28deg; }
.hero .wing.r { right: -6px; transform-origin: 0 100%; --tilt: 28deg; animation-delay: -0.45s; }
.hero .antenna {
  position: absolute; top: -8px; width: 1.8px; height: 9px; background: var(--plum); border-radius: 2px;
  transform-origin: 50% 100%;
}
.hero .antenna::after { content: ''; position: absolute; top: -3px; left: -2px; width: 5px; height: 5px; border-radius: 50%; background: #ffe27a; border: 1.2px solid var(--plum); }
.hero .antenna.l { left: 9px; transform: rotate(-22deg); }
.hero .antenna.r { right: 9px; transform: rotate(22deg); }
.hero-shell {
  position: absolute; inset: 0;
  background: radial-gradient(circle at 38% 32%, #fffbe6 0 22%, #fff0a8 55%, #f7d867);
  border: 2.2px solid var(--plum);
  border-radius: 50% 50% 46% 46% / 54% 54% 46% 46%;
}
.hero-face { position: absolute; inset: 0; transform: scaleX(var(--face, 1)); }
.hero .eye { position: absolute; top: 10px; width: 3.6px; height: 5.5px; background: #2e2440; border-radius: 50%; animation: blink 4.2s infinite; }
.hero .eye:nth-child(1) { left: 9px; }
.hero .eye:nth-child(2) { left: 16px; }
.hero .blush { position: absolute; top: 15px; width: 5.5px; height: 3px; background: #f4a3a0; border-radius: 50%; opacity: 0.85; }
.hero .blush:nth-child(3) { left: 4px; }
.hero .blush:nth-child(4) { left: 19px; }
.hero .mouth { position: absolute; top: 15px; left: 12px; width: 4px; height: 2.5px; border: 1.6px solid #2e2440; border-top: none; border-radius: 0 0 4px 4px; }

.hero.walking .hero-body { animation: glide 0.6s ease-in-out infinite; }
.hero.walking .wing { animation-duration: 0.22s; }
.hero.walking .hero-light { animation: light 0.6s ease-in-out infinite; }

@keyframes hover { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }
@keyframes glide { 0%, 100% { transform: translateY(-3px) rotate(-4deg); } 50% { transform: translateY(-8px) rotate(4deg); } }
@keyframes flap { 0%, 100% { transform: rotate(var(--tilt)) scaleY(1); } 50% { transform: rotate(calc(var(--tilt) * 0.2)) scaleY(0.55); } }
@keyframes lamp { 0%, 100% { filter: brightness(1); } 50% { filter: brightness(1.25); } }
@keyframes light { 0%, 100% { opacity: 0.75; transform: scaleX(1); } 50% { opacity: 1; transform: scaleX(1.12); } }
@keyframes blink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(0.1); } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }

/* ---- 목적지 표시: 작은 등불 ---- */
.pin { width: 26px; height: 36px; pointer-events: none; }
.pin-head {
  position: absolute; left: 4px; top: 6px; width: 18px; height: 22px;
  background: radial-gradient(circle at 50% 45%, #fffbe0, #ffd36e 70%);
  border: 2px solid var(--plum); border-radius: 8px 8px 9px 9px;
  box-shadow: 0 0 14px 4px rgba(255, 211, 110, 0.55);
}
.pin-head::after { content: ''; position: absolute; top: -7px; left: 4px; width: 6px; height: 5px; border: 2px solid var(--plum); border-bottom: none; border-radius: 6px 6px 0 0; }
.pin-dot { position: absolute; left: 50%; bottom: 0; width: 18px; height: 6px; translate: -50% 0; border-radius: 50%; background: rgba(255, 211, 110, 0.45); }
.pin.drop .pin-head { animation: drop 0.5s cubic-bezier(.3,1.6,.5,1); }
@keyframes drop { from { transform: translateY(-24px); opacity: 0; } }

/* ---- 밝힐 때 흩어지는 불티 ---- */
.puff {
  width: 7px; height: 7px; pointer-events: none; border-radius: 50%;
  background: #fff3b0;
  box-shadow: 0 0 6px 2px rgba(255, 226, 122, 0.9), 0 0 16px 5px rgba(255, 211, 110, 0.45);
  animation: puff 1.4s cubic-bezier(.2,.8,.3,1) forwards;
}
@keyframes puff {
  0% { transform: translate(0, 0) scale(0.3); opacity: 0; }
  20% { opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(var(--s)); opacity: 0; }
}

/* ---- 가져오기 시트 ---- */
.sheet-backdrop {
  position: absolute; inset: 0; z-index: 10;
  display: grid; place-items: center; padding: 16px;
  background: rgba(8, 11, 30, 0.55);
  animation: fade-in 0.2s ease;
}
.sheet {
  position: relative; width: min(440px, 100%); max-height: calc(100% - 32px); overflow: auto;
  padding: 22px 22px 18px;
  opacity: 1; transform: none;
  animation: sheet-in 0.35s cubic-bezier(.2,1.4,.4,1);
}
.sheet h2 { margin: 0; font-family: var(--font-hand); font-size: 30px; line-height: 1; }
.sheet-lead { margin: 6px 0 16px; font-size: 14px; color: var(--ink-soft); }
.sheet-close {
  position: absolute; top: 12px; right: 12px; width: 34px; height: 34px; padding: 6px;
  border: 1.5px solid var(--line); border-radius: 50%; background: var(--paper-hi); color: var(--ink); cursor: pointer;
}
.sheet-close svg, .sheet-note svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.sheet-close:hover { background: var(--yellow); color: #3a2c14; }

.drop {
  display: grid; justify-items: center; gap: 4px;
  padding: 18px 14px 16px; margin-bottom: 14px;
  border: 2.5px dashed var(--ink-soft); border-radius: 16px;
  background: repeating-linear-gradient(-45deg, transparent 0 10px, rgba(255, 211, 110, 0.08) 10px 20px), var(--paper);
  text-align: center; cursor: pointer;
  transition: border-color 0.2s, background-color 0.2s, transform 0.15s;
}
.drop:hover, .drop:focus-visible { border-color: var(--yellow); outline: none; transform: translateY(-1px); }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.drop svg { width: 56px; height: 56px; fill: none; stroke: var(--ink); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; animation: float 3s ease-in-out infinite; }
.drop strong { font-family: var(--font-hand); font-size: 21px; }
.drop > span { font-size: 12px; color: var(--ink-soft); }

.sheet details { border-top: 1.5px dashed rgba(255, 243, 220, 0.16); padding: 10px 2px; font-size: 13px; }
.sheet summary { cursor: pointer; font-weight: 700; list-style: none; display: flex; align-items: center; gap: 6px; }
.sheet summary::-webkit-details-marker { display: none; }
.sheet summary::before { content: '›'; display: inline-block; font-size: 18px; line-height: 1; transition: transform 0.2s; }
.sheet details[open] summary::before { transform: rotate(90deg); }
.sheet ul { margin: 8px 0 0; padding-left: 18px; line-height: 1.6; }
.sheet em { font-style: normal; color: var(--yellow); }
.sheet code { font-size: 12px; background: var(--paper); padding: 0 4px; border-radius: 4px; }
.sheet .fine { margin: 6px 0 0; font-size: 11px; color: var(--ink-soft); }
.sheet-note { display: flex; align-items: center; gap: 6px; margin: 8px 0 0; font-size: 12px; color: var(--ink-soft); }
.sheet-note svg { width: 16px; height: 16px; flex: none; }

#drop-overlay {
  position: absolute; inset: 0; z-index: 20; pointer-events: none;
  display: grid; place-items: center;
  background: rgba(25, 32, 61, 0.75);
  opacity: 0; transition: opacity 0.2s;
}
#drop-overlay div {
  padding: 28px 40px; border: 2.5px dashed var(--yellow); border-radius: 24px; background: var(--paper-hi);
  font-family: var(--font-hand); font-size: 30px; box-shadow: var(--shadow);
  transform: scale(0.94); transition: transform 0.3s cubic-bezier(.2,1.6,.4,1);
}
body.dragging #drop-overlay { opacity: 1; }
body.dragging #drop-overlay div { transform: none; }

@keyframes fade-in { from { opacity: 0; } }
@keyframes sheet-in { from { opacity: 0; transform: translateY(16px) scale(0.97); } }

/* 중간 폭에선 오른쪽 아래 저작권 표시와 겹치지 않게 단축키 안내를 버튼 줄 위로 올린다 */
@media (min-width: 641px) and (max-width: 1180px) {
  .hint { bottom: 106px; }
}

@media (max-width: 640px) {
  .only-wide { display: none; }
  .only-narrow { display: inline; }
  .title-card { top: 12px; left: 12px; padding: 6px 12px 6px 8px; }
  .title-card h1 { font-size: 24px; }
  .logo { width: 34px; height: 34px; }
  .stats { top: auto; right: 12px; left: 12px; bottom: 112px; justify-content: space-around; }
  .stat { min-width: 0; padding: 0 6px; }
  .dock { bottom: 40px; gap: 8px; }
  .dock .btn { flex-direction: column; gap: 1px; padding: 6px 10px 4px; border-radius: 16px; font-size: 15px; min-width: 64px; }
  .dock .btn svg { width: 18px; height: 18px; }
  .follow { font-size: 16px; padding: 6px 12px 6px 9px; }
  .hint { display: none; }
  .follow { bottom: 160px; right: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}

/* ---- 앱 모드 (?app): HUD는 앱이 그린다 ---- */
body.app .title-card, body.app .stats, body.app .dock, body.app .hint { display: none; }
body.app .maplibregl-canvas { cursor: grab; }
body.app #toast { top: calc(var(--app-top, 0px) + 16px); }
body.app .follow { bottom: calc(var(--app-bottom, 0px) + 40px); } /* 저작권 표시(ⓘ) 위 */
body.app .maplibregl-ctrl-bottom-right { bottom: var(--app-bottom, 0px); }
