/* ============ Compass · Style ============ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-1: #020a0e;
  --bg-2: #051a23;
  --bg-3: #0a2a35;
  --teal:    #14b8a6;
  --teal-2:  #5eead4;
  --teal-3:  #99f6e4;
  --sky:     #0ea5e9;
  --gold:    #fbbf24;
  --red:     #f43f5e;
  --green:   #22c55e;
  --text:    #e6fffa;
  --muted:   rgba(230,255,250,.55);
  --faint:   rgba(230,255,250,.32);
  --safe-top: env(safe-area-inset-top, 0);
  --safe-bot: env(safe-area-inset-bottom, 0);
}

html, body {
  background: var(--bg-1);
  color: var(--text);
  font-family: 'Heebo', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
body {
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
  padding-top: calc(58px + var(--safe-top));
  padding-bottom: calc(28px + var(--safe-bot));
}

/* Ambient teal background */
.ambient-bg {
  position: fixed;
  inset: 0;
  z-index: -3;
  overflow: hidden;
  background: var(--bg-1);
}
.orb-blur {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: .35;
  pointer-events: none;
  will-change: transform;
}
.orb-blur.o1 {
  width: 60vmax; height: 60vmax;
  background: radial-gradient(circle, var(--teal) 0%, transparent 60%);
  top: -20vh; left: -10vw;
  animation: drift1 26s ease-in-out infinite;
}
.orb-blur.o2 {
  width: 55vmax; height: 55vmax;
  background: radial-gradient(circle, var(--sky) 0%, transparent 60%);
  bottom: -20vh; right: -10vw;
  animation: drift2 32s ease-in-out infinite;
  opacity: .3;
}
@keyframes drift1 {
  0%, 100% { transform: translate(0,0) scale(1); }
  50%      { transform: translate(6vw, 5vh) scale(1.06); }
}
@keyframes drift2 {
  0%, 100% { transform: translate(0,0) scale(1); }
  50%      { transform: translate(-5vw, -6vh) scale(.94); }
}
.ambient-bg .grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(94,234,212,.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(94,234,212,.04) 1px, transparent 1px);
  background-size: 60px 60px;
  mask-image: radial-gradient(ellipse 70% 60% at 50% 50%, #000 30%, transparent 80%);
  -webkit-mask-image: radial-gradient(ellipse 70% 60% at 50% 50%, #000 30%, transparent 80%);
}

/* Top bar */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: calc(58px + var(--safe-top));
  padding-top: var(--safe-top);
  padding-inline: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(2,10,14,.78);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  border-bottom: 1px solid rgba(94,234,212,.12);
  z-index: 100;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .mark {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--teal), var(--sky));
  position: relative;
  box-shadow: 0 6px 18px rgba(20,184,166,.55);
}
.brand .mark::before {
  content: '';
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  background: var(--bg-1);
}
.brand .mark::after {
  content: 'N';
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--red);
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 700;
  font-size: 12px;
}
.brand span:not(.mark) {
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.02em;
}
.header-actions { display: flex; gap: 8px; }
.icon-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid rgba(94,234,212,.18);
  background: rgba(94,234,212,.06);
  color: var(--text);
  cursor: pointer;
  display: grid; place-items: center;
  font-size: 16px;
  transition: background .2s, transform .15s;
}
.icon-btn:hover { background: rgba(94,234,212,.15); }
.icon-btn:active { transform: scale(.92); }
.install-btn {
  background: linear-gradient(135deg, var(--teal), var(--teal-2));
  color: var(--bg-1);
  border: none;
  padding: 8px 16px;
  border-radius: 999px;
  font-family: inherit;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(20,184,166,.5);
}
.hidden { display: none !important; }

main { padding: 16px 18px; max-width: 480px; margin: 0 auto; }
.panel { animation: fade .35s cubic-bezier(.2,.9,.3,1.05); }
@keyframes fade { from{opacity:0; transform:translateY(8px);} to{opacity:1; transform:translateY(0);} }

/* Permission / Desktop */
.perm-panel, .desktop-panel { text-align: center; padding: 60px 22px; margin-top: 30px; }
.perm-icon { font-size: 56px; margin-bottom: 20px; filter: drop-shadow(0 0 20px rgba(20,184,166,.4)); }
.perm-panel h2, .desktop-panel h2 { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; margin-bottom: 10px; }
.perm-panel p, .desktop-panel p { color: var(--muted); font-size: 14px; margin-bottom: 24px; line-height: 1.7; }
.perm-panel strong { color: var(--teal-2); }
.url-box {
  background: rgba(20,184,166,.10);
  border: 1px solid rgba(20,184,166,.35);
  border-radius: 12px;
  padding: 14px 18px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  direction: ltr;
  color: var(--teal-2);
}

/* Status line */
.status-line {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 18px;
}
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--faint);
  transition: background .3s, box-shadow .3s;
}
.status-line.active .status-dot {
  background: var(--teal-2);
  box-shadow: 0 0 12px var(--teal-2);
  animation: dot-pulse 2s ease-in-out infinite;
}
.status-line.aligned .status-dot {
  background: var(--green);
  box-shadow: 0 0 12px var(--green);
  animation: none;
}
@keyframes dot-pulse { 50% { opacity: .4; } }

/* Compass stage */
.compass-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 8px auto 22px;
  position: relative;
}
.compass-wrap {
  width: 320px; height: 320px;
  max-width: 86vw;
  max-height: 86vw;
  position: relative;
}
.compass-dial {
  width: 100%; height: 100%;
  /* Dial rotates with -heading so N stays at top */
  transition: transform .25s cubic-bezier(.34, 1.16, .64, 1);
  will-change: transform;
}
#needleGroup, #waypointPointer {
  transition: transform .35s cubic-bezier(.34, 1.16, .64, 1);
  transform-box: fill-box;
}
.cardinal {
  font-family: 'Heebo', sans-serif;
  font-weight: 700;
  font-size: 22px;
  fill: var(--teal-3);
  letter-spacing: 0.05em;
}
.cardinal.n { fill: var(--red); }

/* Tick marks (added by JS) */
.tick {
  stroke: rgba(94,234,212,.35);
  stroke-width: 1;
}
.tick.major { stroke: rgba(94,234,212,.7); stroke-width: 1.5; }

/* Heading display in center */
.heading-display {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.heading-value {
  font-size: 64px;
  font-weight: 200;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  color: var(--teal-2);
  text-shadow: 0 0 30px rgba(20,184,166,0.35);
  margin-top: 28px;
}
.heading-direction {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 14px;
  letter-spacing: 4px;
  color: var(--muted);
  margin-top: -2px;
}

/* Waypoint info */
.waypoint-info {
  background: rgba(251,191,36,.06);
  border: 1px solid rgba(251,191,36,.28);
  border-radius: 16px;
  padding: 14px 18px;
  margin-bottom: 14px;
}
.waypoint-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
}
.wp-label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10px;
  letter-spacing: 2px;
  color: var(--faint);
  text-transform: uppercase;
}
.wp-name { font-weight: 600; font-size: 14px; color: var(--gold); }
.wp-value {
  font-weight: 600;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  color: var(--gold);
}

/* Actions */
.actions { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.btn-primary {
  width: 100%;
  padding: 16px;
  background: linear-gradient(135deg, var(--teal), var(--teal-2));
  color: var(--bg-1);
  border: none;
  border-radius: 14px;
  font-family: inherit;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  box-shadow: 0 14px 30px -8px rgba(20,184,166,.5);
  transition: transform .15s;
}
.btn-primary:active { transform: scale(.97); }
.btn-mini {
  padding: 12px;
  background: rgba(94,234,212,.06);
  border: 1px solid rgba(94,234,212,.18);
  color: var(--text);
  font-family: inherit;
  font-weight: 600;
  font-size: 13px;
  border-radius: 12px;
  cursor: pointer;
  transition: background .2s;
}
.btn-mini:hover { background: rgba(94,234,212,.12); }
.btn-secondary {
  padding: 13px;
  background: rgba(244,63,94,.08);
  border: 1px solid rgba(244,63,94,.28);
  color: var(--red);
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  border-radius: 12px;
  cursor: pointer;
}
.btn-secondary:hover { background: rgba(244,63,94,.14); }

/* Coords row */
.coords-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}
.coord {
  background: rgba(94,234,212,.04);
  border: 1px solid rgba(94,234,212,.10);
  border-radius: 12px;
  padding: 12px 8px;
  text-align: center;
}
.coord .label {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  letter-spacing: 2px;
  color: var(--faint);
  margin-bottom: 4px;
}
.coord .value {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  font-weight: 500;
}

/* Modal */
.modal {
  position: fixed; inset: 0;
  background: rgba(2,10,14,.78);
  backdrop-filter: blur(8px);
  z-index: 200;
  display: grid;
  place-items: end center;
  animation: modal-in .25s ease;
}
@keyframes modal-in { from{opacity:0;} to{opacity:1;} }
.modal-card {
  background: rgba(5,26,35,.95);
  backdrop-filter: blur(18px) saturate(160%);
  border: 1px solid rgba(94,234,212,.20);
  border-top-left-radius: 28px;
  border-top-right-radius: 28px;
  padding: 24px 22px calc(28px + var(--safe-bot));
  width: 100%;
  max-width: 480px;
  animation: sheet-up .35s cubic-bezier(.2,.9,.3,1.05);
}
@keyframes sheet-up { from{transform:translateY(100%);} to{transform:translateY(0);} }
.modal-card .handle { width: 38px; height: 4px; background: rgba(94,234,212,.30); border-radius: 2px; margin: -8px auto 16px; }
.modal-card h3 { font-size: 20px; font-weight: 800; letter-spacing: -0.02em; margin-bottom: 6px; }
.modal-card p { color: var(--muted); font-size: 13px; margin-bottom: 18px; line-height: 1.7; }
.modal-card p strong { color: var(--teal-2); }
.mark-big {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--teal), var(--sky));
  margin: 0 auto 14px;
  position: relative;
  box-shadow: 0 10px 30px rgba(20,184,166,.55);
}
.mark-big::before {
  content: '';
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  background: var(--bg-1);
}
.mark-big::after {
  content: 'N';
  position: absolute;
  inset: 0;
  display: grid; place-items: center;
  color: var(--red);
  font-weight: 700;
  font-family: 'IBM Plex Mono', monospace;
}
.modal-input {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid rgba(94,234,212,.18);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 12px;
  font-family: inherit;
  font-size: 15px;
  margin-bottom: 14px;
}
.modal-input:focus { outline: 2px solid var(--teal); outline-offset: 2px; }
.modal-summary {
  background: rgba(94,234,212,.05);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  text-align: center;
}
.modal-summary .stat-mini {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  color: var(--teal-2);
}
.modal-summary .stat-mini .k {
  display: block;
  font-size: 9px;
  letter-spacing: 1.5px;
  color: var(--faint);
  margin-top: 4px;
  font-weight: 500;
}
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* Waypoints list */
.waypoints-list { max-height: 50vh; overflow-y: auto; }
.wp-item {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  background: rgba(94,234,212,.05);
  border: 1px solid rgba(94,234,212,.12);
  border-radius: 12px;
  margin-bottom: 8px;
}
.wp-item.active {
  background: rgba(251,191,36,.08);
  border-color: rgba(251,191,36,.35);
}
.wp-item .pin {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: rgba(20,184,166,.18);
  display: grid; place-items: center;
  font-size: 20px;
}
.wp-item.active .pin {
  background: rgba(251,191,36,.18);
  box-shadow: 0 0 12px rgba(251,191,36,.4);
}
.wp-item .info .name { font-weight: 600; font-size: 14px; }
.wp-item .info .meta {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}
.wp-actions { display: flex; flex-direction: column; gap: 4px; }
.wp-actions button {
  background: transparent;
  border: 1px solid rgba(94,234,212,.18);
  color: var(--muted);
  padding: 5px 9px;
  border-radius: 8px;
  font-size: 11px;
  cursor: pointer;
  font-family: inherit;
}
.wp-actions button.go { color: var(--teal-2); border-color: rgba(94,234,212,.4); }
.wp-actions button.del:hover { color: var(--red); border-color: rgba(244,63,94,.4); background: rgba(244,63,94,.08); }
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}
.empty-state .ico { font-size: 40px; margin-bottom: 12px; opacity: .5; }

/* Toast */
.toast {
  position: fixed;
  top: calc(70px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(5,26,35,.96);
  border: 1px solid rgba(94,234,212,.30);
  color: var(--text);
  padding: 10px 22px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  z-index: 300;
  box-shadow: 0 18px 40px rgba(0,0,0,.5);
  backdrop-filter: blur(10px);
  animation: toast-in .25s ease;
}
@keyframes toast-in { from{opacity:0; transform:translate(-50%, -16px);} to{opacity:1; transform:translate(-50%, 0);} }
.toast.success { color: var(--green); border-color: rgba(34,197,94,.5); }
.toast.error { color: var(--red); border-color: rgba(244,63,94,.5); }
