/* Unified page navigation: three round buttons (home, magazine, map), used on
   the home page (horizontal row, labels), and on the map and magazine
   (vertical column in the top-left). Self-contained: it does not depend on
   styles.css, so the home page can load it on its own.
   Spec: PLAN.md, "Unified Navigation". */

.main-nav {
  --nav-size: 54px;
  --nav-black: rgba(0, 0, 0, 0.88);
  --nav-line: rgba(255, 255, 255, 0.14);
  z-index: 30;
}

.main-nav.nav-col {
  display: grid;
  gap: 0.75rem;
}

.main-nav.nav-row {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(2.3rem + env(safe-area-inset-bottom, 0px));
  z-index: 4;
  display: flex;
  justify-content: center;
  gap: 1.6rem;
}

.nav-item {
  position: relative;
  width: var(--nav-size);
  height: var(--nav-size);
}

.nav-row .nav-item {
  height: auto;
}

.nav-btn {
  box-sizing: border-box;
  display: grid;
  place-items: center;
  width: var(--nav-size);
  height: var(--nav-size);
  padding: 0;
  border: 1px solid var(--nav-line);
  border-radius: 999px;
  background: var(--nav-black);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: blur(16px);
  transition: background 0.2s, color 0.2s, transform 0.15s;
}

a.nav-btn:hover,
a.nav-btn:focus-visible {
  background: #1b1f27;
}

.nav-btn:active {
  transform: scale(0.97);
}

.nav-btn:focus-visible,
.nav-chevron:focus-visible,
.nav-sat:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 3px;
}

.nav-item.is-active .nav-btn {
  border-color: transparent;
  background: #fff;
  color: #000;
}

.nav-icon {
  display: block;
  width: 31px;
  height: 31px;
  background: currentColor;
  mask: var(--nav-ic) center / contain no-repeat;
  -webkit-mask: var(--nav-ic) center / contain no-repeat;
}

.nav-icon-home { --nav-ic: url("./packages/client/assets/icons/navigation/nav-home.svg"); }
/* The magazine button is a tear-off calendar leaf with today's date (inline SVG, filled in by nav.js). */
.nav-live { display: block; width: 31px; height: 31px; overflow: visible; }
.nav-live .nav-cal-day { font-family: -apple-system, "Helvetica Neue", "Segoe UI", Arial, sans-serif; }
.nav-icon-map { --nav-ic: url("./packages/client/assets/icons/navigation/nav-map.svg"); }
.nav-icon-tag { --nav-ic: url("./packages/client/assets/icons/navigation/nav-tag.svg"); }
.nav-icon-route { --nav-ic: url("./packages/client/assets/icons/navigation/route.svg"); }
.nav-icon-chevron { --nav-ic: url("./packages/client/assets/icons/navigation/nav-chevron.svg"); }

/* Text labels: only in the horizontal row (home page). */
.nav-label {
  display: none;
}

.nav-row .nav-label {
  display: block;
  margin-top: 0.5rem;
  width: calc(var(--nav-size) + 1.6rem);
  margin-left: -0.8rem;
  color: #fff;
  font: 650 0.72rem/1 system-ui, -apple-system, "Segoe UI", sans-serif;
  letter-spacing: 0.08em;
  text-align: center;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.7);
}

/* The About / legend toggle: a small chevron on the active button only. */
.nav-chevron {
  position: absolute;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  background: none;
  color: #fff;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.2s ease;
}

.nav-chevron .nav-icon {
  width: 14px;
  height: 14px;
}

/* Hit area: about 54 px square, shifted away from the neighbouring buttons. */
.nav-chevron::after {
  content: "";
  position: absolute;
  inset: -16px;
}

.nav-col .nav-chevron {
  left: calc(100% + 1px);
  bottom: -1px;
  transform: rotate(35deg);
}

.nav-col .nav-chevron::after {
  inset: -16px -18px -10px -6px;
}

.nav-col .nav-chevron[aria-expanded="true"] {
  transform: rotate(215deg);
}

.nav-row .nav-chevron {
  top: -22px;
  right: -5px;
  transform: rotate(-55deg);
}

.nav-row .nav-chevron::after {
  inset: -18px -16px -6px -16px;
}

.nav-row .nav-chevron[aria-expanded="true"] {
  transform: rotate(125deg);
}

/* Selection state: a small bubble half over the corner of the active button. */
.nav-sat {
  position: absolute;
  z-index: 3;
  top: -5px;
  right: -5px;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: #000;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.5);
}

.nav-sat[hidden] {
  display: none;
}

.nav-sat .nav-icon {
  width: 13px;
  height: 13px;
}

.nav-sat::after {
  content: "";
  position: absolute;
  inset: -14px;
}

.nav-row .nav-sat {
  right: auto;
  left: -5px;
}

/* A short note when a shared link arrives with a selection. */
.nav-toast {
  position: fixed;
  z-index: 40;
  top: calc(0.9rem + env(safe-area-inset-top, 0px));
  left: calc(0.85rem + env(safe-area-inset-left, 0px) + 54px + 18px);
  max-width: min(70vw, 320px);
  padding: 0.55rem 0.8rem;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.88);
  color: #fff;
  font: 600 0.82rem/1.3 system-ui, -apple-system, "Segoe UI", sans-serif;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
}

.nav-toast.show {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.nav-toast button {
  margin-left: 0.5rem;
  padding: 0;
  border: 0;
  background: none;
  color: #fff;
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

@media (min-width: 970px), (min-width: 780px) and (orientation: landscape) {
  .nav-toast {
    top: calc(1.2rem + env(safe-area-inset-top, 0px));
    left: calc(1.2rem + env(safe-area-inset-left, 0px) + 54px + 18px);
  }
}

/* The hint: the chevron drifts towards the selected button and back, then
   rests in the closest position. It repeats (a single drift) whenever the
   pointer hovers the button. Uses the individual `translate` property so it
   composes with the rotation. --nx / --ny is the closest position. */
.nav-col .nav-chevron { --nx: -5px; --ny: -3px; }
.nav-row .nav-chevron { --nx: -3px; --ny: 5px; }

@keyframes nav-nudge-intro {
  0%, 100% { translate: 0 0; }
  50% { translate: var(--nx) var(--ny); }
}

@keyframes nav-nudge-hover {
  0%, 100% { translate: var(--nx) var(--ny); }
  50% { translate: 0 0; }
}

/* 2.5 cycles: away, near, away, near, away, near -- and it stays near */
.nav-chevron.nudge {
  animation: nav-nudge-intro 2.2s ease-in-out 2.5 forwards;
}

.nav-chevron.nudge-hover {
  animation: nav-nudge-hover 1.6s ease-in-out 1;
}

.nav-chevron.settled {
  translate: var(--nx) var(--ny);
}

@media (prefers-reduced-motion: reduce) {
  .nav-chevron.nudge,
  .nav-chevron.nudge-hover { animation: none; }
  .nav-chevron,
  .nav-btn,
  .nav-toast { transition: none; }
}
