:root {
  --bg-red: #e03e2d;
  --bg-red-dark: #c6281c;
  --bg-dark: #0b0f14;
  --gold: #f5dd6c;
  --text: #ffffff;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; user-select: none; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg-red);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  height: 100dvh;
  overflow: hidden;
}

body.dark-mode { background: var(--bg-dark); }

.app-shell {
  max-width: 520px;
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}

.view { flex: 1; display: none; flex-direction: column; overflow: hidden; position: relative; }
.view.active { display: flex; }

/* ================= TAB 1: LA BÀN (CHUẨN ẢNH 2 & 3) ================= */
.lb-header {
  background: var(--bg-red-dark);
  padding: max(10px, env(safe-area-inset-top)) 14px 10px;
  display: flex; align-items: center; justify-content: space-between;
  font-size: 16px; font-weight: 700; letter-spacing: 0.4px;
}

.lb-body {
  flex: 1;
  background: var(--bg-red);
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: 10px 12px 12px; position: relative;
}

.lb-top-tools { width: 100%; display: flex; align-items: flex-start; justify-content: space-between; }
.bubble-box { width: 48px; height: 48px; display: flex; align-items: center; justify-content: center; }
.bubble-cross {
  width: 40px; height: 40px; border-radius: 50%; border: 1.5px solid rgba(255,255,255,0.85);
  position: relative; display: flex; align-items: center; justify-content: center;
}
.bubble-cross::before, .bubble-cross::after { content: ""; position: absolute; background: rgba(255,255,255,0.65); }
.bubble-cross::before { width: 48px; height: 1px; }
.bubble-cross::after { height: 48px; width: 1px; }
.bubble-dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: #84cc16; border: 1.5px solid #ecfccb;
  box-shadow: 0 0 6px rgba(132, 204, 22, 0.85);
}

.lb-center-readout { text-align: center; flex: 1; padding: 0 6px; }
.lb-huong-text { font-size: 14.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.3px; margin-bottom: 6px; }
.lb-deg-pill {
  display: inline-flex; flex-direction: column; align-items: center;
  background: rgba(255, 255, 255, 0.24); border-radius: 12px; padding: 5px 26px 6px;
  cursor: pointer; backdrop-filter: blur(4px);
}
.lb-deg-pill.locked { background: rgba(0, 0, 0, 0.42); border: 1px solid rgba(255,255,255,0.5); }
.lb-lock-icon { font-size: 12px; margin-bottom: 1px; }
.lb-deg-val { font-size: 25px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.lb-pointer-tri {
  width: 0; height: 0; border-left: 7px solid transparent; border-right: 7px solid transparent;
  border-bottom: 10px solid #fff; margin: 5px auto 0;
}

.icon-circle-btn {
  width: 44px; height: 44px; border-radius: 50%; border: none;
  background: rgba(255, 255, 255, 0.22); color: #fff; font-size: 18px;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}

.compass-wrap {
  position: relative; width: min(88vw, 392px); aspect-ratio: 1 / 1;
  display: flex; align-items: center; justify-content: center; touch-action: none;
  filter: drop-shadow(0 8px 20px rgba(0,0,0,0.28));
}
.compass-rotator { width: 100%; height: 100%; will-change: transform; }
.crosshair-svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

.lb-bottom-readout { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.lb-toa-center { text-align: center; flex: 1; }
.lb-toa-deg { font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; }
.lb-toa-name { font-size: 13.5px; font-weight: 600; text-transform: uppercase; margin-top: 2px; }
.lb-3ban-mini { font-size: 11px; margin-top: 3px; color: #fef08a; font-weight: 600; }

.sensor-bar { display: flex; gap: 8px; align-items: center; justify-content: center; width: 100%; margin-top: 2px; }
.sensor-btn {
  border: none; border-radius: 999px; background: #fff; color: var(--bg-red-dark);
  font-size: 12px; font-weight: 700; padding: 6px 15px; cursor: pointer;
}
.sensor-btn.active { background: #16a34a; color: #fff; }
.mini-btn {
  border: 1px solid rgba(255,255,255,0.45); border-radius: 999px;
  background: rgba(0,0,0,0.18); color: #fff; font-size: 11.5px; font-weight: 600;
  padding: 5px 12px; cursor: pointer;
}

/* ================= TAB 2: LẬP CỰC (CHUẨN ẢNH 1 & 5) ================= */
.lc-container { flex: 1; background: #0b0f14; display: flex; flex-direction: column; position: relative; overflow: hidden; }

.lc-topbar {
  padding: max(8px, env(safe-area-inset-top)) 10px 8px;
  background: #274c77;
  display: flex; align-items: center; justify-content: space-between; gap: 8px; z-index: 30;
}

.lc-top-btn {
  border: none; border-radius: 999px; padding: 7px 14px;
  font-size: 12.5px; font-weight: 700; cursor: pointer;
  display: inline-flex; align-items: center; gap: 5px;
}
.lc-btn-picker { background: rgba(0,0,0,0.35); color: #fff; }
.lc-btn-save { background: #0284c7; color: #fff; }

.sat-search-bar {
  display: none; padding: 6px 10px; background: rgba(15, 20, 28, 0.94);
  border-bottom: 1px solid #232d3b; gap: 6px; align-items: center; z-index: 25;
}
.sat-search-bar.show { display: flex; }
.sat-input {
  flex: 1; background: #1e293b; border: 1px solid #334155; color: #fff;
  border-radius: 8px; padding: 7px 10px; font-size: 13px; user-select: text;
}
.sat-btn { border: none; background: #d97706; color: #fff; border-radius: 8px; padding: 7px 12px; font-size: 12px; font-weight: 700; cursor: pointer; }
.sat-gps-btn { border: 1px solid #334155; background: #1e293b; color: #fff; border-radius: 8px; padding: 7px 10px; font-size: 13px; cursor: pointer; }

.lc-stage { flex: 1; position: relative; overflow: hidden; background: #11161d; touch-action: none; }
#satMap { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 1; display: none; }
#satMap.show { display: block; }

.fp-layer { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; z-index: 2; }
.fp-layer.hidden { display: none; }
.fp-img { max-width: 92%; max-height: 92%; transform-origin: center center; will-change: transform; }

.lc-luopan-wrap {
  position: absolute; width: 340px; height: 340px; left: 50%; top: 50%;
  transform: translate(-50%, -50%); pointer-events: none; z-index: 10;
}
.lc-luopan-rotator { width: 100%; height: 100%; will-change: transform; }

/* Thanh Chữ T nét mảnh đỏ giao tại tâm (chuẩn ảnh 1 ff2ffad2.png) */
.tsquare-wrap {
  position: absolute; width: 340px; height: 340px; left: 50%; top: 50%;
  transform: translate(-50%, -50%); pointer-events: none; z-index: 12;
}
.tsquare-rotator { width: 100%; height: 100%; position: relative; will-change: transform; }
.tsquare-svg { width: 100%; height: 100%; overflow: visible; }
.tsquare-handle-hit { pointer-events: auto; cursor: grab; }

.lc-hud-badges {
  position: absolute; top: 10px; left: 10px; right: 10px;
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  z-index: 15; pointer-events: none;
}
.t-badge-chip {
  background: rgba(220, 38, 38, 0.92); color: #fff; font-size: 13px; font-weight: 800;
  padding: 5px 12px; border-radius: 999px; border: 1.2px solid rgba(255,255,255,0.5);
  font-variant-numeric: tabular-nums; box-shadow: 0 2px 8px rgba(0,0,0,0.35);
}
.lc-deg-badge-bar { display: flex; align-items: center; gap: 4px; pointer-events: auto; }
.round-adj-btn {
  width: 28px; height: 28px; border-radius: 50%; border: 1.2px solid rgba(255,255,255,0.55);
  background: rgba(220, 38, 38, 0.92); color: #fff; font-size: 16px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.lc-deg-chip {
  display: inline-flex; align-items: center; gap: 3px;
  background: rgba(15, 23, 42, 0.88); color: #f5dd6c; font-size: 12px; font-weight: 700;
  padding: 4px 9px; border-radius: 999px; border: 1px solid rgba(245, 221, 108, 0.55);
  font-variant-numeric: tabular-nums; pointer-events: auto;
}
.lc-deg-input {
  width: 48px; background: transparent; border: none; border-bottom: 1px solid rgba(245, 221, 108, 0.5);
  color: #ffffff; font-size: 13px; font-weight: 800; text-align: center; outline: none; user-select: text;
  font-variant-numeric: tabular-nums; padding: 0 2px;
}

.lc-dock {
  background: rgba(15, 20, 28, 0.98); border-top: 1px solid #232d3b;
  padding: 8px 10px; display: flex; flex-direction: column; gap: 8px; z-index: 20;
}
.lc-main-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.action-btn {
  border: 1px solid #334155; background: #1e293b; color: #f8fafc;
  font-size: 11.5px; font-weight: 700; padding: 8px 4px; border-radius: 10px;
  cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.action-btn.active { border-color: #f59e0b; background: rgba(245, 158, 11, 0.2); color: #fde68a; }
.action-btn.primary { background: #0284c7; color: #fff; border-color: #38bdf8; }

.lc-sliders { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }
.mini-slider { display: flex; align-items: center; gap: 6px; font-size: 11px; color: #cbd5e1; }
.mini-slider input { width: 100%; accent-color: var(--gold); }

/* ================= MODAL CHỌN THƯỚC ================= */
.ruler-modal { position: absolute; inset: 0; background: rgba(0,0,0,0.65); z-index: 50; display: none; align-items: flex-end; justify-content: center; }
.ruler-modal.open { display: flex; }
.ruler-sheet { width: 100%; background: #ffffff; color: #0f172a; border-top-left-radius: 18px; border-top-right-radius: 18px; padding: 14px 16px 24px; max-height: 78dvh; overflow-y: auto; }
.sheet-header { display: flex; align-items: center; justify-content: space-between; padding-bottom: 10px; border-bottom: 1px solid #e2e8f0; margin-bottom: 8px; font-size: 15px; font-weight: 700; }
.ruler-option { display: flex; align-items: center; gap: 12px; padding: 10px 6px; border-bottom: 1px solid #f1f5f9; cursor: pointer; }
.ruler-option-icon { width: 48px; height: 48px; border-radius: 50%; border: 1.5px solid #cbd5e1; background: #f8fafc; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 800; color: #b91c1c; flex-shrink: 0; }
.ruler-option-info { flex: 1; }
.ruler-option-title { font-size: 15px; font-weight: 700; color: #0f172a; }
.ruler-option-desc { font-size: 12px; color: #64748b; margin-top: 2px; }
.ruler-check { font-size: 18px; color: #16a34a; font-weight: 800; }

/* ================= TAB 3: CAMERA ================= */
.cam-container { flex: 1; background: #000; position: relative; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.cam-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cam-overlay { position: relative; z-index: 2; width: min(86vw, 370px); aspect-ratio: 1/1; pointer-events: none; }
.cam-hud { position: absolute; top: max(12px, env(safe-area-inset-top)); left: 12px; right: 12px; z-index: 3; display: flex; justify-content: space-between; align-items: center; }
.cam-deg-box { background: rgba(0,0,0,0.65); border: 1px solid rgba(255,255,255,0.3); padding: 6px 14px; border-radius: 10px; font-size: 15px; font-weight: 700; }

/* ================= BOTTOM NAV ================= */
.bottom-nav {
  background: #ffffff; color: #64748b; display: grid; grid-template-columns: repeat(3, 1fr);
  padding: 6px 4px max(6px, env(safe-area-inset-bottom)); border-top: 1px solid #e2e8f0; z-index: 40;
}
.nav-item {
  border: none; background: transparent; color: #64748b;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; font-weight: 600; padding: 4px 0; cursor: pointer;
}
.nav-item .nav-ico { font-size: 18px; line-height: 1.1; }
.nav-item.active { color: #e03e2d; font-weight: 700; }

/* ================= BẢN GỌN: nút trùng đã bỏ, thêm chip, thông báo, gợi ý vệ tinh ================= */
.chip-btn {
  border: 1px solid rgba(255,255,255,0.5); border-radius: 999px; background: rgba(0,0,0,0.2);
  color: #fef08a; font-size: 12.5px; font-weight: 700; padding: 5px 12px; cursor: pointer; min-width: 78px;
}
.head-badge { font-size: 12px; color: #fef08a; min-width: 78px; text-align: right; }
.lc-top-spacer { min-width: 96px; }
.lb-bottom-readout { justify-content: center; }
.sensor-bar { gap: 10px; }
.sensor-bar .sensor-btn { font-size: 13.5px; padding: 9px 22px; }
.sensor-btn.ghost { background: rgba(0,0,0,0.22); color: #fff; border: 1px solid rgba(255,255,255,0.5); }

.toast {
  position: absolute; left: 12px; right: 12px; bottom: calc(64px + env(safe-area-inset-bottom));
  background: rgba(15, 23, 42, 0.94); color: #f8fafc; border: 1px solid rgba(255,255,255,0.18);
  border-radius: 12px; padding: 10px 14px; font-size: 13px; line-height: 1.4; z-index: 60;
  opacity: 0; transform: translateY(8px); pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: none; }

.sat-hint {
  position: absolute; left: 10px; bottom: 10px; max-width: calc(100% - 20px); z-index: 14;
  background: rgba(15, 23, 42, 0.82); color: #fde68a; font-size: 11.5px; font-weight: 600;
  padding: 5px 10px; border-radius: 999px; display: none; pointer-events: none;
}
.sat-hint.show { display: block; }
