:root {
  --bg: #0b1220;
  --panel: #122035;
  --panel-2: #182842;
  --text: #edf4ff;
  --muted: #9fb1c8;
  --line: #2e4364;
  --accent: #49d39b;
  --danger: #ff6b6b;
  --pin: #ffd166;
  --shadow: rgba(0, 0, 0, 0.28);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  display: flex;
  flex-direction: column;
}

[hidden] { display: none !important; }

button,
input {
  font: inherit;
}

button,
.file-button {
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  background: var(--panel-2);
  color: var(--text);
  min-height: 2.2rem;
  padding: 0.48rem 0.68rem;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}

.file-button.primary {
  border-color: rgba(73, 211, 155, 0.75);
  background: rgba(73, 211, 155, 0.14);
}

button.active,
button:hover,
.file-button:hover {
  border-color: var(--accent);
}

button.active {
  background: rgba(73, 211, 155, 0.18);
}

button.danger {
  border-color: rgba(255, 107, 107, 0.65);
}

button.ghost {
  border-radius: 50%;
  width: 2.25rem;
  min-width: 2.25rem;
  padding: 0;
}

.file-button input {
  display: none;
}

.app-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: 3.2rem;
  padding: calc(env(safe-area-inset-top) + 0.32rem) 0.75rem 0.32rem;
  background: rgba(13, 24, 41, 0.96);
  border-bottom: 1px solid var(--line);
}

.header-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 0.45rem;
}

.install-button {
  border-color: rgba(73, 211, 155, 0.75);
  background: rgba(73, 211, 155, 0.16);
}

.app-header h1 {
  font-size: 1rem;
  margin: 0;
  letter-spacing: 0.02em;
}

.app-header p {
  margin: 0.08rem 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  max-width: min(72rem, calc(100vw - 5rem));
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-shell {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
}

.toolbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 0.42rem;
  overflow-x: auto;
  padding: 0.42rem 0.75rem;
  border-bottom: 1px solid var(--line);
  background: rgba(18, 32, 53, 0.92);
  -webkit-overflow-scrolling: touch;
}

.map-panel {
  position: relative;
  min-width: 0;
  min-height: 0;
  background:
    linear-gradient(45deg, rgba(255,255,255,0.035) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255,255,255,0.035) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255,255,255,0.035) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255,255,255,0.035) 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  touch-action: none;
}

#mapCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}

#crosshair {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1rem;
  height: 1rem;
  transform: translate(-50%, -50%);
  pointer-events: none;
  opacity: 0.35;
}

#crosshair::before,
#crosshair::after {
  content: "";
  position: absolute;
  background: var(--text);
}

#crosshair::before {
  left: 50%;
  top: 0;
  width: 1px;
  height: 100%;
}

#crosshair::after {
  left: 0;
  top: 50%;
  width: 100%;
  height: 1px;
}

#crosshair.high-visibility {
  width: 3rem;
  height: 3rem;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 2px #000, inset 0 0 0 2px #000;
  opacity: 1;
}

#crosshair.high-visibility::before {
  left: calc(50% - 1.5px);
  width: 3px;
  background: #fff;
  box-shadow: -2px 0 0 #000, 2px 0 0 #000;
}

#crosshair.high-visibility::after {
  top: calc(50% - 1.5px);
  height: 3px;
  background: #fff;
  box-shadow: 0 -2px 0 #000, 0 2px 0 #000;
}

.empty-state {
  position: absolute;
  inset: auto 1rem 1rem 1rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: rgba(11, 18, 32, 0.86);
  box-shadow: 0 0.75rem 2rem var(--shadow);
}

.empty-state strong,
.empty-state span {
  display: block;
}

.empty-state span {
  margin-top: 0.35rem;
  color: var(--muted);
  line-height: 1.35;
}

.calibration-overlay {
  position: absolute;
  z-index: 20;
  right: max(0.75rem, env(safe-area-inset-right));
  bottom: max(0.75rem, env(safe-area-inset-bottom));
  width: min(29rem, calc(100% - 1.5rem));
  max-height: min(62vh, 34rem);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: rgba(18, 32, 53, 0.96);
  box-shadow: 0 1rem 2.5rem var(--shadow);
  backdrop-filter: blur(8px);
  padding: 0.85rem;
}

.calibration-overlay h2 {
  margin: 0 0 0.55rem;
  font-size: 0.98rem;
}

.calibration-overlay p {
  color: var(--muted);
  margin: 0 0 0.65rem;
  line-height: 1.35;
  font-size: 0.86rem;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

.field-grid label {
  color: var(--muted);
  font-size: 0.82rem;
}

.field-grid input {
  width: 100%;
  min-height: 2.25rem;
  margin-top: 0.25rem;
  border: 1px solid var(--line);
  border-radius: 0.65rem;
  background: rgba(0, 0, 0, 0.18);
  color: var(--text);
  padding: 0.45rem 0.55rem;
}

.button-row {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.button-stack {
  display: grid;
  gap: 0.55rem;
}

.pin-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.pin-list li {
  display: grid;
  gap: 0.22rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid rgba(46, 67, 100, 0.65);
}

.pin-list span {
  color: var(--muted);
  font-size: 0.82rem;
}

.pin-list button {
  justify-self: start;
  min-height: 1.8rem;
  padding: 0.28rem 0.52rem;
  font-size: 0.82rem;
}

.check-list {
  display: grid;
  gap: 0.5rem;
  margin: 0.85rem 0;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 0.62rem;
  padding: 0.62rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 0.72rem;
  background: rgba(0, 0, 0, 0.14);
  cursor: pointer;
}

.check-row input {
  width: 1.05rem;
  height: 1.05rem;
  flex: 0 0 auto;
}

.check-row span,
.check-row strong,
.check-row small {
  display: block;
}

.check-row small {
  margin-top: 0.12rem;
  color: var(--muted);
  font-size: 0.8rem;
}


.navigation-overlay {
  position: absolute;
  z-index: 24;
  left: max(0.75rem, env(safe-area-inset-left));
  top: max(0.75rem, env(safe-area-inset-top));
  width: min(22rem, calc(100% - 1.5rem));
  max-height: min(76vh, 36rem);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: rgba(18, 32, 53, 0.96);
  box-shadow: 0 1rem 2.5rem var(--shadow);
  backdrop-filter: blur(8px);
  padding: 0.85rem;
  pointer-events: auto;
}

.nav-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.7rem;
}

.nav-title {
  min-width: 0;
  flex: 1 1 auto;
}

.nav-actions {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  flex: 0 0 auto;
}

.nav-actions button {
  min-height: 2rem;
  padding: 0.35rem 0.55rem;
  font-size: 0.86rem;
}

.nav-header small,
.nav-header strong {
  display: block;
}

.nav-header small {
  color: var(--muted);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
}

.nav-header strong {
  margin-top: 0.12rem;
  max-width: 13rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-compass-wrap {
  display: grid;
  place-items: center;
  margin: 0.72rem 0;
}

.nav-compass {
  position: relative;
  width: 8.8rem;
  height: 8.8rem;
  border: 2px solid rgba(237, 244, 255, 0.55);
  border-radius: 50%;
  background:
    radial-gradient(circle at center, rgba(73, 211, 155, 0.14), transparent 56%),
    rgba(0, 0, 0, 0.16);
  transform: rotate(0deg);
  transform-origin: 50% 50%;
  transition: transform 0.12s linear;
}

.nav-compass::before,
.nav-compass::after {
  content: "";
  position: absolute;
  background: rgba(237, 244, 255, 0.2);
}

.nav-compass::before {
  left: 50%;
  top: 0.6rem;
  width: 1px;
  height: calc(100% - 1.2rem);
}

.nav-compass::after {
  top: 50%;
  left: 0.6rem;
  width: calc(100% - 1.2rem);
  height: 1px;
}

.nav-compass span {
  position: absolute;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.78rem;
}

.nav-compass.north-up-fallback .nav-n {
  color: var(--accent);
}

.nav-n { left: 50%; top: 0.32rem; transform: translateX(-50%); }
.nav-e { right: 0.42rem; top: 50%; transform: translateY(-50%); }
.nav-s { left: 50%; bottom: 0.32rem; transform: translateX(-50%); }
.nav-w { left: 0.42rem; top: 50%; transform: translateY(-50%); }

.nav-arrow {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1.8rem;
  height: 4.15rem;
  transform: translate(-50%, -72%) rotate(0deg);
  transform-origin: 50% 72%;
  transition: transform 0.12s linear;
  z-index: 2;
}

.nav-arrow::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  transform: translateX(-50%);
  border-left: 0.9rem solid transparent;
  border-right: 0.9rem solid transparent;
  border-bottom: 2.1rem solid var(--accent);
}

.nav-arrow::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 1.9rem;
  width: 0.34rem;
  height: 2.25rem;
  border-radius: 999px;
  transform: translateX(-50%);
  background: var(--accent);
}

.nav-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.46rem;
  margin: 0;
}

.nav-metrics div {
  border: 1px solid rgba(46, 67, 100, 0.78);
  border-radius: 0.72rem;
  padding: 0.48rem 0.55rem;
  background: rgba(0, 0, 0, 0.14);
}

.nav-metrics dt {
  color: var(--muted);
  font-size: 0.72rem;
}

.nav-metrics dd {
  margin: 0.12rem 0 0;
  font-weight: 700;
}

#navHint {
  margin: 0.68rem 0 0;
  color: var(--muted);
  line-height: 1.35;
  font-size: 0.84rem;
}

.pdf-point-list {
  display: grid;
  gap: 0.55rem;
  margin: 0.85rem 0;
  max-height: min(46vh, 24rem);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.pdf-point-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.62rem;
  align-items: flex-start;
  padding: 0.62rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 0.72rem;
  background: rgba(0, 0, 0, 0.14);
  cursor: pointer;
}

.pdf-point-row input {
  width: 1.05rem;
  height: 1.05rem;
  margin-top: 0.12rem;
}

.pdf-point-row strong,
.pdf-point-row span,
.pdf-point-row small {
  display: block;
}

.pdf-point-row strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pdf-point-row span {
  margin-top: 0.14rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.pdf-point-row small {
  margin-top: 0.18rem;
  color: var(--muted);
  font-size: 0.76rem;
}

.pdf-point-empty,
.small-note {
  color: var(--muted);
  line-height: 1.4;
  font-size: 0.86rem;
}

.goto-list {
  display: grid;
  gap: 0.5rem;
  margin: 0.85rem 0;
}

.goto-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.65rem;
  padding: 0.62rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 0.72rem;
  background: rgba(0, 0, 0, 0.14);
}

.goto-row strong,
.goto-row span {
  display: block;
}

.goto-row strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.goto-row span {
  margin-top: 0.15rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.goto-empty {
  color: var(--muted);
  line-height: 1.4;
}

dialog {
  max-width: min(34rem, calc(100vw - 2rem));
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 1rem 3rem var(--shadow);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

dialog h2 {
  margin-top: 0;
}

dialog p,
dialog li {
  color: var(--muted);
  line-height: 1.45;
}

@media (max-width: 900px) {
  .toolbar {
    padding-left: max(0.55rem, env(safe-area-inset-left));
    padding-right: max(0.55rem, env(safe-area-inset-right));
  }

  .calibration-overlay {
    left: max(0.55rem, env(safe-area-inset-left));
    right: max(0.55rem, env(safe-area-inset-right));
    bottom: max(0.55rem, env(safe-area-inset-bottom));
    width: auto;
    max-height: 56vh;
  }
}

@media (max-width: 720px) {
  .app-header {
    min-height: 3rem;
    padding-top: calc(env(safe-area-inset-top) + 0.25rem);
    padding-bottom: 0.25rem;
  }

  .app-header p {
    max-width: calc(100vw - 9rem);
  }

  .toolbar {
    padding-top: 0.34rem;
    padding-bottom: 0.34rem;
    gap: 0.36rem;
  }

  button,
  .file-button {
    min-height: 2.75rem;
    padding: 0.55rem 0.65rem;
    border-radius: 0.62rem;
    font-size: 0.9rem;
  }

  .calibration-overlay {
    max-height: 52vh;
  }

  .navigation-overlay {
    left: max(0.55rem, env(safe-area-inset-left));
    right: max(0.55rem, env(safe-area-inset-right));
    top: max(0.55rem, env(safe-area-inset-top));
    width: auto;
    max-height: 56vh;
  }

  .nav-compass {
    width: 7.8rem;
    height: 7.8rem;
  }
}


@media (orientation: landscape) and (max-height: 520px) {
  .app-header {
    min-height: 2.7rem;
  }

  .app-header p {
    display: none;
  }

  .toolbar {
    padding-top: 0.26rem;
    padding-bottom: 0.26rem;
  }

  button,
  .file-button {
    min-height: 2.5rem;
    padding-top: 0.34rem;
    padding-bottom: 0.34rem;
  }

  .calibration-overlay {
    max-height: 72vh;
  }

  .navigation-overlay {
    max-height: 72vh;
  }
}



/* Compact Go to navigation panel: keep the compass/arrow visible and recover screen space. */
.navigation-overlay.minimized {
  right: auto;
  width: auto;
  max-width: none;
  max-height: none;
  overflow: visible;
  padding: 0.42rem;
  border-radius: 999rem;
}

.navigation-overlay.minimized .nav-header {
  position: absolute;
  z-index: 4;
  top: 0.28rem;
  right: 0.28rem;
  display: block;
}

.navigation-overlay.minimized .nav-title,
.navigation-overlay.minimized #stopNavButton,
.navigation-overlay.minimized .nav-metrics,
.navigation-overlay.minimized #navHint {
  display: none;
}

.navigation-overlay.minimized .nav-actions {
  display: block;
}

.navigation-overlay.minimized #toggleNavPanelButton {
  min-height: 1.55rem;
  padding: 0.16rem 0.42rem;
  border-radius: 999rem;
  background: rgba(18, 32, 53, 0.9);
  font-size: 0.72rem;
  line-height: 1;
}

.navigation-overlay.minimized .nav-compass-wrap {
  margin: 0;
}

.navigation-overlay.minimized .nav-compass {
  width: 7.3rem;
  height: 7.3rem;
}
