* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --primary: #2c7a4b;
  --primary-dark: #1f5c38;
  --accent: #ffb703;
  --bg: #f6f4ef;
  --text: #1d1d1b;
  --card: #ffffff;
  --red: #d94f3d;
}

html, body { height: 100%; }

body {
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

.screen { display: none; width: 100vw; height: 100vh; height: 100dvh; }
.screen.active { display: block; }
.screen.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(20, 24, 20, 0.72);
  backdrop-filter: blur(3px);
}
.screen.overlay.active { display: flex; align-items: center; justify-content: center; }

/* ===== 시작 화면 ===== */
#screen-start { overflow-y: auto; }
.start-inner {
  max-width: 420px; margin: 0 auto; padding: 48px 24px 40px;
  display: flex; flex-direction: column; gap: 16px; text-align: center;
}
.logo {
  font-size: 64px; font-weight: 900; letter-spacing: -2px; color: var(--primary);
}
.logo-q { color: var(--accent); }
.tagline { font-size: 18px; line-height: 1.5; color: #555; margin-bottom: 8px; }

.start-stats { font-size: 14px; color: #777; min-height: 18px; }

.btn {
  border: none; border-radius: 14px; padding: 16px 20px;
  font-size: 17px; font-weight: 700; cursor: pointer;
  transition: transform 0.06s, background 0.15s; font-family: inherit;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #e8e4da; color: var(--text); }
.btn-secondary:hover { background: #ddd8cb; }
.btn-ghost { background: transparent; color: #888; font-weight: 500; }
.btn:disabled { opacity: 0.55; cursor: default; }

.how-to {
  text-align: left; background: var(--card); border-radius: 14px;
  padding: 18px 20px; margin-top: 8px; box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.how-to h3 { font-size: 15px; margin-bottom: 10px; color: var(--primary); }
.how-to ol { padding-left: 20px; font-size: 14px; line-height: 1.9; color: #444; }
.footnote { font-size: 12px; color: #aaa; margin-top: 4px; }

/* ===== 게임 화면 ===== */
#screen-game { position: relative; }
#pano {
  width: 100%; height: 100%; background: #222;
  /* 파노라마 내부 UI(화살표 등)의 높은 z-index가 미니맵/버튼 위로 새어나오지 못하게 가둠 */
  position: relative; z-index: 0; isolation: isolate;
}

/* 상단 바 — 파노라마 기본 UI의 주소 표기를 가리는 역할 겸용 */
.top-bar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px;
  background: linear-gradient(to bottom, rgba(15,20,15,0.92), rgba(15,20,15,0.75));
  color: #fff;
}
.top-logo { font-weight: 900; font-size: 18px; color: var(--accent); }
.top-info { font-size: 15px; font-weight: 600; }
.top-info .sep { opacity: 0.4; margin: 0 6px; }
.btn-mini {
  margin-left: auto; background: rgba(255,255,255,0.14); color: #fff;
  border: none; border-radius: 8px; padding: 7px 12px; font-size: 13px;
  cursor: pointer; font-family: inherit;
}
.btn-mini:hover { background: rgba(255,255,255,0.26); }

/* 미니맵 */
#minimap-wrap {
  position: absolute; right: 16px; bottom: 20px; z-index: 10;
  display: flex; flex-direction: column; gap: 8px;
  transition: width 0.2s, height 0.2s;
}
#minimap {
  width: 100%; flex: 1 1 0; min-height: 0; /* 네이버 지도의 내부 고정 높이가 축소를 막지 못하게 */
  border-radius: 12px; overflow: hidden;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4); border: 2px solid #fff;
}
.minimap-small { width: 260px; height: 240px; }
.minimap-large { width: min(560px, calc(100vw - 32px)); height: min(520px, calc(100vh - 120px)); }
.btn-guess {
  background: var(--accent); color: #3a2c00; font-size: 16px; padding: 13px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.35);
  flex-shrink: 0; /* 지도에 밀려 화면 밖으로 나가지 않게 */
}
.btn-guess:not(:disabled):hover { background: #ffc933; }
.btn-map-toggle { margin-left: 0; align-self: flex-start; background: rgba(15,20,15,0.75); position: absolute; top: 8px; left: 8px; z-index: 11; }

/* 걸음걸이 연출 — 이동 시 헤드밥(위아래 출렁임) + 전진 줌 */
#pano.step-fwd { animation: walk-fwd 0.45s ease-out; }
#pano.step-back { animation: walk-back 0.45s ease-out; }
@keyframes walk-fwd {
  0%   { transform: scale(1) translateY(0); }
  30%  { transform: scale(1.02) translateY(-2px); }
  70%  { transform: scale(1.04) translateY(-3px); }
  100% { transform: scale(1.05) translateY(0); }
}
@keyframes walk-back {
  0%   { transform: scale(1) translateY(0); }
  30%  { transform: scale(0.99) translateY(-2px); }
  70%  { transform: scale(0.975) translateY(-3px); }
  100% { transform: scale(0.965) translateY(0); }
}

/* 점수/타이머 HUD — 크고 잘 보이게 */
.hud {
  position: absolute; top: 56px; left: 50%; transform: translateX(-50%);
  z-index: 10; display: flex; gap: 10px; align-items: center;
}
.hud-pill {
  background: rgba(15, 20, 15, 0.85); color: #fff;
  font-weight: 800; font-size: 19px; letter-spacing: -0.3px;
  padding: 11px 20px; border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.4);
  white-space: nowrap;
}
.hud-timer {
  font-size: 26px; color: var(--accent);
  font-variant-numeric: tabular-nums; text-align: center; min-width: 118px;
}
.timer-danger { color: #ff5a45 !important; border-color: rgba(255, 90, 69, 0.7) !important; animation: blink 0.6s step-end infinite; }
@keyframes blink { 50% { opacity: 0.4; } }
@media (max-width: 640px) {
  .hud { top: 50px; gap: 6px; }
  .hud-pill { font-size: 15px; padding: 8px 14px; }
  .hud-timer { font-size: 20px; min-width: 92px; }
}

/* 라이벌/친구 비교 */
.rival-line { font-size: 14px; color: #777; min-height: 18px; }

/* 학습 팁 */
.tip-line {
  text-align: left; font-size: 13.5px; line-height: 1.55; color: #4a5a4a;
  background: #eef5ee; border-left: 4px solid var(--primary);
  border-radius: 8px; padding: 10px 14px;
}
.tip-line b { color: var(--primary-dark); }

/* 도전장 배너 */
.challenge-banner {
  background: #fff6dd; border: 2px solid var(--accent); border-radius: 14px;
  padding: 16px; font-size: 15px; line-height: 1.5;
}

/* 조작 안내 */
.key-hint {
  position: absolute; left: 16px; bottom: 20px; z-index: 10;
  background: rgba(15,20,15,0.7); color: #ddd; font-size: 13px;
  padding: 8px 14px; border-radius: 10px; display: flex; align-items: center; gap: 5px;
  pointer-events: none;
}
.key-hint .key {
  display: inline-block; background: rgba(255,255,255,0.16); border: 1px solid rgba(255,255,255,0.3);
  border-radius: 5px; padding: 1px 7px; font-weight: 700; font-size: 12px; color: #fff;
}
.key-hint .sep { opacity: 0.4; margin: 0 4px; }
@media (max-width: 640px) { .key-hint { display: none; } }

/* ===== 결과 카드 ===== */
.result-card {
  background: var(--card); border-radius: 20px;
  overflow-y: auto; -webkit-overflow-scrolling: touch; /* 폰에서 카드가 화면보다 길면 내부 스크롤 */
  width: min(680px, calc(100vw - 28px)); max-height: calc(100vh - 40px); max-height: calc(100dvh - 40px);
  display: flex; flex-direction: column;
  box-shadow: 0 12px 48px rgba(0,0,0,0.45);
}
#result-map { flex-shrink: 0; }
#result-map { width: 100%; height: min(360px, 42vh); background: #dfe8df; }
.result-info { padding: 20px 24px 24px; text-align: center; display: flex; flex-direction: column; gap: 10px; }
.result-info h2 { font-size: 20px; }
#result-distance { color: #666; font-size: 15px; }
.score-bar-track { height: 10px; background: #eee; border-radius: 5px; overflow: hidden; }
.score-bar-fill { height: 100%; width: 0%; background: linear-gradient(to right, var(--red), var(--accent), var(--primary)); border-radius: 5px; transition: width 0.8s ease-out; }
.result-score { font-size: 30px; font-weight: 900; color: var(--primary); }

/* ===== 최종 결과 ===== */
.final-card { padding: 32px 28px; text-align: center; gap: 12px; display: flex; flex-direction: column; }
.final-score { font-size: 44px; font-weight: 900; color: var(--primary); }
.final-emoji { font-size: 26px; letter-spacing: 3px; }
.final-rounds { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: #555; margin: 6px 0; }
.final-rounds .fr-row { display: flex; justify-content: space-between; padding: 7px 12px; background: #f4f1ea; border-radius: 8px; }
.streak { font-size: 15px; color: var(--accent); font-weight: 700; }

/* ===== XP / 레벨 ===== */
.start-level {
  background: var(--card); border-radius: 14px; padding: 14px 18px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06); font-size: 15px;
  display: flex; flex-direction: column; gap: 7px; align-items: center;
}
.lv-badge {
  background: var(--primary); color: #fff; font-weight: 800; font-size: 13px;
  border-radius: 999px; padding: 3px 10px; margin-right: 2px;
}
.xp-box {
  background: #f4f1ea; border-radius: 12px; padding: 14px 16px;
  display: flex; flex-direction: column; gap: 8px;
}
.xp-row { display: flex; justify-content: space-between; font-weight: 700; font-size: 15px; }
.xp-gain { color: var(--accent); font-weight: 900; }
.xp-bar-track { height: 10px; background: #e2ddd0; border-radius: 5px; overflow: hidden; width: 100%; }
.xp-bar-track.mini { height: 7px; max-width: 220px; }
.xp-bar-fill { height: 100%; width: 0%; background: linear-gradient(to right, var(--accent), var(--primary)); border-radius: 5px; transition: width 0.9s ease-out; }
.xp-sub { font-size: 12.5px; color: #999; }

/* 전국 랭킹 */
.rank-line { font-size: 16px; font-weight: 800; color: var(--primary); min-height: 20px; }
.lb-overlay {
  position: fixed; inset: 0; z-index: 250;
  background: rgba(20, 24, 20, 0.72); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
}
.lb-card {
  background: var(--card); border-radius: 20px; padding: 24px;
  width: min(420px, calc(100vw - 32px)); max-height: calc(100vh - 60px);
  display: flex; flex-direction: column; gap: 10px; text-align: center;
  box-shadow: 0 12px 48px rgba(0,0,0,0.45);
}
.lb-tabs { display: flex; gap: 6px; justify-content: center; }
.lb-tab {
  border: none; border-radius: 999px; padding: 7px 16px; font-size: 13.5px;
  font-weight: 700; background: #eee8db; color: #666; cursor: pointer; font-family: inherit;
}
.lb-tab-on { background: var(--primary); color: #fff; }
.lb-list { overflow-y: auto; display: flex; flex-direction: column; gap: 4px; text-align: left; }
.lb-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; background: #f4f1ea; border-radius: 8px; font-size: 14px;
}
.lb-row.lb-me { background: #eaf5ea; border: 1.5px solid var(--primary); font-weight: 700; }
.lb-rank { font-weight: 900; color: var(--accent); min-width: 26px; }
.lb-row:nth-child(1) .lb-rank::after { content: " 🥇"; }
.lb-row:nth-child(2) .lb-rank::after { content: " 🥈"; }
.lb-row:nth-child(3) .lb-rank::after { content: " 🥉"; }
.lb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-weight: 700; }

/* 레벨 업 오버레이 */
.levelup-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(15, 18, 24, 0.88);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.levelup-card { text-align: center; display: flex; flex-direction: column; gap: 12px; padding: 20px; z-index: 2; }
.levelup-h { font-size: 52px; font-weight: 900; color: var(--accent); text-shadow: 0 4px 24px rgba(255, 183, 3, 0.45); }
.levelup-level { font-size: 20px; color: #fff; font-weight: 700; }
.levelup-title { font-size: 26px; color: #ffe9b3; font-weight: 800; margin-bottom: 8px; }
.confetti { position: absolute; inset: 0; pointer-events: none; }
.confetti-piece {
  position: absolute; top: -12px; width: 9px; height: 14px; border-radius: 2px;
  animation: confetti-fall 2s linear forwards;
}
@keyframes confetti-fall {
  0%   { transform: translateY(-10px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(105vh) rotate(680deg); opacity: 0.7; }
}

/* ===== 듀얼/채팅/홈랭킹 ===== */
.btn-duel { background: #7b5bd6; }
.btn-duel:hover { background: #6647c4; }
.btn-blitz { background: #e0862a; }
.btn-blitz:hover { background: #c97318; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; font-size: 15px; padding: 13px 10px; }

.home-rank {
  background: var(--card); border-radius: 14px; padding: 14px 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06); text-align: left;
  display: flex; flex-direction: column; gap: 5px;
}
.hr-title { font-size: 14.5px; font-weight: 800; color: var(--primary); display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }

.duel-wait-msg { font-size: 15px; color: #555; }
.duel-spinner { align-self: center; border-color: rgba(0,0,0,0.1); border-top-color: #7b5bd6; }

.opp-pin {
  width: 22px; height: 22px; border-radius: 50% 50% 50% 0;
  background: #7b5bd6; transform: rotate(-45deg);
  border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}

.chat-card { height: min(560px, calc(100vh - 60px)); }
.chat-list {
  flex: 1; min-height: 0; overflow-y: auto; text-align: left;
  display: flex; flex-direction: column; gap: 6px;
  background: #f7f5f0; border-radius: 10px; padding: 10px;
}
.chat-row { font-size: 14px; line-height: 1.45; word-break: break-word; }
.chat-row b { color: var(--primary-dark); }
.chat-tier {
  font-size: 11px; background: #e8e2d4; border-radius: 6px; padding: 1px 6px;
  color: #7a6a45; font-weight: 700;
}
.chat-input-row { display: flex; gap: 8px; }
.chat-input {
  flex: 1; border: 2px solid #ddd6c6; border-radius: 10px; padding: 11px 12px;
  font-size: 14px; font-family: inherit; outline: none;
}
.chat-input:focus { border-color: var(--primary); }
.chat-send { padding: 11px 18px; font-size: 14px; }

/* ===== 로딩/토스트 ===== */
.loading-overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(15,20,15,0.85);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; color: #fff;
}
.spinner {
  width: 44px; height: 44px; border: 4px solid rgba(255,255,255,0.2);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: #222; color: #fff; padding: 12px 22px; border-radius: 24px;
  font-size: 14px; z-index: 200; opacity: 0; transition: all 0.25s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* 게스 마커 */
.guess-pin {
  width: 22px; height: 22px; border-radius: 50% 50% 50% 0;
  background: var(--red); transform: rotate(-45deg);
  border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}
.answer-pin {
  width: 22px; height: 22px; border-radius: 50% 50% 50% 0;
  background: var(--primary); transform: rotate(-45deg);
  border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}

/* 모바일 */
/* 지도 접힘 상태 (모바일 기본): 지도를 완전히 숨기고 FAB만 표시 */
.minimap-collapsed { width: auto; height: auto; }
.minimap-collapsed #minimap,
.minimap-collapsed .btn-guess,
.minimap-collapsed .btn-map-toggle { display: none; }

.map-fab {
  position: absolute; right: 14px; bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 11; width: 64px; height: 64px; border-radius: 50%;
  background: var(--accent); color: #3a2c00; border: none;
  font-size: 22px; font-weight: 800; font-family: inherit;
  box-shadow: 0 5px 16px rgba(0,0,0,0.45); cursor: pointer;
  display: none; flex-direction: column; align-items: center; justify-content: center; gap: 0;
}
.map-fab span { font-size: 11px; font-weight: 800; }
@media (min-width: 641px) { .map-fab { display: none !important; } }

@media (max-width: 640px) {
  /* 모바일: 지도는 열었을 때 거의 전체 화면 (핀 정밀도 확보) */
  .minimap-large { width: calc(100vw - 20px); height: calc(100dvh - 130px); }
  #minimap-wrap { right: 10px; bottom: calc(12px + env(safe-area-inset-bottom)); }
  .btn-guess { font-size: 15px; padding: 13px; }
  .logo { font-size: 52px; }
}
