:root {
  /* Brand — sky blue (var names kept for backward refs across the app) */
  --green:    #1e96d8;
  --green-2:  #1a82bd;
  --green-bg: rgba(30,150,216,.12);
  --blue:     #3267a8;
  --blue-bg:  rgba(50,103,168,.10);
  /* iOS system labels / fills (light) */
  --label:    #1c1c1e;
  --label-2:  rgba(60,60,67,.60);
  --label-3:  rgba(60,60,67,.30);
  --separator:rgba(60,60,67,.16);
  --fill:     rgba(118,118,128,.12);
  --bg:       #f2f2f7;   /* systemGroupedBackground */
  --card:     #ffffff;
  --white:    #fff;
  /* Aliases kept for backward references */
  --black: var(--label); --gray1: var(--label-2); --gray2: var(--label-2); --border: var(--separator);
  /* Shape & motion */
  --r:    14px;
  --r-lg: 20px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 10px 30px rgba(0,0,0,.06);
  --ease: cubic-bezier(.32,.72,0,1);   /* iOS spring-like */
}
*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI", sans-serif;
  color: var(--label); background: var(--bg); min-height: 100dvh;
  letter-spacing: -.01em; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
button { font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; border: none; background: none; color: inherit; }

.gps-badge { display: flex; align-items: center; gap: 5px; font-size: 13px; color: var(--label-2); }
.gps-dot { display: block; width: 8px; height: 8px; border-radius: 50%; background: var(--label-3); }
.gps-dot.active     { background: #34c759; }
.gps-dot.requesting { background: #ff9f0a; animation: blink 1.2s infinite; }
.gps-dot.denied     { background: #ff3b30; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.2} }

/* ══ SCREEN 1 ═══════════════════════════════════════════════════════ */
#selectScreen {
  min-height: 100dvh; background: var(--bg);
  max-width: 460px; margin: 0 auto;
}

.app-header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) 18px 12px;
  background: rgba(248,248,250,.82); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: .5px solid var(--separator);
}
.logo { font-size: 20px; font-weight: 800; color: var(--green); letter-spacing: -.02em; }

.page-pad { padding: 8px 16px calc(env(safe-area-inset-bottom) + 48px); }
.page-title { font-size: 30px; font-weight: 800; letter-spacing: -.03em; margin: 14px 2px 18px; }

/* Search — iOS search field */
.search-box {
  display: flex; align-items: center; gap: 7px;
  padding: 10px 12px; margin-bottom: 16px;
  border-radius: 11px; background: var(--fill);
  transition: background .2s var(--ease);
}
.search-box:focus-within { background: #fff; box-shadow: 0 0 0 3px var(--green-bg); }
.search-box svg { flex-shrink: 0; color: var(--label-2); }
.search-box input { flex: 1; min-width: 0; border: none; outline: none; font-size: 17px; background: transparent; color: var(--label); }
.search-box input::placeholder { color: var(--label-2); }

/* Search results — iOS inset-grouped list */
.search-results:not(:empty) { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 18px; }
.search-row {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 12px 14px; background: none;
  border-bottom: .5px solid var(--separator);
  transition: background .15s var(--ease);
}
.search-row:last-child { border-bottom: none; }
.search-row:active { background: var(--fill); }
.search-emoji { font-size: 22px; flex-shrink: 0; width: 26px; text-align: center; }
.search-info  { display: flex; flex-direction: column; min-width: 0; gap: 1px; }
.search-info strong { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-info span   { font-size: 13px; color: var(--label-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-hint  { padding: 16px; font-size: 15px; color: var(--label-2); }
.section-label { font-size: 13px; font-weight: 600; color: var(--label-2); margin: 4px 4px 10px; }

/* Trip plan builder */
.plan-panel { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 14px; margin-bottom: 18px; }
.plan-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.plan-title { font-size: 15px; font-weight: 700; }
.plan-opt { font-size: 13px; font-weight: 600; color: var(--green); background: var(--green-bg); padding: 6px 11px; border-radius: 999px; }
.plan-opt:active { opacity: .8; }
.plan-opt:disabled { opacity: .5; }
.plan-note { font-size: 12px; color: var(--label-2); line-height: 1.45; margin-bottom: 10px; }
.plan-list { display: flex; flex-direction: column; }
.plan-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: .5px solid var(--separator); }
.plan-row:last-child { border-bottom: none; }
.plan-num { width: 22px; height: 22px; flex-shrink: 0; display: grid; place-items: center; border-radius: 50%; background: var(--green); color: #fff; font-size: 12px; font-weight: 700; }
.plan-emoji { font-size: 18px; }
.plan-name { flex: 1; min-width: 0; font-size: 15px; font-weight: 600; display: flex; flex-direction: column; }
.plan-name > small.plan-hours { font-size: 11px; font-weight: 500; color: var(--label-2); margin-top: 1px; }
.arrive-hours { padding: 10px 16px; font-size: 14px; font-weight: 600; color: var(--green); background: var(--green-bg); border-bottom: .5px solid var(--separator); }
.arrive-hours .ah-rest { font-weight: 500; color: var(--label-2); }
.plan-del { width: 26px; height: 26px; border-radius: 50%; color: var(--label-2); font-size: 13px; display: grid; place-items: center; }
.plan-del:active { background: var(--fill); }
.plan-start { width: 100%; margin-top: 12px; padding: 13px; border-radius: 12px; background: var(--green); color: #fff; font-size: 16px; font-weight: 600; transition: transform .15s var(--ease); }
.plan-start:active { transform: scale(.98); }

/* Header plan chip + overview */
.plan-chip { flex-shrink: 0; padding: 5px 10px; border-radius: 999px; background: var(--fill); color: var(--label); font-size: 13px; font-weight: 600; }
.plan-chip:active { opacity: .7; }
.plan-overview { padding: 8px 4px; display: flex; flex-direction: column; gap: 2px; }
.po-row { display: flex; align-items: center; gap: 12px; padding: 14px 12px; border-radius: var(--r); }
.po-row.current { background: var(--green-bg); }
.po-mark { width: 22px; text-align: center; font-size: 16px; color: var(--label-3); }
.po-row.done .po-mark { color: var(--green); }
.po-row.current .po-mark { color: var(--green); }
.po-emoji { font-size: 22px; }
.po-name { font-size: 17px; font-weight: 600; }
.po-row.done .po-name { color: var(--label-2); text-decoration: line-through; }

.spot-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.spot-card {
  display: flex; flex-direction: column; gap: 7px; align-items: flex-start;
  padding: 16px 15px; border-radius: var(--r);
  background: var(--card); text-align: left; box-shadow: var(--shadow);
  transition: transform .2s var(--ease), opacity .2s var(--ease);
}
.spot-card:active { transform: scale(.96); opacity: .85; }
.spot-emoji   { font-size: 30px; line-height: 1; }
.spot-name    { font-size: 15px; font-weight: 600; line-height: 1.3; }
.spot-name-en { font-size: 12px; color: var(--label-2); }

/* ══ SCREEN 2 ═══════════════════════════════════════════════════════ */
#navScreen {
  display: flex; flex-direction: column;
  height: 100dvh; background: var(--bg);
  max-width: 460px; margin: 0 auto; position: relative; overflow: hidden;
}

/* Navigation bar — iOS translucent material */
.nav-header {
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
  background: rgba(248,248,250,.82); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: .5px solid var(--separator); flex-shrink: 0; z-index: 10;
}
.back-btn { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; color: var(--green); flex-shrink: 0; transition: background .15s var(--ease); }
.back-btn:active { background: var(--fill); }
.nav-header strong { flex: 1; font-size: 17px; font-weight: 600; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dist-pill { flex-shrink: 0; padding: 5px 11px; border-radius: 999px; background: var(--green-bg); color: var(--green); font-size: 13px; font-weight: 700; letter-spacing: -.01em; }

/* Map — fills the space */
#mainMap { flex: 1; min-height: 0; position: relative; }
.scan-fab {
  position: absolute; right: 14px; bottom: 14px; z-index: 6;
  width: 54px; height: 54px; border-radius: 50%; background: var(--card);
  box-shadow: 0 2px 6px rgba(0,0,0,.12), 0 8px 20px rgba(0,0,0,.14);
  display: grid; place-items: center; font-size: 24px;
  transition: transform .15s var(--ease);
}
.scan-fab:active { transform: scale(.9); }
.map-placeholder { position: absolute; inset: 0; display: grid; place-items: center; background: var(--bg); }

/* Bottom sheet — iOS detent with grabber + rounded top, lifted over the map */
.bottom-sheet {
  flex-shrink: 0; background: var(--card);
  margin-top: -18px; border-radius: var(--r-lg) var(--r-lg) 0 0;
  box-shadow: 0 -1px 0 var(--separator), 0 -8px 28px rgba(0,0,0,.10);
  position: relative; z-index: 5;
  display: flex; flex-direction: column;
  max-height: 62vh;                       /* never cover more than ~62% — map stays visible */
  transition: height .28s var(--ease);
}
.bottom-sheet.dragging { transition: none; }
/* Grabber = full-width drag/tap zone with a centered pill */
.sheet-grabber { flex-shrink: 0; height: 24px; display: grid; place-items: center; cursor: grab; touch-action: none; }
.sheet-grabber::before { content: ''; width: 40px; height: 5px; border-radius: 3px; background: var(--label-3); transition: background .15s; }
.bottom-sheet.dragging .sheet-grabber { cursor: grabbing; }
.sheet-grabber:active::before { background: var(--label-2); }
/* Scrollable sheet body (collapses behind the grabber when dragged down) */
.sheet-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: env(safe-area-inset-bottom); }

/* Goal bar */
.goal-bar {
  display: flex; align-items: center; gap: 13px;
  padding: 12px 16px; border-bottom: .5px solid var(--separator);
  transition: background .25s var(--ease);
  touch-action: none; cursor: grab;       /* header doubles as a sheet drag handle */
}
.bottom-sheet.dragging .goal-bar { cursor: grabbing; }
.goal-icon  { font-size: 27px; flex-shrink: 0; }
.goal-text  { flex: 1; min-width: 0; }
.goal-text strong { display: block; font-size: 17px; font-weight: 600; letter-spacing: -.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.goal-text span   { font-size: 13px; color: var(--label-2); }
.goal-dist { flex-shrink: 0; font-size: 17px; font-weight: 700; color: var(--green); letter-spacing: -.02em; }

/* Waiting at a stop — the app's core "which vehicle?" moment */
.goal-bar.waiting { background: var(--green-bg); }
.goal-bar.waiting .goal-icon { animation: waitPulse 1.6s ease-in-out infinite; }
.goal-bar.waiting .goal-text strong { color: var(--green); }
.goal-bar.waiting .goal-dist { font-size: 13px; font-weight: 700; padding: 5px 11px; border-radius: 999px; background: var(--green); color: #fff; }
@keyframes waitPulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.12); } }
/* Approaching the goal — gentle "곧 도착" cue before the leg switches */
.goal-bar.near { background: var(--green-bg); }
.goal-bar.near .goal-dist { color: #fff; background: var(--green); padding: 5px 11px; border-radius: 999px; font-size: 13px; font-weight: 700; animation: waitPulse 1.2s ease-in-out infinite; }
/* Riding — calmer blue tint */
.goal-bar.riding { background: var(--blue-bg); }
.goal-bar.riding .goal-dist { font-size: 13px; font-weight: 700; padding: 5px 11px; border-radius: 999px; background: var(--blue); color: #fff; }

/* Progress row */
.progress-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; border-bottom: .5px solid var(--separator);
}
.step-dots { display: flex; align-items: center; gap: 6px; }
.step-dot  { width: 8px; height: 8px; border-radius: 50%; background: var(--label-3); transition: background .25s var(--ease), transform .25s var(--ease); }
.step-dot.active { background: var(--green); transform: scale(1.3); }
.step-dot.done   { background: var(--green); opacity: .4; }
.step-line { width: 18px; height: 2px; border-radius: 1px; background: var(--label-3); }
.step-line.done  { background: var(--green); opacity: .4; }

/* Prominent iOS filled action button */
.next-btn {
  padding: 11px 20px; border-radius: 12px; background: var(--green); color: #fff;
  font-size: 16px; font-weight: 600; letter-spacing: -.01em; flex-shrink: 0;
  transition: transform .18s var(--ease), opacity .18s var(--ease);
}
.next-btn:active { transform: scale(.95); opacity: .9; }

/* Restaurant "how to use this place" guide */
.place-guide { max-height: 40vh; overflow-y: auto; margin-bottom: 12px; -webkit-overflow-scrolling: touch; }
.pg-cuisine { font-size: 14px; font-weight: 600; color: var(--green); margin-bottom: 12px; }
.pg-sec { margin-bottom: 14px; }
.pg-sec h4 { font-size: 13px; font-weight: 600; color: var(--label-2); margin-bottom: 7px; }
.pg-menu { display: flex; flex-direction: column; gap: 1px; padding: 8px 0; border-bottom: .5px solid var(--separator); }
.pg-menu strong { font-size: 15px; font-weight: 600; }
.pg-menu span { font-size: 13px; color: var(--label-2); }
.pg-list { margin: 0; padding-left: 18px; }
.pg-list li { font-size: 14px; color: var(--label-2); line-height: 1.5; margin-bottom: 4px; }

/* Per-step web-researched info */
.leg-info { background: var(--bg); border-radius: var(--r); padding: 13px 15px; margin-bottom: 12px; }
.li-head { font-size: 13px; font-weight: 700; color: var(--label); margin-bottom: 7px; display: flex; align-items: center; gap: 7px; }
.li-web { font-size: 10px; font-weight: 700; color: var(--green); background: var(--green-bg); padding: 2px 7px; border-radius: 999px; text-transform: uppercase; letter-spacing: .04em; }
.li-summary { font-size: 14px; line-height: 1.5; color: var(--label); margin-bottom: 8px; }
.li-tips { margin: 0 0 8px; padding-left: 18px; }
.li-tips li { font-size: 13px; line-height: 1.5; color: var(--label-2); margin-bottom: 4px; }
.li-src { font-size: 12px; color: var(--label-2); }
.li-src a { color: var(--green); font-weight: 600; text-decoration: none; padding: 0 3px; }
.li-loading { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--label-2); }
.li-loading .spinner { width: 18px; height: 18px; border-width: 2px; }

/* Destination info (arrival, web-searched) */
.dest-info { background: var(--green-bg); border-radius: var(--r); padding: 14px 16px; margin-bottom: 12px; }
.di-head { font-size: 14px; font-weight: 800; color: var(--label); margin-bottom: 8px; display: flex; align-items: center; gap: 7px; }
.di-web { font-size: 10px; font-weight: 700; color: var(--green); background: #fff; padding: 2px 7px; border-radius: 999px; text-transform: uppercase; letter-spacing: .04em; }
.di-summary { font-size: 14px; line-height: 1.55; color: var(--label); margin-bottom: 6px; }
.di-history { font-size: 13px; line-height: 1.5; color: var(--label-2); margin-bottom: 8px; }
.di-sec { margin-top: 10px; }
.di-sec h4 { font-size: 13px; font-weight: 700; color: var(--label-2); margin-bottom: 6px; }
.di-list { margin: 0; padding-left: 18px; }
.di-list li { font-size: 14px; line-height: 1.5; color: var(--label-2); margin-bottom: 4px; }
.di-tmi h4 { color: var(--green); }

/* Phrase area */
.phrase-area { padding: 12px 16px calc(env(safe-area-inset-bottom) + 16px); }
.phrase-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.phrase-label { font-size: 13px; font-weight: 600; color: var(--label-2); }
.phrase-src { font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--green-bg); color: var(--green); font-weight: 600; }
.phrase-loading { font-size: 13px; color: var(--label-2); }
.phrase-scroll {
  display: flex; gap: 11px; overflow-x: auto; padding: 2px 4px 4px 0;
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
  scroll-snap-type: x proximity; scroll-padding-left: 0;
  cursor: grab; touch-action: pan-x;
}
.phrase-scroll::-webkit-scrollbar { display: none; }
.phrase-scroll.dragging { cursor: grabbing; scroll-snap-type: none; user-select: none; }
.phrase-scroll.dragging .phrase-chip { pointer-events: none; }

.phrase-chip {
  flex: 0 0 180px; padding: 13px 14px; border-radius: var(--r); background: var(--card);
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px; text-align: left;
  scroll-snap-align: start; transition: transform .15s var(--ease);
}
.phrase-chip:active { transform: scale(.97); }
.chip-ctx  { font-size: 11px; color: var(--label-2); font-weight: 600; }
.chip-ko   { font-size: 16px; font-weight: 700; color: var(--label); line-height: 1.3; letter-spacing: -.02em; }
.chip-en   { font-size: 12px; color: var(--label-2); line-height: 1.4; flex: 1; }
.chip-tap  { margin-top: 6px; font-size: 11px; font-weight: 600; color: var(--green); }

/* Fullscreen help card — hold up to a local to ask for help */
.help-overlay {
  position: fixed; inset: 0; z-index: 100; background: var(--card);
  display: flex; flex-direction: column;
  padding: calc(env(safe-area-inset-top) + 16px) 20px calc(env(safe-area-inset-bottom) + 20px);
  animation: helpIn .26s var(--ease);
}
@keyframes helpIn { from { opacity: 0; transform: scale(1.03); } to { opacity: 1; transform: none; } }
.help-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.help-badge { font-size: 14px; font-weight: 600; color: var(--green); background: var(--green-bg); padding: 7px 13px; border-radius: 999px; }
.help-close { width: 38px; height: 38px; border-radius: 50%; background: var(--fill); display: grid; place-items: center; font-size: 16px; color: var(--label-2); flex-shrink: 0; transition: transform .15s var(--ease); }
.help-close:active { transform: scale(.92); }
.help-main { flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; gap: 16px; padding: 24px 0; }
.help-ctx { font-size: 16px; font-weight: 600; color: var(--label-2); }
.help-ko  { font-size: clamp(30px, 8vw, 46px); font-weight: 800; line-height: 1.22; letter-spacing: -.02em; color: var(--label); }
.help-en  { font-size: clamp(16px, 4.5vw, 20px); color: var(--label-2); line-height: 1.4; }
.help-situation { background: var(--bg); border-radius: var(--r); padding: 16px 18px; }
.help-situation h4 { font-size: 13px; font-weight: 600; color: var(--label-2); margin-bottom: 6px; }
.help-situation p  { font-size: 16px; line-height: 1.55; color: var(--label); }

/* Camera sign-reading result */
.scan-body { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 14px; padding: 16px 4px; overflow-y: auto; }
.scan-arrow  { font-size: 92px; line-height: 1; color: var(--green); }
.scan-action { font-size: clamp(22px, 6vw, 30px); font-weight: 800; letter-spacing: -.02em; line-height: 1.25; }
.scan-detail { font-size: 15px; color: var(--label-2); line-height: 1.5; max-width: 34ch; }
.scan-read   { font-size: 13px; color: var(--label-2); background: var(--bg); padding: 10px 14px; border-radius: var(--r); max-width: 36ch; line-height: 1.5; }
.scan-phrase { background: var(--green-bg); border-radius: var(--r); padding: 14px 20px; }
.scan-phrase .sp-ko { font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.scan-phrase .sp-en { font-size: 14px; color: var(--label-2); margin-top: 3px; }
.scan-again { margin-top: 6px; padding: 12px 22px; border-radius: 12px; background: var(--green); color: #fff; font-size: 16px; font-weight: 600; transition: transform .15s var(--ease); }
.scan-again:active { transform: scale(.95); }
.scan-loading { display: flex; flex-direction: column; align-items: center; gap: 16px; color: var(--label-2); font-size: 15px; line-height: 1.5; }

/* Spinner */
.spinner { width: 28px; height: 28px; border: 3px solid var(--fill); border-top-color: var(--green); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Map overlays */
.user-dot { width: 16px; height: 16px; border-radius: 50%; background: #007aff; border: 2.5px solid #fff; box-shadow: 0 0 0 3px rgba(0,122,255,.25); transform: translate(-50%,-50%); animation: sonar 2s ease-out infinite; }
@keyframes sonar { 0%{box-shadow:0 0 0 0 rgba(0,122,255,.5)} 70%{box-shadow:0 0 0 11px rgba(0,122,255,0)} 100%{box-shadow:0 0 0 0 rgba(0,122,255,0)} }

.goal-pin { padding: 5px 11px; border-radius: 999px; background: var(--green); color: #fff; font-size: 12px; font-weight: 700; white-space: nowrap; transform: translate(-50%,-120%); box-shadow: 0 4px 12px rgba(0,0,0,.22); }
.goal-pin.transit-board { background: var(--blue); }
.goal-pin.transit-alight { background: var(--green); }
.dest-pin { padding: 6px 13px; border-radius: 999px; background: var(--white); color: var(--green); font-size: 13px; font-weight: 700; white-space: nowrap; transform: translate(-50%,-120%); box-shadow: 0 4px 14px rgba(0,0,0,.18); }

/* ── Responsive: keep a centered phone-width app, device-like on desktop ──── */
@media (min-width: 480px) {
  #selectScreen, #navScreen {
    box-shadow: 0 0 0 1px var(--separator), 0 20px 60px rgba(0,0,0,.12);
  }
  #navScreen { height: min(100dvh, 920px); margin-top: max(0px, calc((100dvh - 920px) / 2)); border-radius: 0; }
}
