/* ==========================================================================
   Homepage widgets
   Visitor counter · dark mode · TOC · reading progress · back-to-top ·
   copy-to-clipboard · toasts
   Loaded after main.css so plain-specificity rules win.
   ========================================================================== */

:root {
  --w-accent: #00369f;
  --w-surface: #ffffff;
  --w-surface-2: #f6f7f9;
  --w-border: #e3e5e8;
  --w-text: #494d51;
  --w-text-dim: #7a8288;
  --w-shadow: 0 2px 10px rgba(0, 0, 0, .12);
  --w-radius: 8px;
}

/* --------------------------------------------------------------------------
   1. Dark theme
   -------------------------------------------------------------------------- */

html[data-theme="dark"] {
  --w-accent: #5b9dff;
  --w-surface: #1c1f24;
  --w-surface-2: #23262c;
  --w-border: #33373f;
  --w-text: #c7cbd1;
  --w-text-dim: #8b929c;
  --w-shadow: 0 2px 10px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

html[data-theme="dark"] body {
  background-color: #14161a;
  color: var(--w-text);
}

html[data-theme="dark"] .masthead {
  background-color: var(--w-surface);
  border-bottom-color: var(--w-border);
}

html[data-theme="dark"] .greedy-nav,
html[data-theme="dark"] .greedy-nav .hidden-links {
  background: var(--w-surface);
}

html[data-theme="dark"] .greedy-nav a,
html[data-theme="dark"] .greedy-nav .hidden-links a {
  color: var(--w-text);
}

html[data-theme="dark"] .greedy-nav a:hover,
html[data-theme="dark"] .greedy-nav .hidden-links a:hover {
  color: var(--w-accent);
}

html[data-theme="dark"] .greedy-nav button {
  background-color: var(--w-surface-2);
}

html[data-theme="dark"] .greedy-nav .hidden-links:before {
  border-bottom-color: var(--w-border);
}

html[data-theme="dark"] .greedy-nav .hidden-links:after {
  border-bottom-color: var(--w-surface);
}

html[data-theme="dark"] .navicon,
html[data-theme="dark"] .navicon:before,
html[data-theme="dark"] .navicon:after {
  background: var(--w-text);
}

html[data-theme="dark"] .page__content,
html[data-theme="dark"] .page__inner-wrap,
html[data-theme="dark"] .sidebar,
html[data-theme="dark"] .author__content,
html[data-theme="dark"] .author__urls-wrapper li {
  color: var(--w-text);
}

html[data-theme="dark"] h1,
html[data-theme="dark"] h2,
html[data-theme="dark"] h3,
html[data-theme="dark"] h4,
html[data-theme="dark"] h5,
html[data-theme="dark"] h6,
html[data-theme="dark"] .author__name,
html[data-theme="dark"] strong {
  color: #e8eaed;
}

html[data-theme="dark"] a {
  color: var(--w-accent);
}

html[data-theme="dark"] a:hover {
  color: #8fbcff;
}

html[data-theme="dark"] a:visited {
  color: #9d8fe0;
}

html[data-theme="dark"] .author__urls.social-icons a,
html[data-theme="dark"] .author__urls-wrapper a {
  color: var(--w-accent);
}

html[data-theme="dark"] .author__urls {
  background: transparent;
  border-color: var(--w-border);
}

html[data-theme="dark"] .author__avatar img {
  border-color: var(--w-border);
}

html[data-theme="dark"] .paper-box {
  border-bottom-color: var(--w-border);
}

html[data-theme="dark"] .paper-box-image img {
  box-shadow: 3px 3px 8px rgba(0, 0, 0, .6);
  filter: brightness(.9);
}

html[data-theme="dark"] .badge {
  background-color: #2f5bb7;
  color: #fff;
}

html[data-theme="dark"] code,
html[data-theme="dark"] pre,
html[data-theme="dark"] tt {
  background: var(--w-surface-2);
  color: #e0c58a;
}

html[data-theme="dark"] blockquote {
  border-left-color: var(--w-border);
  color: var(--w-text-dim);
}

html[data-theme="dark"] hr,
html[data-theme="dark"] .page__content hr {
  border-color: var(--w-border);
}

html[data-theme="dark"] table,
html[data-theme="dark"] td,
html[data-theme="dark"] th {
  border-color: var(--w-border);
}

html[data-theme="dark"] th {
  background: var(--w-surface-2);
}

html[data-theme="dark"] .container,
html[data-theme="dark"] .container .header {
  border-color: var(--w-border);
  background-color: var(--w-surface-2);
}

/* MathJax inherits currentColor for CHTML, but be explicit anyway */
html[data-theme="dark"] .MathJax,
html[data-theme="dark"] .MathJax_CHTML {
  color: var(--w-text) !important;
}

/* --------------------------------------------------------------------------
   2. Shared button chrome
   -------------------------------------------------------------------------- */

.w-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--w-border);
  background: var(--w-surface);
  color: var(--w-text-dim);
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  font-size: 15px;
  line-height: 1;
  transition: color .18s, border-color .18s, background-color .18s, transform .18s, opacity .2s, visibility .2s;
  -webkit-appearance: none;
          appearance: none;
}

.w-btn:hover,
.w-btn:focus-visible {
  color: var(--w-accent);
  border-color: var(--w-accent);
  outline: none;
}

.w-btn:active {
  transform: scale(.92);
}

/* --------------------------------------------------------------------------
   3. Reading progress bar
   -------------------------------------------------------------------------- */

#w-progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0;
  background: var(--w-accent);
  z-index: 60;
  transition: width .08s linear;
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   4. Theme toggle (lives in the masthead)
   -------------------------------------------------------------------------- */

.w-theme-toggle {
  width: 32px;
  height: 32px;
  float: right;
  margin: 2px 0 0 .5em;
}

.w-theme-toggle .fa-moon { display: none; }
html[data-theme="dark"] .w-theme-toggle .fa-moon { display: inline; }
html[data-theme="dark"] .w-theme-toggle .fa-sun  { display: none; }

/* --------------------------------------------------------------------------
   5. Floating control dock (TOC + back to top)
   -------------------------------------------------------------------------- */

.w-dock {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 50;
}

.w-dock .w-btn {
  width: 40px;
  height: 40px;
  box-shadow: var(--w-shadow);
  font-size: 16px;
}

.w-btn.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   6. Table of contents panel
   -------------------------------------------------------------------------- */

.w-toc {
  position: fixed;
  right: 70px;
  bottom: 18px;
  width: 230px;
  max-height: 65vh;
  overflow-y: auto;
  padding: .85em 1em;
  background: var(--w-surface);
  border: 1px solid var(--w-border);
  border-radius: var(--w-radius);
  box-shadow: var(--w-shadow);
  z-index: 50;
  font-size: 13px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(6px);
  transition: opacity .18s, transform .18s, visibility .18s;
}

.w-toc.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.w-toc__title {
  font-weight: 700;
  color: var(--w-text-dim);
  text-transform: uppercase;
  letter-spacing: .06em;
  font-size: 10px;
  margin-bottom: .6em;
}

.w-toc ul {
  list-style: none;
  margin: 0;
  padding: 0;
  padding-inline-start: 0;
}

.w-toc li { margin: 0; }

.w-toc a {
  display: block;
  padding: .32em .5em;
  border-radius: 5px;
  color: var(--w-text);
  text-decoration: none;
  border-left: 2px solid transparent;
  line-height: 1.35;
}

.w-toc a:hover {
  background: var(--w-surface-2);
  color: var(--w-accent);
}

.w-toc a.is-active {
  color: var(--w-accent);
  border-left-color: var(--w-accent);
  background: var(--w-surface-2);
  font-weight: 600;
}

@media (max-width: 600px) {
  .w-toc {
    right: 14px;
    left: 14px;
    width: auto;
    bottom: 70px;
  }
}

/* --------------------------------------------------------------------------
   7. Visitor stats (sidebar)
   -------------------------------------------------------------------------- */

.w-stats {
  margin-top: 1em;
  padding-top: .8em;
  border-top: 1px solid var(--w-border);
  font-size: 12px;
  color: var(--w-text-dim);
  line-height: 1.9;
  white-space: normal;
}

.w-stats[hidden] { display: none; }

.w-stats__item { white-space: nowrap; }

.w-stats__item i {
  opacity: .75;
  margin-right: .15em;
}

.w-stats__num {
  font-weight: 700;
  color: var(--w-text);
  font-variant-numeric: tabular-nums;
}

.w-stats__sep {
  margin: 0 .45em;
  opacity: .45;
}

.w-stats__map {
  margin-top: .6em;
  display: block;
  max-width: 100%;
}

/* --------------------------------------------------------------------------
   8. Copy buttons
   -------------------------------------------------------------------------- */

.w-copy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.55em;
  height: 1.55em;
  margin-left: .35em;
  border: 0;
  background: transparent;
  color: var(--w-text-dim);
  cursor: pointer;
  border-radius: 4px;
  font-size: .85em;
  vertical-align: middle;
  padding: 0;
  transition: color .15s, background-color .15s;
}

.w-copy:hover,
.w-copy:focus-visible {
  color: var(--w-accent);
  background: var(--w-surface-2);
  outline: none;
}

.w-copy.is-done { color: #2e9e4f; }

/* "Copy citation" button under each paper */
.w-cite {
  display: inline-flex;
  align-items: center;
  gap: .4em;
  margin-top: .9em;
  padding: .28em .75em;
  font-size: 12px;
  font-family: "Trebuchet MS", Helvetica, sans-serif;
  color: var(--w-text-dim);
  background: transparent;
  border: 1px solid var(--w-border);
  border-radius: 999px;
  cursor: pointer;
  transition: color .15s, border-color .15s, background-color .15s;
}

.w-cite:hover,
.w-cite:focus-visible {
  color: var(--w-accent);
  border-color: var(--w-accent);
  outline: none;
}

.w-cite.is-done {
  color: #2e9e4f;
  border-color: #2e9e4f;
}

/* --------------------------------------------------------------------------
   9. Toast
   -------------------------------------------------------------------------- */

.w-toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translate(-50%, 12px);
  background: rgba(28, 31, 36, .94);
  color: #fff;
  padding: .6em 1.1em;
  border-radius: 999px;
  font-size: 13px;
  z-index: 80;
  opacity: 0;
  visibility: hidden;
  transition: opacity .2s, transform .2s, visibility .2s;
  pointer-events: none;
  max-width: 80vw;
  text-align: center;
}

.w-toast.is-open {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, 0);
}

/* --------------------------------------------------------------------------
   10. Paper figures — sizing, zoom cursor, hover lift
   -------------------------------------------------------------------------- */

/* A figure may be either an <img> or a <video>, so both get the framing the
   theme defines for images (main.scss styles the img only).

   The tags carry their intrinsic width/height so the browser can reserve the
   right space before the file arrives (no layout jump). Those attributes only
   work as an aspect ratio if height is left automatic. */
.paper-box-image img,
.paper-box-image video {
  width: 100%;
  height: auto;
  transition: transform .28s ease, box-shadow .28s ease;
}

.paper-box-image video {
  max-width: 400px;
  box-shadow: 3px 3px 6px #888;
  display: block;
  background: #000;
}

.paper-box-image img {
  cursor: zoom-in;
}

/* A clip is clickable too, but nothing about a bare <video> says so, hence
   the cursor and the corner hint. */
.paper-box-image video.is-zoomable {
  cursor: zoom-in;
}

/* Constrained to the clip's own width so the corner hint lands on the video
   rather than out in the empty part of the flex track. */
.w-video-frame {
  position: relative;
  max-width: 400px;
}

.w-video-zoom {
  position: absolute;
  right: 8px;
  bottom: 8px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: .35em;
  padding: .25em .55em;
  border-radius: 4px;
  background: rgba(0, 0, 0, .58);
  color: #fff;
  font-size: 10px;
  letter-spacing: .04em;
  pointer-events: none;
  opacity: 0;
  transition: opacity .25s ease;
}

.w-video-frame:hover .w-video-zoom {
  opacity: 1;
}

/* ------------------------------------------------- enlarged video overlay */

.w-vbox {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 1rem;
  background: rgba(11, 12, 14, .93);
  opacity: 0;
  visibility: hidden;
  transition: opacity .22s ease, visibility .22s ease;
}

.w-vbox.is-open {
  opacity: 1;
  visibility: visible;
}

.w-vbox video {
  max-width: 92vw;
  max-height: 84vh;
  width: auto;
  height: auto;
  background: #000;
  box-shadow: 0 12px 44px rgba(0, 0, 0, .65);
}

.w-vbox__close {
  position: absolute;
  top: 12px;
  right: 16px;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .1);
  color: #fff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: background-color .18s ease;
}

.w-vbox__close:hover,
.w-vbox__close:focus-visible {
  background: rgba(255, 255, 255, .22);
  outline: none;
}

.paper-box:hover .paper-box-image img,
.paper-box:hover .paper-box-image video {
  transform: translateY(-4px) scale(1.015);
  box-shadow: 5px 8px 18px rgba(0, 0, 0, .28);
}

html[data-theme="dark"] .paper-box:hover .paper-box-image img,
html[data-theme="dark"] .paper-box:hover .paper-box-image video {
  box-shadow: 5px 8px 20px rgba(0, 0, 0, .75);
}

html[data-theme="dark"] .paper-box-image video {
  box-shadow: 3px 3px 8px rgba(0, 0, 0, .6);
}

/* Nudge the title as well, so the whole card feels like one hover target. */
.paper-box-text > p:first-of-type a {
  transition: color .2s ease;
}

/* ---------------------------------------------------- hover-to-play video */

/* Only applied to figures that actually declare data-video, so the default
   layout is untouched when there is no clip. */
.w-video-host {
  position: relative;
  max-width: 400px;
}

.w-hover-video {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity .3s ease;
  pointer-events: none;
  box-shadow: 3px 3px 6px #888;
}

.w-video-host.is-playing .w-hover-video {
  opacity: 1;
}


/* Small "has a clip" hint in the corner of the figure. */
.w-video-badge {
  position: absolute;
  right: 8px;
  bottom: 8px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: .3em;
  padding: .2em .5em;
  border-radius: 4px;
  background: rgba(0, 0, 0, .6);
  color: #fff;
  font-size: 10px;
  letter-spacing: .04em;
  pointer-events: none;
  transition: opacity .3s ease;
}

.w-video-host.is-playing .w-video-badge {
  opacity: 0;
}

/* --------------------------------------------------------------------------
   11. Scroll reveal
   -------------------------------------------------------------------------- */

/* The hiding is gated on [data-reveal] which the <head> script sets, so the
   content is never hidden unless the script that reveals it also ran. */
html[data-reveal="on"] .paper-box,
html[data-reveal="on"] .w-news__item {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity .55s ease, transform .55s ease;
  will-change: opacity, transform;
}

html[data-reveal="on"] .paper-box.is-visible,
html[data-reveal="on"] .w-news__item.is-visible {
  opacity: 1;
  transform: none;
  will-change: auto;
}

/* News entries sit close together and would otherwise all pop at once, so
   cascade the first few. */
html[data-reveal="on"] .w-news__item:nth-child(2) { transition-delay: .06s; }
html[data-reveal="on"] .w-news__item:nth-child(3) { transition-delay: .12s; }
html[data-reveal="on"] .w-news__item:nth-child(4) { transition-delay: .18s; }
html[data-reveal="on"] .w-news__item:nth-child(5) { transition-delay: .24s; }
html[data-reveal="on"] .w-news__item:nth-child(n+6) { transition-delay: .3s; }

/* --------------------------------------------------------------------------
   12. News timeline
   -------------------------------------------------------------------------- */

.w-news__list {
  list-style: none;
  margin: 0 0 1em;
  padding: 0 0 0 1.1em;
  padding-inline-start: 1.1em;
  position: relative;
}

/* The vertical rail. */
.w-news__list:before {
  content: '';
  position: absolute;
  left: 3px;
  top: .55em;
  bottom: .55em;
  width: 2px;
  background: var(--w-border);
}

.w-news__item {
  position: relative;
  margin: 0 0 .75em;
  padding-left: .85em;
  line-height: 1.6;
}

/* Older entries, collapsed until the toggle is pressed. Kept in the same
   <ul> as the rest so the timeline rail runs unbroken through them. */
.w-news:not(.is-expanded) .w-news__item.is-extra {
  display: none;
}

.w-news__dot {
  position: absolute;
  left: -1.1em;
  top: .5em;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--w-surface);
  border: 2px solid var(--w-text-dim);
  transition: background-color .2s, border-color .2s, transform .2s;
}

.w-news__item:hover .w-news__dot {
  border-color: var(--w-accent);
  transform: scale(1.25);
}

/* Highlighted entries (`highlight: true` in _data/news.yml). */
.w-news__item--hot .w-news__dot {
  background: var(--w-accent);
  border-color: var(--w-accent);
}

.w-news__date {
  font-style: italic;
  color: var(--w-text-dim);
  margin-right: .35em;
  white-space: nowrap;
}

.w-news__more {
  margin: 0;
  padding-left: 2.1em;
  font-size: .9em;
}

.w-news__toggle {
  background: none;
  border: 0;
  padding: 0;
  color: var(--w-text-dim);
  cursor: pointer;
  font-size: inherit;
  font-family: inherit;
  border-bottom: 1px dotted currentColor;
}

.w-news__toggle:hover,
.w-news__toggle:focus-visible {
  color: var(--w-accent);
  outline: none;
}

/* --------------------------------------------------------------------------
   13. Page footer
   -------------------------------------------------------------------------- */

.w-footer {
  clear: both;
  margin: 3em auto 1.5em;
  padding: 1.2em 1em 0;
  max-width: 1200px;
  border-top: 1px solid var(--w-border);
  text-align: center;
  font-size: 12px;
  color: var(--w-text-dim);
  line-height: 1.9;
}

.w-footer a { color: inherit; }
.w-footer a:hover { color: var(--w-accent); }

/* --------------------------------------------------------------------------
   14. Respect reduced-motion / print
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .w-btn, .w-toc, .w-toast, #w-progress, .w-copy, .w-cite,
  .paper-box-image img, .w-hover-video, .w-news__dot {
    transition: none;
  }

  /* Show everything straight away rather than sliding it in, and drop the
     hover lift — both are motion the visitor asked not to see. */
  html[data-reveal="on"] .paper-box,
  html[data-reveal="on"] .w-news__item {
    opacity: 1;
    transform: none;
  }

  .paper-box:hover .paper-box-image img {
    transform: none;
  }
}

@media print {
  #w-progress, .w-dock, .w-toc, .w-toast,
  .w-theme-toggle, .w-copy, .w-cite,
  .w-hover-video, .w-video-badge,
  .w-video-zoom, .w-vbox {
    display: none !important;
  }

  /* Never let a figure stay invisible on paper because it was never scrolled to. */
  html[data-reveal="on"] .paper-box,
  html[data-reveal="on"] .w-news__item {
    opacity: 1 !important;
    transform: none !important;
  }
}
