:root {
  --c-deep: #0d2818;
  --c-primary: #1b4332;
  --c-secondary: #2d6a4f;
  --c-accent: #52b788;
  --c-light: #74c69d;
  --c-lighter: #b7e4c7;
  --c-lightest: #d8f3dc;
  --c-mist: #f0fdf4;
  --c-bg: #fafff9;
  --c-gold: #c9a227;
  --c-gold-light: #e9c46a;
  --c-water: #4cc9f0;
  --c-water-deep: #277da1;
  --c-text: #1b2b1f;
  --c-text-light: #52796f;
  --c-text-muted: #84a98c;
  --shadow-float: 0 14px 40px rgba(13, 40, 24, 0.22);
  --shadow-modal: 0 28px 80px rgba(5, 19, 11, 0.42);
  --radius: 16px;
  --radius-sm: 10px;
  --serif: "Noto Serif SC", "Songti SC", "SimSun", serif;
  --sans: "Noto Sans SC", "Microsoft YaHei", "PingFang SC", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body,
#cesiumContainer {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  color: var(--c-text);
  background: var(--c-deep);
  font-family: var(--sans);
  text-rendering: optimizeLegibility;
}

[hidden] {
  display: none !important;
}

::selection {
  color: var(--c-deep);
  background: var(--c-light);
}

button,
select {
  font: inherit;
}

button,
a,
select {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
select:focus-visible {
  outline: 3px solid var(--c-water);
  outline-offset: 3px;
}

body.placement-active #cesiumContainer canvas {
  cursor: crosshair !important;
}

/* Header */

#mapHeader {
  position: fixed;
  inset: 0 0 auto;
  z-index: 25;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  height: 58px;
  padding: 0 18px;
  color: #fff;
  background: rgba(13, 40, 24, 0.94);
  box-shadow: 0 8px 28px rgba(5, 19, 11, 0.18);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.map-brand {
  display: inline-flex;
  align-items: center;
  justify-self: start;
  gap: 9px;
  color: var(--c-lighter);
  font-family: var(--serif);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-decoration: none;
}

.map-brand-dot {
  width: 8px;
  height: 8px;
  background: var(--c-accent);
  border-radius: 50%;
}

.map-title-group {
  justify-self: center;
}

.map-title {
  color: #fff;
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

#backLink {
  justify-self: end;
  padding: 8px 11px;
  color: rgba(216, 243, 220, 0.78);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  transition: color 160ms ease, background-color 160ms ease;
}

#backLink:hover {
  color: #fff;
  background: rgba(82, 183, 136, 0.14);
}

/* Compact tool dock */

#viewerControls {
  position: fixed;
  top: 74px;
  left: 16px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  color: #fff;
  background: rgba(13, 40, 24, 0.92);
  border-radius: 14px;
  box-shadow: var(--shadow-float);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.control-heading {
  padding: 0 8px;
  color: var(--c-lighter);
  font-family: var(--serif);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.control-field {
  display: flex;
  align-items: center;
  gap: 7px;
}

.control-label {
  color: rgba(183, 228, 199, 0.66);
  font-size: 11px;
  white-space: nowrap;
}

#backgroundSelect {
  min-width: 150px;
  height: 38px;
  padding: 0 32px 0 11px;
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
  border: 0;
  border-radius: 9px;
  font-size: 12px;
  cursor: pointer;
}

#backgroundSelect:hover {
  background: rgba(255, 255, 255, 0.12);
}

#backgroundSelect:disabled {
  cursor: wait;
  opacity: 0.55;
}

#backgroundSelect option {
  color: var(--c-text);
  background: #fff;
}

.control-actions {
  display: flex;
  gap: 6px;
}

#centerButton,
#footprintsButton,
#placementButton,
#exportPointsButton {
  min-width: 84px;
  height: 38px;
  padding: 0 12px;
  color: rgba(255, 255, 255, 0.84);
  background: transparent;
  border: 0;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: color 160ms ease, background-color 160ms ease;
}

#centerButton:hover:not(:disabled),
#footprintsButton:hover:not(:disabled),
#placementButton:hover:not(:disabled),
#exportPointsButton:hover:not(:disabled) {
  color: #fff;
  background: rgba(82, 183, 136, 0.14);
}

#footprintsButton.active {
  color: #fff;
  background: var(--c-water-deep);
}

#placementButton.active {
  color: var(--c-deep);
  background: var(--c-gold-light);
}

#centerButton:disabled,
#footprintsButton:disabled,
#placementButton:disabled,
#exportPointsButton:disabled {
  cursor: wait;
  opacity: 0.42;
}

/* Status, legend, tooltip */

#status {
  position: fixed;
  bottom: 62px;
  left: 16px;
  z-index: 18;
  max-width: min(520px, calc(100vw - 32px));
  padding: 10px 13px;
  color: var(--c-lighter);
  background: rgba(13, 40, 24, 0.94);
  border-radius: 9px;
  box-shadow: 0 8px 24px rgba(5, 19, 11, 0.16);
  font-size: 12px;
  line-height: 1.5;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

#mapLegend {
  position: fixed;
  right: 50%;
  bottom: 14px;
  z-index: 16;
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 9px 12px;
  color: rgba(255, 255, 255, 0.78);
  background: rgba(13, 40, 24, 0.84);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(5, 19, 11, 0.14);
  font-size: 11px;
  transform: translateX(50%);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  transition: opacity 160ms ease;
}

.footprints-hidden .legend-item {
  opacity: 0.28;
}

.legend-dot {
  width: 8px;
  height: 8px;
  border: 2px solid #fff;
  border-radius: 50%;
}

.legend-dot.footprint {
  background: #1e90ff;
}

.legend-dot.control {
  background: #ffd700;
}

.legend-help {
  padding-left: 13px;
  color: rgba(183, 228, 199, 0.56);
  border-left: 1px solid rgba(183, 228, 199, 0.18);
  white-space: nowrap;
}

#pointTooltip {
  position: fixed;
  z-index: 30;
  display: none;
  max-width: 260px;
  padding: 8px 10px;
  color: #fff;
  background: rgba(13, 40, 24, 0.96);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(5, 19, 11, 0.2);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
  pointer-events: none;
  transform: translate(12px, 12px);
}

/* Footprint detail */

.footprint-modal[hidden] {
  display: none;
}

.footprint-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 28px;
  font-family: var(--sans);
}

.footprint-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 19, 11, 0.72);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
  animation: modalBackdropIn 220ms cubic-bezier(0.16, 1, 0.3, 1);
}

.footprint-modal-card {
  position: relative;
  width: min(920px, 100%);
  max-height: calc(100vh - 56px);
  overflow: auto;
  color: var(--c-text);
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-modal);
  animation: modalCardIn 260ms cubic-bezier(0.16, 1, 0.3, 1);
  scrollbar-color: rgba(45, 106, 79, 0.5) transparent;
  scrollbar-width: thin;
}

@keyframes modalBackdropIn {
  from {
    opacity: 0.76;
  }
}

@keyframes modalCardIn {
  from {
    opacity: 0.86;
    transform: translateY(12px) scale(0.99);
    filter: blur(2px);
  }
}

.footprint-modal-card::-webkit-scrollbar {
  width: 9px;
}

.footprint-modal-card::-webkit-scrollbar-thumb {
  background: rgba(45, 106, 79, 0.46);
  border: 2px solid #fff;
  border-radius: 10px;
}

.footprint-modal-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 22px 24px 18px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--c-lightest);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.footprint-modal-title {
  margin: 0;
  color: var(--c-primary);
  font-family: var(--serif);
  font-size: clamp(24px, 3vw, 32px);
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.footprint-modal-meta {
  margin-top: 5px;
  color: var(--c-text-light);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.footprint-modal-close {
  min-width: 54px;
  min-height: 40px;
  padding: 0 12px;
  color: var(--c-secondary);
  background: var(--c-mist);
  border: 0;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: color 160ms ease, background-color 160ms ease;
}

.footprint-modal-close:hover {
  color: #fff;
  background: var(--c-secondary);
}

.footprint-modal-body {
  padding: 24px;
}

.footprint-modal-body > .footprint-text:first-child {
  max-width: 72ch;
  margin: 0 0 28px;
  color: var(--c-text-light);
  font-size: 15px;
  line-height: 1.9;
}

.footprint-block {
  padding: 0 0 30px;
}

.footprint-block + .footprint-block {
  padding-top: 28px;
  border-top: 1px solid var(--c-lightest);
}

.footprint-block:last-child {
  padding-bottom: 0;
}

.footprint-block h3 {
  margin: 0 0 16px;
  color: var(--c-primary);
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.4;
}

.footprint-video {
  display: block;
  width: 100%;
  max-height: 68vh;
  background: var(--c-deep);
  border-radius: 12px;
}

.footprint-gallery {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.footprint-gallery a {
  display: grid;
  place-items: center;
  min-height: 180px;
  overflow: hidden;
  background: var(--c-mist);
  border-radius: 12px;
}

.footprint-gallery img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 540px;
  object-fit: contain;
}

.footprint-table-wrap {
  overflow-x: auto;
  border-radius: 10px;
}

.footprint-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.footprint-table th,
.footprint-table td {
  padding: 11px 13px;
  text-align: left;
  border-bottom: 1px solid var(--c-lightest);
}

.footprint-table th {
  color: var(--c-primary);
  background: var(--c-mist);
  font-weight: 700;
}

.footprint-table tbody tr:last-child td {
  border-bottom: 0;
}

.footprint-table tbody tr:hover td {
  background: rgba(216, 243, 220, 0.34);
}

.footprint-note,
.footprint-text,
.footprint-empty,
.footprint-error {
  max-width: 72ch;
  margin: 10px 0 0;
  color: var(--c-text-light);
  font-size: 14px;
  line-height: 1.85;
}

.footprint-empty,
.footprint-error {
  padding: 14px 16px;
  background: var(--c-mist);
  border-radius: 10px;
}

/* Cesium native controls */

.cesium-viewer-toolbar {
  top: 72px;
  right: 16px;
}

.cesium-button {
  overflow: hidden;
  background: rgba(13, 40, 24, 0.9) !important;
  border: 0 !important;
  border-radius: 9px !important;
  box-shadow: 0 8px 24px rgba(5, 19, 11, 0.16);
}

.cesium-button:hover {
  background: var(--c-secondary) !important;
}

.cesium-viewer-fullscreenContainer {
  right: 16px;
  bottom: 16px;
  width: 36px;
  height: 36px;
}

.cesium-widget-credits {
  opacity: 0.58;
}

/* Responsive */

@media (max-width: 860px) {
  #mapHeader {
    grid-template-columns: 1fr auto;
    height: 56px;
    padding: 0 12px;
  }

  .map-title-group {
    display: none;
  }

  .map-brand {
    font-size: 13px;
  }

  #viewerControls {
    top: 68px;
    right: 10px;
    left: 10px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 7px 10px;
    padding: 9px;
  }

  .control-heading {
    padding: 0 4px;
  }

  .control-field {
    min-width: 0;
  }

  #backgroundSelect {
    width: 100%;
    min-width: 0;
  }

  .control-actions {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #centerButton,
  #footprintsButton,
  #placementButton,
  #exportPointsButton {
    width: 100%;
    min-width: 0;
    min-height: 44px;
  }

  #mapLegend {
    right: 10px;
    bottom: 10px;
    left: 10px;
    justify-content: center;
    transform: none;
  }

  .legend-help {
    display: none;
  }

  #status {
    right: 10px;
    bottom: 56px;
    left: 10px;
    max-width: none;
  }

  .cesium-viewer-toolbar {
    top: 176px;
    right: 10px;
  }

  body.editing-enabled .cesium-viewer-toolbar {
    top: 224px;
  }
}

@media (max-width: 620px) {
  .footprint-modal {
    place-items: end center;
    padding: 0;
  }

  .footprint-modal-card {
    width: 100%;
    max-height: calc(100vh - 24px);
    border-radius: 16px 16px 0 0;
  }

  .footprint-modal-header {
    padding: 18px 16px 15px;
  }

  .footprint-modal-title {
    font-size: 24px;
  }

  .footprint-modal-body {
    padding: 18px 16px 24px;
  }

  .footprint-modal-close {
    min-height: 44px;
  }

  .footprint-gallery {
    grid-template-columns: 1fr;
  }

  .footprint-gallery a {
    min-height: 0;
  }
}

@media (max-width: 420px) {
  #mapHeader {
    padding: 0 10px;
  }

  #backLink {
    padding-right: 6px;
    padding-left: 6px;
  }

  .control-heading {
    display: none;
  }

  #viewerControls {
    grid-template-columns: 1fr;
  }

  .control-field,
  .control-actions {
    grid-column: 1;
  }

  #mapLegend {
    gap: 9px;
    font-size: 10px;
  }

  .cesium-viewer-toolbar,
  body.editing-enabled .cesium-viewer-toolbar {
    top: 218px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
