:root {
  --bg: #0f1419;
  --panel: #161c23;
  --panel-2: #1d252e;
  --line: #2a3440;
  --text: #e6ebf0;
  --muted: #8b98a7;
  --accent: #ff6b3d;
  --ok: #3ecf8e;
  --warn: #f5b942;
  --bad: #ff4d4f;
  --radius: 10px;
  font-family: "Vazirmatn", system-ui, sans-serif;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f6f8; --panel: #ffffff; --panel-2: #f0f3f6; --line: #dde3e9;
    --text: #18202a; --muted: #5d6b7a;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  display: grid; grid-template-rows: auto 1fr auto; overflow: hidden;
  font-size: 14px; line-height: 1.6;
}
button, select, input { font: inherit; color: inherit; }

/* Header */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 20px; margin: 0; font-weight: 700; }
.logo {
  width: 26px; height: 26px; border-radius: 50%;
  background: radial-gradient(circle, var(--accent) 0 28%, transparent 30% 48%, var(--accent) 50% 56%, transparent 58%);
}
.live { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.live.ok i { background: var(--ok); box-shadow: 0 0 0 0 var(--ok); animation: pulse 2s infinite; }
.live.stale i { background: var(--warn); }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  display: flex; flex-direction: column; align-items: center; min-width: 92px;
  padding: 4px 12px; background: var(--panel-2); border-radius: var(--radius); border: 1px solid var(--line);
}
.chip b { font-size: 17px; }
.chip span { font-size: 11px; color: var(--muted); }

/* Layout */
.layout { display: grid; grid-template-columns: 360px 1fr; min-height: 0; }
.panel {
  background: var(--panel); border-inline-end: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0; overflow: hidden;
}
.handle { display: none; }
.map-wrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; }

/* Filters */
.filters { padding: 12px; border-bottom: 1px solid var(--line); display: grid; gap: 10px; }
.group { display: grid; grid-template-columns: repeat(6, 1fr); background: var(--panel-2); border-radius: var(--radius); padding: 3px; }
.group button { border: 0; background: transparent; padding: 6px 4px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.group button.on { background: var(--accent); color: #fff; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row label { display: grid; gap: 2px; font-size: 12px; color: var(--muted); }
select {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px;
}
.toggles label { display: flex; align-items: center; gap: 6px; color: var(--text); font-size: 13px; cursor: pointer; }
input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; }

/* Event list */
.list { display: flex; flex-direction: column; }
.list-head { display: flex; justify-content: space-between; padding: 8px 12px; font-size: 12px; border-bottom: 1px solid var(--line); }
.muted { color: var(--muted); }
#events { list-style: none; margin: 0; padding: 0; }
#events li {
  display: grid; grid-template-columns: 46px 1fr; gap: 10px; align-items: center;
  padding: 8px 12px; border-bottom: 1px solid var(--line); cursor: pointer;
}
#events li:hover, #events li.sel { background: var(--panel-2); }
.mag {
  width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; font-size: 15px; color: #fff;
}
.ev-place { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: ltr; text-align: right; }
.ev-meta { font-size: 12px; color: var(--muted); }

/* Detail */
.detail { padding: 12px; border-bottom: 1px solid var(--line); background: var(--panel-2); }
.detail h2 { margin: 0 0 4px; font-size: 16px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.detail .close { border: 0; background: transparent; cursor: pointer; font-size: 20px; color: var(--muted); }
.detail dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 8px 0 0; font-size: 13px; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; }
.detail h3 { font-size: 13px; margin: 12px 0 0; color: var(--accent); }
.ltr { direction: ltr; unicode-bidi: isolate; }

/* Legend */
.legend {
  position: absolute; bottom: 28px; left: 12px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 8px 10px; font-size: 12px; display: grid; gap: 4px;
}
.legend .sw { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-inline-start: 6px; vertical-align: middle; }

.note { padding: 6px 16px; font-size: 11px; color: var(--muted); border-top: 1px solid var(--line); background: var(--panel); }

/* Map popups */
.maplibregl-popup-content { background: var(--panel); color: var(--text); font-family: inherit; border-radius: 8px; padding: 8px 10px; }
.maplibregl-popup-tip { display: none; }

/* Phone: map on top, list as a bottom sheet */
@media (max-width: 760px) {
  .top { padding: 8px 12px; gap: 8px; }
  .chips { width: 100%; display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
  .chip { min-width: 0; padding: 2px 4px; }
  .chip b { font-size: 14px; }
  .chip span { font-size: 9px; text-align: center; line-height: 1.3; }
  .layout { grid-template-columns: 1fr; position: relative; }
  .map-wrap { grid-row: 1; grid-column: 1; }
  .panel {
    grid-row: 1; grid-column: 1; align-self: end; z-index: 2; height: 46%;
    border: 0; border-top: 1px solid var(--line); border-radius: 16px 16px 0 0;
    transition: height .25s;
  }
  .panel.min { height: 92px; }
  .handle { display: block; border: 0; background: transparent; height: 18px; cursor: pointer; flex: none; }
  .handle::before { content: ""; display: block; margin: 6px auto; width: 40px; height: 4px; border-radius: 2px; background: var(--line); }
  .legend { bottom: calc(46% + 10px); }
  .note { display: none; }
}

.nomap { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; color: var(--muted); }
#events { overflow-x: hidden; }
#events li > div { min-width: 0; }

/* v5: scrolling panel, more filters, per-year chart */
.scroll { flex: 1; overflow-y: auto; overflow-x: hidden; min-height: 0; }
.list-head { position: sticky; top: 0; background: var(--panel); z-index: 1; }
.group button { font-size: 12px; padding: 6px 2px; }
.row.three { grid-template-columns: 1.3fr 1fr 1fr; }
.row input[type=search] {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; width: 100%;
}
.row label.check { display: flex; align-items: center; gap: 6px; color: var(--text); font-size: 12px; }
details { border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 10px; display: grid; gap: 8px; }
details[open] { padding-bottom: 10px; }
details[open] > summary { margin-bottom: 8px; }
summary { cursor: pointer; color: var(--text); font-size: 13px; }
.badge { background: var(--accent); color: #fff; border-radius: 9px; padding: 0 7px; font-size: 11px; margin-inline-start: 4px; }
.seasons { border: 0; padding: 0; margin: 0 0 8px; display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; }
.seasons legend { font-size: 12px; color: var(--muted); padding: 0; margin-bottom: 2px; }
.seasons label { display: flex; align-items: center; gap: 4px; cursor: pointer; }
.toggles { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; }
button.link { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0; font-size: 12px; margin-inline-start: auto; }
.small { font-size: 11px; }

.years { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.years-head { display: flex; justify-content: space-between; align-items: center; font-size: 13px; margin-bottom: 6px; }
.years-head select { font-size: 12px; padding: 2px 6px; }
.bars { display: flex; align-items: flex-end; gap: 1px; height: 90px; direction: ltr; }
.bars button {
  flex: 1; min-width: 2px; border: 0; padding: 0; background: var(--accent); opacity: .55; cursor: pointer;
  border-radius: 2px 2px 0 0; position: relative;
}
.bars button:hover, .bars button.on { opacity: 1; }
.bars button.on { background: #ffb02e; }
.bars-axis { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); direction: ltr; margin-top: 2px; }
.legend .note2 { max-width: 190px; font-size: 11px; color: var(--muted); line-height: 1.4; }
.heat-bar { height: 8px; border-radius: 4px; background: linear-gradient(to left, #7a0177, #c51b8a, #f768a1, #fbb4b9, rgba(254,235,226,.3)); }

@media (max-width: 760px) {
  .legend { font-size: 10px; padding: 4px 6px; gap: 1px; left: 8px; }
  .legend .sw { width: 9px; height: 9px; }
  .legend .note2 { display: none; }
  .bars { height: 70px; }
}

/* v9: Persian location text */
.ev-place.fa { direction: rtl; text-align: right; }
.loc-fa { font-weight: 500; }
.detail dd.ltr { text-align: right; font-size: 12px; color: var(--muted); }
.note a { color: inherit; }

/* v10: point history */
.near-chip {
  display: flex; align-items: center; gap: 8px; background: var(--accent); color: #fff;
  border-radius: var(--radius); padding: 6px 10px; font-size: 13px;
}
.near-chip span { flex: 1; }
.near-chip select { background: rgba(255,255,255,.15); border: 0; color: #fff; font-size: 12px; padding: 2px 4px; }
.near-chip select option { color: #000; }
.near-chip button { border: 0; background: none; color: #fff; font-size: 20px; cursor: pointer; line-height: 1; }
.history { padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--panel-2); font-size: 13px; }
.history h3 { margin: 0 0 6px; font-size: 14px; }
.history table { width: 100%; border-collapse: collapse; margin: 6px 0; }
.history th, .history td { text-align: right; padding: 3px 4px; border-bottom: 1px solid var(--line); font-weight: normal; }
.history th { color: var(--muted); font-size: 12px; }
.history ol { margin: 4px 0 0; padding-inline-start: 18px; }
.history li { cursor: pointer; }
.history li:hover { color: var(--accent); }
.btn {
  border: 1px solid var(--accent); color: var(--accent); background: transparent; border-radius: 8px;
  padding: 5px 10px; cursor: pointer; font-size: 13px;
}
.btn:hover { background: var(--accent); color: #fff; }
.detail .actions { display: flex; gap: 8px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.near-chip[hidden], .history[hidden] { display: none; }

/* v15: circle close button, hover popup */
.circle-close {
  width: 32px; height: 32px; border-radius: 50%; border: 2px solid #fff; background: var(--accent); color: #fff;
  font-size: 20px; line-height: 1; cursor: pointer; display: grid; place-items: center; padding: 0;
  box-shadow: 0 2px 6px rgba(0,0,0,.35);
}
.circle-close:hover { filter: brightness(1.1); }
.hover-pop .maplibregl-popup-content { direction: rtl; text-align: right; font-size: 12px; line-height: 1.7; padding: 6px 10px; pointer-events: none; }
.hover-pop .hp-mag { font-weight: 700; font-size: 13px; }

/* v16: links in the list, server-rendered pages */
a.ev-link { color: inherit; text-decoration: none; }
a.ev-link:hover { text-decoration: underline; }
a.btn { text-decoration: none; display: inline-block; }
body.page { display: block; overflow: auto; }
.home-link { color: inherit; text-decoration: none; font-size: 20px; }
.article { max-width: 760px; margin: 0 auto; padding: 20px 16px 40px; }
.article h1 { font-size: 26px; margin: 8px 0 4px; }
.article h2 { font-size: 17px; margin: 24px 0 8px; }
.article .lead { font-size: 17px; margin: 0 0 16px; }
.article .chips { justify-content: flex-start; margin: 12px 0; }
table.facts { width: 100%; border-collapse: collapse; margin: 8px 0 18px; }
table.facts th, table.facts td { text-align: right; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.facts th { color: var(--muted); font-weight: 500; width: 38%; }
.sbar { height: 10px; background: var(--accent); border-radius: 3px; min-width: 2px; }

/* v18: site nav, visit badge, list pages */
.site-nav { display: flex; gap: 14px; font-size: 13px; }
.site-nav a { color: var(--muted); text-decoration: none; }
.site-nav a:hover { color: var(--accent); }
.visits { font-size: 12px; color: var(--muted); background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 3px 10px; white-space: nowrap; }
.visits b { color: var(--text); font-weight: 500; }
.crumbs { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.crumbs a { color: var(--muted); }
.qlist { padding-inline-start: 0; list-style: none; margin: 6px 0 16px; }
.qlist li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.qlist a { color: var(--text); }
.mag-s { display: inline-block; min-width: 34px; text-align: center; background: var(--accent); color: #fff;
  border-radius: 6px; padding: 0 6px; font-weight: 700; font-size: 13px; }
ul.cols { columns: 2 240px; padding-inline-start: 18px; }
ul.cols li { break-inside: avoid; margin-bottom: 4px; }
ul.cols a { color: var(--text); }
body.page .top { flex-wrap: wrap; }
@media (max-width: 760px) {
  .site-nav { order: 3; width: 100%; justify-content: center; }
  .top .visits { font-size: 11px; }
}

/* v19: professional earthquake lists */
body.page { font-size: 15px; line-height: 1.85; }
.article { max-width: 880px; }
.article h1 { font-size: 28px; font-weight: 700; }
.article .lead { color: var(--muted); font-size: 15px; }
.summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 14px 0 18px; }
.summary div { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; text-align: center; }
.summary b { display: block; font-size: 22px; font-weight: 700; }
.summary span { color: var(--muted); font-size: 12px; }
.qcards { list-style: none; padding: 0; margin: 8px 0 22px; display: grid; gap: 8px; }
.qcard { display: grid; grid-template-columns: 52px 1fr auto; gap: 14px; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
.qcard:hover { border-color: var(--accent); }
.qmag { width: 48px; height: 48px; border-radius: 12px; display: grid; place-items: center; color: #fff;
  font-weight: 700; font-size: 18px; }
.qmag.m2 { background: #5f8fb4; } .qmag.m3 { background: #e0a526; } .qmag.m4 { background: #f07a2a; }
.qmag.m5 { background: #e0392b; } .qmag.m6 { background: #8e1020; }
.qbody { min-width: 0; }
.qplace { color: var(--text); text-decoration: none; font-weight: 500; font-size: 16px; display: block; }
.qplace:hover { color: var(--accent); }
.qmeta { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; color: var(--muted); margin-top: 2px; }
.qmeta .qtime { color: var(--text); font-weight: 500; }
.qact { display: flex; gap: 6px; }
.qbtn { font-size: 13px; padding: 5px 12px; border-radius: 8px; background: var(--accent); color: #fff;
  text-decoration: none; white-space: nowrap; }
.qbtn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.qbtn:hover { filter: brightness(1.1); }
.empty-note { padding: 12px 0; }
@media (max-width: 640px) {
  .summary { grid-template-columns: repeat(2, 1fr); }
  .qcard { grid-template-columns: 44px 1fr; gap: 10px; padding: 10px; }
  .qmag { width: 42px; height: 42px; font-size: 16px; }
  .qact { grid-column: 1 / -1; }
  .qbtn { flex: 1; text-align: center; }
}

/* v20: full navbar, FAQ, responsive for every size */
.site-nav { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.site-nav::-webkit-scrollbar { display: none; }
.site-nav a { white-space: nowrap; padding: 5px 10px; border-radius: 8px; font-size: 13px; }
.site-nav a:hover { background: var(--panel-2); color: var(--text); }
.site-nav a[aria-current="page"] { color: var(--accent); background: var(--panel-2); font-weight: 500; }
details.faq { border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; margin: 8px 0; background: var(--panel); }
details.faq summary { font-weight: 500; font-size: 16px; }
details.faq p { margin: 8px 0 0; color: var(--text); }
.article ul a { color: var(--text); }
img, svg, video { max-width: 100%; }
/* tablets only (phones have their own rules below) */
@media (min-width: 761px) and (max-width: 1100px) {
  .layout { grid-template-columns: 320px 1fr; }
  .chip { min-width: 78px; padding: 4px 8px; }
}
/* flex/grid children must be allowed to shrink, or a long row widens the whole page */
.site-nav, .chips, .brand, .qbody, .detail, .panel, .map-wrap { min-width: 0; }
/* phones: nav gets its own scrollable row */
@media (max-width: 760px) {
  .top { row-gap: 6px; }
  .brand { flex: 1; min-width: 0; }
  .brand h1 { font-size: 18px; }
  .live { font-size: 11px; }
  .site-nav { order: 3; width: 100%; max-width: 100%; justify-content: flex-start; }
  .chips { width: 100%; }
  .chip { min-width: 0; }
  .top > .visits { order: 2; }
  .chips { order: 4; }
  .article { padding: 14px 12px 32px; }
  .article h1 { font-size: 22px; }
  table.facts th { width: 42%; }
  table.facts th, table.facts td { padding: 6px 4px; font-size: 14px; }
  .group button { font-size: 11px; padding: 6px 0; }
  .row.three { grid-template-columns: 1fr 1fr 1fr; }
  .detail .actions .btn { flex: 1; text-align: center; }
}
/* small phones (320-380px) */
@media (max-width: 380px) {
  .brand .live { display: none; }
  .chip b { font-size: 13px; }
  .chip span { font-size: 8.5px; }
  .group { grid-template-columns: repeat(3, 1fr); row-gap: 3px; }
  .row, .row.three { grid-template-columns: 1fr 1fr; }
  .summary b { font-size: 18px; }
  .qplace { font-size: 15px; }
  .visits { font-size: 10.5px; padding: 2px 8px; }
}
/* large screens */
@media (min-width: 1600px) {
  .layout { grid-template-columns: 420px 1fr; }
  .article { max-width: 980px; }
}

/* the page grid column never grows past the screen */
body { grid-template-columns: minmax(0, 1fr); }
.top, .layout, .note { min-width: 0; max-width: 100vw; }
@media (max-width: 760px) { .layout { grid-template-columns: minmax(0, 1fr); } .group { grid-template-columns: repeat(3, minmax(0, 1fr)); row-gap: 3px; } .row, .row.three { grid-template-columns: repeat(2, minmax(0, 1fr)); } .chips { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
