/* Bartels rotation page. */

.bartels-page {
  --navy:#002E40; --ink:#07384a; --muted:#536971; --line:#dce6e9; --wash:#f3f7f8;
  --gold:hsl(43,27%,56%); --gold-ink:#6f5724; --gold-wash:#f2ead7;
  --above:#c5e0e3; --below:#365659; --spread:rgb(150,149,92); --open:#286343;
}
.bartels-page .bt-intro {margin-bottom:1.8rem; color:var(--muted); }

/* ---------- controls  ---------- */
.bt-controls { padding:1.25rem 1.25rem 1rem; border:1px solid var(--line); border-radius:14px; background:#fff; }
.bt-field label { display:block; margin:0 0 .35rem; color:var(--ink); font-size:.85rem; font-weight:700; }
.bt-controls .form-control { height:46px; }
.bt-plot { display:inline-flex; align-items:center; justify-content:center; height:46px; }
.bt-plot:disabled { opacity:.6; cursor:progress; }
.bt-meta { display:flex; flex-wrap:wrap; justify-content:space-between; gap:.2rem 1.5rem; min-height:1.3em; margin-top:.45rem; color:var(--muted); font-size:.78rem; }
.bt-meta p { margin:0; }

/* observatory search */
.bt-combo { position:relative; }
.bt-combo input { padding-left:2.5rem; font-weight:600; color:var(--ink);
  background:#fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' fill='none' stroke='%23536971' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='8' cy='8' r='5.5'/%3E%3Cpath d='m12.5 12.5 4 4'/%3E%3C/svg%3E") no-repeat .85rem 50%; }
.bt-combo.open input { border-bottom-left-radius:0; border-bottom-right-radius:0; }
.bt-combo ul { position:absolute; z-index:30; top:100%; left:0; right:0; max-height:min(360px,55vh); margin:0; padding:.3rem 0; overflow-y:auto; list-style:none;
  border:1px solid #002e4085; border-top:0; border-radius:0 0 10px 10px; background:#fff; box-shadow:0 14px 30px rgba(0,46,64,.16); }
.bt-combo li[role=option] { display:grid; grid-template-columns:3.4rem minmax(0,1fr) auto; gap:.75rem; align-items:baseline; padding:.5rem .9rem; cursor:pointer; }
.bt-combo li[aria-selected=true] { background:#eef5f6; }
.bt-combo li.current { box-shadow:inset 3px 0 0 var(--gold); }
.bt-combo li b { color:var(--navy); font-variant-numeric:tabular-nums; letter-spacing:.04em; }
.bt-opt-name { color:var(--ink); overflow-wrap:anywhere; }
.bt-opt-name small { display:block; color:var(--muted); font-size:.76rem; }
.bt-opt-years { color:var(--muted); font-size:.8rem; white-space:nowrap; font-variant-numeric:tabular-nums; }
.bt-opt-years.open { color:var(--open); }
.bt-combo mark { padding:0; background:var(--gold-wash); color:inherit; }
.bt-empty { padding:.8rem 1rem; color:var(--muted); font-size:.9rem; }

/* year stepper */
.bt-year { position:relative; display:flex; }
.bt-year-pick { display:none; }
.bt-year input { flex:1 1 auto; min-width:0; border-radius:0; text-align:center; font-weight:700; color:var(--ink); font-variant-numeric:tabular-nums; }
.bt-year button { flex:0 0 40px; border:1px solid #ced4da; background:var(--wash); color:var(--navy); font-size:1.5rem; line-height:1; padding:0 0 .15rem; }
.bt-year button:first-child { border-right:0; border-radius:.25rem 0 0 .25rem; }
.bt-year button:last-child { border-left:0; border-radius:0 .25rem .25rem 0; }
.bt-year button:hover:not(:disabled) { background:#e4eef0; }
.bt-year button:disabled { color:#a9b6ba; cursor:default; }

/* selected observatory */
.bt-obs { margin-top:.9rem; padding-top:1rem; border-top:1px solid var(--line); }
.bt-obs:empty { display:none; }
.bt-obs-head { display:flex; flex-wrap:wrap; align-items:center; gap:.4rem 1rem; }
.bt-obs-code { padding:.35rem .6rem; border-radius:8px; background:var(--navy); color:#fff; font-weight:700; letter-spacing:.06em; }
.bt-obs-head strong { margin-right:.6rem; color:var(--navy); font-size:1.15rem; }
.bt-status { display:inline-flex; align-items:center; gap:.35rem; color:var(--muted); font-size:.8rem; font-weight:600; }
.bt-status.open { color:var(--open); } .bt-status.open::before { background:var(--open); }
.bt-obs { position:relative; }
.bt-obs-link { position:absolute; top:1rem; right:0; color:var(--navy); font-size:.85rem; font-weight:700; text-decoration:underline; }
.bt-obs-head { padding-right:11rem; }   /* room for the link on wide screens */
.bt-obs dl { display:flex; flex-wrap:wrap; gap:.5rem 2rem; margin:.8rem 0 0; }
.bt-obs dt { color:var(--muted); font-size:.75rem; font-weight:600; }
.bt-obs dd { margin:0; color:var(--ink); font-size:.9rem; font-variant-numeric:tabular-nums; }
.bt-obs-none { margin:0; color:var(--muted); }

/* ---------- years with data (built by bartels-obs.js after #obsInfo) ---------- */
.bt-avail { position:relative; margin-top:1rem; padding-top:.9rem; border-top:1px solid var(--line); }
.bt-avail-msg { margin:0; color:var(--muted); font-size:.85rem; }
.bt-avail-head { display:flex; flex-wrap:wrap; align-items:baseline; justify-content:space-between; gap:.3rem 1.5rem; margin-bottom:.55rem; }
.bt-avail-head strong { margin-right:.7rem; color:var(--ink); font-size:.85rem; }
.bt-avail-head span { color:var(--muted); font-size:.82rem; font-variant-numeric:tabular-nums; }
.bt-avail-key { display:flex; gap:1rem; margin:0; padding:0; list-style:none; color:var(--muted); font-size:.75rem; }
.bt-avail-key li { display:flex; align-items:center; gap:.35rem; }
.bt-avail-key i { width:.7rem; height:.7rem; border-radius:2px; }
.bt-avail-scroll { overflow-x:auto; padding:9px 7px 0; margin:0 -3px; }
.bt-avail-inner { position:relative; min-width:calc(var(--n) * 2px); }   /* fits the card: no sideways scrolling for long records */
.bt-avail-strip { display:flex; gap:1px; height:30px; touch-action:pan-y; user-select:none; -webkit-user-select:none; }
.bt-avail-strip button { flex:1 1 0; min-width:0; padding:0; border:0; border-radius:2px; cursor:pointer; transition:transform .12s, opacity .12s; }
.bt-avail-strip button:hover:not(:disabled) { opacity:.75; transform:scaleY(1.12); }
.bt-avail-strip button:focus-visible { outline:2px solid var(--gold); outline-offset:2px; }
.bt-avail-strip button[aria-pressed=true] { position:relative; z-index:1; transform:scaleY(1.2); background:var(--gold) !important; box-shadow:0 0 0 2px #fff, 0 0 0 3px var(--gold); }
.bt-avail-strip button:disabled { cursor:default; }
.bt-avail-strip button.is-scrub { position:relative; z-index:2; transform:scaleY(1.25); background:var(--gold) !important; }
/* year bubble shown while hovering (mouse) or dragging (touch) along the strip */
.bt-avail-tip { position:absolute; z-index:10; transform:translate(-50%, calc(-100% - 8px)); padding:.25rem .55rem; border-radius:6px;
  background:var(--navy); color:#fff; font-size:.78rem; font-weight:700; white-space:nowrap; font-variant-numeric:tabular-nums;
  pointer-events:none; box-shadow:0 4px 12px rgba(0,46,64,.2); }
.bt-avail-tip::after { content:""; position:absolute; top:100%; left:50%; margin-left:-5px; border:5px solid transparent; border-top-color:var(--navy); }
.bt-avail-tip[hidden] { display:none; }
.bt-avail .full { background:var(--navy); }
.bt-avail .part { background:#7fa3ad; }
.bt-avail .none { background:var(--line); }
.bt-avail-axis { position:relative; height:1.4rem; margin-top:.5rem; color:var(--muted); font-size:.72rem; font-variant-numeric:tabular-nums; }
.bt-avail-axis span { position:absolute; top:0; transform:translateX(-50%); white-space:nowrap; }
.bt-avail-axis span::before { content:""; position:absolute; top:-.3rem; left:50%; height:.25rem; border-left:1px solid #b9c7cb; }
.bt-avail-note { margin:.5rem 0 0; padding:.45rem .75rem; border-radius:8px; background:var(--gold-wash); color:var(--gold-ink); font-size:.82rem; }
@media (prefers-reduced-motion:reduce) { .bt-avail-strip button { transition:none; } }

/* ---------- plot ---------- */
.bt-plotcard { margin-top:1.5rem; padding:1rem 1rem .5rem; border:1px solid var(--line); border-radius:14px; background:#fff; }
.bt-plotbar { display:flex; flex-wrap:wrap; align-items:center; justify-content:space-between; gap:.8rem; margin-bottom:.6rem; }
.bt-legend { display:flex; flex-wrap:wrap; gap:.4rem 1.2rem; margin:0; padding:0; list-style:none; color:var(--muted); font-size:.8rem; }
.bt-legend li { display:flex; align-items:center; gap:.45rem; }
/* legend keys are small drawings of what's on the plot */
.bt-key { flex:none; width:20px; height:13px; overflow:visible; }
.bt-key .k-above { fill:var(--above); } .bt-key .k-below { fill:var(--below); }
.bt-key .k-trace { fill:none; stroke:var(--ink); stroke-width:1.2; stroke-linejoin:round; }
.bt-key .k-mean { stroke:var(--ink); stroke-width:.8; stroke-dasharray:2 1.5; }
.bt-key-bar { width:10px; height:15px; }
.bt-key-bar path { fill:none; stroke:var(--spread); stroke-width:1.6; }
#scaleValue { color:var(--ink); font-weight:700; font-variant-numeric:tabular-nums; }

#viewToggle { gap:0; border:1px solid var(--line); border-radius:999px; padding:3px; background:var(--wash); }
#viewToggle button { padding:.3rem .9rem; border:0; border-radius:999px; background:none; color:var(--muted); font-size:.82rem; font-weight:700; }
#viewToggle button[aria-pressed=true] { background:#fff; color:var(--navy); box-shadow:0 1px 3px rgba(0,46,64,.18); }

.bartels-page #badYear { margin:0 0 .8rem; }

#chartContainer { position:relative; height:clamp(640px,110vh,1050px); }
.bartels-page #bartelsCanvas { border:0; border-radius:0; }
.rotation-label { position:absolute; right:2px; color:var(--muted); font-size:11px; font-variant-numeric:tabular-nums; line-height:1; pointer-events:none; }
.month-label { position:absolute; transform:translateX(-50%); padding:0 .3rem; border-radius:4px; background:rgba(255,255,255,.85); color:var(--gold-ink); font-size:10.5px; font-weight:700; line-height:1.5; pointer-events:none; }

/* loading and empty states */
#loadingOverlay { position:absolute; inset:0; z-index:5; display:none; flex-direction:column; align-items:center; justify-content:center; gap:.7rem; border-radius:10px; background:rgba(255,255,255,.9); transition:opacity .2s; }
#loaderStatus { color:var(--navy); font-weight:700; }
.loader-bar { width:min(320px,70%); height:6px; overflow:hidden; border-radius:99px; background:var(--line); }
.loader-fill { width:0; height:100%; border-radius:inherit; background:var(--navy); transition:width .1s linear; }
#loaderCount { color:var(--muted); font-size:.8rem; font-variant-numeric:tabular-nums; }

.bt-credit { margin:.5rem -.5rem 0; padding:.8rem .5rem .3rem; border-top:1px solid var(--line); color:var(--muted); font-size:.8rem; text-align:center; }

/* ---------- reading the plot ---------- */
.bt-help { margin-top:3rem; padding:2.6rem 1.5rem 2rem; border-radius:16px; background:var(--wash); text-align:center; color:#29434b; }
.bt-help h2 { margin-bottom:.6rem; color:var(--navy); font-size:clamp(1.4rem,3vw,1.75rem); font-weight:600; }
.bt-help-lead { margin-bottom:2.2rem; color:var(--muted); }
.bt-help-item { margin-bottom:1.6rem; padding:2rem}
.bt-help-item svg { display:block; width:100%; height:auto; margin:0 auto 1rem; padding:.6rem; border:1px solid var(--line); border-radius:12px; background:#fff; }
.bt-help-item h3 { margin-bottom:.4rem; color:var(--navy); font-size:1.05rem; font-weight:700; }
.bt-help-item p {  margin:0 auto; font-size:.92rem; line-height:1.6; }
.bt-help-note { margin:.6rem auto 0; color:var(--muted); font-size:.85rem; }
.bt-help .ill-base line { stroke:var(--line); stroke-width:1; stroke-dasharray:3 2; }
.bt-help .ill-trace, .bt-help .ill-trace use { fill:none; stroke:var(--navy); stroke-width:1.4; stroke-linejoin:round; }
.bt-help .ill-num text { fill:var(--muted); font-size:8px; font-family:inherit; }
.bt-help .ill-above { fill:var(--above); } .bt-help .ill-below { fill:var(--below); }
.bt-help .ill-mean { stroke:var(--navy); stroke-width:.8; stroke-dasharray:4 2; }
.bt-help .ill-band { fill:var(--gold-wash); stroke:var(--gold); stroke-width:1; }

/* ---------- small screens ---------- */
@media (max-width:991.98px) {
  .bt-meta { justify-content:flex-start; }
}
@media (max-width:767.98px) {
  .bt-controls { padding:1rem .9rem .8rem; }
  .bt-field label { font-size:.8rem; }
  .bt-combo ul { max-height:50vh; }
  .bt-combo li[role=option] { grid-template-columns:3rem minmax(0,1fr); padding:.55rem .75rem; }
  .bt-opt-years { grid-column:2; }

  .bt-obs-head strong { font-size:1.05rem; }
  .bt-obs-head { padding-right:0; }

  .bt-obs-link { position:static; display:inline-flex; align-items:center; gap:.3rem; margin-top:.9rem; padding:.35rem .8rem;
    border:1px solid var(--line); border-radius:999px; background:var(--wash); font-size:.78rem; text-decoration:none; }
  .bt-obs dl { display:grid; grid-template-columns:1fr 1fr; gap:.6rem 1rem; }
  .bt-obs dl div:last-child:nth-child(odd) { grid-column:1 / -1; }
  .bt-plotbar { flex-direction:column; align-items:stretch; }
  .bt-legend { gap:.3rem 1rem; font-size:.76rem; }

  #viewToggle button { flex:1; }
  #chartContainer { height:clamp(560px,95vh,820px); }

  .bt-plotcard { padding:.6rem .4rem .4rem; }
  .bt-help { margin-top:2rem; padding:2rem 1rem 1.2rem; }
}
@media (prefers-reduced-motion:reduce) { #loadingOverlay, .loader-fill { transition:none; } }

/* ---------- view toggle + download ---------- */
.bt-actions { display:flex; align-items:stretch; gap:.5rem; }

.bt-download {
  display:inline-flex; align-items:center; justify-content:center; gap:.4rem;
  padding:.3rem .95rem;
  border:1px solid var(--below); border-radius:999px;
  background:#fff; color:var(--below);
  font-size:.82rem; font-weight:700; line-height:1.2; white-space:nowrap;
  transition:background-color .15s ease, color .15s ease, box-shadow .15s ease;
}
.bt-download svg { flex:none; width:1.05em; height:1.05em; }
.bt-download:hover:not(:disabled),
.bt-download:focus-visible { background:var(--below); color:#fff; box-shadow:0 2px 8px rgba(54,86,89,.25); }
.bt-download:focus-visible { outline:2px solid var(--above); outline-offset:2px; }
.bt-download:disabled { display:none; }   /* hidden while loading, or when there is nothing to download */

@media (max-width:767.98px) {
  .bt-actions { width:100%; }
  .bt-actions #viewToggle { flex:1 1 auto; min-width:0; }
  .bt-actions #viewToggle button { padding:.35rem .45rem; font-size:.78rem; white-space:nowrap; }
  .bt-download { flex:0 0 auto; width:42px; padding:0; }
  .bt-download span { position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0 0 0 0); white-space:nowrap; }
}
@media (prefers-reduced-motion:reduce) { .bt-download { transition:none; } }

/* ---------- phones and touch screens: the year is chosen with the device's own picker ---------- */
@media (pointer:coarse), (max-width:767.98px) {
  /* invisible native <select> over the year number: tapping it opens the system wheel/list */
  .bt-year-pick { display:block; position:absolute; top:0; bottom:0; left:40px; width:calc(100% - 80px);
    opacity:0; font-size:16px; /* 16px stops iOS zooming in */ cursor:pointer; }
  .bt-year input { padding-right:1.4rem;
    background:#fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none' stroke='%23536971' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m1 1 4 4 4-4'/%3E%3C/svg%3E") no-repeat right .6rem center; }
  /* the strip becomes an overview only: too many years to tap accurately */
  .bt-avail-strip { height:16px; pointer-events:none; }
}