:root {
  --ink: #14304a;          /* chart navy ink */
  --ink-soft: #3f5e7d;
  --magenta: #b51e7a;       /* chart magenta (lights, compass, cautions) */
  --paper: #f7f0dd;         /* parchment */
  --paper-2: #fbf6e7;
  --rule: #1b3a5b;          /* chart border blue */
  --chan-red: #c0392b;
  --chan-green: #1f8a4c;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: #dfe7ea; color: var(--ink);
  font-family: "Spectral", Georgia, serif; overflow: hidden; }
#map { position: absolute; inset: 0; background: #cfe0e6; }
.mono { font-family: "IBM Plex Mono", ui-monospace, monospace; }

/* Paper grain + warm tooth over the whole chart, so it (and the pencil paths
   drawn into it) read as pigment on printed paper rather than a flat screen. */
#grain {
  position: absolute; inset: 0; z-index: 2; pointer-events: none;
  background-image:
    radial-gradient(120% 90% at 50% 40%, rgba(255,247,225,0) 55%, rgba(120,92,40,0.16) 100%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.5'/%3E%3C/svg%3E");
  background-size: cover, 200px 200px;
  mix-blend-mode: multiply; opacity: 0.42;
}

/* ---- Parchment panel base (shared) ---- */
.paper {
  background:
    linear-gradient(0deg, rgba(20,48,74,0.025), rgba(20,48,74,0.025)),
    var(--paper);
  border: 1px solid var(--rule);
  box-shadow: 0 0 0 3px var(--paper), 0 0 0 4px var(--rule),
    0 10px 34px rgba(10,30,50,0.28);
}

/* ---- Title ---- */
#title {
  position: absolute; top: 20px; left: 22px; z-index: 5; max-width: 392px;
  padding: 13px 18px 14px; pointer-events: none;
  background: rgba(251,246,231,0.9); border: 1px solid var(--rule);
  box-shadow: 0 0 0 3px rgba(251,246,231,0.9), 0 0 0 4px var(--rule), 0 8px 26px rgba(10,30,50,0.25);
  backdrop-filter: blur(2px);
  transition: opacity 0.5s ease;
}
#title.dim { opacity: 0.18; }
#title.dim:hover { opacity: 1; }
#title.hidden { opacity: 0; pointer-events: none; }
#title-close { position: absolute; top: 5px; right: 7px; z-index: 6; pointer-events: auto;
  border: 0; background: transparent; color: var(--ink-soft); font: 400 18px/1 "Spectral", serif;
  cursor: pointer; padding: 2px 5px; }
#title-close:hover { color: var(--magenta); }
#title h1 { font-size: 30px; font-weight: 700; letter-spacing: 0.5px; line-height: 1;
  color: var(--ink); font-variant: small-caps; }
#title .sub { margin-top: 7px; font-size: 13.5px; font-style: italic; color: var(--ink-soft);
  line-height: 1.4; }

/* ---- Compass rose ---- */
#compass { position: absolute; top: 78px; right: 26px; width: 116px; height: 116px;
  z-index: 4; opacity: 0.82; pointer-events: none;
  filter: drop-shadow(0 2px 6px rgba(10,30,50,0.25)); }

/* ---- Mode toggle ---- */
#modes {
  position: absolute; top: 20px; right: 22px; z-index: 6; display: flex; gap: 0;
  background: var(--paper); border: 1px solid var(--rule); padding: 4px;
  box-shadow: 0 0 0 3px var(--paper), 0 0 0 4px var(--rule), 0 8px 26px rgba(10,30,50,0.25);
}
#modes button {
  border: 0; background: transparent; color: var(--ink-soft); cursor: pointer;
  font: 600 13px "Spectral", serif; padding: 7px 17px; letter-spacing: 0.4px;
  font-variant: small-caps; transition: all 0.16s;
}
#modes button.active { background: var(--ink); color: var(--paper-2); }
#modes button.day.active { background: var(--magenta); color: #fff; }
#modes button.live.active { background: var(--chan-red); color: #fff; }

/* ---- Bottom control panel ---- */
#panel {
  position: absolute; left: 22px; right: 22px; bottom: 20px; z-index: 5;
  padding: 14px 20px 15px; display: grid; gap: 10px;
  background: linear-gradient(0deg, rgba(20,48,74,0.02), rgba(20,48,74,0.02)), rgba(247,240,221,0.94);
  border: 1px solid var(--rule);
  box-shadow: 0 0 0 3px rgba(247,240,221,0.94), 0 0 0 4px var(--rule), 0 10px 34px rgba(10,30,50,0.3);
  backdrop-filter: blur(2px);
  transition: opacity 0.3s ease;
}
/* chart-corner ticks */
.corner { position: absolute; width: 11px; height: 11px; border: 0 solid var(--magenta); }
.corner.tl { top: 5px; left: 5px; border-top-width: 2px; border-left-width: 2px; }
.corner.tr { top: 5px; right: 5px; border-top-width: 2px; border-right-width: 2px; }
.corner.bl { bottom: 5px; left: 5px; border-bottom-width: 2px; border-left-width: 2px; }
.corner.br { bottom: 5px; right: 5px; border-bottom-width: 2px; border-right-width: 2px; }

.row { display: flex; align-items: center; gap: 15px; flex-wrap: wrap; }

#clock { display: flex; align-items: baseline; gap: 11px; min-width: 250px; }
#clock #date { font-size: 25px; font-weight: 600; letter-spacing: 1px; color: var(--ink); }
#clock #season { font-size: 12px; color: var(--magenta); text-transform: uppercase;
  letter-spacing: 2.5px; font-family: "IBM Plex Mono", monospace; }
#clock #daytime { font-size: 18px; color: var(--magenta); font-weight: 500; }
#clock #live-count { font-size: 14px; color: var(--chan-red); font-style: italic; }

#play {
  width: 42px; height: 42px; border-radius: 50%; border: 2px solid var(--ink);
  background: var(--paper-2); color: var(--ink); cursor: pointer; font-size: 15px;
  display: grid; place-items: center; transition: all 0.15s; flex: none;
}
#play:hover { background: var(--ink); color: var(--paper-2); }
#tl-wrap { flex: 1; min-width: 180px; display: flex; flex-direction: column; gap: 3px; }
#timeline { width: 100%; margin: 0; accent-color: var(--magenta); height: 3px; cursor: pointer; }
#tl-ticks { display: flex; justify-content: space-between; font-family: "IBM Plex Mono", monospace;
  font-size: 9.5px; letter-spacing: 0.5px; color: var(--ink-soft); padding-top: 2px;
  border-top: 1px solid rgba(27,58,91,0.18); }
#speed { background: var(--paper-2); color: var(--ink); border: 1px solid var(--rule);
  padding: 7px 9px; font: 500 12px "IBM Plex Mono", monospace; cursor: pointer; }
#daynote { font-size: 11.5px; font-style: italic; color: var(--ink-soft); }
#aiscaveat { font-size: 11px; font-style: italic; color: var(--ink-soft); line-height: 1.35; }
#daytoggle { background: var(--paper-2); color: var(--ink); border: 1.5px solid var(--rule);
  padding: 8px 14px; font: 600 13px "Spectral", serif; font-variant: small-caps; letter-spacing: 0.5px;
  cursor: pointer; white-space: nowrap; box-shadow: 0 1px 4px rgba(10,30,50,0.15); }
#daytoggle:hover { background: var(--ink); color: var(--paper-2); }
#daytoggle.on { background: var(--magenta); color: #fff; border-color: var(--magenta); }

.keylabel { font-size: 11px; letter-spacing: 2px; text-transform: uppercase; color: var(--ink-soft);
  font-family: "IBM Plex Mono", monospace; }
#legend { display: flex; gap: 7px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer; user-select: none;
  background: var(--paper-2); border: 1px solid var(--rule); color: var(--ink);
  padding: 5px 11px 5px 8px; font-size: 12.5px; transition: all 0.15s;
}
.chip .dot { width: 11px; height: 11px; border-radius: 50%; border: 1px solid rgba(20,48,74,0.45); }
.chip .cnt { font-family: "IBM Plex Mono", monospace; font-size: 11px; color: var(--ink-soft);
  margin-left: 3px; font-variant-numeric: tabular-nums; }
.chip.off { opacity: 0.6; background: transparent; text-decoration: line-through;
  text-decoration-color: rgba(20,48,74,0.55); }
.chip.off .dot { background: transparent !important; }
.chip:hover { box-shadow: inset 0 0 0 1px var(--magenta); }

/* tooltip */
#tooltip {
  position: absolute; z-index: 7; pointer-events: none; display: none;
  background: var(--paper-2); border: 1px solid var(--rule); padding: 7px 11px;
  font-size: 13px; max-width: 240px; box-shadow: 0 0 0 2px var(--paper-2), 0 0 0 3px var(--rule), 0 6px 20px rgba(10,30,50,0.35);
}
#tooltip .nm { font-weight: 600; color: var(--ink); }
#tooltip .meta { color: var(--ink-soft); font-size: 11.5px; margin-top: 2px; font-family: "IBM Plex Mono", monospace; }

/* live-loading toast */
#toast { position: absolute; top: 78px; left: 50%; transform: translateX(-50%); z-index: 8;
  background: rgba(247,240,221,0.96); border: 1px solid var(--rule); color: var(--ink-soft);
  font-size: 12px; font-style: italic; padding: 7px 15px; max-width: 78vw; text-align: center;
  box-shadow: 0 0 0 2px rgba(247,240,221,0.96), 0 0 0 3px var(--rule), 0 6px 18px rgba(10,30,50,0.3);
  opacity: 0; pointer-events: none; transition: opacity 0.5s ease; }
#toast.show { opacity: 1; }

/* status */
#status {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); z-index: 8;
  padding: 15px 24px; font-size: 14px; font-style: italic; color: var(--ink); display: none;
  background: var(--paper); border: 1px solid var(--rule);
  box-shadow: 0 0 0 3px var(--paper), 0 0 0 4px var(--rule), 0 10px 30px rgba(10,30,50,0.3);
}
#status.show { display: block; }
.spin { display: inline-block; width: 13px; height: 13px; border: 2px solid rgba(181,30,122,0.3);
  border-top-color: var(--magenta); border-radius: 50%; animation: s 0.8s linear infinite;
  vertical-align: -1px; margin-right: 9px; }
@keyframes s { to { transform: rotate(360deg); } }

#notice { position: absolute; bottom: 4px; left: 26px; z-index: 5; font-size: 10.5px;
  font-style: italic; color: var(--ink-soft); font-family: "IBM Plex Mono", monospace;
  letter-spacing: 0.5px; text-shadow: 0 1px 2px rgba(247,240,221,0.8); }
/* ---- Stats ("by the numbers") ---- */
#stats-btn { position: absolute; bottom: 3px; left: 50%; transform: translateX(-50%); z-index: 5;
  background: var(--paper); border: 1px solid var(--rule); color: var(--ink); cursor: pointer;
  font: 600 11px "Spectral", serif; font-variant: small-caps; letter-spacing: 0.6px; padding: 3px 14px;
  box-shadow: 0 0 0 2px var(--paper), 0 0 0 3px var(--rule); }
#stats-btn:hover { background: var(--ink); color: var(--paper-2); }
#stats-panel { position: absolute; inset: 0; z-index: 9; display: flex; align-items: center;
  justify-content: center; background: rgba(10,30,50,0.4); backdrop-filter: blur(3px); }
#stats-panel.hidden { display: none; }
#stats-body { position: relative; background: var(--paper); border: 1px solid var(--rule);
  box-shadow: 0 0 0 3px var(--paper), 0 0 0 4px var(--rule), 0 18px 50px rgba(10,30,50,0.45);
  max-width: 740px; width: calc(100% - 44px); max-height: 88vh; overflow-y: auto; padding: 24px 28px 26px; }
#stats-close { position: absolute; top: 10px; right: 14px; border: 0; background: transparent;
  color: var(--ink-soft); font: 400 22px/1 "Spectral", serif; cursor: pointer; }
#stats-close:hover { color: var(--magenta); }
.sh1 { font-size: 22px; font-variant: small-caps; letter-spacing: 0.5px; color: var(--ink); }
.ssub { color: var(--ink-soft); font-style: italic; margin: 2px 0 14px; }
.sh2 { font-size: 14px; font-variant: small-caps; letter-spacing: 0.6px; color: var(--ink);
  margin: 18px 0 8px; border-bottom: 1px solid rgba(27,58,91,0.2); padding-bottom: 3px; }
.sh2 span { color: var(--ink-soft); font-variant: normal; font-style: italic; font-size: 12px; letter-spacing: 0; }
.scols { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; }
.srow { display: grid; grid-template-columns: 130px 1fr 52px; align-items: center; gap: 8px; margin: 4px 0; font-size: 12.5px; }
.slab { color: var(--ink); display: flex; align-items: center; gap: 6px; }
.sdot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.sbar { background: rgba(20,48,74,0.08); height: 12px; border-radius: 2px; overflow: hidden; }
.sbar span { display: block; height: 100%; }
.sval { font-family: "IBM Plex Mono", monospace; font-size: 11.5px; text-align: right; color: var(--ink); }
.sfacts { margin: 4px 0 0; padding-left: 18px; } .sfacts li { margin: 7px 0; line-height: 1.5; }
.snote { color: var(--ink-soft); font-style: italic; font-size: 11.5px; margin-top: 8px; }
@media (max-width: 640px) { .scols { grid-template-columns: 1fr; } .srow { grid-template-columns: 110px 1fr 46px; } }
a.method { position: absolute; bottom: 4px; right: 26px; z-index: 5; font-size: 11px;
  color: var(--magenta); text-decoration: none; font-style: italic; text-shadow: 0 1px 2px rgba(247,240,221,0.8); }
a.method:hover { text-decoration: underline; }

/* maplibre controls -> chart tint */
.maplibregl-ctrl-group { border: 1px solid var(--rule) !important; }

@media (max-width: 660px) {
  #title { max-width: 54vw; padding: 9px 12px; } #title h1 { font-size: 19px; }
  #title .sub { display: none; }
  #modes { padding: 3px; } #modes button { padding: 6px 11px; font-size: 12px; }
  #compass { display: none; }
  #clock #date { font-size: 20px; }
  #panel { left: 8px; right: 8px; bottom: 8px; padding: 11px 13px 13px; }
  .keylabel { display: none; }
  #notice, a.method { display: none; }
}
