/* ── 3D Terrain Sandbox ─── terrain-3d.html ───────────── */
:root {
  --t3d-bg: #0a0f18;
  --t3d-panel: rgba(18, 25, 36, 0.92);
  --t3d-border: rgba(236, 233, 228, 0.12);
  --t3d-text: rgba(236, 233, 228, 0.85);
  --t3d-text-dim: rgba(236, 233, 228, 0.5);
  --t3d-accent: #e8a83e;
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--t3d-bg);
  font-family: "Noto Sans SC", sans-serif;
  color: var(--t3d-text);
}

/* ── Loading Screen ────────────────────────────────────── */
.terrain-loader {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--t3d-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.2rem;
  transition: opacity 0.6s ease;
}
.terrain-loader.hidden {
  opacity: 0;
  pointer-events: none;
}
.loader-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--t3d-text);
  letter-spacing: 0.05em;
}
.loader-bar-wrap {
  width: 240px;
  height: 4px;
  background: rgba(255,255,255,0.08);
  border-radius: 4px;
  overflow: hidden;
}
.loader-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--t3d-accent), #f0c75e);
  border-radius: 4px;
  transition: width 0.3s ease;
}
.loader-percent {
  font-size: 0.78rem;
  color: var(--t3d-text-dim);
  font-variant-numeric: tabular-nums;
}

/* ── Top Bar (mirrors explore-topbar dark variant) ─────── */
.terrain-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  z-index: 100;
  background: var(--t3d-panel);
  border-bottom: 1px solid var(--t3d-border);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}
.terrain-topbar-inner {
  width: min(1180px, calc(100vw - 24px));
  margin: 0 auto;
  height: 56px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 1rem;
}
.terrain-topbar .explore-logo {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  text-decoration: none;
  color: var(--t3d-text);
  flex-shrink: 0;
}
.terrain-topbar .explore-logo svg {
  width: 26px;
  height: 26px;
}
.terrain-topbar .explore-logo span {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.terrain-topbar .top-links {
  display: inline-flex;
  align-items: center;
  gap: 0.95rem;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.terrain-topbar .top-links::-webkit-scrollbar { display: none; }
.terrain-topbar .top-link {
  text-decoration: none;
  color: var(--t3d-text-dim);
  font-size: 0.84rem;
  white-space: nowrap;
  transition: color 180ms;
}
.terrain-topbar .top-link.active,
.terrain-topbar .top-link:hover {
  color: var(--t3d-text);
}
.terrain-topbar .top-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
.terrain-topbar .user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--t3d-border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--t3d-text-dim);
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color 200ms, transform 200ms, color 200ms;
  overflow: hidden;
  text-decoration: none;
}
.terrain-topbar .user-avatar:hover {
  color: var(--t3d-text);
  border-color: rgba(236, 233, 228, 0.3);
}
.terrain-topbar .avatar-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: 0.86rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: inherit;
}

/* ── Canvas Container ──────────────────────────────────── */
.terrain-canvas-wrap {
  position: fixed;
  inset: 0;
  top: 56px;
}
#terrain-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ── Back Button ───────────────────────────────────────── */
.back-to-2d {
  position: fixed;
  top: 72px;
  left: 1rem;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  background: var(--t3d-panel);
  border: 1px solid var(--t3d-border);
  border-radius: 10px;
  color: var(--t3d-text-dim);
  font-family: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  transition: color 200ms, border-color 200ms, background 200ms;
  text-decoration: none;
}
.back-to-2d:hover {
  color: var(--t3d-text);
  border-color: rgba(236, 233, 228, 0.3);
  background: rgba(18, 25, 36, 0.98);
}
.back-to-2d svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* ── Toolbar ───────────────────────────────────────────── */
.terrain-toolbar {
  position: fixed;
  top: 72px;
  right: 1rem;
  z-index: 50;
  display: flex;
  gap: 0.5rem;
}
.t3d-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  height: 36px;
  padding: 0 0.85rem;
  background: var(--t3d-panel);
  border: 1px solid var(--t3d-border);
  border-radius: 10px;
  color: var(--t3d-text-dim);
  font-family: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  transition: color 200ms, border-color 200ms, background 200ms;
  white-space: nowrap;
}
.t3d-btn:hover,
.t3d-btn.active {
  color: var(--t3d-text);
  border-color: rgba(236, 233, 228, 0.3);
  background: rgba(18, 25, 36, 0.98);
}
.t3d-btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* ── Info Panel (click on location) ────────────────────── */
.terrain-info-panel {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  z-index: 60;
  width: min(420px, calc(100vw - 2rem));
  background: var(--t3d-panel);
  border: 1px solid var(--t3d-border);
  border-radius: 16px;
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  box-shadow: 0 12px 48px rgba(0,0,0,0.4);
  padding: 1.2rem 1.4rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.terrain-info-panel.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}
.info-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.6rem;
}
.info-panel-name {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--t3d-text);
}
.info-panel-close {
  width: 28px;
  height: 28px;
  border: none;
  background: rgba(255,255,255,0.08);
  border-radius: 50%;
  color: var(--t3d-text-dim);
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
}
.info-panel-close:hover {
  background: rgba(255,255,255,0.15);
  color: var(--t3d-text);
}
.info-panel-desc {
  font-size: 0.84rem;
  line-height: 1.6;
  color: var(--t3d-text-dim);
  margin-bottom: 1rem;
}
.info-panel-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1.2rem;
  background: linear-gradient(135deg, var(--t3d-accent), #d4960a);
  border: none;
  border-radius: 999px;
  color: #fff;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.2s, box-shadow 0.2s;
}
.info-panel-link:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(232, 168, 62, 0.35);
}
.info-panel-link svg {
  width: 14px;
  height: 14px;
}

/* ── Location Label (CSS2D) ────────────────────────────── */
.terrain-label {
  position: relative;
  pointer-events: auto;
  cursor: pointer;
  padding: 0.35rem 0.7rem;
  background: rgba(18, 25, 36, 0.85);
  border: 1px solid rgba(232, 168, 62, 0.3);
  border-radius: 6px;
  font-family: "Noto Sans SC", sans-serif;
  font-size: 11px;
  font-weight: 600;
  color: rgba(236, 233, 228, 0.85);
  white-space: nowrap;
  transition: all 0.2s ease;
  transform: translate(-50%, -100%);
  text-align: center;
  user-select: none;
}
.terrain-label::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 50%;
  transform: translateX(-50%);
  width: 6px;
  height: 6px;
  background: var(--t3d-accent);
  border-radius: 50%;
  box-shadow: 0 0 6px rgba(232, 168, 62, 0.6);
}
.terrain-label:hover,
.terrain-label.hovered {
  background: rgba(232, 168, 62, 0.9);
  color: #fff;
  border-color: var(--t3d-accent);
  transform: translate(-50%, -100%) scale(1.1);
  box-shadow: 0 0 20px rgba(232, 168, 62, 0.4);
}

/* ── Hint text ─────────────────────────────────────────── */
.terrain-hint {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  font-size: 0.72rem;
  color: var(--t3d-text-dim);
  padding: 0.4rem 1rem;
  background: var(--t3d-panel);
  border: 1px solid var(--t3d-border);
  border-radius: 999px;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  pointer-events: none;
  opacity: 0.7;
  transition: opacity 0.6s ease;
}
.terrain-hint.fade-out {
  opacity: 0;
}

/* ── Legend ─────────────────────────────────────────────── */
.terrain-legend {
  position: fixed;
  bottom: 1rem;
  left: 1rem;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 1rem;
  background: var(--t3d-panel);
  border: 1px solid var(--t3d-border);
  border-radius: 10px;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  font-size: 0.7rem;
  color: var(--t3d-text-dim);
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}
.legend-swatch {
  width: 14px;
  height: 8px;
  border-radius: 2px;
}

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 768px) {
  .terrain-topbar-inner {
    width: calc(100vw - 14px);
    gap: 0.65rem;
  }
  .terrain-topbar .explore-logo span { display: none; }
  .terrain-topbar .top-links {
    gap: 0.7rem;
  }
  .terrain-toolbar {
    top: auto;
    bottom: 3.5rem;
    right: 0.5rem;
    flex-direction: column;
  }
  .t3d-btn span { display: none; }
  .t3d-btn { padding: 0 0.6rem; width: 36px; height: 36px; }
  .back-to-2d span { display: none; }
  .back-to-2d { padding: 0.5rem 0.6rem; }
  .terrain-legend { display: none; }
  .terrain-info-panel { width: calc(100vw - 1.5rem); bottom: 1rem; }
  .terrain-compass { right: 0.5rem; bottom: auto; top: 72px; }
}

/* ── Compass ──────────────────────────────────────────────── */
.terrain-compass {
  position: fixed;
  bottom: 4rem;
  right: 1rem;
  z-index: 30;
}
.compass-ring {
  position: relative;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--t3d-panel);
  border: 1px solid var(--t3d-border);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.compass-n {
  position: absolute;
  top: 2px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.58rem;
  font-weight: 700;
  color: var(--t3d-accent);
  line-height: 1;
  pointer-events: none;
}
.compass-arrow {
  transition: transform 0.15s ease-out;
}
