:root {
  --bg: #0b0b0a;
  --ink: #ecebe6;
  --ink-2: rgba(236, 235, 230, 0.58);
  --ink-3: rgba(236, 235, 230, 0.34);
  --ink-4: rgba(236, 235, 230, 0.2);
  --line: rgba(236, 235, 230, 0.12);
  --accent: #ff5a1f;
  --lat: #d9c08a;
  --lon: #8db8d8;

  --serif: 'Noto Serif SC', 'Songti SC', serif;
  --display: 'Instrument Serif', Georgia, serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --gutter: clamp(16px, 3vw, 40px);
  /* 左右两栏只占顶部信息与底部栏之间的空间，互不遮挡 */
  --panel-top: calc(var(--gutter) + 92px);
  --panel-bottom: calc(var(--gutter) + 40px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.mono {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  font-feature-settings: 'tnum' 1;
}
.dim { color: var(--ink-3); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- 舞台：地球、刻度环、标签 ---------- */
.stage { position: fixed; inset: 0; }
#globe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: pan-y;
  cursor: grab;
}
.vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse 75% 70% at 50% 50%, transparent 55%, rgba(0, 0, 0, 0.42) 100%);
}
#globe.dragging { cursor: grabbing; }
#globe.over-land { cursor: crosshair; }

#bezel {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0;
  overflow: visible;
  transition: opacity 1.6s ease 0.6s;
}
body.ready #bezel { opacity: 1; }
#bezel circle { fill: none; stroke: var(--line); stroke-width: 1; }
#bezel line { stroke: var(--ink-3); stroke-width: 1; }
#bezel line.minor { stroke: var(--line); }
#bezel line.lat { stroke: var(--lat); }
#bezel line.lon { stroke: var(--lon); }
#bezel text.lat { fill: var(--lat); }
#bezel text.lon { fill: var(--lon); }
#bezel text.legend { font-size: 9px; letter-spacing: 0.1em; }
#bezel text {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.06em;
  fill: var(--ink-3);
}
#bezel text.center { fill: var(--ink-2); }
#bezel polyline { fill: none; stroke: var(--ink-2); stroke-width: 1; }

#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
/* 地图上的标签按屏幕几何摆放，不随从右到左的语言镜像 */
#labels, #bezel { direction: ltr; }
.pin-name, .body-label { unicode-bidi: plaintext; }
.pin {
  position: absolute;
  left: 0; top: 0;
  display: none;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
  transition: opacity 0.3s;
}
.pin.on { display: flex; }
.pin.left { flex-direction: row-reverse; }
.pin-key {
  font-family: var(--mono);
  font-size: 10px;
  line-height: 1;
  color: var(--bg);
  background: var(--ink);
  padding: 2px 4px;
}
.pin-name { font-size: 13px; color: var(--ink); text-shadow: 0 0 8px var(--bg), 0 0 2px var(--bg); }

.body-label {
  position: absolute;
  left: 0; top: 0;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.08em;
  color: var(--ink-3);
  white-space: nowrap;
  opacity: 0;
}
.body-label::before { content: ''; display: inline-block; width: 8px; height: 1px; background: var(--ink-4); margin-inline-end: 5px; vertical-align: 3px; }
.body-label.sun { color: rgba(255, 214, 170, 0.6); }

/* ---------- 顶部 ---------- */
.top {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: var(--gutter);
  pointer-events: none;
}
.mark h1 {
  margin: 0;
  font-weight: 500;
  font-size: 22px;
  letter-spacing: 0.32em;
}
:lang(en) .mark h1, :lang(es) .mark h1, :lang(fr) .mark h1, :lang(de) .mark h1, :lang(pt) .mark h1,
:lang(ro) .mark h1, :lang(it) .mark h1, :lang(nl) .mark h1, :lang(pl) .mark h1, :lang(sv) .mark h1,
:lang(hu) .mark h1, :lang(cs) .mark h1, :lang(tr) .mark h1, :lang(id) .mark h1 {
  font-family: var(--display);
  font-style: italic;
  font-weight: 400;
  font-size: 30px;
  letter-spacing: 0.01em;
  line-height: 0.9;
}
:lang(ru) .mark h1, :lang(uk) .mark h1, :lang(el) .mark h1, :lang(vi) .mark h1 { font-size: 22px; letter-spacing: 0.12em; }
:lang(ar) .mark h1, :lang(fa) .mark h1, :lang(he) .mark h1, :lang(th) .mark h1, :lang(hi) .mark h1, :lang(bn) .mark h1 { letter-spacing: 0; font-size: 26px; }
.mark p { margin: 8px 0 0; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.18em; }
.census { text-align: end; line-height: 1.8; }
.census .live::before { content: ''; display: inline-block; width: 4px; height: 4px; border-radius: 50%; background: var(--accent); margin-inline-end: 5px; vertical-align: 2px; animation: blink 2.4s infinite; }
#population { color: var(--ink); }

/* ---------- 左：两个地点 ---------- */
.places {
  position: fixed;
  left: var(--gutter);
  top: var(--panel-top);
  bottom: var(--panel-bottom);
  width: 260px;
  display: flex;
  flex-direction: column;
  gap: 34px;
  z-index: 2;
  pointer-events: none;
}
.places > * { pointer-events: auto; }
/* 空间够时垂直居中；不够时从顶部开始排 */
.places > :first-child, .result > :first-child { margin-top: auto; }
.places > :last-child, .result > :last-child { margin-bottom: auto; }
.slot-head { display: flex; align-items: baseline; gap: 12px; border-bottom: 1px solid var(--line); padding-bottom: 9px; transition: border-color 0.2s; }
.slot:focus-within .slot-head { border-color: var(--ink-3); }
.key { color: var(--ink-3); flex: none; }
.field { position: relative; flex: 1; min-width: 0; }
.field input {
  width: 100%;
  background: transparent;
  border: 0;
  outline: none;
  padding: 0;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 17px;
  letter-spacing: 0.03em;
}
.field input::placeholder { color: var(--ink-3); font-size: 13px; letter-spacing: 0.04em; }
.place-name {
  appearance: none;
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 20px;
  letter-spacing: 0.05em;
  text-align: start;
  cursor: text;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.place-name small { font-size: 12px; color: var(--ink-2); letter-spacing: 0.04em; margin-inline-start: 8px; }
.place-name:hover small { color: var(--ink); }
.place-name[hidden], .field input[hidden] { display: none; }

.suggest {
  position: absolute;
  top: calc(100% + 12px);
  left: -8px;
  right: -8px;
  margin: 0;
  padding: 4px 0;
  list-style: none;
  background: var(--bg);
  border: 1px solid var(--line);
  z-index: 5;
}
.suggest[hidden] { display: none; }
.suggest li {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  gap: 10px;
  padding: 7px 10px;
  cursor: pointer;
}
.suggest li.active, .suggest li:hover { background: rgba(236, 235, 230, 0.06); }
.suggest .s-name { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.suggest .s-name small { font-size: 11px; color: var(--ink-3); margin-inline-start: 6px; }
.suggest .s-coord { font-family: var(--mono); font-size: 9px; color: var(--ink-3); }
.suggest .s-empty { color: var(--ink-3); font-size: 12px; cursor: default; }

.details { margin: 12px 0 0; display: grid; gap: 7px; animation: fade-up 0.6s cubic-bezier(.2, .7, .2, 1) both; }
.details[hidden] { display: none; }
.details div, .facts div { display: flex; justify-content: space-between; gap: 16px; }
dt { color: var(--ink-3); }
dd { margin: 0; color: var(--ink-2); text-align: end; }
.coord, .s-coord, #population, #utc, #percent { direction: ltr; unicode-bidi: isolate; }

/* ---------- 右：结果 ---------- */
.result {
  position: fixed;
  right: var(--gutter);
  top: var(--panel-top);
  bottom: var(--panel-bottom);
  width: 300px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  /* 内容超出时，上下边缘柔和地淡出，而不是被硬生生切断 */
  -webkit-mask-image: linear-gradient(transparent 0, #000 14px, #000 calc(100% - 22px), transparent 100%);
  mask-image: linear-gradient(transparent 0, #000 14px, #000 calc(100% - 22px), transparent 100%);
  animation: rise 0.9s cubic-bezier(.2, .7, .2, 1) 0.2s both;
}
.result[hidden] { display: none; }
.result::-webkit-scrollbar { display: none; }
.result > * { flex: none; }
.result-label { text-wrap: balance; }
.result-label { margin: 0 0 14px; font-size: 13px; color: var(--ink-2); letter-spacing: 0.12em; }
.odds {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  line-height: 0.9;
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  font-feature-settings: 'tnum' 1;
}
/* 分数始终从左往右读：1 / N */
.odds { direction: ltr; }
[dir="rtl"] .odds { justify-content: flex-end; }
.odds-one { font-size: 40px; color: var(--ink-2); }
.odds-slash { font-size: 40px; color: var(--ink-3); font-style: italic; margin: 0 0.22em 0 0.14em; }
.odds-n { font-size: 52px; letter-spacing: -0.01em; }
.odds-n .g { margin-left: 0.16em; }
.percent { margin: 12px 0 0; color: var(--ink-3); }
.verse {
  margin: 26px 0 0;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: 15px;
  line-height: 1.85;
  color: var(--ink);
  font-weight: 300;
}
.verse em { font-style: normal; color: var(--accent); }
/* 可能性的小故事 */
.stories { margin-top: 22px; }
.stories-head { display: flex; justify-content: space-between; align-items: baseline; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.12em; }
.stories-head .link { text-transform: none; letter-spacing: 0.04em; }
.story-no { color: var(--ink-4); margin-inline-start: 6px; letter-spacing: 0.06em; white-space: nowrap; display: inline-block; }
.stories-head { gap: 12px; }
.stories-head .link { white-space: nowrap; }
.story {
  margin: 12px 0 0;
  font-size: 14px;
  line-height: 1.8;
  color: var(--ink-2);
  font-weight: 300;
  min-height: 3.6em;
  animation: fade-up 0.6s cubic-bezier(.2, .7, .2, 1) both;
}
.story b { font-weight: 400; color: var(--ink); }

.facts { margin: 22px 0 0; display: grid; gap: 7px; }
.facts dd { color: var(--ink); }
.actions { display: flex; gap: 10px; margin-top: 28px; }

.btn {
  appearance: none;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--bg);
  background: var(--ink);
  border: 1px solid var(--ink);
  border-radius: 0;
  padding: 9px 14px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.btn:hover { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.btn.ghost { background: transparent; color: var(--ink-2); border-color: var(--line); }
.btn.ghost:hover { color: var(--ink); border-color: var(--ink-3); background: transparent; }

/* ---------- 底部 ---------- */
.bottom {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 6;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 16px;
  padding: var(--gutter);
  pointer-events: none;
}
.cursor { color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cursor b { font-weight: 400; color: var(--ink-2); }
.hint { color: var(--ink-2); text-align: center; transition: opacity 0.4s; }
.hint::before { content: ''; display: inline-block; width: 5px; height: 5px; background: var(--accent); margin-inline-end: 10px; vertical-align: 1px; animation: blink 2.4s infinite; }
.foot-right { justify-self: end; display: flex; align-items: baseline; gap: 18px; pointer-events: auto; }
.sound {
  appearance: none;
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--ink-3);
  cursor: pointer;
  display: inline-flex;
  align-items: baseline;
  gap: 7px;
}
.sound:hover, .sound[aria-pressed="true"] { color: var(--ink-2); }
.sound .bars { display: inline-flex; align-items: flex-end; gap: 2px; height: 9px; }
.sound .bars i { display: block; width: 2px; height: 2px; background: currentColor; }
.sound[aria-pressed="true"] .bars i { animation: eq 1.6s ease-in-out infinite; }
.sound[aria-pressed="true"] .bars i:nth-child(2) { animation-delay: -0.4s; }
.sound[aria-pressed="true"] .bars i:nth-child(3) { animation-delay: -0.9s; }
.sound[aria-pressed="true"] .bars i:nth-child(4) { animation-delay: -1.2s; }
@keyframes eq { 0%, 100% { height: 2px; } 50% { height: 9px; } }
.lang select {
  appearance: none;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  color: var(--ink-3);
  font: inherit;
  padding: 0 14px 0 0;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 4px center, right 0 center;
  background-size: 4px 4px;
  background-repeat: no-repeat;
}
.lang select:hover, .lang select:focus { color: var(--ink); outline: none; }
.lang option { background: var(--bg); color: var(--ink); }
.link {
  appearance: none;
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--ink-3);
  cursor: pointer;
  border-bottom: 1px solid var(--line);
}
.link:hover { color: var(--ink); }

/* ---------- 提示 ---------- */
.toast {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  padding: 10px 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}
.toast.on { opacity: 1; }

.loader {
  position: fixed;
  inset: 0;
  display: grid;
  place-content: center;
  grid-auto-flow: column;
  gap: 8px;
  color: var(--ink-3);
  background: var(--bg);
  transition: opacity 0.8s;
}
.loader #loader-count { color: var(--ink); }
body.ready .loader { opacity: 0; pointer-events: none; }
body:not(.ready) .top, body:not(.ready) .bottom, body:not(.ready) .places { opacity: 0; }
.top, .bottom, .places { transition: opacity 1.2s ease 0.4s; }

/* ---------- 关于 ---------- */
dialog {
  max-width: 560px;
  width: calc(100vw - 32px);
  max-height: calc(100vh - 64px);
  padding: 0;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
}
dialog::backdrop { background: rgba(11, 11, 10, 0.72); backdrop-filter: blur(2px); }
.about-inner { padding: 36px 36px 32px; position: relative; }
.about-inner h2 { margin: 0 0 20px; font-weight: 500; font-size: 20px; letter-spacing: 0.12em; }
.about-inner p { font-size: 14px; line-height: 1.9; color: var(--ink-2); margin: 0 0 14px; font-weight: 300; }
.about-inner .small { font-size: 12px; color: var(--ink-3); margin-top: 22px; }
.close {
  position: absolute;
  top: 18px; inset-inline-end: 18px;
  background: none; border: 0; color: var(--ink-3); cursor: pointer;
}
.close:hover { color: var(--ink); }
.formula {
  margin: 22px 0;
  padding: 18px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.formula p { color: var(--ink); margin: 0 0 6px; font-weight: 400; font-size: 13px; line-height: 1.8; }
.params { display: grid; gap: 10px; margin: 0; }
.params div { display: grid; grid-template-columns: 56px 1fr; gap: 12px; }
.params dd { text-align: left; }

/* ---------- 质感 ---------- */
.grain {
  position: fixed;
  inset: -50%;
  pointer-events: none;
  opacity: 0.04;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 0.9 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

@keyframes rise { from { opacity: 0; transform: translateY(12px); } }

/* 屏幕较矮时（笔记本、浏览器窗口不大），收紧右栏的字号与间距 */
@media (min-width: 901px) and (max-height: 860px) {
  .result-label { margin-bottom: 10px; }
  .odds-one, .odds-slash { font-size: 34px; }
  .odds-n { font-size: 44px; }
  .percent { margin-top: 8px; }
  .verse { margin-top: 18px; padding-top: 14px; font-size: 14px; line-height: 1.7; }
  .stories { margin-top: 16px; }
  .story { margin-top: 8px; font-size: 13px; line-height: 1.7; min-height: 0; }
  .facts { margin-top: 16px; gap: 5px; }
  .actions { margin-top: 18px; }
  .places { gap: 24px; }
  .details { margin-top: 10px; gap: 5px; }
  .facts div:last-child { display: none; }        /* "对照"与小故事里的比较重复，矮屏上先省掉 */
}
@media (min-width: 901px) and (max-height: 700px) {
  :root { --panel-top: calc(var(--gutter) + 84px); --panel-bottom: calc(var(--gutter) + 32px); }
  .facts div:nth-child(n + 4) { display: none; }   /* 太矮时只留最重要的三项 */
}
@keyframes fade-up { from { opacity: 0; transform: translateY(8px); } }
@keyframes blink { 0%, 60% { opacity: 1; } 80%, 100% { opacity: 0.15; } }

/* ---------- 窄屏 ---------- */
@media (max-width: 900px) {
  /* 手机上让整个页面滚动：地球与标题随内容一起上移，底部栏固定 */
  html, body { height: auto; overflow: visible; }
  html { overflow-y: auto; }
  body { min-height: 100%; position: relative; display: flow-root; }  /* flow-root：防止栏目的上边距穿透到页面外 */
  .stage { position: absolute; top: 0; left: 0; right: 0; bottom: auto; height: 64vh; }
  .stage::after { content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 18%; background: linear-gradient(transparent, var(--bg)); pointer-events: none; }
  .top { position: absolute; }
  .census div:last-child { display: none; }
  .places, .result {
    position: relative;
    left: auto; right: auto; top: auto; bottom: auto;
    transform: none;
    width: auto;
    margin: 0 var(--gutter);
    -webkit-mask-image: none;
    mask-image: none;
  }
  .places { margin-top: calc(64vh + 4px); gap: 26px; }
  .place-name { font-size: 18px; }
  .result { margin-top: 30px; margin-bottom: 150px; max-height: none; overflow: visible; }
  .places { margin-bottom: 120px; }
  body:has(.result:not([hidden])) .places { margin-bottom: 0; }
  .foot-right { gap: 12px; }
  .odds-n { font-size: 44px; }
  .bottom { position: fixed; grid-template-columns: 1fr; gap: 10px; padding-top: 36px; background: linear-gradient(transparent 0, var(--bg) 30px, var(--bg) 100%); }
  .cursor { display: none; }
  .hint { text-align: start; }
  .foot-right { justify-self: start; }
  @keyframes rise { from { opacity: 0; transform: translateY(12px); } }
}
