/* ============================================================
   Kronik Dunia - gaya tampilan
   Palet parchment, sekeluarga dengan Chronica Islamica.
   ============================================================ */

:root {
  --bg:      #f5f0e8;
  --bg2:     #ede7d9;
  --panel:   #fffaf2;
  --white:   #ffffff;
  --text:    #2c2418;
  --text2:   #6b5e4a;
  --text3:   #9c8e7a;
  --border:  #d8cfc2;
  --border2: #c6bbaa;
  --tick:    #b8aa96;

  --d-peristiwa:  #a32020;
  --d-negara:     #b8620f;
  --d-penguasa:   #8a7410;
  --d-penjelajah: #4d7a20;
  --d-agama:      #157a4a;
  --d-sains:      #0b7285;
  --d-filsafat:   #1554a8;
  --d-sastra:     #4b3fb5;
  --d-seni:       #8b2fa0;
  --d-musik:      #b32d70;

  --ruler-h: 54px;
  --bottom-h: 46px;
  --lane-h: 22px;
  --lane-gap: 3px;
  --shadow: 0 2px 6px rgba(44,36,24,.09);
  --shadow-lg: 0 16px 40px rgba(44,36,24,.22);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

/* Atribut hidden harus menang atas display apa pun di bawah ini. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  font-family: 'Nunito', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

kbd {
  font-family: inherit;
  font-size: .75rem;
  font-weight: 700;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 5px;
}

/* ---------- TOPBAR ---------- */
.topbar {
  background: var(--white);
  border-bottom: 2px solid var(--border);
  padding: 8px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  box-shadow: var(--shadow);
  z-index: 40;
}
.app-icon {
  width: 30px; height: 30px;
  flex-shrink: 0;
  border-radius: 8px;
  box-shadow: 0 2px 5px rgba(44,36,24,.16);
}
.topbar h1 {
  font-family: 'Playfair Display', serif;
  font-size: 1.12rem;
  font-weight: 700;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar h1 small {
  font-family: 'Nunito', sans-serif;
  font-size: .72rem;
  font-weight: 400;
  color: var(--text3);
  margin-left: 8px;
}

.icon-btn {
  flex-shrink: 0;
  width: 27px; height: 27px;
  border: 1.5px solid var(--border);
  border-radius: 50%;
  background: var(--bg);
  color: var(--text2);
  font-family: inherit;
  font-size: .9rem;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background .14s, color .14s, border-color .14s;
}
.icon-btn:hover { background: var(--bg2); color: var(--text); border-color: var(--border2); }

.count-badge {
  flex-shrink: 0;
  font-size: .7rem;
  font-weight: 700;
  color: var(--text2);
  background: var(--bg2);
  border-radius: 20px;
  padding: 3px 10px;
  white-space: nowrap;
}

/* ---------- PENCARIAN ---------- */
.search-wrap { position: relative; flex-shrink: 0; }
.search-wrap input {
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: 6px 30px 6px 28px;
  font-family: inherit;
  font-size: .8rem;
  background: var(--bg);
  color: var(--text);
  outline: none;
  width: 240px;
  transition: border-color .15s, width .18s;
}
.search-wrap input:focus { border-color: var(--text3); width: 260px; }
.search-icon {
  position: absolute; left: 9px; top: 50%;
  transform: translateY(-50%);
  font-size: .7rem;
  pointer-events: none;
}
.search-clear {
  position: absolute; right: 7px; top: 50%;
  transform: translateY(-50%);
  width: 18px; height: 18px;
  border: 0; border-radius: 50%;
  background: rgba(107,94,74,.18);
  color: var(--text2);
  font-size: .82rem; font-weight: 800; line-height: 18px;
  display: none; cursor: pointer; padding: 0;
}
.search-clear.show { display: block; }
.search-clear:hover { background: rgba(163,32,32,.18); color: var(--d-peristiwa); }

.search-suggestions {
  position: absolute;
  top: calc(100% + 7px);
  right: 0;
  width: min(400px, calc(100vw - 24px));
  max-height: 340px;
  overflow-y: auto;
  background: var(--panel);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  z-index: 80;
  display: none;
  padding: 5px;
}
.search-suggestions.show { display: block; }
.suggestion-item {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  text-align: left;
  padding: 7px 9px;
  border-radius: 7px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}
.suggestion-item:hover, .suggestion-item.active { background: var(--bg2); }
.suggestion-item .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.suggestion-item .s-name { font-size: .82rem; font-weight: 700; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggestion-item .s-yr { font-size: .7rem; color: var(--text3); font-weight: 600; white-space: nowrap; }
.suggestion-empty { padding: 12px; font-size: .78rem; color: var(--text3); text-align: center; }

/* ---------- BARIS SARINGAN ---------- */
.filter-row {
  background: var(--white);
  border-bottom: 1.5px solid var(--border);
  padding: 6px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  z-index: 30;
}
.filter-row.sub { background: var(--bg2); border-bottom-color: var(--border2); }
.row-label {
  font-size: .64rem;
  font-weight: 800;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--text3);
  flex-shrink: 0;
  width: 52px;
}
.chip-scroll {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  flex: 1;
  min-width: 0;
  padding-bottom: 2px;
  scrollbar-width: thin;
}
/* Chip terakhir memudar, bukan terpotong tegas, supaya jelas barisnya masih
   bisa digeser - terutama di layar sempit. */
.chip-scroll {
  -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 20px), transparent 100%);
  mask-image: linear-gradient(90deg, #000 calc(100% - 20px), transparent 100%);
}
.chip-scroll::-webkit-scrollbar { height: 4px; }
.chip-scroll::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 4px; }

.chip {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1.5px solid var(--border2);
  border-radius: 20px;
  padding: 3px 11px;
  font-family: inherit;
  font-size: .74rem;
  font-weight: 700;
  color: var(--text2);
  background: var(--white);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: background .13s, color .13s, border-color .13s, opacity .13s;
}
.chip .dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.chip:hover { border-color: var(--text3); }
.chip.off { opacity: .42; }
.chip.on { color: var(--text); border-color: currentColor; }
.chip.on .dot { box-shadow: 0 0 0 3px rgba(255,255,255,.65); }
.chip.ghost { background: transparent; }
.chip.view-chip { background: var(--white); }
.row-sep { width: 1px; height: 18px; background: var(--border2); flex-shrink: 0; }

/* ---------- PANGGUNG ---------- */
.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  position: relative;
}
.chart {
  flex: 1;
  min-width: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
  cursor: grab;
  touch-action: none;
}
.chart.dragging { cursor: grabbing; }

.loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: .85rem;
  font-weight: 700;
  color: var(--text3);
  background: var(--bg);
  z-index: 25;
}

/* ---------- MISTAR TAHUN ---------- */
.ruler {
  height: var(--ruler-h);
  flex-shrink: 0;
  position: relative;
  background: var(--panel);
  border-bottom: 1.5px solid var(--border2);
  overflow: hidden;
  z-index: 20;
  cursor: crosshair;
  box-shadow: 0 2px 5px rgba(44,36,24,.07);
}
.era-strip { position: absolute; left: 0; top: 0; right: 0; height: 22px; }
.era-band {
  position: absolute;
  top: 0; height: 22px;
  display: flex;
  align-items: center;
  padding: 0 8px;
  font-size: .63rem;
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  border-right: 1px solid rgba(44,36,24,.14);
}
.tick-strip { position: absolute; left: 0; top: 22px; right: 0; bottom: 0; }
.tick {
  position: absolute;
  top: 0; bottom: 0;
  border-left: 1px solid var(--tick);
  padding-left: 5px;
  font-size: .68rem;
  font-weight: 700;
  color: var(--text2);
  white-space: nowrap;
  display: flex;
  align-items: center;
}
.tick.minor { border-left-color: rgba(184,170,150,.5); }
.tick.minor span { display: none; }
.tick.zero { border-left: 2px solid var(--text2); }

/* ---------- BARIS ---------- */
.rows-vp {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
}
.rows-vp::-webkit-scrollbar { width: 9px; }
.rows-vp::-webkit-scrollbar-track { background: var(--bg2); }
.rows-vp::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 6px; }
.rows-inner { position: relative; }
.layer { position: absolute; left: 0; top: 0; right: 0; bottom: 0; }
.backdrop-layer { z-index: 1; }
.bars-layer { z-index: 4; }
.titles-layer { z-index: 9; pointer-events: none; }

.grid-line {
  position: absolute;
  top: 0; bottom: 0;
  width: 1px;
  background: rgba(184,170,150,.34);
  pointer-events: none;
}
.grid-line.strong { background: rgba(160,144,120,.55); }
.era-tint { position: absolute; top: 0; bottom: 0; pointer-events: none; }

.group-band {
  position: absolute;
  left: 0; right: 0;
  pointer-events: none;
}
.group-band.alt { background: rgba(255,255,255,.42); }
.group-title {
  position: absolute;
  top: 2px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 9px;
  background: rgba(255,250,242,.93);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: .64rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text2);
  white-space: nowrap;
  box-shadow: 0 1px 3px rgba(44,36,24,.1);
  pointer-events: none;
  z-index: 9;
}
.group-title .dot { width: 8px; height: 8px; border-radius: 50%; }
.group-title .g-count { color: var(--text3); font-weight: 700; }

/* ---------- BATANG ---------- */
.bar {
  position: absolute;
  left: 0; top: 0;
  height: var(--lane-h);
  border-radius: 5px;
  display: flex;
  align-items: center;
  cursor: pointer;
  overflow: hidden;
  border: 1px solid rgba(0,0,0,.16);
  box-shadow: 0 1px 2px rgba(44,36,24,.13);
  transition: filter .12s, box-shadow .12s;
  contain: layout style paint;
}
.bar:hover { filter: brightness(1.1); box-shadow: 0 2px 7px rgba(44,36,24,.28); z-index: 6; }
.bar-label {
  font-size: .72rem;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 7px;
  text-shadow: 0 1px 2px rgba(0,0,0,.4);
  pointer-events: none;
}
.bar.clip-l { border-top-left-radius: 0; border-bottom-left-radius: 0; border-left: 0; }
.bar.clip-r { border-top-right-radius: 0; border-bottom-right-radius: 0; border-right: 0; }
.bar.clip-l .bar-label { padding-left: 17px; }

/* Masih berjalan: ujung kanannya memudar, bukan berhenti tegas. Tanggal wafat
   dan "masih hidup" tidak boleh terlihat sama. */
.bar.kini {
  border-right: 0;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 26px), transparent 100%);
  mask-image: linear-gradient(90deg, #000 calc(100% - 26px), transparent 100%);
}
.pt.kini .pt-mark {
  -webkit-mask-image: linear-gradient(90deg, #000 55%, transparent 100%);
  mask-image: linear-gradient(90deg, #000 55%, transparent 100%);
  border-right: 0;
}
.bar .edge {
  position: absolute;
  top: 0; bottom: 0;
  width: 15px;
  display: grid;
  place-items: center;
  font-size: .58rem;
  color: rgba(255,255,255,.92);
  background: linear-gradient(90deg, rgba(0,0,0,.3), rgba(0,0,0,0));
  pointer-events: none;
}
.bar .edge.r { right: 0; background: linear-gradient(270deg, rgba(0,0,0,.3), rgba(0,0,0,0)); }
.bar .edge.l { left: 0; }

.pt {
  position: absolute;
  left: 0; top: 0;
  height: var(--lane-h);
  display: flex;
  align-items: center;
  cursor: pointer;
  white-space: nowrap;
  contain: layout style;
}
.pt-mark {
  width: 11px; height: 11px;
  flex-shrink: 0;
  transform: rotate(45deg);
  border-radius: 2px;
  border: 1px solid rgba(0,0,0,.25);
  box-shadow: 0 1px 2px rgba(44,36,24,.2);
}
/* Entri yang rentangnya sudah terukur digambar sebagai batang pendek,
   bukan belah ketupat, supaya panjang hidupnya tetap kebaca. */
.pt.span .pt-mark {
  height: 16px;
  transform: none;
  border-radius: 4px;
}
.pt-label {
  font-size: .71rem;
  font-weight: 700;
  color: var(--text);
  margin-left: 6px;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(255,250,242,.82);
  pointer-events: none;
}
.pt:hover { z-index: 7; }
.pt:hover .pt-label { background: var(--white); box-shadow: 0 1px 4px rgba(44,36,24,.2); }

.bar .reign {
  position: absolute;
  top: 0; bottom: 0;
  background: rgba(255,255,255,.3);
  border-left: 1px solid rgba(255,255,255,.75);
  border-right: 1px solid rgba(255,255,255,.75);
  pointer-events: none;
}

.bar.hit, .pt.hit .pt-mark { outline: 2.5px solid #2c2418; outline-offset: 1px; z-index: 8; }
.pt.hit .pt-label { background: #2c2418; color: #fff; }
.dim { opacity: .2; }

.empty-note {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: .85rem;
  font-weight: 700;
  color: var(--text3);
}

/* ---------- GARIS TAHUN ---------- */
.playhead {
  position: absolute;
  top: 0; bottom: 0;
  width: 1px;
  background: rgba(44,36,24,.5);
  pointer-events: none;
  z-index: 22;   /* di atas mistar, supaya benderanya kelihatan */
}
.playhead.pinned { background: var(--d-peristiwa); width: 2px; }
.playhead-flag {
  position: absolute;
  top: 26px;
  left: 3px;
  background: var(--text);
  color: #fff;
  font-size: .68rem;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 4px;
  white-space: nowrap;
  box-shadow: 0 2px 6px rgba(44,36,24,.3);
}
.playhead.pinned .playhead-flag { background: var(--d-peristiwa); }
.playhead.flip .playhead-flag { left: auto; right: 3px; }

/* ---------- PANEL SAMPING ---------- */
.sidepanel {
  width: 320px;
  flex-shrink: 0;
  background: var(--panel);
  border-left: 2px solid var(--border2);
  display: flex;
  flex-direction: column;
  box-shadow: -6px 0 18px rgba(44,36,24,.1);
  z-index: 22;
}
.sp-hd {
  padding: 10px 12px;
  border-bottom: 1.5px solid var(--border);
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.sp-kicker {
  font-size: .62rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text3);
}
.sp-year {
  font-family: 'Playfair Display', serif;
  font-size: 1.32rem;
  font-weight: 900;
  line-height: 1.15;
}
.sp-hd > div { flex: 1; }
.sp-bd { flex: 1; overflow-y: auto; padding: 8px 10px 20px; }
.sp-group { margin-bottom: 12px; }
.sp-group h3 {
  font-size: .63rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text3);
  margin-bottom: 5px;
  padding-bottom: 3px;
  border-bottom: 1px solid var(--border);
}
.sp-item {
  display: flex;
  align-items: baseline;
  gap: 7px;
  width: 100%;
  border: 0;
  background: transparent;
  font-family: inherit;
  text-align: left;
  padding: 4px 5px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text);
}
.sp-item:hover { background: var(--bg2); }
.sp-item .dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; transform: translateY(-1px); }
.sp-item .i-name { font-size: .78rem; font-weight: 700; flex: 1; }
.sp-item .i-age { font-size: .67rem; color: var(--text3); font-weight: 700; white-space: nowrap; }
.sp-empty { font-size: .78rem; color: var(--text3); padding: 14px 4px; text-align: center; }

/* ---------- BILAH BAWAH ---------- */
.bottombar {
  height: var(--bottom-h);
  flex-shrink: 0;
  background: var(--white);
  border-top: 2px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  z-index: 30;
  box-shadow: 0 -2px 6px rgba(44,36,24,.07);
}
.zoom-ctl { display: flex; align-items: center; gap: 7px; flex-shrink: 0; }
.zoom-ctl input[type=range] { width: 110px; accent-color: var(--d-peristiwa); cursor: pointer; }
.zoom-read {
  font-size: .66rem;
  font-weight: 700;
  color: var(--text3);
  width: 86px;
  white-space: nowrap;
}
.minimap {
  flex: 1;
  min-width: 0;
  height: 26px;
  position: relative;
  background: var(--bg2);
  border: 1.5px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
}
.minimap canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.mm-window {
  position: absolute;
  top: 0; bottom: 0;
  background: rgba(163,32,32,.16);
  border-left: 2px solid var(--d-peristiwa);
  border-right: 2px solid var(--d-peristiwa);
  min-width: 3px;
  pointer-events: none;
}

/* ---------- POPUP ---------- */
.popup {
  position: fixed;
  width: 340px;
  max-height: 76vh;
  background: var(--panel);
  border: 1.5px solid var(--border2);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  z-index: 90;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.popup-handle { display: none; }
.popup-hd {
  padding: 11px 34px 10px 13px;
  border-bottom: 1.5px solid var(--border);
  position: relative;
  background: var(--white);
}
.popup-close {
  position: absolute;
  top: 8px; right: 9px;
  width: 24px; height: 24px;
  border: 0; border-radius: 50%;
  background: rgba(107,94,74,.14);
  color: var(--text2);
  font-size: .8rem; font-weight: 800;
  cursor: pointer;
  line-height: 1;
}
.popup-close:hover { background: rgba(163,32,32,.18); color: var(--d-peristiwa); }
.popup-cat {
  font-size: .62rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  margin-bottom: 3px;
}
.popup-name {
  font-family: 'Playfair Display', serif;
  font-size: 1.14rem;
  font-weight: 700;
  line-height: 1.25;
}
.popup-yr { font-size: .76rem; color: var(--text2); font-weight: 700; margin-top: 3px; }
.popup-bd { padding: 11px 13px 15px; overflow-y: auto; }
.popup-thumb { margin-bottom: 10px; }
.popup-thumb img {
  width: 100%;
  max-height: 190px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  display: block;
}
.popup-meta {
  font-size: .74rem;
  color: var(--text2);
  font-weight: 700;
  margin-bottom: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
}
.popup-meta span {
  background: var(--bg2);
  border-radius: 20px;
  padding: 2px 9px;
}
.popup-bio { font-size: .82rem; line-height: 1.6; color: var(--text); }
.popup-sez { margin-top: 12px; }
.popup-sez h4 {
  font-size: .62rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text3);
  margin-bottom: 5px;
  padding-bottom: 3px;
  border-bottom: 1px solid var(--border);
}
.sez-item {
  display: flex;
  align-items: baseline;
  gap: 7px;
  width: 100%;
  border: 0;
  background: transparent;
  font-family: inherit;
  text-align: left;
  padding: 3px 5px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text);
}
.sez-item:hover { background: var(--bg2); }
.sez-item .dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; transform: translateY(-1px); }
.sez-item .z-name { font-size: .76rem; font-weight: 700; flex: 1; }
.sez-item .z-yr { font-size: .66rem; color: var(--text3); font-weight: 700; white-space: nowrap; }

.popup-links { margin-top: 11px; }
.popup-links a {
  font-size: .74rem;
  font-weight: 700;
  color: var(--d-filsafat);
  text-decoration: none;
  border-bottom: 1px dotted currentColor;
}

/* ---------- LEMBAR BANTUAN ---------- */
.sheet {
  position: fixed;
  inset: 0;
  background: rgba(44,36,24,.45);
  z-index: 95;
  display: grid;
  place-items: center;
  padding: 18px;
}
.sheet-card {
  position: relative;
  background: var(--panel);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  max-width: 520px;
  width: 100%;
  max-height: 84vh;
  overflow-y: auto;
  padding: 20px 22px 22px;
}
.sheet-card h2 {
  font-family: 'Playfair Display', serif;
  font-size: 1.28rem;
  margin-bottom: 12px;
}
.help-list dt {
  font-size: .78rem;
  font-weight: 800;
  margin-top: 11px;
  color: var(--text);
}
.help-list dd { font-size: .8rem; line-height: 1.55; color: var(--text2); }
.edge-demo {
  display: inline-block;
  background: var(--text);
  color: #fff;
  border-radius: 3px;
  padding: 0 4px;
  font-size: .66rem;
}
.help-foot {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: .74rem;
  color: var(--text3);
  line-height: 1.55;
}

/* ---------- LAYAR KECIL ---------- */
@media (max-width: 860px) {
  .sidepanel {
    position: absolute;
    top: 0; right: 0; bottom: 0;
    width: min(300px, 84vw);
  }
}
@media (max-width: 640px) {
  .topbar { padding: 7px 10px; gap: 8px; flex-wrap: wrap; }
  .topbar h1 { font-size: .98rem; order: 1; flex: 1; }
  .topbar h1 small { display: none; }
  .app-icon { order: 0; width: 26px; height: 26px; }
  .count-badge { order: 2; }
  #helpBtn { order: 3; }
  .search-wrap { order: 4; width: 100%; }
  .search-wrap input, .search-wrap input:focus { width: 100%; }
  .row-label { display: none; }
  .filter-row { padding: 5px 10px; }
  .bottombar { padding: 0 10px; gap: 8px; }
  .zoom-read { display: none; }
  .zoom-ctl input[type=range] { width: 74px; }
  #fitBtn { display: none; }
  .popup {
    left: 0 !important; right: 0;
    bottom: 0 !important;
    top: auto !important;
    width: 100%;
    max-height: 66vh;
    border-radius: 14px 14px 0 0;
    border-bottom: 0;
  }
  .popup-handle {
    display: block;
    width: 38px; height: 4px;
    background: var(--border2);
    border-radius: 3px;
    margin: 7px auto 0;
  }
}

/* ---------- PERANGKAT SENTUH ----------
   Chip setinggi 24px cukup untuk kursor, tidak untuk jari. Di perangkat yang
   penunjuknya kasar, semua sasaran ketuk diperbesar. */
@media (pointer: coarse) {
  .chip { padding: 7px 13px; font-size: .78rem; }
  .chip .dot { width: 10px; height: 10px; }
  .icon-btn { width: 36px; height: 36px; font-size: 1rem; }
  .search-wrap input { padding-top: 9px; padding-bottom: 9px; }
  .search-clear { width: 26px; height: 26px; line-height: 26px; right: 5px; }
  .popup-close { width: 32px; height: 32px; font-size: .95rem; }
  .sp-item, .sez-item, .suggestion-item { padding-top: 9px; padding-bottom: 9px; }
  .zoom-ctl input[type=range] { height: 28px; }
  .minimap { height: 32px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
