/* =========================================================================
   TERRAIN — پنل توپوگرافی: کانواس تمام‌صفحه + خوانش‌های فنی روی آن
   ========================================================================= */

.panel--terrain {
  background: var(--ink-950);
  touch-action: pan-y;
}

/* تصویر منبع فقط برای استخراج خطوط تراز است و دیده نمی‌شود */
.terrain__src {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.terrain__canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* لایه‌ی نوشته‌ها و نشانه‌ها */
.terrain__hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  color: var(--text-muted);
  opacity: clamp(0, calc(var(--terrain-in, 1) * 1.6), 1);
}

.terrain__hud-center {
  position: absolute;
  left: 50%;
  top: clamp(16px, 2.8vh, 28px);
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 22px;
  background: rgba(3, 7, 13, 0.94);
  border: 1px solid rgba(240, 163, 46, 0.35);
  border-radius: var(--radius-sm);
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.9);
  pointer-events: none;
  z-index: 5;
}

.terrain__hud-center::before,
.terrain__hud-center::after {
  content: '';
  position: absolute;
  width: 7px;
  height: 7px;
  border: 2px solid var(--accent-bright);
}

.terrain__hud-center::before {
  top: -2px;
  left: -2px;
  border-right: none;
  border-bottom: none;
}

.terrain__hud-center::after {
  bottom: -2px;
  right: -2px;
  border-left: none;
  border-top: none;
}

.terrain__watermark {
  font-family: var(--font-display);
  font-size: clamp(1.2rem, 1.8vw, 1.45rem);
  letter-spacing: 0;
  font-weight: 800;
  color: var(--accent-bright);
  text-shadow: 0 0 16px rgba(241, 169, 56, 0.55);
  direction: rtl;
  line-height: 1.3;
}

.terrain__subcode {
  font-size: 0.75rem;
  color: var(--text-muted);
  letter-spacing: 0.12em;
}

.terrain__hud-tl,
.terrain__hud-tr {
  position: absolute;
  display: flex;
  flex-direction: column;
  gap: 6px;
  top: clamp(16px, 2.8vh, 28px);
  padding: 12px 18px;
  background: rgba(3, 7, 13, 0.94);
  border: 1px solid rgba(240, 163, 46, 0.35);
  border-radius: var(--radius-sm);
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.9);
}

.terrain__hud-tl {
  /* موقعیت فیزیکی (نه منطقی): در مرجع، مختصات همیشه سمت چپ کادر است */
  left: var(--gutter);
}

.terrain__hud-tr {
  /* مطلق می‌ماند (نه relative) وگرنه از کادر بیرون می‌افتد؛ گوشه‌های
     تزئینی هم همچنان نسبت به همین بلوک جای می‌گیرند. */
  position: absolute;
  right: var(--gutter);
  align-items: flex-end;
}

.terrain__hud-tr::before,
.terrain__hud-tr::after {
  content: '';
  position: absolute;
  width: 8px;
  height: 8px;
  border: 2px solid var(--accent-bright);
}

.terrain__hud-tr::before {
  top: -2px;
  left: -2px;
  border-right: none;
  border-bottom: none;
}

.terrain__hud-tr::after {
  bottom: -2px;
  right: -2px;
  border-left: none;
  border-top: none;
}

/* نوار پیمایش و اسکن بالا-چپ */
.terrain__meter {
  display: block;
  width: 120px;
  height: 4px;
  background: rgba(163, 163, 155, 0.15);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 4px;
}

.terrain__meter i {
  display: block;
  height: 100%;
  width: 100%;
  transform: scaleX(var(--terrain-p, 0));
  transform-origin: left;
  background: var(--accent-bright);
  box-shadow: 0 0 12px rgba(246, 186, 88, 0.9);
  will-change: transform;
}

/* نوارهای عمودی لبه — مقیاس نردبانی ارتفاع */
.terrain__scale {
  position: absolute;
  top: 20%;
  bottom: 20%;
  width: 16px;
  background: repeating-linear-gradient(
    to bottom,
    rgba(240, 163, 46, 0.55) 0,
    rgba(240, 163, 46, 0.55) 1px,
    transparent 1px,
    transparent 12px
  );
  border-inline-start: 1px solid rgba(240, 163, 46, 0.35);
  pointer-events: none;
}

.terrain__scale::after {
  content: '';
  position: absolute;
  inset-inline-start: -5px;
  width: 22px;
  height: 3px;
  top: calc(var(--terrain-p, 0) * (100% - 3px));
  background: var(--accent-bright);
  box-shadow: 0 0 14px rgba(246, 186, 88, 1);
}

.terrain__scale--start {
  inset-inline-start: calc(var(--gutter) * 0.4);
}

.terrain__scale--end {
  inset-inline-end: calc(var(--gutter) * 0.4);
}

/* نشانه‌های نقطه‌ای روی زمین — به کانواس سه‌بعدی واگذار شد تا با دوربین همگام بماند */
.terrain__pin {
  display: none;
}

.terrain__pin-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-bright);
  box-shadow: 0 0 14px rgba(246, 186, 88, 0.9);
}

.terrain__pin-ring {
  position: absolute;
  width: 42px;
  height: 42px;
  border: 1px solid var(--border-accent);
  border-radius: 50%;
  animation: pin-pulse 3.4s var(--ease-out) infinite;
}

.terrain__pin-label {
  position: absolute;
  top: 14px;
  left: 14px;
  white-space: nowrap;
  color: var(--accent);
  opacity: 0.95;
}

.terrain__pin-label::before {
  content: '';
  position: absolute;
  right: 100%;
  top: 50%;
  width: 16px;
  height: 1px;
  background: var(--border-accent);
}

@keyframes pin-pulse {
  0% {
    transform: scale(0.5);
    opacity: 0;
  }
  40% {
    opacity: 0.85;
  }
  100% {
    transform: scale(1.55);
    opacity: 0;
  }
}

/* قطب‌نماها */
.terrain__compass {
  position: absolute;
  bottom: clamp(22px, 5vh, 54px);
  display: grid;
  place-items: center;
  gap: 4px;
  color: var(--accent);
  opacity: 0.8;
}

.terrain__compass--end {
  right: calc(var(--gutter) + 18px);
}

.terrain__needle {
  transform-origin: 32px 32px;
  transform: rotate(calc(var(--terrain-p, 0) * 32deg));
}

/* توضیح کوتاه پایین صحنه */
.terrain__caption {
  position: absolute;
  inset-inline: 0;
  bottom: clamp(26px, 6vh, 62px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding-inline: var(--gutter);
  max-width: none;
  text-align: center;
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

@media (prefers-reduced-motion: reduce) {
  .terrain__pin,
  .terrain__needle {
    transform: none !important;
  }
  .terrain__pin-ring {
    animation: none;
    opacity: 0.45;
  }
}

/* حالت پشته‌ای */
@media (max-width: 900px), (prefers-reduced-motion: reduce) {
  .panel--terrain {
    min-height: clamp(520px, 86svh, 740px);
    overflow: hidden;
    touch-action: pan-y;
  }

  .terrain__canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    touch-action: pan-y;
    pointer-events: none;
  }

  .terrain__compass--end,
  .terrain__scale {
    display: none;
  }
}
