*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface2: #16213e;
  --accent: #e8c547;
  --accent2: #4ecdc4;
  --danger: #e84393;
  --text: #e8e8f0;
  --text-dim: #8888aa;
  --radius: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.5);
}

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

.hidden { display: none !important; }

/* ── Views ── */
.view {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* ── Home View ── */
#view-home {
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 30%, #1a2040 0%, var(--bg) 70%);
}

.home-logo {
  font-size: 3.5rem;
  font-weight: 900;
  letter-spacing: -2px;
  margin-bottom: 0.25em;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.home-subtitle {
  color: var(--text-dim);
  font-size: 1rem;
  margin-bottom: 2.5rem;
  letter-spacing: 2px;
  text-transform: uppercase;
}

.btn {
  display: inline-block;
  padding: 0.75em 2em;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  transition: transform 0.1s, opacity 0.1s;
  text-decoration: none;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: #111;
}
.btn-primary:hover { opacity: 0.9; }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid #333;
}
.btn-secondary:hover { background: var(--surface2); }

.btn-lg { font-size: 1.15rem; padding: 0.85em 2.5em; }

.home-btns { display: flex; gap: 1rem; flex-wrap: wrap; justify-content: center; }

.home-challenge-info {
  margin-top: 2rem;
  padding: 1rem 1.5rem;
  background: var(--surface);
  border-radius: var(--radius);
  border-left: 3px solid var(--accent2);
  max-width: 400px;
  text-align: center;
}
.home-challenge-info .challenger-name { font-size: 1.1rem; font-weight: 700; color: var(--accent2); }
.home-challenge-info .challenger-score { color: var(--text-dim); font-size: 0.9rem; margin-top: 0.25rem; }

/* ── Game View ── */
#view-game {
  background: #000;
}

#panorama {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.game-status-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 0.6rem 1rem;
  background: linear-gradient(to bottom, rgba(0,0,0,0.85) 0%, transparent 100%);
  display: flex;
  align-items: center;
  gap: 1.5rem;
  z-index: 10;
  pointer-events: none;
}

.status-round {
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text);
  text-shadow: 0 1px 4px rgba(0,0,0,0.9);
}
.status-round span { color: var(--accent); font-size: 1rem; }

.status-score {
  font-size: 0.85rem;
  color: var(--text);
  text-shadow: 0 1px 4px rgba(0,0,0,0.9);
}
.status-score span { color: var(--accent); font-weight: 600; }

.status-steps {
  font-size: 0.85rem;
  color: var(--text);
  text-shadow: 0 1px 4px rgba(0,0,0,0.9);
  margin-left: auto;
}

.hint-btn {
  background: rgba(0,0,0,0.45);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 20px;
  color: var(--text);
  font-size: 0.85rem;
  padding: 0.2rem 0.65rem;
  cursor: pointer;
  pointer-events: all;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
  transition: opacity 0.2s, background 0.2s;
  white-space: nowrap;
}
.hint-btn:hover:not(.depleted) { background: rgba(232,197,71,0.15); }
.hint-btn.depleted { opacity: 0.35; cursor: not-allowed; }
.hint-btn.photo-active { background: rgba(232,197,71,0.22); border-color: rgba(232,197,71,0.6); color: var(--accent); }

.hint-toast {
  position: absolute;
  top: 3.2rem;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15,15,26,0.92);
  border: 1px solid rgba(232,197,71,0.45);
  border-radius: 8px;
  color: var(--text);
  padding: 0.5rem 1.1rem;
  font-size: 0.9rem;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  white-space: nowrap;
}
.hint-toast.visible { opacity: 1; }

/* ── Photo mode ── */
.location-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  user-select: none;
}

/* ── Mini-map panel ── */
.guess-panel {
  position: absolute;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.5rem;
}

#mini-map {
  width: 280px;
  height: 200px;
  border-radius: var(--radius);
  border: 2px solid rgba(255,255,255,0.2);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: width 0.25s, height 0.25s;
  cursor: crosshair;
}

#mini-map:hover, #mini-map.expanded {
  width: 380px;
  height: 280px;
}

.btn-guess {
  background: var(--accent);
  color: #111;
  padding: 0.6em 1.4em;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 700;
  transition: opacity 0.1s, transform 0.1s;
  pointer-events: all;
  opacity: 0.5;
}
.btn-guess.active { opacity: 1; }
.btn-guess.active:hover { opacity: 0.9; }
.btn-guess.active:active { transform: scale(0.97); }

.no-coverage-msg {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(15,15,26,0.92);
  gap: 0.75rem;
  z-index: 5;
}
.no-coverage-msg .icon { font-size: 2.5rem; }
.no-coverage-msg p { color: var(--text-dim); font-size: 0.9rem; }

/* ── Round Result View ── */
#view-round {
  background: var(--bg);
  overflow-y: auto;
}

.round-header {
  padding: 1.5rem 2rem 0;
  display: flex;
  align-items: baseline;
  gap: 1rem;
}
.round-title { font-size: 1.3rem; font-weight: 800; }
.round-number { color: var(--text-dim); font-size: 0.9rem; }

.round-map-wrap {
  padding: 1rem 2rem;
}

#result-map {
  width: 100%;
  height: clamp(280px, 42vh, 500px);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid #333;
}

.round-stats {
  display: flex;
  gap: 1.5rem;
  padding: 0 2rem;
  flex-wrap: wrap;
}

.stat-card {
  flex: 1;
  min-width: 120px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}
.stat-label { font-size: 0.75rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; }
.stat-value { font-size: 1.6rem; font-weight: 800; margin-top: 0.2rem; }
.stat-value.score-value { color: var(--accent); }
.stat-value.dist-value { color: var(--accent2); }
.stat-comment { font-size: 0.75rem; margin-top: 0.2rem; }

/* ── Round result reveal ── */
.result-reveal {
  margin: 0 2rem 0.5rem;
  border-radius: var(--radius);
  border: 1px solid #333;
  background: #000;
  text-align: center;
}
.result-reveal-photo {
  max-width: 100%;
  max-height: 50vh;
  width: auto;
  height: auto;
  display: block;
  margin: 0 auto;
}
.result-cultural-text {
  padding: 0.6rem 1rem;
  font-size: 0.875rem;
  color: var(--text-dim);
  background: var(--surface);
  line-height: 1.55;
}

.round-location-name {
  padding: 0.75rem 2rem 0;
  color: var(--text-dim);
  font-size: 0.9rem;
}
.round-location-name strong { color: var(--text); }

.round-footer {
  padding: 1rem 2rem 1.5rem;
  display: flex;
  gap: 1rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}

/* ── Final Result View ── */
#view-final {
  background: var(--bg);
  overflow-y: auto;
}

.final-header {
  padding: 2rem 2rem 1rem;
  text-align: center;
}
.final-title { font-size: 1.8rem; font-weight: 900; }
.final-total-score {
  font-size: 4rem;
  font-weight: 900;
  color: var(--accent);
  line-height: 1;
  margin: 0.25em 0;
}
.final-max { color: var(--text-dim); font-size: 0.9rem; }

.final-rounds {
  padding: 0 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.round-row {
  display: flex;
  align-items: center;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  gap: 1rem;
}
.round-row-num { color: var(--text-dim); font-size: 0.8rem; width: 1.5rem; }
.round-row-label { flex: 1; font-size: 0.9rem; }
.round-row-dist { color: var(--text-dim); font-size: 0.85rem; width: 70px; text-align: right; }
.round-row-score { font-weight: 700; color: var(--accent); width: 55px; text-align: right; }
.round-row-hints { font-size: 0.8rem; width: 42px; text-align: right; }
.round-row-hints.used { color: var(--accent); }
.round-row-hints.zero { color: var(--text-dim); }

.score-bar-wrap { width: 80px; }
.score-bar-bg { background: #333; border-radius: 4px; height: 6px; overflow: hidden; }
.score-bar-fill { height: 100%; background: linear-gradient(to right, var(--accent2), var(--accent)); border-radius: 4px; transition: width 0.6s ease; }

.final-challenge-section {
  padding: 1.5rem 2rem;
}
.challenge-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  border: 1px solid #333;
}
.challenge-box h3 { margin-bottom: 0.75rem; font-size: 1rem; }
.challenge-link-wrap { display: flex; gap: 0.5rem; align-items: center; }
#challenge-link-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid #444;
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.5em 0.75em;
  font-size: 0.85rem;
  font-family: monospace;
}
.btn-copy { padding: 0.5em 1em; font-size: 0.85rem; }
.copy-feedback { font-size: 0.8rem; color: var(--accent2); margin-top: 0.4rem; height: 1.2em; }

.qr-wrap {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.4rem;
}
#qr-code canvas, #qr-code img {
  border-radius: 6px;
  display: block;
}
.qr-hint { font-size: 0.75rem; color: var(--text-dim); }

.final-footer {
  padding: 1rem 2rem 2rem;
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* ── Baidu static map zoom buttons ── */
.bd-zoom-btn {
  width: 32px; height: 32px;
  background: rgba(0,0,0,0.65);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: var(--radius);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s;
}
.bd-zoom-btn:hover { background: rgba(0,0,0,0.9); }

/* ── Leaflet overrides ── */
.leaflet-container { background: #1a2030; }
.leaflet-tile { filter: brightness(0.8) saturate(0.9); }
.leaflet-control-zoom a { background: var(--surface) !important; color: var(--text) !important; border-color: #444 !important; }

/* ── Mode selector ── */
.home-mode-select {
  margin-top: 1.5rem;
  text-align: center;
}
.mode-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: var(--text-dim);
  margin-bottom: 0.75rem;
}
.mode-options {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}
.mode-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.9rem 1.25rem;
  border-radius: var(--radius);
  border: 2px solid #333;
  cursor: pointer;
  min-width: 140px;
  transition: border-color 0.15s, background 0.15s;
  background: var(--surface);
}
.mode-option input[type="radio"] { display: none; }
.mode-option:has(input:checked) {
  border-color: var(--accent);
  background: rgba(232,197,71,0.08);
}
.mode-icon { font-size: 1.5rem; }
.mode-name { font-weight: 700; font-size: 0.9rem; }
.mode-desc { font-size: 0.72rem; color: var(--text-dim); text-align: center; }

/* ── Responsive ── */
@media (max-width: 600px) {
  #mini-map { width: 220px; height: 160px; }
  #mini-map:hover, #mini-map.expanded { width: 300px; height: 220px; }
  .round-stats { padding: 0 1rem; }
  .round-map-wrap, .round-header, .round-footer { padding-left: 1rem; padding-right: 1rem; }
  .final-header, .final-rounds, .final-challenge-section, .final-footer { padding-left: 1rem; padding-right: 1rem; }
  .final-total-score { font-size: 3rem; }
  .result-reveal { margin-left: 1rem; margin-right: 1rem; }
  .result-reveal-photo { max-height: 35vh; }
}
