/* css/style.css — light, natural, calm theme 2025 */

:root {
  /* palette */
  --clr-leaf: #4a7c59;
  /* buttons / accents */
  --clr-sky: #6fa8dc;
  /* secondary accent */
  --clr-sand: #f6e7cb;
  /* subtle highlights */
  --clr-success: #66bb6a;
  --clr-warning: #ffca28;
  --clr-danger: #e57373;

  --bg-body: #f9fbfc;
  /* page background */
  --bg-card: #ffffff;
  /* cards / inputs   */
  --clr-text: #2e3a46;
  /* primary text     */

  /* layout */
  --space: clamp(.75rem, 2vw, 1.25rem);
  --radius: .75rem;
  --shadow: 0 2px 10px rgba(25, 39, 52, .08);

  /* timing */
  --t-fast: .2s;
  --t-med: .35s;
}

/* ─── Reset ────────────────────────────────────────────────────── */
*,
::before,
::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-body);
  color: var(--clr-text);
  line-height: 1.6;
  padding: 1.25rem;
  max-width: 1400px;
  margin: 0 auto;
  font-size: 1rem;
  font-weight: 400;
}

/* ─── Helpers ──────────────────────────────────────────────────── */
/* Style for visibility cards */
.card {
  display: flex;
  flex-direction: column;
  /* Stack items vertically */
  align-items: center;
  /* Center-align content */
  text-align: center;
  /* Center-align text */
  padding: 1rem;
  border: 1px solid #ddd;
  border-radius: 8px;
  background-color: #f9f9f9;
}

.card strong {
  font-size: 1.2rem;
  margin-bottom: 0.5rem;
  /* Add spacing below the header */
}

.card .value {
  font-size: 1rem;
  font-weight: bold;
  margin-bottom: 0.25rem;
  /* Add spacing below the value */
}

.card .sub-info {
  font-size: 0.9rem;
  color: #666;
}

.grid {
  display: grid;
  gap: var(--space);
}

.shadow {
  box-shadow: var(--shadow);
}

/* ─── Header ───────────────────────────────────────────────────── */
header {
  text-align: center;
  margin-block-end: calc(var(--space)*2);
}

h1 {
  font-size: clamp(1.7rem, 2vw+1rem, 2.4rem);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
}

/* ─── Observation controls ─────────────────────────────────────── */
.observation-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--space);
  margin-block-end: calc(var(--space)*2);
}

.observation-controls label {
  margin-block-end: .35rem;
  font-weight: 500;
}

.observation-controls input {
  inline-size: 100%;
  padding: .8rem .9rem;
  background: var(--bg-card);
  border: 1px solid rgba(0, 0, 0, .12);
  border-radius: var(--radius);
  font-size: 1rem;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

.observation-controls input:focus {
  outline: none;
  border-color: var(--clr-sky);
  box-shadow: 0 0 0 3px rgba(111, 168, 220, .25);
}

/* ─── Moon‑info / visibility tiles ─────────────────────────────── */
/* NEW: shared rule for moon-grid & visibility-grid */
.moon-grid,
.visibility-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space);
  margin-block-end: calc(var(--space)*2);
}

.value {
  font-size: 1.15rem;
  margin-block: .4rem;
}

.sub-info {
  font-size: .9rem;
  color: #667788;
}

/* optional hover lift */
@media (hover:hover) {

  .moon-grid .card,
  .visibility-grid .card {
    transition: transform var(--t-fast), box-shadow var(--t-fast);
  }

  .moon-grid .card:hover,
  .visibility-grid .card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 14px rgba(0, 0, 0, .12);
  }
}

/* ─── Map section ──────────────────────────────────────────────── */
#map {
  inline-size: 100%;
  block-size: 500px;
  border-radius: var(--radius);
  overflow: hidden;
  background: #eaf0f6;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .12);
  margin-block-end: calc(var(--space));
}

.timeline-container {
  margin-block-end: calc(var(--space));
}

.leaflet-container {
  background: #eaf0f6;
}

.leaflet-control-zoom a {
  inline-size: 44px;
  block-size: 44px;
  line-height: 44px;
  font-size: 20px;
  background: var(--bg-card) !important;
  color: var(--clr-text) !important;
  border: 1px solid rgba(0, 0, 0, .1) !important;
  border-radius: var(--radius) !important;
}

/* ─── Legend ───────────────────────────────────────────────────── */
/* ─── Legend layout fix ─────────────────────────────────────────── */
.map-legend {
  /* kill the flexbox so we can let CSS‑grid do its job */
  display: grid;
  /* was: flex */
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  justify-items: center;
  margin-top: 16px;
  /* keeps spacing */
}

/* cards stay the same */
.legend-card {
  background: var(--bg-card);
  border: 1px solid rgba(0, 0, 0, .05);
  border-radius: var(--radius);
  padding: 1rem .9rem;
  min-inline-size: 140px;
  text-align: center;
  box-shadow: var(--shadow);
  line-height: 1.45;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: .5rem;
}

/* ─── Explanation Box ──────────────────────────────────────────────── */
#explanation-box {
  margin-top: calc(var(--space) * 1.5);
  padding: 1.5rem;
  background: linear-gradient(to bottom, var(--bg-card), #fafbfc);
  border: 1px solid rgba(0, 0, 0, .1);
  border-left: 4px solid var(--clr-leaf);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--clr-text);
}

#explanation-box strong {
  color: var(--clr-text);
  font-weight: 600;
  display: block;
  margin-bottom: 0.25rem;
}

#explanation-box em {
  color: var(--clr-sky);
  font-style: normal;
  font-weight: 500;
}

#explanation-box > div > div {
  padding: 0.75rem;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 6px;
  transition: background 0.2s ease;
}

#explanation-box > div > div:hover {
  background: rgba(255, 255, 255, 0.9);
}

/* ─── Technical details accordion ──────────────────────────────── */
.technical-details {
  margin-block-start: calc(var(--space)*2);
}

.technical-details h2 {
  padding: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  background: var(--clr-sand);
  border-radius: var(--radius) var(--radius) 0 0;
  font-weight: 600;
}

.technical-details h2::after {
  content: "›";
  transform: rotate(90deg);
  transition: transform var(--t-fast);
}

.technical-details.collapsed h2::after {
  transform: rotate(0);
}

.technical-details .moon-grid {
  padding: 1rem;
  transition: max-height var(--t-med) ease;
}

.technical-details.collapsed .moon-grid {
  max-height: 0;
  overflow: hidden;
  padding-block: 0;
}

/* ─── Markers ──────────────────────────────────────────────────── */
:root {
  --size-marker: 40px;
}

.celestial-marker {
  inline-size: var(--size-marker);
  block-size: var(--size-marker);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  background: #fff;
  box-shadow: 0 0 8px rgba(0, 0, 0, .15);
  z-index: 1000;
}

.sun-marker {
  background: #ffefb0;
}

.moon-marker {
  background: #dee3ff;
}

/* gentle pulsing (respects reduced‑motion) */
@media (prefers-reduced-motion:no-preference) {
  @keyframes gentlyPulse {
    0% {
      transform: scale(.97);
    }

    50% {
      transform: scale(1.03);
    }

    100% {
      transform: scale(.97);
    }
  }

  .sun-marker {
    animation: gentlyPulse 5s infinite;
  }

  .moon-marker {
    animation: gentlyPulse 6s infinite;
  }
}

/* ─── Direction arrow ──────────────────────────────────────────── */
.moon-direction-arrow {
  position: fixed;
  inset-block-end: 24px;
  inset-inline-end: 24px;
  inline-size: 64px;
  block-size: 64px;
  border-radius: 50%;
  background: var(--clr-leaf);
  color: #fff;
  font-size: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 10px rgba(0, 0, 0, .25);
  cursor: pointer;
  transition: transform var(--t-med);
}

.moon-direction-arrow:hover {
  transform: scale(1.05);
}

.moon-direction-arrow::after {
  content: 'Moon';
  position: absolute;
  inset-block-start: 100%;
  inset-inline-start: 50%;
  transform: translateX(-50%);
  font-size: .75rem;
  margin-block-start: .3rem;
}

/* ─── Location input icon & dropdown ───────────────────────────── */
.location-picker {
  position: relative;
}

.location-picker input {
  padding-inline-end: 2.2rem;
}

.location-picker::after {
  content: "📍";
  position: absolute;
  inset-inline-end: .8rem;
  inset-block-start: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  font-size: 1rem;
  opacity: .6;
}

.location-dropdown {
  position: absolute;
  inset-block-start: 100%;
  inset-inline: 0;
  background: var(--bg-card);
  max-block-size: 230px;
  overflow-y: auto;
  border: 1px solid rgba(0, 0, 0, .1);
  border-radius: 0 0 var(--radius) var(--radius);
  z-index: 1000;
}

.dropdown-item {
  padding: .65rem .9rem;
  cursor: pointer;
  border-block-end: 1px solid rgba(0, 0, 0, .06);
}

.dropdown-item:hover {
  background: var(--clr-sand);
}

/* ─── Google Places component tweaks ───────────────────────────── */
gmpx-placeautocomplete {
  --gmpx-color-surface: #fff;
  --gmpx-color-on-surface: #2e3a46;
  --gmpx-color-outline: #b0bec5;
  --gmpx-color-primary: var(--clr-sky);
  font-family: inherit;
}

/* ─── Responsive tweaks ────────────────────────────────────────── */
@media(max-width:600px) {
  body {
    padding: 0.75rem;
  }

  .moon-grid,
  .visibility-grid {
    grid-template-columns: 1fr;
  }

  .observation-controls {
    grid-template-columns: 1fr;
  }

  .location-input {
    font-size: 16px; /* Prevents zoom on iOS */
    max-width: 100%;
  }

  #map {
    height: 400px; /* Smaller on mobile */
  }

  .card {
    padding: 0.75rem;
  }

  .card strong {
    font-size: 1rem;
  }

  .value {
    font-size: 1rem;
  }

  .map-legend {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.75rem;
  }

  .legend-card {
    min-inline-size: 120px;
    padding: 0.75rem 0.5rem;
    font-size: 0.85rem;
  }

  #explanation-box {
    padding: 1rem;
    font-size: 0.9rem;
  }

  .current-location-btn {
    width: 100%;
    padding: 10px;
    font-size: 15px;
  }

  h1 {
    font-size: 1.5rem;
  }

  h2 {
    font-size: 1.25rem;
  }
}

/* ─── Location Search Styles ────────────────────────────────────── */
.search-container {
  margin-bottom: 8px;
}

.location-input {
  width: 100%;
  max-width: 400px;
  padding: 8px 12px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 14px;
}

.location-input:focus {
  outline: none;
  border-color: #666;
  box-shadow: 0 0 0 2px rgba(0,0,0,0.1);
}

.selected-place {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  background: #f8f8f8;
  border-radius: 4px;
  margin-top: 8px;
}

.clear-button {
  margin-left: auto;
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: #666;
  padding: 0 4px;
}

.clear-button:hover {
  color: #333;
}

.place-icon {
  font-size: 16px;
}

.place-name {
  font-weight: 500;
}

/* ─── Current Location Button ──────────────────────────────────── */
.current-location-btn {
  margin-top: 8px;
  padding: 8px 16px;
  background: var(--clr-sky);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  transition: background var(--t-fast);
}

.current-location-btn:hover {
  background: #5a97c4;
}

.current-location-btn:active {
  transform: scale(0.98);
}

/* ─── Loading Spinner ──────────────────────────────────────────── */
.value.loading::after {
  content: '';
  display: inline-block;
  width: 16px;
  height: 16px;
  margin-left: 8px;
  border: 2px solid #f3f3f3;
  border-top: 2px solid var(--clr-leaf);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  vertical-align: middle;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* ─── Error Messages ──────────────────────────────────────────── */
.error-message {
  padding: 12px;
  background: #fee;
  color: #c33;
  border-radius: 4px;
  margin-top: 12px;
  border-left: 4px solid #c33;
}

.success-message {
  padding: 12px;
  background: #efe;
  color: #3c3;
  border-radius: 4px;
  margin-top: 12px;
  border-left: 4px solid #3c3;
}

/* ─── Focus Styles for Accessibility ──────────────────────────── */
*:focus {
  outline: 2px solid var(--clr-sky);
  outline-offset: 2px;
}

button:focus,
input:focus,
select:focus {
  outline: 2px solid var(--clr-sky);
  outline-offset: 2px;
}

/* ─── Timeline Slider ───────────────────────────────────────────── */
.timeline-container {
  margin-top: calc(var(--space) * 2);
  padding: 1.5rem;
  background: var(--bg-card);
  border: 1px solid rgba(0, 0, 0, .1);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.timeline-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.timeline-header h3 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--clr-text);
}

.timeline-time {
  font-weight: 600;
  color: var(--clr-sky);
  font-size: 1.1rem;
}

.timeline-wrapper {
  position: relative;
  margin: 2rem 0 1rem;
}

.timeline-track {
  position: relative;
  height: 60px;
  background: linear-gradient(to right, #1a1a2e 0%, #16213e 50%, #1a1a2e 100%);
  border-radius: 8px;
  border: 2px solid rgba(255, 255, 255, 0.1);
  overflow: visible;
}

.timeline-track::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  background: repeating-linear-gradient(
    to right,
    transparent,
    transparent calc(100% / 24 - 1px),
    rgba(255, 255, 255, 0.1) calc(100% / 24 - 1px),
    rgba(255, 255, 255, 0.1) calc(100% / 24)
  );
  pointer-events: none;
}

/* Hour markers */
.timeline-hour-marker {
  position: absolute;
  top: 0;
  width: 2px;
  height: 100%;
  background: rgba(255, 255, 255, 0.3);
  transform: translateX(-50%);
}

.timeline-hour-marker.major {
  background: rgba(255, 255, 255, 0.5);
  height: 100%;
}

.timeline-hour-label {
  position: absolute;
  top: -20px;
  transform: translateX(-50%);
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.7);
  white-space: nowrap;
}

.timeline-sun-moon {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
}

.timeline-sun,
.timeline-moon {
  position: absolute;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  top: 50%;
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
  border: 2px solid white;
  transition: left 0.3s ease;
}

.timeline-sun {
  background: #ffd700;
  z-index: 10;
}

.timeline-moon {
  background: #c0c0c0;
  z-index: 9;
}

.timeline-slider {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  width: 100%;
  height: 4px;
  margin: 0;
  transform: translateY(-50%);
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  cursor: pointer;
  z-index: 20;
}

.timeline-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--clr-leaf);
  border: 3px solid white;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s;
}

.timeline-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

.timeline-slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--clr-leaf);
  border: 3px solid white;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s;
}

.timeline-slider::-moz-range-thumb:hover {
  transform: scale(1.2);
}

.timeline-controls {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  margin-top: 1rem;
}

.timeline-btn {
  padding: 0.5rem 1rem;
  background: var(--clr-sky);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background var(--t-fast);
}

.timeline-btn:hover {
  background: #5a97c4;
}

.timeline-btn:active {
  transform: scale(0.98);
}

.timeline-btn.playing {
  background: var(--clr-success);
}

@media (max-width: 600px) {
  .timeline-container {
    padding: 1rem;
  }
  
  .timeline-track {
    height: 50px;
  }
  
  .timeline-sun,
  .timeline-moon {
    width: 20px;
    height: 20px;
  }
  
  .timeline-hour-label {
    font-size: 0.65rem;
    top: -18px;
  }
}

/* ─── Reduced‑motion global override ───────────────────────────── */
@media(prefers-reduced-motion:reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
  
  .value.loading::after {
    animation: none;
  }
  
  .timeline-sun,
  .timeline-moon {
    transition: none;
  }
}