* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: #1a1a1a;
  background: #fafafa;
  transition: background-color 0.3s ease;
}

/* Whole-page carrier for the alarm state (see tickAlarm's setPageState in app.js).
   Colours are pale tints, not full-strength, so the map/cards/buttons — each on
   their own opaque background — stay crisp rather than washed out; verified
   against the WCAG AA 4.5:1 threshold for every text colour that sits directly on
   the page background (no card of its own): #1a1a1a, #444, #666, #a33. */
body.state-green {
  background: #d9f0da;
}

body.state-amber {
  background: #ffe9c2;
}

body.state-red {
  /* Desaturated (dusty terracotta, not pure #f00) — a fully saturated red across
     the whole viewport is a known OLED "vibration" discomfort issue. Also used
     for the "deadline already passed" case (see tickAlarm), not just a low margin. */
  background: #f2e0de;
}

.app-header {
  background: #1a5d1a;
  color: #fff;
  padding: 1rem;
  padding-top: max(1rem, env(safe-area-inset-top));
  text-align: center;
}

.app-header h1 {
  margin: 0;
  font-size: 1.5rem;
}

.tagline {
  margin: 0.25rem 0 0;
  font-size: 0.95rem;
  opacity: 0.9;
}

main {
  padding: 1rem;
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
  max-width: 640px;
  margin: 0 auto;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.location-controls {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

button {
  font-size: 1rem;
  padding: 0.75rem 1rem;
  min-height: 44px;
  border: none;
  border-radius: 8px;
  background: #1a5d1a;
  color: #fff;
  cursor: pointer;
}

button:hover {
  background: #144a14;
}

.address-form {
  display: flex;
  gap: 0.5rem;
}

.address-form input {
  flex: 1;
  min-width: 0;
  font-size: 1rem;
  padding: 0.75rem;
  min-height: 44px;
  border: 1px solid #ccc;
  border-radius: 8px;
}

.message {
  min-height: 1.25rem;
  margin: 0;
  font-size: 0.9rem;
  color: #a33;
}

.boundary-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: #444;
}

.boundary-toggle select {
  font-size: 0.9rem;
  padding: 0.4rem;
  border-radius: 6px;
  border: 1px solid #ccc;
}

#map {
  width: 100%;
  height: 60vh;
  min-height: 300px;
  border-radius: 8px;
  overflow: hidden;
}

.status-message {
  margin-top: 1rem;
  font-size: 1.05rem;
  font-weight: 600;
  text-align: center;
}

.route-result {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 8px;
}

.route-primary {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: #1a5d1a;
  text-align: center;
}

.route-alternatives {
  margin: 0.5rem 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.9rem;
  color: #444;
  text-align: center;
}

.deadline-controls {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 1rem;
  font-size: 0.9rem;
  color: #444;
}

.deadline-presets,
.buffer-control {
  flex: 1 1 calc(50% - 0.5rem);
  min-width: 0;
}

.buffer-control {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Narrow phones (e.g. iPhone SE-width and below): stack full width so both
   controls stay comfortably tappable rather than cramped side by side. */
@media (max-width: 380px) {
  .deadline-controls {
    flex-direction: column;
  }

  .deadline-presets,
  .buffer-control {
    flex-basis: 100%;
  }
}

.deadline-controls input {
  font-size: 1rem;
  padding: 0.5rem;
  min-height: 44px;
  border: 1px solid #ccc;
  border-radius: 8px;
}

.deadline-presets {
  border: 0;
  margin: 0;
  padding: 0;
}

.deadline-presets legend {
  font: inherit;
  padding: 0;
  margin: 0 0 0.5rem;
}

.preset-buttons {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}

.preset-btn {
  min-height: 48px;
  background: #fff;
  color: #1a5d1a;
  border: 2px solid #1a5d1a;
  font-weight: 600;
}

.preset-btn:hover {
  background: #e6f4ea;
}

.preset-btn.selected {
  background: #1a5d1a;
  color: #fff;
}

.sunset-status {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
  color: #666;
}

.alarm-banner {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  text-align: center;
}

/* No background here any more — the state colour now lives on body (see
   body.state-* above). These set only the message/countdown text colour. */
.alarm-banner.state-green {
  color: #1a5d1a;
}

.alarm-banner.state-amber {
  color: #8a5a00;
}

.alarm-banner.state-red {
  color: #a33;
}

.alarm-message {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.alarm-countdown {
  margin: 0.25rem 0 0;
  font-size: 1.4rem;
  font-weight: 700;
}

.alarm-stale-notice {
  margin: 0.25rem 0 0;
  font-size: 0.85rem;
  font-style: italic;
  opacity: 0.8;
}

#install-btn {
  margin-bottom: 0.75rem;
}

.ios-install-hint {
  margin: 0 0 0.75rem;
  padding: 0.5rem 0.75rem;
  background: #f0f0f0;
  border-radius: 8px;
  font-size: 0.85rem;
  color: #444;
  text-align: center;
}

.offline-banner {
  margin: 0 0 0.75rem;
  padding: 0.75rem 1rem;
  background: #fff4e0;
  color: #8a5a00;
  border-radius: 8px;
  text-align: center;
}

.intro {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  color: #444;
  text-align: center;
}

.app-error {
  margin: 0 0 0.75rem;
  padding: 0.75rem 1rem;
  background: #fdeaea;
  color: #a33;
  border-radius: 8px;
  text-align: center;
}

.route-caveat {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
  color: #666;
  text-align: center;
}

.share-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.share-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  border: 1px solid #ddd;
  border-radius: 50%;
  background: transparent;
  color: #666;
}

.share-btn:hover {
  background: #f0f0f0;
  color: #1a5d1a;
}

.share-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.share-status {
  flex-basis: 100%;
  margin: 0.25rem 0 0;
  font-size: 0.8rem;
  color: #1a5d1a;
  text-align: center;
  min-height: 1rem;
}

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