/* Night Lights. Mobile first; one dark theme (it's a night sky). */

:root {
  color-scheme: dark;
  --bg: #05070d;
  --surface: #0d1220;
  --surface-2: #151c2e;
  --line: #222b42;
  --text: #e9edf6;
  --muted: #8d98ae;
  --glow: #f5c56b; /* sodium-lamp amber, like the lights in the photos */
  --glow-ink: #1b1300;
  --red: #e5534b;
  --orange: #ee8a3c;
  --yellow: #e9c64a;
  --green: #4cbb6c;
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: radial-gradient(120% 60% at 50% 0%, #0c1426 0%, var(--bg) 60%) fixed, var(--bg);
  color: var(--text);
  line-height: 1.45;
  display: flex;
  flex-direction: column;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

a {
  color: var(--glow);
}

/* ---- header ---- */

.bar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  border-bottom: 1px solid var(--line);
}

h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

h1 span {
  color: var(--glow);
  text-shadow: 0 0 14px rgb(245 197 107 / 0.55);
}

.bar-right {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: none;
}

.icon-btn:hover,
.units:hover {
  background: var(--surface-2);
}

.icon-btn svg,
.share svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn .fill {
  fill: currentColor;
  stroke: none;
}

.units {
  min-width: 44px;
  height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: none;
  font-size: 0.85rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ---- main ---- */

main {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 12px 16px 24px;
  flex: 1;
}

.meta {
  margin: 0 0 10px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.photo {
  margin: 0;
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  box-shadow: 0 0 0 1px var(--line), 0 18px 50px -18px rgb(245 197 107 / 0.35);
}

.photo img {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
}

.photo figcaption {
  position: absolute;
  left: 10px;
  bottom: 10px;
  padding: 3px 9px;
  border-radius: 99px;
  background: rgb(5 7 13 / 0.7);
  color: var(--muted);
  font-size: 0.78rem;
}

/* ---- guess input ---- */

.guess-form {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.combo {
  position: relative;
  flex: 1;
  min-width: 0;
}

#guess-input {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 1rem; /* 16px+ keeps iOS from zooming in */
}

#guess-input:focus {
  outline: 2px solid var(--glow);
  outline-offset: 1px;
  border-color: transparent;
}

#suggestions {
  position: absolute;
  z-index: 5;
  top: calc(100% + 6px);
  left: 0;
  right: -96px; /* reach under the Guess button too */
  margin: 0;
  padding: 4px;
  list-style: none;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-2);
  box-shadow: 0 16px 40px rgb(0 0 0 / 0.6);
  max-height: 50vh;
  overflow-y: auto;
}

#suggestions li {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
}

#suggestions li[aria-selected="true"],
#suggestions li:hover {
  background: #232d47;
}

#suggestions .country {
  color: var(--muted);
}

#suggestions mark {
  background: none;
  color: var(--glow);
  font-weight: 600;
}

.primary {
  height: 48px;
  padding: 0 20px;
  border: 0;
  border-radius: 12px;
  background: var(--glow);
  color: var(--glow-ink);
  font-weight: 700;
}

.primary:disabled {
  background: var(--surface-2);
  color: var(--muted);
  cursor: default;
}

.primary:focus-visible,
.icon-btn:focus-visible,
.units:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

.message {
  min-height: 1.4em;
  margin: 6px 2px 0;
  color: var(--yellow);
  font-size: 0.9rem;
}

/* ---- guesses ---- */

.guesses {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.guess {
  display: grid;
  grid-template-columns: 1fr auto 30px 44px;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 6px 12px;
  border-radius: 10px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--tone) 22%, var(--surface)) var(--pct), var(--surface) var(--pct));
  border: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
  animation: rise 0.35s ease-out;
}

.guess.empty {
  border-style: dashed;
  background: none;
  animation: none;
}

.guess .name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.guess .name small {
  color: var(--muted);
  font-weight: 400;
}

.guess .dist {
  color: var(--muted);
  font-size: 0.92rem;
  text-align: right;
}

.guess .arrow {
  width: 26px;
  height: 26px;
  color: var(--tone);
}

.guess .arrow path {
  fill: currentColor;
}

.guess .pct {
  text-align: right;
  font-weight: 700;
  color: var(--tone);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* ---- end of game ---- */

.result {
  margin-top: 18px;
  padding: 18px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  text-align: center;
  animation: rise 0.45s ease-out;
}

.result-kicker {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.result h2 {
  margin: 2px 0 14px;
  font-size: 1.5rem;
  line-height: 1.2;
}

.world {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  background: #000;
}

.world img {
  display: block;
  width: 100%;
  height: auto;
}

.mark {
  position: absolute;
  width: 8px;
  height: 8px;
  margin: -4px 0 0 -4px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 1.5px var(--bg);
}

.mark.answer {
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  background: var(--glow);
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--glow);
  animation: ping 1.6s ease-out infinite;
}

@keyframes ping {
  0% {
    box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px rgb(245 197 107 / 0.9);
  }
  100% {
    box-shadow: 0 0 0 2px var(--bg), 0 0 0 16px rgb(245 197 107 / 0);
  }
}

.share {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 16px;
  width: 100%;
  justify-content: center;
}

.next {
  margin: 12px 0 0;
  color: var(--muted);
}

.next time {
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ---- stats ---- */

.stat-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin: 18px 0 14px;
}

.stat-row b {
  display: block;
  font-size: 1.6rem;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.stat-row span {
  color: var(--muted);
  font-size: 0.75rem;
}

.dist-title {
  margin: 0 0 8px;
  font-size: 0.85rem;
  color: var(--muted);
  text-align: left;
}

.bars {
  display: grid;
  gap: 4px;
  margin: 0 0 6px;
  padding: 0;
  list-style: none;
}

.bars li {
  display: grid;
  grid-template-columns: 14px 1fr;
  gap: 8px;
  align-items: center;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.bars .bar-fill {
  min-width: 26px;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--surface-2);
  text-align: right;
  font-weight: 600;
}

.bars li.today .bar-fill {
  background: var(--glow);
  color: var(--glow-ink);
}

/* ---- dialogs ---- */

.sheet {
  width: min(440px, calc(100% - 32px));
  max-height: calc(100dvh - 32px);
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
}

.sheet::backdrop {
  background: rgb(0 0 0 / 0.65);
  backdrop-filter: blur(2px);
}

.sheet h2 {
  margin: 0 0 8px;
  font-size: 1.25rem;
}

.sheet ul {
  padding-left: 1.2em;
}

.sheet .primary {
  width: 100%;
  margin-top: 8px;
}

.muted {
  color: var(--muted);
}

/* ---- footer, toast ---- */

footer {
  padding: 12px 16px max(18px, env(safe-area-inset-bottom));
  text-align: center;
  color: var(--muted);
  font-size: 0.75rem;
}

footer p {
  margin: 4px 0;
}

.toast {
  position: fixed;
  left: 50%;
  top: 70px;
  transform: translate(-50%, -12px);
  padding: 8px 16px;
  border-radius: 99px;
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.2s,
    transform 0.2s;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
