/* Chfy essay page. The page marker is added by preview.js so this
   works even in browsers/themes where :has() is unreliable. */
html.chfy-essay-doc #page.chfy-essay-paper,
#page.chfy-essay-paper,
#page:has(.chfy-essay-page) {
  overflow: hidden !important;
  padding: 38px !important;
  border: var(--border-style, 1px solid rgba(138, 154, 185, 0.18)) !important;
  border-radius: 20px !important;
  background: var(--trans-light, rgba(250, 250, 250, 0.9)) !important;
  box-shadow: 0 22px 70px rgba(33, 50, 88, 0.12) !important;
  backdrop-filter: blur(14px);
}

html.chfy-essay-doc #page.chfy-essay-paper #article-container,
#page.chfy-essay-paper #article-container,
#page:has(.chfy-essay-page) #article-container {
  padding: 0 !important;
}

html.chfy-essay-doc #page.chfy-essay-paper > hr,
html.chfy-essay-doc #page.chfy-essay-paper #article-container + hr,
#page.chfy-essay-paper > hr,
#page.chfy-essay-paper #article-container + hr,
#page:has(.chfy-essay-page) > hr,
#page:has(.chfy-essay-page) #article-container + hr {
  height: 1px !important;
  margin: 30px 0 26px !important;
  border: 0 !important;
  background: linear-gradient(90deg, transparent, rgba(138, 154, 185, 0.38), transparent) !important;
}

html.chfy-essay-doc #page.chfy-essay-paper #post-comment,
#page.chfy-essay-paper #post-comment,
#page:has(.chfy-essay-page) #post-comment {
  margin-top: 0 !important;
  padding-bottom: 0 !important;
}

#article-container .chfy-essay-page {
  --chfy-essay-accent: var(--theme-color, #39c5bb);
  --chfy-essay-card: var(--trans-light, rgba(255, 255, 255, 0.82));
  --chfy-essay-card-border: rgba(108, 127, 164, 0.16);
  --chfy-essay-text: var(--font-color, #2f3640);
  --chfy-essay-muted: #6f7785;
  --chfy-essay-line: rgba(126, 165, 226, 0.24);
  color: var(--chfy-essay-text);
}

.chfy-essay-hero {
  position: relative;
  overflow: hidden;
  min-height: 122px;
  margin-bottom: 26px;
  border: 1px solid var(--chfy-essay-card-border);
  border-radius: 12px;
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--trans-light, rgba(255, 255, 255, 0.94)) 94%, transparent), color-mix(in srgb, var(--trans-light, rgba(255, 255, 255, 0.7)) 70%, transparent)),
    var(--chfy-essay-cover, linear-gradient(135deg, #e9f6ff, #f8fbff));
  background-position: center;
  background-size: cover;
  box-shadow: 0 14px 34px rgba(35, 62, 112, 0.08);
}

.chfy-essay-hero-inner {
  display: flex;
  min-height: 122px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 24px;
}

.chfy-essay-kicker {
  margin: 0 0 8px;
  color: var(--chfy-essay-muted);
  font-size: 0.92rem;
}

.chfy-essay-hero h1 {
  margin: 0;
  font-size: 1.75rem;
  line-height: 1.2;
  letter-spacing: 0;
}

.chfy-essay-subtitle {
  max-width: 640px;
  margin: 10px 0 0;
  color: var(--chfy-essay-muted);
  font-size: 1rem;
}

.chfy-essay-hero-action {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 9px 16px;
  background: var(--chfy-essay-accent);
  color: #fff !important;
  line-height: 1;
  box-shadow: 0 10px 24px color-mix(in srgb, var(--chfy-essay-accent) 26%, transparent);
}

.chfy-essay-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  align-items: start;
}

.chfy-essay-card {
  display: flex;
  min-width: 0;
  min-height: 100%;
  flex-direction: column;
  margin: 0;
  padding: 18px 16px 14px;
  border: 1px solid var(--chfy-essay-card-border);
  border-radius: 10px;
  background: var(--chfy-essay-card) !important;
  box-shadow: 0 14px 36px rgba(36, 57, 96, 0.06);
  backdrop-filter: blur(10px);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.chfy-essay-card:hover {
  border-color: color-mix(in srgb, var(--chfy-essay-accent) 32%, var(--chfy-essay-card-border));
  box-shadow: 0 18px 48px rgba(36, 57, 96, 0.1);
  transform: translateY(-3px);
}

.chfy-essay-card.is-hidden {
  display: none;
}

.chfy-essay-content {
  min-height: 1.75em;
  font-size: 1rem;
  font-weight: 650;
  line-height: 1.75;
}

.chfy-essay-link {
  display: inline-flex;
  margin-top: 10px;
  color: var(--chfy-essay-accent) !important;
  font-size: 0.93rem;
}

.chfy-essay-media {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.chfy-essay-media.is-single {
  grid-template-columns: minmax(130px, 58%);
}

.chfy-essay-media.is-duo {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.chfy-essay-media.is-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.chfy-essay-image {
  position: relative;
  display: block;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 1 / 1;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: #eef3f8;
  line-height: 0;
  cursor: zoom-in;
}

.chfy-essay-media.is-single .chfy-essay-image {
  aspect-ratio: 16 / 11;
}

.chfy-essay-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.2s ease;
}

.chfy-essay-image:hover img {
  transform: scale(1.04);
}

.chfy-essay-videos {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.chfy-essay-video {
  overflow: hidden;
  border-radius: 7px;
  background: #101820;
  aspect-ratio: 16 / 9;
}

.chfy-essay-video iframe {
  width: 100%;
  height: 100%;
  border: 0;
}

.chfy-essay-divider {
  margin: auto 0 12px;
  padding-top: 18px;
  border-top: 1px dashed var(--chfy-essay-line);
}

.chfy-essay-card-meta {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-height: 27px;
  color: var(--chfy-essay-muted);
  font-size: 0.9rem;
}

.chfy-essay-meta-left {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
}

.chfy-essay-date,
.chfy-essay-meta-item {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 9px;
  background: rgba(122, 132, 148, 0.12);
  line-height: 1;
}

.chfy-essay-date::before {
  width: 13px;
  height: 13px;
  margin-right: 5px;
  border-radius: 50%;
  background: currentColor;
  content: "";
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20Zm1 5v4.58l3.2 1.85-1 1.73L11 12.75V7h2Z'/%3E%3C/svg%3E") center / contain no-repeat;
}

.chfy-essay-like {
  display: inline-flex;
  width: 28px;
  min-width: 28px;
  height: 28px;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: rgba(122, 132, 148, 0.1);
  color: #98a1af;
  cursor: pointer;
  line-height: 1;
  transition: background 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.chfy-essay-like:hover {
  color: #ff6680;
  transform: translateY(-1px);
}

.chfy-essay-like.is-liked {
  background: rgba(255, 102, 128, 0.13);
  color: #ff4f70;
}

.chfy-essay-like-icon {
  width: 15px;
  height: 15px;
  background: currentColor;
  content: "";
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 21.35 10.55 20.03C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35Z'/%3E%3C/svg%3E") center / contain no-repeat;
}

.chfy-essay-comment {
  display: inline-flex;
  min-width: 28px;
  height: 28px;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
  justify-self: end;
  color: #8e6be8;
  line-height: 1;
}

.chfy-essay-comment::before {
  display: block;
  width: 18px;
  height: 18px;
  background: currentColor;
  content: "";
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M20 3H4a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h11.2l4.05 3.24A.75.75 0 0 0 20.5 20.6V5A2 2 0 0 0 20 3Z'/%3E%3C/svg%3E") center / contain no-repeat;
}

.chfy-essay-load-more,
.chfy-essay-empty {
  margin: 30px auto 0;
  color: var(--chfy-essay-muted);
  text-align: center;
}

.chfy-essay-load-more {
  display: block;
  width: min(430px, 100%);
  border: 0;
  border-radius: 999px;
  padding: 8px 18px;
  background: color-mix(in srgb, var(--trans-light, rgba(255, 255, 255, 0.82)) 70%, transparent);
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(138, 154, 185, 0.14);
  transition: color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.chfy-essay-load-more:not(:disabled):hover {
  color: var(--chfy-essay-accent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--chfy-essay-accent) 28%, transparent);
  transform: translateY(-1px);
}

.chfy-essay-load-more.is-complete {
  cursor: default;
  opacity: 0.86;
}

[data-theme="dark"] #article-container .chfy-essay-page,
html[data-theme="dark"].chfy-essay-doc #article-container .chfy-essay-page {
  --chfy-essay-card: var(--trans-dark, rgba(18, 18, 18, 0.72));
  --chfy-essay-card-border: rgba(255, 255, 255, 0.12);
  --chfy-essay-text: #eef3fb;
  --chfy-essay-muted: rgba(222, 229, 241, 0.72);
  --chfy-essay-line: rgba(255, 255, 255, 0.16);
}

html[data-theme="dark"].chfy-essay-doc #page.chfy-essay-paper,
html[data-theme="dark"] #page.chfy-essay-paper,
html[data-theme="dark"] #page:has(.chfy-essay-page),
[data-theme="dark"] #page.chfy-essay-paper,
[data-theme="dark"] #page:has(.chfy-essay-page) {
  border: var(--border-style, 1px solid rgba(255, 255, 255, 0.14)) !important;
  background: var(--trans-dark, rgba(18, 18, 18, 0.72)) !important;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.36) !important;
}

html[data-theme="dark"].chfy-essay-doc .chfy-essay-card,
[data-theme="dark"] .chfy-essay-card {
  border-color: var(--chfy-essay-card-border);
  background: var(--chfy-essay-card) !important;
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.2);
}

html[data-theme="dark"].chfy-essay-doc .chfy-essay-card:hover,
[data-theme="dark"] .chfy-essay-card:hover {
  border-color: color-mix(in srgb, var(--chfy-essay-accent) 38%, rgba(255, 255, 255, 0.16));
  box-shadow: 0 20px 56px rgba(0, 0, 0, 0.26);
}

html[data-theme="dark"].chfy-essay-doc .chfy-essay-hero,
[data-theme="dark"] .chfy-essay-hero {
  background:
    linear-gradient(90deg, rgba(13, 17, 28, 0.86), rgba(13, 17, 28, 0.48)),
    var(--chfy-essay-cover, linear-gradient(135deg, #161b22, #252d39));
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.24);
}

html[data-theme="dark"].chfy-essay-doc .chfy-essay-image,
[data-theme="dark"] .chfy-essay-image {
  background: #222a34;
}

html[data-theme="dark"].chfy-essay-doc .chfy-essay-date,
html[data-theme="dark"].chfy-essay-doc .chfy-essay-meta-item,
[data-theme="dark"] .chfy-essay-date,
[data-theme="dark"] .chfy-essay-meta-item {
  background: rgba(255, 255, 255, 0.09);
}

html[data-theme="dark"].chfy-essay-doc .chfy-essay-comment,
[data-theme="dark"] .chfy-essay-comment {
  color: #bda8ff;
}

html[data-theme="dark"].chfy-essay-doc .chfy-essay-like,
html[data-theme="dark"].chfy-essay-doc .chfy-essay-load-more,
[data-theme="dark"] .chfy-essay-like,
[data-theme="dark"] .chfy-essay-load-more {
  background: rgba(255, 255, 255, 0.09);
}

html[data-theme="dark"].chfy-essay-doc .chfy-essay-like.is-liked,
[data-theme="dark"] .chfy-essay-like.is-liked {
  background: rgba(255, 102, 128, 0.18);
  color: #ff6f89;
}

@media (max-width: 1100px) {
  .chfy-essay-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 768px) {
  html.chfy-essay-doc #page.chfy-essay-paper,
  #page.chfy-essay-paper,
  #page:has(.chfy-essay-page) {
    padding: 18px !important;
    border-radius: 12px !important;
  }

  .chfy-essay-hero-inner {
    min-height: 132px;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    padding: 24px 20px;
  }

  .chfy-essay-hero h1 {
    font-size: 1.6rem;
  }

  .chfy-essay-grid {
    grid-template-columns: 1fr;
  }

  .chfy-essay-media.is-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
