/* تایم‌لاین تاریخ — one stylesheet, no framework.
   Theme: flag-chart on an ink-dark plate; light plate available via the toggle.
   Time runs left -> right (the chart convention); every label is RTL Persian. */

@font-face{font-family:"Vazirmatn";src:url("fonts/Vazirmatn-Regular.woff2") format("woff2");font-weight:400;font-display:swap}
@font-face{font-family:"Vazirmatn";src:url("fonts/Vazirmatn-Medium.woff2")  format("woff2");font-weight:500;font-display:swap}
@font-face{font-family:"Vazirmatn";src:url("fonts/Vazirmatn-Bold.woff2")    format("woff2");font-weight:700;font-display:swap}
@font-face{font-family:"Vazirmatn";src:url("fonts/Vazirmatn-Black.woff2")   format("woff2");font-weight:900;font-display:swap}

:root{
  --bg:#0e141b; --bg2:#121a24; --plate:#0b1016;
  --ink:#e9eef4; --ink2:#9fb0c2; --ink3:#64788c;
  --line:#243242; --line2:#1a242f;
  --gold:#e8c37a; --accent:#6fb3d2;
  --shadow:0 10px 34px rgba(0,0,0,.45);
  --chip:#18222e; --chipon:#25374a;
  --c-philosophy:#8fb8e8; --c-politics:#e0a86a; --c-science:#7fcfae;
  --c-war:#d98a8a;        --c-technology:#b79be0; --c-economics:#e3cd79;
  --c-religion:#e59ec4;   --c-literature:#89cfd8; --c-default:#9aa8b8;
  --period-fill:rgba(232,195,122,.10); --period-edge:rgba(232,195,122,.38);
}
:root[data-theme="light"]{
  --bg:#f3efe6; --bg2:#fbf9f4; --plate:#fdfcf8;
  --ink:#1d2630; --ink2:#5c6b7a; --ink3:#8b9aa8;
  --line:#ddd6c7; --line2:#eae4d7;
  --gold:#9a7427; --accent:#2f6f93;
  --shadow:0 8px 26px rgba(40,34,20,.14);
  --chip:#efe9dc; --chipon:#e0d6c0;
  --c-philosophy:#3f6fae; --c-politics:#a9671f; --c-science:#1f7d59;
  --c-war:#ab4848;        --c-technology:#6f4aa8; --c-economics:#8a6f12;
  --c-religion:#a84a7c;   --c-literature:#1f7682; --c-default:#5d6b7a;
  --period-fill:rgba(154,116,39,.10); --period-edge:rgba(154,116,39,.40);
}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0; font-family:"Vazirmatn",system-ui,sans-serif; background:var(--bg); color:var(--ink);
  display:flex; flex-direction:column; overflow:hidden;
  -webkit-text-size-adjust:100%;
}
.sr{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0)}

/* ---------- top bar ---------- */
.topbar{
  display:flex; align-items:center; gap:16px; flex-wrap:wrap;
  padding:10px 16px; background:var(--bg2); border-bottom:1px solid var(--line);
}
.brand{display:flex; align-items:baseline; gap:10px; min-width:0}
.brand h1{margin:0; font-size:17px; font-weight:700; letter-spacing:.2px; white-space:nowrap}
.brand h1::before{content:"";display:inline-block;width:22px;height:3px;border-radius:2px;background:var(--gold);vertical-align:middle;margin-inline-end:8px}
.tally{margin:0; font-size:12px; color:var(--ink2); white-space:nowrap}
.tally b{color:var(--ink); font-weight:500}
.tally .seedflag{color:var(--gold)}

.tools{display:flex; align-items:center; gap:10px; margin-inline-start:auto; flex-wrap:wrap}
.search input{
  font:inherit; font-size:13px; color:var(--ink); background:var(--chip);
  border:1px solid var(--line); border-radius:8px; padding:6px 10px; width:150px;
}
.search input:focus{outline:2px solid var(--accent); outline-offset:1px}
.zoom{display:flex; align-items:center; gap:6px; background:var(--chip); border:1px solid var(--line); border-radius:8px; padding:3px 6px}
.zoom button{
  font:inherit; font-size:15px; line-height:1; color:var(--ink); background:transparent;
  border:0; cursor:pointer; padding:4px 7px; border-radius:6px;
}
.zoom button.txt{font-size:12px}
.zoom button:hover{background:var(--chipon)}
.zoom input[type=range]{width:110px; accent-color:var(--gold)}
button.icon{
  font:inherit; font-size:15px; color:var(--ink); background:var(--chip);
  border:1px solid var(--line); border-radius:8px; cursor:pointer; padding:5px 9px;
}
button.icon:hover{background:var(--chipon)}

/* ---------- filters ---------- */
.filters{
  display:flex; align-items:flex-start; gap:18px; flex-wrap:wrap;
  padding:8px 16px; background:var(--bg2); border-bottom:1px solid var(--line);
}
.filters .row{display:flex; align-items:center; gap:8px; flex-wrap:wrap; min-width:0}
.rowlabel{font-size:11px; color:var(--ink3); flex:0 0 auto}
.chips{display:flex; gap:6px; flex-wrap:wrap}
.chip{
  font:inherit; font-size:12px; color:var(--ink2); background:var(--chip);
  border:1px solid var(--line); border-radius:999px; padding:3px 10px; cursor:pointer;
  display:inline-flex; align-items:center; gap:6px; white-space:nowrap;
}
.chip:hover{color:var(--ink)}
.chip[aria-pressed="true"]{color:var(--ink); background:var(--chipon); border-color:var(--ink3)}
.chip .dot{width:8px; height:8px; border-radius:2px; background:var(--c-default); flex:0 0 auto}
.chip .n{font-size:10px; color:var(--ink3)}
.reset{
  font:inherit; font-size:11px; color:var(--ink3); background:none; border:0;
  cursor:pointer; text-decoration:underline; margin-inline-start:auto; padding:4px;
}
.reset:hover{color:var(--ink)}

/* ---------- stage ---------- */
.stage{
  position:relative; flex:1 1 auto; min-height:0; overflow:hidden;
  background:
    radial-gradient(1200px 400px at 50% -80px, color-mix(in oklab, var(--accent) 7%, transparent), transparent 70%),
    var(--plate);
  cursor:grab; touch-action:none; user-select:none; outline:none;
}
.stage.dragging{cursor:grabbing}
.stage:focus-visible{box-shadow:inset 0 0 0 2px var(--accent)}
/* The plot itself is LTR: time increases to the right. Labels flip back. */
.scroller{position:absolute; inset:0; direction:ltr}

.band{position:absolute; left:0; right:0}
.band-periods{top:14px}
.band-events{top:0}       /* positioned from JS: sits just above the axis */
.band-people{top:0}       /* positioned from JS: starts just below the axis */

/* ---------- axis ---------- */
.axis{position:absolute; left:0; right:0; height:34px}
.axis::before{
  content:""; position:absolute; left:0; right:0; top:0; height:2px;
  background:linear-gradient(90deg, transparent, var(--gold) 6%, var(--gold) 94%, transparent);
  opacity:.75;
}
.tick{position:absolute; top:0; width:1px; background:var(--line); height:7px}
.tick.major{height:11px; background:var(--ink3)}
.tick .lbl{
  position:absolute; top:12px; left:0; transform:translateX(-50%);
  direction:rtl; font-size:11px; color:var(--ink2); white-space:nowrap; font-variant-numeric:tabular-nums;
}
.tick.major .lbl{color:var(--ink); font-weight:500}
.grid{position:absolute; top:0; bottom:0; width:1px; background:var(--line2)}

/* ---------- items ---------- */
.item{position:absolute; cursor:pointer; direction:rtl}
.item:focus-visible{outline:2px solid var(--accent); outline-offset:2px; border-radius:4px}

/* people: a bar over the lifespan, label inside when it fits, outside when not */
.bar{
  height:22px; border-radius:4px; display:flex; align-items:center;
  background:color-mix(in oklab, var(--col) 24%, transparent);
  border:1px solid color-mix(in oklab, var(--col) 70%, transparent);
  border-inline-start:3px solid var(--col);
}
.bar .t{
  font-size:12px; font-weight:500; color:var(--ink); white-space:nowrap;
  padding:0 7px; line-height:1;
}
/* A label that will not fit inside its bar hangs to the left of it, which is
   where Persian text wants to run and where the packer kept room. */
.item.out .bar{overflow:visible}
.item.out .bar .t{
  position:absolute; top:4px; right:calc(100% + 8px);
  color:var(--ink); background:linear-gradient(90deg,transparent,var(--plate) 14%);
  padding-inline-start:6px; border-radius:3px;
}
.item .yrs{font-size:10px; color:var(--ink3); white-space:nowrap; padding-inline-end:6px; font-variant-numeric:tabular-nums}

/* events: a flag whose plate hangs to the left of a pole standing on the axis.
   The item itself is zero-width and sits exactly on its year. */
.item.flag{width:0}
.item.flag .plate{
  position:absolute; top:0; right:0;
  display:inline-flex; align-items:center; gap:6px; white-space:nowrap;
  background:var(--bg2); border:1px solid color-mix(in oklab, var(--col) 60%, var(--line));
  border-bottom:2px solid var(--col);
  border-radius:4px; padding:3px 8px; box-shadow:var(--shadow); font-size:12px; font-weight:500;
}
.item.flag .plate .yr{font-size:10px; color:var(--ink3); font-variant-numeric:tabular-nums}
.item.flag .pole{position:absolute; top:24px; left:-1px; width:2px; background:var(--col); opacity:.6}
.item.flag .knob{position:absolute; left:-4px; width:8px; height:8px; border-radius:50%; background:var(--col)}

/* a period whose label will not fit sits to the left of the slab too */
.item.out .slab{overflow:visible}
.item.out .slab .t{position:absolute; top:4px; right:calc(100% + 8px)}

/* ...unless that would push it off the left edge of the screen, in which case
   it flips to the other side rather than being clipped away. */
.item.out.flip .bar .t,
.item.out.flip .slab .t{
  right:auto; left:calc(100% + 8px);
  background:linear-gradient(270deg,transparent,var(--plate) 14%);
  padding-inline-start:0; padding-inline-end:6px;
}
.item.flag.flip .plate{right:auto; left:0}

/* periods: a wide translucent slab */
.slab{
  height:24px; border-radius:3px; display:flex; align-items:center;
  background:var(--period-fill); border:1px dashed var(--period-edge);
  border-top:2px solid color-mix(in oklab, var(--col) 80%, transparent);
}
.slab .t{font-size:12px; color:var(--ink2); white-space:nowrap; padding:0 8px; font-weight:500}

.item .seed{
  width:6px; height:6px; border-radius:50%; background:var(--gold);
  flex:0 0 auto; margin-inline-start:4px; opacity:.8;
}
.item.dim{opacity:.22}
.item.hit .bar,.item.hit .plate,.item.hit .slab{box-shadow:0 0 0 2px var(--accent)}
.item:hover{z-index:40}
.item:hover .bar,.item:hover .plate,.item:hover .slab{filter:brightness(1.18)}

/* ---------- playhead ---------- */
.playhead{position:absolute; top:0; bottom:0; width:1px; background:var(--accent); opacity:.55; pointer-events:none; z-index:30}
.playhead-year{
  position:absolute; top:4px; right:6px; direction:rtl; font-size:11px; font-weight:500;
  color:var(--plate); background:var(--accent); border-radius:4px; padding:2px 6px; white-space:nowrap;
  font-variant-numeric:tabular-nums;
}

.empty{position:absolute; inset:auto 0 50% 0; text-align:center; color:var(--ink3); font-size:13px}
.loading{
  position:fixed; inset:0; display:grid; place-items:center; background:var(--bg);
  color:var(--ink2); font-size:13px; z-index:90;
}
.loading[hidden]{display:none}
.loading.err{color:var(--c-war); white-space:pre-line; text-align:center; padding:24px}

/* ---------- hint bar ---------- */
.hintbar{
  display:flex; gap:16px; align-items:center; padding:5px 16px;
  background:var(--bg2); border-top:1px solid var(--line); font-size:11px; color:var(--ink3);
}
.hintbar span+span::before{content:"·"; margin-inline-end:16px; color:var(--line)}
.hintbar #buildstamp{margin-inline-start:auto}

/* ---------- detail card ---------- */
.card{
  position:fixed; top:0; bottom:0; inset-inline-end:0; width:min(400px,94vw); z-index:80;
  background:var(--bg2); border-inline-start:1px solid var(--line); box-shadow:var(--shadow);
  overflow-y:auto; padding:22px 22px 32px; animation:slide .18s ease-out;
}
@keyframes slide{from{transform:translateX(-14px);opacity:0}to{transform:none;opacity:1}}
.card[hidden]{display:none}
.card .close{
  position:absolute; top:12px; inset-inline-start:12px; font:inherit; font-size:14px;
  color:var(--ink3); background:none; border:0; cursor:pointer; padding:4px 7px; border-radius:6px;
}
.card .close:hover{color:var(--ink); background:var(--chip)}
.card h2{margin:0 0 4px; font-size:20px; font-weight:700; padding-inline-end:28px}
.card .meta{display:flex; gap:8px; flex-wrap:wrap; margin:0 0 16px; font-size:12px; color:var(--ink2)}
.card .meta .pill{background:var(--chip); border:1px solid var(--line); border-radius:999px; padding:2px 9px}
.card .meta .pill.dates{color:var(--ink); font-variant-numeric:tabular-nums}
.card .meta .pill.cat{border-color:color-mix(in oklab, var(--col) 60%, var(--line)); color:var(--ink)}
.card .meta .pill.seedy{border-color:var(--gold); color:var(--gold)}
.card h3{
  margin:16px 0 5px; font-size:11px; font-weight:500; color:var(--ink3);
  letter-spacing:.3px; text-transform:none;
}
.card p{margin:0; font-size:14px; line-height:1.85; color:var(--ink)}
.card .why{
  font-size:14px; line-height:1.85; background:var(--chip); border-inline-start:3px solid var(--gold);
  border-radius:0 6px 6px 0; padding:10px 12px;
}
.card .rel{display:flex; gap:6px; flex-wrap:wrap}
.card .rel button{
  font:inherit; font-size:12px; color:var(--ink); background:var(--chip);
  border:1px solid var(--line); border-radius:999px; padding:4px 11px; cursor:pointer;
}
.card .rel button:hover{background:var(--chipon); border-color:var(--accent)}
.card .rel .ghost{
  font-size:12px; color:var(--ink3); background:transparent; border:1px dashed var(--line);
  border-radius:999px; padding:4px 11px; cursor:default;
}
.card .src{margin-top:20px; font-size:11px; color:var(--ink3); word-break:break-all}
.card .src span{direction:ltr; unicode-bidi:isolate; display:inline-block}

/* While the card is open the chart gives up the space rather than hiding under it. */
body.carded .stage{margin-inline-end:min(400px,94vw); transition:margin .18s ease-out}
@media (max-width:760px){ body.carded .stage{margin-inline-end:0} }

/* ---------- small screens ---------- */
.only-small{display:none}

@media (max-width:760px){
  .only-small{display:inline-block}
  /* The filter chips are three rows of them; on a phone they would own the
     screen, so they live behind the فیلتر button and the chart keeps the space. */
  .filters{display:none}
  body.filters-open .filters{display:flex; max-height:46vh; overflow-y:auto}
  .topbar{gap:10px; padding:8px 12px}
  .brand h1{font-size:15px}
  .tally{display:none}
  .search input{width:110px}
  .zoom input[type=range]{width:70px}
  .filters{padding:7px 12px; gap:10px}
  .rowlabel{display:none}
  .hintbar{display:none}
  .card{
    inset:auto 0 0 0; width:auto; max-height:72vh; border-inline-start:0;
    border-top:1px solid var(--line); border-radius:14px 14px 0 0; padding:18px 18px 26px;
  }
  @keyframes slide{from{transform:translateY(16px);opacity:0}to{transform:none;opacity:1}}
}
@media (prefers-reduced-motion:reduce){.card{animation:none}}
