/* Shared premium surface system — restrained glass, readable content. */
html[data-premium-ui] {
  --premium-accent: var(--accent, var(--green, #8a3139));
  --premium-glass: rgba(255, 255, 255, .52);
  --premium-glass-strong: rgba(255, 255, 255, .72);
  --premium-panel: rgba(255, 255, 255, .38);
  --premium-border: rgba(255, 255, 255, .66);
  --premium-line: rgba(47, 42, 37, .13);
  --premium-shadow: 0 22px 55px rgba(50, 43, 37, .11);
  --premium-shadow-soft: 0 10px 28px rgba(50, 43, 37, .075);
  --premium-radius: 16px;
  --premium-radius-small: 11px;
  color-scheme: light;
}

html[data-premium-ui] body:not(.dark) {
  background-color: #f1f0eb !important;
  background-image:
    radial-gradient(circle at 8% 4%, rgba(137, 74, 78, .13), transparent 29rem),
    radial-gradient(circle at 92% 12%, rgba(44, 111, 103, .12), transparent 31rem),
    linear-gradient(145deg, rgba(255, 255, 255, .42), rgba(242, 240, 233, .2) 48%, rgba(236, 239, 235, .52)) !important;
  background-attachment: fixed !important;
}

html[data-premium-ui] body.dark,
html[data-premium-ui][data-theme="dark"] body {
  --premium-glass: rgba(25, 31, 37, .58);
  --premium-glass-strong: rgba(24, 30, 36, .78);
  --premium-panel: rgba(28, 35, 42, .46);
  --premium-border: rgba(255, 255, 255, .1);
  --premium-line: rgba(255, 255, 255, .1);
  --premium-shadow: 0 24px 58px rgba(0, 0, 0, .28);
  --premium-shadow-soft: 0 10px 30px rgba(0, 0, 0, .2);
  color-scheme: dark;
  background-color: #101418 !important;
  background-image:
    radial-gradient(circle at 10% 0, rgba(135, 73, 84, .18), transparent 28rem),
    radial-gradient(circle at 92% 10%, rgba(48, 121, 116, .16), transparent 30rem),
    linear-gradient(145deg, #11161a, #151a1f 55%, #101417) !important;
  background-attachment: fixed !important;
}

html[data-premium-ui] :where(.site-header, .top, .blog-header) {
  position: sticky;
  top: 0;
  z-index: 80;
}

html[data-premium-ui] :where(body > header, .site-header, .top, .blog-header, .topbar) {
  border-color: var(--premium-line) !important;
  background-color: var(--premium-glass-strong) !important;
  box-shadow: 0 1px 0 var(--premium-border), 0 10px 34px rgba(44, 39, 34, .055);
  -webkit-backdrop-filter: blur(22px) saturate(145%);
  backdrop-filter: blur(22px) saturate(145%);
}

/* Some standalone pages put the max-width layout class directly on <header>.
   Keep the controls aligned to that layout, but extend the glass surface and
   divider across the full viewport instead of leaving uncovered side gutters. */
html[data-premium-ui] body > header.wrap {
  position: relative;
  isolation: isolate;
  border-bottom-color: transparent !important;
  background-color: transparent !important;
  box-shadow: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

html[data-premium-ui] body > header.wrap::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0 calc(50% - 50vw);
  border-bottom: 1px solid var(--premium-line);
  background-color: var(--premium-glass-strong);
  box-shadow: 0 1px 0 var(--premium-border), 0 10px 34px rgba(44, 39, 34, .055);
  -webkit-backdrop-filter: blur(22px) saturate(145%);
  backdrop-filter: blur(22px) saturate(145%);
}

html[data-premium-ui] :where(
  .chapter-toc, .mobile-index, .toolbar, .filter-bar, .filter-panel,
  .filters, .hero-panel, .profile-panel, .stats-strip, .table-wrap,
  .search-wrap,
  .visual-summary, .learning-figure, .paper-card, .course-card, .friend,
  .entry, .topic, .academic-quiet, .photo-card, .modal, .dialog-panel
) {
  border-color: var(--premium-border) !important;
  border-radius: var(--premium-radius);
  background-color: var(--premium-glass) !important;
  box-shadow: var(--premium-shadow);
  -webkit-backdrop-filter: blur(17px) saturate(128%);
  backdrop-filter: blur(17px) saturate(128%);
}

/* Study systems commonly use a dark navigation rail with light text. Keep that
   contrast while giving the rail the same translucent depth as the light UI. */
html[data-premium-ui] .sidebar {
  color: var(--sidebar-text, #edf1f3);
  border-color: rgba(255, 255, 255, .09) !important;
  border-radius: 0 var(--premium-radius) var(--premium-radius) 0;
  background-color: color-mix(in srgb, var(--sidebar-bg, #1b242d) 88%, transparent) !important;
  box-shadow: 14px 0 42px rgba(24, 29, 34, .18);
  -webkit-backdrop-filter: blur(19px) saturate(125%);
  backdrop-filter: blur(19px) saturate(125%);
}

html[data-premium-ui] .sidebar :where(a, h1, h2, h3, small, span) {
  color: inherit;
}

/* Reading shells and generic headers are layout containers, not cards. Avoid
   the oversized floating white shapes that appear when they inherit panel
   backgrounds and rounded corners. */
html[data-premium-ui] :where(.reading, .header) {
  border-radius: 0;
  background-color: transparent !important;
  box-shadow: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

/* A chapter table of contents behaves like a navigation rail. Its corners
   should be restrained so it does not look like a clipped pill at page edges. */
html[data-premium-ui] .chapter-toc {
  border-radius: 6px;
}

html[data-premium-ui] .mobile-index {
  border-radius: 8px;
}

html[data-premium-ui] article.chapter {
  border-radius: 7px;
}

html[data-premium-ui] :where(
  .card, .box, .tool, .analysis, .caution, .callout, .highlight-box,
  .key-box, .def-card, .term-card, .chapter-card, .formula, .exercise,
  .field, .compare, .understand, .master, .summary-card, .dashboard-card,
  .chapter
) {
  border-color: var(--premium-line) !important;
  border-radius: var(--premium-radius-small);
  background-color: var(--premium-panel);
  box-shadow: var(--premium-shadow-soft);
}

html[data-premium-ui] :where(button, .btn, .button, .primary-button, .read, input:not(.search-bar__input), select, textarea) {
  border-color: var(--premium-line);
  border-radius: 10px;
}

html[data-premium-ui] :where(input:not(.search-bar__input), select, textarea) {
  background-color: rgba(255, 255, 255, .58);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .62), 0 6px 18px rgba(45, 39, 34, .055);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

html[data-premium-ui] body.dark :where(input:not(.search-bar__input), select, textarea),
html[data-premium-ui][data-theme="dark"] :where(input:not(.search-bar__input), select, textarea) {
  background-color: rgba(19, 25, 31, .68);
}

html[data-premium-ui] :where(button, .btn, .button, .primary-button, .read, nav a, .pager a) {
  transition: color .18s ease, border-color .18s ease, background-color .18s ease,
    box-shadow .18s ease, transform .18s ease;
}

html[data-premium-ui] :where(button, .btn, .button, .primary-button):hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(48, 42, 37, .12);
}

html[data-premium-ui] :where(a, button, input, select, textarea):focus-visible {
  outline: 3px solid color-mix(in srgb, var(--premium-accent) 42%, transparent);
  outline-offset: 3px;
}

html[data-premium-ui] :where(table) {
  border-color: var(--premium-line);
  background-color: rgba(255, 255, 255, .2);
}

html[data-premium-ui] :where(th) {
  background-color: var(--premium-glass-strong);
}

html[data-premium-ui] :where(td, th) {
  border-color: var(--premium-line) !important;
}

html[data-premium-ui] :where(dialog)::backdrop {
  background: rgba(18, 23, 27, .52);
  -webkit-backdrop-filter: blur(9px);
  backdrop-filter: blur(9px);
}

html[data-premium-ui] :where(.site-footer, body > footer, .blog-footer) {
  border-color: var(--premium-line) !important;
  background-color: rgba(247, 246, 241, .5);
  -webkit-backdrop-filter: blur(18px) saturate(130%);
  backdrop-filter: blur(18px) saturate(130%);
}

html[data-premium-ui] body.dark :where(.site-footer, body > footer, .blog-footer),
html[data-premium-ui][data-theme="dark"] :where(.site-footer, body > footer, .blog-footer) {
  background-color: rgba(17, 22, 27, .58);
}

html[data-premium-ui] :where(.photo-card, .blog-cover, .cover, .learning-figure img) {
  overflow: hidden;
  border-radius: var(--premium-radius);
}

html[data-premium-ui] :where(h1, h2, h3) {
  text-wrap: balance;
}

html[data-premium-ui] ::selection {
  color: #fff;
  background: color-mix(in srgb, var(--premium-accent) 82%, #4b2025);
}

html[data-premium-ui] {
  scrollbar-color: color-mix(in srgb, var(--premium-accent) 48%, #8c8b86) transparent;
  scrollbar-width: thin;
}

@supports not ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  html[data-premium-ui] :where(body > header, .site-header, .top, .blog-header, .topbar,
    .chapter-toc, .mobile-index, .toolbar, .filter-bar, .filter-panel,
    .filters, .hero-panel, .profile-panel, .stats-strip, .table-wrap,
    .search-wrap,
    .visual-summary, .learning-figure, .paper-card, .course-card, .friend,
    .entry, .topic, .academic-quiet, .photo-card, .modal, .dialog-panel) {
    background-color: rgba(248, 247, 243, .94) !important;
  }
}

@media (max-width: 720px) {
  html[data-premium-ui] {
    --premium-radius: 13px;
    --premium-radius-small: 9px;
    --premium-shadow: 0 15px 38px rgba(50, 43, 37, .095);
  }
  html[data-premium-ui] :where(.site-header, .top, .blog-header) {
    -webkit-backdrop-filter: blur(18px) saturate(135%);
    backdrop-filter: blur(18px) saturate(135%);
  }
}

@media (prefers-reduced-motion: reduce) {
  html[data-premium-ui] *,
  html[data-premium-ui] *::before,
  html[data-premium-ui] *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
  }
}

/* Desktop reading layouts -------------------------------------------------
   The chapter shells used to stop at a fixed 1160px/235px/820px grid. That
   looked acceptable on a laptop, but left a wide monitor with an oversized
   reading card and a narrow navigation rail. These tiers deliberately affect
   only the long-form finance/relationship shells; phone and tablet rules in
   their own stylesheets remain the source of truth below 1100px. */
@media (min-width: 1100px) {
  html[data-premium-ui] body:has(> main.page-shell:not(.quiz-shell)) > :where(header.wrap, main.page-shell),
  html[data-premium-ui] body:has(> .directory) > :where(header.wrap, .directory-hero, main.directory),
  html[data-premium-ui] body:has(> main.layout) > :where(header.wrap, section.wrap, main.layout) {
    width: min(1320px, calc(100% - 64px));
  }

  html[data-premium-ui] body:has(> main.page-shell:not(.quiz-shell)) > main.page-shell,
  html[data-premium-ui] body:has(> main.layout) > main.layout {
    grid-template-columns: 260px minmax(0, 1fr);
    justify-content: stretch;
    gap: clamp(44px, 3.6vw, 58px);
  }

  html[data-premium-ui] body:has(> main.page-shell:not(.quiz-shell)) .chapter-toc,
  html[data-premium-ui] body:has(> main.layout) .toc {
    font-size: .9rem;
  }

  html[data-premium-ui] body:has(> main.page-shell:not(.quiz-shell)) .chapter,
  html[data-premium-ui] body:has(> main.layout) .chapter {
    padding: clamp(36px, 3.2vw, 48px) clamp(36px, 3.8vw, 56px);
  }

  html[data-premium-ui] body:has(> main.page-shell:not(.quiz-shell)) .chapter h3,
  html[data-premium-ui] body:has(> main.layout) .chapter h3 {
    font-size: clamp(2.15rem, 2.9vw, 2.85rem);
  }

  /* Keep paragraphs comfortable on wide screens while allowing tables and
     comparison blocks to use the complete article width. */
  html[data-premium-ui] body:has(> main.page-shell:not(.quiz-shell)) .chapter > :where(p, ul, ol),
  html[data-premium-ui] body:has(> main.layout) .chapter > :where(p, ul, ol) {
    max-width: 72em;
  }

  html[data-premium-ui] body:has(> .directory) .directory-hero {
    padding-top: 88px;
    padding-bottom: 66px;
  }

  html[data-premium-ui] body:has(> .directory) .directory {
    padding-top: 68px;
  }

  html[data-premium-ui] body:has(> .directory) .chapter-cards {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
  }
}

@media (min-width: 1680px) {
  html[data-premium-ui] body:has(> main.page-shell:not(.quiz-shell)) > :where(header.wrap, main.page-shell),
  html[data-premium-ui] body:has(> .directory) > :where(header.wrap, .directory-hero, main.directory),
  html[data-premium-ui] body:has(> main.layout) > :where(header.wrap, section.wrap, main.layout) {
    width: min(1500px, calc(100% - 96px));
  }

  html[data-premium-ui] body:has(> main.page-shell:not(.quiz-shell)) > main.page-shell,
  html[data-premium-ui] body:has(> main.layout) > main.layout {
    grid-template-columns: 286px minmax(0, 1fr);
    gap: clamp(56px, 4vw, 70px);
  }

  html[data-premium-ui] body:has(> main.page-shell:not(.quiz-shell)) .chapter,
  html[data-premium-ui] body:has(> main.layout) .chapter {
    padding: 50px 60px;
  }
}

/* Unified site chrome ------------------------------------------------------
   Core pages used to define their own header widths and flex arrangements.
   Keep the content layouts independent, but give every public site-level
   header the same reading width, vertical rhythm, title position and control
   treatment. Game screens with an intentionally cinematic header are not
   targeted by this block. */
html[data-premium-ui] :where(body > header.wrap:not(.site-header), .site-header) {
  box-sizing: border-box;
  width: min(1320px, calc(100% - 64px)) !important;
  min-height: 72px;
  margin-inline: auto;
  padding: 0;
  border-bottom: 1px solid var(--premium-line) !important;
  background: transparent !important;
  box-shadow: none !important;
  position: sticky;
  top: 0;
  z-index: 80;
  isolation: isolate;
}

html[data-premium-ui] body > header.wrap:not(.site-header) {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  column-gap: 24px;
}

/* The page-local glass fallback targets `body > header.wrap` with higher
   specificity, so repeat the sticky position on the explicit selector. */
html[data-premium-ui] body > header.wrap:not(.site-header) {
  position: sticky;
  top: 0;
}

html[data-premium-ui] body > header.wrap:not(.site-header)::before {
  z-index: -1;
}

html[data-premium-ui] body > header.wrap:not(.site-header) > .back {
  grid-column: 1;
  justify-self: start;
}

html[data-premium-ui] body > header.wrap:not(.site-header) > .small {
  grid-column: 2;
  justify-self: center;
}

html[data-premium-ui] body > header.wrap:not(.site-header) > :where(.language-select, #gameLanguageSelect, select, .header-link, .header-action) {
  grid-column: 3;
  justify-self: end;
}

html[data-premium-ui] :where(body > header.wrap:not(.site-header), .site-header) :where(.back, .header-brand) {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  color: var(--ink, #24272c);
  font-size: .9rem;
  font-weight: 800;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
}

html[data-premium-ui] :where(body > header.wrap:not(.site-header), .site-header) :where(.back, .header-brand):hover {
  color: var(--premium-accent, #8a3139);
}

html[data-premium-ui] :where(body > header.wrap:not(.site-header), .site-header) .back span {
  margin-right: 0;
  color: var(--premium-accent, #8a3139);
  font-size: 1.18em;
}

html[data-premium-ui] :where(body > header.wrap:not(.site-header), .site-header) .back::first-letter {
  color: var(--premium-accent, #8a3139);
}

html[data-premium-ui] :where(body > header.wrap:not(.site-header), .site-header) .small {
  color: var(--muted, #70757d);
  font-size: .88rem;
  font-weight: 700;
  letter-spacing: .04em;
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
}

html[data-premium-ui] .site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

/* Detail and subtopic pages share one rail: the site identity stays on the
   left, while the contextual return link and any controls stay on the right.
   A few older pages put the back link first in the markup; explicit grid
   placement keeps their visual order consistent without changing content. */
html[data-premium-ui] body > header.site-header:has(> .header-brand) {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  column-gap: 24px;
}

html[data-premium-ui] body > header.site-header:has(> .header-brand) > .header-brand {
  grid-column: 1;
  grid-row: 1;
  justify-self: start;
  min-width: 0;
}

html[data-premium-ui] body > header.site-header:has(> .header-brand) > :where(.back, .header-side, .header-link, .header-action) {
  grid-column: 3;
  grid-row: 1;
  justify-self: end;
  min-width: 0;
}

/* Page-local styles use `position: relative` for the shared site header.
   Keep the public header anchored during long topic pages. */
html[data-premium-ui] body > header.site-header {
  position: sticky;
  top: 0;
}

html[data-premium-ui] body > header.wrap:not(.site-header) :where(.header-link, .header-action) {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  color: var(--muted, #70757d);
  font-size: .86rem;
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
}

html[data-premium-ui] body > header.wrap:not(.site-header) :where(.header-link, .header-action):hover {
  color: var(--premium-accent, #8a3139);
}

/* A few interactive topic pages keep their own `.top` wrapper. Align its
   inner content to the same reading rail without changing the page body. */
html[data-premium-ui] body > header.top {
  min-height: 72px;
  padding: 0;
  display: flex;
  align-items: center;
}

html[data-premium-ui] body > header.top .top-in {
  width: min(1320px, calc(100% - 64px));
  min-height: 72px;
  margin-inline: auto;
}

html[data-premium-ui] .site-header .header-side {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
  min-width: 0;
}

html[data-premium-ui] :where(body > header.wrap:not(.site-header), .site-header) :where(.language-select, #gameLanguageSelect, select) {
  box-sizing: border-box;
  min-width: 78px;
  min-height: 42px;
  padding: 0 14px !important;
  border: 1px solid var(--premium-line) !important;
  border-radius: 999px !important;
  background: rgba(255, 255, 255, .56) !important;
  color: var(--ink, #24272c) !important;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .7), 0 7px 20px rgba(45, 39, 34, .06) !important;
  font: 700 .8rem/1 "Microsoft YaHei", system-ui, sans-serif !important;
  cursor: pointer;
}

html[data-premium-ui] :where(body > header.wrap:not(.site-header), .site-header) :where(.language-select, #gameLanguageSelect, select):hover {
  border-color: color-mix(in srgb, var(--premium-accent, #8a3139) 48%, var(--premium-line)) !important;
  color: var(--premium-accent, #8a3139) !important;
}

html[data-premium-ui] :where(body > header.wrap:not(.site-header), .site-header) :where(.language-select, #gameLanguageSelect, select):focus-visible {
  outline: 3px solid color-mix(in srgb, var(--premium-accent, #8a3139) 30%, transparent);
  outline-offset: 3px;
}

@media (min-width: 1680px) {
  html[data-premium-ui] :where(body > header.wrap:not(.site-header), .site-header) {
    width: min(1500px, calc(100% - 96px));
  }
}

@media (max-width: 720px) {
  html[data-premium-ui] :where(body > header.wrap:not(.site-header), .site-header) {
    /* Keep the site chrome inside the viewport.  `calc()` is intentional:
       older page-local styles use the same expression, and an unwrapped
       subtraction can be parsed as an invalid width by some browsers. */
    width: calc(100% - 30px) !important;
    max-width: 1320px !important;
    margin-inline: 15px !important;
    min-height: 62px;
  }

  html[data-premium-ui] body > header.top {
    min-height: 62px;
  }

  html[data-premium-ui] body > header.wrap:not(.site-header) {
    column-gap: 10px;
  }

  html[data-premium-ui] body > header.site-header:has(> .header-brand) {
    column-gap: 10px;
  }

  /* Some language pages collapse the contextual label to an arrow on small
     screens. The shared rail keeps the label visible so every subtopic has
     the same readable return affordance. */
  html[data-premium-ui] body > header.site-header:has(> .header-brand) .header-side .back {
    font-size: .82rem;
    line-height: 1.2;
  }

  html[data-premium-ui] body > header.site-header:has(> .header-brand) .header-side .back::before {
    content: none;
  }

  html[data-premium-ui] body > header.top .top-in {
    width: calc(100% - 30px);
    min-height: 62px;
  }

  html[data-premium-ui] :where(body > header.wrap:not(.site-header), .site-header) :where(.back, .header-brand) {
    min-height: 38px;
    font-size: .82rem;
  }

  html[data-premium-ui] :where(body > header.wrap:not(.site-header), .site-header) .small {
    font-size: .78rem;
  }

  html[data-premium-ui] :where(body > header.wrap:not(.site-header), .site-header) :where(.language-select, #gameLanguageSelect, select) {
    min-width: 70px;
    min-height: 38px;
    padding-inline: 10px !important;
    font-size: .75rem !important;
  }

  html[data-premium-ui] .site-header .header-side {
    gap: 8px;
  }
}
