/* Locus — typography-led, restrained. The narrative does the work. */
:root {
  --bg: #faf8f4;
  --ink: #1c1a17;
  --muted: #6b655c;
  --faint: #a9a297;
  --rule: #e7e2d8;
  --accent: #9a5b3c;
  --card: #fffefb;
  --serif: Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  --sans: "Helvetica Neue", Arial, system-ui, sans-serif;
  --maxw: 42rem;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.eyebrow {
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--faint);
  margin: 0 0 1.5rem;
}
.eyebrow a { color: var(--faint); }

/* ---------- Landing ---------- */
/* Top-aligned (not vertically centred) and tightly spaced so the whole landing
   — map picker included — fits a phone screen with the footer within reach. The
   footer's margin-top:auto (below) still drops it to the viewport bottom when the
   content happens to be short. */
.landing {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 1.5rem 1.25rem 1.75rem;
}
.landing-inner { width: 100%; max-width: 34rem; }

.wordmark {
  font-size: clamp(2.5rem, 9vw, 3.6rem);
  font-weight: normal;
  letter-spacing: -0.02em;
  margin: 0 0 0.5rem;
  line-height: 1;
}
.tagline {
  font-size: 1rem;
  color: var(--muted);
  font-style: italic;
  margin: 0 0 1.4rem;
  max-width: 26rem;
}

.dropzone {
  display: block;
  border: 1.5px dashed var(--rule);
  border-radius: 10px;
  background: var(--card);
  padding: 1.4rem 1.25rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
  font-family: var(--sans);
}
.dropzone:hover, .dropzone.drag {
  border-color: var(--accent);
  background: #fff;
}
.dropzone strong { display: block; font-size: 0.98rem; margin-bottom: 0.35rem; color: var(--ink); }
.dropzone span { font-size: 0.82rem; color: var(--faint); }
.dropzone input { display: none; }

.divider {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 1.75rem 0;
  color: var(--faint);
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--rule);
}

/* Results-page top bar: brand link + an easy way back to a new search. */
.narrative-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.5rem;
}
.new-search {
  font-family: var(--sans);
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  color: var(--accent);
  text-decoration: none;
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 0.32rem 0.8rem;
  white-space: nowrap;
}
.new-search:hover { border-color: var(--accent); }
/* "Explore this point" button under the results map, shown after a map click. */
.map-pick-go { margin-top: 0.85rem; width: 100%; }
.map-hint {
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--faint);
  text-align: center;
  margin: 0.6rem 0 0;
}

/* Disambiguation chooser chips on the results page. */
.candidates {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  margin-top: 0.85rem;
  font-family: var(--sans);
}
.candidates .cand-label {
  font-size: 0.78rem;
  color: var(--faint);
  margin-right: 0.1rem;
}
.candidates .chip {
  font-size: 0.82rem;
  color: var(--ink);
  text-decoration: none;
  border: 1px solid var(--rule);
  border-radius: 999px;
  padding: 0.28rem 0.72rem;
  white-space: nowrap;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.candidates a.chip:hover { border-color: var(--accent); color: var(--accent); }
.candidates .chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.chooser-prompt { font-style: italic; color: var(--muted); }

/* What a chip is, in a word — "railway station", "cafe", "settlement". */
.chip .chip-kind {
  font-size: 0.68rem;
  opacity: 0.65;
  margin-left: 0.4rem;
  text-transform: lowercase;
}
.chip .chip-roman {
  margin-left: 0.4rem;
  opacity: 0.7;
  font-style: italic;
}
.chip .chip-roman::before { content: "· "; opacity: 0.7; }

/* Chooser escape hatch: free-text "say where you are". */
.context-row { display: flex; gap: 0.5rem; margin-top: 1.1rem; }
.context-row input {
  flex: 1;
  font-family: var(--sans);
  font-size: 0.95rem;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
}
.context-row input:focus { outline: none; border-color: var(--accent); }
.context-row .btn { padding: 0.7rem 1.1rem; }

/* Shown when the model was unavailable and the prose is the data fallback. */
.fallback-note {
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--muted);
  background: var(--card);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 0.6rem 0.85rem;
  margin-bottom: 1.1rem;
}

/* Landing-page "pick a point on the map" chooser. */
.pick-map { margin-top: 1rem; }
.pick-map .map-canvas { height: 210px; cursor: crosshair; }
.pick-go {
  margin-top: 0.85rem;
  width: 100%;
  transition: opacity 0.15s ease;
}
.pick-go .pick-coords {
  font-family: var(--sans);
  font-size: 0.82rem;
  opacity: 0.85;
  margin-left: 0.45rem;
}

.location-form { display: flex; gap: 0.5rem; margin-top: 1rem; }
.location-form input[type="text"] {
  flex: 1;
  font-family: var(--sans);
  font-size: 1rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
}
.location-form input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}

/* Text-search disambiguation: several distinct places share the name. */
.geo-choices { margin-top: 1rem; }
.geo-choices-label {
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.55rem;
}
.geo-choices-list { display: flex; flex-direction: column; gap: 0.5rem; }
.geo-choice {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  text-align: left;
  font-family: var(--sans);
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.geo-choice:hover { border-color: var(--accent); }
.geo-choice.suggested { border-color: var(--accent); }
.geo-choice-label { font-size: 0.95rem; }
.geo-choice-detail {
  font-size: 0.75rem;
  color: var(--faint);
  text-transform: lowercase;
  white-space: nowrap;
}

.btn {
  font-family: var(--sans);
  font-size: 0.9rem;
  padding: 0.85rem 1.4rem;
  border: none;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  cursor: pointer;
  transition: opacity 0.15s ease;
}
.btn:hover { opacity: 0.85; }
.btn:disabled { opacity: 0.4; cursor: default; }

.ghost-btn {
  display: inline-block;
  font-family: var(--sans);
  font-size: 0.85rem;
  padding: 0.7rem 1.2rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  color: var(--ink);
}
.ghost-btn:hover { border-color: var(--accent); text-decoration: none; }

.locate-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  margin-top: 0.85rem;
  padding: 0.8rem 1rem;
  font-family: var(--sans);
  font-size: 0.9rem;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}
.locate-btn:hover { border-color: var(--accent); }
.locate-btn svg { color: var(--accent); flex-shrink: 0; }
.locate-btn:disabled { cursor: default; color: var(--faint); }
.locate-btn.locating svg { animation: locate-pulse 1s infinite ease-in-out; }
@keyframes locate-pulse { 0%, 100% { opacity: 0.4; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .locate-btn.locating svg { animation: none; } }

.hint { font-family: var(--sans); font-size: 0.78rem; color: var(--faint); margin-top: 0.9rem; }
.error {
  font-family: var(--sans);
  font-size: 0.85rem;
  color: #a3352a;
  margin-top: 1rem;
  min-height: 1.2em;
}

/* ---------- Narrative / share ---------- */
.narrative-wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 3.5rem 1.5rem 5rem;
}
.narrative-header { margin-bottom: 1.5rem; }
.narrative-header h1 {
  font-size: clamp(2rem, 6vw, 3rem);
  font-weight: normal;
  letter-spacing: -0.015em;
  line-height: 1.1;
  margin: 0 0 0.5rem;
}
.venue {
  font-family: var(--sans);
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  color: var(--accent);
  margin: 0;
}
/* District + country under the headline, so a bare venue or peak name is always
   placed (e.g. "Lawson" · "Tokyo, Japan"). */
.place-region {
  font-family: var(--sans);
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  color: var(--muted);
  margin: 0.25rem 0 0;
}
/* The 'what is this place' subtitle — name (local script + romanisation), type,
   and region — kept beside the title in the finished narrative. */
.identity {
  font-family: var(--sans);
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0.35rem 0 0;
}
.map-embed {
  position: relative;
  margin: 1.25rem 0 0;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--rule);
  line-height: 0;
}
.map-embed iframe { width: 100%; height: 240px; border: 0; display: block; }
.map-canvas { width: 100%; height: 240px; background: #e7e2d8; }
/* Custom Leaflet control glyphs (locate, full-screen) share the native
   .leaflet-bar look; just size the glyph. */
.map-embed .leaflet-bar a.map-glyph { font-size: 1.05rem; font-weight: 400; }
/* Strip Leaflet's default divIcon white box so the SVG pin sits clean. */
.locus-pin { background: transparent; border: 0; }

/* CSS-based fullscreen overlay (iOS-safe — the Fullscreen API can't fullscreen
   an arbitrary element on iOS Safari). */
.map-embed.expanded {
  position: fixed;
  inset: 0;
  z-index: 1000;
  margin: 0;
  border: 0;
  border-radius: 0;
}
.map-embed.expanded .map-canvas,
.map-embed.expanded iframe { height: 100vh; height: 100dvh; }
body.map-open { overflow: hidden; }
.map-links {
  font-family: var(--sans);
  font-size: 0.82rem;
  color: var(--faint);
  margin-top: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
  align-items: center;
}
.map-links a { color: var(--accent); }
.pin-fallback {
  font-family: var(--sans);
  font-size: 0.8rem;
  color: var(--faint);
  margin-top: 0.6rem;
}

.prose { font-size: 1.19rem; line-height: 1.72; }
.prose p { margin: 0 0 1.35rem; }
/* Drop cap on the narrative's opening paragraph only — never on the fallback
   notice (a div) or the chooser prompt. */
.prose p:first-of-type:not(.chooser-prompt)::first-letter {
  font-size: 3.1rem;
  line-height: 0.8;
  float: left;
  padding: 0.1rem 0.55rem 0 0;
  color: var(--accent);
}

.layers {
  margin-top: 3rem;
  border-top: 1px solid var(--rule);
  padding-top: 2rem;
}
.layers h2 {
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--faint);
  margin: 0 0 1.5rem;
}
.layer { margin-bottom: 1.5rem; }
.layer h3 {
  font-family: var(--sans);
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 0.4rem;
}
.layer p { margin: 0; font-size: 1.02rem; line-height: 1.6; color: var(--muted); }

.actions {
  margin-top: 3rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}
.sources {
  font-family: var(--sans);
  font-size: 0.74rem;
  letter-spacing: 0.04em;
  color: var(--faint);
  margin-top: 2.5rem;
}
.generated-at {
  font-family: var(--sans);
  font-size: 0.78rem;
  color: var(--faint);
  margin: 1.5rem 0 0.4rem;
}
.share-footer { margin-top: 3rem; }

.copied { font-family: var(--sans); font-size: 0.8rem; color: var(--muted); }

.search-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1rem;
  font-family: var(--sans);
  font-size: 0.85rem;
  color: var(--muted);
  cursor: pointer;
}
.search-toggle input { accent-color: var(--accent); width: 1rem; height: 1rem; }
.search-toggle span { color: var(--faint); }

.web-sources {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.web-sources-title {
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--faint);
  margin: 0 0 0.4rem;
}
.web-sources a {
  font-family: var(--sans);
  font-size: 0.85rem;
  line-height: 1.4;
  word-break: break-word;
}

/* ---------- Loading ---------- */
.loading {
  min-height: 60vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  text-align: center;
  padding: 2rem;
}
.loading p { font-style: italic; color: var(--muted); margin: 0; }
/* The identity answer, surfaced on the loading screen so the name and type land
   in about a second while the narrative is still being written. */
.loading-identity-name {
  font-family: var(--serif, Georgia, serif);
  font-style: normal !important;
  font-size: 1.5rem;
  line-height: 1.25;
  color: var(--ink, inherit) !important;
}
.loading-identity-desc {
  font-style: normal !important;
  font-family: var(--sans);
  font-size: 0.9rem;
}
.dots { display: inline-flex; gap: 0.4rem; }
.dots span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.2s infinite ease-in-out;
}
.dots span:nth-child(2) { animation-delay: 0.2s; }
.dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes pulse { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }

/* In-prose "writing the narrative…" placeholder, shown after the map paints
   while the model is still generating — so the page never looks finished-yet-
   empty during the gap before the first words arrive. */
.generating-note {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  font-style: italic;
  color: var(--muted);
  min-height: 30vh;
}
/* While generating, hide the completion affordances (actions, open-in links,
   search toggle) so the page clearly reads as "still working". */
#content.generating .actions,
#content.generating .map-links,
#content.generating .search-toggle { display: none; }

.hidden { display: none !important; }

/* ---------- Site footer (link to the recent Locus Points list) ---------- */
.site-footer {
  font-family: var(--sans);
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  text-align: center;
  margin: 1.75rem auto 0.5rem;
  padding-top: 1.25rem;
}
.site-footer a { color: var(--muted); }
.site-footer a:hover { color: var(--accent); }
.share-footer .site-footer { margin-bottom: 0; padding-top: 1rem; }
/* On the landing the footer drops to the bottom of the viewport when the content
   is short, and sits just under the map picker when it isn't — either way it's
   reachable without a long scroll. */
.landing > .site-footer { margin-top: auto; width: 100%; }

/* ---------- Recent Locus Points (/lps) ---------- */
.lps-wrap {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 3.5rem 1.5rem 4rem;
}
.lps-wrap h1 {
  font-size: 1.8rem;
  font-weight: 600;
  margin: 0.4rem 0 0.3rem;
}
.lps-intro { color: var(--muted); margin: 0 0 1.8rem; }
.lps-search {
  width: 100%;
  font-family: var(--serif);
  font-size: 1.05rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--card);
  color: var(--ink);
  margin-bottom: 1.6rem;
}
.lps-search:focus { outline: none; border-color: var(--accent); }
.lps-count {
  font-family: var(--sans);
  font-size: 0.74rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
  margin: 0 0 1rem;
}
.lp-list { list-style: none; margin: 0; padding: 0; }
.lp-item { border-top: 1px solid var(--rule); }
.lp-item:last-child { border-bottom: 1px solid var(--rule); }
/* Each row is one big tap target: text on the left, a chevron on the right so it
   reads as tappable on mobile (where there's no hover to hint at it). */
.lp-item a {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.95rem 0.5rem 0.95rem 0.25rem;
  color: var(--ink);
}
.lp-item a:hover,
.lp-item a:active { text-decoration: none; background: var(--card); }
.lp-text { flex: 1 1 auto; min-width: 0; }
.lp-name { display: block; font-size: 1.08rem; font-weight: 600; }
.lp-name .lp-venue { color: var(--muted); font-weight: 400; }
.lp-name .lp-reading { color: var(--muted); font-weight: 400; }
.lp-meta {
  display: block;
  font-family: var(--sans);
  font-size: 0.75rem;
  color: var(--faint);
  margin-top: 0.2rem;
}
.lp-go { flex: none; color: var(--accent); font-size: 1.5rem; line-height: 1; }
/* Tapped-row feedback: the chevron becomes a spinner and the meta line reads
   "Retrieving…" while the point's narrative regenerates. */
.lp-item a.is-loading { background: var(--card); }
.lp-item a.is-loading .lp-meta { color: var(--accent); }
.lp-spin {
  width: 1.05rem;
  height: 1.05rem;
  border: 2px solid var(--rule);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: lp-spin 0.7s linear infinite;
}
@keyframes lp-spin { to { transform: rotate(360deg); } }
.lp-empty { color: var(--muted); padding: 2rem 0; }
.lps-more {
  display: block;
  margin: 2rem auto 0;
  font-family: var(--sans);
  font-size: 0.82rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16140f;
    --ink: #ece7dd;
    --muted: #a8a297;
    --faint: #6f6a60;
    --rule: #322e27;
    --accent: #d08a63;
    --card: #1d1a14;
  }
}
