/*
 * Moonlit Reading — local-only legibility redesign
 * Placed AFTER the existing Fuwari + Moonlit Quartz stylesheets.
 *
 * The illustration is atmosphere, never the reading surface.
 * The article is paper, cards are soft vellum, transient panels are quiet glass.
 *
 * This file can be disabled by removing its single <link> in Layout.astro.
 */
:root {
  --reading-ink: #20323e;
  --reading-muted: #465865;
  --reading-soft: #4b5e69;
  --reading-line: rgba(69, 87, 98, .20);
  --reading-paper: rgba(245, 248, 248, .96);
  --reading-card: rgba(240, 245, 246, .91);
  --reading-sidebar: rgba(239, 244, 245, .92);
  --reading-popover: rgba(245, 248, 249, .97);
  --reading-subtle: rgba(55, 90, 103, .085);
  --reading-accent: #286477;
  --primary: #286477;
  --btn-content: #2d5d6c;
  --deep-text: #20323e;
  --card-bg: var(--reading-card);
  --float-panel-bg: var(--reading-popover);
  --line-color: var(--reading-line);
  --btn-regular-bg: rgba(213, 224, 227, .70);
  --btn-regular-bg-hover: rgba(200, 217, 222, .89);
  --btn-card-bg-hover: rgba(219, 230, 232, .83);
  --glass-ink: var(--reading-ink);
  --glass-muted: var(--reading-muted);
  --glass-quiet-ink: #344b59;
  --glass-quiet-well: rgba(210, 223, 227, .48);
  --glass-quiet-border: rgba(82, 112, 124, .19);
  --glass-image-well: rgba(228, 235, 236, .8);
  --glass-surface: linear-gradient(156deg,
    rgba(246, 249, 249, .93) 0%,
    rgba(239, 245, 246, .90) 53%,
    rgba(244, 247, 247, .92) 100%);
  --glass-reflection: linear-gradient(143deg,
    rgba(255, 255, 255, .08) 0%,
    rgba(255, 255, 255, .02) 32%,
    transparent 74%);
  --glass-spectrum: linear-gradient(135deg,
    rgba(255, 255, 255, .76) 0%,
    rgba(211, 227, 230, .43) 48%,
    rgba(111, 134, 147, .28) 100%);
  --glass-blur: blur(18px) saturate(82%);
  --glass-shadow: 0 10px 29px rgba(5, 14, 21, .15),
    0 2px 8px rgba(10, 26, 35, .07),
    inset 0 1px 0 rgba(255, 255, 255, .65);
  --glass-popover: linear-gradient(var(--reading-popover), var(--reading-popover));
  --glass-focus: #236c84;
}

:root.dark {
  color-scheme: dark;
  --reading-ink: #edf2f5;
  --reading-muted: #d1dce4;
  --reading-soft: #b5c5d1;
  --reading-line: rgba(179, 202, 216, .19);
  --reading-paper: rgba(25, 35, 45, .97);
  --reading-card: rgba(32, 44, 55, .93);
  --reading-sidebar: rgba(29, 41, 51, .94);
  --reading-popover: rgba(27, 38, 48, .98);
  --reading-subtle: rgba(183, 206, 216, .10);
  --reading-accent: #9dcedc;
  --primary: #9dcedc;
  --btn-content: #d3e8ee;
  --deep-text: #edf2f5;
  --btn-regular-bg: rgba(74, 94, 108, .55);
  --btn-regular-bg-hover: rgba(86, 112, 128, .71);
  --btn-card-bg-hover: rgba(61, 80, 94, .78);
  --glass-quiet-ink: #d7e2e9;
  --glass-quiet-well: rgba(113, 138, 153, .27);
  --glass-quiet-border: rgba(180, 204, 217, .19);
  --glass-image-well: rgba(32, 42, 49, .88);
  --glass-surface: linear-gradient(156deg,
    rgba(38, 50, 61, .94) 0%,
    rgba(32, 44, 55, .92) 55%,
    rgba(29, 41, 52, .94) 100%);
  --glass-reflection: linear-gradient(145deg,
    rgba(234, 245, 250, .055) 0%,
    rgba(221, 231, 237, .012) 34%,
    transparent 73%);
  --glass-spectrum: linear-gradient(135deg,
    rgba(182, 208, 222, .29) 0%,
    rgba(127, 156, 170, .17) 50%,
    rgba(65, 82, 96, .22) 100%);
  --glass-blur: blur(19px) saturate(74%);
  --glass-shadow: 0 14px 33px rgba(0, 0, 0, .35),
    0 2px 8px rgba(0, 0, 0, .17),
    inset 0 1px 0 rgba(237, 248, 255, .105);
  --glass-focus: #a9dbe7;
}

/* The night photograph is kept, but subdued so it no longer competes with text.
 * A single cool slate veil is much calmer than V2/V3 saturated detail. */
html {
  background-image:
    linear-gradient(112deg, rgba(27, 40, 52, .51), rgba(30, 38, 48, .59)),
    url("/wallpapers/user-night-desk.avif") !important;
  background-color: #293843 !important;
}
html.dark {
  background-image:
    linear-gradient(112deg, rgba(8, 15, 24, .74), rgba(12, 18, 27, .81)),
    url("/wallpapers/user-night-desk.avif") !important;
  background-color: #111a23 !important;
}
body::after { display: none !important; }
body {
  color: var(--reading-ink) !important;
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Glass reflects only along the thin edge. Legible inner vellum stays stable
 * across the very different dark and bright patches of the illustration. */
.card-base, .float-panel {
  border: 1px solid transparent !important;
  background:
    var(--glass-reflection) padding-box,
    var(--glass-surface) padding-box,
    var(--glass-spectrum) border-box !important;
  backdrop-filter: var(--glass-blur) !important;
  -webkit-backdrop-filter: var(--glass-blur) !important;
  box-shadow: var(--glass-shadow) !important;
}
#content-wrapper .card-base { min-width: 0; }
#sidebar .card-base {
  background: var(--reading-sidebar) !important;
  border: 1px solid var(--reading-line) !important;
  backdrop-filter: blur(18px) saturate(78%) !important;
  -webkit-backdrop-filter: blur(18px) saturate(78%) !important;
}
#post-container.card-base,
#post-container .card-base,
#content-wrapper > .card-base:has(.custom-md) {
  background: var(--reading-paper) !important;
  border: 1px solid var(--reading-line) !important;
  box-shadow: var(--glass-shadow) !important;
}
#navbar-wrapper .card-base {
  background: var(--reading-popover) !important;
  border: 1px solid var(--reading-line) !important;
}
#search-panel, #nav-menu-panel {
  background: var(--reading-popover) !important;
  border: 1px solid var(--reading-line) !important;
  backdrop-filter: blur(20px) saturate(78%) !important;
  -webkit-backdrop-filter: blur(20px) saturate(78%) !important;
}

/* Page headings outside cards are on the photograph: deliberately white
 * in both modes. Within the card we instead use full-strength theme ink. */
#content-wrapper > header h1 {
  color: #f7f9fb !important;
  text-shadow: 0 2px 8px rgba(0, 0, 0, .84);
  font-weight: 750;
  letter-spacing: -.018em;
}
#content-wrapper :is(h1,h2,h3) { font-weight: 700; letter-spacing: -.014em; }
#content-wrapper .card-base :is(h1,h2,h3) { color: var(--reading-ink) !important; }
#content-wrapper .card-base .font-bold,
#sidebar .card-base .font-bold { color: var(--reading-ink) !important; }
#sidebar .text-75, #content-wrapper .text-75 { color: var(--reading-muted) !important; }
#sidebar .text-50, #content-wrapper .text-50 { color: var(--reading-soft) !important; }
#sidebar .text-30, #content-wrapper .text-30,
#sidebar .text-25, #content-wrapper .text-25 { color: var(--reading-soft) !important; }
/* Prior white text outlines were compensating for legibility on transparent
 * panels; on stable reading cards those outlines make glyphs less crisp. */
html:not(.dark) #content-wrapper .card-base .text-75,
html:not(.dark) #content-wrapper .card-base .text-50,
html:not(.dark) #sidebar .card-base .text-75,
html:not(.dark) #sidebar .card-base .text-50 { text-shadow: none !important; }

.glass-story { border-color: transparent !important; }
.glass-story .text-75, .glass-story .text-50 {
  line-height: 1.7;
}
.glass-story h2 { line-height: 1.4; letter-spacing: -.015em; }
#sidebar widget-layout[data-id="categories"] button .flex.items-center.justify-between > div:last-child {
  color: var(--reading-ink) !important;
  background: var(--reading-subtle) !important;
  border: 1px solid var(--reading-line);
}
#sidebar widget-layout[data-id="tags"] .btn-regular,
.btn-regular { color: var(--reading-ink) !important; }
#sidebar widget-layout[data-id="tags"] .btn-regular {
  background: var(--reading-subtle) !important;
  border-color: var(--reading-line) !important;
}
.meta-icon { background: var(--reading-subtle) !important; border-color: var(--reading-line) !important; }

/* Essential metadata is part of the reading experience, not decorative noise. */
#post-container > .flex:first-child,
#post-container > .flex:first-child :is(span,div),
#post-container :is(.text-30,.text-50),
html.dark #post-container .text-white\\/30 {
  color: var(--reading-muted) !important;
  font-weight: 500;
}
#content-wrapper .card-base .text-xs {
  font-size: 13.5px !important;
  line-height: 1.5 !important;
}
#content-wrapper .card-base .text-sm {
  font-size: 14.5px !important;
  line-height: 1.65 !important;
}

/* Upstream has a .text-black/30 rule even in dark mode. Override its actual
 * class, otherwise reading time/word count becomes dark-gray-on-charcoal. */
html.dark #post-container [class~="text-black/30"],
html.dark #post-container [class~="text-white/30"],
html.dark #content-wrapper [class~="text-black/30"],
html.dark #post-container > .flex:first-child {
  color: #c7d4dd !important;
}

/* Reading typography: slightly larger CJK-friendly type and generous rhythm,
 * not ultra-light gray with tiny labels. Preserve math, table and code layouts. */
.custom-md {
  color: var(--reading-ink) !important;
  font-size: 1.04rem;
  line-height: 1.9;
  letter-spacing: .004em;
  font-family: inherit;
  font-weight: 400;
  overflow-wrap: break-word;
}
.custom-md :is(p,li,blockquote,dt,dd,th,td) {
  font-size: 17px !important;
  line-height: 1.9;
  color: var(--reading-ink) !important;
}
.custom-md :is(h1,h2,h3,h4,h5,h6,strong) {
  color: var(--reading-ink) !important;
  font-weight: 700;
}
.custom-md :is(h2,h3) { line-height: 1.45; letter-spacing: -.008em; }
.custom-md a { color: var(--reading-accent) !important; text-underline-offset: .17em; }
.custom-md a:hover { text-decoration-thickness: 2px; }
.custom-md :is(figcaption,small) { color: var(--reading-muted) !important; }
.custom-md :is(pre,code,.katex) { letter-spacing: normal; }
.custom-md :is(.katex-display,.katex-display-container) { max-width: 100%; }
html:not(.dark) .custom-md :is(p,li,blockquote,dt,dd,th,td,h1,h2,h3,h4,strong) {
  /* Ensure recent article-specific light typography rules remain honored. */
  color: #171717 !important;
}
html.dark .custom-md :is(p,li,blockquote,dt,dd,th,td,h1,h2,h3,h4,strong) {
  color: #edf2f5 !important;
}

/* Function labels, search and date metadata should not disappear under the
 * old Fuwari opacity tokens. */
#search-panel .text-50, #nav-menu-panel .text-50,
#search-bar input::placeholder, #search-bar-inside input::placeholder {
  color: var(--reading-muted) !important;
  opacity: 1 !important;
}
#search-bar input, #search-bar-inside input {
  color: var(--reading-ink) !important;
}
#site-footer .site-footer-copy {
  color: #f3f7f8 !important;
  text-shadow: 0 1px 4px rgba(0,0,0,.9);
}

/* Leave icons and photo color intact, but remove animation glare and
 * prevent huge contrast jumps when hovering across reading cards. */
.glass-story { transition: translate .2s ease, box-shadow .2s ease !important; }
@media (hover:hover) and (pointer:fine) {
  .glass-story:hover { translate: 0 -1px; }
}
@media (max-width:768px) {
  body::before {
    background:
      linear-gradient(112deg, rgba(27,40,52,.53), rgba(30,38,48,.61)),
      url("/wallpapers/user-night-desk.avif") center / cover no-repeat !important;
    filter: saturate(.75);
  }
  html.dark body::before {
    background:
      linear-gradient(112deg, rgba(8,15,24,.77), rgba(12,18,27,.82)),
      url("/wallpapers/user-night-desk.avif") center / cover no-repeat !important;
  }
  .card-base, .float-panel {
    backdrop-filter: blur(13px) saturate(75%) !important;
    -webkit-backdrop-filter: blur(13px) saturate(75%) !important;
  }
  .custom-md { font-size: 16px; line-height: 1.85; }
  .custom-md :is(p,li,blockquote,dt,dd,th,td) { font-size: 16px !important; }
  #content-wrapper .glass-story { font-size: 15px; }
  #sidebar .card-base { font-size: 15px; }
  .custom-md :is(p,li,blockquote) { line-height: 1.85; }
}
@media (prefers-reduced-transparency: reduce) {
  :root { --glass-surface: linear-gradient(#f5f8f8,#f5f8f8); }
  :root.dark { --glass-surface: linear-gradient(#1b2630,#1b2630); }
}
@media (prefers-reduced-motion: reduce) {
  .glass-story { transition: none !important; }
  .glass-story:hover { translate: 0 !important; }
}

/* V6: stable table of contents. Never put muted ink directly over the night
   photo, including inactive links and the areas between hover states. */
#toc-inner-wrapper:has(table-of-contents) {
  -webkit-mask-image: none;
  mask-image: none;
  background: var(--reading-sidebar);
  border: 1px solid var(--reading-line);
  border-radius: 1rem;
  box-shadow: 0 10px 28px rgba(9, 22, 30, .16);
  overscroll-behavior: contain;
}
html.dark #toc-inner-wrapper:has(table-of-contents) {
  box-shadow: 0 12px 30px rgba(0, 0, 0, .34);
}
#toc table-of-contents {
  display: block;
  padding-inline: .65rem;
}
#toc a {
  color: var(--reading-muted) !important;
  background: transparent;
  transition: color .16s ease, background-color .16s ease;
}
#toc a :is(.text-30, .text-50) {
  color: var(--reading-muted) !important;
  opacity: 1 !important;
}
#toc a:hover,
#toc a:focus-visible {
  background: var(--reading-subtle) !important;
  color: var(--reading-ink) !important;
}
#toc a.visible {
  background: var(--reading-subtle);
  color: var(--reading-ink) !important;
  font-weight: 650;
}
#toc a.visible :is(.text-30, .text-50) {
  color: var(--reading-ink) !important;
}
#toc #active-indicator {
  display: none !important; /* Avoid a dark overlap behind the now-highlighted link */
}

/* V6: almost-opaque reading surfaces do not benefit from costly backdrop blur.
   Removing the fullscreen/long-card GPU filters keeps the same layered paper
   colors while leaving blur for the small, transient popovers only. */
.card-base,
#sidebar .card-base,
#navbar-wrapper .card-base,
#post-container.card-base {
  -webkit-backdrop-filter: none !important;
  backdrop-filter: none !important;
}
@media (max-width: 768px) {
  body::before { filter: none !important; }
}
