:root {
  --blue: #4a7cff;
  --blue-dark: #3a63d8;
  --navy: #1f2a44;
  --bg: #eef2f8;
  --card: #ffffff;
  --text: #1f2a44;
  --muted: #8a93a6;
  --border: #e3e8f0;
  --gold: #ffb020;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Noto Sans KR", -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}
.hidden { display: none !important; }

/* 화면 공통: 전체를 덮는 레이어 */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* ===== 화면1 인트로 ===== */
.intro {
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #4a7cff 0%, #6a4dff 100%);
  color: #fff;
}
.intro-inner { text-align: center; }
.intro-logo { font-size: 90px; animation: pop 0.8s cubic-bezier(0.17,0.89,0.32,1.28) both; }
.intro-title { font-size: 38px; font-weight: 800; margin: 12px 0 6px; animation: rise 0.6s ease 0.3s both; }
.intro-sub { font-size: 16px; opacity: 0.9; margin: 0; animation: rise 0.6s ease 0.5s both; }
@keyframes pop { 0%{transform:scale(0.3);opacity:0} 60%{opacity:1} 100%{transform:scale(1);opacity:1} }
@keyframes rise { 0%{transform:translateY(14px);opacity:0} 100%{transform:translateY(0);opacity:1} }

/* ===== 상단 바 ===== */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  z-index: 5;
}
.icon-btn {
  background: var(--bg);
  border: none;
  width: 40px; height: 40px;
  border-radius: 10px;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
}
.icon-btn:hover { background: #e0e6f0; }
.screen-title { font-size: 18px; margin: 0; flex: 1; }

.route-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  justify-content: center;
}
.route-chip {
  background: var(--bg);
  padding: 7px 14px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  max-width: 40vw;
  overflow: hidden;
  text-overflow: ellipsis;
}
.swap-btn {
  background: none; border: none;
  font-size: 18px; cursor: pointer; color: var(--blue);
}
.go-guide-btn {
  background: var(--blue);
  color: #fff;
  border: none;
  padding: 9px 14px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  flex-shrink: 0;
}
.go-guide-btn:hover { background: var(--blue-dark); }

/* ===== 검색 ===== */
.search-wrap { position: relative; padding: 10px 12px; background: var(--card); z-index: 4; }
.search-form { display: flex; gap: 8px; }
.search-form input {
  flex: 1; padding: 11px 14px;
  border: 1px solid var(--border); border-radius: 10px; font-size: 15px;
}
.search-form button {
  background: var(--blue); color: #fff; border: none;
  padding: 0 18px; border-radius: 10px; font-weight: 600; cursor: pointer;
}
.search-results {
  list-style: none; margin: 8px 0 0; padding: 0;
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  max-height: 240px; overflow-y: auto;
  position: absolute; left: 12px; right: 12px; z-index: 10;
  box-shadow: 0 8px 24px rgba(0,0,0,0.1);
}
.search-results li {
  padding: 12px 14px; cursor: pointer; border-bottom: 1px solid var(--border);
}
.search-results li:last-child { border-bottom: none; }
.search-results li:hover { background: var(--bg); }
.result-name { font-weight: 600; }
.result-addr { font-size: 12px; color: var(--muted); margin-top: 3px; }

/* ===== 지도 ===== */
.map { flex: 1; width: 100%; }

/* ===== 화면3 3D 길안내 ===== */
.guide-3d { flex: 1; width: 100%; background: #87ceeb; position: relative; }
.rv-loading {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  text-align: center; color: #3a4556; font-size: 16px; font-weight: 600; line-height: 1.6;
  background: #eef2f7;
}
.guide-3d canvas { display: block; }
.minimap {
  position: absolute;
  top: 70px; right: 14px;
  width: 200px; height: 200px;
  border-radius: 14px;
  overflow: hidden;
  border: 3px solid #fff;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  z-index: 6;
}
.hint-btn {
  position: absolute;
  top: 282px; right: 14px;
  background: var(--card);
  border: none;
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 15px; font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  z-index: 6;
}
.controls {
  position: absolute;
  bottom: 28px; left: 0; right: 0;
  display: flex; justify-content: center; gap: 16px;
  z-index: 6;
}
.ctrl {
  width: 64px; height: 64px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.92);
  font-size: 24px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  user-select: none;
}
.ctrl:active { background: var(--blue); color: #fff; }
.guide-msg {
  position: absolute;
  top: 50%; left: 50%; transform: translate(-50%,-50%);
  background: rgba(31,42,68,0.95);
  color: #fff;
  padding: 24px 32px;
  border-radius: 16px;
  font-size: 20px; font-weight: 700;
  text-align: center;
  z-index: 20;
}

/* 길이탈 방향 화살표 (5초) */
.dir-arrow {
  position: absolute;
  top: 42%; left: 50%; transform: translate(-50%, -50%);
  z-index: 11; text-align: center; pointer-events: none;
}
.dir-arrow .da-icon { font-size: 76px; filter: drop-shadow(0 2px 6px rgba(0,0,0,0.3)); }
.dir-arrow .da-txt {
  display: inline-block; margin-top: 4px;
  background: rgba(31,42,68,0.92); color: #fff;
  padding: 6px 16px; border-radius: 20px; font-size: 16px; font-weight: 700;
}

/* ===== 사이드바 ===== */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 40; }
.sidebar {
  position: fixed; top: 0; left: 0;
  width: 320px; max-width: 85vw; height: 100%;
  background: var(--card);
  box-shadow: 2px 0 20px rgba(0,0,0,0.2);
  padding: 20px;
  transform: translateX(-100%);
  transition: transform 0.25s ease;
  z-index: 50;
  overflow-y: auto;
}
.sidebar.open { transform: translateX(0); }
.sidebar h3 { font-size: 15px; margin: 22px 0 8px; color: var(--blue-dark); }
.sidebar h3:first-of-type { margin-top: 30px; }
.icon-btn.close { position: absolute; top: 14px; right: 14px; }
.side-form { display: flex; gap: 6px; }
.side-form input { flex: 1; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; }
.side-form button { background: var(--blue); color: #fff; border: none; padding: 0 14px; border-radius: 8px; cursor: pointer; }
.side-current { font-size: 13px; color: var(--muted); margin: 6px 0 0; }
.school-info { font-size: 14px; line-height: 1.6; color: var(--text); }
.school-info a { color: var(--blue); }
.side-foot { margin-top: 30px; display: flex; flex-direction: column; gap: 8px; }
.side-link {
  background: var(--bg); border: none; padding: 13px; border-radius: 10px;
  font-size: 15px; text-align: left; cursor: pointer;
}
.side-link:hover { background: #e0e6f0; }

/* ===== 화면4 꾸미기 ===== */
.dressup-body { flex: 1; overflow-y: auto; padding: 16px; }
.char-preview {
  width: 160px; height: 220px;
  margin: 0 auto 20px;
  background: linear-gradient(160deg, #eaf4ff 0%, #f6faff 100%);
  border: 1px solid var(--border);
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; color: var(--muted);
  position: relative;
}
.cat-tabs { display: flex; gap: 6px; justify-content: center; margin-bottom: 16px; flex-wrap: wrap; }
.gender-tabs { display: flex; gap: 8px; justify-content: center; margin-bottom: 12px; }.gender-tab {
  background: var(--card); border: 1px solid var(--border);
  padding: 9px 22px; border-radius: 20px; cursor: pointer; font-size: 14px; font-weight: 600;
}
.gender-tab.active { background: var(--blue); color: #fff; border-color: var(--blue); }
.cat-tab {
  background: var(--card); border: 1px solid var(--border);
  padding: 9px 16px; border-radius: 20px; cursor: pointer; font-size: 14px;
}
.cat-tab.active { background: var(--blue); color: #fff; border-color: var(--blue); }

/* 꾸미기/상점 전환 탭 */
.ds-tabs {
  display: flex; gap: 8px; justify-content: center;
  padding: 10px 16px 4px; 
}
.ds-tab {
  flex: 1; max-width: 160px;
  background: var(--card); border: 1px solid var(--border);
  padding: 11px 0; border-radius: 22px; cursor: pointer;
  font-size: 15px; font-weight: 700;
}
.ds-tab.active { background: var(--blue); color: #fff; border-color: var(--blue); }
.item-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(100px,1fr));
  gap: 12px; max-width: 520px; margin: 0 auto;
}
.item-cell {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 16px 8px; text-align: center;
  cursor: pointer; position: relative; font-size: 14px;
}
.item-cell .item-emoji { font-size: 32px; display: block; margin-bottom: 6px; }
.item-cell.locked { color: var(--muted); opacity: 0.6; cursor: default; }
.item-cell.locked .lock { position: absolute; right: 8px; bottom: 8px; font-size: 16px; }
.item-cell.equipped { border-color: var(--blue); box-shadow: 0 0 0 2px var(--blue); }

/* 캐릭터 미리보기 레이어 */
.char-stack { position: relative; width: 120px; height: 200px; }
.char-layer { position: absolute; left: 0; width: 100%; text-align: center; }

/* ===== 화면5 상점 ===== */
.shop-body { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 20px; }
.coin-display { font-weight: 700; font-size: 16px; }
.chest { font-size: 110px; cursor: default; transition: transform 0.2s; }
.chest.shake { animation: shake 0.4s; }
@keyframes shake { 0%,100%{transform:rotate(0)} 25%{transform:rotate(-12deg)} 75%{transform:rotate(12deg)} }
.shop-desc { color: var(--muted); margin: 10px 0 20px; }
.draw-btn {
  background: var(--gold); color: #5a3d00; border: none;
  padding: 15px 40px; border-radius: 14px; font-size: 18px; font-weight: 800;
  cursor: pointer; box-shadow: 0 4px 0 #d8920f;
}
.draw-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #d8920f; }
.draw-btn:disabled { background: #ccc; color: #888; box-shadow: none; cursor: not-allowed; }
.draw-result {
  margin-top: 24px; background: var(--card); border: 1px solid var(--border);
  border-radius: 16px; padding: 24px 32px; text-align: center;
  animation: pop 0.4s ease;
}
.draw-result .r-emoji { font-size: 56px; }
.draw-result .r-name { font-size: 20px; font-weight: 800; margin-top: 8px; }
.draw-result .r-tag { font-size: 13px; color: var(--muted); margin-top: 4px; }
.draw-result .r-new { color: var(--blue); font-weight: 700; }

@media (max-width: 480px) {
  .minimap { width: 140px; height: 140px; }
  .hint-btn { top: 222px; }
  .route-chip { max-width: 28vw; }
}

/* 정류장 탑승 오버레이 */
.board-overlay {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 12;
  display: flex; justify-content: center;
  padding: 0 16px 26px;
}
.board-overlay-box {
  background: rgba(255,255,255,0.97);
  border-radius: 18px; padding: 18px 22px; width: 100%; max-width: 420px;
  text-align: center; box-shadow: 0 -4px 20px rgba(0,0,0,0.2);
}
.bo-title { font-size: 20px; font-weight: 800; }
.bo-route { font-size: 15px; color: #3a4556; margin: 6px 0; }
.bo-time { font-size: 13px; color: #8a93a6; margin-bottom: 12px; }

/* 3D 조작 안내 오버레이 */
.guide-intro {
  position: absolute; inset: 0; z-index: 12;
  background: rgba(31,42,68,0.72);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.guide-intro-box {
  background: #fff; border-radius: 18px; padding: 24px 22px;
  max-width: 340px; width: 100%; text-align: center;
}
.gi-title { font-size: 20px; font-weight: 800; margin-bottom: 16px; }
.gi-row { font-size: 15px; color: #3a4556; margin: 10px 0; }
.gi-key {
  display: inline-block; min-width: 26px; padding: 2px 8px;
  background: #eef1f6; border-radius: 6px; font-weight: 700; margin: 0 2px;
}
.guide-intro-box .board-btn { margin-top: 18px; }

/* 도착 종료 화면 */
.arrival-scene {
  width: 100%; height: 100%;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px;
  background: linear-gradient(160deg, #fff6d6 0%, #ffe9b0 100%);
  text-align: center; padding: 20px;
}
.arrival-icon { font-size: 90px; animation: pop 0.6s cubic-bezier(0.17,0.89,0.32,1.28) both; }
.arrival-title { font-size: 28px; font-weight: 800; color: #7a5a00; }
.arrival-sub { font-size: 15px; color: #8a6a00; line-height: 1.6; }

/* 2D 캐릭터 미리보기 */
.char2d {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 0; line-height: 1;
}
.char2d .c-hat { font-size: 34px; height: 30px; }
.char2d .c-head { font-size: 40px; position: relative; }
.char2d .c-head .c-face { position: absolute; left: 50%; top: 50%; transform: translate(-50%,-40%); font-size: 26px; }
.char2d .c-body { font-size: 54px; margin-top: -6px; }
.char2d .c-shoes { font-size: 30px; margin-top: -10px; }

/* 설정(주소/학교) 탭 */
.setup-tabs { display: flex; gap: 8px; padding: 12px 16px 0; }
.setup-tab {
  flex: 1; padding: 12px; border: none; border-radius: 12px 12px 0 0;
  background: #e8edf5; color: #5a6475; font-size: 15px; font-weight: 700; cursor: pointer;
}
.setup-tab.active { background: var(--card); color: var(--blue); box-shadow: 0 -2px 0 var(--blue) inset; }
.setup-body { flex: 1; overflow-y: auto; padding: 18px 16px; background: var(--card); }
.setup-pane { max-width: 520px; margin: 0 auto; }
.setup-desc { font-size: 14px; color: var(--muted); margin: 0 0 14px; }

/* 사이드바 메뉴 */
.side-brand { font-size: 18px; font-weight: 800; margin: 30px 0 20px; }
.side-menu { display: flex; flex-direction: column; gap: 10px; }

/* 버스/지하철 탑승 화면 */
.board-scene {
  width: 100%; height: 100%;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 10px;
  background: linear-gradient(160deg, #eaf0fb 0%, #dfe7f5 100%);
  padding: 20px; text-align: center;
}
.board-icon { font-size: 80px; }
.station { margin-bottom: 6px; }
.board-icon.moving { animation: ride 1.2s ease-in-out infinite; }
@keyframes ride { 0%,100%{transform:translateX(-14px)} 50%{transform:translateX(14px)} }
.board-line { font-size: 20px; font-weight: 800; color: #2f3b52; }
.board-route { font-size: 15px; color: #5a6475; }
.board-route span { color: #9aa3b2; margin: 0 4px; }
.board-time { font-size: 13px; color: #8a93a6; }
.board-btn {
  margin-top: 14px;
  background: var(--blue); color: #fff; border: none;
  padding: 15px 36px; border-radius: 14px;
  font-size: 18px; font-weight: 800; cursor: pointer;
  box-shadow: 0 4px 0 var(--blue-dark);
}
.board-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--blue-dark); }

/* 경로 선택 바텀시트 */
.route-sheet {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 380px; max-width: 90vw;
  background: var(--card);
  border-radius: 20px 0 0 20px;
  box-shadow: -6px 0 24px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  z-index: 8;
  animation: sheet-in 0.25s ease;
}
@keyframes sheet-in { from { transform: translateX(100%); } to { transform: translateX(0); } }
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }

/* 모바일: 하단 바텀시트 */
@media (max-width: 720px) {
  .route-sheet {
    top: auto; left: 0; right: 0; bottom: 0; width: 100%; max-width: none;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -6px 24px rgba(0,0,0,0.18);
    max-height: 55%;
    animation: sheet-up 0.25s ease;
  }
}
.route-sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  font-weight: 700; font-size: 16px;
}
.route-list { overflow-y: auto; padding: 12px 16px 20px; display: flex; flex-direction: column; gap: 12px; }
.route-card {
  border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px;
  cursor: pointer; transition: border-color 0.15s, box-shadow 0.15s;
}
.route-card:hover { border-color: var(--blue); box-shadow: 0 4px 12px rgba(74,124,255,0.15); }
.route-card-top { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.route-time { font-size: 20px; font-weight: 800; }
.route-meta { font-size: 13px; color: var(--muted); }
.route-segs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }

/* 경로 상세(hover/탭 시 펼침) */
.route-detail { display: none; margin-top: 12px; border-top: 1px solid var(--border); padding-top: 10px; }
.route-card.open .route-detail { display: block; }
.route-card.open { border-color: var(--blue); box-shadow: 0 6px 18px rgba(74,124,255,0.22); }
.route-detail-list { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
.rd-row { font-size: 13px; color: #3a4556; }
.route-go-btn {
  width: 100%; background: var(--blue); color: #fff; border: none;
  padding: 11px; border-radius: 10px; font-size: 15px; font-weight: 700; cursor: pointer;
}
.route-go-btn:hover { background: var(--blue-dark); }
.seg-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: 16px; font-size: 13px; font-weight: 600;
}
.seg-walk { background: #eef1f6; color: #5a6475; }
.seg-bus { background: #e6f3ea; color: #1f8b4c; }
.seg-subway { background: #e7eeff; color: #2f59bd; }
.seg-arrow { color: var(--muted); font-size: 12px; }

/* 하단 토스트 안내 */
.toast {
  position: fixed;
  left: 50%; bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  background: rgba(31,42,68,0.95);
  color: #fff;
  padding: 13px 20px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 600;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 6px 20px rgba(0,0,0,0.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
