/*
 * Ethereal 侧栏增强 — scoped styles.
 *
 * Layout invariant (this is what the "card turned transparent" bug was about):
 * Ethereal puts cards directly inside a flex column (#sidebar-sticky). A
 * `widget-layout` custom element defaults to `display: inline`, and only flex
 * blockification turns it into a block box with a stretch width. Every
 * container this plugin creates around a card must therefore stay a flex
 * column, otherwise the card collapses to `inline` / `width: auto` and its
 * card background box disappears.
 *
 * Also: never put opacity/transform/filter on an ancestor of a card. Ethereal
 * cards may use backdrop-filter, and such an ancestor becomes the backdrop
 * root, which drops the frost. Switch animation is applied to the card itself.
 */

.ethereal-sidebar-merged {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  min-width: 0;
  flex: 0 0 auto;
}

.ethereal-sidebar-single {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: 0;
}

.ethereal-sidebar-group {
  position: relative;
  display: block;
  width: 100%;
  min-width: 0;
}

/* The stage owns the height. When two cards differ, JS sets an explicit height
 * and CSS animates it, which is what makes the widgets below glide instead of
 * jumping. The duration comes from the "高度变化时长" setting. */
.ethereal-sidebar-stage {
  position: relative;
  display: block;
  width: 100%;
  min-width: 0;
  /* Even in and out: the box leaves the old height, travels, then settles. A
   * hard ease-out made the first 100ms do almost all the work. */
  transition: height var(--ethereal-sidebar-height-duration, 340ms)
    cubic-bezier(0.4, 0.1, 0.2, 1);
}

/* Inactive slides stay laid out. Themes and custom widgets measure themselves
 * (scroll heights, "fit N items" logic) and a `display: none` parent reports 0,
 * which is what collapsed a custom "recent comments" card to a few pixels. Only
 * the active slide takes part in the flow; the others are invisible but still
 * have real boxes.
 *
 * The switch itself is a pure cross-fade: the incoming card fades in over the
 * outgoing one, no travel. Height differences are handled by the stage, which
 * owns an explicit height and is clipped while it animates so the card's
 * background appears to unfold or fold away. */
.ethereal-sidebar-slide {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: 0;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  z-index: 0;
  transition:
    opacity var(--etsb-fade, 500ms) ease,
    visibility 0s linear var(--etsb-fade, 500ms);
}

.ethereal-sidebar-group .ethereal-sidebar-slide.is-active {
  position: relative;
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
  z-index: 1;
  transition:
    opacity var(--etsb-fade, 500ms) ease,
    visibility 0s linear 0s;
}

/* The outgoing card stays painted above the slot until it has faded out. */
.ethereal-sidebar-slide.is-leaving-prev,
.ethereal-sidebar-slide.is-leaving-next,
.ethereal-sidebar-slide.is-leaving {
  display: flex;
  flex-direction: column;
  visibility: visible;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2;
  pointer-events: none;
  overflow: visible;
}

.ethereal-sidebar-slide.is-leaving-next,
.ethereal-sidebar-slide.is-leaving-prev {
  opacity: 0 !important;
}

/* While a switch runs, the stage clips its own box: when the next card is
 * taller the card's background unfolds as the stage grows, and when it is
 * shorter the background folds away instead of leaving an empty gap. */
.ethereal-sidebar-group.is-resizing .ethereal-sidebar-stage {
  overflow: hidden;
  border-radius: var(--radius-large, 1rem);
}

.ethereal-sidebar-slide > *,
.ethereal-sidebar-single > * {
  min-width: 0;
}

/* One dot per card, under the card. */
.ethereal-sidebar-dots {
  position: absolute;
  left: 50%;
  bottom: -0.85rem;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.35rem;
  border-radius: 999px;
  transform: translateX(-50%);
}

.ethereal-sidebar-dot {
  width: 0.375rem;
  height: 0.375rem;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: color-mix(in oklab, var(--deep-text, #27313f) 22%, transparent);
  cursor: pointer;
  transition: width 160ms ease, background-color 160ms ease;
}

.ethereal-sidebar-dot:hover {
  background: color-mix(in oklab, var(--primary, #39c5bb) 55%, transparent);
}

.ethereal-sidebar-dot.is-active {
  width: 1rem;
  background: var(--primary, #39c5bb);
}

.ethereal-sidebar-dot:focus-visible {
  outline: 2px solid color-mix(in oklab, var(--primary, #39c5bb) 80%, white);
  outline-offset: 2px;
}


}

/* Debug panel, only rendered when the corresponding setting is enabled. */
.ethereal-sidebar-debug {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 9999;
  width: min(22rem, calc(100vw - 2rem));
  max-height: min(26rem, calc(100vh - 2rem));
  overflow: auto;
  padding: 0.8rem 0.9rem;
  border: 1px solid rgb(255 255 255 / 14%);
  border-radius: 0.8rem;
  background: rgb(22 24 28 / 86%);
  color: rgb(255 255 255 / 88%);
  box-shadow: 0 12px 36px rgb(0 0 0 / 28%);
  backdrop-filter: blur(16px) saturate(150%);
  -webkit-backdrop-filter: blur(16px) saturate(150%);
  font-size: 0.75rem;
  line-height: 1.55;
}

.ethereal-sidebar-debug-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
}

.ethereal-sidebar-debug-head strong {
  font-size: 0.78rem;
  font-weight: 700;
}

.ethereal-sidebar-debug-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.35rem;
  height: 1.35rem;
  border: 0;
  border-radius: 999px;
  background: rgb(255 255 255 / 10%);
  color: inherit;
  cursor: pointer;
  font-size: 0.95rem;
  line-height: 1;
}

.ethereal-sidebar-debug-close:hover {
  background: rgb(255 255 255 / 18%);
}

.ethereal-sidebar-debug-line {
  margin-top: 0.3rem;
  font-weight: 600;
  color: rgb(255 255 255 / 95%);
}

.ethereal-sidebar-debug-item {
  margin-left: 0.55rem;
  color: rgb(255 255 255 / 68%);
  overflow-wrap: anywhere;
}

@media (prefers-reduced-motion: reduce) {
  /* No travel, no fade, no height glide: switch instantly. */
  .ethereal-sidebar-stage,
  .ethereal-sidebar-slide,
  .ethereal-sidebar-slide.is-active {
    transition: none !important;
  }
}





/* The theme slides #main-grid (translate) from the previous banner offset to
 * the new one after a swap. Pinned during the switch so the columns land in
 * place instead of drifting on their own. */

/* Cross-page motion follows the theme: the content keeps its short fade, and
 * the side columns are pinned so they never replay an entrance of their own
 * while the swap animates (the right column already had this rule; the left
 * one and the mobile drawer are covered here). */
html.is-changing #sidebar,
html.is-animating #sidebar,
html.swup-visited #sidebar,
html.is-changing #mobile-sidebar,
html.is-animating #mobile-sidebar,
html.swup-visited #mobile-sidebar {
  transition: none !important;
  animation: none !important;
  opacity: 1 !important;
  transform: none !important;
  translate: none !important;
}

html.swup-visited #sidebar .onload-animation,
html.swup-visited #mobile-sidebar .onload-animation {
  animation: none !important;
  opacity: 1 !important;
  transform: none !important;
  translate: none !important;
}

/* ===== Article cards =====
 * One row of meta, then title, excerpt and a bottom bar. Every measurement is a
 * CSS variable published from the two settings groups; the mobile set is
 * swapped in by the media query at the end so a single stylesheet serves both. */

.post-card {
  height: auto !important;
  min-height: 0;
}

.post-card .post-card-content {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  padding-top: var(--etsb-pt, 20px) !important;
  padding-bottom: var(--etsb-pb, 14px) !important;
}

/* ---- first row: pinned badge, date, categories ---- */
.etsb-card-eyebrow {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
  min-width: 0;
  overflow: hidden;
  font-size: var(--etsb-meta, 12px);
  line-height: 1;
  color: color-mix(in srgb, var(--btn-content) 88%, transparent);
}

.etsb-card-eyebrow > * {
  flex: 0 0 auto;
}

.etsb-card-eyebrow .etsb-eyebrow-cats {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
}

.etsb-eyebrow-date {
  display: inline-flex;
  align-items: center;
  font-size: var(--etsb-meta, 12px) !important;
  font-weight: 700;
  white-space: nowrap;
}

.etsb-card-eyebrow .meta-icon,
.etsb-eyebrow-date .meta-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: calc(var(--etsb-icon, 20px) * 1.3);
  height: calc(var(--etsb-icon, 20px) * 1.3);
  margin-right: 0.3rem;
  border-radius: 0.375rem;
  background: color-mix(in srgb, var(--primary) 10%, transparent);
  color: var(--primary);
}

.etsb-card-eyebrow .meta-icon > span,
.etsb-eyebrow-date .meta-icon > span {
  font-size: var(--etsb-icon, 20px) !important;
  line-height: 1;
}

.etsb-eyebrow-pinned {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.4rem;
  border-radius: 0.375rem;
  background: color-mix(in srgb, var(--primary) 10%, transparent);
  color: var(--primary);
  font-size: calc(var(--etsb-icon, 20px) * 0.7) !important;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}

.etsb-eyebrow-pinned > span {
  font-size: calc(var(--etsb-icon, 20px) * 0.7) !important;
  line-height: 1;
}

.etsb-eyebrow-pinned > span[class*="material-symbols"] {
  font-size: var(--etsb-icon, 20px) !important;
}

.etsb-eyebrow-cats {
  display: flex;
  align-items: center;
  white-space: nowrap;
}

.etsb-eyebrow-cats a {
  font-size: var(--etsb-meta, 12px) !important;
  font-weight: 500;
  white-space: nowrap;
}

.etsb-eyebrow-cats .meta-icon {
  flex: 0 0 auto;
}

/* ---- title ---- */
.post-card .post-card-title {
  flex: 0 0 auto;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: var(--etsb-title-lines, 2);
  line-clamp: var(--etsb-title-lines, 2);
  font-size: var(--etsb-title, 20px) !important;
  line-height: 1.35 !important;
  font-weight: 700;
  margin-bottom: 0 !important;
  overflow: hidden;
}

/* The theme paints a short primary-colored bar to the left of the title and an
 * arrow that slides in on hover; the card design has neither. */
.post-card .post-card-title::before,
.post-card .post-card-arrow {
  display: none !important;
  content: none !important;
}

/* ---- excerpt ---- */
html body #post-list-container .post-card .post-card-excerpt {
  flex: 1 1 auto;
  min-height: 0;
  font-size: var(--etsb-excerpt, 14px) !important;
  line-height: 1.5 !important;
  margin-top: var(--etsb-excerpt-top, 6px) !important;
  margin-bottom: var(--etsb-gap-top, 10px) !important;
  max-height: calc(var(--etsb-excerpt, 14px) * 1.5 * var(--etsb-excerpt-lines, 2));
  overflow: hidden !important;
  display: -webkit-box !important;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: var(--etsb-excerpt-lines, 2);
}

/* ---- bottom bar: tags left, counts right ---- */
.etsb-card-bottom {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  margin-top: auto;
  padding-top: var(--etsb-gap-bottom, 8px);
  border-top: 1px solid color-mix(in srgb, var(--btn-content) 10%, transparent);
  min-width: 0;
}

.etsb-card-tags {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  min-width: 0;
  overflow: hidden;
  /* Keeps the bar the same height for posts without tags: an empty row would
   * otherwise collapse and make that card shorter than its neighbours. */
  min-height: calc(var(--etsb-tag, 12px) * 1.5 + 0.2rem);
}

.etsb-tag {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  max-width: 7rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  color: var(--primary);
  font-size: var(--etsb-tag, 12px);
  font-weight: 500;
  line-height: 1.5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background-color 150ms ease, color 150ms ease;
}

a.etsb-tag:hover {
  background: color-mix(in srgb, var(--primary) 24%, transparent);
}

.etsb-tag-more {
  background: color-mix(in srgb, var(--btn-content) 10%, transparent);
  color: color-mix(in srgb, var(--btn-content) 80%, transparent);
}

.etsb-card-bottom .etsb-card-stats {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: var(--etsb-stat-gap, 10px);
  margin-left: auto;
  margin-right: var(--etsb-stat-offset, 0px);
  font-size: var(--etsb-stat, 12px);
  color: color-mix(in srgb, var(--btn-content) 70%, transparent);
}

.etsb-card-bottom .etsb-card-stats > div {
  gap: 0.25rem;
}

/* The counts are icon + number; the rounded grey plate behind each icon made
 * them read as a second row of chips, so the plate is dropped. */
.etsb-card-bottom .etsb-card-stats span[class*="h-6"],
.etsb-card-bottom .etsb-card-stats span[class*="bg-black"] {
  background: transparent !important;
  height: 1.05em !important;
  width: 1.05em !important;
  border-radius: 0 !important;
  color: inherit;
}

.etsb-card-bottom .etsb-card-stats span[class*="material-symbols"],
.etsb-card-bottom .etsb-card-stats span[class*="mdi--"] {
  font-size: 1.15em !important;
}

.etsb-card-bottom .etsb-card-stats > div {
  font-size: inherit;
}

/* ---- device metrics ----
 * The card has one fixed design per device class. Values are literal so the
 * settings page stays focused on the sidebar; the only adaptivity left is the
 * one that keeps content inside the card at every width. */
:root {
  --etsb-h: 220px;
  --etsb-pt: 20px;
  --etsb-pb: 20px;
  --etsb-icon: 22px;
  --etsb-meta: 14px;
  --etsb-title: 24px;
  --etsb-excerpt: 16px;
  --etsb-tag: 12px;
  --etsb-stat: 14px;
  --etsb-stat-gap: 12px;
  --etsb-stat-offset: 14px;
  --etsb-gap-top: 10px;
  --etsb-gap-bottom: 14px;
  --etsb-excerpt-top: 10px;
  --etsb-title-lines: 1;
  --etsb-excerpt-lines: 2;
  --etsb-cover-ratio: 16 / 9;
}

@media (max-width: 767.98px) {
  :root {
    --etsb-h: 375px;
    --etsb-pt: 20px;
    --etsb-pb: 20px;
    --etsb-icon: 18px;
    --etsb-meta: 12px;
    --etsb-title: 18px;
    --etsb-excerpt: 14px;
    --etsb-tag: 11px;
    --etsb-stat: 12px;
    --etsb-stat-gap: 8px;
    --etsb-stat-offset: 0px;
    --etsb-gap-top: 8px;
    --etsb-gap-bottom: 10px;
    --etsb-excerpt-top: 6px;
    --etsb-title-lines: 2;
    --etsb-excerpt-lines: 2;
    --etsb-cover-ratio: 16 / 9;
  }
}

@media (max-width: 767.98px) {
  .post-card .post-card-content {
    flex: 0 0 auto;
  }
}

@media (max-width: 767.98px) {
  /* The divider is the bar's own top border, so the gap below it is the bar's
   * padding and the gap above the card edge is its bottom margin. Both use the
   * same value, which centres the row in that band. */
  .etsb-card-bottom {
    margin-top: var(--etsb-gap-top, 8px);
    padding-top: calc(var(--etsb-gap-bottom, 10px) - 1px);
    margin-bottom: var(--etsb-gap-bottom, 10px);
  }

  .post-card .post-card-excerpt {
    margin-bottom: 0 !important;
  }

  .post-card .post-card-content {
    padding-bottom: 0 !important;
  }
}

/* ---- keep every row inside the card ----
 * Long titles and excerpts end with an ellipsis, long category names shrink,
 * the tag row drops chips by measurement, and the counts never shrink. */
.post-card .post-card-content {
  overflow: hidden;
}

.etsb-eyebrow-cats {
  overflow: hidden;
}

.etsb-eyebrow-cats a {
  overflow: hidden;
  text-overflow: ellipsis;
}

.etsb-card-bottom .post-card-stats,
.etsb-card-bottom .etsb-card-stats {
  flex: 0 0 auto;
}

/* ---- cover ratio ----
 * The shape comes from the ratio, the size from the card: on the list layout the
 * cover spans the card height and the ratio decides how wide it is; when the card
 * stacks (narrow screens) the cover spans the width and the ratio decides height. */
.post-card .post-card-cover {
  aspect-ratio: var(--etsb-cover-ratio, 16 / 9) !important;
}

.post-card .post-card-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

@media (min-width: 768px) {
  /* Pinned by insets instead of a translate: the theme also writes top/bottom
   * on this element, and a transform-based centring ended up shifted by half a
   * cover and clipped by the card. Height follows the card, width follows the
   * ratio. */
  .post-card .post-card-cover {
    top: 12px !important;
    bottom: auto !important;
    left: auto !important;
    right: 12px !important;
    height: calc(100% - 24px) !important;
    width: auto !important;
    max-width: 62% !important;
    transform: none !important;
  }
}

@media (max-width: 767.98px) {
  .post-card .post-card-cover,
  .post-card .post-card-cover-placeholder {
    max-height: none !important;
  }
}
