:root {
  --bg: #2b2620;
  --accent: #c98a4b;
  --accent-dark: #a86f38;
  --panel: #fbf7f1;
  --text-dark: #2b2620;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
}

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

/* Title overlay */
#title-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  padding-top: max(14vh, 60px);
  pointer-events: none;
  transition: opacity 0.5s ease;
  z-index: 5;
  text-align: center;
}

#title-overlay h1 {
  margin: 0;
  color: #fff;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 500;
  font-size: clamp(28px, 8vw, 52px);
  line-height: 1.15;
  text-shadow: 0 2px 18px rgba(0,0,0,0.65), 0 1px 3px rgba(0,0,0,0.5);
  letter-spacing: 0.5px;
}


/* Floating action buttons */
.fab {
  position: absolute;
  right: 16px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 10px rgba(0,0,0,0.35);
  cursor: pointer;
  z-index: 6;
}

.fab-secondary {
  background: var(--text-dark);
  color: #fff;
}

/* locate/layers/gallery/analysis/add stay hidden until the single toggle
   button below them is tapped, instead of several buttons always stacked on
   screen - tapping any of them (or tapping the map/closing a sheet) folds
   them back away. Same size as the toggle itself so the whole stack lines
   up cleanly, and closer together than the old always-visible stack. */
.fab-menu-item {
  width: 55px;
  height: 55px;
  font-size: 23px;
  opacity: 0;
  transform: scale(0.6);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
body.menu-open .fab-menu-item {
  opacity: 1;
  transform: scale(1);
  pointer-events: auto;
}
#add-btn { bottom: calc(24px + 1*70px); font-size: 25px; }
#analysis-btn { bottom: calc(24px + 2*70px); }
#gallery-btn { bottom: calc(24px + 3*70px); }
#layers-btn { bottom: calc(24px + 4*70px); }

.fab-menu-toggle {
  bottom: 24px;
  width: 55px;
  height: 55px;
  background: var(--text-dark);
  color: #fff;
  font-size: 24px;
  transition: transform 0.18s ease;
}
body.menu-open .fab-menu-toggle {
  transform: rotate(90deg);
}

/* Off on its own, opposite corner from the other controls - it's a map
   navigation aid (like the zoom control), not a feature panel, so it
   doesn't belong folded in with the others. Same dark color as everything
   else, just smaller/softened to stay out of the way. */
.fab-locate {
  left: 16px;
  right: auto;
  bottom: 20px;
  width: 50px;
  height: 50px;
  font-size: 20px;
  background: rgba(43, 38, 32, 0.85);
  color: #fff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

/* Bottom sheets */
.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 82vh;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  background: var(--panel);
  color: var(--text-dark);
  border-radius: 18px 18px 0 0;
  padding: 10px 20px 28px;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.3);
  z-index: 20;
  transform: translateY(0);
  transition: transform 0.25s ease;
}
.sheet.hidden { transform: translateY(110%); pointer-events: none; }
.sheet-tall { max-height: 78vh; }

/* The Analysis plot's dots/labels are sized in SVG units against its own
   box, so on a wide desktop browser it would otherwise render much larger
   than on a phone. The panel itself stays full-width like every other sheet
   — only the plot box is capped (and centered) on wider viewports, keeping
   dot/label size close to phone scale without shrinking the whole panel. */
@media (min-width: 640px) {
  #pca-plot {
    max-width: 420px;
    margin-left: auto;
    margin-right: auto;
  }
}

/* The visible bar is tiny (by design, a subtle affordance) but it still
   needs to be easy to actually grab on a touchscreen - the real hit target
   is the full-width strip around it, drawn via ::after so the look is
   unchanged. touch-action: none keeps the browser from trying to scroll
   the page while a drag is in progress (see the swipe-to-dismiss JS). */
.sheet-handle {
  width: 100%;
  height: 28px;
  margin: 0 0 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  touch-action: none;
}
.sheet-handle::after {
  content: "";
  width: 40px;
  height: 4px;
  background: #d8cfc2;
  border-radius: 2px;
}

.sheet h2 {
  margin: 0 0 12px;
  font-size: 19px;
}

.hint {
  font-size: 13px;
  color: #7a6f5f;
  margin: 4px 0 12px;
}

.btn-primary, .btn-secondary {
  width: 100%;
  display: block;
  padding: 13px;
  border-radius: 10px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 10px;
  cursor: pointer;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:disabled { background: #d8cfc2; color: #93897a; }
.btn-secondary { background: #eee5d8; color: var(--text-dark); }

.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin: 12px 0 6px;
}

#rock-form input[type="file"],
#rock-form input[type="text"],
#rock-form textarea,
#rock-form input[type="password"] {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #d8cfc2;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
}

#photo-preview {
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: 10px;
  margin-top: 10px;
}


.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  font-size: 15px;
  border-bottom: 1px solid #eee2d2;
}
.switch-row input { width: 20px; height: 20px; }

#pick-hint {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.7);
  color: #fff;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 13px;
  z-index: 15;
}

#toast {
  position: absolute;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20,20,20,0.9);
  color: #fff;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 13px;
  z-index: 30;
  max-width: 85vw;
  text-align: center;
}

.hidden { display: none !important; }

/* MapLibre popup styling */
.maplibregl-popup-content {
  border-radius: 12px;
  padding: 10px;
  max-width: 260px;
  max-height: 70vh;
  overflow-y: auto;
}
.rock-popup img {
  width: 100%;
  border-radius: 8px;
  margin-bottom: 6px;
  display: block;
}
.rock-popup .title { font-size: 15px; font-weight: 700; margin-top: 2px; }
.rock-popup .desc { font-size: 13px; margin: 4px 0; }
.rock-popup .meta { font-size: 11px; color: #888; }

/* AI composition bar chart (add-rock preview + popup) */
.comp-chart { margin: 8px 0; }
.comp-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 3px 0;
}
.comp-label {
  flex: 0 0 auto;
  width: 84px;
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.comp-bar-track {
  flex: 1;
  height: 9px;
  background: #eee2d2;
  border-radius: 5px;
  overflow: hidden;
}
.comp-bar-fill { height: 100%; border-radius: 5px; }
.comp-pct { flex: 0 0 auto; width: 32px; font-size: 11px; color: #888; text-align: right; }
.comp-pct-wide { width: 58px; }

.rock-marker {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #c98a4b;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  overflow: hidden;
}
.rock-marker img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  /* Slightly zoomed in - a straight full-frame thumbnail at this size tends
     to be mostly background/hand with the rock a small blob in the middle;
     cropping in a bit keeps the rock itself legible. */
  transform: scale(1.35);
}

.map-credits {
  font-size: 11px;
  line-height: 1.5;
  margin: 14px 0 16px;
}
.map-credits a { color: inherit; }

#map-style-select {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #d8cfc2;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  margin-bottom: 14px;
}

/* Analysis / PCA plot */
#pca-color-select {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #d8cfc2;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  margin-bottom: 14px;
}
#pca-plot {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #fff;
  border-radius: 12px;
  overflow: visible;
}
#pca-plot circle {
  cursor: pointer;
  stroke: #fff;
  stroke-width: 1.5px;
}
#pca-plot circle.selected {
  stroke: var(--text-dark);
  stroke-width: 2.5px;
  r: 8;
}
.pca-cluster-label {
  font-size: 11px;
  font-weight: 400;
  paint-order: stroke;
  stroke: #fff;
  stroke-width: 3px;
  pointer-events: none;
}
#pca-selected:empty { display: none; }
.pca-selected-card {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin: 14px 0;
  padding: 10px;
  background: #fff;
  border-radius: 10px;
  cursor: pointer;
}
.pca-selected-card > img,
.pca-selected-card > div:first-child {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
  background: #eee2d2;
}
.pca-selected-card .gallery-row-text { flex: 1; min-width: 0; }
.pca-selected-card .title {
  font-size: 14px;
  font-weight: 700;
  white-space: normal;
  overflow-wrap: break-word;
}
.pca-selected-card .meta { font-size: 12px; color: #93897a; margin-top: 2px; }
#pca-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin: 12px 0;
}
#pca-summary, #pca-corr-summary {
  margin-top: 20px;
}
.pca-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #6b6153;
}
.pca-colorbar {
  width: 100%;
  flex: 1 1 100%;
  margin: 12px 0;
}
.pca-colorbar-gradient {
  height: 10px;
  border-radius: 5px;
}
.pca-colorbar-labels {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: #6b6153;
  margin-top: 4px;
}
.pca-legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.pca-section-title {
  margin: 22px 0 2px;
  font-size: 16px;
}
.corr-table-wrap {
  overflow-x: auto;
  background: #eee2d2;
  border-radius: 12px;
  margin: 10px 0 20px;
  padding: 2px;
}
.corr-table {
  border-collapse: separate;
  border-spacing: 2px;
  font-size: 12px;
}
.corr-table th, .corr-table td {
  padding: 0;
  text-align: center;
}
.corr-table td {
  width: 20px;
  height: 20px;
  min-width: 20px;
  border-radius: 3px;
  cursor: pointer;
}
.corr-table td.selected {
  outline: 2px solid var(--text-dark);
  outline-offset: -2px;
}
th.corr-row-head {
  position: sticky;
  left: 0;
  background: #eee2d2;
  padding: 0 8px 0 10px;
  text-align: right;
  font-weight: 400;
  white-space: nowrap;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
}
th.corr-col-head {
  height: 92px;
  vertical-align: bottom;
  padding-bottom: 4px;
}
th.corr-col-head span {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  white-space: nowrap;
  font-weight: 400;
}
#pca-corr-selected:empty { display: none; }

/* Gallery */
.gallery-country-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid #eee2d2;
  cursor: pointer;
}
.gallery-country-row img,
.gallery-country-row div:first-child {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
  background: #eee2d2;
}
.gallery-country-name { flex: 1; font-size: 15px; font-weight: 700; }
.gallery-country-count { font-size: 13px; color: #93897a; white-space: nowrap; }
.gallery-detail { padding: 4px 0 16px; }
.gallery-detail .rock-popup { font-size: inherit; }
.gallery-detail .title { font-size: 18px; }
.gallery-detail .desc { font-size: 14px; line-height: 1.5; }
.gallery-back-btn {
  display: block;
  border: none;
  background: transparent;
  color: var(--accent, #b5622c);
  font-size: 14px;
  font-weight: 600;
  padding: 4px 0 12px;
  cursor: pointer;
}
.gallery-country {
  position: sticky;
  top: 0;
  background: var(--panel);
  font-size: 15px;
  font-weight: 800;
  color: #2b2620;
  padding: 14px 0 4px;
  border-bottom: 2px solid #eee2d2;
}
.gallery-month {
  position: sticky;
  top: 0;
  background: var(--panel);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #93897a;
  padding: 12px 0 6px;
}
.gallery-row {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid #eee2d2;
  cursor: pointer;
}
.gallery-row img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
  background: #eee2d2;
}
.gallery-row-text { min-width: 0; }
.gallery-row .title,
.gallery-row .desc {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.gallery-row .title { font-size: 14px; font-weight: 700; }
.gallery-row .desc { font-size: 13px; color: #6b6153; margin-top: 1px; }
.gallery-row .meta { font-size: 12px; color: #93897a; margin-top: 2px; }
.gallery-empty { text-align: center; color: #93897a; padding: 40px 0; }

/* Geology legend */
.legend-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 8px 0;
  border-bottom: 1px solid #eee2d2;
}
.legend-swatch {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  flex-shrink: 0;
  margin-top: 2px;
  border: 1px solid rgba(0,0,0,0.15);
}
.legend-text { min-width: 0; }
.legend-name { font-size: 13px; font-weight: 600; }
.legend-age { font-size: 12px; color: #93897a; margin-top: 1px; }
