/* ============================================================
  territory.css — 明朝版图 · 逐笔绘制
  背景：p5 画布需要响应式承载，控制条/面积揭示复用 base 令牌。
  设计意图：画布透明叠在宣纸底色上，墨线即页面的一部分；
            面积区用大号朱色数字＋对比条收束全课。
  约束：375px 不横向溢出；单列居中（max 960px）。
  ============================================================ */

.terr-main {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 calc(var(--sp) * 3) calc(var(--sp) * 6);
}

/* ---------- 标题区（lesson 通用样式本课自带） ---------- */

.lesson-head { padding: calc(var(--sp) * 5) 0 calc(var(--sp) * 3); }
.kicker {
  font-size: var(--fs-sm);
  letter-spacing: .14em;
  margin-bottom: var(--sp);
}
.lesson-head h1 { font-size: var(--fs-xl); margin-bottom: calc(var(--sp) * 2); }
.intro { max-width: 680px; color: var(--ink-soft); }

/* ---------- 画布舞台 ---------- */

.terr-stage {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--pattern-lotus), var(--paper-2);
  padding: calc(var(--sp) * 2);
}

.terr-canvas-wrap {
  position: relative;
  width: 100%;
}

.terr-canvas-wrap canvas {
  display: block;
  width: 100% !important;
  height: auto !important;
  /* 手势分工：纵向滚动归页面（用户在地图外也能正常上下翻），
     真正在地图上的单指拖动/双指捏合由 JS 判定后自行接管。 */
  touch-action: pan-y !important;
}

/* ---------- 图例（左下）与比例尺（右下） ---------- */

.terr-legend {
  position: absolute;
  left: 10px;
  bottom: 10px;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 8px 10px;
  background: color-mix(in srgb, var(--paper-2) 88%, transparent);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 11px;
  line-height: 1;
  color: var(--ink-soft);
  pointer-events: none;
}

.terr-legend span { display: flex; align-items: center; gap: 6px; }

.terr-legend i {
  display: inline-block;
  width: 16px;
  height: 0;
  border-top: 3px solid;
  border-radius: 2px;
}
.terr-legend i.lg-ming { border-color: var(--zhu); border-top-width: 8px; border-radius: 1px; }
.terr-legend i.lg-nb { border-color: rgba(58, 47, 36, 0.45); border-top-style: dashed; }
.terr-legend i.lg-wall { border-color: var(--gold); }
.terr-legend i.lg-river { border-color: var(--qing); }
.terr-legend i.lg-bd { border-color: rgba(58, 47, 36, 0.35); border-top-style: dashed; border-top-width: 2px; }

.terr-scale {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 1;
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 6px 8px;
  background: color-mix(in srgb, var(--paper-2) 88%, transparent);
  border: 1px solid var(--line);
  border-radius: 8px;
  pointer-events: none;
}

.terr-scale i {
  display: inline-block;
  height: 6px;
  border-left: 2px solid var(--ink-soft);
  border-right: 2px solid var(--ink-soft);
  border-bottom: 2px solid var(--ink-soft);
}

.terr-scale span {
  font-size: 10.5px;
  line-height: 1;
  color: var(--ink-soft);
  white-space: nowrap;
}

@media (max-width: 760px) {
  .terr-legend { font-size: 10px; padding: 6px 8px; gap: 2px; }
  .terr-scale span { font-size: 9.5px; }
}

/* 开始遮罩：居中毛笔按钮 */
.terr-cover {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--paper-2) 55%, transparent);
  transition: opacity .35s ease;
}

.terr-cover.gone {
  opacity: 0;
  pointer-events: none;
}

.terr-cover .btn-primary { font-size: 1.05rem; }

.terr-caption {
  margin: calc(var(--sp) * 2) 4px 0;
  min-height: 1.75em;
  font-size: 1rem;
  line-height: 1.7;
  color: var(--ink-soft);
  text-align: center;
}

/* ---------- 控制（重播 + 提示；阶段步进条已按用户要求移除） ---------- */

.terr-controls {
  margin-top: calc(var(--sp) * 3);
  display: flex;
  flex-direction: column;
  gap: calc(var(--sp) * 2);
}

.terr-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: calc(var(--sp) * 2);
  flex-wrap: wrap;
}

.terr-hint { font-size: .85rem; color: var(--ink-soft); }

/* ---------- 面积揭示 ---------- */

.terr-area {
  margin-top: calc(var(--sp) * 4);
  padding: calc(var(--sp) * 4) calc(var(--sp) * 3);
  border: 1px solid var(--line);
  border-left: 4px solid var(--zhu);
  border-radius: var(--radius);
  background: var(--paper);
  opacity: 0;
  transform: translateY(8px);
}

.terr-area.show {
  opacity: 1;
  transform: none;
  transition: opacity .8s ease, transform .8s ease;
}

@media (prefers-reduced-motion: reduce) {
  .terr-area.show { transition: none; }
}

.ta-head { margin: 0; font-size: .95rem; color: var(--ink-soft); }

.ta-big {
  display: flex;
  align-items: baseline;
  gap: .5em;
  flex-wrap: wrap;
  margin: calc(var(--sp) * 2) 0;
}

.ta-big .num {
  font-size: clamp(2.4rem, 7vw, 3.6rem);
  color: var(--zhu);
  letter-spacing: .01em;
}

.ta-unit { font-size: 1rem; color: var(--ink-soft); }

.ta-bars {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 640px;
}

.ta-row {
  display: grid;
  grid-template-columns: 8.5em 1fr 6em;
  align-items: center;
  gap: 10px;
}

.ta-label { font-size: .92rem; color: var(--ink); white-space: nowrap; }

.ta-track {
  height: 12px;
  border-radius: 6px;
  background: var(--paper-3);
  overflow: hidden;
}

.ta-fill {
  height: 100%;
  border-radius: 6px;
  transform-origin: left center;
}

.terr-area.show .ta-fill { animation: ta-grow .9s ease-out both; }

@media (prefers-reduced-motion: reduce) {
  .terr-area.show .ta-fill { animation: none; }
}

@keyframes ta-grow {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

.ta-fill.ming  { width: 100%;  background: var(--zhu); }
.ta-fill.china { width: 96.3%; background: var(--qing); }
.ta-fill.spain { width: 5.1%;  min-width: 6px; background: var(--huang); }

.ta-num { font-size: .95rem; color: var(--ink); white-space: nowrap; }

.ta-src {
  margin: calc(var(--sp) * 3) 0 0;
  font-size: .85rem;
  line-height: 1.7;
  color: var(--ink-soft);
}

/* ---------- 示意声明 ---------- */

.terr-note {
  margin-top: calc(var(--sp) * 3);
  font-size: .85rem;
  line-height: 1.7;
  color: var(--ink-soft);
  text-align: center;
}

/* ---------- 移动端 ---------- */

@media (max-width: 760px) {
  .terr-main { padding: 0 calc(var(--sp) * 2) calc(var(--sp) * 5); }
  .ta-row { grid-template-columns: 1fr; gap: 4px; }
  .ta-num { order: 3; }
}
