benjamin5607 commited on
Commit
3d3f989
·
verified ·
1 Parent(s): 2f889a4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +142 -198
app.py CHANGED
@@ -8,10 +8,10 @@ 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")
15
 
16
  st.set_page_config(page_title="Drunken Plane", page_icon="✈️", layout="wide")
17
 
@@ -24,7 +24,7 @@ st.markdown("""
24
  """, unsafe_allow_html=True)
25
 
26
  # ==========================================
27
- # 2. 데이터 로드 및 "강력한" 정제 (Anti-SyntaxError)
28
  # ==========================================
29
  PLACE_DB = {}
30
 
@@ -32,15 +32,11 @@ try:
32
  if SHEET_URL:
33
  response = requests.get(SHEET_URL)
34
  response.raise_for_status()
35
-
36
- try:
37
- df = pd.read_csv(io.StringIO(response.text), on_bad_lines='skip')
38
- except:
39
- df = pd.read_csv(io.StringIO(response.text), engine='python', on_bad_lines='skip')
40
 
41
- # [핵심 수정] 모든 문자열 컬럼에서 JS 에러를 유발하는 문자들(엔터, 탭, 따옴표) 제거
42
  for col in df.select_dtypes(include=['object']).columns:
43
- df[col] = df[col].astype(str).str.replace(r'[\r\n\t]+', ' ', regex=True).str.replace('"', '').str.replace("'", "")
44
 
45
  df.columns = df.columns.str.strip()
46
  col_mapping = {col: 'Country' for col in df.columns if col.lower() == 'country'}
@@ -49,20 +45,10 @@ try:
49
  if 'Country' in df.columns:
50
  for country, group in df.groupby('Country'):
51
  PLACE_DB[country] = group.fillna("").to_dict(orient='records')
52
- else:
53
- st.error("🚨 CSV에 'Country' 컬럼이 없습니다.")
54
- else:
55
- if os.path.exists('places.json'):
56
- with open('places.json', 'r', encoding='utf-8-sig') as f:
57
- PLACE_DB = json.load(f)
58
-
59
  except Exception as e:
60
- st.error(f"❌ 데이터 로드 실패: {e}")
61
- PLACE_DB = {}
62
 
63
- # ==========================================
64
- # 3. 데이터 인코딩
65
- # ==========================================
66
  emily_base64 = ""
67
  if os.path.exists('emily.jpg'):
68
  try:
@@ -70,12 +56,11 @@ if os.path.exists('emily.jpg'):
70
  emily_base64 = base64.b64encode(f.read()).decode()
71
  except: pass
72
 
73
- # Base64로 인코딩하여 JS 전달 (따옴표 충돌 원천 방지)
74
- db_json_raw = json.dumps(PLACE_DB, ensure_ascii=False)
75
- db_base64 = base64.b64encode(db_json_raw.encode('utf-8')).decode('utf-8')
76
 
77
  # ==========================================
78
- # 4. 프론트엔드 (HTML/JS/CSS) - 100% 검증 버전
79
  # ==========================================
80
  html_code = f"""
81
  <!DOCTYPE html>
@@ -101,53 +86,38 @@ html_code = f"""
101
  .brand-subtitle {{ font-size: 11px; color: #ccc; letter-spacing: 2px; margin-bottom: 15px; }}
102
  .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); }}
103
  .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; }}
104
- .country-select-wrapper {{ width: 85%; max-width: 400px; margin-bottom: 15px; }}
105
- .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; }}
106
  .type-filter-container {{ width: 100%; padding: 10px 20px; overflow-x: auto; display: flex; gap: 8px; scrollbar-width: none; }}
107
  .type-btn {{ padding: 8px 16px; border-radius: 20px; font-size: 12px; font-weight: bold; cursor: pointer; background: #222; color: #888; border: 1px solid #444; white-space: nowrap; }}
108
  .type-btn.selected {{ background: var(--gold); color: black; border-color: var(--gold); }}
109
  .place-list-container {{ width: 100%; max-width: 600px; flex: 1; overflow-y: auto; padding: 0 20px 120px 20px; box-sizing: border-box; }}
110
- .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; }}
111
- .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); }}
112
  .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; }}
113
  .place-card.visited .visited-badge {{ display: block; }}
114
- .pc-name {{ font-size: 18px; font-weight: bold; color: white; }}
115
- .place-card.visited .pc-name {{ color: var(--gold); }}
116
- .pc-cat {{ font-size: 11px; color: var(--gold); font-weight: bold; text-transform: uppercase; margin-bottom: 4px; }}
117
- .pc-desc {{ font-size: 13px; color: #bbb; line-height: 1.5; margin-top: 5px; }}
118
  .card-actions {{ display: flex; gap: 10px; margin-top: 15px; }}
119
  .btn-action {{ flex: 1; padding: 12px; border-radius: 8px; font-size: 12px; font-weight: bold; border: none; cursor: pointer; }}
120
  .btn-ai {{ background: var(--gold); color: black; }}
121
  .btn-map {{ background: #333; color: white; border: 1px solid #555; }}
122
  #chat-page {{ background: var(--dark); z-index: 1000; transform: translateY(100%); display: flex; flex-direction: column; }}
123
  #chat-messages {{ flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 15px; }}
124
- .msg {{ max-width: 85%; padding: 12px 18px; border-radius: 15px; font-size: 14px; line-height: 1.6; position: relative; }}
125
  .msg.bot {{ align-self: flex-start; background: #222; color: #eee; border: 1px solid #333; }}
126
  .msg.user {{ align-self: flex-end; background: var(--gold); color: black; font-weight: bold; }}
127
- .reco-btn {{ display: inline-block; margin-top: 10px; padding: 12px 20px; background: var(--gold); color: black !important; border-radius: 20px; font-weight: 900; text-decoration: none; font-size: 13px; text-align: center; border: none; cursor: pointer; }}
128
  .chat-input-area {{ padding: 15px; background: #111; border-top: 1px solid #333; display: flex; gap: 10px; }}
129
  .chat-input {{ flex: 1; background: #222; border: 1px solid #444; color: white; padding: 14px; border-radius: 10px; outline: none; }}
130
  #detail-page {{ background: #111; z-index: 300; transform: translateX(100%); display: flex; flex-direction: column; }}
131
- .nav-bar {{ height: 60px; background: rgba(0,0,0,0.9); border-bottom: 1px solid #333; display: flex; align-items: center; padding: 0 20px; justify-content: space-between; }}
132
  #mini-map {{ width: 100%; height: 35%; border-bottom: 2px solid var(--gold); }}
133
- .stamp-btn {{ width: 100%; background: #4a1c1c; color: #ffcc00; border: 2px dashed #ffcc00; padding: 15px; margin-top: 20px; border-radius: 10px; font-weight: bold; cursor: pointer; text-transform: uppercase; letter-spacing: 2px; }}
134
- .stamp-btn:hover {{ background: #ffcc00; color: #4a1c1c; border-style: solid; }}
135
  #passport-page {{ background: #1a1a1a; z-index: 400; transform: translateY(100%); display: flex; flex-direction: column; }}
136
- .passport-cover {{ padding: 20px; border-bottom: 1px solid #333; display: flex; justify-content: space-between; align-items: center; background: #2c0b0e; }}
137
- .passport-grid {{ display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 20px; padding: 25px; overflow-y: auto; flex: 1; background-image: radial-gradient(#333 15%, transparent 16%), radial-gradient(#333 15%, transparent 16%); background-size: 20px 20px; }}
138
  .stamp-card {{ aspect-ratio: 1/1; display: flex; justify-content: center; align-items: center; position: relative; }}
139
- .stamp-mark {{ width: 110px; height: 110px; border: 3px double #d42222; border-radius: 50%; display: flex; flex-direction: column; justify-content: center; align-items: center; color: #d42222; font-family: 'Special Elite', cursive; transform: rotate(-12deg); background: rgba(212, 34, 34, 0.05); box-shadow: 0 0 0 4px rgba(212, 34, 34, 0.1) inset; text-align: center; padding: 10px; mask-image: url('https://www.transparenttextures.com/patterns/black-felt.png'); }}
140
- .stamp-country {{ font-size: 10px; letter-spacing: 2px; text-transform: uppercase; border-bottom: 1px solid #d42222; margin-bottom: 5px; }}
141
- .stamp-name {{ font-size: 13px; font-weight: bold; line-height: 1.2; margin-bottom: 5px; }}
142
- .stamp-date {{ font-size: 10px; font-family: monospace; }}
143
- .data-controls {{ padding: 15px; background: #111; border-top: 1px solid #333; display: flex; gap: 10px; justify-content: center; }}
144
- .data-btn {{ background: #333; border: 1px solid #555; color: #ccc; padding: 10px 15px; border-radius: 5px; cursor: pointer; font-size: 12px; }}
145
  #world-map-page {{ background: #111; z-index: 200; transform: translateY(100%); }}
146
  #full-map {{ width: 100%; height: 100%; }}
147
- .map-search-bar {{ position: absolute; top: 80px; left: 50%; transform: translateX(-50%); z-index: 2000; display: flex; gap: 10px; background: rgba(0,0,0,0.85); padding: 10px 20px; border-radius: 30px; border: 1px solid var(--gold); box-shadow: 0 4px 15px rgba(0,0,0,0.5); }}
148
  .search-input {{ background: transparent; border: none; color: white; outline: none; width: 180px; font-size: 15px; }}
149
- .search-btn {{ background: var(--gold); border: none; border-radius: 50%; width: 35px; height: 35px; cursor: pointer; font-weight: bold; display: flex; align-items: center; justify-content: center; }}
150
- .map-gps-btn {{ position: absolute; bottom: 30%; right: 20px; z-index: 2000; width: 60px; height: 60px; border-radius: 50%; background: #222; border: 3px solid var(--gold); color: white; font-size: 26px; cursor: pointer; box-shadow: 0 4px 15px rgba(212, 175, 55, 0.6); display: flex; justify-content: center; align-items: center; animation: bounce-float 3s ease-in-out infinite; }}
151
  .loading-screen {{ position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.9); z-index: 8000; display: none; flex-direction: column; justify-content: center; align-items: center; }}
152
  .loader-ring {{ width: 45px; height: 45px; border: 4px solid #333; border-top: 4px solid var(--gold); border-radius: 50%; animation: spin 1s linear infinite; }}
153
  @keyframes spin {{ 0% {{ transform: rotate(0deg); }} 100% {{ transform: rotate(360deg); }} }}
@@ -156,18 +126,18 @@ html_code = f"""
156
  <body>
157
  <div id="main-page" class="page">
158
  <div class="lang-switcher">
159
- <div class="lang-btn active" id="l-KO" onclick="setLanguage('KO', this)">🇰🇷</div>
160
- <div class="lang-btn" id="l-EN" onclick="setLanguage('EN', this)">🇺🇸</div>
161
- <div class="lang-btn" id="l-JP" onclick="setLanguage('JP', this)">🇯🇵</div>
162
- <div class="lang-btn" id="l-CN" onclick="setLanguage('CN', this)">🇨🇳</div>
163
  </div>
164
  <div style="text-align:center; padding:10px 0;">
165
  <div class="brand-title">DRUNKEN PLANE</div>
166
  <div id="app-subtitle" class="brand-subtitle">GLOBAL ALCOHOL HERITAGE TOUR</div>
167
- <button id="world-map-btn" class="world-map-btn" onclick="openWorldMapPage()">🗺️ WORLD MAP EXPLORER</button>
168
- <button id="passport-btn" class="passport-btn" onclick="openPassportPage()" style="margin: 10px auto;">📘 MY PASSPORT</button>
169
  </div>
170
- <div class="country-select-wrapper"><select id="country-select" class="country-select" onchange="selectCountry(this.value)"></select></div>
171
  <div class="type-filter-container">
172
  <div class="type-btn selected" id="f-btn-0" onclick="filterType('All', this)">🌐 All</div>
173
  <div class="type-btn" id="f-btn-1" onclick="filterType('Traditional', this)">🏺 Trad.</div>
@@ -181,52 +151,63 @@ html_code = f"""
181
  </div>
182
 
183
  <div id="chat-page" class="page">
184
- <div class="nav-bar"><button onclick="closeChat()" style="background:none; border:none; color:var(--gold); font-size:24px;">←</button><div id="emily-name" style="color:var(--gold); font-weight:bold;">에밀리 (Emily)</div><div></div></div>
 
 
 
185
  <div id="chat-messages"></div>
186
- <div class="chat-input-area"><input type="text" id="chat-input" class="chat-input" placeholder="..." onkeydown="if(event.key === 'Enter') askBartender()"><button id="chat-send-btn" onclick="askBartender()" style="background:var(--gold); border:none; padding:10px 20px; border-radius:8px; font-weight:bold;">SEND</button></div>
 
 
 
187
  </div>
188
 
189
  <div id="detail-page" class="page">
190
- <div class="nav-bar"><button onclick="closeDetail()" style="background:none; border:none; color:var(--gold); font-size:24px;">←</button><div id="repo-header" style="color:white; font-weight:bold;">REPORT</div><div></div></div>
 
 
191
  <div id="mini-map"></div>
192
- <div class="report-container" style="flex:1; overflow-y:auto; padding:20px;">
193
- <div id="repo-title" style="font-size:24px; color:var(--gold); font-weight:bold; margin-bottom:10px;"></div>
194
- <div id="repo-content" style="font-size:15px; color:#ddd; line-height:1.8; white-space:pre-wrap;"></div>
195
  <button class="stamp-btn" onclick="stampCurrentPlace()">💮 Stamp This Place</button>
196
  </div>
197
  </div>
198
 
199
  <div id="passport-page" class="page">
200
- <div class="passport-cover"><button onclick="closePassportPage()" style="background:none; border:none; color:var(--gold); font-size:24px;">←</button><div style="color:var(--gold); font-weight:bold; font-size: 18px;">DRUNKARD'S PASSPORT</div><div></div></div>
 
 
201
  <div id="passport-grid" class="passport-grid"></div>
202
- <div class="data-controls"><button class="data-btn" onclick="exportData()">💾 Save Game</button><button class="data-btn" onclick="document.getElementById('import-file').click()">📂 Load Game</button><input type="file" id="import-file" style="display:none" onchange="importData(this)"></div>
203
  </div>
204
 
205
- <div id="world-map-page" class="page"><div class="nav-bar"><button id="nav-home-btn" onclick="closeWorldMapPage()" style="background:none; border:none; color:var(--gold); font-size:24px;">🏠 HOME</button></div><div class="map-search-bar"><input type="text" id="map-search-input" class="search-input" placeholder="..." onkeydown="if(event.key === 'Enter') searchLocation()"><button class="search-btn" onclick="searchLocation()">🔍</button></div><button class="map-gps-btn" onclick="flyToUserLocation()">🎯</button><div id="full-map"></div></div>
206
- <div id="loader" class="loading-screen"><div class="loader-ring"></div><div id="loader-msg" style="color:var(--gold); font-family:monospace; margin-top:15px;"></div></div>
 
 
 
 
 
 
 
 
 
 
 
207
 
208
  <script>
209
- // 안전한 데이터 디코딩
210
- function b64DecodeUnicode(str) {{
211
- try {{
212
- return decodeURIComponent(atob(str).split('').map(function(c) {{
213
- return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
214
- }}).join(''));
215
- }} catch(e) {{ return "{{}}"; }}
216
- }}
217
 
218
- // 전역 데이터 (열쇠 역할을 하는 숫자 ID 활용)
219
- const PLACE_DB = JSON.parse(b64DecodeUnicode("{db_base64}"));
220
- let userLat = null, userLon = null, selectedCountry = "", selectedType = "All", currentLang = "KO", chatInitialized = false;
221
- let miniMap = null, worldMap = null, currentFilteredList = [];
222
- let MAP_CACHE = {{}}; // 지도에서 클릭 시 데이터 조회를 위한 캐시
223
- let mapIdCounter = 0;
224
 
225
  const TRANSLATIONS = {{
226
- "KO": {{ "sub": "글로벌 주류 헤리티지 투어", "ai": "Korean", "mapBtn": "🗺️ 월드맵 탐험", "passBtn": "📘 내 여권", "filters": ["🌐 전체", "🏺 전통주", "🥃 위스키", "🍺 맥주", "🍷 와인", "🍹 바"], "chatPlace": "에밀리에게 말해봐...", "send": "전송", "home": "🏠 홈", "searchPlace": "장소 검색", "emilyName": "에밀리", "reportHeader": "리포트", "aiBtn": "AI 리뷰", "mapLinkBtn": "지도" }},
227
- "EN": {{ "sub": "GLOBAL ALCOHOL HERITAGE TOUR", "ai": "English", "mapBtn": "🗺️ EXPLORER", "passBtn": "📘 PASSPORT", "filters": ["🌐 All", "🏺 Trad.", "🥃 Whiskey", "🍺 Beer", "🍷 Wine", "🍹 Bar"], "chatPlace": "Talk to Emily...", "send": "SEND", "home": "🏠 HOME", "searchPlace": "Search", "emilyName": "Emily", "reportHeader": "REPORT", "aiBtn": "AI REVIEW", "mapLinkBtn": "MAP" }},
228
- "JP": {{ "sub": "世界のお酒ヘリテージツアー", "ai": "Japanese", "mapBtn": "🗺️ 地図探索", "passBtn": "📘 パ스포트", "filters": ["🌐 全て", "🏺 伝統酒", "🥃 ウイスキー", "🍺 ビール", "🍷 ワイン", "🍹 バー"], "chatPlace": "エミリーに話して...", "send": "送信", "home": "🏠 ホーム", "searchPlace": "場所検索", "emilyName": "エミリー", "reportHeader": "レポート", "aiBtn": "AI レビュー", "mapLinkBtn": "地図" }},
229
- "CN": {{ "sub": "全球酒类遗产之旅", "ai": "Chinese", "mapBtn": "🗺️ 探索地图", "passBtn": "📘 我的护照", "filters": ["🌐 全部", "🏺 传统酒", "🥃 威士忌", "🍺 啤酒", "🍷 葡萄酒", "🍹 酒吧"], "chatPlace": "和艾米丽聊聊...", "send": "发送", "home": "🏠 主页", "searchPlace": "搜索", "emilyName": "艾米丽", "reportHeader": "报告", "aiBtn": "AI 点评", "mapLinkBtn": "地图" }}
230
  }};
231
 
232
  window.onload = function() {{
@@ -237,176 +218,139 @@ html_code = f"""
237
  navigator.geolocation.getCurrentPosition(p => {{ userLat = p.coords.latitude; userLon = p.coords.longitude; }}, e => console.log("GPS Off"));
238
  }};
239
 
 
 
 
 
 
 
 
 
240
  function setLanguage(lang, el) {{
241
  currentLang = lang;
242
  document.querySelectorAll('.lang-btn').forEach(b => b.classList.remove('active'));
243
  el.classList.add('active');
244
- const t = TRANSLATIONS[currentLang];
245
- document.getElementById('app-subtitle').innerText = t.sub;
246
- document.getElementById('world-map-btn').innerText = t.mapBtn;
247
- document.getElementById('passport-btn').innerText = t.passBtn;
248
- document.getElementById('chat-input').placeholder = t.chatPlace;
249
- document.getElementById('chat-send-btn').innerText = t.send;
250
- document.getElementById('nav-home-btn').innerText = t.home;
251
- document.getElementById('map-search-input').placeholder = t.searchPlace;
252
- document.getElementById('emily-name').innerText = t.emilyName;
253
- document.getElementById('repo-header').innerText = t.reportHeader;
254
- for(let i=0; i<6; i++) {{ document.getElementById('f-btn-' + i).innerText = t.filters[i]; }}
255
  renderList();
256
  }}
257
 
258
- function selectCountry(c) {{ selectedCountry = c; renderList(); }}
259
- function filterType(t, el) {{ selectedType = t; document.querySelectorAll('.type-btn').forEach(b => b.classList.remove('selected')); el.classList.add('selected'); renderList(); }}
260
-
261
- // 리스트 렌더링 (숫자 ID 기반 클릭 이벤트)
262
  function renderList() {{
263
  const list = document.getElementById('place-list'); list.innerHTML = "";
264
- const stamps = getStamps();
265
- const visitedSet = new Set(stamps.map(s => s ? s.name + '|' + s.country : ''));
266
  const filtered = (PLACE_DB[selectedCountry] || []).filter(p => selectedType === "All" || p.category === selectedType);
267
  currentFilteredList = filtered;
268
- const t = TRANSLATIONS[currentLang];
269
 
270
  filtered.forEach((p, idx) => {{
271
- const card = document.createElement('div');
272
  const isVisited = visitedSet.has(p.name + '|' + selectedCountry);
 
273
  card.className = isVisited ? 'place-card visited' : 'place-card';
274
- let desc = (currentLang === 'KO' ? p.desc_ko : (currentLang === 'EN' ? p.desc_en : (currentLang === 'JP' ? p.desc_jp : p.desc_cn))) || p.desc_en || "...";
275
 
276
- // [안전] 텍스트에 직접 접근하지 않고 숫자(idx)만 넘김
277
- card.innerHTML = `<div class='visited-badge'>VISITED 💮</div>
278
- <b>${{p.name}}</b>
279
- <div class='pc-cat'>${{p.category}}</div>
280
- <div class='pc-desc'>${{desc}}</div>
281
- <div class='card-actions'>
282
- <button class='btn-action btn-ai' onclick='clickAction(${{idx}}, "ai")'>${{t.aiBtn}}</button>
283
- <button class='btn-action btn-map' onclick='clickAction(${{idx}}, "map")'>${{t.mapLinkBtn}}</button>
284
- </div>`;
 
 
 
 
 
285
  list.appendChild(card);
286
  }});
287
  }}
288
 
289
- // 숫자 ID로 데이터 찾기 (에러 방지 1순위)
290
  function clickAction(idx, type) {{
291
  const p = currentFilteredList[idx];
292
  if(!p) return;
293
  if(type === 'ai') openDetail(p.name, selectedCountry);
294
  else {{
295
- const url = (selectedCountry.includes("Korea") || selectedCountry.includes("한국"))
296
- ? "https://map.naver.com/p/search/" + encodeURIComponent(p.address || p.name)
297
- : "http://google.com/maps/search/" + encodeURIComponent(p.name + " " + selectedCountry);
298
  window.open(url, '_blank');
299
  }}
300
  }}
301
 
302
- // 지도 팝업 클릭 핸들러 (숫자 Key 활용)
303
- function clickMapAction(key, type) {{
304
- const data = MAP_CACHE[key];
305
- if(!data) return;
306
- if(type === 'ai') {{ closeWorldMapPage(); openDetail(data.name, data.country); }}
307
- else window.open(data.url, '_blank');
308
- }}
309
-
310
- function getStamps() {{ try {{ return JSON.parse(localStorage.getItem('drunk_passport') || '[]'); }} catch(e) {{ return []; }} }}
311
- function stampCurrentPlace() {{
312
- if(!currentDetailPlace) return;
313
- const stamps = getStamps();
314
- if(stamps.find(s => s.name === currentDetailPlace.name)) return alert("Already Stamped!");
315
- stamps.push({{ name: currentDetailPlace.name, country: currentDetailPlace.country, date: new Date().toLocaleDateString() }});
316
- localStorage.setItem('drunk_passport', JSON.stringify(stamps));
317
- renderList(); alert("Stamped! 💮");
318
- }}
319
-
320
- function openPassportPage() {{ document.getElementById('passport-page').style.transform = 'translateY(0%)'; renderPassport(); }}
321
- function renderPassport() {{
322
- const grid = document.getElementById('passport-grid'); grid.innerHTML = "";
323
- getStamps().forEach(s => {{
324
- if(!s.name) return;
325
- const el = document.createElement('div'); el.className = 'stamp-card';
326
- el.innerHTML = `<div class='stamp-mark' style='transform: rotate(${{Math.random()*20-10}}deg)'>
327
- <div class='stamp-country'>${{s.country}}</div>
328
- <div class='stamp-name'>${{s.name}}</div>
329
- <div class='stamp-date'>${{s.date}}</div>
330
- </div>`;
331
- grid.appendChild(el);
332
- }});
333
- }}
334
-
335
- function exportData() {{ const blob = new Blob([localStorage.getItem('drunk_passport')], {{type: 'application/json'}}); const a = document.createElement('a'); a.href = URL.createObjectURL(blob); a.download = 'passport.json'; a.click(); }}
336
- function importData(input) {{ const reader = new FileReader(); reader.onload = e => {{ localStorage.setItem('drunk_passport', e.target.result); renderList(); alert("Loaded!"); }}; reader.readAsText(input.files[0]); }}
337
-
338
  function openWorldMapPage() {{
339
  document.getElementById('world-map-page').style.transform = 'translateY(0%)';
340
  if(!worldMap) {{
341
  worldMap = L.map('full-map').setView([20, 0], 2);
342
  L.tileLayer('https://{{s}}.tile.openstreetmap.org/{{z}}/{{x}}/{{y}}.png').addTo(worldMap);
343
- MAP_CACHE = {{}}; mapIdCounter = 0;
344
  Object.keys(PLACE_DB).forEach(c => PLACE_DB[c].forEach(p => {{
345
  if(p.lat && p.lon) {{
346
  const key = mapIdCounter++;
347
- const mapUrl = (c.includes("Korea") || c.includes("한국"))
348
- ? "https://map.naver.com/p/search/" + encodeURIComponent(p.address || p.name)
349
- : "http://google.com/maps/search/" + encodeURIComponent(p.name + " " + c);
350
- MAP_CACHE[key] = {{ name: p.name, country: c, url: mapUrl }};
351
-
352
- // [중요] 팝업 버튼에도 숫자 ID(key)만 넘김
353
- const popupHtml = `<div style='text-align:center'><b>${{p.name}}</b><br>
354
- <div style='display:flex; gap:5px; margin-top:5px;'>
355
- <button onclick='clickMapAction(${{key}}, "ai")' style='background:#d4af37; border:none; padding:4px 8px; border-radius:4px; font-size:11px; cursor:pointer;'>🤖 AI</button>
356
- <button onclick='clickMapAction(${{key}}, "map")' style='background:#333; color:white; border:none; padding:4px 8px; border-radius:4px; font-size:11px; cursor:pointer;'>🗺️ MAP</button>
357
- </div></div>`;
358
- L.marker([p.lat, p.lon]).bindPopup(popupHtml).addTo(worldMap);
359
  }}
360
  }}));
361
  }}
362
  setTimeout(() => worldMap.invalidateSize(), 400);
363
  }}
364
 
365
- async function callGroq(messages) {{
366
- const url = "https://api.groq.com/openai/v1/chat/completions";
367
- try {{
368
- const res = await fetch(url, {{
369
- method: 'POST',
370
- headers: {{ 'Content-Type': 'application/json', 'Authorization': 'Bearer {GROQ_API_KEY}' }},
371
- body: JSON.stringify({{ model: "llama-3.3-70b-versatile", messages: messages, temperature: 0.7 }})
372
- }});
373
- const data = await res.json(); return data.choices[0].message.content;
374
- }} catch(e) {{ return "Error..."; }}
375
- }}
376
-
377
- function openChat() {{ document.getElementById('chat-page').style.transform = 'translateY(0%)'; }}
378
- function closeChat() {{ document.getElementById('chat-page').style.transform = 'translateY(100%)'; }}
379
- async function askBartender() {{
380
- const inp = document.getElementById('chat-input'); const msg = inp.value.trim(); if(!msg) return;
381
- addChatMessage(msg, 'user'); inp.value = "";
382
- const res = await callGroq([{{ role: "system", content: "You are Emily. Act flirtatious. In " + TRANSLATIONS[currentLang].ai }}, {{ role: "user", content: msg }}]);
383
- addChatMessage(res, 'bot');
384
  }}
385
 
386
- function addChatMessage(t, s) {{ const box = document.getElementById('chat-messages'); const div = document.createElement('div'); div.className = "msg " + s; div.innerText = t; box.appendChild(div); box.scrollTop = box.scrollHeight; }}
387
- function closeDetail() {{ document.getElementById('detail-page').style.transform = 'translateX(100%)'; }}
388
  async function openDetail(n, c) {{
389
  const p = PLACE_DB[c].find(x => x.name === n); if(!p) return;
390
  currentDetailPlace = {{ name: n, country: c }};
391
  document.getElementById('detail-page').style.transform = 'translateX(0%)';
392
  document.getElementById('repo-title').innerText = n;
393
  document.getElementById('loader').style.display='flex';
394
- if(!miniMap) {{ miniMap = L.map('mini-map'); L.tileLayer('https://{{s}}.tile.openstreetmap.org/{{z}}/{{x}}/{{y}}.png').addTo(miniMap); }}
 
 
 
 
395
  setTimeout(() => {{ miniMap.invalidateSize(); miniMap.setView([p.lat, p.lon], 15); L.marker([p.lat, p.lon]).addTo(miniMap); }}, 400);
396
- const res = await callGroq([{{ role: "system", content: "Write a travel report in " + TRANSLATIONS[currentLang].ai }}, {{ role: "user", content: "Report for " + n }}]);
 
397
  document.getElementById('loader').style.display='none';
398
  document.getElementById('repo-content').innerText = res;
399
  }}
400
 
401
- function closeWorldMapPage() {{ document.getElementById('world-map-page').style.transform = 'translateY(100%)'; }}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
402
  function closePassportPage() {{ document.getElementById('passport-page').style.transform = 'translateY(100%)'; }}
403
- async function searchLocation() {{
404
- const q = document.getElementById('map-search-input').value; if(!q) return;
405
- const res = await fetch(`https://nominatim.openstreetmap.org/search?format=json&q=${{encodeURIComponent(q)}}`);
406
- const data = await res.json();
407
- if(data.length > 0) worldMap.flyTo([data[0].lat, data[0].lon], 12);
 
 
 
 
 
 
 
 
 
 
 
 
408
  }}
409
- function flyToUserLocation() {{ if(userLat) worldMap.flyTo([userLat, userLon], 14); }}
410
  </script>
411
  </body>
412
  </html>
 
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", "")
15
 
16
  st.set_page_config(page_title="Drunken Plane", page_icon="✈️", layout="wide")
17
 
 
24
  """, unsafe_allow_html=True)
25
 
26
  # ==========================================
27
+ # 2. 데이터 로드 및 정제 (JS 에러 원천 봉쇄)
28
  # ==========================================
29
  PLACE_DB = {}
30
 
 
32
  if SHEET_URL:
33
  response = requests.get(SHEET_URL)
34
  response.raise_for_status()
35
+ df = pd.read_csv(io.StringIO(response.text), on_bad_lines='skip')
 
 
 
 
36
 
37
+ # [방어막] 모든 문자열에서 따옴표, 역슬래시, 줄바꿈 제거 (에러의 주범들)
38
  for col in df.select_dtypes(include=['object']).columns:
39
+ df[col] = df[col].astype(str).replace({r'["\\'']': '', r'[\r\n\t]+': ' '}, regex=True)
40
 
41
  df.columns = df.columns.str.strip()
42
  col_mapping = {col: 'Country' for col in df.columns if col.lower() == 'country'}
 
45
  if 'Country' in df.columns:
46
  for country, group in df.groupby('Country'):
47
  PLACE_DB[country] = group.fillna("").to_dict(orient='records')
 
 
 
 
 
 
 
48
  except Exception as e:
49
+ st.error(f"데이터 로드 실패: {e}")
 
50
 
51
+ # 에밀리 이미지
 
 
52
  emily_base64 = ""
53
  if os.path.exists('emily.jpg'):
54
  try:
 
56
  emily_base64 = base64.b64encode(f.read()).decode()
57
  except: pass
58
 
59
+ # JS에 넘길 데이터 인코딩
60
+ db_json_encoded = base64.b64encode(json.dumps(PLACE_DB, ensure_ascii=False).encode('utf-8')).decode('utf-8')
 
61
 
62
  # ==========================================
63
+ # 3. 프론트엔드 (f-string 중괄호 완벽 보호)
64
  # ==========================================
65
  html_code = f"""
66
  <!DOCTYPE html>
 
86
  .brand-subtitle {{ font-size: 11px; color: #ccc; letter-spacing: 2px; margin-bottom: 15px; }}
87
  .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); }}
88
  .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; }}
89
+ .country-select {{ width: 85%; max-width: 400px; padding: 14px; background: rgba(30,30,30,0.9); border: 1px solid var(--gold); color: white; font-size: 16px; border-radius: 10px; outline: none; margin-bottom: 15px; }}
 
90
  .type-filter-container {{ width: 100%; padding: 10px 20px; overflow-x: auto; display: flex; gap: 8px; scrollbar-width: none; }}
91
  .type-btn {{ padding: 8px 16px; border-radius: 20px; font-size: 12px; font-weight: bold; cursor: pointer; background: #222; color: #888; border: 1px solid #444; white-space: nowrap; }}
92
  .type-btn.selected {{ background: var(--gold); color: black; border-color: var(--gold); }}
93
  .place-list-container {{ width: 100%; max-width: 600px; flex: 1; overflow-y: auto; padding: 0 20px 120px 20px; box-sizing: border-box; }}
94
+ .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; }}
95
+ .place-card.visited {{ border: 1px solid var(--gold); background: linear-gradient(135deg, rgba(40,10,10,0.9), rgba(20,20,20,0.9)); }}
96
  .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; }}
97
  .place-card.visited .visited-badge {{ display: block; }}
 
 
 
 
98
  .card-actions {{ display: flex; gap: 10px; margin-top: 15px; }}
99
  .btn-action {{ flex: 1; padding: 12px; border-radius: 8px; font-size: 12px; font-weight: bold; border: none; cursor: pointer; }}
100
  .btn-ai {{ background: var(--gold); color: black; }}
101
  .btn-map {{ background: #333; color: white; border: 1px solid #555; }}
102
  #chat-page {{ background: var(--dark); z-index: 1000; transform: translateY(100%); display: flex; flex-direction: column; }}
103
  #chat-messages {{ flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 15px; }}
104
+ .msg {{ max-width: 85%; padding: 12px 18px; border-radius: 15px; font-size: 14px; line-height: 1.6; }}
105
  .msg.bot {{ align-self: flex-start; background: #222; color: #eee; border: 1px solid #333; }}
106
  .msg.user {{ align-self: flex-end; background: var(--gold); color: black; font-weight: bold; }}
 
107
  .chat-input-area {{ padding: 15px; background: #111; border-top: 1px solid #333; display: flex; gap: 10px; }}
108
  .chat-input {{ flex: 1; background: #222; border: 1px solid #444; color: white; padding: 14px; border-radius: 10px; outline: none; }}
109
  #detail-page {{ background: #111; z-index: 300; transform: translateX(100%); display: flex; flex-direction: column; }}
 
110
  #mini-map {{ width: 100%; height: 35%; border-bottom: 2px solid var(--gold); }}
111
+ .stamp-btn {{ width: 100%; background: #4a1c1c; color: #ffcc00; border: 2px dashed #ffcc00; padding: 15px; margin-top: 20px; border-radius: 10px; font-weight: bold; cursor: pointer; }}
 
112
  #passport-page {{ background: #1a1a1a; z-index: 400; transform: translateY(100%); display: flex; flex-direction: column; }}
113
+ .passport-grid {{ display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 20px; padding: 25px; overflow-y: auto; flex: 1; }}
 
114
  .stamp-card {{ aspect-ratio: 1/1; display: flex; justify-content: center; align-items: center; position: relative; }}
115
+ .stamp-mark {{ width: 110px; height: 110px; border: 3px double #d42222; border-radius: 50%; display: flex; flex-direction: column; justify-content: center; align-items: center; color: #d42222; font-family: 'Special Elite', cursive; transform: rotate(-12deg); background: rgba(212, 34, 34, 0.05); text-align: center; padding: 10px; }}
 
 
 
 
 
116
  #world-map-page {{ background: #111; z-index: 200; transform: translateY(100%); }}
117
  #full-map {{ width: 100%; height: 100%; }}
118
+ .map-search-bar {{ position: absolute; top: 80px; left: 50%; transform: translateX(-50%); z-index: 2000; display: flex; gap: 10px; background: rgba(0,0,0,0.85); padding: 10px 20px; border-radius: 30px; border: 1px solid var(--gold); }}
119
  .search-input {{ background: transparent; border: none; color: white; outline: none; width: 180px; font-size: 15px; }}
120
+ .map-gps-btn {{ position: absolute; bottom: 30%; right: 20px; z-index: 2000; width: 60px; height: 60px; border-radius: 50%; background: #222; border: 3px solid var(--gold); color: white; font-size: 26px; cursor: pointer; display: flex; justify-content: center; align-items: center; }}
 
121
  .loading-screen {{ position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.9); z-index: 8000; display: none; flex-direction: column; justify-content: center; align-items: center; }}
122
  .loader-ring {{ width: 45px; height: 45px; border: 4px solid #333; border-top: 4px solid var(--gold); border-radius: 50%; animation: spin 1s linear infinite; }}
123
  @keyframes spin {{ 0% {{ transform: rotate(0deg); }} 100% {{ transform: rotate(360deg); }} }}
 
126
  <body>
127
  <div id="main-page" class="page">
128
  <div class="lang-switcher">
129
+ <div class="lang-btn active" onclick="setLanguage('KO', this)">🇰🇷</div>
130
+ <div class="lang-btn" onclick="setLanguage('EN', this)">🇺🇸</div>
131
+ <div class="lang-btn" onclick="setLanguage('JP', this)">🇯🇵</div>
132
+ <div class="lang-btn" onclick="setLanguage('CN', this)">🇨🇳</div>
133
  </div>
134
  <div style="text-align:center; padding:10px 0;">
135
  <div class="brand-title">DRUNKEN PLANE</div>
136
  <div id="app-subtitle" class="brand-subtitle">GLOBAL ALCOHOL HERITAGE TOUR</div>
137
+ <button class="world-map-btn" onclick="openWorldMapPage()">🗺️ WORLD MAP EXPLORER</button>
138
+ <button class="passport-btn" onclick="openPassportPage()" style="margin: 10px auto;">📘 MY PASSPORT</button>
139
  </div>
140
+ <center><select id="country-select" class="country-select" onchange="selectCountry(this.value)"></select></center>
141
  <div class="type-filter-container">
142
  <div class="type-btn selected" id="f-btn-0" onclick="filterType('All', this)">🌐 All</div>
143
  <div class="type-btn" id="f-btn-1" onclick="filterType('Traditional', this)">🏺 Trad.</div>
 
151
  </div>
152
 
153
  <div id="chat-page" class="page">
154
+ <div class="nav-bar" style="background:#111; padding:15px; display:flex; align-items:center;">
155
+ <button onclick="closeChat()" style="background:none; border:none; color:var(--gold); font-size:24px;">←</button>
156
+ <div id="emily-name" style="color:var(--gold); font-weight:bold; margin-left:15px;">에밀리</div>
157
+ </div>
158
  <div id="chat-messages"></div>
159
+ <div class="chat-input-area">
160
+ <input type="text" id="chat-input" class="chat-input" placeholder="..." onkeydown="if(event.key === 'Enter') askBartender()">
161
+ <button onclick="askBartender()" style="background:var(--gold); border:none; padding:10px 20px; border-radius:8px; font-weight:bold;">SEND</button>
162
+ </div>
163
  </div>
164
 
165
  <div id="detail-page" class="page">
166
+ <div class="nav-bar" style="background:#000; padding:15px;">
167
+ <button onclick="closeDetail()" style="background:none; border:none; color:var(--gold); font-size:24px;">←</button>
168
+ </div>
169
  <div id="mini-map"></div>
170
+ <div style="flex:1; overflow-y:auto; padding:20px;">
171
+ <div id="repo-title" style="font-size:24px; color:var(--gold); font-weight:bold;"></div>
172
+ <div id="repo-content" style="margin-top:15px; line-height:1.8; white-space:pre-wrap;"></div>
173
  <button class="stamp-btn" onclick="stampCurrentPlace()">💮 Stamp This Place</button>
174
  </div>
175
  </div>
176
 
177
  <div id="passport-page" class="page">
178
+ <div class="nav-bar" style="background:#2c0b0e; padding:15px;">
179
+ <button onclick="closePassportPage()" style="background:none; border:none; color:var(--gold); font-size:24px;">←</button>
180
+ </div>
181
  <div id="passport-grid" class="passport-grid"></div>
 
182
  </div>
183
 
184
+ <div id="world-map-page" class="page">
185
+ <div class="nav-bar" style="background:#000; padding:15px;">
186
+ <button onclick="closeWorldMapPage()" style="background:none; border:none; color:var(--gold); font-size:18px;">🏠 HOME</button>
187
+ </div>
188
+ <div class="map-search-bar">
189
+ <input type="text" id="map-search-input" class="search-input" placeholder="..." onkeydown="if(event.key === 'Enter') searchLocation()">
190
+ <button onclick="searchLocation()" style="background:var(--gold); border:none; border-radius:50%; width:30px; height:30px;">🔍</button>
191
+ </div>
192
+ <button class="map-gps-btn" onclick="flyToUserLocation()">🎯</button>
193
+ <div id="full-map"></div>
194
+ </div>
195
+
196
+ <div id="loader" class="loading-screen"><div class="loader-ring"></div><div id="loader-msg" style="color:var(--gold); margin-top:15px;"></div></div>
197
 
198
  <script>
199
+ // [안전장치] Base64로 데이터를 받아 파싱 (문자열 깨짐 방지)
200
+ const RAW_DATA = "{db_json_encoded}";
201
+ const PLACE_DB = JSON.parse(decodeURIComponent(escape(atob(RAW_DATA))));
 
 
 
 
 
202
 
203
+ let userLat=null, userLon=null, selectedCountry="", selectedType="All", currentLang="KO", chatInitialized=false;
204
+ let miniMap=null, worldMap=null, currentFilteredList=[], mapCache={{}}, mapIdCounter=0;
 
 
 
 
205
 
206
  const TRANSLATIONS = {{
207
+ "KO": {{ "ai": "Korean", "aiBtn": "AI 리뷰", "mapLinkBtn": "지도" }},
208
+ "EN": {{ "ai": "English", "aiBtn": "AI REVIEW", "mapLinkBtn": "MAP" }},
209
+ "JP": {{ "ai": "Japanese", "aiBtn": "AI レビュー", "mapLinkBtn": "地図" }},
210
+ "CN": {{ "ai": "Chinese", "aiBtn": "AI 点评", "mapLinkBtn": "地图" }}
211
  }};
212
 
213
  window.onload = function() {{
 
218
  navigator.geolocation.getCurrentPosition(p => {{ userLat = p.coords.latitude; userLon = p.coords.longitude; }}, e => console.log("GPS Off"));
219
  }};
220
 
221
+ function selectCountry(c) {{ selectedCountry = c; renderList(); }}
222
+ function filterType(t, el) {{
223
+ selectedType = t;
224
+ document.querySelectorAll('.type-btn').forEach(b => b.classList.remove('selected'));
225
+ el.classList.add('selected');
226
+ renderList();
227
+ }}
228
+
229
  function setLanguage(lang, el) {{
230
  currentLang = lang;
231
  document.querySelectorAll('.lang-btn').forEach(b => b.classList.remove('active'));
232
  el.classList.add('active');
 
 
 
 
 
 
 
 
 
 
 
233
  renderList();
234
  }}
235
 
 
 
 
 
236
  function renderList() {{
237
  const list = document.getElementById('place-list'); list.innerHTML = "";
238
+ const stamps = JSON.parse(localStorage.getItem('drunk_passport') || '[]');
239
+ const visitedSet = new Set(stamps.map(s => s.name + '|' + s.country));
240
  const filtered = (PLACE_DB[selectedCountry] || []).filter(p => selectedType === "All" || p.category === selectedType);
241
  currentFilteredList = filtered;
 
242
 
243
  filtered.forEach((p, idx) => {{
 
244
  const isVisited = visitedSet.has(p.name + '|' + selectedCountry);
245
+ const card = document.createElement('div');
246
  card.className = isVisited ? 'place-card visited' : 'place-card';
 
247
 
248
+ const t = TRANSLATIONS[currentLang];
249
+ const desc = p['desc_' + currentLang.toLowerCase()] || p.desc_en || "...";
250
+
251
+ // [안전] 숫자로만 버튼 이벤트 연결
252
+ card.innerHTML = `
253
+ <div class='visited-badge'>VISITED 💮</div>
254
+ <b style='font-size:18px;'>${{p.name}}</b>
255
+ <div style='color:var(--gold); font-size:11px;'>${{p.category}}</div>
256
+ <div style='font-size:13px; color:#bbb; margin-top:5px;'>${{desc}}</div>
257
+ <div class='card-actions'>
258
+ <button class='btn-action btn-ai' onclick='clickAction(${{idx}}, "ai")'>${{t.aiBtn}}</button>
259
+ <button class='btn-action btn-map' onclick='clickAction(${{idx}}, "map")'>${{t.mapLinkBtn}}</button>
260
+ </div>
261
+ `;
262
  list.appendChild(card);
263
  }});
264
  }}
265
 
 
266
  function clickAction(idx, type) {{
267
  const p = currentFilteredList[idx];
268
  if(!p) return;
269
  if(type === 'ai') openDetail(p.name, selectedCountry);
270
  else {{
271
+ const url = (selectedCountry.includes("Korea") || selectedCountry.includes("한국"))
272
+ ? "https://map.naver.com/p/search/" + encodeURIComponent(p.address || p.name)
273
+ : "https://www.google.com/maps/search/" + encodeURIComponent(p.name + " " + selectedCountry);
274
  window.open(url, '_blank');
275
  }}
276
  }}
277
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
278
  function openWorldMapPage() {{
279
  document.getElementById('world-map-page').style.transform = 'translateY(0%)';
280
  if(!worldMap) {{
281
  worldMap = L.map('full-map').setView([20, 0], 2);
282
  L.tileLayer('https://{{s}}.tile.openstreetmap.org/{{z}}/{{x}}/{{y}}.png').addTo(worldMap);
283
+ mapCache = {{}}; mapIdCounter = 0;
284
  Object.keys(PLACE_DB).forEach(c => PLACE_DB[c].forEach(p => {{
285
  if(p.lat && p.lon) {{
286
  const key = mapIdCounter++;
287
+ mapCache[key] = {{ name: p.name, country: c }};
288
+ const html = `<div style='text-align:center;'><b>${{p.name}}</b><br><button onclick='clickMapDetail(${{key}})' style='background:var(--gold); border:none; margin-top:5px; padding:5px 10px; border-radius:4px; font-weight:bold; cursor:pointer;'>REVIEW</button></div>`;
289
+ L.marker([p.lat, p.lon]).bindPopup(html).addTo(worldMap);
 
 
 
 
 
 
 
 
 
290
  }}
291
  }}));
292
  }}
293
  setTimeout(() => worldMap.invalidateSize(), 400);
294
  }}
295
 
296
+ function clickMapDetail(key) {{
297
+ const data = mapCache[key];
298
+ if(data) {{ closeWorldMapPage(); openDetail(data.name, data.country); }}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
299
  }}
300
 
 
 
301
  async function openDetail(n, c) {{
302
  const p = PLACE_DB[c].find(x => x.name === n); if(!p) return;
303
  currentDetailPlace = {{ name: n, country: c }};
304
  document.getElementById('detail-page').style.transform = 'translateX(0%)';
305
  document.getElementById('repo-title').innerText = n;
306
  document.getElementById('loader').style.display='flex';
307
+
308
+ if(!miniMap) {{
309
+ miniMap = L.map('mini-map');
310
+ L.tileLayer('https://{{s}}.tile.openstreetmap.org/{{z}}/{{x}}/{{y}}.png').addTo(miniMap);
311
+ }}
312
  setTimeout(() => {{ miniMap.invalidateSize(); miniMap.setView([p.lat, p.lon], 15); L.marker([p.lat, p.lon]).addTo(miniMap); }}, 400);
313
+
314
+ const res = await callGroq([{{ role: "system", content: "You are Emily. Write a report." }}, {{ role: "user", content: "Review " + n + " in " + c }}]);
315
  document.getElementById('loader').style.display='none';
316
  document.getElementById('repo-content').innerText = res;
317
  }}
318
 
319
+ async function callGroq(msgs) {{
320
+ try {{
321
+ const res = await fetch("https://api.groq.com/openai/v1/chat/completions", {{
322
+ method: "POST",
323
+ headers: {{ "Content-Type": "application/json", "Authorization": "Bearer {GROQ_API_KEY}" }},
324
+ body: JSON.stringify({{ model: "llama-3.3-70b-versatile", messages: msgs }})
325
+ }});
326
+ const data = await res.json();
327
+ return data.choices[0].message.content;
328
+ }} catch(e) {{ return "Error..."; }}
329
+ }}
330
+
331
+ function openChat() {{ document.getElementById('chat-page').style.transform = 'translateY(0%)'; }}
332
+ function closeChat() {{ document.getElementById('chat-page').style.transform = 'translateY(100%)'; }}
333
+ function closeDetail() {{ document.getElementById('detail-page').style.transform = 'translateX(100%)'; }}
334
+ function openPassportPage() {{ document.getElementById('passport-page').style.transform = 'translateY(0%)'; renderPassport(); }}
335
  function closePassportPage() {{ document.getElementById('passport-page').style.transform = 'translateY(100%)'; }}
336
+ function closeWorldMapPage() {{ document.getElementById('world-map-page').style.transform = 'translateY(100%)'; }}
337
+
338
+ function stampCurrentPlace() {{
339
+ const stamps = JSON.parse(localStorage.getItem('drunk_passport') || '[]');
340
+ stamps.push({{ name: currentDetailPlace.name, country: currentDetailPlace.country, date: new Date().toLocaleDateString() }});
341
+ localStorage.setItem('drunk_passport', JSON.stringify(stamps));
342
+ renderList(); alert("Stamped! 💮");
343
+ }}
344
+
345
+ function renderPassport() {{
346
+ const grid = document.getElementById('passport-grid'); grid.innerHTML = "";
347
+ const stamps = JSON.parse(localStorage.getItem('drunk_passport') || '[]');
348
+ stamps.forEach(s => {{
349
+ const el = document.createElement('div'); el.className = 'stamp-card';
350
+ el.innerHTML = `<div class='stamp-mark'><div>${{s.country}}</div><div style='font-weight:bold;'>${{s.name}}</div><div style='font-size:10px;'>${{s.date}}</div></div>`;
351
+ grid.appendChild(el);
352
+ }});
353
  }}
 
354
  </script>
355
  </body>
356
  </html>