@font-face {
  font-family: 'Vazirmatn';
  src: url('../fonts/Vazirmatn-var.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}

:root {
  /* «ها» palette: Atlas red, brandbook gold, cream, warm ink */
  --paper: #f6efe3;
  --paper-2: #efe5d4;
  --card: rgba(253, 250, 245, 0.86);
  --card-solid: #fdfaf5;
  --ink: #37261e;
  --ink-2: #6b5446;
  --ink-3: #9a8574;
  --line: rgba(55, 38, 30, 0.12);
  --red: #cc3333;
  --red-deep: #9a2525;
  --gold: #bb7a39;
  --gold-soft: #dcb07d;
  --sea: #cfdcd9;
  --lost: #8f7f73;
  --shadow: 0 10px 30px -12px rgba(55, 38, 30, 0.28), 0 2px 6px -2px rgba(55, 38, 30, 0.12);
  --r: 16px;
  --gutter: 20px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: 'Vazirmatn', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--ink);
  background: radial-gradient(120% 90% at 50% 45%, #fbf7f0 0%, var(--paper) 55%, var(--paper-2) 100%);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
a { color: inherit; }

#globe { position: fixed; inset: 0; cursor: grab; direction: ltr; } /* the label layer positions from the left */
[lang='fa'] #globe .lb, [lang='fa'] .terr-label, [lang='fa'] .route-label { direction: rtl; }
#globe:active { cursor: grabbing; }

/* ---------- brand ---------- */
.brand {
  position: fixed; top: var(--gutter); inset-inline-start: var(--gutter);
  display: flex; align-items: center; gap: 12px; z-index: 5;
}
.brand-mark {
  display: grid; place-items: center; width: 48px; height: 48px; border-radius: 14px;
  background: var(--card-solid); box-shadow: var(--shadow);
}
.brand h1 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -0.01em; }
.brand p { margin: 2px 0 0; font-size: 12px; color: var(--ink-2); }

/* ---------- tools ---------- */
.tools {
  position: fixed; top: var(--gutter); inset-inline-end: var(--gutter);
  display: flex; gap: 8px; z-index: 5;
}
.chip {
  border: 1px solid var(--line); background: var(--card); backdrop-filter: blur(10px);
  border-radius: 999px; padding: 8px 14px; font-size: 13px; font-weight: 600; cursor: pointer;
  box-shadow: var(--shadow);
}
.chip:hover { border-color: var(--ink-3); }
.icon-btn {
  width: 40px; height: 40px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); backdrop-filter: blur(10px); display: grid; place-items: center;
  cursor: pointer; box-shadow: var(--shadow); padding: 0;
}
.icon-btn:hover { border-color: var(--ink-3); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: var(--ink); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#btn-sound svg path:first-child { fill: var(--ink); stroke: none; }
#btn-sound .mute { display: none; }
#btn-sound[aria-pressed='false'] .wave { display: none; }
#btn-sound[aria-pressed='false'] .mute { display: inline; }
#btn-key.on { background: var(--ink); }
#btn-key.on svg { stroke: var(--card-solid); }
#btn-key.on svg circle { fill: var(--card-solid); }
#btn-key svg circle { fill: var(--ink); stroke: none; }
[dir='rtl'] #btn-prev svg, [dir='rtl'] #btn-next svg { transform: scaleX(-1); }

/* ---------- chapter panel ---------- */
.panel {
  position: fixed; top: 92px; inset-inline-end: var(--gutter); width: 360px;
  max-height: calc(100vh - 92px - 170px); overflow-y: auto; z-index: 4;
  background: var(--card); backdrop-filter: blur(14px) saturate(1.1);
  border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow);
  padding: 20px 22px 16px; transition: opacity .35s, transform .35s;
  scrollbar-width: thin;
}
.panel.hidden, .legend.hidden { opacity: 0; pointer-events: none; transform: translateY(8px); }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.kick { font-size: 12px; font-weight: 700; color: var(--red-deep); letter-spacing: .02em; }
.years { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.panel h2 { margin: 6px 0 2px; font-size: 26px; font-weight: 800; line-height: 1.3; }
.panel .sub { margin: 0 0 12px; color: var(--gold); font-weight: 600; font-size: 14px; }
.story { margin: 0 0 14px; font-size: 14.5px; line-height: 2; color: var(--ink); text-align: justify; }
[lang='en'] .story { line-height: 1.7; text-align: start; }
.events { list-style: none; margin: 0; padding: 12px 0 0; border-top: 1px solid var(--line); display: grid; gap: 2px; }
.events li {
  display: grid; grid-template-columns: 18px 1fr auto; align-items: center; gap: 10px;
  padding: 6px 8px; margin: 0 -8px; border-radius: 10px; cursor: pointer; font-size: 13.5px;
  opacity: .38; transition: opacity .5s, background .2s;
}
.events li.on { opacity: 1; }
.events li:hover { background: rgba(187, 122, 57, 0.1); }
.events li .ey { color: var(--ink-3); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- legend ---------- */
.legend {
  position: fixed; inset-inline-start: var(--gutter); bottom: 150px; z-index: 4; width: 250px;
  background: var(--card); backdrop-filter: blur(14px); border: 1px solid var(--line);
  border-radius: var(--r); box-shadow: var(--shadow); padding: 14px 16px 12px;
  transition: opacity .35s, transform .35s;
}
.legend ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.legend li { display: flex; align-items: center; gap: 10px; font-size: 13px; cursor: pointer; user-select: none; }
.legend li.off { opacity: .35; }
.legend li.off span { text-decoration: line-through; }
.credits { margin: 12px 0 0; padding-top: 10px; border-top: 1px solid var(--line); font-size: 11px; line-height: 1.7; color: var(--ink-3); }
.sw { flex: none; width: 22px; height: 14px; border-radius: 4px; display: inline-block; position: relative; }
.sw-territory { background: rgba(204, 51, 51, .32); border: 1.5px solid var(--red); }
.sw-lost { background: repeating-linear-gradient(45deg, rgba(143,127,115,.45) 0 3px, rgba(143,127,115,.15) 3px 6px); border: 1.5px dashed var(--lost); }
.sw-today { border-top: 2px dashed var(--ink); height: 0; border-radius: 0; margin-top: 2px; }
.sw-route { border-top: 2.5px dotted var(--gold); height: 0; border-radius: 0; }
.sw-battle, .sw-monument, .sw-event { width: 22px; height: 22px; border-radius: 50%; background: no-repeat center/contain; }
.sw-battle { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='12' r='11' fill='%23fdfaf5' stroke='%23cc3333' stroke-width='1.6'/%3E%3Cpath d='M7 7l10 10M17 7L7 17M6 15l3 3M18 15l-3 3' stroke='%2337261e' stroke-width='1.7' stroke-linecap='round'/%3E%3C/svg%3E"); }
.sw-monument { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='12' r='11' fill='%23fdfaf5' stroke='%23bb7a39' stroke-width='1.6'/%3E%3Cpath d='M7 17h10M8 17v-4h8v4M8.5 13a3.5 3.5 0 0 1 7 0M12 7.5v2' stroke='%237c4d29' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); }
.sw-event { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='12' r='11' fill='%23fdfaf5' stroke='%2337261e' stroke-width='1.4'/%3E%3Cpath d='M12 6.5l1.6 3.9 4.2.3-3.2 2.7 1 4.1L12 15.3l-3.6 2.2 1-4.1-3.2-2.7 4.2-.3z' fill='%2337261e'/%3E%3C/svg%3E"); }

/* ---------- markers on the globe ---------- */
.mk { position: relative; pointer-events: auto; cursor: pointer; transform: translate(-50%, -50%); }
.mk .ic { width: 24px; height: 24px; display: block; transition: transform .25s; }
.mk:hover .ic { transform: scale(1.18); }
.mk .lb {
  position: absolute; top: 50%; left: 28px; transform: translateY(-50%);
  white-space: nowrap; font-size: 12.5px; font-weight: 700; color: var(--ink);
  background: rgba(253, 250, 245, .82); padding: 2px 8px; border-radius: 6px;
  box-shadow: 0 1px 3px rgba(55, 38, 30, .15);
  opacity: 0; transition: opacity .4s;
}
.mk.fresh .lb, .mk:hover .lb { opacity: 1; }
.mk.appear .ic { animation: pop .6s cubic-bezier(.2, 1.6, .4, 1); }
.mk.past { opacity: .5; }
.mk.past .ic { width: 14px; height: 14px; }
@keyframes pop { from { transform: scale(0); } to { transform: scale(1); } }
.terr-label {
  transform: translate(-50%, -50%); pointer-events: none; white-space: nowrap;
  font-size: 19px; font-weight: 800; letter-spacing: .02em; color: var(--red-deep);
  text-shadow: 0 0 6px #fdfaf5, 0 0 12px #fdfaf5, 0 0 2px #fdfaf5; opacity: .82;
  transition: opacity .8s;
}
[lang='en'] .terr-label { text-transform: uppercase; letter-spacing: .14em; font-size: 15px; }
.route-label {
  transform: translate(-50%, -140%); pointer-events: none; white-space: nowrap;
  font-size: 11.5px; font-weight: 700; color: #7c4d29; font-style: italic;
  text-shadow: 0 0 5px #fdfaf5, 0 0 10px #fdfaf5;
}

/* ---------- dock: year + timeline ---------- */
.dock {
  position: fixed; left: 50%; bottom: var(--gutter); transform: translateX(-50%);
  width: min(960px, calc(100vw - 2 * var(--gutter))); z-index: 5; text-align: center;
  pointer-events: none;
}
.dock > * { pointer-events: auto; }
.year { display: inline-flex; flex-direction: column; align-items: center; margin-bottom: 10px; pointer-events: none; }
.y-main {
  font-size: clamp(34px, 5.4vw, 58px); font-weight: 900; line-height: 1; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums; color: var(--ink);
  text-shadow: 0 0 18px rgba(251, 247, 240, .95), 0 0 4px rgba(251, 247, 240, .9);
}
.y-sub { font-size: 13px; color: var(--ink-2); font-weight: 600; margin-top: 4px; text-shadow: 0 0 8px #fbf7f0; }
.bar {
  display: flex; align-items: center; gap: 8px; padding: 8px;
  background: var(--card); backdrop-filter: blur(14px); border: 1px solid var(--line);
  border-radius: 999px; box-shadow: var(--shadow);
}
.bar .icon-btn { box-shadow: none; flex: none; }
.bar .play { background: var(--ink); border-color: var(--ink); }
.bar .play svg { stroke: var(--card-solid); }
.bar .play .i-play { fill: var(--card-solid); display: none; }
body.paused .bar .play .i-play { display: inline; }
body.paused .bar .play .i-pause { display: none; }
.timeline { flex: 1; display: flex; gap: 3px; height: 40px; align-items: center; cursor: pointer; padding: 0 6px; outline: none; }
.seg { flex: 1; height: 8px; border-radius: 4px; background: rgba(55, 38, 30, .1); position: relative; overflow: visible; transition: height .2s; }
.seg:hover, .seg.cur { height: 12px; }
.seg .fill { position: absolute; inset-block: 0; inset-inline-start: 0; width: 0; border-radius: inherit; background: var(--red); }
.seg.done .fill { width: 100%; background: var(--gold-soft); }
.seg .tip {
  position: absolute; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--card-solid); font-size: 12px; font-weight: 600;
  white-space: nowrap; padding: 5px 10px; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .15s;
}
.seg:hover .tip { opacity: 1; }
.hint { font-size: 11.5px; color: var(--ink-3); margin-top: 8px; }

/* ---------- event card ---------- */
.card {
  position: fixed; z-index: 8; width: 300px; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: var(--card-solid); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: 0 24px 60px -20px rgba(55, 38, 30, .45); padding: 18px 20px 16px;
  animation: rise .3s ease-out;
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, -46%); } }
.card-x { position: absolute; top: 8px; inset-inline-end: 10px; border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--ink-3); line-height: 1; }
.card-type { font-size: 11.5px; font-weight: 700; color: var(--gold); }
.card h3 { margin: 4px 0 2px; font-size: 20px; font-weight: 800; }
.card-year { font-size: 12.5px; color: var(--ink-3); }
.card p { font-size: 14px; line-height: 1.9; margin: 10px 0 12px; }
.card-links { display: flex; flex-wrap: wrap; gap: 8px; }
.card-links a {
  font-size: 12.5px; font-weight: 700; text-decoration: none; padding: 7px 12px; border-radius: 999px;
  border: 1px solid var(--line);
}
.card-links a:hover { border-color: var(--ink-3); }
.card-links a.exp { background: var(--red); border-color: var(--red); color: #fff; }
.card-links a.exp:hover { background: var(--red-deep); }
.card-links a[hidden] { display: none; }

/* ---------- intro / end ---------- */
.intro {
  position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(70% 60% at 50% 50%, rgba(251, 247, 240, .55), rgba(246, 239, 227, .92));
  backdrop-filter: blur(3px); transition: opacity .8s;
}
.intro.gone { opacity: 0; pointer-events: none; }
.intro-card { max-width: 560px; text-align: center; }
.intro-mark { border-radius: 16px; background: var(--card-solid); box-shadow: var(--shadow); padding: 8px; }
.intro-kicker { margin: 18px 0 6px; font-size: 13px; font-weight: 700; color: var(--gold); letter-spacing: .04em; }
.intro-title { margin: 0; font-size: clamp(48px, 10vw, 88px); font-weight: 900; letter-spacing: -0.03em; line-height: 1.1; }
[lang='en'] .intro-title { letter-spacing: -0.02em; }
.intro-lead { font-size: 17px; line-height: 1.9; color: var(--ink-2); margin: 12px auto 26px; max-width: 460px; }
.intro-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.btn {
  border: 1px solid rgba(55, 38, 30, .22); background: var(--card-solid); border-radius: 999px;
  padding: 13px 24px; font-size: 15px; font-weight: 700; cursor: pointer; text-decoration: none;
  transition: transform .15s, background .2s;
}
.btn:hover { transform: translateY(-1px); border-color: var(--ink-2); }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; box-shadow: 0 10px 24px -10px rgba(204, 51, 51, .7); }
.btn.primary:hover { background: var(--red-deep); }
.btn:disabled { opacity: .5; cursor: wait; }
.intro-hint { font-size: 12.5px; color: var(--ink-3); margin: 22px 0 14px; line-height: 1.8; }
.intro-loading { font-size: 12px; color: var(--ink-3); min-height: 1em; margin: 10px 0 0; }

/* ---------- mobile ---------- */
@media (max-width: 760px) {
  :root { --gutter: 12px; }
  .brand h1 { font-size: 18px; }
  .brand p { display: none; }
  .brand-mark { width: 40px; height: 40px; border-radius: 12px; }
  .brand-mark img { width: 30px; height: 30px; }
  .chip { padding: 7px 11px; font-size: 12px; }
  .icon-btn { width: 36px; height: 36px; }
  .panel {
    top: auto; bottom: 146px; inset-inline: var(--gutter); width: auto; max-height: 42vh; padding: 12px 16px 10px;
  }
  .panel-head { cursor: pointer; }
  .panel-head::after { content: '⌃'; font-size: 14px; color: var(--ink-3); transition: transform .25s; }
  .panel.collapsed .panel-head::after { transform: rotate(180deg); }
  .panel.collapsed .story, .panel.collapsed .events { display: none; }
  .panel.collapsed .sub { margin-bottom: 0; }
  .panel h2 { font-size: 20px; margin-top: 2px; }
  .panel .sub { margin-bottom: 6px; }
  .story { font-size: 13.5px; line-height: 1.9; }
  .legend { bottom: auto; top: 64px; width: auto; inset-inline-end: var(--gutter); }
  .y-main { font-size: 30px; }
  .year { margin-bottom: 6px; }
  .bar { gap: 4px; padding: 5px; }
  .bar .icon-btn { width: 32px; height: 32px; }
  .timeline { gap: 2px; padding: 0 2px; }
  .seg .tip { display: none; }
  .hint { display: none; }
  .mk .lb { font-size: 11px; }
  .terr-label { font-size: 15px; }
  .card { width: calc(100vw - 32px); }
}
@media (max-width: 760px) and (max-height: 700px) {
  .panel { max-height: 26vh; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
