/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1923;
  --surface: #1a2535;
  --surface2: #243044;
  --accent: #e8453c;
  --accent2: #f5a623;
  --text: #f0f4f8;
  --text-muted: #8a9bb0;
  --border: #2d3f55;
  --green: #27ae60;
  --yellow: #f1c40f;
  --orange: #e67e22;
  --red: #e74c3c;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

html {
  height: 100%;
  height: -webkit-fill-available;
}
body {
  height: 100%;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ===== HEADER ===== */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 100;
  flex-shrink: 0;
}

.logo {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text);
}
.logo span { color: var(--accent); }

.header-center {
  display: flex;
  align-items: center;
  gap: 8px;
}

.round-pips {
  display: flex;
  gap: 6px;
}

.pip {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border);
  transition: background 0.3s;
}
.pip.done { background: var(--green); }
.pip.active { background: var(--accent); }

.round-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.total-score {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent2);
  min-width: 80px;
  text-align: right;
}

/* ===== MAIN LAYOUT ===== */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  min-height: -webkit-fill-available;
}

#game-area {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ===== STREET VIEW PANEL ===== */
.sv-panel {
  flex: 0 0 50%;
  display: flex;
  flex-direction: column;
  background: #000;
  position: relative;
}

#sv-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.sv-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.9rem;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.sv-overlay-label {
  position: absolute;
  bottom: 16px;
  left: 16px;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0.3px;
}

/* ===== MAP PANEL ===== */
.map-panel {
  flex: 0 0 50%;
  display: flex;
  flex-direction: column;
  position: relative;
}

#map {
  flex: 1;
  cursor: crosshair !important;
}

/* Leaflet cursor override */
.leaflet-container { cursor: crosshair !important; }
.leaflet-grab { cursor: crosshair !important; }
.leaflet-dragging .leaflet-grab { cursor: crosshair !important; }

.map-footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 12px;
}

.map-hint {
  flex: 1;
  font-size: 0.82rem;
  color: var(--text-muted);
}
.map-hint strong { color: var(--text); }

#guess-btn {
  padding: 10px 22px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s, opacity 0.2s;
  white-space: nowrap;
}
#guess-btn:disabled {
  background: var(--border);
  color: var(--text-muted);
  cursor: not-allowed;
}
#guess-btn:not(:disabled):hover { background: #c0392b; }
#guess-btn:not(:disabled):active { transform: scale(0.97); }

/* ===== RESULT OVERLAY ===== */
#result-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 16, 25, 0.88);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  transition: opacity 0.3s;
}
#result-overlay.hidden { display: none; }

.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 32px;
  max-width: 480px;
  width: 100%;
  text-align: center;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.result-name {
  font-size: 1.4rem;
  font-weight: 800;
  margin-bottom: 10px;
  color: var(--text);
}

.result-fact {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 20px;
  font-style: italic;
}

.result-stats {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-bottom: 22px;
}

.stat-box {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 20px;
  min-width: 110px;
}
.stat-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.stat-value {
  font-size: 1.5rem;
  font-weight: 800;
}
.stat-value.score-great { color: var(--green); }
.stat-value.score-good { color: var(--yellow); }
.stat-value.score-ok { color: var(--orange); }
.stat-value.score-bad { color: var(--red); }

#next-btn {
  width: 100%;
  padding: 13px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s;
}
#next-btn:hover { background: #c0392b; }

/* ===== SUMMARY SCREEN ===== */
#summary-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: 20px;
}
#summary-screen.hidden { display: none; }

.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
  max-width: 520px;
  width: 100%;
  text-align: center;
  animation: slideUp 0.4s ease;
}

.summary-title {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.summary-date {
  font-size: 1.6rem;
  font-weight: 800;
  margin-bottom: 24px;
}

.score-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.score-row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface2);
  border-radius: 8px;
  padding: 10px 14px;
  text-align: left;
}

.score-row-name {
  flex: 1;
  font-size: 0.88rem;
  color: var(--text);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.score-row-dist {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.score-row-pts {
  font-size: 0.95rem;
  font-weight: 800;
  min-width: 60px;
  text-align: right;
}

.summary-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

.summary-total {
  font-size: 2.2rem;
  font-weight: 900;
  color: var(--accent2);
  margin-bottom: 6px;
}

.summary-total-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 20px;
}

.emoji-grid {
  font-size: 1.6rem;
  letter-spacing: 4px;
  margin-bottom: 20px;
  line-height: 1.8;
  background: var(--surface2);
  border-radius: 8px;
  padding: 14px;
}

.summary-buttons {
  display: flex;
  gap: 10px;
  flex-direction: column;
}

#share-btn, #copy-btn {
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

#share-btn {
  background: var(--accent);
  color: #fff;
}
#share-btn:hover { background: #c0392b; }

#copy-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
}
#copy-btn:hover { background: var(--border); }

.next-game-label {
  margin-top: 14px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.countdown {
  font-weight: 700;
  color: var(--text);
}

/* ===== TOAST ===== */
#toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 0.9rem;
  z-index: 999;
  transition: transform 0.3s ease;
  pointer-events: none;
}
#toast.show { transform: translateX(-50%) translateY(0); }

/* ===== WELCOME SCREEN ===== */
#welcome-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 400;
  padding: 20px;
}
#welcome-screen.hidden { display: none; }

.welcome-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 32px;
  max-width: 440px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow);
  animation: slideUp 0.4s ease;
}

.welcome-logo {
  font-size: 2.4rem;
  font-weight: 900;
  margin-bottom: 6px;
}
.welcome-logo span { color: var(--accent); }

.welcome-tagline {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 28px;
}

.how-to-play {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 28px;
  text-align: left;
}

.htp-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.htp-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.htp-text {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.5;
  padding-top: 8px;
}
.htp-text strong { color: var(--text); }

#start-btn {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1.05rem;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.2s;
  letter-spacing: 0.3px;
}
#start-btn:hover { background: #c0392b; }

/* ===== CUSTOM MAP MARKERS ===== */
.guess-marker-icon {
  width: 24px;
  height: 24px;
  background: var(--accent);
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
}

.actual-marker-icon {
  width: 24px;
  height: 24px;
  background: var(--green);
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 700px) {
  #game-area { flex-direction: column; }
  .sv-panel { flex: 1 1 0; min-height: 0; }
  .map-panel { flex: 0 0 60dvh; }
  .result-card { padding: 20px; }
  .result-stats { flex-direction: column; gap: 10px; }
  .stat-box { min-width: unset; }
  .summary-card { padding: 24px 16px; }
  .next-game-label { padding-bottom: env(safe-area-inset-bottom); }
}
