:root {
  --bg: #000000;
  --panel: #0a0a0a;
  --panel-line: #262626;
  --ink: #e8e8e8;
  --ink-dim: #8a8a8a;
  --amber: #ffb000;
  --amber-dim: #7a5600;
  --danger: #ff4d4d;
  --safe: #4dff88;
  --tap-min: 44px;
  --font-display: 'Bahnschrift', 'DIN Alternate', 'Arial Narrow', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Roboto Mono', ui-monospace, monospace;
}

/* Night mode: whole app shifts to red/amber monochrome to protect night vision */
:root.night-mode {
  --bg: #000000;
  --panel: #0a0000;
  --panel-line: #3a0000;
  --ink: #ff5533;
  --ink-dim: #7a2a1a;
  --amber: #ff3300;
  --amber-dim: #661400;
  --danger: #ff5533;
  --safe: #ff5533;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-display);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overflow: hidden;
}

button {
  font-family: inherit;
  background: none;
  border: 1px solid var(--panel-line);
  color: var(--ink);
  border-radius: 4px;
  min-height: var(--tap-min);
  padding: 8px 12px;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
}
button:active { background: var(--panel-line); }
button.primary { color: var(--amber); border-color: var(--amber-dim); }
button.active { background: var(--amber-dim); color: var(--amber); border-color: var(--amber); }

input, select {
  font-family: var(--font-mono);
  background: var(--panel);
  border: 1px solid var(--panel-line);
  color: var(--ink);
  border-radius: 4px;
  padding: 8px;
  min-height: var(--tap-min);
  font-size: 1rem;
}

/* ---------- Top status bar ---------- */
#status-bar {
  display: flex;
  justify-content: space-between;
  padding: 6px 12px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--ink-dim);
  border-bottom: 1px solid var(--panel-line);
  flex: 0 0 auto;
}
#status-bar span.warn { color: var(--danger); }
#status-bar span.ok { color: var(--safe); }
/* ---------- Main view switcher ---------- */
#views {
  flex: 1 1 auto;
  position: relative;
  overflow: hidden;
}
.view {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  overflow-y: auto;
}
.view.active { display: flex; }

/* ---------- Compass view ---------- */
#compass-stage {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  min-height: 0;
}
.compass-corner-btn {
  position: absolute;
  top: 6px;
  z-index: 5;
  font-size: 0.72rem;
  padding: 6px 10px;
  min-height: 34px;
}
.compass-corner-tl { left: 6px; }
.compass-corner-tr { right: 6px; }
#bearing-toggle, #compass-mark-waypoint { color: var(--amber); border-color: var(--amber-dim); }
#compass-rose-wrap {
  width: min(80vw, 60vh, 420px);
  height: min(80vw, 60vh, 420px);
  max-width: 100%;
  max-height: 100%;
  position: relative;
}
#compass-rose {
  width: 100%;
  height: 100%;
  transition: transform 0.1s linear;
  will-change: transform;
}
#level-crosshair {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
#level-crosshair svg { width: 36px; height: 36px; }
#level-crosshair.level .crosshair-mark { stroke: var(--amber); }
.crosshair-mark { stroke: var(--ink); stroke-width: 2; transition: stroke 0.15s; }

#bearing-readout {
  text-align: center;
  padding: 4px 0 10px;
  flex: 0 0 auto;
}
#bearing-value {
  font-size: 3rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}
#bearing-sub {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--ink-dim);
  margin-top: 2px;
}
#target-lock-info {
  margin-top: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
}
#target-lock-name { color: var(--amber); font-weight: 600; }
#target-lock-rename { font-size: 0.7rem; padding: 2px 6px; min-height: 26px; opacity: 0.75; }
#target-lock-text { color: var(--ink); }
#target-lock-clear { font-size: 0.7rem; padding: 4px 8px; min-height: 30px; }

/* ---------- Data drawer ---------- */
#data-drawer {
  flex: 0 0 auto;
  border-top: 1px solid var(--panel-line);
  padding: 8px 14px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 10px;
  transition: max-height 0.2s ease;
  overflow: hidden;
}
#data-drawer.collapsed { max-height: 0; padding-top: 0; padding-bottom: 0; border-top: none; }
.data-row { display: flex; justify-content: space-between; gap: 6px; }
.data-label { color: var(--ink-dim); }
.data-value { color: var(--ink); }
.data-row.full { grid-column: 1 / -1; }

#drawer-toggle-hit {
  flex: 0 0 auto;
  text-align: center;
  padding: 4px;
  color: var(--ink-dim);
  font-size: 0.7rem;
  letter-spacing: 0.15em;
}

/* ---------- Bottom nav ---------- */
.bottom-nav {
  flex: 0 0 auto;
  display: flex;
  border-top: 1px solid var(--panel-line);
}
.bottom-nav button {
  flex: 1;
  border: none;
  border-right: 1px solid var(--panel-line);
  border-radius: 0;
  font-size: 0.8rem;
  padding: 10px 4px;
}
.bottom-nav button:last-child { border-right: none; }
.bottom-nav button.active { color: var(--amber); }

/* ---------- Generic panel content ---------- */
.panel-content {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}
.panel-title {
  font-size: 1.1rem;
  color: var(--amber);
  margin: 0 0 12px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  font-size: 0.9rem;
}
.field-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--panel-line);
}
.field-row label { color: var(--ink-dim); font-size: 0.9rem; }
.button-row { display: flex; gap: 8px; margin: 10px 0; flex-wrap: wrap; }
.button-row-fit { flex-wrap: nowrap; }
.button-row-fit button { flex: 1 1 0; min-width: 0; font-size: 0.82rem; padding: 10px 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hint { color: var(--ink-dim); font-size: 0.78rem; line-height: 1.4; margin: 6px 0 14px; }

/* ---------- Sight/camera view ---------- */
#sight-video-wrap {
  position: relative;
  flex: 1;
  background: #000;
  overflow: hidden;
}
#sight-video { width: 100%; height: 100%; object-fit: cover; }

/* AR target overlay (current sighting target — always rendered on top of other markers) */
#sight-ar-target {
  position: absolute;
  z-index: 10;
  transform: translate(-50%, -100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  transition: left 0.15s linear, top 0.15s linear;
}
#sight-ar-markers {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}
#sight-ar-markers .ar-marker { pointer-events: auto; }
#sight-ar-markers .ar-marker.kind-scout { z-index: 4; }
#sight-ar-markers .ar-marker.kind-route { z-index: 3; }
#sight-ar-markers .ar-marker.kind-sightedpoi,
#sight-ar-markers .ar-marker.kind-fieldnote { z-index: 2; }
#sight-ar-markers .ar-marker.kind-waypoint { z-index: 1; }
#sight-ar-marker { color: #ff5533; font-size: 1.4rem; line-height: 1; text-shadow: 0 0 4px rgba(0,0,0,0.8); }
#sight-ar-label {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(0,0,0,0.6);
  color: #ff5533;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 2px 6px;
  border-radius: 4px;
  pointer-events: auto;
  white-space: nowrap;
}
#sight-ar-rename {
  border: none;
  min-height: 0;
  padding: 0 2px;
  font-size: 0.75rem;
  color: #ff5533;
  opacity: 0.7;
}
.sight-ar-edge {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  color: #ff5533;
  font-size: 1.6rem;
  text-shadow: 0 0 4px rgba(0,0,0,0.8);
  pointer-events: none;
}
#sight-ar-edge-left { left: 8px; }
#sight-ar-edge-right { right: 8px; }

#sight-reticle {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 90px;
  height: 90px;
  pointer-events: none;
}
#sight-reticle svg { width: 100%; height: 100%; }
#sight-live-bearing {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--amber);
  text-align: center;
  background: rgba(0,0,0,0.5);
  padding: 5px 6px;
  border-radius: 6px;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#sight-stability { font-size: 0.72rem; }
#sight-stability.steady { color: var(--safe); }
#sight-stability.unsteady { color: var(--danger); }
#sight-points-readout {
  position: absolute;
  top: 38px;
  left: 10px;
  right: 10px;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--ink-dim);
  text-align: center;
  letter-spacing: 0.08em;
}
.reticle-line { stroke: var(--amber); stroke-width: 2; opacity: 0.9; }
.reticle-ring { stroke: var(--amber); stroke-width: 1.5; fill: none; opacity: 0.9; }
.reticle-dot { fill: var(--amber); }
#sight-readout {
  position: absolute;
  bottom: 10px;
  left: 10px;
  right: 10px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  background: rgba(0,0,0,0.55);
  padding: 8px;
  border-radius: 6px;
  color: var(--amber);
}
.sight-readout-warning {
  color: #fff !important;
  background: rgba(180,40,20,0.85) !important;
  font-weight: 600;
}
#sight-controls {
  flex: 0 0 auto;
  padding: 10px;
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
}
#sight-controls button {
  flex: 1 1 0;
  min-width: 0;
  font-size: 0.8rem;
  padding: 10px 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Waypoint log ---------- */
.wpt-item {
  border-bottom: 1px solid var(--panel-line);
  padding: 10px 0;
  font-size: 0.85rem;
}
.wpt-item .wpt-name { color: var(--amber); }
.wpt-item .wpt-meta { color: var(--ink-dim); font-family: var(--font-mono); font-size: 0.75rem; }
.wpt-item .wpt-actions { margin-top: 4px; }
.wpt-item .wpt-actions button { font-size: 0.7rem; padding: 4px 8px; min-height: 32px; }
.wpt-kind {
  font-size: 0.62rem;
  color: var(--ink-dim);
  border: 1px solid var(--panel-line);
  border-radius: 3px;
  padding: 1px 4px;
  margin-left: 6px;
  letter-spacing: 0.05em;
}
.wpt-note { color: var(--ink); font-size: 0.82rem; margin-top: 4px; white-space: pre-wrap; }
.wpt-photo-slot:empty { display: none; }
.wpt-photo { max-width: 100%; max-height: 220px; border-radius: 6px; margin-top: 6px; display: block; }
.wpt-kind.kind-sightedpoi { color: #cc66ff; border-color: #cc66ff; }

/* ---------- Trip status (Route view) ---------- */
#trip-status-row { align-items: center; }
#trip-status-label { color: var(--ink); font-size: 0.85rem; }
#trip-status-row.active #trip-status-label { color: var(--amber); }

/* ---------- Trip history (Log view) ---------- */
.trip-item {
  border-bottom: 1px solid var(--panel-line);
  padding: 10px 0;
  font-size: 0.85rem;
}
.trip-item .trip-name { color: var(--amber); }
.trip-item .trip-meta { color: var(--ink-dim); font-family: var(--font-mono); font-size: 0.75rem; }
.trip-item .trip-actions { margin-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; }
.trip-item .trip-actions button { font-size: 0.68rem; padding: 4px 8px; min-height: 30px; }

/* ---------- Multi-marker AR overlay ---------- */
.ar-marker {
  position: absolute;
  transform: translate(-50%, -100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  transition: left 0.15s linear, top 0.15s linear;
}
.ar-marker-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid rgba(0,0,0,0.6);
}
.ar-marker-label {
  display: none;
  background: rgba(0,0,0,0.65);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  padding: 2px 6px;
  border-radius: 4px;
  white-space: nowrap;
  margin-bottom: 2px;
}
.ar-marker.expanded .ar-marker-label { display: block; }
.ar-marker.kind-route .ar-marker-dot { background: #00b0ff; }
.ar-marker.kind-route .ar-marker-label { color: #00b0ff; }
.ar-marker.kind-sightedpoi .ar-marker-dot { background: #cc66ff; }
.ar-marker.kind-sightedpoi .ar-marker-label { color: #cc66ff; }
.ar-marker.kind-waypoint .ar-marker-dot { background: #e8e8e8; }
.ar-marker.kind-waypoint .ar-marker-label { color: #e8e8e8; }
.ar-marker.kind-fieldnote .ar-marker-dot { background: #ffe83d; }
.ar-marker.kind-fieldnote .ar-marker-label { color: #ffe83d; }
.ar-marker.kind-scout .ar-marker-dot { background: #ffaa33; }
.ar-marker.kind-scout .ar-marker-label { color: #ffaa33; }

#log-filter-tabs { display: flex; gap: 4px; margin: 10px 0; }
#log-filter-tabs button { flex: 1; font-size: 0.62rem; padding: 8px 2px; }

/* ---------- Save-note modal (photo + note capture) ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-box {
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 10px;
  padding: 16px;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
}
#save-note-photo-wrap {
  background: #000;
  border-radius: 6px;
  min-height: 160px;
  max-width: 100%;
  width: 100%;
  margin: 0 auto 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
#save-note-photo-preview { width: 100%; display: block; }
#save-note-video { width: 100%; display: block; background: #000; }
#save-note-photo-buttons { justify-content: center; }
#save-note-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
#save-note-header .panel-title { margin: 0; padding-top: 4px; }
#save-note-header-actions { display: flex; gap: 6px; flex: 0 0 auto; }
#save-note-header-actions button { font-size: 0.78rem; padding: 8px 10px; min-height: 36px; }
#save-note-photo-placeholder { color: var(--ink-dim); font-size: 0.78rem; padding: 14px; text-align: center; }
#save-note-name, #modal-prompt-input {
  width: 100%;
  font-family: inherit;
  background: var(--bg);
  border: 1px solid var(--panel-line);
  color: var(--ink);
  border-radius: 6px;
  padding: 8px;
  font-size: 0.9rem;
  margin: 8px 0;
}
#save-note-text {
  width: 100%;
  font-family: inherit;
  background: var(--bg);
  border: 1px solid var(--panel-line);
  color: var(--ink);
  border-radius: 6px;
  padding: 8px;
  font-size: 0.9rem;
  resize: vertical;
  margin: 8px 0;
}
#modal-confirm-message, #modal-prompt-message {
  color: var(--ink-dim);
  font-size: 0.85rem;
  line-height: 1.4;
  margin: 6px 0 10px;
}
.danger-btn { color: var(--danger); border-color: var(--danger); }

/* ---------- Sensor-enable hint banner ---------- */
/* Shown briefly on launch only if the compass hasn't received a real
   orientation reading yet (see app.js selfHealSensors). Sits above
   everything but must never intercept the very tap it's asking for. */
.sensor-hint-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 70;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  background: rgba(120,80,0,0.92);
  color: var(--amber);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.sensor-hint-banner.visible { opacity: 1; transform: translateY(0); }

/* ---------- Toasts ---------- */
#toast-container {
  position: fixed;
  bottom: 90px;
  left: 0; right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  z-index: 60;
}
.toast {
  background: rgba(20,20,20,0.95);
  color: var(--ink);
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.82rem;
  max-width: 85vw;
  text-align: center;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.toast.visible { opacity: 1; transform: translateY(0); }

/* ---------- Sight buffer tabs (Target / Scout POI) ---------- */
#sight-buffer-tabs { display: flex; gap: 6px; padding: 8px 10px 0; flex: 0 0 auto; }
#sight-buffer-tabs button { flex: 1; font-size: 0.78rem; }
#scout-slot-picker { display: flex; gap: 6px; padding: 8px 10px 0; flex: 0 0 auto; }
.scout-slot-chip {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  padding: 8px 2px;
  position: relative;
}
.scout-slot-chip .chip-count { display: block; font-size: 0.62rem; color: var(--ink-dim); }
.scout-slot-chip.active { border-color: #ff5533; color: #ff5533; }
.scout-slot-chip.active .chip-count { color: #ff5533; }
.scout-slot-chip.full { color: var(--safe); border-color: var(--safe); }
#scout-rename { flex: 0 0 auto; padding: 8px 10px; font-size: 0.9rem; }

/* ---------- Map view ---------- */
#map-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  background: var(--bg);
}
#map-svg { width: 100%; height: 100%; max-width: 500px; max-height: 500px; }
.map-line-route { stroke: #00b0ff; stroke-width: 2; stroke-dasharray: 6,4; fill: none; }
.map-line-path { stroke: #33ffcc; stroke-width: 2; fill: none; }
.map-point { cursor: pointer; }
.map-point-me circle { fill: var(--amber); }
.map-point-target circle { fill: #ff5533; }
.map-point-scout circle { fill: #ffaa33; }
.map-point-route circle { fill: #00b0ff; }
.map-point-waypoint circle { fill: #3dd1ff; }
.map-point-sightedpoi circle { fill: #ff5533; }
.map-point-fieldnote circle { fill: #ffe83d; }
.map-label {
  font-family: var(--font-mono);
  font-size: 10px;
  fill: var(--ink);
  display: none;
}
.map-point.expanded .map-label { display: block; }
.map-north-arrow text, .map-scale-text { font-family: var(--font-mono); font-size: 10px; fill: var(--ink-dim); }
.map-north-arrow line { stroke: var(--ink-dim); stroke-width: 1.5; }
.map-scale-line { stroke: var(--ink-dim); stroke-width: 1.5; }

/* ---------- Route legs ---------- */
.leg-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--panel-line);
}
.leg-row.active-leg { color: var(--amber); }
#steer-indicator {
  text-align: center;
  padding: 20px 0;
  font-size: 1.4rem;
}
#steer-arrow { font-size: 3rem; display: block; }

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: var(--panel-line); }

/* ---------- Compass rose SVG theming (classes, not inline var() attrs) ---------- */
.rose-ring-outer { fill: none; stroke: var(--panel-line); stroke-width: 1.5; }
.rose-ring-inner { fill: none; stroke: var(--panel-line); stroke-width: 0.75; }
.rose-tick-cardinal { stroke: var(--amber); stroke-width: 2.5; }
.rose-tick-major { stroke: var(--ink-dim); stroke-width: 1.5; }
.rose-tick-minor { stroke: var(--ink-dim); stroke-width: 0.75; opacity: 0.6; }
.rose-label-cardinal { fill: var(--amber); font-size: 20px; font-family: var(--font-mono); font-weight: 700; }
.rose-label-minor { fill: var(--ink-dim); font-size: 11px; font-family: var(--font-mono); }
.rose-north-tri { fill: var(--amber); }
.rose-tn-line { stroke: var(--ink); stroke-width: 2; stroke-dasharray: 2,2; }
.rose-tn-label { fill: var(--ink); font-size: 10px; font-family: var(--font-mono); }
.rose-sun-dot { fill: var(--safe); }
.rose-sun-label { fill: var(--safe); font-size: 10px; font-family: var(--font-mono); }
.rose-target-tri { fill: #ff5533; }
.rose-target-line { stroke: #ff5533; stroke-width: 2; }
.rose-route-line { stroke: #00b0ff; stroke-width: 2; }
.rose-route-dot { fill: #00b0ff; }
.rose-route-label { fill: #00b0ff; font-size: 10px; font-family: var(--font-mono); }
.rose-route-line-prev { stroke: #00b0ff; stroke-width: 2; stroke-dasharray: 2,2; opacity: 0.7; }
.rose-route-dot-prev { fill: #00b0ff; opacity: 0.7; }
.rose-route-label-prev { fill: #00b0ff; font-size: 10px; font-family: var(--font-mono); opacity: 0.7; }
.rose-hub { fill: var(--ink-dim); }
.rose-lubber { stroke: var(--amber); stroke-width: 3; }

.reduced-motion #compass-rose { transition: none; }
@media (prefers-reduced-motion: reduce) {
  #compass-rose { transition: none; }
}
