/* ==========================================================================
   耳根宇宙 — night-xianxia polish layer: nebula, glass, glow, motion
   Loaded after style.css; only overrides and additions live here.
   ========================================================================== */

/* ---------- backdrop ---------- */
#sky {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
}
[data-theme='night'] body {
  background:
    radial-gradient(1100px 700px at 85% -10%, rgba(90, 70, 160, .22), transparent 60%),
    radial-gradient(900px 600px at -10% 30%, rgba(30, 80, 120, .20), transparent 60%),
    radial-gradient(1000px 500px at 50% 110%, rgba(232, 96, 74, .14), transparent 60%),
    var(--paper);
  background-attachment: fixed;
}
.cursor-glow {
  position: fixed; left: -220px; top: -220px; width: 440px; height: 440px; z-index: 0; pointer-events: none;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(226, 184, 102, .09), transparent 65%);
  transition: transform .25s cubic-bezier(.2, .7, .2, 1);
}
[data-theme='ink'] .cursor-glow { background: radial-gradient(circle, rgba(178, 58, 43, .06), transparent 65%); }

/* ---------- header: transparent at top, glass when scrolled ---------- */
.site-header {
  background: transparent; border-bottom-color: transparent; backdrop-filter: none;
  transition: background-color .35s, border-color .35s, backdrop-filter .35s;
}
.site-header.scrolled {
  background: color-mix(in srgb, var(--paper) 72%, transparent);
  border-bottom-color: var(--line);
  backdrop-filter: blur(14px) saturate(1.2);
}
.brand-zh { background: linear-gradient(100deg, var(--ink) 30%, var(--gold) 50%, var(--ink) 70%); background-size: 250% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent; animation: sheen 7s linear infinite; }
.main-nav a { font-family: var(--font-body); letter-spacing: .01em; }
.main-nav a[aria-current='page']::after { background: linear-gradient(90deg, var(--gold), var(--cinnabar)); box-shadow: 0 0 12px var(--gold); }

/* ---------- typography ---------- */
.pinyin, .hero-copy .eyebrow, .eyebrow { font-family: var(--font-latin); }
.pinyin { font-size: 1.02em; letter-spacing: .02em; }
.eyebrow { font-style: italic; letter-spacing: .25em; color: var(--gold); }
.page-head h1, .work-hero h1, .entry-main h1 { font-weight: 800; letter-spacing: -.005em; }

@keyframes sheen { to { background-position: -250% 0; } }

/* ---------- hero ---------- */
.hero { min-height: min(92vh, 860px); border-bottom: 0; }
.hero::after { /* fade into the page */
  content: ''; position: absolute; inset: auto 0 0 0; height: 220px; z-index: -1;
  background: linear-gradient(transparent, var(--paper));
}
.hero-art [data-depth] { will-change: transform; transition: transform .5s cubic-bezier(.2, .7, .2, 1); }
.hero-copy h1 {
  font-size: clamp(2.6rem, 6.2vw, 5rem); line-height: 1.08; font-weight: 800; letter-spacing: -.01em;
  text-wrap: balance;
}
.hero-copy h1 em {
  font-style: normal;
  background: linear-gradient(100deg, var(--gold) 0%, #fff1c9 35%, var(--cinnabar) 70%, var(--gold) 100%);
  background-size: 220% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: sheen 6s linear infinite;
  filter: drop-shadow(0 0 22px rgba(226, 184, 102, .35));
}
.hero-copy p { font-size: 1.1rem; color: var(--ink-2); font-weight: 300; }
.hero-title { text-shadow: 0 0 30px rgba(226, 184, 102, .25); }
[data-theme='night'] .hero-title { color: var(--ink); }
[data-theme='night'] .hero-sun {
  background: radial-gradient(circle at 40% 38%, #fff8e3 0%, #f3d792 35%, var(--gold) 70%);
  box-shadow: 0 0 90px 20px rgba(226, 184, 102, .28), 0 0 220px 60px rgba(226, 184, 102, .12);
  animation: breathe-sun 8s ease-in-out infinite;
}
@keyframes breathe-sun { 50% { filter: brightness(1.15) saturate(1.1); } }

/* rune ring behind the vertical title */
.rune-ring {
  position: absolute; right: -6%; top: 50%; width: min(560px, 62vw); aspect-ratio: 1; z-index: -1;
  transform: translateY(-50%); pointer-events: none; opacity: .55;
}
.rune-ring svg { width: 100%; height: 100%; overflow: visible; }
.rune-ring .spin { transform-origin: 50% 50%; animation: spin 90s linear infinite; }
.rune-ring .spin.rev { animation-duration: 140s; animation-direction: reverse; }
.rune-ring text { font-family: var(--font-zh); font-size: 15px; letter-spacing: 6px; fill: var(--gold); }
.rune-ring circle { fill: none; stroke: var(--gold); }
@keyframes spin { to { transform: rotate(360deg); } }

/* buttons */
.btn { border-radius: 999px; padding: .75rem 1.5rem; font-family: var(--font-body); font-weight: 500; position: relative; overflow: hidden; }
.btn-primary {
  background: linear-gradient(135deg, var(--cinnabar), color-mix(in srgb, var(--cinnabar) 60%, var(--gold)));
  border-color: transparent; box-shadow: 0 10px 30px -10px var(--cinnabar);
}
.btn-primary::after { /* light sweep */
  content: ''; position: absolute; inset: 0; transform: translateX(-120%);
  background: linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, .35), transparent 70%);
  transition: transform .7s;
}
.btn-primary:hover::after { transform: translateX(120%); }
.btn:not(.btn-primary) { border-color: var(--line-strong); backdrop-filter: blur(6px); }
.btn:not(.btn-primary):hover { border-color: var(--gold); box-shadow: var(--glow); }

/* ---------- section headings ---------- */
.section-head h2 { font-size: clamp(1.6rem, 3vw, 2.2rem); font-weight: 800; }
.section-head h2 .brush {
  color: var(--gold); text-shadow: 0 0 18px rgba(226, 184, 102, .45);
}
.section-head { position: relative; padding-bottom: .9rem; }
.section-head::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: 0; height: 1px;
  background: linear-gradient(90deg, var(--gold), transparent 70%); opacity: .5;
}

/* ---------- glass panels ---------- */
[data-theme='night'] .news-card,
[data-theme='night'] .aside-card,
[data-theme='night'] .quote-block,
[data-theme='night'] .ladder li,
[data-theme='night'] .lede,
[data-theme='night'] .search-panel {
  background: var(--glass);
  backdrop-filter: blur(10px);
  border-color: var(--line);
}
.news-card, .aside-card, .quote-block { border-radius: 14px; }
.ladder li { border-radius: 12px; }

/* cursor-following sheen on cards */
.tiltable { position: relative; isolation: isolate; }
.tiltable:not(.scroll)::before {
  content: ''; position: absolute; inset: 0; border-radius: inherit; z-index: -1; pointer-events: none;
  background: radial-gradient(420px circle at var(--mx, 50%) var(--my, 50%), rgba(226, 184, 102, .12), transparent 45%);
  opacity: 0; transition: opacity .3s;
}
.tiltable:not(.scroll):hover::before { opacity: 1; }
.news-card:hover, .aside-card:hover, .quote-block:hover { border-color: var(--line-strong); }

/* dictionary rows become soft cards */
.dict-item { border-radius: 12px; padding: 1.1rem .9rem; border-bottom-color: var(--line); transition: background-color .3s; }
.dict-item:hover { background: color-mix(in srgb, var(--paper-2) 70%, transparent); }
.dict-zh { color: var(--ink); }
[data-theme='night'] .dict-item:hover .dict-zh { color: var(--gold); text-shadow: 0 0 16px rgba(226, 184, 102, .5); }

/* ---------- hanging scrolls: 3D tilt + glow ---------- */
.scrolls { perspective: 1100px; }
.scroll { transform-style: preserve-3d; }
.scroll .scroll-paper {
  transform: rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg));
  transition: transform .25s ease-out, box-shadow .4s;
}
.scroll:hover .scroll-paper {
  transform: rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)) translateY(-6px);
  box-shadow: 0 30px 60px -25px rgba(0, 0, 0, .8), 0 0 40px -10px color-mix(in srgb, var(--accent) 70%, var(--gold));
}
[data-theme='night'] .scroll-paper {
  background:
    radial-gradient(260px circle at var(--mx, 50%) var(--my, 30%), color-mix(in srgb, var(--accent) 35%, transparent), transparent 60%),
    linear-gradient(180deg, color-mix(in srgb, var(--accent) 28%, var(--paper-2)), var(--paper-2) 55%);
  border-inline-color: color-mix(in srgb, var(--accent) 60%, var(--gold));
}
[data-theme='night'] .scroll-emblem { filter: drop-shadow(0 0 14px color-mix(in srgb, var(--accent) 60%, var(--gold))); }

/* ---------- realms ladder: glowing level node ---------- */
[data-theme='night'] .ladder li::before { border-color: var(--gold); color: var(--gold); box-shadow: 0 0 14px -2px rgba(226, 184, 102, .5); }
.ladder li { transition: transform .3s, border-color .3s; }
.ladder li:hover { transform: translateX(6px); border-color: var(--line-strong); }

/* ---------- timeline: glowing seals ---------- */
[data-theme='night'] .timeline::before { background: linear-gradient(180deg, var(--gold), transparent); }
.timeline > li::before { box-shadow: 0 0 22px -4px var(--cinnabar); border-radius: 8px; }

/* ---------- emblem halo on work page ---------- */
[data-theme='night'] .work-emblem {
  box-shadow: 0 0 0 6px var(--paper), 0 0 0 7px var(--gold), 0 0 60px -10px var(--accent);
  animation: halo 6s ease-in-out infinite;
}
@keyframes halo { 50% { box-shadow: 0 0 0 6px var(--paper), 0 0 0 7px var(--gold), 0 0 90px 0 var(--accent); } }

/* ---------- scroll reveal ---------- */
.reveal { opacity: 0; transform: translateY(24px); filter: blur(4px); }
.reveal.is-in {
  opacity: 1; transform: none; filter: none;
  transition: opacity .8s cubic-bezier(.2, .7, .2, 1) var(--d, 0ms), transform .8s cubic-bezier(.2, .7, .2, 1) var(--d, 0ms), filter .8s var(--d, 0ms);
}
/* the ladder rows slide in from the side */
.ladder li.reveal { transform: translateX(-18px); }
.ladder li.reveal.is-in { transform: none; }

/* page transition: fade + rise instead of the clip-path unroll */
.page { animation: rise .7s cubic-bezier(.2, .7, .2, 1) both; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); filter: blur(6px); } to { opacity: 1; transform: none; filter: none; } }

/* ---------- footer ---------- */
.site-footer { background: linear-gradient(180deg, transparent, color-mix(in srgb, var(--paper-2) 80%, transparent)); border-top-color: var(--line); }
.footer-mark { text-shadow: 0 0 20px var(--cinnabar); }

/* ---------- search ---------- */
.search-panel { border-radius: 16px; box-shadow: 0 40px 100px -20px rgba(0, 0, 0, .7), var(--glow); }

@media (max-width: 760px) {
  .rune-ring { right: -12%; top: 50%; width: 62vw; opacity: .3; }
  .rune-ring text { font-size: 13px; }
  .hero-copy h1 { font-size: clamp(2.3rem, 10vw, 3.2rem); }
  .cursor-glow { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .reveal { opacity: 1; transform: none; filter: none; }
  .brand-zh, .hero-copy h1 em { animation: none; }
}

/* ==========================================================================
   Layout fixes: Thai line spacing, readable hero text, scroll card sizing
   ========================================================================== */

/* Thai stacks vowels and tone marks above the line, so headings need room */
h1, h2, h3 { line-height: 1.35; }
.hero-copy h1 { line-height: 1.22; padding-top: .1em; }
.section-head h2, .page-head h1, .work-hero h1, .entry-main h1 { line-height: 1.3; }

/* hero: less empty space, text stays readable over the mountains */
.hero { min-height: min(84vh, 780px); }
.hero-inner { padding-block: 3.5rem 5rem; }
.hero-copy p, .hero-copy .eyebrow { text-shadow: 0 1px 2px var(--paper), 0 0 18px var(--paper); }
.hero-copy p { text-wrap: pretty; max-width: 34rem; }
.hero-actions { margin-top: 1.5rem; }

/* hanging scrolls: same comfortable size at every width instead of stretching */
.scrolls { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); justify-items: center; gap: 2rem 1.25rem; }
.scroll { width: 100%; max-width: 210px; }
.scroll-paper { aspect-ratio: 9 / 16; }
.scroll-emblem { align-self: center; margin: 2.2rem 0 0; }
.scroll-meta { margin-top: .4rem; }
.scroll-meta strong { font-family: var(--font-body); font-weight: 600; font-size: .86rem; line-height: 1.45; }
.scroll-meta span { display: block; margin-top: .15rem; }

/* news: breathing room between title and text */
.news-card h3 { line-height: 1.4; margin: .35rem 0 .5rem; }
.news-meta { gap: .5rem; }

/* dictionary cards: keep the vertical Chinese name from crowding the text */
.dict-item { grid-template-columns: 3.6rem 1fr; gap: 1.1rem; }
.dict-body h3 { line-height: 1.45; }

@media (max-width: 760px) {
  .rune-ring { display: none; }  /* the title is horizontal here, the ring only clutters it */
  .scrolls { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .hero { min-height: auto; }
  .hero-inner { padding-block: 2rem 4rem; }
}

/* hero blends into the nebula instead of ending on a flat band */
.hero::after { display: none; }
.hero-art { -webkit-mask-image: linear-gradient(#000 62%, transparent 98%); mask-image: linear-gradient(#000 62%, transparent 98%); }

/* spoilers: misty blurred text instead of a solid bright bar */
.spoiler {
  background: color-mix(in srgb, var(--gold) 10%, transparent);
  color: transparent;
  text-shadow: 0 0 9px color-mix(in srgb, var(--ink) 85%, transparent);
  filter: none; border-radius: 6px; padding: .05em .3em;
  outline: 1px dashed color-mix(in srgb, var(--gold) 35%, transparent); outline-offset: -1px;
}
.spoiler:hover { background: color-mix(in srgb, var(--gold) 16%, transparent); }
.spoiler.revealed, [data-spoilers='shown'] .spoiler { text-shadow: none; outline: 0; }

/* summary box: no dangling paragraph margin */
.lede { padding: 1rem 1.25rem; border-radius: 0 12px 12px 0; }
.lede p:last-child, .prose p:last-child { margin-bottom: 0; }
.entry-main .prose + .tags { margin-top: 1.25rem; }

/* realms page heads */
.realm-group-head { align-items: center; margin-bottom: 1.25rem; }
.realm-group-head .brush { white-space: nowrap; }
.realm-path-title { margin-top: .5rem; }
@media (max-width: 760px) {
  .realm-group-head { gap: .75rem; }
  .realm-group-head .brush { font-size: 2rem; }
  .realm-group-head h2 { font-size: 1.15rem; }
  .ladder li { grid-template-columns: 2.3rem 4.6rem 1fr; }
  .ladder .realm-zh.long { font-size: 1rem; }
}
@media (max-width: 760px) {
  /* phone: Chinese name sits above the Thai name instead of taking its own column */
  .ladder li { grid-template-columns: 2.3rem 1fr; row-gap: .15rem; align-items: start; }
  .ladder li::before { grid-row: span 2; align-self: center; }
  .ladder .realm-zh, .ladder .realm-zh.long { grid-column: 2; font-size: 1.2rem; }
}
@media (max-width: 760px) {
  /* phone: the moon moves to the empty space beside the buttons so it never sits under the title */
  .hero-sun { top: auto; bottom: 12%; right: 6%; width: 86px; }
  .hero-inner { padding-block: 1.5rem 3rem; }
}

/* ---------- scrolls with artwork ---------- */
.scroll.has-image .scroll-paper { padding: 0; }
.scroll.has-image .scroll-image { opacity: 1; transition: transform .6s cubic-bezier(.2, .7, .2, 1), filter .6s; filter: saturate(1.05) contrast(1.05); }
.scroll.has-image:hover .scroll-image { transform: scale(1.06); filter: saturate(1.2) contrast(1.08); }
.scroll.has-image .scroll-paper::after { /* shade top and bottom so the titles stay readable */
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background:
    linear-gradient(180deg, rgba(5, 7, 12, .72) 0%, transparent 30%),
    linear-gradient(0deg, rgba(5, 7, 12, .95) 0%, rgba(5, 7, 12, .55) 28%, transparent 50%);
}
.scroll.has-image .scroll-emblem { visibility: hidden; }
.scroll.has-image .scroll-title,
.scroll.has-image .scroll-order,
.scroll.has-image .scroll-meta,
.scroll.has-image .scroll-stamp { position: absolute; z-index: 2; }
.scroll.has-image .scroll-title { color: #fff4dc; text-shadow: 0 2px 10px #000; }
.scroll.has-image .scroll-order { color: rgba(255, 244, 220, .75); }
.scroll.has-image .scroll-meta { left: 0; right: 0; bottom: .8rem; padding: 0 .6rem; color: #fff4dc; }
.scroll.has-image .scroll-meta span { color: rgba(255, 244, 220, .7); }

.work-emblem img { object-fit: cover; }
.work-emblem { overflow: hidden; }
.image-credit { font-size: .78rem; color: var(--ink-soft); margin: -.4rem 0 1rem; }
/* fill the row: empty tracks collapse, so six scrolls spread across the width */
.scrolls { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.scroll { max-width: 240px; }

/* ==========================================================================
   Performance pass: lighter motion everywhere, much lighter on phones/tablets
   ========================================================================== */

/* reveal and page entry: opacity + small lift only (blur filters are costly) */
.reveal { opacity: 0; transform: translateY(14px); filter: none; }
.reveal.is-in {
  opacity: 1; transform: none; filter: none;
  transition: opacity .5s ease var(--d, 0ms), transform .5s cubic-bezier(.2, .7, .2, 1) var(--d, 0ms);
}
.ladder li.reveal { transform: translateX(-10px); }
.page { animation: rise-lite .45s cubic-bezier(.2, .7, .2, 1) both; }
@keyframes rise-lite { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* endless animations that repaint every frame: calmer or static */
.brand-zh { animation: none; background: none; color: var(--ink); -webkit-background-clip: border-box; background-clip: border-box; }
.hero-copy h1 em { animation-duration: 12s; filter: none; }
[data-theme='night'] .hero-sun { animation: none; }
[data-theme='night'] .work-emblem { animation: none; box-shadow: 0 0 0 6px var(--paper), 0 0 0 7px var(--gold), 0 0 50px -12px var(--accent); }
.rune-ring .spin { animation-duration: 160s; will-change: transform; }
.rune-ring .spin.rev { animation-duration: 240s; }
.mist { animation-duration: 60s; }
.mist.slow { animation-duration: 90s; }

/* the canvas and glow live on their own layers */
#sky, .cursor-glow { will-change: transform; }

/* ---------- lite mode: phones, tablets, weak devices ---------- */
.fx-lite body { background-attachment: scroll; }
.fx-lite .cursor-glow { display: none; }
.fx-lite .site-header.scrolled { backdrop-filter: none; background: color-mix(in srgb, var(--paper) 94%, transparent); }
.fx-lite .news-card,
.fx-lite .aside-card,
.fx-lite .quote-block,
.fx-lite .ladder li,
.fx-lite .lede,
.fx-lite .search-panel,
.fx-lite .btn:not(.btn-primary) { backdrop-filter: none; }
[data-theme='night'].fx-lite .news-card,
[data-theme='night'].fx-lite .aside-card,
[data-theme='night'].fx-lite .quote-block,
[data-theme='night'].fx-lite .ladder li,
[data-theme='night'].fx-lite .lede { background: rgba(16, 22, 36, .82); }
.fx-lite .search-overlay { backdrop-filter: none; background: rgba(4, 6, 10, .72); }
.fx-lite .mist, .fx-lite .rune-ring .spin, .fx-lite .hero-copy h1 em { animation: none; }
.fx-lite .scroll:hover .scroll-paper { transform: none; }
.fx-lite .scroll.has-image:hover .scroll-image { transform: none; }
.fx-lite .ladder li:hover { transform: none; }
.fx-lite .hero-art svg { filter: none; }

/* ---------- tablets (iPad portrait/landscape) ---------- */
@media (min-width: 761px) and (max-width: 1180px) {
  .hero { min-height: auto; }
  .hero-inner { padding-block: 4rem 5rem; grid-template-columns: minmax(0, 1fr) auto; gap: 1.5rem; }
  .hero-copy h1 { font-size: clamp(2.4rem, 5.4vw, 3.6rem); }
  .hero-title { font-size: clamp(4rem, 9vw, 6.5rem); margin-right: 0; }
  .rune-ring { width: 300px; right: -70px; opacity: .35; }
  .hero-sun { right: 6%; top: 8%; width: 110px; }
  .scrolls { grid-template-columns: repeat(3, 1fr); }
  .home-grid { grid-template-columns: 1fr; gap: 2rem; }
}
