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

:root {
  --bg: #101010;
  --surface: #181818;
  --surface2: #222;
  --border: #2a2a2a;
  --accent: #e8e8e8;
  --dim: #666;
  --green: #4ade80;
  --yellow: #fbbf24;
  --red: #f87171;
  --text: #e8e8e8;
  --text-dim: #777;
  --mono: 'Space Mono', monospace;
  --sans: 'Space Grotesk', -apple-system, sans-serif;
}

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

#app {
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
  padding: 0 16px;
}

.screen { display: none; }
.screen.active { display: flex; }

/* ---- START SCREEN ---- */

#start-screen {
  min-height: 100vh;
  align-items: center;
  justify-content: center;
}

.start-inner { text-align: center; }

#start-screen h1 {
  font-family: var(--mono);
  font-size: 3.4rem;
  font-weight: 700;
  line-height: 0.95;
  letter-spacing: -2px;
  color: var(--text);
  margin-bottom: 20px;
}

.subtitle {
  color: var(--text-dim);
  margin-bottom: 32px;
  font-size: 1rem;
  font-weight: 400;
}

/* Streak */
.streak-display {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--green);
  margin-bottom: 20px;
  letter-spacing: 0.5px;
}
.streak-display.hidden { display: none; }

/* Name input */
.name-input-wrap {
  margin-bottom: 20px;
}
#player-name {
  width: 200px;
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.85rem;
  text-align: center;
  outline: none;
  transition: border-color 0.15s;
}
#player-name:focus { border-color: #555; }
#player-name::placeholder { color: var(--dim); }

.category-select { margin-bottom: 32px; }
.category-buttons {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.cat-btn {
  padding: 10px 24px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.8rem;
  letter-spacing: 0.5px;
  transition: all 0.15s;
}
.cat-btn:not(:last-child) { border-right: 1px solid var(--border); }
.cat-btn:hover { color: var(--text); background: var(--surface); }
.cat-btn.selected {
  background: var(--text);
  color: var(--bg);
}

.primary-btn {
  padding: 12px 48px;
  background: var(--text);
  color: var(--bg);
  border: none;
  border-radius: 6px;
  font-family: var(--sans);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.3px;
  transition: opacity 0.15s;
}
.primary-btn:hover { opacity: 0.85; }

.info-text {
  color: var(--dim);
  font-family: var(--mono);
  font-size: 0.7rem;
  margin-top: 24px;
  letter-spacing: 0.5px;
}

/* Mode toggle */
.mode-select {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 20px;
}
.mode-btn {
  padding: 10px 32px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.8rem;
  letter-spacing: 0.5px;
  transition: all 0.15s;
}
.mode-btn:not(:last-child) { border-right: 1px solid var(--border); }
.mode-btn:hover { color: var(--text); background: var(--surface); }
.mode-btn.selected { background: var(--text); color: var(--bg); }

.daily-info {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--dim);
  margin-bottom: 20px;
  display: flex;
  justify-content: center;
  gap: 12px;
}
.daily-info.hidden { display: none; }

/* ---- GAME SCREEN ---- */

#game-screen {
  flex-direction: column;
  min-height: 100vh;
  padding-top: 12px;
  padding-bottom: 20px;
}

.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--text-dim);
  padding: 0 2px;
}
.header-center {
  font-size: 0.7rem;
  letter-spacing: 2px;
  color: var(--dim);
}
.header-right { text-align: right; }

/* Street View */
#pano-container {
  position: relative;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 14px;
  border: 1px solid var(--border);
  flex: 1;
  min-height: 400px;
}
#pano {
  width: 100%;
  height: 100%;
  position: absolute;
  inset: 0;
  background: var(--surface);
}
.pano-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  color: var(--dim);
  font-family: var(--mono);
  font-size: 0.85rem;
  letter-spacing: 1px;
  z-index: 10;
  transition: opacity 0.3s;
}
.pano-loading.hidden {
  opacity: 0;
  pointer-events: none;
}

/* Hints */
.hints-toggle {
  display: block;
  width: 100%;
  padding: 8px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--dim);
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 1px;
  cursor: pointer;
  margin-bottom: 10px;
  transition: color 0.15s, border-color 0.15s;
}
.hints-toggle:hover { color: var(--text-dim); border-color: var(--text-dim); }
.hints-toggle.open { color: var(--text-dim); border-color: var(--text-dim); }

.hints-panel {
  margin-bottom: 12px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
}
.hints-panel.hidden { display: none; }

.hints-scale {
  position: relative;
  margin-bottom: 12px;
  padding: 0 4px;
}
.hints-track {
  position: relative;
  height: 3px;
  background: var(--surface2);
  border-radius: 2px;
}
.hints-markers {
  position: relative;
  height: 100%;
}
.hint-mark {
  position: absolute;
  top: -16px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
}
.hint-mark::after {
  content: '';
  width: 2px;
  height: 10px;
  border-radius: 1px;
  background: var(--dim);
}
.hint-mark-val {
  font-family: var(--mono);
  font-size: 0.6rem;
  color: var(--text-dim);
  margin-bottom: 3px;
  white-space: nowrap;
}

@media (max-width: 600px) {
  .hints-scale { display: none; }
  .hints-legend {
    flex-direction: column;
    gap: 2px;
  }
}

.hints-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-family: var(--mono);
  font-size: 0.6rem;
  color: var(--dim);
  line-height: 1.6;
}
.hint-item {
  white-space: nowrap;
}

/* Guess Area */
.guess-area {
  padding: 0;
}
.guess-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
#guess-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 1.1rem;
  outline: none;
  transition: border-color 0.15s;
}
#guess-input:focus { border-color: #555; }
#guess-input::placeholder { color: var(--dim); }
/* hide number spinner */
#guess-input::-webkit-outer-spin-button,
#guess-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.guess-btn {
  padding: 12px 32px;
  background: var(--text);
  color: var(--bg);
  border: none;
  border-radius: 4px;
  font-family: var(--sans);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  white-space: nowrap;
}
.guess-btn:hover { opacity: 0.85; }
.guess-btn:disabled { opacity: 0.3; cursor: default; }

.slider-area { padding: 0; }
#guess-slider {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 3px;
  border-radius: 2px;
  background: var(--surface2);
  outline: none;
}
#guess-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--text);
  cursor: pointer;
}
#guess-slider::-moz-range-thumb {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--text);
  border: none;
  cursor: pointer;
}
.slider-labels {
  display: flex;
  justify-content: space-between;
  color: var(--dim);
  font-family: var(--mono);
  font-size: 0.65rem;
  margin-top: 4px;
}

/* ---- RESULT OVERLAY ---- */

.result-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  z-index: 2000;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 40px 20px;
  backdrop-filter: blur(4px);
}
.result-overlay.hidden { display: none; }

.result-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 28px 24px;
  max-width: 420px;
  width: 100%;
}

.result-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 24px;
}
.result-city-name {
  font-size: 1.15rem;
  font-weight: 600;
}
.result-points {
  font-family: var(--mono);
  font-size: 0.85rem;
}

.result-comparison {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 24px;
}
.result-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.result-col:last-child { text-align: right; }
.result-num {
  font-family: var(--mono);
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1;
}
.result-sub {
  font-size: 0.7rem;
  color: var(--dim);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.result-divider {
  width: 1px;
  height: 36px;
  background: var(--border);
}

/* Comparison bar */
.result-bar-container {
  margin-bottom: 24px;
}
.result-bar-track {
  position: relative;
  height: 3px;
  background: var(--surface2);
  border-radius: 2px;
}
.bar-mark {
  position: absolute;
  top: -14px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
}
.bar-mark.bar-close { top: -28px; }
.bar-mark::after {
  content: '';
  width: 2px;
  border-radius: 1px;
}
.bar-mark.actual::after { background: var(--green); height: 12px; }
.bar-mark.guess::after { background: var(--text-dim); height: 12px; }
.bar-mark.bar-close.guess::after { height: 26px; }

.bar-mark-label {
  font-family: var(--mono);
  font-size: 0.55rem;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  margin-bottom: 4px;
  white-space: nowrap;
}
.bar-mark.actual .bar-mark-label { color: var(--green); }
.bar-mark.guess .bar-mark-label { color: var(--text-dim); }

.result-breakdown {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--dim);
  margin-bottom: 16px;
  line-height: 1.8;
}
.breakdown-row { margin-bottom: 2px; }
.breakdown-stats {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.stat-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 3px 8px;
  font-size: 0.68rem;
  color: var(--text-dim);
  letter-spacing: 0.02em;
}
.race-bar {
  display: flex;
  height: 6px;
  border-radius: 3px;
  overflow: hidden;
  margin-top: 10px;
  gap: 1px;
}
.race-seg {
  min-width: 2px;
  transition: opacity 0.15s;
}
.race-seg:hover { opacity: 0.7; }
.race-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-top: 6px;
  font-family: var(--mono);
  font-size: 0.62rem;
  color: var(--dim);
}
.race-label { display: flex; align-items: center; gap: 4px; }
.race-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

/* National dot map */
.national-map {
  margin-bottom: 16px;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
}
.national-map canvas {
  width: 100%;
  height: 120px;
  display: block;
}
.national-rank {
  font-family: var(--mono);
  font-size: 0.65rem;
  color: var(--dim);
  text-align: center;
  margin-top: 8px;
  letter-spacing: 0.3px;
}

.result-map {
  width: 100%;
  height: 160px;
  border-radius: 4px;
  margin-bottom: 20px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.result-content .primary-btn {
  width: 100%;
}

/* ---- END SCREEN ---- */

#end-screen {
  min-height: 100vh;
  align-items: center;
  justify-content: center;
}
.end-inner {
  width: 100%;
  max-width: 480px;
  text-align: center;
}
.end-label {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--dim);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.final-score {
  font-family: var(--mono);
  font-size: 4.5rem;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 4px;
}
.final-grade {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 28px;
}

/* Leaderboard */
.leaderboard-section {
  margin-bottom: 28px;
  text-align: left;
}
.leaderboard-section.hidden { display: none; }
.start-lb {
  margin-top: 32px;
  max-width: 320px;
  margin-left: auto;
  margin-right: auto;
}
.leaderboard-title {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--dim);
  letter-spacing: 1px;
  text-transform: uppercase;
  text-align: center;
  margin-bottom: 12px;
}
.leaderboard {
  border-top: 1px solid var(--border);
}
.lb-row {
  display: flex;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
}
.lb-rank {
  width: 28px;
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--dim);
}
.lb-name {
  flex: 1;
  color: var(--text);
}
.lb-name.lb-you {
  color: var(--green);
}
.lb-score {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--dim);
}
.lb-empty {
  text-align: center;
  padding: 16px 0;
  font-size: 0.75rem;
  color: var(--dim);
}

.end-summary {
  margin-bottom: 32px;
  text-align: left;
  border-top: 1px solid var(--border);
}
.summary-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
}
.summary-row .city { color: var(--text); }
.summary-row .pts {
  font-family: var(--mono);
  color: var(--dim);
  font-size: 0.75rem;
}

/* Share */
.share-section {
  margin-bottom: 24px;
}
.share-section.hidden { display: none; }
.share-btn {
  padding: 10px 32px;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s;
}
.share-btn:hover { background: var(--surface2); }
.share-copied {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--green);
  margin-top: 8px;
}
.share-copied.hidden { display: none; }

/* Score history */
.history-section {
  margin-top: 28px;
  margin-bottom: 4px;
  max-width: 320px;
  margin-left: auto;
  margin-right: auto;
}
.history-section.hidden { display: none; }
.history-title {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--dim);
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 10px;
}
.history-bars {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 58px;
  padding: 0 2px;
}
.hist-bar-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
}
.hist-mode {
  font-family: var(--mono);
  font-size: 0.65rem;
  color: var(--dim);
  margin-top: 3px;
  line-height: 1;
}
.hist-bar {
  width: 100%;
  min-height: 2px;
  border-radius: 1px 1px 0 0;
  transition: height 0.3s;
}
.history-stats {
  font-family: var(--mono);
  font-size: 0.65rem;
  color: var(--dim);
  margin-top: 6px;
}

/* Streak */
.best-streak-display {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--dim);
  margin-bottom: 20px;
  letter-spacing: 0.5px;
}
.best-streak-display.hidden { display: none; }
.streak-eliminated {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--red);
  margin-top: -4px;
  margin-bottom: 4px;
  letter-spacing: 0.5px;
}

@media (max-width: 480px) {
  #start-screen h1 { font-size: 2.4rem; }
  #pano-container { min-height: 300px; }
  .result-overlay { padding: 20px 12px; }
  .result-content { padding: 20px 16px; }
  .result-map { height: 120px; }
  .result-num { font-size: 1.4rem; }
  .result-header { flex-direction: column; gap: 4px; }
  .stat-chip { font-size: 0.62rem; padding: 2px 6px; }
  .national-map canvas { height: 90px; }
  .national-map { padding: 8px; }
}
