/* Look: a travel collage. Sky-blue backdrop, cream paper, flat poster colours,
   "sticker" shapes with a white outline, postage-stamp labels. */
:root {
  --sky: #a9d3e8;
  --navy: #1d2b3a;
  --teal: #234a73; /* primary blue (name kept from the first version) */
  --teal-dark: #1d2b3a;
  --green: #3f7d4e;
  --green-dark: #2f6a3f;
  --poppy: #d6402f;
  --accent: #f2b92d;
  --ink: #1d2b3a;
  --muted: #5b6672;
  --paper: #f6efe2;
  --line: #e2d6bf;
  --danger: #b3261e;
  --display: "Fraunces", Georgia, "Times New Roman", serif;
  --body: "Poppins", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--body);
  color: var(--ink);
  background: var(--paper);
}

/* Buttons and fields do not inherit the page font on their own. */
button, input, select, textarea { font-family: inherit; }

h1, h2, h3 { font-family: var(--display); }

/* Give the map a warm, printed-paper tint so it matches the rest. */
.leaflet-tile-pane { filter: sepia(0.22) saturate(0.85) hue-rotate(-8deg); }

body.reader-open { overflow: hidden; }

.hidden { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 2px solid #fff;
  box-shadow: 0 0 0 4px var(--teal-dark);
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ---- Top bar ---- */
#topbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  padding-top: calc(0.5rem + env(safe-area-inset-top));
  background: var(--sky);
  color: var(--navy);
  flex-wrap: wrap;
}

#topbar h1 {
  font-size: 1.25rem;
  font-weight: 900;
  margin: 0 auto 0 0;
  white-space: nowrap;
}

/* White "sticker" pills */
.chip-btn {
  min-height: 40px;
  max-width: 55vw;
  padding: 0.35rem 0.9rem;
  border: none;
  border-radius: 999px;
  background: #fff;
  color: var(--navy);
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: 0 2px 0 rgba(29, 43, 58, 0.25);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chip-btn:hover { background: #fff7e0; }

/* Row 1: brand + My spots. Row 2: the destination as a full-width bar. */
#destination-btn {
  order: 3;
  flex: 1 1 100%;
  max-width: none;
  text-align: left;
}

/* ---- Map ---- */
#map-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
}

#map {
  position: absolute;
  inset: 0;
  z-index: 0;
}

#new-spot-btn {
  position: absolute;
  left: 50%;
  bottom: calc(1.2rem + env(safe-area-inset-bottom));
  transform: translateX(-50%) rotate(-2deg);
  z-index: 500;
  min-height: 54px;
  padding: 0.6rem 1.4rem;
  border: 3px solid #fff; /* sticker outline */
  border-radius: 999px;
  background: var(--poppy);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 800;
  box-shadow: 0 4px 0 rgba(29, 43, 58, 0.25), 0 6px 14px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  white-space: nowrap;
}

#new-spot-btn span { margin-right: 0.3rem; font-size: 1.2em; }
#new-spot-btn:hover { background: #e24b39; }

#locate-btn {
  position: absolute;
  right: 0.8rem;
  bottom: calc(1.2rem + env(safe-area-inset-bottom));
  z-index: 500;
  width: 48px;
  height: 48px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--accent);
  font-size: 1.3rem;
  box-shadow: 0 3px 0 rgba(29, 43, 58, 0.25), 0 4px 10px rgba(0, 0, 0, 0.25);
  cursor: pointer;
}

.map-hint {
  position: absolute;
  left: 50%;
  bottom: calc(5.5rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 500;
  margin: 0;
  padding: 0.5rem 0.9rem;
  max-width: 90%;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.25);
  font-size: 0.9rem;
  text-align: center;
}

/* Teardrop pin: the container is rotated so its sharp corner points down. */
.pin {
  width: 34px;
  height: 34px;
  border-radius: 50% 50% 50% 0;
  background: var(--pin);
  border: 3px solid white;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.45);
  transform: rotate(-45deg) translate(-4px, 4px);
  transform-origin: center;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pin span {
  transform: rotate(45deg);
  font-size: 1rem;
  line-height: 1;
}

.popup-title { font-weight: 600; }

/* ---- Modals ---- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(29, 43, 58, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal-box {
  background: var(--paper);
  border-radius: 18px;
  padding: 1.2rem;
  width: 100%;
  max-width: 460px;
  max-height: 92vh;
  max-height: 92dvh;
  overflow-y: auto;
}

@media (max-width: 600px) {
  .modal.sheet { align-items: flex-end; padding: 0; }
  .modal.sheet .modal-box {
    max-width: none;
    border-radius: 22px 22px 0 0;
    padding-bottom: calc(1.2rem + env(safe-area-inset-bottom));
    max-height: 94vh;
    max-height: 94dvh;
  }
}

.modal-box h2 { margin: 0 0 0.6rem; font-size: 1.15rem; }

.modal-box label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  margin-top: 0.8rem;
}

.modal-box input[type="text"],
.modal-box select,
.modal-box textarea {
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.55rem 0.7rem;
  border: 2px solid var(--line);
  border-radius: 12px;
  font-size: 1rem; /* 16px keeps iOS from zooming into the field */
  font-family: inherit;
  background: white;
  color: var(--ink);
}

.modal-box fieldset.plain {
  border: none;
  margin: 0.9rem 0 0;
  padding: 0;
  min-width: 0;
}

.modal-box fieldset.plain legend {
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0;
  margin-bottom: 0.3rem;
}

.hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0.3rem 0;
}

.form-error {
  min-height: 1.2em;
  margin: 0.8rem 0 0;
  color: var(--danger);
  font-size: 0.9rem;
  font-weight: 600;
}

.inline-row { display: flex; gap: 0.5rem; align-items: center; }
.inline-row.between { justify-content: space-between; }
.inline-row input { flex: 1; min-width: 0; }

.primary-btn,
.secondary-btn {
  min-height: 44px;
  padding: 0.5rem 1.1rem;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

.primary-btn {
  width: 100%;
  border: none;
  background: var(--teal);
  color: white;
}

.secondary-btn {
  border: 1px solid var(--teal);
  background: white;
  color: var(--teal);
  margin-top: 0.3rem;
}

.primary-btn:disabled { opacity: 0.6; cursor: progress; }

.link-btn {
  padding: 0.5rem 0;
  min-height: 40px;
  border: none;
  background: none;
  color: var(--teal);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}

.link-btn:disabled { opacity: 0.6; }

.result-list { list-style: none; margin: 0; padding: 0; }

.result-list button {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 0.5rem 0.6rem;
  border: none;
  border-bottom: 1px solid var(--line);
  background: none;
  text-align: left;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}

.result-list button:hover { background: #f1f5f6; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

.modal-actions.wrap { flex-wrap: wrap; }

.modal-actions button {
  min-height: 44px;
  padding: 0.45rem 1.2rem;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  background: var(--teal);
  color: white;
}

.modal-actions button.secondary { background: #fff; color: var(--ink); box-shadow: inset 0 0 0 2px var(--line); }
.modal-actions button.danger { background: white; color: var(--danger); border: 1px solid var(--danger); margin-right: auto; }
.modal-actions button:disabled { opacity: 0.6; cursor: progress; }

/* ---- Photo ---- */
.photo-buttons { display: flex; gap: 0.5rem; }

.file-btn {
  position: relative;
  flex: 1;
  margin: 0 !important;
  min-height: 48px;
  display: flex !important;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--teal);
  border-radius: 14px;
  background: #fff;
  color: var(--teal);
  font-weight: 600;
  cursor: pointer;
}

.file-btn:hover { background: #eef5f7; }
.file-btn input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.file-btn:focus-within { outline: 2px solid #fff; box-shadow: 0 0 0 4px var(--teal-dark); }

.photo-preview {
  display: block;
  max-width: 100%;
  max-height: 220px;
  border-radius: 8px;
  margin-top: 0.6rem;
}

/* ---- Category cards ---- */
.category-options {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(135px, 1fr));
  gap: 0.5rem;
}

.cat-card {
  position: relative;
  display: flex !important;
  flex-direction: column;
  gap: 0.1rem;
  margin: 0 !important;
  padding: 0.6rem 0.7rem;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: #fff;
  cursor: pointer;
  font-weight: 400 !important;
}

.cat-card input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.cat-icon { font-size: 1.4rem; }
.cat-name { font-weight: 700; font-size: 0.95rem; }
.cat-hint { font-size: 0.75rem; color: var(--muted); line-height: 1.25; }

.cat-card:has(input:checked) {
  border-color: var(--pin);
  background: color-mix(in srgb, var(--pin) 10%, white);
}

.cat-card:has(input:checked)::after {
  content: "✓";
  position: absolute;
  top: 0.4rem;
  right: 0.55rem;
  font-weight: 700;
  color: var(--pin);
}

.cat-card:has(input:focus-visible) { outline: 2px solid #fff; box-shadow: 0 0 0 4px var(--teal-dark); }

/* ---- Mini map in the form ---- */
.mini-map {
  height: 190px;
  border-radius: 10px;
  border: 1px solid var(--line);
  z-index: 0;
}

#spot-extras { margin-top: 0.9rem; }
#spot-extras summary { cursor: pointer; font-weight: 600; font-size: 0.9rem; padding: 0.7rem 0; }

.rating-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

.remark-row { display: flex; gap: 0.4rem; margin-top: 0.5rem; }
.remark-row input { min-width: 0; padding: 0.5rem; border: 1px solid #aab3b6; border-radius: 8px; font-size: 1rem; }
.remark-row .remark-label { flex: 0 0 34%; }
.remark-row .remark-text { flex: 1; }

.remove-remark {
  flex: 0 0 auto;
  width: 44px;
  border: 1px solid #ccc;
  border-radius: 8px;
  background: white;
  color: var(--danger);
  cursor: pointer;
}

/* ---- Detail + My spots ---- */
.detail-photo {
  display: block;
  width: 100%;
  max-height: 300px;
  object-fit: cover;
  border-radius: 10px;
  margin-bottom: 0.8rem;
}

.detail-meta { margin: 0 0 0.6rem; color: var(--muted); font-size: 0.9rem; }

.country-group { margin-top: 1rem; }

.group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.group-head h3 { margin: 0; font-size: 1.05rem; }
.count { color: var(--muted); font-weight: 400; font-size: 0.85em; margin-left: 0.2rem; }

.city-list { list-style: none; margin: 0.3rem 0 0; padding: 0; }

.city-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--line);
}

.share-btn {
  min-height: 40px;
  padding: 0.3rem 0.9rem;
  border: 2px solid var(--teal);
  border-radius: 999px;
  background: white;
  color: var(--teal);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.share-btn:hover { background: #eef5f7; }
.share-btn.is-shared { background: var(--green); border-color: var(--green); color: #fff; }
.share-btn.is-shared:hover { background: var(--green-dark); }

#share-link-input {
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.5rem;
  border-radius: 8px;
  border: 1px solid #aab3b6;
  font-size: 0.85rem;
}

/* ---- Toast ---- */
#toast {
  position: fixed;
  left: 50%;
  top: calc(0.8rem + env(safe-area-inset-top));
  transform: translateX(-50%);
  z-index: 3000;
  max-width: 90%;
  padding: 0.6rem 1rem;
  border-radius: 999px;
  border: 2px solid #fff;
  background: var(--navy);
  color: white;
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

#toast.show { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  #toast { transition: none; }
}

/* ---- Receiver view ---- */
#reader {
  position: fixed;
  inset: 0;
  z-index: 2000;
  overflow-y: auto;
  background: var(--paper);
  color: var(--ink);
}

.reader-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding-bottom: 2rem;
}

.reader-hero {
  position: relative;
  min-height: 220px;
  height: 36vh;
  max-height: 360px;
  display: flex;
  align-items: flex-end;
  background: var(--sky);
  color: var(--navy);
  overflow: hidden;
}

.reader-hero.has-cover { color: white; }

.reader-cover {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.reader-hero.has-cover::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.72), rgba(0, 0, 0, 0.1) 65%);
}

.reader-hero-text { position: relative; z-index: 1; padding: 1.2rem 1rem; }
.reader-hero h1 { margin: 0; font-size: 2.2rem; font-weight: 900; line-height: 1.1; }
.reader-dest { margin: 0 0 0.3rem; font-size: 0.95rem; }

.reader-close {
  position: absolute;
  top: calc(0.8rem + env(safe-area-inset-top));
  left: 0.8rem;
  z-index: 2;
  min-height: 40px;
  padding: 0.4rem 0.9rem;
  border: none;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.95);
  color: var(--ink);
  font-weight: 600;
  cursor: pointer;
}

.reader-intro { padding: 1rem; }
.reader-intro p { margin: 0; }
.reader-intro .reader-count { color: var(--muted); font-size: 0.9rem; }

.reader-filters { display: flex; gap: 0.5rem; padding: 0 1rem 1rem; overflow-x: auto; }

.reader-chip {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  border: 2px solid #fff;
  background: white;
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: 0 2px 0 rgba(29, 43, 58, 0.2);
  cursor: pointer;
}

.reader-chip span { color: var(--muted); margin-left: 0.2rem; }
.reader-chip[aria-pressed="true"] { background: var(--teal); border-color: var(--teal); color: white; }
.reader-chip[aria-pressed="true"] span { color: #d7e6eb; }

.reader-body { display: flex; flex-direction: column; gap: 1rem; padding: 0 1rem; }

.reader-map {
  height: 320px;
  border-radius: 18px;
  border: 3px solid #fff;
  box-shadow: 0 3px 12px rgba(29, 43, 58, 0.18);
  z-index: 0;
}

.reader-marker {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--pin, var(--teal));
  color: white;
  border: 2px solid white;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
}

.reader-marker.is-active { background: var(--accent); color: #1f2a2e; transform: scale(1.2); }

.reader-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1rem; }

.reader-card {
  background: #fff;
  border: 3px solid #fff;
  border-radius: 18px;
  box-shadow: 0 3px 12px rgba(29, 43, 58, 0.18);
  overflow: hidden;
}
.reader-card[hidden] { display: none; }
.reader-card.is-active { border-color: var(--accent); }

.reader-photo { border-radius: 14px 14px 0 0; }

.reader-photo { display: block; width: 100%; max-height: 280px; object-fit: cover; }

.reader-card-body { padding: 0.9rem 1rem 1rem; }
.reader-card-head { display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem; }
.reader-card-head h2 { margin: 0; font-size: 1.15rem; flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }

.reader-num {
  flex: 0 0 auto;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--teal);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
}

/* Postage-stamp style label */
.reader-badge {
  font-size: 0.78rem;
  color: var(--muted);
  white-space: nowrap;
  padding: 0.1rem 0.5rem;
  border: 2px dashed var(--line);
  border-radius: 6px;
}

.reader-ratings { display: flex; gap: 1.2rem; margin: 0.7rem 0 0; }
.reader-rating dt { font-size: 0.75rem; color: var(--muted); }
.reader-rating dd { margin: 0; display: flex; align-items: center; gap: 0.5rem; }
.reader-rating-value { font-weight: 700; font-size: 1.1rem; }
.reader-rating-value small { font-weight: 400; color: var(--muted); font-size: 0.75rem; }

.reader-rating-bar { display: block; width: 56px; height: 6px; border-radius: 3px; background: #e3e8e6; overflow: hidden; }
.reader-rating-bar span { display: block; height: 100%; background: var(--green); }

.reader-text { margin: 0.8rem 0 0; line-height: 1.5; white-space: pre-line; overflow-wrap: anywhere; }

.reader-remarks { margin: 0.8rem 0 0; padding: 0.6rem 0.8rem; background: var(--paper); border-radius: 8px; font-size: 0.9rem; }
.reader-remarks div + div { margin-top: 0.4rem; }
.reader-remarks dt { font-weight: 600; }
.reader-remarks dd { margin: 0; white-space: pre-line; }

.reader-actions { display: flex; gap: 1rem; align-items: center; margin-top: 0.9rem; }

.show-on-map {
  min-height: 40px;
  padding: 0.35rem 1rem;
  border-radius: 999px;
  border: 2px solid var(--teal);
  background: white;
  color: var(--teal);
  font-weight: 600;
  cursor: pointer;
}

.reader-actions a { color: var(--teal); font-weight: 600; }

.reader-footer { margin: 2rem 1rem 0; padding: 1rem; border-top: 1px solid var(--line); text-align: center; }
.reader-footer p { margin: 0 0 0.6rem; color: var(--muted); font-size: 0.85rem; }

.reader-footer button {
  min-height: 44px;
  padding: 0.4rem 1.2rem;
  border: none;
  border-radius: 999px;
  background: var(--poppy);
  color: white;
  font-weight: 700;
  cursor: pointer;
}

@media (min-width: 900px) {
  .reader-hero h1 { font-size: 3rem; }
  .reader-hero-text, .reader-intro, .reader-filters, .reader-body { padding-left: 1.5rem; padding-right: 1.5rem; }
  .reader-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
  .reader-map { order: 2; position: sticky; top: 1rem; height: calc(100vh - 2rem); }
}
