/* 攀山拯救 Field Map V5 — iPhone-first field UI.
   Sunlight: high contrast, bold type. Night: dark chrome (prefers-color-scheme). Gloves: ≥52px targets. */
:root {
  --me: #1d6fe0;
  --target: #dc2626;
  --good: #16a34a;
  --moderate: #ca8a04;
  --poor: #ea580c;
  --bad: #dc2626;
  --stale: #6b7280;
  --surface: rgba(255, 255, 255, 0.97);
  --surface-2: #f3f4f6;
  --text: #0b1220;
  --text-2: #4b5563;
  --line: #d1d5db;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.22);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --sb-h: 52px;
  --fab: 62px;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang HK", "PingFang TC", "Heiti TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --surface: rgba(17, 24, 39, 0.96);
    --surface-2: #1f2937;
    --text: #f9fafb;
    --text-2: #cbd5e1;
    --line: #374151;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #111827; color: var(--text); font-family: var(--font); -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
[hidden] { display: none !important; }

#map { position: fixed; inset: 0; }

/* ---------------- Loading ---------------- */
.loading { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: #111827; color: #fff; transition: opacity .35s; }
.loading.done { opacity: 0; pointer-events: none; }
.loading-card { text-align: center; }
.loading-title { font-weight: 800; font-size: 20px; margin-top: 14px; }
.loading-msg { color: #cbd5e1; margin-top: 6px; }
.spinner { width: 40px; height: 40px; margin: 0 auto; border: 4px solid rgba(255,255,255,.25); border-top-color: #fff; border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.noscript { position: fixed; inset: 0; z-index: 200; background: #fff; color: #000; padding: 40px 20px; font-size: 18px; }

/* ---------------- Top stack: banner + target card ---------------- */
.top-stack { position: fixed; z-index: 20; top: calc(var(--safe-t) + 8px); left: calc(var(--safe-l) + 8px); right: calc(var(--safe-r) + 8px); display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.top-stack > * { pointer-events: auto; }
.banner { display: flex; align-items: center; gap: 5px; min-height: 42px; padding: 4px 5px 4px 10px; border-radius: 12px; background: #7f1d1d; color: #fff; font-weight: 700; font-size: 14px; box-shadow: var(--shadow); }
.banner[data-severity="warning"] { background: #9a3412; }
.banner[data-severity="info"] { background: #1e3a8a; }
.banner-text { flex: 1; line-height: 1.3; }
.banner-btn { min-width: 42px; min-height: 36px; border: 0; border-radius: 10px; background: rgba(255,255,255,.18); color: #fff; font-weight: 800; }

.target-card { display: flex; align-items: stretch; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); border-left: 6px solid var(--target); overflow: hidden; }
.tc-main { flex: 1; min-width: 0; text-align: left; border: 0; background: transparent; padding: 8px 10px 8px 10px; display: flex; flex-direction: column; gap: 2px; }
.tc-row1 { display: flex; align-items: center; gap: 8px; min-width: 0; }
.tc-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--target); flex: none; box-shadow: 0 0 0 2px #fff; }
.tc-label { font-weight: 800; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tc-grid { margin-left: auto; font-family: var(--mono); font-weight: 700; font-size: 14px; color: var(--text-2); white-space: nowrap; }
.tc-row2 { display: flex; align-items: center; gap: 10px; }
.tc-arrow { width: 44px; height: 44px; flex: none; display: grid; place-items: center; }
.tc-arrow svg { transition: transform .25s ease-out; will-change: transform; }
.tc-nums { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.tc-bearing { font-family: var(--mono); font-weight: 900; font-size: 24px; letter-spacing: -.5px; }
.tc-distance { font-weight: 900; font-size: 24px; color: var(--target); }
.tc-note { font-size: 13px; font-weight: 700; color: #b45309; }
.tc-guide { flex: none; width: 74px; padding: 0 4px; line-height: 1.15; border: 0; border-left: 1px solid var(--line); background: var(--surface-2); font-weight: 800; font-size: 14px; color: var(--target); }
.target-card.guiding { border-left-width: 8px; }
.target-card.guiding .tc-arrow { width: 54px; height: 54px; }
.target-card.guiding .tc-arrow svg { width: 54px; height: 54px; }
.target-card.guiding .tc-bearing, .target-card.guiding .tc-distance { font-size: 27px; }
.target-card.guiding .tc-guide { background: var(--target); color: #fff; }

/* ---------------- FABs ---------------- */
.fabs { position: fixed; z-index: 15; right: calc(var(--safe-r) + 12px); bottom: calc(var(--sb-h) + var(--safe-b) + 14px); display: flex; flex-direction: column; gap: 12px; }
.fab { width: var(--fab); height: var(--fab); border-radius: 18px; border: 0; background: var(--surface); box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; color: var(--text); }
.fab-icon { font-size: 26px; line-height: 1; font-weight: 700; }
.fab-label { font-size: 11px; font-weight: 800; white-space: nowrap; }
.fab.locate .fab-icon { color: var(--me); }
.fab.locate[data-mode="FOLLOW_NORTH"], .fab.locate[data-mode="FOLLOW_HEADING"] { background: var(--me); color: #fff; }
.fab.locate[data-mode="FOLLOW_NORTH"] .fab-icon, .fab.locate[data-mode="FOLLOW_HEADING"] .fab-icon { color: #fff; }
.fab.locate[data-mode="FOLLOW_HEADING"] { box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--me), var(--shadow); }
.fab.locate[data-mode="TARGET_GUIDANCE"] { background: var(--target); color: #fff; }
.fab.locate[data-mode="TARGET_GUIDANCE"] .fab-icon { color: #fff; }
.fab.target .fab-icon { color: var(--target); font-size: 30px; }
.fab.target.active { background: var(--target); color: #fff; }
.fab.target.active .fab-icon { color: #fff; }
.fab:active { transform: scale(.96); }

.north-btn { position: fixed; z-index: 15; right: calc(var(--safe-r) + 20px); bottom: calc(var(--sb-h) + var(--safe-b) + 14px + 3 * var(--fab) + 36px + 12px); width: 48px; height: 48px; border-radius: 50%; border: 0; background: var(--surface); box-shadow: var(--shadow); display: grid; place-items: center; }
.north-needle { display: flex; flex-direction: column; align-items: center; line-height: .9; color: var(--target); font-weight: 900; font-size: 16px; transition: transform .1s linear; }
.nn-n { font-size: 11px; color: var(--text); }

/* ---------------- Status bar ---------------- */
.status-bar { position: fixed; z-index: 16; left: 0; right: 0; bottom: 0; height: calc(var(--sb-h) + var(--safe-b)); padding: 0 calc(var(--safe-r) + 12px) var(--safe-b) calc(var(--safe-l) + 12px); display: flex; align-items: center; gap: 10px; border: 0; border-top: 1px solid var(--line); background: var(--surface); text-align: left; font-variant-numeric: tabular-nums; }
.sb-dot { width: 16px; height: 16px; border-radius: 50%; flex: none; box-shadow: 0 0 0 2px #fff, 0 0 0 3px rgba(0,0,0,.2); }
.sb-dot.good { background: var(--good); } .sb-dot.moderate { background: var(--moderate); } .sb-dot.poor { background: var(--poor); }
.sb-dot.bad { background: var(--bad); } .sb-dot.stale { background: var(--stale); animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.sb-acc { font-weight: 800; font-size: 15px; white-space: nowrap; }
.sb-grid { font-family: var(--mono); font-weight: 800; font-size: 16px; white-space: nowrap; margin-left: auto; }
.sb-grid.dim { color: var(--stale); text-decoration: line-through; text-decoration-thickness: 1px; }
.sb-heading { font-family: var(--mono); font-weight: 800; font-size: 15px; white-space: nowrap; }
.sb-heading.warn { color: var(--poor); font-family: var(--font); font-size: 13px; }
.sb-chip { font-size: 11px; font-weight: 900; padding: 3px 6px; border-radius: 6px; white-space: nowrap; }
.sb-chip.rec { background: var(--target); color: #fff; }
.sb-chip.net { background: #374151; color: #fff; }

/* MapLibre controls sit above the status bar */
.maplibregl-ctrl-bottom-left { bottom: calc(var(--sb-h) + var(--safe-b) + 4px) !important; left: var(--safe-l); }
.maplibregl-ctrl-bottom-right { bottom: calc(var(--sb-h) + var(--safe-b) + 4px) !important; }
.maplibregl-ctrl-scale { font-size: 11px; font-weight: 700; }

/* ---------------- Markers ---------------- */
.me-marker { width: 26px; height: 26px; position: relative; }
.me-dot { position: absolute; inset: 2px; border-radius: 50%; background: var(--me); border: 3px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.25), 0 2px 6px rgba(0,0,0,.45); }
.me-cone { position: absolute; left: -37px; top: -37px; width: 100px; height: 100px; border-radius: 50%; opacity: 0; background: conic-gradient(from -12deg, rgba(29,111,224,.55) 0deg 24deg, transparent 24deg); -webkit-mask: radial-gradient(circle, #000 0 48%, transparent 49%); mask: radial-gradient(circle, #000 0 48%, transparent 49%); transition: transform .15s linear; pointer-events: none; }
.me-marker.has-heading .me-cone { opacity: 1; }
.me-marker.poor .me-dot { background: #60a5fa; }
.me-marker.stale .me-dot { background: #9ca3af; border-style: dashed; }
.me-marker.unreliable .me-dot { background: #dc2626; border-style: dashed; }
.target-marker { width: 44px; height: 44px; position: relative; cursor: pointer; }
.tm-ring { position: absolute; inset: 0; border-radius: 50%; border: 4px solid var(--target); background: rgba(220,38,38,.12); box-shadow: 0 0 0 2px #fff, 0 2px 6px rgba(0,0,0,.35); }
.tm-ring::before, .tm-ring::after { content: ""; position: absolute; background: var(--target); }
.tm-ring::before { left: 50%; top: -10px; bottom: -10px; width: 3px; transform: translateX(-50%); }
.tm-ring::after { top: 50%; left: -10px; right: -10px; height: 3px; transform: translateY(-50%); }
.tm-dot { position: absolute; left: 50%; top: 50%; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; background: var(--target); box-shadow: 0 0 0 2px #fff; }
.tm-label { position: absolute; top: 50px; left: 50%; transform: translateX(-50%); background: var(--target); color: #fff; font-weight: 900; font-size: 12px; padding: 1px 7px; border-radius: 6px; white-space: nowrap; box-shadow: 0 0 0 1.5px #fff; }

/* ---------------- Crosshair placement ---------------- */
.crosshair { position: fixed; z-index: 12; left: 50%; top: 50%; width: 72px; height: 72px; margin: -36px 0 0 -36px; pointer-events: none; }
.crosshair::before, .crosshair::after { content: ""; position: absolute; background: var(--target); box-shadow: 0 0 0 1.5px #fff; }
.crosshair::before { left: 50%; top: 0; bottom: 0; width: 3px; transform: translateX(-50%); }
.crosshair::after { top: 50%; left: 0; right: 0; height: 3px; transform: translateY(-50%); }
.crosshair span { position: absolute; left: 50%; top: 50%; width: 30px; height: 30px; margin: -15px 0 0 -15px; border: 3px solid var(--target); border-radius: 50%; box-shadow: 0 0 0 1.5px #fff; }
.place-bar { position: fixed; z-index: 17; left: calc(var(--safe-l) + 8px); right: calc(var(--safe-r) + 8px); bottom: calc(var(--sb-h) + var(--safe-b) + 10px); background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px; }
.place-hint { font-size: 13px; color: var(--text-2); font-weight: 700; }
.place-readout { font-family: var(--mono); font-weight: 900; font-size: 19px; margin: 4px 0 8px; }
.place-actions { display: grid; grid-template-columns: 1fr 2fr; gap: 8px; }
body.placing .fabs { bottom: calc(var(--sb-h) + var(--safe-b) + 150px); }
body.placing .fab:not(.target) { display: none; }

/* ---------------- Toast ---------------- */
.toast { position: fixed; z-index: 60; left: calc(var(--safe-l) + 12px); right: calc(var(--safe-r) + 90px); bottom: calc(var(--sb-h) + var(--safe-b) + 16px); padding: 12px 14px; border-radius: 12px; background: rgba(17,24,39,.94); color: #fff; font-weight: 700; font-size: 15px; opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s; pointer-events: none; }
.toast.show { opacity: 1; transform: none; }
body.placing .toast { bottom: calc(var(--sb-h) + var(--safe-b) + 160px); }
body.sheet-open .toast { top: calc(var(--safe-t) + 12px); bottom: auto; right: calc(var(--safe-r) + 12px); }

/* ---------------- Sheets ---------------- */
.sheet-overlay { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.38); display: flex; align-items: flex-end; }
.sheet { width: 100%; max-height: 88dvh; max-height: 88vh; display: flex; flex-direction: column; background: var(--surface); color: var(--text); border-radius: 18px 18px 0 0; box-shadow: 0 -4px 20px rgba(0,0,0,.3); padding-bottom: var(--safe-b); transform: translateY(12px); transition: transform .18s ease-out; }
@supports (height: 1dvh) { .sheet { max-height: 88dvh; } }
.sheet.short { max-height: 60vh; }
.sheet-overlay.open .sheet { transform: none; }
.sheet-head { position: relative; display: flex; align-items: center; gap: 8px; padding: 14px calc(var(--safe-r) + 8px) 8px calc(var(--safe-l) + 16px); border-bottom: 1px solid var(--line); touch-action: none; }
.sheet-head h2 { margin: 0; font-size: 18px; font-weight: 900; flex: 1; }
.handle { position: absolute; top: 5px; left: 50%; width: 40px; height: 5px; margin-left: -20px; border-radius: 3px; background: var(--line); }
.icon-btn { width: 52px; height: 48px; border: 0; border-radius: 12px; background: var(--surface-2); font-size: 26px; font-weight: 700; line-height: 1; }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 8px calc(var(--safe-r) + 16px) 20px calc(var(--safe-l) + 16px); overscroll-behavior: contain; }
.section { padding: 10px 0; border-bottom: 1px solid var(--line); }
.section:last-child { border-bottom: 0; }
.section-title { margin: 0 0 8px; font-size: 13px; font-weight: 900; color: var(--text-2); letter-spacing: .5px; }
.big-title { font-size: 21px; font-weight: 900; margin-top: 6px; }
.sub-title { font-size: 15px; color: var(--text-2); font-weight: 700; }
.big-grid { font-family: var(--mono); font-size: 26px; font-weight: 900; margin: 6px 0 2px; letter-spacing: -.5px; }
.kv { display: grid; grid-template-columns: minmax(96px, 34%) 1fr; gap: 7px 10px; margin: 0; font-size: 15px; }
.kv dt { color: var(--text-2); font-weight: 700; }
.kv dd { margin: 0; font-weight: 700; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.note { color: var(--text-2); font-size: 13px; line-height: 1.45; margin: 8px 0 0; }
.fine { color: var(--text-2); font-size: 12px; line-height: 1.45; margin: 6px 0; }
.warning { background: #fef3c7; color: #78350f; border-radius: 10px; padding: 10px 12px; font-size: 13px; font-weight: 700; line-height: 1.45; margin: 8px 0 0; }
.error { color: #b91c1c; font-weight: 800; font-size: 14px; margin: 8px 0; }
.hint { color: var(--text-2); font-size: 14px; margin: 8px 0; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 900; color: #fff; background: var(--stale); }
.pill.good { background: var(--good); } .pill.moderate { background: var(--moderate); } .pill.poor { background: var(--poor); } .pill.bad { background: var(--bad); }
.mono { font-family: var(--mono); font-size: 11px; white-space: pre-wrap; overflow-wrap: anywhere; background: var(--surface-2); padding: 8px; border-radius: 8px; }
details summary { font-weight: 800; min-height: 44px; display: flex; align-items: center; }

/* ---------------- Controls ---------------- */
.row { display: flex; gap: 8px; }
.input, .select { flex: 1; min-width: 0; min-height: 52px; padding: 0 12px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface-2); font-size: 17px; font-weight: 700; }
.select { width: 100%; }
.input:focus, .select:focus { outline: none; border-color: var(--me); }
.btn { min-height: 52px; padding: 0 14px; border-radius: 12px; border: 0; background: #111827; color: #fff; font-weight: 800; font-size: 15px; display: inline-flex; align-items: center; justify-content: center; text-align: center; text-decoration: none; line-height: 1.2; }
@media (prefers-color-scheme: dark) { .btn { background: #e5e7eb; color: #111827; } }
.btn.blue { background: var(--me); color: #fff; }
.btn.red { background: var(--target); color: #fff; }
.btn.green { background: var(--good); color: #fff; }
.btn.light { background: var(--surface-2); color: var(--text); border: 1.5px solid var(--line); }
.btn.outline { background: transparent; color: var(--text); border: 2px solid var(--line); }
.btn.danger { color: var(--target); border-color: var(--target); }
.btn.armed { background: var(--target) !important; color: #fff !important; }
.btn.wide { width: 100%; margin-top: 8px; }
.btn:disabled { opacity: .45; }
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn-row { display: flex; gap: 8px; margin-top: 8px; }
.linkish { border: 0; background: none; padding: 0; color: var(--me); font-weight: 800; text-decoration: underline; text-align: left; min-height: 32px; }
.results { margin-top: 6px; }
.r-group { margin: 12px 0 4px; font-size: 13px; color: var(--text-2); }
.result { width: 100%; min-height: 56px; display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto; align-items: center; column-gap: 8px; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: transparent; padding: 8px 2px; }
.r-title { font-weight: 900; font-size: 16px; }
.r-sub { grid-row: 2; color: var(--text-2); font-size: 13px; font-weight: 600; }
.r-extra { grid-row: 1 / span 2; grid-column: 2; font-weight: 800; color: var(--me); font-size: 14px; }
.switch-row { display: flex; align-items: center; gap: 12px; min-height: 60px; border-bottom: 1px solid var(--line); }
.switch-row:last-child { border-bottom: 0; }
.switch-text { flex: 1; display: flex; flex-direction: column; }
.switch-text span { color: var(--text-2); font-size: 12px; font-weight: 600; }
.switch { appearance: none; -webkit-appearance: none; width: 58px; height: 34px; border-radius: 17px; background: #9ca3af; position: relative; flex: none; transition: background .15s; margin: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 28px; height: 28px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.35); transition: transform .15s; }
.switch:checked { background: var(--good); }
.switch:checked::after { transform: translateX(24px); }
.track-stat { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 8px; text-align: center; }
.track-stat div { background: var(--surface-2); border-radius: 10px; padding: 8px 2px; display: flex; flex-direction: column; }
.track-stat strong { font-size: 16px; font-variant-numeric: tabular-nums; }
.track-stat span { font-size: 11px; color: var(--text-2); font-weight: 700; }
.copy-area { width: 100%; min-height: 180px; margin-top: 8px; border-radius: 10px; border: 2px solid var(--line); padding: 10px; font-family: var(--mono); font-size: 13px; background: var(--surface-2); }

@media (max-width: 360px) {
  :root { --fab: 58px; }
  .sb-acc { font-size: 14px; } .sb-grid { font-size: 14px; } .sb-heading { font-size: 13px; }
  .tc-bearing, .tc-distance { font-size: 21px; }
}
@media (orientation: landscape) and (max-height: 500px) {
  :root { --fab: 54px; --sb-h: 44px; }
  .fabs { flex-direction: row; }
  .north-btn { bottom: calc(var(--sb-h) + var(--safe-b) + 14px + var(--fab) + 12px); }
  .top-stack { right: calc(var(--safe-r) + 50%); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
