/* Mumbai Through Time — Admiralty-chart palette */
:root {
  --sea: #a9c2c6;        /* chart blue */
  --sea-deep: #8eabb3;
  --land: #e2d6b3;       /* buff, as on survey sheets */
  --new: #c4891d;        /* ochre wash for freshly reclaimed land */
  --marsh: #8b9a6c;      /* sage, hatched */
  --ink: #1f3340;        /* blue-black iron-gall ink */
  --ink-soft: #4c5f69;
  --sheet: rgba(240, 233, 214, 0.94);  /* card paper */
  --rule: rgba(31, 51, 64, 0.28);
  /* crisp 1px cartographic halo (eight offsets), not a blurred glow */
  --halo: 1px 0 0 var(--land), -1px 0 0 var(--land), 0 1px 0 var(--land), 0 -1px 0 var(--land),
          1px 1px 0 var(--land), -1px -1px 0 var(--land), 1px -1px 0 var(--land), -1px 1px 0 var(--land);
  --display: "IM Fell English", Georgia, serif;
  --body: "Alegreya Sans", "Gill Sans", system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { background: var(--sea); color: var(--ink); font: 16px/1.5 var(--body); scrollbar-color: var(--ink-soft) transparent; }
::selection { background: var(--new); color: var(--ink); }

#map { position: absolute; inset: 0; }
.paper {
  position: absolute; inset: 0; pointer-events: none; z-index: 1; mix-blend-mode: multiply; opacity: .5;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .45 0 0 0 0 .38 0 0 0 0 .25 0 0 0 .22 0'/%3E%3C/filter%3E%3Crect width='240' height='240' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* --- cartouche: the year is the hero --- */
#cartouche {
  position: absolute; z-index: 2; top: 20px; left: 24px; pointer-events: none;
  text-shadow: var(--halo);
}
#year {
  margin: 0; font: 400 clamp(4rem, 11vw, 8.5rem)/.88 var(--display);
  letter-spacing: -.02em; font-variant-numeric: oldstyle-nums; color: var(--ink);
}
#title { margin: .2em 0 0; max-width: 18ch; font: italic 400 clamp(1.25rem, 2.4vw, 1.75rem)/1.15 var(--display); }

/* --- era card --- */
#card {
  position: absolute; z-index: 2; left: 24px; bottom: 112px; width: min(400px, calc(100vw - 32px));
  max-height: calc(100vh - 360px); overflow: auto;
  padding: 18px 20px 16px; background: var(--sheet); border: 1px solid var(--rule);
  box-shadow: 0 2px 4px rgba(31, 51, 64, .08), 0 10px 24px -12px rgba(31, 51, 64, .3);
}
#caption { margin: 0; font-size: 1.02rem; line-height: 1.55; max-width: 62ch; }
#note { margin: .7em 0 0; font: italic .92rem/1.45 var(--body); color: var(--ink-soft); }
#stats { display: grid; grid-template-columns: repeat(3, auto); gap: 4px 18px; margin: 14px 0 0; padding-top: 12px; border-top: 1px solid var(--rule); }
#stats div { min-width: 0; }
#stats dt { font-size: .78rem; line-height: 1.2; color: var(--ink-soft); }
#stats dd { margin: 2px 0 0; font: 1.35rem/1.1 var(--display); font-variant-numeric: lining-nums; }
#s-added { color: #8a5c08; }

#underlay-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin-top: 12px; }
#underlay-row[hidden] { display: none; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 500; }
.switch input { width: 18px; height: 18px; accent-color: var(--ink); margin: 0; }
#underlay-opacity { flex: 1 1 110px; accent-color: var(--ink); }
#underlay-opacity:disabled { opacity: .35; }
#underlay-name { flex-basis: 100%; margin: 0; font: italic .9rem/1.3 var(--body); color: var(--ink-soft); }
#underlay-name a { color: inherit; }

/* --- legend --- */
#legend {
  position: absolute; z-index: 2; top: 20px; right: 20px; padding: 12px 14px;
  background: var(--sheet); border: 1px solid var(--rule); font-size: .9rem;
}
.chart-title { margin: 0 0 8px; padding-bottom: 7px; border-bottom: 1px solid var(--rule); font: 400 1.2rem/1.1 var(--display); }
#legend ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; }
#legend li { display: flex; align-items: center; gap: 9px; }
.sw { display: inline-block; width: 22px; height: 13px; border: 1px solid var(--ink); flex: none; }
.sw.land { background: var(--land); }
.sw.new { background: var(--new); }
.sw.marsh { background: repeating-linear-gradient(-45deg, var(--marsh) 0 1.5px, var(--land) 1.5px 4px); }
.sw.future { border: 1.5px dashed var(--ink-soft); background: transparent; }
.sw.link { height: 0; border: 0; border-top: 3px solid var(--ink); }
#about-open {
  margin-top: 10px; padding: 0; border: 0; background: none; color: var(--ink); cursor: pointer;
  font: italic 1rem var(--display); text-decoration: underline; text-decoration-color: var(--rule); text-underline-offset: 3px;
}
.about-btn:hover, .credit a:hover, .mobile-meta a:hover, #about a:hover, #underlay-name a:hover { text-decoration-color: currentColor; text-decoration-thickness: 2px; }

.mobile-meta { display: none; }
.credit { max-width: 24ch; margin: 10px 0 0; padding-top: 9px; border-top: 1px solid var(--rule); font-size: .85rem; line-height: 1.35; color: var(--ink-soft); }
.credit a { color: var(--ink); text-underline-offset: 2px; }

/* --- timeline as a chart scale bar --- */
#timeline {
  position: absolute; z-index: 2; left: 0; right: 0; bottom: 0; display: flex; align-items: center; gap: 14px;
  padding: 14px 28px 18px 20px; background: linear-gradient(to top, rgba(240, 233, 214, .96) 70%, rgba(240, 233, 214, 0));
}
#play {
  flex: none; width: 46px; height: 46px; border-radius: 50%; border: 1.5px solid var(--ink);
  background: var(--sheet); color: var(--ink); cursor: pointer; display: grid; place-items: center;
  transition: background-color .15s ease-out, color .15s ease-out;
}
#play:hover { background: var(--ink); color: var(--sheet); }
#play svg { width: 18px; height: 18px; fill: currentColor; }
#scale { position: relative; flex: 1; height: 72px; }
#bar {
  position: absolute; left: 0; right: 0; top: 30px; height: 9px; border: 1.5px solid var(--ink);
  /* alternating 50-year blocks, like a scale of miles; --seg is set from JS */
  background: repeating-linear-gradient(to right, var(--ink) 0 var(--seg, 10%), var(--land) var(--seg, 10%) calc(var(--seg, 10%) * 2));
  background-position-x: var(--seg-off, 0);
}
#ticks { list-style: none; margin: 0; padding: 0; position: absolute; inset: 0; }
#ticks li { position: absolute; top: 0; height: 100%; transform: translateX(-50%); }
#ticks button {
  position: relative; height: 100%; padding: 0 2px; border: 0; background: none; cursor: pointer;
  color: var(--ink-soft); font: .95rem/1 var(--display); font-variant-numeric: lining-nums;
}
#ticks button::before { /* the tick mark through the bar */
  content: ""; position: absolute; left: 50%; top: 24px; width: 1.5px; height: 21px; background: var(--ink); transform: translateX(-50%);
}
#ticks button::after { /* era marker: a small triangle, like a north arrow tip */
  content: ""; position: absolute; left: 50%; top: 44px; transform: translateX(-50%);
  border: 6px solid transparent; border-bottom: 9px solid var(--ink-soft); border-top: 0;
}
#ticks .lbl { position: absolute; left: 50%; transform: translateX(-50%); white-space: nowrap; bottom: 0; }
#ticks li.up .lbl { top: 2px; bottom: auto; }
#ticks button[aria-current="true"] { color: var(--ink); }
#ticks button[aria-current="true"] .lbl { font-size: 1.15rem; font-style: italic; }
#ticks button[aria-current="true"]::after { border-bottom-color: var(--new); border-width: 0 8px 12px; top: 42px; }
#ticks button:hover { color: var(--ink); }

button:focus-visible, input:focus-visible, a:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* place names */
.place { font: italic 15px/1 var(--display); color: var(--ink); white-space: nowrap; pointer-events: none;
  text-shadow: var(--halo); }
.place.covered { visibility: hidden; }
.place.isl { font-size: 17px; letter-spacing: .04em; }
.place.sea { color: #33505b; text-shadow: none; letter-spacing: .3em; font-size: 14px; }

/* about dialog */
#about { max-width: 640px; width: calc(100vw - 32px); max-height: calc(100vh - 48px); padding: 24px 28px; border: 1px solid var(--ink);
  background: #f0e9d6; color: var(--ink); font-size: 1rem; line-height: 1.55; }
#about::backdrop { background: rgba(31, 51, 64, .35); }
#about h2 { margin: 0 0 .5em; font: 400 1.9rem/1.1 var(--display); }
#about h3 { margin: 1.2em 0 .3em; font: italic 400 1.25rem var(--display); }
#about ul { padding-left: 1.2em; }
#about li { margin: .25em 0; }
#about a { color: var(--ink); }
#about .close { position: absolute; top: 10px; right: 10px; width: 44px; height: 44px; display: grid; place-items: center; border: 0; background: none; cursor: pointer; color: var(--ink); }
#about .close svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; }
#about .close:hover { background: rgba(31, 51, 64, .08); }

.maplibregl-ctrl-attrib { background: rgba(240, 233, 214, .85) !important; font-family: var(--body); }
.maplibregl-ctrl-bottom-right { bottom: 96px; }
.maplibregl-ctrl-scale { font: 12px var(--body); color: var(--ink); background: var(--sheet); border-color: var(--ink); }
.maplibregl-ctrl-group { background: var(--sheet); border-radius: 0; box-shadow: none; border: 1px solid var(--rule); }

/* --- phones --- */
@media (max-width: 720px) {
  #cartouche { top: 12px; left: 16px; }
  #year { font-size: 3.6rem; }
  #title { font-size: 1.15rem; max-width: 20ch; }
  #legend { display: none; }
  .mobile-meta { display: flex; flex-wrap: wrap; gap: 2px 12px; align-items: baseline; margin: 10px 0 0; padding-top: 8px; border-top: 1px solid var(--rule); font-size: .85rem; color: var(--ink-soft); }
  .mobile-meta a { color: var(--ink); }
  .mobile-meta .about-btn { padding: 6px 0; border: 0; background: none; color: var(--ink); font: italic .95rem var(--display); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
  #card { left: 16px; right: 16px; width: auto; bottom: 96px; max-height: 32vh; padding: 12px 14px; }
  #note { font-size: .85rem; }
  #stats { margin-top: 10px; padding-top: 8px; }
  #caption { font-size: .95rem; }
  #stats dd { font-size: 1.1rem; }
  #timeline { padding: 10px 16px 14px; gap: 10px; }
  #play { width: 40px; height: 40px; }
  #ticks .lbl { font-size: .78rem; }
  #ticks li:not(.on):not(.major) .lbl, #ticks li.near .lbl { visibility: hidden; }
  .maplibregl-ctrl-bottom-right { bottom: calc(32vh + 104px); }
  .maplibregl-ctrl-group { display: none; }
  .maplibregl-ctrl-top-right { display: none; }
}

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