/* World Atlas — styles */
:root {
  --space: #04060c;
  --panel: rgba(12, 17, 26, 0.9);
  --panel-solid: #0c1119;
  --line: rgba(170, 190, 215, 0.16);
  --line-strong: rgba(170, 190, 215, 0.32);
  --ink: #e8eef6;
  --dim: #95a2b4;
  --faint: #6c7888;
  --red: #ff1f2e;
  --grey: #d9dce1;
  --accent: #9fd2ff;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font-lang, ui-sans-serif, system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif);
  background: var(--space);
  color: var(--ink);
  font: 15px/1.35 ui-sans-serif, system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  grid-template-rows: 56px minmax(0, 1fr) auto;
  height: 100vh;
  height: 100dvh;
}

/* header */
.head {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(4, 6, 12, 0.94);
  position: relative;
  z-index: 5;
  min-width: 0;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-size: 17px;
  font-weight: 650;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand__dot {
  width: 18px; height: 18px; flex: none; border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #ffd9dc 0 7%, var(--red) 34%, #7b0811 100%);
  box-shadow: 0 0 12px rgba(255, 31, 46, 0.55);
}
.head__spacer { flex: 1 1 auto; }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 32px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 999px;
  background: transparent; cursor: pointer;
  font-size: 13px; white-space: nowrap;
  transition: background-color .15s, border-color .15s;
}
.btn:hover { background: rgba(255, 255, 255, 0.07); border-color: var(--line-strong); }
.btn[aria-pressed="false"] { color: var(--dim); }
.btn:disabled { opacity: .45; cursor: default; }
.only-narrow { display: none; }

/* stage */
.stage { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
#globe, #sky { position: absolute; inset: 0; width: 100%; height: 100%; }
#globe { touch-action: none; cursor: grab; }
#globe:active { cursor: grabbing; }
.hint {
  position: absolute; left: 16px; bottom: 12px; margin: 0;
  font-size: 12px; color: var(--faint); pointer-events: none;
}
.tip {
  position: absolute; z-index: 3; left: 0; top: 0;
  padding: 4px 9px; border: 1px solid var(--line); border-radius: 8px;
  background: rgba(6, 9, 15, 0.92); color: var(--ink);
  font-size: 13px; font-weight: 550; white-space: nowrap;
  pointer-events: none; opacity: 0;
  transform: translate(-50%, calc(-100% - 16px));
  transition: opacity .12s;
}
.tip[data-on="1"] { opacity: 1; }

/* panel */
.panel {
  display: flex; flex-direction: column; min-height: 0;
  border-left: 1px solid var(--line);
  background: var(--panel-solid);
}
.panel__head { display: grid; gap: 10px; padding: 12px 14px 10px; border-bottom: 1px solid var(--line); }
.panel__row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.panel__title { margin: 0; font-size: 15px; font-weight: 650; }
.panel__note { margin: 0; font-size: 12px; color: var(--dim); font-variant-numeric: tabular-nums; }
.handle { display: none; }

.hud { display: grid; gap: 4px; }
.hud__line { margin: 0; display: flex; align-items: baseline; gap: 6px; font-variant-numeric: tabular-nums; }
.hud__n { font-size: 32px; font-weight: 720; line-height: 1; color: var(--red); text-shadow: 0 0 20px rgba(255, 31, 46, 0.5); }
#hud-total { font-size: 14px; color: var(--dim); }
.hud__pct { margin: 0; font-size: 13px; color: var(--dim); font-variant-numeric: tabular-nums; }
#hud-pct { color: var(--ink); font-weight: 600; }
.hud__bonus { color: #ffc0c4; font-size: 12px; }
.bars { display: grid; gap: 5px; margin: 8px 0 0; padding: 0; list-style: none; }
.bar { display: grid; gap: 3px; }
.bar__row { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--dim); font-variant-numeric: tabular-nums; }
.bar__rail { height: 6px; border-radius: 999px; background: rgba(217, 220, 225, 0.13); overflow: hidden; }
.bar__fill { height: 100%; border-radius: inherit; transition: width .3s; }

.search {
  width: 100%; height: 38px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: rgba(255, 255, 255, 0.05); font-size: 14px;
}
.search::placeholder { color: var(--dim); }
.search:focus { border-color: rgba(159, 210, 255, 0.55); outline: none; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip {
  height: 26px; padding: 0 11px; border: 1px solid var(--line); border-radius: 999px;
  background: transparent; color: var(--dim); font-size: 12px; cursor: pointer;
}
.chip:hover { color: var(--ink); border-color: var(--line-strong); }
.chip[aria-pressed="true"] { color: var(--ink); background: rgba(217, 220, 225, 0.13); border-color: rgba(217, 220, 225, 0.5); }
.chips__count { margin-left: auto; font-size: 11.5px; color: var(--faint); font-variant-numeric: tabular-nums; }

.list { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0 8px 12px; }
/* Section heading that sticks while its group scrolls. It must be fully
   opaque and above the rows it floats over, with room for the sticky slide
   (scroll-margin) so a row never ends up underneath the heading. */
.group {
  position: sticky; top: 0; z-index: 3; margin: 0;
  padding: 12px 6px 8px; font-size: 11.5px; font-weight: 650;
  letter-spacing: .09em; text-transform: uppercase; color: var(--dim);
  background: var(--panel-solid);
  box-shadow: 0 6px 6px -6px rgba(0, 0, 0, 0.8);
}
.group__count { margin-left: 6px; color: var(--faint); letter-spacing: 0; text-transform: none; font-weight: 500; font-variant-numeric: tabular-nums; }
.group__list { margin: 0; padding: 0; list-style: none; }
.item { display: flex; align-items: center; gap: 6px; border-radius: 9px; scroll-margin: 46px 0 46px; }
/* .item sets display, which would otherwise beat the default hidden rule */
.item[hidden], .group[hidden], .group__list[hidden] { display: none; }
.item:hover { background: rgba(255, 255, 255, 0.05); }
.item__label { flex: 1 1 auto; display: flex; align-items: center; gap: 10px; min-width: 0; min-height: 36px; padding: 2px 6px; cursor: pointer; }
.item__box {
  appearance: none; -webkit-appearance: none; flex: none;
  width: 18px; height: 18px; margin: 0; position: relative;
  border: 1.5px solid rgba(217, 220, 225, 0.48); border-radius: 5px;
  background: transparent; cursor: pointer;
  transition: background-color .15s, border-color .15s, box-shadow .15s;
}
.item__box:checked { background: var(--red); border-color: var(--red); box-shadow: 0 0 9px rgba(255, 41, 55, 0.6); }
.item__box:checked::after {
  content: ""; position: absolute; left: 5px; top: 1px; width: 4px; height: 8px;
  border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(42deg);
}
.item__name { flex: 1 1 auto; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 14px; }
.item.is-visited .item__name { color: #ffd9dc; }
.item__code { flex: none; font-size: 10.5px; color: var(--faint); font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.item__bonus { flex: none; font-size: 11px; color: var(--faint); }
.item__go {
  flex: none; width: 28px; height: 28px; margin-right: 4px;
  border: 1px solid transparent; border-radius: 7px; background: transparent;
  color: var(--dim); font-size: 13px; cursor: pointer; opacity: 0;
  transition: opacity .12s, color .12s, border-color .12s;
}
.item:hover .item__go, .item__go:focus-visible { opacity: 1; }
.item__go:hover { color: var(--ink); border-color: var(--line-strong); }
.list__empty { margin: 0; padding: 22px 14px; text-align: center; font-size: 13.5px; color: var(--dim); }
.panel__foot { display: flex; gap: 6px; padding: 10px 12px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.panel__foot .btn { height: 30px; padding: 0 11px; font-size: 12.5px; }

/* footer */
.foot {
  grid-column: 1 / -1;
  display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center;
  padding: 7px 14px; border-top: 1px solid var(--line);
  background: rgba(4, 6, 12, 0.96);
  font-size: 11.5px; color: var(--dim);
}
.foot p { margin: 0; }
.foot__warn { color: #ffc0c4; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 48px; z-index: 20;
  max-width: min(460px, calc(100% - 28px));
  padding: 9px 14px; border: 1px solid var(--line); border-radius: 10px;
  background: rgba(13, 18, 27, 0.97); font-size: 13px; text-align: center;
  opacity: 0; transform: translate(-50%, 8px); pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast[data-on="1"] { opacity: 1; transform: translate(-50%, 0); }

/* narrow screens: the list becomes a bottom drawer */
@media (max-width: 760px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 52px minmax(0, 1fr) auto;
  }
  .head { padding: 0 10px; gap: 6px; }
  .brand { font-size: 15px; gap: 7px; }
  .brand__dot { width: 15px; height: 15px; }
  .head .btn { height: 30px; padding: 0 10px; font-size: 12.5px; }
  .only-narrow { display: inline-flex; }
  .only-wide { display: none; }
  .panel {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
    height: min(72dvh, 600px);
    border-left: 0; border-top: 1px solid var(--line-strong);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -20px 44px rgba(0, 0, 0, 0.55);
    transform: translateY(103%);
    visibility: hidden;
    transition: transform .22s ease, visibility 0s linear .22s;
  }
  .panel[data-open="1"] { transform: translateY(0); visibility: visible; transition: transform .22s ease, visibility 0s; }
  .handle { display: block; width: 42px; height: 4px; margin: 7px auto 0; border-radius: 999px; background: rgba(217, 220, 225, 0.3); }
  /* on a phone the drawer is short: keep the list the star of the show */
  .panel .hud .bars { display: none; }
  .panel .hud__n { font-size: 22px; }
  .panel__head { gap: 8px; padding: 8px 12px 8px; }
  .hud__n { font-size: 26px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.001ms !important; animation-duration: 0.001ms !important; }
}

/* ------------------------------------------------------------------ language */
.lang {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 30px;
  padding: 0 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
}
.lang__btn {
  border: 0;
  background: transparent;
  color: var(--dim);
  font-size: 12.5px;
  padding: 3px 7px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.lang__btn:hover { color: var(--ink); }
.lang__btn[aria-pressed="true"] { color: var(--ink); background: rgba(217, 220, 225, 0.16); }
.lang__sep { color: var(--faint); font-size: 11px; }

/* CJK: slightly more line-height and no letter-spacing on Chinese text */
html[data-lang="zh-Hans"] body { line-height: 1.5; }
html[data-lang="zh-Hans"] .item__name { letter-spacing: 0; }

/* ------------------------------------------------------------ narrow header */
@media (max-width: 760px) {
  .head { gap: 4px; padding: 0 8px; }
  .brand { flex: 0 1 auto; min-width: 0; overflow: hidden; }
  .brand__name { overflow: hidden; text-overflow: ellipsis; }
  .head .btn { padding: 0 8px; }
  .lang { padding: 0 2px; }
  .lang__btn { padding: 3px 5px; }
  /* the attribution line lives in the README + nginx footer comment; on a
     phone it costs a whole row of globe height */
  .foot > p:first-child { display: none; }
}

/* --------------------------------------------------------------- subdivisions */
.item__main { flex: 1 1 auto; min-width: 0; }
.item__subs {
  flex: none;
  width: 22px; height: 22px;
  margin-left: 2px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: transparent;
  color: var(--dim);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  transition: transform .15s;
}
.item__subs.is-open { transform: rotate(90deg); }
.item__subs-count { flex: none; font-size: 11px; color: var(--faint); font-variant-numeric: tabular-nums; }
.subs { margin: 0 0 4px 26px; padding: 0; list-style: none; border-left: 1px solid var(--line); }
.subs[hidden] { display: none; }
.sub { display: flex; align-items: center; }
.sub__label { min-height: 30px; padding-left: 10px; }
.sub .item__box--sub { width: 15px; height: 15px; }
.sub .item__name { font-size: 13px; color: var(--dim); }
.sub.is-visited .item__name { color: #ffd9dc; }
.sub[hidden] { display: none; }

/* -------------------------------------------------------------------- modal */
.modal { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px; }
.modal[hidden] { display: none; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(2, 5, 10, 0.66); backdrop-filter: blur(2px); }
.modal__box {
  position: relative;
  width: min(620px, 100%);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  display: grid;
  gap: 12px;
  padding: 18px;
  border: 1px solid var(--hairline-2);
  border-radius: 16px;
  background: var(--panel-solid);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}
.modal__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.modal__title { margin: 0; font-size: 17px; font-weight: 650; }
.modal__help { margin: 0; color: var(--dim); font-size: 13px; line-height: 1.45; }
.modal__text {
  width: 100%;
  min-height: 160px;
  resize: vertical;
  padding: 10px 12px;
  border: 1px solid var(--hairline);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  font: inherit;
  font-size: 13.5px;
  line-height: 1.5;
  font-family: var(--font-lang, inherit);
  white-space: pre;
  overflow: auto;
}
.modal__text:focus { outline: 2px solid var(--ring); outline-offset: 1px; }
.modal__row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.modal__file { color: var(--faint); font-size: 12px; }
.modal__mode { margin: 0; padding: 8px 10px; border: 1px solid var(--hairline); border-radius: 10px; display: flex; gap: 18px; flex-wrap: wrap; font-size: 13px; }
.modal__mode legend { padding: 0 4px; color: var(--dim); font-size: 12px; }
.modal__mode label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.modal__result { font-size: 13.5px; }
.modal__result[data-state="ok"] { color: #9ff0c0; }
.modal__result[data-state="partial"] { color: #ffd58a; }
.modal__result[data-state="none"] { color: var(--dim); }
.modal__unmatched { margin: 0; padding: 0 0 0 18px; max-height: 120px; overflow: auto; color: #ffc0c4; font-size: 12.5px; }
.modal__unmatched:empty { display: none; }
.modal__actions { display: flex; justify-content: flex-end; gap: 8px; }
.btn--primary { border-color: rgba(255, 31, 46, 0.7); background: rgba(255, 31, 46, 0.16); }
.btn--primary:hover { background: rgba(255, 31, 46, 0.26); border-color: rgba(255, 31, 46, 0.9); }
.btn--primary:disabled { opacity: 0.4; }
body.modal-open { overflow: hidden; }
