:root {
  --color-primary: #0078BD;
  --color-corp: #00A6E2;
  --color-title: #FFFFFF;
  --color-highlight: #F01F76;
  --color-sun-yellow: #FFE417;
  --color-sun-orange: #FFAE17;

  --bg-deep: #050b18;
  --bg-panel: #0c1830;
  --bg-panel-2: #122246;
  --border-soft: rgba(0, 166, 226, 0.25);

  --color-cartouche: #00569C;
  --color-cartouche-sunset: #E27800;

  --text-primary: var(--color-title);
  --text-secondary: rgba(255, 255, 255, 0.68);
  --text-muted: rgba(255, 255, 255, 0.4);

  --radius-md: 14px;
  --radius-lg: 20px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);

  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-deep);
}

body {
  font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--text-primary);
  background: linear-gradient(180deg, #24405c 0%, #122544 40%, #0a1728 70%, var(--bg-deep) 100%);
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; }

.app {
  min-height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(82px + var(--safe-bottom));
  position: relative;
}

/* ---------- Sound toggle ---------- */

.sound-toggle {
  position: fixed;
  top: 30px;
  right: 30px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(3, 10, 22, 0.55);
  color: var(--color-corp);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 40;
}

.sound-toggle.is-muted { color: var(--text-muted); }

.sound-toggle svg { width: 20px; height: 20px; fill: currentColor; }

/* ---------- Header ---------- */

.header {
  padding: calc(100px + var(--safe-top)) 18px 8px;
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.location-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 4px;
  max-width: 100%;
}

.icon-pin {
  width: 18px;
  height: 18px;
  fill: var(--color-highlight);
  flex: none;
}

.location-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

.edit-pill {
  background: rgba(3, 10, 22, 0.55);
  border: none;
  color: var(--color-corp);
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: lowercase;
  padding: 6px 22px;
  border-radius: 999px;
  cursor: pointer;
  margin-bottom: 8px;
}

.eclipse-stats-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 22px;
  width: 100%;
  margin-bottom: 2px;
}

.stat {
  text-align: center;
  min-width: 74px;
  flex: none;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  text-transform: lowercase;
  margin-bottom: 4px;
}

.stat-value {
  font-size: 1.4rem;
  font-weight: 400;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.eclipse-visual {
  width: 84px;
  height: 84px;
  flex: none;
}

.eclipse-visual svg { width: 100%; height: 100%; display: block; }

.eclipse-type-heading {
  font-size: 1.35rem;
  font-weight: 400;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  text-align: center;
  margin: 0;
}

/* ---------- Phase list / countdown ---------- */

.main { flex: 1 1 auto; padding: 0 18px 18px; }

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

.no-eclipse-message {
  padding: 32px 8px;
  text-align: center;
}

.no-eclipse-message p {
  margin: 0 0 14px;
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--text-secondary);
}

.no-eclipse-message p:last-child { margin-bottom: 0; }

.no-eclipse-message a {
  color: var(--color-corp);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.phase-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 6px;
  transition: opacity .5s ease, background-color .5s ease;
}

.phase-item .phase-name {
  font-weight: 500;
  font-size: 0.95rem;
  text-transform: lowercase;
}

.phase-item .phase-time {
  font-size: 0.85rem;
  font-weight: 600;
  color: #fff;
  background: var(--color-cartouche);
  padding: 6px 18px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

.phase-item.is-sunset .phase-time {
  background: var(--color-cartouche-sunset);
}

.phase-item.is-past {
  opacity: 0.25;
}

.phase-item .countdown-big { display: none; }

.phase-item.is-target {
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: var(--color-primary);
  border-radius: var(--radius-lg);
  padding: 10px 16px 8px;
  margin: 4px 0;
}

.phase-item.is-target .phase-name {
  order: 1;
  font-size: 1.05rem;
  font-weight: 600;
  color: #fff;
  text-align: center;
  text-transform: none;
}

.phase-item.is-target .phase-name::first-letter {
  text-transform: uppercase;
}

.phase-item.is-target .countdown-big {
  order: 2;
  display: flex;
}

.phase-item.is-target .phase-time {
  order: 3;
  background: rgba(3, 10, 22, 0.55);
}

.countdown-big {
  justify-content: center;
  align-items: baseline;
  gap: 8px;
  font-variant-numeric: tabular-nums;
  color: #fff;
  line-height: 1;
}

.countdown-big .cd-colon {
  font-size: 1.5rem;
  font-weight: 400;
  align-self: flex-start;
  margin-top: 2px;
}

.countdown-big .cd-segment {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.countdown-big .cd-value { font-size: 1.8rem; font-weight: 400; }
.countdown-big .cd-segment-days .cd-value { font-weight: 800; }
.countdown-big .cd-segment-days { margin-right: 18px; }
.countdown-big .cd-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.65);
  letter-spacing: 0.05em;
}

/* ---------- Footer ---------- */

.footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  gap: 10px;
  padding: 10px 18px calc(10px + var(--safe-bottom));
  background: linear-gradient(0deg, var(--bg-deep) 55%, transparent);
}

.footer-btn {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--color-corp);
  padding: 6px 4px;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.15;
  text-align: center;
  text-transform: lowercase;
  cursor: pointer;
}

.footer-btn-icon {
  width: 32px;
  height: 32px;
  fill: var(--color-corp);
}

/* ---------- Overlays / Modals ---------- */

.overlay, .modal {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 16, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.overlay.hidden, .modal.hidden { display: none; }

.overlay-card, .modal-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.modal-card-wide { max-width: 520px; }

/* Bottom sheet variant (weather / horizon popups): slides up from the bottom,
   white surface, content area fills the rest of the sheet edge-to-edge. */
.modal.sheet {
  align-items: flex-end;
  padding: 0;
}

.sheet-card {
  width: 100%;
  max-width: 560px;
  height: 75vh;
  background: #ffffff;
  border-radius: 24px 24px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: sheet-up .32s cubic-bezier(.16, 1, .3, 1);
}

@keyframes sheet-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.sheet-card.closing {
  animation: sheet-down .32s cubic-bezier(.16, 1, .3, 1) forwards;
}

@keyframes sheet-down {
  from { transform: translateY(0); }
  to { transform: translateY(100%); }
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: none;
  padding: 20px 20px 4px;
}

.sheet-header h2 {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0;
  color: var(--color-primary);
}

.sheet-header .modal-close {
  width: 34px;
  height: 34px;
  flex: none;
  border-radius: 50%;
  background: var(--color-corp);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  padding: 0;
}

.sheet-intro {
  flex: none;
  margin: 0;
  padding: 0 20px 14px;
  font-size: 0.85rem;
  color: #5a6472;
}

.sheet-fill {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
}

.sheet-fill-padded {
  padding: 4px 20px 20px;
  overflow-y: auto;
  font-size: 0.88rem;
  color: #333;
}

.sheet-fill-bleed {
  display: flex;
}

.overlay-card p { margin: 0 0 16px; font-size: 0.9rem; color: var(--text-secondary); }

.overlay-actions { display: flex; gap: 10px; }

.btn-primary, .btn-secondary, .btn-ghost {
  border-radius: var(--radius-md);
  padding: 11px 16px;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  border: 1px solid transparent;
}

#location-modal .btn-primary,
#location-modal .btn-secondary,
#sound-enable-overlay .btn-primary,
#sound-enable-overlay .btn-ghost {
  border-radius: 999px;
}

.btn-primary {
  background: var(--color-highlight);
  color: #fff;
  flex: 1;
}

.btn-secondary {
  background: var(--color-primary);
  color: #fff;
  width: 100%;
  margin-bottom: 14px;
}

.btn-ghost {
  background: transparent;
  border-color: var(--border-soft);
  color: var(--text-secondary);
  flex: 1;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.modal-header h2 { font-size: 1rem; margin: 0; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px;
}

.search-row { display: flex; gap: 8px; margin-bottom: 12px; }

#location-search-input {
  flex: 1;
  background: #f0f2f5;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  color: #222;
  /* iOS Safari auto-zooms the page when a focused input's font-size is under 16px */
  font-size: 16px;
}

.location-results {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
  max-height: 220px;
  overflow-y: auto;
}

.location-results li {
  padding: 10px 8px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  font-size: 0.85rem;
  color: #222;
  cursor: pointer;
}

.location-results li:hover { background: rgba(0, 0, 0, 0.04); }

.location-status { font-size: 0.8rem; color: #888; min-height: 1em; }

.reload-link {
  background: none;
  border: none;
  padding: 6px 0 0;
  margin: 0;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-corp);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  display: block;
}

.horizon-frame-wrap {
  width: 100%;
  height: 100%;
  background: #000;
}

.horizon-frame-wrap iframe { width: 100%; height: 100%; border: 0; display: block; }

.sheet-fill-padded p { margin: 0; }

/* ---------- Toasts ---------- */

.toast-container {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(76px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 0 18px;
  pointer-events: none;
  z-index: 60;
}

.toast {
  background: var(--color-highlight);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 10px 16px;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  animation: toast-in .3s ease;
  max-width: 460px;
  text-align: center;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (min-width: 600px) {
  .app { padding-top: calc(24px + var(--safe-top)); }
}
