:root {
  --bg: #0f1218;
  --panel: #171c26;
  --panel-2: #1f2633;
  --line: #2b3445;
  --text: #e8ecf3;
  --muted: #97a3b8;
  --accent: #ff5fa2;
  --accent-2: #37c8e0;
  --ok: #4fd08a;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Rubik", "Assistant", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
}

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  height: 54px;
  padding: 0 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 17px; letter-spacing: .2px; white-space: nowrap; }
.brand span { color: var(--accent); }
.nav { display: flex; gap: 4px; }
.nav a {
  padding: 7px 13px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 600;
}
.nav a:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--panel-2); color: var(--text); }
.topbar .note { margin-inline-start: auto; color: var(--muted); font-size: 12.5px; }

/* ---------- map page ---------- */
.map-layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  height: calc(100% - 54px);
}
.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-inline-end: 1px solid var(--line);
}
.sidebar .block { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.sidebar h2 { margin: 0 0 8px; font-size: 13px; color: var(--muted); font-weight: 600; }

input[type="search"], input[type="text"], select, textarea {
  width: 100%;
  padding: 9px 11px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-2); outline-offset: -1px; }
textarea { resize: vertical; min-height: 60px; }

.cats { display: flex; flex-wrap: wrap; gap: 6px; }
.cat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}
.cat .n { color: var(--muted); font-size: 12px; }
.cat.off { opacity: .4; }
.cat:hover { border-color: var(--accent-2); }

.results { flex: 1; overflow-y: auto; min-height: 0; }
.result {
  display: flex;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  color: inherit;
  font: inherit;
  text-align: start;
  cursor: pointer;
}
.result:hover { background: var(--panel-2); }
.result .ico { font-size: 19px; line-height: 1.3; }
.result .t { font-weight: 600; }
.result .d { color: var(--muted); font-size: 13px; }
.empty { padding: 22px 14px; color: var(--muted); text-align: center; }

.btn {
  padding: 8px 12px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1a0b12; }
.btn.on { background: var(--ok); border-color: var(--ok); color: #06200f; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.stack > * + * { margin-top: 8px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 6px 0 0; }
[hidden] { display: none !important; }

#map { height: 100%; background: #14507a; }
.leaflet-container { font: inherit; }
.pin {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .55);
  font-size: 16px;
}
.pin.mine { border-style: dashed; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); color: var(--text); }
.leaflet-popup-content { margin: 12px 14px; direction: rtl; text-align: right; min-width: 190px; }
.popup h3 { margin: 0 0 2px; font-size: 16px; }
.popup .cat-name { color: var(--muted); font-size: 12.5px; }
.popup p { margin: 8px 0 0; }
.popup .coords { margin-top: 8px; color: var(--muted); font-size: 12px; direction: ltr; text-align: left; }
.popup .del { margin-top: 8px; }

/* ---------- content pages ---------- */
.page { max-width: 980px; margin: 0 auto; padding: 26px 20px 60px; }
.page h1 { margin: 0 0 6px; font-size: 27px; }
.page .lead { color: var(--muted); margin: 0 0 20px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.card {
  display: block;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: inherit;
}
.card:hover { border-color: var(--accent-2); text-decoration: none; }
.card .tag { color: var(--accent); font-size: 12.5px; font-weight: 700; }
.card h3 { margin: 4px 0 6px; font-size: 17px; }
.card p { margin: 0; color: var(--muted); font-size: 14px; }

.article { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px 24px; }
.article h2 { margin: 22px 0 6px; font-size: 19px; }
.article h2:first-child { margin-top: 0; }
.article li { margin: 4px 0; }
.back { display: inline-block; margin-bottom: 14px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; background: var(--panel); }
th, td { padding: 10px 14px; border-bottom: 1px solid var(--line); text-align: start; vertical-align: top; }
th { background: var(--panel-2); color: var(--muted); font-size: 13px; }
tr:last-child td { border-bottom: 0; }
td.en { direction: ltr; text-align: left; font-family: Consolas, "Courier New", monospace; font-size: 14px; }
td.note { color: var(--muted); font-size: 14px; }
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input { flex: 1; min-width: 200px; }
.toolbar select { width: auto; }

.sample-banner {
  margin-bottom: 16px;
  padding: 10px 14px;
  background: rgba(255, 95, 162, .1);
  border: 1px solid rgba(255, 95, 162, .4);
  border-radius: var(--radius);
  font-size: 14px;
}

/* ---------- mobile ---------- */
@media (max-width: 780px) {
  .topbar { gap: 8px; padding: 0 10px; }
  .topbar .note { display: none; }
  .brand { font-size: 15px; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .nav { flex-shrink: 0; }
  .nav a { padding: 6px 9px; }
  .map-layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: 46vh minmax(0, 1fr); }
  .map-layout > * { min-width: 0; }
  .sidebar { order: 2; border-inline-end: 0; border-top: 1px solid var(--line); }
  .page { padding: 18px 14px 50px; }
}

/* ---------- 3D map ---------- */
#stage {
  position: relative;
  overflow: hidden;
  min-height: 0;
  background: linear-gradient(#4aa6e8 0%, #9fd4f2 55%, #d9f0fb 100%);
}
#stage.sunset { background: linear-gradient(#2a1b5e 0%, #b0468f 45%, #ff9a6b 80%, #ffd28a 100%); }
#stage canvas { display: block; width: 100%; height: 100%; cursor: grab; }
#stage canvas:active { cursor: grabbing; }
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.l3 {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: auto;
  cursor: pointer;
  font: inherit;
  direction: rtl;
  white-space: nowrap;
  will-change: transform;
}
.l3.region {
  padding: 5px 12px 6px;
  background: rgba(15, 18, 24, .82);
  border: 0;
  border-bottom: 3px solid var(--c);
  border-radius: 8px;
  color: #fff;
  text-align: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .35);
}
.l3.region b { display: block; font-size: 15px; }
.l3.region small { display: block; direction: ltr; color: #b9c3d4; font-size: 11px; }
.l3.region:hover { background: rgba(15, 18, 24, .95); }
.l3.pin3 {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 2px solid #fff;
  border-radius: 50%;
  font-size: 14px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .5);
}
.l3.pin3.off { visibility: hidden; }

.region-list { display: grid; gap: 6px; }
.region-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  text-align: start;
  cursor: pointer;
}
.region-btn:hover, .region-btn.active { border-color: var(--c); }
.region-btn .dot { width: 11px; height: 11px; border-radius: 50%; background: var(--c); flex: none; }
.region-btn b { display: block; font-size: 14px; }
.region-btn small { display: block; color: var(--muted); font-size: 12px; direction: ltr; text-align: right; }
.sidebar .popup h3 { margin: 0 0 2px; font-size: 16px; }
.sidebar .popup p { margin: 8px 0 0; }
.check { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.sidebar { overflow-y: auto; }

/* ---------- 2D vector map labels ---------- */
.rlabel {
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
  text-shadow: 0 1px 4px #000, 0 0 2px #000;
  transform: translate(-50%, 20px);
  direction: rtl;
  pointer-events: none;
}

/* ---------- small screens: compact header and map labels ---------- */
@media (max-width: 780px) {
  .brand .w { display: none; }
  .nav a { padding: 6px 8px; font-size: 14px; }
  .l3.region { padding: 3px 8px 4px; border-bottom-width: 2px; }
  .l3.region b { font-size: 12px; }
  .l3.region small { display: none; }
  .l3.pin3 { width: 24px; height: 24px; font-size: 12px; }
  .rlabel { font-size: 11px; }
}

/* ---------- missions page ---------- */
.mlist { display: grid; gap: 8px; }
.mcard { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.mcard[open] { border-color: var(--accent-2); }
.mcard summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 11px 14px;
  cursor: pointer;
  list-style: none;
}
.mcard summary::-webkit-details-marker { display: none; }
.mtitle { font-weight: 700; flex: 1; min-width: 140px; }
.tag { padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--panel-2); color: var(--muted); }
.tag.t-mission { background: rgba(255, 95, 162, .16); color: var(--accent); }
.tag.t-activity { background: rgba(55, 200, 224, .16); color: var(--accent-2); }
.tag.t-tutorial { background: rgba(79, 208, 138, .16); color: var(--ok); }
.chip { padding: 2px 9px; border: 1px solid var(--line); border-radius: 999px; font-size: 12px; color: var(--muted); }
.chip.warn { border-color: #f5b942; color: #f5b942; }
.chip.en { direction: ltr; }
.mbody { padding: 0 16px 14px; border-top: 1px solid var(--line); }
.mbody p { margin: 12px 0 0; }
.mbody h4 { margin: 14px 0 4px; font-size: 13px; color: var(--muted); }
.mbody ol, .mbody ul { margin: 0; padding-inline-start: 22px; }
.mbody li { margin: 3px 0; }
.people { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
@media (max-width: 780px) {
  .nav { overflow-x: auto; }
  .nav a { padding: 6px 7px; font-size: 13.5px; white-space: nowrap; }
}
