/* The depth gauge. Built by Bright Presence Digital, https://brightpresencedigital.com

   Reading an article is a descent. This is the instrument that shows how deep you are: a line
   with a mark for each section, a marker that follows the scroll exactly, the section you are
   in, and the reading time left. On a wide window it stands in the left margin. On a tablet or a
   phone it folds into one slim strip at the top that opens the contents when tapped.

   The script sets one number, --p, from 0 at the first line to 1 at the last. Everything that
   moves here is drawn from that number, so the marker can never lag behind the page.
   Layout names (--gauge-left, --gauge-w, --gauge-strip, --page-pad, --fs) come from the reading
   page's own stylesheet. Each has a fallback so this file stands up without it. */

.gauge{
  --p:0;
  font-family:var(--ui);
  font-size:calc(var(--fs,19px) * .78);
  line-height:1.3;
  font-variant-numeric:lining-nums tabular-nums;
  color:var(--ink-quiet);
}
.gauge:empty{display:none}
.gauge ol{list-style:none;margin:0;padding:0}
.gauge li{margin:0;padding:0}
.gauge a{color:inherit;text-decoration:none}
.gauge-time{margin:0;white-space:nowrap}
.gauge :focus-visible{outline:2px solid var(--accent-ink);outline-offset:3px;border-radius:2px}
.gauge-sr{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}

/* A heading that was jumped to takes focus so the keyboard carries on from there. It is not a
   control, so it shows no ring. */
.article-content h2[tabindex="-1"]:focus,.story-title[tabindex="-1"]:focus{outline:none}

/* The way back to where a returning reader stopped. Offered once, quietly, never forced. */
.gauge-resume{display:none}
.gauge--resume .gauge-resume{display:block}
.gauge a.gauge-resume{
  color:var(--ink);
  text-decoration:underline;text-decoration-color:var(--accent-ink);
  text-decoration-thickness:1px;text-underline-offset:.3em;
}

/* ------------------------------------------------------------------------------------------
   Wide windows: the instrument in the left margin
   ------------------------------------------------------------------------------------------ */
@media (min-width:1100px){
  .gauge{
    --gh:var(--gauge-h,clamp(300px,56vh,600px));
    position:fixed;z-index:5;
    left:var(--gauge-left,32px);width:var(--gauge-w,240px);
    top:calc(50vh - var(--gh) / 2);height:var(--gh);
    pointer-events:none;
  }
  .gauge > *{transition:opacity .45s var(--ease,ease),visibility 0s linear 0s}
  .gauge[data-on="0"] > :not(.gauge-resume){opacity:0;visibility:hidden;transition-delay:0s,.45s}
  .gauge[data-on="1"] > *,.gauge--resume .gauge-resume{pointer-events:auto}
  .gauge-bar,.gauge-scrim{display:none}

  /* The line itself. One pixel of rule, and over it the part already read in the topic's ink. */
  .gauge-line{position:absolute;left:0;top:0;width:1px;height:100%;background:var(--rule-strong)}
  .gauge-fill{
    position:absolute;left:-.5px;top:0;width:2px;height:100%;
    background:var(--accent-ink);
    transform-origin:50% 0;transform:scaleY(var(--p));will-change:transform;
  }
  /* The marker rides a carrier as tall as the line, so a move of --p times its own height is a
     move of --p times the line. The dark ring lifts it off the marks it passes. */
  .gauge-run{position:absolute;inset:0;transform:translateY(calc(var(--p) * 100%));will-change:transform}
  .gauge-dot{
    position:absolute;left:-4px;top:-4.5px;width:9px;height:9px;border-radius:50%;
    background:var(--accent-ink);box-shadow:0 0 0 3px var(--bg);
  }

  /* The marks. Each starts on the line at the section's true depth and leads to its label. */
  .gauge-ticks{position:absolute;left:0;top:0;width:24px;height:100%;overflow:visible}
  .gauge-ticks path{
    fill:none;stroke:var(--rule-strong);stroke-width:1;
    stroke-linecap:round;stroke-linejoin:round;transition:stroke .3s;
  }
  .gauge-ticks path.is-current{stroke:var(--accent-ink);stroke-width:1.5}

  .gauge-nav{position:absolute;left:30px;right:0;top:0}
  .gauge-nav li{position:absolute;left:0;right:0;top:0;transform:translateY(var(--y,0px))}
  .gauge-nav a{
    display:block;width:fit-content;max-width:100%;padding:3px 0;
    text-wrap:balance;transition:color .3s;
  }
  .gauge-nav a:hover{color:var(--ink)}
  .gauge-nav a[aria-current]{color:var(--ink)}

  .gauge-readout{position:absolute;left:30px;top:calc(100% + 1.9em);color:var(--ink-quiet)}
  .gauge--bare .gauge-readout{left:18px;top:auto;bottom:-.55em}
  .gauge-resume{position:absolute;left:0;right:0;bottom:calc(100% + 2em);width:fit-content;text-wrap:balance}
}

/* ------------------------------------------------------------------------------------------
   Tablets and phones: a strip at the top, and the contents behind a tap
   ------------------------------------------------------------------------------------------ */
@media (max-width:1099.98px){
  .gauge{
    position:fixed;z-index:40;left:0;right:0;top:0;
    display:flex;flex-direction:column;
    padding-top:env(safe-area-inset-top,0px);
    background:var(--bg);
    font-size:15px;
    transform:translateY(-101%);visibility:hidden;
    transition:transform .4s var(--ease,ease),visibility 0s linear .4s;
  }
  .gauge[data-on="1"],.gauge--resume{transform:none;visibility:visible;transition-delay:0s}
  .gauge-ticks,.gauge-readout,.gauge-run{display:none}

  .gauge-bar{
    order:1;
    display:grid;grid-template-columns:minmax(0,1fr) auto auto;align-items:center;gap:0 16px;
    width:100%;min-height:var(--gauge-strip,44px);margin:0;
    padding:7px max(var(--page-pad,20px),env(safe-area-inset-right,0px)) 7px max(var(--page-pad,20px),env(safe-area-inset-left,0px));
    border:0;border-radius:0;background:none;
    font:inherit;line-height:1.25;color:var(--ink-quiet);text-align:left;
    cursor:pointer;-webkit-tap-highlight-color:transparent;touch-action:manipulation;
  }
  .gauge-bar:focus-visible{outline-offset:-4px}
  .gauge-bar:disabled{cursor:default}
  .gauge-now{color:var(--ink);font-weight:500;text-wrap:balance}
  .gauge--bare .gauge-bar{grid-template-columns:auto}
  .gauge--bare .gauge-now{display:none}
  /* A small chevron, drawn not fetched. It turns over when the panel is open. */
  .gauge-chev{
    width:8px;height:8px;margin:0 2px 4px 0;
    border-right:1.5px solid var(--ink-quiet);border-bottom:1.5px solid var(--ink-quiet);
    transform:rotate(45deg);transform-origin:70% 70%;transition:transform .35s var(--ease,ease);
  }
  .gauge--open .gauge-chev{transform:rotate(-135deg)}

  /* The progress line is the bottom edge of the strip. */
  .gauge-line{order:2;position:relative;height:2px;background:var(--rule);overflow:hidden}
  .gauge-fill{
    position:absolute;inset:0;background:var(--accent-ink);
    transform-origin:0 50%;transform:scaleX(var(--p));will-change:transform;
  }
  .gauge[data-on="0"] .gauge-bar,.gauge[data-on="0"] .gauge-line{display:none}

  .gauge-resume{
    order:3;
    padding:11px max(var(--page-pad,20px),env(safe-area-inset-right,0px)) 12px max(var(--page-pad,20px),env(safe-area-inset-left,0px));
    border-bottom:1px solid var(--rule);
  }

  /* The contents panel drops out from under the strip. Closed, it is not there at all: it can
     not be tabbed into or touched. */
  .gauge-nav{
    position:absolute;left:0;right:0;top:100%;
    max-height:calc(100vh - 140px);max-height:calc(100dvh - 140px);
    overflow-y:auto;overscroll-behavior:contain;-webkit-overflow-scrolling:touch;
    background:var(--bg);border-bottom:1px solid var(--rule-strong);
    font-size:17px;line-height:1.3;
    visibility:hidden;clip-path:inset(0 0 100% 0);
    transition:clip-path .4s var(--ease,ease),visibility 0s linear .4s;
  }
  .gauge--open .gauge-nav{visibility:visible;clip-path:inset(0);transition-delay:0s}
  .gauge-nav ol{padding:8px 0 12px}
  .gauge-nav li{transform:none}
  .gauge-nav a{
    position:relative;display:block;
    padding:12px max(var(--page-pad,20px),env(safe-area-inset-right,0px)) 12px max(var(--page-pad,20px),env(safe-area-inset-left,0px));
    color:var(--ink-soft);text-wrap:balance;
  }
  .gauge-nav a:focus-visible{outline-offset:-4px}
  .gauge-nav a[aria-current]{color:var(--ink);font-weight:500}
  /* The current section carries the same mark the topic uses everywhere else: a short rule. */
  .gauge-nav a[aria-current]::before{
    content:'';position:absolute;left:0;top:50%;height:2px;margin-top:-1px;
    width:calc(max(var(--page-pad,20px),env(safe-area-inset-left,0px)) - 8px);
    background:var(--accent-ink);
  }

  /* Dims the page while the panel is open, and catches the tap that closes it. */
  .gauge-scrim{
    position:absolute;left:0;right:0;top:100%;height:100vh;height:100dvh;z-index:-1;
    background:rgba(18,18,24,.62);
    opacity:0;visibility:hidden;transition:opacity .4s var(--ease,ease),visibility 0s linear .4s;
  }
  .gauge--open .gauge-scrim{opacity:1;visibility:visible;transition-delay:0s}
}

@media print{.gauge{display:none}}
