/* ==========================================================================
   雅鲁藏布江下游水电工程 · 三维沙盘
   版式：一张测绘图幅 —— 冷石灰岩底、墨色字、水青与赭石取自场景本身
   ========================================================================== */

:root {
  --field: #dfe4dd;
  --field-2: #cfd7cf;
  --ink: #16211e;
  --ink-2: #41504a;
  --ink-3: #56665f;
  --rule: rgba(22, 33, 30, .16);
  --rule-strong: rgba(22, 33, 30, .38);
  --water: #0f6b6c;
  --work: #96622f;

  --font-sans: "HarmonyOS Sans SC", "MiSans", "PingFang SC", "Source Han Sans SC",
    "Noto Sans CJK SC", "Microsoft YaHei", system-ui, sans-serif;

  --ease: cubic-bezier(.22, .68, .28, 1);
}

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

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--field);
  color: var(--ink);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

body {
  background:
    radial-gradient(74% 58% at 16% -6%, rgba(255, 255, 255, .62), transparent 62%),
    radial-gradient(62% 56% at 104% 108%, rgba(15, 107, 108, .10), transparent 68%),
    var(--field);
}

::selection { background: rgba(15, 107, 108, .22); }

:focus-visible {
  outline: 2px solid var(--water);
  outline-offset: 3px;
}

/* ---------------------------------- 画布 ---------------------------------- */
#app {
  position: fixed;
  inset: 0;
}

#app canvas { display: block; }

/* 轻微暗角，把视线收到沙盘上 */
#app::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  background: radial-gradient(120% 92% at 50% 44%, transparent 58%, rgba(22, 33, 30, .16) 100%);
}

.label-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 4;
}

/* ---------------------------------- 图廓 ---------------------------------- */
.plate {
  position: fixed;
  inset: 16px;
  z-index: 6;
  border: 1px solid var(--rule);
  pointer-events: none;
}

/* 对角两处注册角标，代替四角对称的框线 */
.plate::before,
.plate::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
}

.plate::before {
  top: -1px;
  left: -1px;
  border-top: 2px solid var(--ink);
  border-left: 2px solid var(--ink);
}

.plate::after {
  right: -1px;
  bottom: -1px;
  border-right: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
}

/* ---------------------------------- 通用 ---------------------------------- */
.hud {
  position: fixed;
  z-index: 10;
  margin: 0;
}

.hud__label {
  margin: 0 0 9px;
  padding-bottom: 7px;
  border-bottom: 1px solid var(--rule-strong);
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .04em;
  color: var(--ink);
}

.hud__note {
  margin: 12px 0 0;
  font-size: .66rem;
  line-height: 1.7;
  color: var(--ink-3);
}

/* ---- 图名 ---- */
.hud--title {
  top: 42px;
  left: 42px;
  max-width: 24em;
  pointer-events: none;
}

.plate-name {
  margin: 0 0 4px;
  font-size: .74rem;
  font-weight: 500;
  letter-spacing: .02em;
  color: var(--ink-2);
}

.title {
  margin: 0;
  font-size: clamp(2.1rem, 3.9vw, 3.4rem);
  font-weight: 700;
  line-height: 1.02;
  letter-spacing: .01em;
}

.plate-scale {
  margin: 14px 0 0;
  padding-top: 9px;
  border-top: 1px solid var(--rule-strong);
  font-size: .66rem;
  line-height: 1.6;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

.plate-scale span + span {
  margin-left: 1.4em;
}

/* ---- 位置索引图 ---- */
.hud--locator {
  top: 214px;
  left: 42px;
  width: 206px;
  padding: 11px 12px 10px;
  background: rgba(223, 228, 221, .94);
  background: color-mix(in srgb, var(--field) 94%, transparent);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid var(--rule);
}

.locator__label {
  margin: 0 0 9px;
  font-size: .6rem;
  font-weight: 600;
  color: var(--ink-3);
}

.locator__map {
  display: block;
  width: 100%;
  height: auto;
}

.locator__cap {
  margin: 9px 0 0;
  padding-top: 8px;
  border-top: 1px solid var(--rule);
  font-size: .68rem;
  line-height: 1.5;
  color: var(--ink-2);
}

/* ---- 数据表 ---- */
.hud--info {
  top: 42px;
  right: 42px;
  width: 300px;
  max-height: calc(100dvh - 148px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--rule-strong) transparent;
  padding: 18px 20px 16px;
  background: rgba(223, 228, 221, .92);
  background: color-mix(in srgb, var(--field) 92%, transparent);
  -webkit-backdrop-filter: blur(12px) saturate(.9);
  backdrop-filter: blur(12px) saturate(.9);
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--rule);
  transition: padding .2s var(--ease);
}

.sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
  padding-bottom: 7px;
  border-bottom: 1px solid var(--rule-strong);
}

.hud--info .hud__label {
  margin: 0;
  padding-bottom: 0;
  border-bottom: 0;
}

.sheet-toggle {
  flex: none;
  appearance: none;
  border: 0;
  padding: 0;
  background: none;
  font: inherit;
  font-size: .62rem;
  line-height: 1.4;
  color: var(--ink-3);
  cursor: pointer;
}

.sheet-toggle:hover { color: var(--ink); }

.hud--info.is-collapsed {
  width: 176px;
  padding-bottom: 12px;
}

.hud--info.is-collapsed #info-body,
.hud--info.is-collapsed .hud__note { display: none; }

#info-body {
  display: grid;
  margin: 0;
}

.fact {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  gap: 4px 14px;
  padding: 8px 0;
  border-bottom: 1px solid var(--rule);
}

.fact:last-child { border-bottom: 0; }

.fact dt {
  font-size: .74rem;
  color: var(--ink-2);
}

.fact dd {
  margin: 0;
  text-align: right;
  font-size: .95rem;
  font-weight: 600;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
}

.fact dd em {
  display: block;
  margin-top: 2px;
  font-style: normal;
  font-size: .64rem;
  font-weight: 400;
  line-height: 1.5;
  color: var(--ink-3);
}

/* ---- 图层 ---- */
.hud--layers {
  left: 42px;
  bottom: 32px;
  width: 236px;
}

.toggles {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 16px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: .74rem;
  color: var(--ink-2);
  cursor: pointer;
  user-select: none;
  transition: color .25s var(--ease);
}

.toggle:hover { color: var(--ink); }

.toggle span { white-space: nowrap; }

.toggle input {
  position: relative;
  flex: none;
  width: 11px;
  height: 11px;
  margin: 0;
  padding: 0;
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--rule-strong);
  background: transparent;
  cursor: pointer;
  transition: background .2s var(--ease), border-color .2s var(--ease);
}

.toggle input:checked {
  background: var(--ink);
  border-color: var(--ink);
}

.toggle input:checked::after {
  content: "";
  position: absolute;
  inset: 3px;
  background: var(--field);
}

.toggle:has(input:not(:checked)) span { color: var(--ink-3); }

/* ---- 索引图 / 剖切详图 ---- */
body.is-system .hud--locator { display: none; }

@media (max-width: 1100px) {
  body.is-system .hud--info,
  body.is-system .hud--layers { display: none; }
}

/* ---- 视角 ---- */
.hud--views {
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  display: flex;
  align-items: stretch;
}

.hud--views button {
  appearance: none;
  position: relative;
  border: 0;
  border-left: 1px solid var(--rule);
  padding: 7px 15px;
  background: transparent;
  font: inherit;
  font-size: .76rem;
  color: var(--ink-2);
  cursor: pointer;
  white-space: nowrap;
  flex: 0 0 auto;
  transition: color .2s var(--ease);
}

.hud--views button:first-child { border-left: 0; }

.hud--views button:hover { color: var(--ink); }

.hud--views button.is-active {
  color: var(--ink);
  font-weight: 600;
}

.hud--views button.is-active::after {
  content: "";
  position: absolute;
  left: 15px;
  right: 15px;
  bottom: 1px;
  height: 2px;
  background: var(--ink);
}

/* ---- 操作提示 ---- */
.hud--hint {
  right: 42px;
  bottom: 32px;
  max-width: 21em;
  text-align: right;
  pointer-events: none;
}

.hint__act {
  margin: 0 0 6px;
  font-size: .72rem;
  color: var(--ink-2);
}

/* ---------------------------------- 标注 ---------------------------------- */
.map-label {
  padding: 1px 4px;
  background: rgba(223, 228, 221, .8);
  background: color-mix(in srgb, var(--field) 80%, transparent);
  font-size: 12px;
  line-height: 1.4;
  letter-spacing: .02em;
  white-space: nowrap;
  color: var(--ink);
  pointer-events: none;
}

.map-label--major {
  font-size: 13px;
  font-weight: 600;
}

.map-label--peak { color: var(--ink-2); }

.map-label--river {
  color: var(--water);
  font-weight: 500;
}

.map-label--place { color: var(--ink-3); }

.map-label--works {
  color: var(--work);
  font-weight: 600;
}

.map-label__sub {
  display: block;
  margin-top: 1px;
  font-size: .74em;
  font-weight: 400;
  letter-spacing: 0;
  color: var(--ink-2);
}

.map-label--system-title {
  background: none;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--ink);
}

.map-label--dim {
  background: none;
  font-size: 11px;
  color: var(--ink-2);
  letter-spacing: .02em;
  font-variant-numeric: tabular-nums;
}

.map-label--station {
  font-size: 11px;
  color: var(--work);
}

/* ---------------------------------- 载入 ---------------------------------- */
#loading {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  gap: 0;
  background: var(--field);
  font-size: .72rem;
  letter-spacing: .04em;
  color: var(--ink-3);
  transition: opacity .6s var(--ease);
}

#loading span::before {
  content: "";
  display: block;
  width: 96px;
  height: 1px;
  margin: 0 auto 14px;
  background: linear-gradient(90deg, var(--rule-strong) 0 60%, transparent 60% 100%);
  background-size: 200% 100%;
  animation: sweep 1.6s linear infinite;
}

body.is-ready #loading {
  opacity: 0;
  pointer-events: none;
}

.no-webgl #loading span::after {
  content: "当前浏览器不支持 WebGL，无法显示三维沙盘。";
  display: block;
  margin-top: 12px;
  max-width: 18em;
  line-height: 1.7;
  color: var(--ink-2);
}

@keyframes sweep {
  from { background-position: 100% 0; }
  to { background-position: -100% 0; }
}

/* ---------------------------------- 响应式 --------------------------------- */
@media (max-width: 1180px) {
  .hud--hint { display: none; }
  .hud--info { width: 264px; }
}

@media (max-width: 940px) {
  .plate { inset: 10px; }

  .hud--title {
    top: 24px;
    left: 22px;
  }

  .plate-name { font-size: .66rem; }
  .title { font-size: 1.65rem; }
  .plate-scale { margin-top: 10px; font-size: .62rem; }

  .hud--info {
    top: 20px;
    right: 20px;
    width: clamp(170px, 46vw, 250px);
    max-height: 44vh;
    overflow-y: auto;
    padding: 12px 13px 10px;
  }

  .hud--locator {
    top: 150px;
    left: 22px;
    width: 128px;
    padding: 8px 9px 7px;
  }

  .locator__label {
    margin-bottom: 6px;
    font-size: .56rem;
  }

  .locator__cap {
    margin-top: 6px;
    padding-top: 5px;
    font-size: .6rem;
  }

  .hud__label { font-size: .62rem; }
  .fact {
    display: block;
    padding: 6px 0;
  }
  .fact dt { font-size: .62rem; }
  .fact dd {
    margin-top: 1px;
    text-align: left;
    font-size: .8rem;
  }
  .fact dd em { display: none; }
  .hud__note { font-size: .62rem; }

  .hud--views {
    left: 12px;
    right: 12px;
    bottom: 62px;
    transform: none;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .hud--views::-webkit-scrollbar { display: none; }

  .hud--views button { padding: 6px 11px; font-size: .72rem; }
  .hud--views button:first-child { border-left: 0; }
  .hud--views button.is-active::after {
    left: 11px;
    right: 11px;
  }

  .hud--layers {
    left: 22px;
    right: 22px;
    bottom: 18px;
    width: auto;
  }

  .hud--layers .hud__label { border-bottom: 0; padding-bottom: 0; margin-bottom: 7px; }

  .toggles {
    display: flex;
    gap: 14px;
    overflow-x: auto;
    scrollbar-width: none;
  }

  .toggles::-webkit-scrollbar { display: none; }

  .toggle { font-size: .68rem; }

  .map-label { font-size: 11px; }
  .map-label--major { font-size: 12px; }
  .map-label--station { font-size: 10px; }
}

@media (max-width: 640px) {
  .map-label--station { display: none; }
  .hud--title { max-width: 12em; }

  .hud--locator {
    top: 138px;
    width: 112px;
  }

  .map-label--system-title,
  .map-label__sub { display: none; }
}

@media (max-height: 620px) {
  .hud--layers { display: none; }
  .hud--hint { display: none; }
}

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