benjamin5607 commited on
Commit
913da7d
ยท
verified ยท
1 Parent(s): 36f47ef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +82 -116
app.py CHANGED
@@ -8,7 +8,7 @@ import requests
8
  import io
9
 
10
  # ==========================================
11
- # ๐Ÿ” 1. ์‹œํฌ๋ฆฟ ๋ฐ ๊ธฐ๋ณธ ์„ค์ •
12
  # ==========================================
13
  GROQ_API_KEY = os.environ.get("GROQ_API_KEY")
14
  SHEET_URL = os.environ.get("PRIVATE_SHEET_URL")
@@ -24,33 +24,37 @@ st.markdown("""
24
  """, unsafe_allow_html=True)
25
 
26
  # ==========================================
27
- # 2. ๋ฐ์ดํ„ฐ ๋กœ๋“œ ๋ฐ ์ •์ œ (๊ฐ€์žฅ ์ค‘์š”!)
28
  # ==========================================
29
  PLACE_DB = {}
30
 
31
  if not GROQ_API_KEY:
32
- st.error("๐Ÿšจ 'GROQ_API_KEY'๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค! Settings > Secrets ์„ค์ •์„ ํ™•์ธํ•ด์ฃผ์„ธ์š”.")
33
 
34
  try:
35
  if SHEET_URL:
36
  response = requests.get(SHEET_URL)
37
  response.raise_for_status()
38
 
 
39
  try:
40
  df = pd.read_csv(io.StringIO(response.text), on_bad_lines='skip')
41
  except:
42
  df = pd.read_csv(io.StringIO(response.text), engine='python', on_bad_lines='skip')
43
 
44
- # [ํ•ต์‹ฌ ์ˆ˜์ • 1] ๋ฐ์ดํ„ฐ ๋Œ€์ฒญ์†Œ: ์ค„๋ฐ”๊ฟˆ(\n, \r)๊ณผ ๋”ฐ์˜ดํ‘œ ์ œ๊ฑฐ
45
- # ์ด๊ฒŒ ์—†์œผ๋ฉด ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋กœ ๋„˜์–ด๊ฐˆ ๋•Œ ์ฝ”๋“œ๊ฐ€ ๋Š๊ฒจ์„œ ์—๋Ÿฌ๊ฐ€ ๋‚จ
46
- df = df.replace({r'\r': ' ', r'\n': ' ', r'"': '', r"'": ''}, regex=True)
47
-
 
48
  df.columns = df.columns.str.strip()
49
  col_mapping = {col: 'Country' for col in df.columns if col.lower() == 'country'}
50
  df.rename(columns=col_mapping, inplace=True)
51
 
 
52
  if 'Country' in df.columns:
53
  for country, group in df.groupby('Country'):
 
54
  cleaned_group = group.fillna("").to_dict(orient='records')
55
  PLACE_DB[country] = cleaned_group
56
  else:
@@ -61,7 +65,7 @@ try:
61
  PLACE_DB = json.load(f)
62
 
63
  except Exception as e:
64
- st.error(f"โŒ ๋ฐ์ดํ„ฐ ๋กœ๋“œ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {e}")
65
  PLACE_DB = {}
66
 
67
  # ==========================================
@@ -74,11 +78,12 @@ if os.path.exists('emily.jpg'):
74
  emily_base64 = base64.b64encode(f.read()).decode()
75
  except: pass
76
 
 
77
  db_json_raw = json.dumps(PLACE_DB, ensure_ascii=False)
78
  db_base64 = base64.b64encode(db_json_raw.encode('utf-8')).decode('utf-8')
79
 
80
  # ==========================================
81
- # 4. ํ”„๋ก ํŠธ์—”๋“œ (HTML/JS/CSS) - ํƒฑํฌ ๋ฒ„์ „ ๐Ÿ›ก๏ธ
82
  # ==========================================
83
  html_code = f"""
84
  <!DOCTYPE html>
@@ -96,18 +101,9 @@ html_code = f"""
96
  :root {{ --gold: #d4af37; --dark: #0a0a0a; --text: #e0e0e0; }}
97
  body {{ margin: 0; padding: 0; background: var(--dark); color: var(--text); font-family: 'Segoe UI', sans-serif; overflow: hidden; }}
98
  .page {{ position: absolute; top: 0; left: 0; width: 100%; height: 100vh; transition: transform 0.5s ease; display: flex; flex-direction: column; }}
 
99
 
100
- #main-page {{
101
- background: linear-gradient(rgba(0,0,0,0.7), rgba(0,0,0,0.95)), url('https://images.unsplash.com/photo-1516981879613-9f5da904015f?q=80&w=2560&auto=format&fit=crop');
102
- background-size: cover; background-position: center; z-index: 100; align-items: center; justify-content: flex-start; padding-top: 20px;
103
- }}
104
-
105
- .bartender-btn {{
106
- position: fixed; bottom: 30%; right: 20px; width: 85px; height: 85px; border-radius: 50%;
107
- background-image: url('data:image/jpeg;base64,{emily_base64}'); background-size: cover; background-position: center;
108
- background-color: #222; border: 3px solid var(--gold); box-shadow: 0 8px 30px rgba(212, 175, 55, 0.6);
109
- cursor: pointer; z-index: 999; animation: bounce-float 3s ease-in-out infinite;
110
- }}
111
  @keyframes bounce-float {{ 0%, 100% {{ transform: translateY(0); }} 50% {{ transform: translateY(-15px); }} }}
112
 
113
  .lang-switcher {{ position: absolute; top: 20px; right: 20px; z-index: 200; display: flex; gap: 8px; }}
@@ -117,16 +113,8 @@ html_code = f"""
117
  .brand-title {{ font-size: 26px; font-weight: 900; color: var(--gold); letter-spacing: 4px; margin-top: 10px; text-transform: uppercase; }}
118
  .brand-subtitle {{ font-size: 11px; color: #ccc; letter-spacing: 2px; margin-bottom: 15px; }}
119
 
120
- .world-map-btn {{
121
- background: rgba(212, 175, 55, 0.2); border: 1px solid var(--gold); color: var(--gold);
122
- padding: 12px 25px; border-radius: 30px; font-weight: bold; cursor: pointer; margin-bottom: 20px;
123
- display: flex; align-items: center; gap: 8px; backdrop-filter: blur(5px);
124
- }}
125
- .passport-btn {{
126
- background: rgba(0,0,0,0.6); border: 1px solid var(--gold); color: var(--gold);
127
- padding: 8px 15px; border-radius: 20px; font-size: 12px; cursor: pointer; margin-top: 10px;
128
- display: flex; align-items: center; gap: 5px;
129
- }}
130
 
131
  .country-select-wrapper {{ width: 85%; max-width: 400px; margin-bottom: 15px; }}
132
  .country-select {{ width: 100%; padding: 14px; background: rgba(30,30,30,0.9); border: 1px solid var(--gold); color: white; font-size: 16px; border-radius: 10px; outline: none; }}
@@ -136,28 +124,16 @@ html_code = f"""
136
  .type-btn.selected {{ background: var(--gold); color: black; border-color: var(--gold); }}
137
 
138
  .place-list-container {{ width: 100%; max-width: 600px; flex: 1; overflow-y: auto; padding: 0 20px 120px 20px; box-sizing: border-box; }}
139
-
140
- .place-card {{
141
- background: rgba(30,30,30,0.6); backdrop-filter: blur(10px);
142
- border: 1px solid rgba(255,255,255,0.1); border-radius: 15px;
143
- padding: 18px; margin-bottom: 15px; position: relative; transition: all 0.3s ease;
144
- }}
145
- .place-card.visited {{
146
- background: linear-gradient(135deg, rgba(40,10,10,0.9), rgba(20,20,20,0.9));
147
- border: 1px solid var(--gold);
148
- box-shadow: 0 0 15px rgba(212, 175, 55, 0.2);
149
- }}
150
- .visited-badge {{
151
- position: absolute; top: 10px; right: 10px;
152
- background: var(--gold); color: black; font-size: 10px; font-weight: bold;
153
- padding: 3px 8px; border-radius: 10px; display: none;
154
- }}
155
  .place-card.visited .visited-badge {{ display: block; }}
156
 
157
  .pc-name {{ font-size: 18px; font-weight: bold; color: white; }}
158
  .place-card.visited .pc-name {{ color: var(--gold); }}
159
  .pc-cat {{ font-size: 11px; color: var(--gold); font-weight: bold; text-transform: uppercase; margin-bottom: 4px; }}
160
  .pc-desc {{ font-size: 13px; color: #bbb; line-height: 1.5; margin-top: 5px; }}
 
161
  .card-actions {{ display: flex; gap: 10px; margin-top: 15px; }}
162
  .btn-action {{ flex: 1; padding: 12px; border-radius: 8px; font-size: 12px; font-weight: bold; border: none; cursor: pointer; }}
163
  .btn-ai {{ background: var(--gold); color: black; }}
@@ -282,44 +258,21 @@ html_code = f"""
282
  let miniMap = null, worldMap = null, worldMarkers = L.layerGroup();
283
  let chatHistory = [];
284
  let currentDetailPlace = null;
285
- let currentFilteredList = [];
286
 
287
- // [ํ•ต์‹ฌ ์ˆ˜์ • 2] ์ง€๋„ ํŒ์—…์šฉ ๋ฐ์ดํ„ฐ ์ €์žฅ์†Œ (๊ธ€์ž ๊นจ์ง ๋ฐฉ์ง€์šฉ)
288
- let MAP_POPUP_DATA = {{}};
 
 
289
 
290
  const TRANSLATIONS = {{
291
- "KO": {{
292
- "sub": "๊ธ€๋กœ๋ฒŒ ์ฃผ๋ฅ˜ ํ—ค๋ฆฌํ‹ฐ์ง€ ํˆฌ์–ด", "ai": "Korean", "mapBtn": "๐Ÿ—บ๏ธ ์›”๋“œ๋งต ํƒํ—˜", "passBtn": "๐Ÿ“˜ ๋‚ด ์—ฌ๊ถŒ",
293
- "filters": ["๐ŸŒ ์ „์ฒด", "๐Ÿบ ์ „ํ†ต์ฃผ", "๐Ÿฅƒ ์œ„์Šคํ‚ค", "๐Ÿบ ๋งฅ์ฃผ", "๐Ÿท ์™€์ธ", "๐Ÿน ๋ฐ”"],
294
- "chatPlace": "์—๋ฐ€๋ฆฌ์—๊ฒŒ ๋งํ•ด๋ด, ์ž๊ธฐ์•ผ...", "send": "์ „์†ก", "home": "๐Ÿ  ํ™ˆ",
295
- "searchPlace": "์žฅ์†Œ ๊ฒ€์ƒ‰ (์˜ˆ: ๊ฐ•๋‚จ)", "emilyName": "์—๋ฐ€๋ฆฌ (Emily)", "reportHeader": "๋ฆฌํฌํŠธ",
296
- "aiBtn": "AI ๋ฆฌ๋ทฐ", "mapLinkBtn": "์ง€๋„"
297
- }},
298
- "EN": {{
299
- "sub": "GLOBAL ALCOHOL HERITAGE TOUR", "ai": "English", "mapBtn": "๐Ÿ—บ๏ธ WORLD MAP EXPLORER", "passBtn": "๐Ÿ“˜ MY PASSPORT",
300
- "filters": ["๐ŸŒ All", "๐Ÿบ Trad.", "๐Ÿฅƒ Whiskey", "๐Ÿบ Beer", "๐Ÿท Wine", "๐Ÿน Bar"],
301
- "chatPlace": "Talk to Emily...", "send": "SEND", "home": "๐Ÿ  HOME",
302
- "searchPlace": "Search (e.g. Gangnam)", "emilyName": "Emily", "reportHeader": "REPORT",
303
- "aiBtn": "AI REVIEW", "mapLinkBtn": "MAP"
304
- }},
305
- "JP": {{
306
- "sub": "ไธ–็•ŒใฎใŠ้…’ใƒ˜ใƒชใƒ†ใƒผใ‚ธใƒ„ใ‚ขใƒผ", "ai": "Japanese", "mapBtn": "๐Ÿ—บ๏ธ ไธ–็•Œๅœฐๅ›ณๆŽข็ดข", "passBtn": "๐Ÿ“˜ ใƒžใ‚คใƒ‘ใ‚นใƒใƒผใƒˆ",
307
- "filters": ["๐ŸŒ ๅ…จใฆ", "๐Ÿบ ไผ็ตฑ้…’", "๐Ÿฅƒ ใ‚ฆใ‚คใ‚นใ‚ญใƒผ", "๐Ÿบ ใƒ“ใƒผใƒซ", "๐Ÿท ใƒฏใ‚คใƒณ", "๐Ÿน ใƒใƒผ"],
308
- "chatPlace": "ใ‚จใƒŸใƒชใƒผใซ่ฉฑใ—ใ‹ใ‘ใฆ...", "send": "้€ไฟก", "home": "๐Ÿ  ใƒ›ใƒผใƒ ",
309
- "searchPlace": "ๅ ดๆ‰€ๆคœ็ดข (ไพ‹: ๆ–ฐๅฎฟ)", "emilyName": "ใ‚จใƒŸใƒชใƒผ (Emily)", "reportHeader": "ใƒฌใƒใƒผใƒˆ",
310
- "aiBtn": "AI ใƒฌใƒ“ใƒฅใƒผ", "mapLinkBtn": "ๅœฐๅ›ณ"
311
- }},
312
- "CN": {{
313
- "sub": "ๅ…จ็ƒ้…’็ฑป้—ไบงไน‹ๆ—…", "ai": "Chinese", "mapBtn": "๐Ÿ—บ๏ธ ไธ–็•Œๅœฐๅ›พๆŽข็ดข", "passBtn": "๐Ÿ“˜ ๆˆ‘็š„ๆŠค็…ง",
314
- "filters": ["๐ŸŒ ๅ…จ้ƒจ", "๐Ÿบ ไผ ็ปŸ้…’", "๐Ÿฅƒ ๅจๅฃซๅฟŒ", "๐Ÿบ ๅ•ค้…’", "๐Ÿท ่‘ก่„้…’", "๐Ÿน ้…’ๅง"],
315
- "chatPlace": "่ทŸ่‰พ็ฑณไธฝ่Šๅคฉ...", "send": "ๅ‘้€", "home": "๐Ÿ  ไธป้กต",
316
- "searchPlace": "ๆœ็ดขๅœฐ็‚น (ไพ‹ๅฆ‚: ๆฑŸๅ—)", "emilyName": "่‰พ็ฑณไธฝ (Emily)", "reportHeader": "ๆŠฅๅ‘Š",
317
- "aiBtn": "AI ็‚น่ฏ„", "mapLinkBtn": "ๅœฐๅ›พ"
318
- }}
319
  }};
320
 
321
- const GREETINGS = {{ "KO": "์•ˆ๋…•, ์ž๊ธฐ? ๋ญ ๋งˆ์‹œ๊ณ  ์‹ถ์–ด?", "EN": "Hey darling, thirsty?", "JP": "ใ‚ใ‚‰ใ€ใƒใƒ‹ใƒผใ€‚ไฝ•ใ‹้ฃฒใ‚€๏ผŸ", "CN": "ไบฒ็ˆฑ็š„๏ผŒๆƒณๅ–็‚นไป€ไนˆ๏ผŸ" }};
322
- const LOAD_MSGS = {{ "KO": ["์ˆ ์žฅ ๋’ค์ง€๋Š” ์ค‘...", "์ž ์‹œ๋งŒ ๊ธฐ๋‹ค๋ ค์ค˜ ์ž๊ธฐ์•ผ"], "EN": ["Checking cellar...", "One moment..."], "JP": ["็ขบ่ชไธญ...", "ๅพ…ใฃใฆใฆใญ"], "CN": ["ๆญฃๅœจๆŸฅๆ‰พ...", "็จ็ญ‰..."] }};
323
  const CAT_MAP = {{ "Traditional": 1, "Whiskey": 2, "Beer": 3, "Wine": 4, "Bar": 5 }};
324
  const getRandom = (arr) => arr[Math.floor(Math.random() * arr.length)];
325
 
@@ -355,52 +308,66 @@ html_code = f"""
355
  else {{ return "https://www.google.com/maps/search/" + encodeURIComponent(name) + "/@" + lat + "," + lon + ",18z"; }}
356
  }}
357
 
358
- function openMapLink(url) {{ window.open(url, '_blank'); }}
359
-
360
  function renderList() {{
361
  const list = document.getElementById('place-list'); list.innerHTML = "";
362
  const stamps = getStamps();
363
  const visitedSet = new Set(stamps.map(s => s ? s.name + '|' + s.country : ''));
 
364
  const filtered = (PLACE_DB[selectedCountry] || []).filter(p => selectedType === "All" || p.category === selectedType);
365
- currentFilteredList = filtered;
 
366
  const t = TRANSLATIONS[currentLang];
367
 
368
  filtered.forEach((p, idx) => {{
369
- const card = document.createElement('div');
370
  const isVisited = visitedSet.has(p.name + '|' + selectedCountry);
371
  card.className = isVisited ? 'place-card visited' : 'place-card';
372
  let desc = (currentLang === 'KO' ? p.desc_ko : (currentLang === 'EN' ? p.desc_en : (currentLang === 'JP' ? p.desc_jp : p.desc_cn))) || p.desc_en || "No description.";
 
 
 
 
 
373
  let catIdx = CAT_MAP[p.category] || 0;
374
  let translatedCat = t.filters[catIdx] || p.category;
375
- const addr = p.address || "";
376
- const mapLink = getMapUrl(p.name, selectedCountry, p.lat, p.lon, addr);
377
 
378
- // [์•ˆ์ „์žฅ์น˜] HTML ์ƒ์„ฑ ์‹œ ํŠน์ˆ˜๋ฌธ์ž ์ œ๊ฑฐ
379
- const safeName = String(p.name).replace(/['"]/g, "");
380
- const safeDesc = String(desc).replace(/['"]/g, "");
381
- const safeMapLink = mapLink.replace(/['"]/g, "");
382
-
383
- card.innerHTML = "<div class='visited-badge'>VISITED ๐Ÿ’ฎ</div><b>" + safeName + "</b><div class='pc-cat'>" + translatedCat + "</div><div class='pc-desc'>" + safeDesc + "</div>" +
384
- "<div class='card-actions'><button class='btn-action btn-ai' onclick='openDetailByIndex(" + idx + ")'>" + t.aiBtn + "</button>" +
385
- "<button class='btn-action btn-map' onclick='openMapLink(\"" + safeMapLink + "\")'>" + t.mapLinkBtn + "</button></div>";
386
  list.appendChild(card);
387
  }});
388
  }}
389
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
390
  function getStamps() {{
391
  try {{ return JSON.parse(localStorage.getItem('drunk_passport') || '[]'); }}
392
  catch(e) {{ localStorage.setItem('drunk_passport', '[]'); return []; }}
393
  }}
394
 
395
  function stampCurrentPlace() {{
396
- if(!currentDetailPlace) {{ alert("์žฅ์†Œ ์ •๋ณด๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค!"); return; }}
397
  const stamps = getStamps();
398
  const exists = stamps.find(s => s.name === currentDetailPlace.name && s.country === currentDetailPlace.country);
399
- if(exists) {{ alert("์ด๋ฏธ ๋„์žฅ์ด ์žˆ์Šต๋‹ˆ๋‹ค! ๐Ÿ’ฎ"); return; }}
400
  stamps.push({{ name: currentDetailPlace.name, country: currentDetailPlace.country, date: new Date().toLocaleDateString() }});
401
  localStorage.setItem('drunk_passport', JSON.stringify(stamps));
402
  renderList();
403
- alert("์ธ์ฆ ์™„๋ฃŒ! ๐Ÿ’ฎ");
404
  }}
405
 
406
  function openPassportPage() {{ document.getElementById('passport-page').style.transform = 'translateY(0%)'; renderPassport(); }}
@@ -414,7 +381,7 @@ html_code = f"""
414
  el.innerHTML = "<div class='stamp-mark' style='transform: rotate(" + rot + "deg)'><div class='stamp-country'>" + s.country + "</div><div class='stamp-name'>" + s.name + "</div><div class='stamp-date'>" + s.date + "</div></div>";
415
  grid.appendChild(el);
416
  }});
417
- if(stamps.length === 0) grid.innerHTML = "<div style='color:#666; text-align:center; width:100%; margin-top:50px; grid-column: 1/-1;'>๋„์žฅ์ด ์—†์–ด์š” ใ… ใ… </div>";
418
  }}
419
 
420
  function exportData() {{
@@ -430,9 +397,9 @@ html_code = f"""
430
  reader.onload = function(e) {{
431
  try {{
432
  const data = JSON.parse(e.target.result);
433
- if(Array.isArray(data)) {{ localStorage.setItem('drunk_passport', JSON.stringify(data)); renderPassport(); renderList(); alert("Loaded!"); }}
434
  else {{ alert("Invalid File"); }}
435
- }} catch(err) {{ alert("Error"); }}
436
  }};
437
  reader.readAsText(file);
438
  }}
@@ -479,24 +446,26 @@ html_code = f"""
479
 
480
  function addChatMessage(t, s, html=false) {{ const box = document.getElementById('chat-messages'); const div = document.createElement('div'); div.className = "msg " + s; if(html) div.innerHTML = t.replace(/\\n/g, '<br>'); else div.innerText = t; box.appendChild(div); box.scrollTop = box.scrollHeight; return div; }}
481
 
482
- // [ํ•ต์‹ฌ ์ˆ˜์ • 3] ์›”๋“œ๋งต ํŒ์—… ์ƒ์„ฑ ์‹œ '์ขŒํ‘œ'๋ฅผ ID๋กœ ์‚ฌ์šฉํ•˜์—ฌ ๋ฌธ์ž์—ด ์ถฉ๋Œ ์™„๋ฒฝ ๋ฐฉ์ง€
483
  function openWorldMapPage() {{
484
  document.getElementById('world-map-page').style.transform = 'translateY(0%)';
485
  if(!worldMap) {{
486
  worldMap = L.map('full-map').setView([20, 0], 2); L.tileLayer('https://{{s}}.tile.openstreetmap.org/{{z}}/{{x}}/{{y}}.png').addTo(worldMap);
487
- MAP_POPUP_DATA = {{}}; // ์ดˆ๊ธฐํ™”
488
 
489
  Object.keys(PLACE_DB).forEach(c => PLACE_DB[c].forEach(p => {{
490
  if(p.lat && p.lon) {{
491
- // ์ขŒํ‘œ๋ฅผ ๊ณ ์œ  ํ‚ค(Key)๋กœ ์‚ฌ์šฉ
492
  const key = p.lat + "_" + p.lon;
493
- MAP_POPUP_DATA[key] = {{ name: p.name, country: c, url: getMapUrl(p.name, c, p.lat, p.lon, "") }};
 
 
494
 
495
- // HTML์—๋Š” ์˜ค์ง 'key'๋งŒ ์ „๋‹ฌ (ํŠน์ˆ˜๋ฌธ์ž ์—†์Œ -> ์—๋Ÿฌ ์—†์Œ)
496
- const popupContent = "<div style='text-align:center'><b>" + p.name + "</b><br>" +
497
  "<div style='display:flex; gap:5px; margin-top:5px; justify-content:center;'>" +
498
- "<button onclick=\"openDetailFromKey('" + key + "')\" style='background:#d4af37; border:none; border-radius:4px; padding:4px 8px; font-size:11px; cursor:pointer;'>๐Ÿค– REVIEW</button>" +
499
- "<button onclick=\"openMapFromKey('" + key + "')\" style='background:#333; color:white; border:1px solid #555; border-radius:4px; padding:4px 8px; font-size:11px; cursor:pointer;'>๐Ÿ—บ๏ธ MAP</button>" +
500
  "</div></div>";
501
  L.marker([p.lat, p.lon]).bindPopup(popupContent).addTo(worldMap);
502
  }}
@@ -505,14 +474,14 @@ html_code = f"""
505
  setTimeout(() => worldMap.invalidateSize(), 400);
506
  }}
507
 
508
- // [์ƒˆ๋กœ์šด ํ•จ์ˆ˜] Key๋กœ ๋ฐ์ดํ„ฐ ์ฐพ์•„์„œ ์‹คํ–‰
509
- function openDetailFromKey(key) {{
510
- const data = MAP_POPUP_DATA[key];
511
  if(data) {{ closeWorldMapPage(); openDetail(data.name, data.country); }}
512
  }}
513
 
514
- function openMapFromKey(key) {{
515
- const data = MAP_POPUP_DATA[key];
516
  if(data) window.open(data.url, '_blank');
517
  }}
518
 
@@ -526,8 +495,7 @@ html_code = f"""
526
  function flyToUserLocation() {{ if(userLat && userLon) {{ worldMap.flyTo([userLat, userLon], 13); L.marker([userLat, userLon]).addTo(worldMap).bindPopup("๐Ÿ“ You").openPopup(); }} else alert("GPS..."); }}
527
  function closeWorldMapPage() {{ document.getElementById('world-map-page').style.transform = 'translateY(100%)'; }}
528
 
529
- function openDetailFromMap(n, c) {{ closeWorldMapPage(); openDetail(n, c); }}
530
- function openDetailByIndex(idx) {{ const p = currentFilteredList[idx]; if(p) openDetail(p.name, selectedCountry); }}
531
  async function openDetail(n, c) {{
532
  const p = (PLACE_DB[c] || []).find(x => x.name === n); if(!p) return;
533
  currentDetailPlace = {{ name: n, country: c }};
@@ -540,8 +508,6 @@ html_code = f"""
540
  }}
541
 
542
  function closeChat() {{ document.getElementById('chat-page').style.transform = 'translateY(100%)'; }}
543
- function closeDetail() {{ document.getElementById('detail-page').style.transform = 'translateX(100%)'; }}
544
- function closeWorldMapPage() {{ document.getElementById('world-map-page').style.transform = 'translateY(100%)'; }}
545
  function closePassportPage() {{ document.getElementById('passport-page').style.transform = 'translateY(100%)'; }}
546
  </script>
547
  </body>
 
8
  import io
9
 
10
  # ==========================================
11
+ # ๐Ÿ” 1. ์„ค์ • ๋ฐ ์‹œํฌ๋ฆฟ ๋กœ๋“œ
12
  # ==========================================
13
  GROQ_API_KEY = os.environ.get("GROQ_API_KEY")
14
  SHEET_URL = os.environ.get("PRIVATE_SHEET_URL")
 
24
  """, unsafe_allow_html=True)
25
 
26
  # ==========================================
27
+ # 2. ๋ฐ์ดํ„ฐ ๋กœ๋“œ ๋ฐ "๊ฐ•๋ ฅํ•œ" ์ •์ œ
28
  # ==========================================
29
  PLACE_DB = {}
30
 
31
  if not GROQ_API_KEY:
32
+ st.error("๐Ÿšจ 'GROQ_API_KEY'๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค! Settings > Secrets๋ฅผ ํ™•์ธํ•ด์ฃผ์„ธ์š”.")
33
 
34
  try:
35
  if SHEET_URL:
36
  response = requests.get(SHEET_URL)
37
  response.raise_for_status()
38
 
39
+ # 1. CSV ํŒŒ์‹ฑ
40
  try:
41
  df = pd.read_csv(io.StringIO(response.text), on_bad_lines='skip')
42
  except:
43
  df = pd.read_csv(io.StringIO(response.text), engine='python', on_bad_lines='skip')
44
 
45
+ # 2. [๊ฐ€์žฅ ์ค‘์š”] ๋ฐ์ดํ„ฐ ๋Œ€์ฒญ์†Œ (Sanitization)
46
+ # ์ค„๋ฐ”๊ฟˆ, ํƒญ, ๋”ฐ์˜ดํ‘œ ๋“ฑ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋ฅผ ๊นจ๋œจ๋ฆด ์ˆ˜ ์žˆ๋Š” ๋ชจ๋“  ํŠน์ˆ˜๋ฌธ์ž ์ œ๊ฑฐ/์น˜ํ™˜
47
+ df = df.replace({r'\r': ' ', r'\n': ' ', r'\t': ' ', r'"': "'"}, regex=True)
48
+
49
+ # ์ปฌ๋Ÿผ ์ด๋ฆ„ ์ •๋ฆฌ
50
  df.columns = df.columns.str.strip()
51
  col_mapping = {col: 'Country' for col in df.columns if col.lower() == 'country'}
52
  df.rename(columns=col_mapping, inplace=True)
53
 
54
+ # 3. JSON ๊ตฌ์กฐ ๋ณ€ํ™˜
55
  if 'Country' in df.columns:
56
  for country, group in df.groupby('Country'):
57
+ # NaN ๊ฐ’์„ ๋นˆ ๋ฌธ์ž์—ด๋กœ ์ฒ˜๋ฆฌ
58
  cleaned_group = group.fillna("").to_dict(orient='records')
59
  PLACE_DB[country] = cleaned_group
60
  else:
 
65
  PLACE_DB = json.load(f)
66
 
67
  except Exception as e:
68
+ st.error(f"โŒ ๋ฐ์ดํ„ฐ ๋กœ๋“œ ์‹คํŒจ: {e}")
69
  PLACE_DB = {}
70
 
71
  # ==========================================
 
78
  emily_base64 = base64.b64encode(f.read()).decode()
79
  except: pass
80
 
81
+ # JSON ๋คํ”„ ์‹œ ensure_ascii=False๋กœ ํ•œ๊ธ€ ๊นจ์ง ๋ฐฉ์ง€
82
  db_json_raw = json.dumps(PLACE_DB, ensure_ascii=False)
83
  db_base64 = base64.b64encode(db_json_raw.encode('utf-8')).decode('utf-8')
84
 
85
  # ==========================================
86
+ # 4. ํ”„๋ก ํŠธ์—”๋“œ (HTML/JS/CSS) - Safe Logic ์ ์šฉ
87
  # ==========================================
88
  html_code = f"""
89
  <!DOCTYPE html>
 
101
  :root {{ --gold: #d4af37; --dark: #0a0a0a; --text: #e0e0e0; }}
102
  body {{ margin: 0; padding: 0; background: var(--dark); color: var(--text); font-family: 'Segoe UI', sans-serif; overflow: hidden; }}
103
  .page {{ position: absolute; top: 0; left: 0; width: 100%; height: 100vh; transition: transform 0.5s ease; display: flex; flex-direction: column; }}
104
+ #main-page {{ background: linear-gradient(rgba(0,0,0,0.7), rgba(0,0,0,0.95)), url('https://images.unsplash.com/photo-1516981879613-9f5da904015f?q=80&w=2560&auto=format&fit=crop'); background-size: cover; background-position: center; z-index: 100; align-items: center; justify-content: flex-start; padding-top: 20px; }}
105
 
106
+ .bartender-btn {{ position: fixed; bottom: 30%; right: 20px; width: 85px; height: 85px; border-radius: 50%; background-image: url('data:image/jpeg;base64,{emily_base64}'); background-size: cover; background-position: center; background-color: #222; border: 3px solid var(--gold); box-shadow: 0 8px 30px rgba(212, 175, 55, 0.6); cursor: pointer; z-index: 999; animation: bounce-float 3s ease-in-out infinite; }}
 
 
 
 
 
 
 
 
 
 
107
  @keyframes bounce-float {{ 0%, 100% {{ transform: translateY(0); }} 50% {{ transform: translateY(-15px); }} }}
108
 
109
  .lang-switcher {{ position: absolute; top: 20px; right: 20px; z-index: 200; display: flex; gap: 8px; }}
 
113
  .brand-title {{ font-size: 26px; font-weight: 900; color: var(--gold); letter-spacing: 4px; margin-top: 10px; text-transform: uppercase; }}
114
  .brand-subtitle {{ font-size: 11px; color: #ccc; letter-spacing: 2px; margin-bottom: 15px; }}
115
 
116
+ .world-map-btn {{ background: rgba(212, 175, 55, 0.2); border: 1px solid var(--gold); color: var(--gold); padding: 12px 25px; border-radius: 30px; font-weight: bold; cursor: pointer; margin-bottom: 20px; display: flex; align-items: center; gap: 8px; backdrop-filter: blur(5px); }}
117
+ .passport-btn {{ background: rgba(0,0,0,0.6); border: 1px solid var(--gold); color: var(--gold); padding: 8px 15px; border-radius: 20px; font-size: 12px; cursor: pointer; margin-top: 10px; display: flex; align-items: center; gap: 5px; }}
 
 
 
 
 
 
 
 
118
 
119
  .country-select-wrapper {{ width: 85%; max-width: 400px; margin-bottom: 15px; }}
120
  .country-select {{ width: 100%; padding: 14px; background: rgba(30,30,30,0.9); border: 1px solid var(--gold); color: white; font-size: 16px; border-radius: 10px; outline: none; }}
 
124
  .type-btn.selected {{ background: var(--gold); color: black; border-color: var(--gold); }}
125
 
126
  .place-list-container {{ width: 100%; max-width: 600px; flex: 1; overflow-y: auto; padding: 0 20px 120px 20px; box-sizing: border-box; }}
127
+ .place-card {{ background: rgba(30,30,30,0.6); backdrop-filter: blur(10px); border: 1px solid rgba(255,255,255,0.1); border-radius: 15px; padding: 18px; margin-bottom: 15px; position: relative; transition: all 0.3s ease; }}
128
+ .place-card.visited {{ background: linear-gradient(135deg, rgba(40,10,10,0.9), rgba(20,20,20,0.9)); border: 1px solid var(--gold); box-shadow: 0 0 15px rgba(212, 175, 55, 0.2); }}
129
+ .visited-badge {{ position: absolute; top: 10px; right: 10px; background: var(--gold); color: black; font-size: 10px; font-weight: bold; padding: 3px 8px; border-radius: 10px; display: none; }}
 
 
 
 
 
 
 
 
 
 
 
 
 
130
  .place-card.visited .visited-badge {{ display: block; }}
131
 
132
  .pc-name {{ font-size: 18px; font-weight: bold; color: white; }}
133
  .place-card.visited .pc-name {{ color: var(--gold); }}
134
  .pc-cat {{ font-size: 11px; color: var(--gold); font-weight: bold; text-transform: uppercase; margin-bottom: 4px; }}
135
  .pc-desc {{ font-size: 13px; color: #bbb; line-height: 1.5; margin-top: 5px; }}
136
+
137
  .card-actions {{ display: flex; gap: 10px; margin-top: 15px; }}
138
  .btn-action {{ flex: 1; padding: 12px; border-radius: 8px; font-size: 12px; font-weight: bold; border: none; cursor: pointer; }}
139
  .btn-ai {{ background: var(--gold); color: black; }}
 
258
  let miniMap = null, worldMap = null, worldMarkers = L.layerGroup();
259
  let chatHistory = [];
260
  let currentDetailPlace = null;
 
261
 
262
+ // [ํ•ต์‹ฌ ๋ณ€๊ฒฝ 1] ๋ฆฌ์ŠคํŠธ์™€ ๋งต ๋ฐ์ดํ„ฐ "๊ธˆ๊ณ " (Global Cache)
263
+ // HTML์— ๋ฐ์ดํ„ฐ๋ฅผ ์ง์ ‘ ๋„ฃ์ง€ ์•Š๊ณ , ์ด๊ณณ์— ์ €์žฅ ํ›„ "๋ฒˆํ˜ธํ‘œ(Key)"๋กœ๋งŒ ๋ถˆ๋Ÿฌ์˜ต๋‹ˆ๋‹ค.
264
+ let LIST_CACHE = [];
265
+ let MAP_CACHE = {{}};
266
 
267
  const TRANSLATIONS = {{
268
+ "KO": {{ "sub": "๊ธ€๋กœ๋ฒŒ ์ฃผ๋ฅ˜ ํ—ค๋ฆฌํ‹ฐ์ง€ ํˆฌ์–ด", "ai": "Korean", "mapBtn": "๐Ÿ—บ๏ธ ์›”๋“œ๋งต ํƒํ—˜", "passBtn": "๐Ÿ“˜ ๋‚ด ์—ฌ๊ถŒ", "filters": ["๐ŸŒ ์ „์ฒด", "๐Ÿบ ์ „ํ†ต์ฃผ", "๐Ÿฅƒ ์œ„์Šคํ‚ค", "๐Ÿบ ๋งฅ์ฃผ", "๐Ÿท ์™€์ธ", "๐Ÿน ๋ฐ”"], "chatPlace": "์—๋ฐ€๋ฆฌ์—๊ฒŒ ๋งํ•ด๋ด, ์ž๊ธฐ์•ผ...", "send": "์ „์†ก", "home": "๐Ÿ  ํ™ˆ", "searchPlace": "์žฅ์†Œ ๊ฒ€์ƒ‰ (์˜ˆ: ๊ฐ•๋‚จ)", "emilyName": "์—๋ฐ€๋ฆฌ (Emily)", "reportHeader": "๋ฆฌํฌํŠธ", "aiBtn": "AI ๋ฆฌ๋ทฐ", "mapLinkBtn": "์ง€๋„" }},
269
+ "EN": {{ "sub": "GLOBAL ALCOHOL HERITAGE TOUR", "ai": "English", "mapBtn": "๐Ÿ—บ๏ธ WORLD MAP EXPLORER", "passBtn": "๐Ÿ“˜ MY PASSPORT", "filters": ["๐ŸŒ All", "๐Ÿบ Trad.", "๐Ÿฅƒ Whiskey", "๐Ÿบ Beer", "๐Ÿท Wine", "๐Ÿน Bar"], "chatPlace": "Talk to Emily...", "send": "SEND", "home": "๐Ÿ  HOME", "searchPlace": "Search (e.g. Gangnam)", "emilyName": "Emily", "reportHeader": "REPORT", "aiBtn": "AI REVIEW", "mapLinkBtn": "MAP" }},
270
+ "JP": {{ "sub": "ไธ–็•ŒใฎใŠ้…’ใƒ˜ใƒชใƒ†ใƒผใ‚ธใƒ„ใ‚ขใƒผ", "ai": "Japanese", "mapBtn": "๐Ÿ—บ๏ธ ไธ–็•Œๅœฐๅ›ณๆŽข็ดข", "passBtn": "๐Ÿ“˜ ใƒžใ‚คใƒ‘ใ‚นใƒใƒผใƒˆ", "filters": ["๐ŸŒ ๅ…จใฆ", "๐Ÿบ ไผ็ตฑ้…’", "๐Ÿฅƒ ใ‚ฆใ‚คใ‚นใ‚ญใƒผ", "๐Ÿบ ใƒ“ใƒผใƒซ", "๐Ÿท ใƒฏใ‚คใƒณ", "๐Ÿน ใƒใƒผ"], "chatPlace": "ใ‚จใƒŸใƒชใƒผใซ่ฉฑใ—ใ‹ใ‘ใฆ...", "send": "้€ไฟก", "home": "๐Ÿ  ใƒ›ใƒผใƒ ", "searchPlace": "ๅ ดๆ‰€ๆคœ็ดข (ไพ‹: ๆ–ฐๅฎฟ)", "emilyName": "ใ‚จใƒŸใƒชใƒผ (Emily)", "reportHeader": "ใƒฌใƒใƒผใƒˆ", "aiBtn": "AI ใƒฌใƒ“ใƒฅใƒผ", "mapLinkBtn": "ๅœฐๅ›ณ" }},
271
+ "CN": {{ "sub": "ๅ…จ็ƒ้…’็ฑป้—ไบงไน‹ๆ—…", "ai": "Chinese", "mapBtn": "๐Ÿ—บ๏ธ ไธ–็•Œๅœฐๅ›พๆŽข็ดข", "passBtn": "๐Ÿ“˜ ๆˆ‘็š„ๆŠค็…ง", "filters": ["๐ŸŒ ๅ…จ้ƒจ", "๐Ÿบ ไผ ็ปŸ้…’", "๐Ÿฅƒ ๅจๅฃซๅฟŒ", "๐Ÿบ ๅ•ค้…’", "๐Ÿท ่‘ก่„้…’", "๐Ÿน ้…’ๅง"], "chatPlace": "่ทŸ่‰พ็ฑณไธฝ่Šๅคฉ...", "send": "ๅ‘้€", "home": "๐Ÿ  ไธป้กต", "searchPlace": "ๆœ็ดขๅœฐ็‚น (ไพ‹ๅฆ‚: ๆฑŸๅ—)", "emilyName": "่‰พ็ฑณไธฝ (Emily)", "reportHeader": "ๆŠฅๅ‘Š", "aiBtn": "AI ็‚น่ฏ„", "mapLinkBtn": "ๅœฐๅ›พ" }}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
272
  }};
273
 
274
+ const GREETINGS = {{ "KO": "์•ˆ๋…•, ์ž๊ธฐ? ์˜ค๋Š˜ ์ •๋ง ๊ณ ์ƒ ๋งŽ์•˜์–ด. ์—๋ฐ€๋ฆฌํ•œํ…Œ ๋ญ๋“  ๋ฌผ์–ด๋ด~", "EN": "Hey darling, rough day? Let Emily pour you a drink.", "JP": "ใ‚ใ‚‰ใ€ใƒใƒ‹ใƒผใ€‚ไปŠๆ—ฅใฏใŠ็–ฒใ‚Œๆง˜ใ€‚ใ‚จใƒŸใƒชใƒผใซใชใ‚“ใงใ‚‚่žใ„ใฆ๏ผŸ", "CN": "ไบฒ็ˆฑ็š„๏ผŒไปŠๅคฉ่พ›่‹ฆไบ†ใ€‚ๆœ‰ไป€ไนˆๆƒณๅ–็š„ๅ—๏ผŸ" }};
275
+ const LOAD_MSGS = {{ "KO": ["์Œ~ ์ž๊ธฐ๋ฅผ ์œ„ํ•œ ์„ฑ์ง€๊ฐ€ ์–ด๋”” ์žˆ๋”๋ผ?", "๊ธˆ๋ฐœ ๋จธ๋ฆฌ ์ข€ ์ •๋ฆฌํ•˜๊ณ  ์•Œ๋ ค์ค„๊ฒŒ!"], "EN": ["Searching for your perfect spot...", "Fixing my hair, one sec!"], "JP": ["้›†ไธญใ—ใฆใ‚‹ใ‚...", "้ซชใ‚’ๆ•ดใˆใฆใ™ใใซๆ•™ใˆใ‚‹ใ‚ใญ"], "CN": ["ๆญฃๅœจๅ€พๅฌ...", "ๆญฃๅœจๆ•ด็†้‡‘ๅ‘..."] }};
276
  const CAT_MAP = {{ "Traditional": 1, "Whiskey": 2, "Beer": 3, "Wine": 4, "Bar": 5 }};
277
  const getRandom = (arr) => arr[Math.floor(Math.random() * arr.length)];
278
 
 
308
  else {{ return "https://www.google.com/maps/search/" + encodeURIComponent(name) + "/@" + lat + "," + lon + ",18z"; }}
309
  }}
310
 
311
+ // [ํ•ต์‹ฌ ๋ณ€๊ฒฝ 2] ๋ฆฌ์ŠคํŠธ ๋ Œ๋”๋ง ๋กœ์ง (์ธ๋ฑ์Šค ๊ธฐ๋ฐ˜)
 
312
  function renderList() {{
313
  const list = document.getElementById('place-list'); list.innerHTML = "";
314
  const stamps = getStamps();
315
  const visitedSet = new Set(stamps.map(s => s ? s.name + '|' + s.country : ''));
316
+
317
  const filtered = (PLACE_DB[selectedCountry] || []).filter(p => selectedType === "All" || p.category === selectedType);
318
+ LIST_CACHE = filtered; // ํ˜„์žฌ ๋ฆฌ์ŠคํŠธ๋ฅผ ์ „์—ญ ๋ณ€์ˆ˜์— ์ €์žฅ (์ธ๋ฑ์Šค๋กœ ์ ‘๊ทผํ•˜๊ธฐ ์œ„ํ•จ)
319
+
320
  const t = TRANSLATIONS[currentLang];
321
 
322
  filtered.forEach((p, idx) => {{
323
+ const card = document.createElement('div');
324
  const isVisited = visitedSet.has(p.name + '|' + selectedCountry);
325
  card.className = isVisited ? 'place-card visited' : 'place-card';
326
  let desc = (currentLang === 'KO' ? p.desc_ko : (currentLang === 'EN' ? p.desc_en : (currentLang === 'JP' ? p.desc_jp : p.desc_cn))) || p.desc_en || "No description.";
327
+
328
+ // HTML ํ‘œ์‹œ์šฉ (๋”ฐ์˜ดํ‘œ ์ œ๊ฑฐ)
329
+ const displayDesc = String(desc).replace(/['"]/g, "");
330
+ const displayName = String(p.name).replace(/['"]/g, "");
331
+
332
  let catIdx = CAT_MAP[p.category] || 0;
333
  let translatedCat = t.filters[catIdx] || p.category;
 
 
334
 
335
+ // onclick์—๋Š” ์˜ค์ง 'idx'(์ˆซ์ž)๋งŒ ์ „๋‹ฌ -> ์—๋Ÿฌ ์›์ฒœ ์ฐจ๋‹จ
336
+ card.innerHTML = "<div class='visited-badge'>VISITED ๐Ÿ’ฎ</div><b>" + displayName + "</b><div class='pc-cat'>" + translatedCat + "</div><div class='pc-desc'>" + displayDesc + "</div>" +
337
+ "<div class='card-actions'><button class='btn-action btn-ai' onclick='clickListDetail(" + idx + ")'>" + t.aiBtn + "</button>" +
338
+ "<button class='btn-action btn-map' onclick='clickListMap(" + idx + ")'>" + t.mapLinkBtn + "</button></div>";
 
 
 
 
339
  list.appendChild(card);
340
  }});
341
  }}
342
 
343
+ // [ํ•ต์‹ฌ ๋ณ€๊ฒฝ 3] ๋ฆฌ์ŠคํŠธ ํด๋ฆญ ํ•ธ๋“ค๋Ÿฌ (์ธ๋ฑ์Šค๋กœ ๋ฐ์ดํ„ฐ ์ฐพ๊ธฐ)
344
+ function clickListDetail(idx) {{
345
+ const p = LIST_CACHE[idx];
346
+ if(p) openDetail(p.name, selectedCountry);
347
+ }}
348
+
349
+ function clickListMap(idx) {{
350
+ const p = LIST_CACHE[idx];
351
+ if(p) {{
352
+ const url = getMapUrl(p.name, selectedCountry, p.lat, p.lon, p.address || "");
353
+ window.open(url, '_blank');
354
+ }}
355
+ }}
356
+
357
  function getStamps() {{
358
  try {{ return JSON.parse(localStorage.getItem('drunk_passport') || '[]'); }}
359
  catch(e) {{ localStorage.setItem('drunk_passport', '[]'); return []; }}
360
  }}
361
 
362
  function stampCurrentPlace() {{
363
+ if(!currentDetailPlace) {{ alert("No place selected."); return; }}
364
  const stamps = getStamps();
365
  const exists = stamps.find(s => s.name === currentDetailPlace.name && s.country === currentDetailPlace.country);
366
+ if(exists) {{ alert("Already Stamped! ๐Ÿ’ฎ"); return; }}
367
  stamps.push({{ name: currentDetailPlace.name, country: currentDetailPlace.country, date: new Date().toLocaleDateString() }});
368
  localStorage.setItem('drunk_passport', JSON.stringify(stamps));
369
  renderList();
370
+ alert("Stamped! ๐Ÿ’ฎ");
371
  }}
372
 
373
  function openPassportPage() {{ document.getElementById('passport-page').style.transform = 'translateY(0%)'; renderPassport(); }}
 
381
  el.innerHTML = "<div class='stamp-mark' style='transform: rotate(" + rot + "deg)'><div class='stamp-country'>" + s.country + "</div><div class='stamp-name'>" + s.name + "</div><div class='stamp-date'>" + s.date + "</div></div>";
382
  grid.appendChild(el);
383
  }});
384
+ if(stamps.length === 0) grid.innerHTML = "<div style='color:#666; text-align:center; width:100%; margin-top:50px; grid-column: 1/-1;'>No Stamps Yet.</div>";
385
  }}
386
 
387
  function exportData() {{
 
397
  reader.onload = function(e) {{
398
  try {{
399
  const data = JSON.parse(e.target.result);
400
+ if(Array.isArray(data)) {{ localStorage.setItem('drunk_passport', JSON.stringify(data)); renderPassport(); renderList(); alert("Data Loaded!"); }}
401
  else {{ alert("Invalid File"); }}
402
+ }} catch(err) {{ alert("File Error"); }}
403
  }};
404
  reader.readAsText(file);
405
  }}
 
446
 
447
  function addChatMessage(t, s, html=false) {{ const box = document.getElementById('chat-messages'); const div = document.createElement('div'); div.className = "msg " + s; if(html) div.innerHTML = t.replace(/\\n/g, '<br>'); else div.innerText = t; box.appendChild(div); box.scrollTop = box.scrollHeight; return div; }}
448
 
449
+ // [ํ•ต์‹ฌ ๋ณ€๊ฒฝ 4] ์›”๋“œ๋งต ํŒ์—… ๋กœ์ง (Key-Value ๋ฐฉ์‹)
450
  function openWorldMapPage() {{
451
  document.getElementById('world-map-page').style.transform = 'translateY(0%)';
452
  if(!worldMap) {{
453
  worldMap = L.map('full-map').setView([20, 0], 2); L.tileLayer('https://{{s}}.tile.openstreetmap.org/{{z}}/{{x}}/{{y}}.png').addTo(worldMap);
454
+ MAP_CACHE = {{}}; // ์ดˆ๊ธฐํ™”
455
 
456
  Object.keys(PLACE_DB).forEach(c => PLACE_DB[c].forEach(p => {{
457
  if(p.lat && p.lon) {{
458
+ // ์ขŒํ‘œ๋ฅผ ๊ณ ์œ  ID(Key)๋กœ ์‚ฌ์šฉ (๋ฌธ์ž์—ด ์•„๋‹˜)
459
  const key = p.lat + "_" + p.lon;
460
+ MAP_CACHE[key] = {{ name: p.name, country: c, url: getMapUrl(p.name, c, p.lat, p.lon, "") }};
461
+
462
+ const safeName = String(p.name).replace(/['"]/g, "");
463
 
464
+ // onclick์—๋Š” ์˜ค์ง 'key'๋งŒ ์ „๋‹ฌ (ํŠน์ˆ˜๋ฌธ์ž ์—†์Œ)
465
+ const popupContent = "<div style='text-align:center'><b>" + safeName + "</b><br>" +
466
  "<div style='display:flex; gap:5px; margin-top:5px; justify-content:center;'>" +
467
+ "<button onclick=\"clickMapDetail('" + key + "')\" style='background:#d4af37; border:none; border-radius:4px; padding:4px 8px; font-size:11px; cursor:pointer;'>๐Ÿค– REVIEW</button>" +
468
+ "<button onclick=\"clickMapLink('" + key + "')\" style='background:#333; color:white; border:1px solid #555; border-radius:4px; padding:4px 8px; font-size:11px; cursor:pointer;'>๐Ÿ—บ๏ธ MAP</button>" +
469
  "</div></div>";
470
  L.marker([p.lat, p.lon]).bindPopup(popupContent).addTo(worldMap);
471
  }}
 
474
  setTimeout(() => worldMap.invalidateSize(), 400);
475
  }}
476
 
477
+ // ๋งต ํด๋ฆญ ํ•ธ๋“ค๋Ÿฌ (Key๋กœ ๋ฐ์ดํ„ฐ ์ฐพ๊ธฐ)
478
+ function clickMapDetail(key) {{
479
+ const data = MAP_CACHE[key];
480
  if(data) {{ closeWorldMapPage(); openDetail(data.name, data.country); }}
481
  }}
482
 
483
+ function clickMapLink(key) {{
484
+ const data = MAP_CACHE[key];
485
  if(data) window.open(data.url, '_blank');
486
  }}
487
 
 
495
  function flyToUserLocation() {{ if(userLat && userLon) {{ worldMap.flyTo([userLat, userLon], 13); L.marker([userLat, userLon]).addTo(worldMap).bindPopup("๐Ÿ“ You").openPopup(); }} else alert("GPS..."); }}
496
  function closeWorldMapPage() {{ document.getElementById('world-map-page').style.transform = 'translateY(100%)'; }}
497
 
498
+ function closeDetail() {{ document.getElementById('detail-page').style.transform = 'translateX(100%)'; }}
 
499
  async function openDetail(n, c) {{
500
  const p = (PLACE_DB[c] || []).find(x => x.name === n); if(!p) return;
501
  currentDetailPlace = {{ name: n, country: c }};
 
508
  }}
509
 
510
  function closeChat() {{ document.getElementById('chat-page').style.transform = 'translateY(100%)'; }}
 
 
511
  function closePassportPage() {{ document.getElementById('passport-page').style.transform = 'translateY(100%)'; }}
512
  </script>
513
  </body>