/*
  Global product layer.
  Shared everywhere: reset, global header, reading-column primitives,
  kicker/divider vocabulary. Module-specific rules stay in the module's own
  stylesheet (see docs/features/scoring-criteria/UI_SPEC.md §2 layer table).
*/

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background-color: var(--color-bg);
  /* Faint paper grain (~5% noise, SVG data URI — no extra request, no
     effect on load time) so the background reads as material rather
     than a flat digital fill. Owner review 2026-08-16. */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.05'/%3E%3C/svg%3E");
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
}

a:focus-visible,
button:focus-visible,
summary:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 3px;
}

ul,
ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

p {
  margin: 0;
}

.icon {
  display: inline-block;
  flex-shrink: 0;
}

.icon svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* ---- Global header (product-level, persistent everywhere) ---- */

.global-header {
  position: sticky;
  top: 0;
  z-index: 20;
  height: var(--header-height);
  display: flex;
  align-items: center;
  gap: 2.5rem;
  padding: 0 3rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.global-header__brand {
  font-family: var(--font-sans);
  font-size: var(--fs-wordmark);
  font-weight: 700;
  color: var(--color-text);
}

.global-header__brand a {
  display: flex;
  align-items: center;
  text-decoration: none;
  color: inherit;
}

.global-header__brand img {
  display: block;
  height: 32px;
  width: auto;
}

.global-header__nav {
  display: flex;
  align-items: center;
  gap: 1.75rem;
  font-size: var(--fs-nav);
}

.global-header__nav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  text-decoration: none;
  color: var(--color-text-muted);
  font-weight: 500;
}

.global-header__nav a:hover {
  color: var(--color-text);
}

.global-header__menu {
  position: relative;
}

.global-header__menu-trigger {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  gap: 0.3rem;
  background: none;
  border: none;
  font: inherit;
  color: var(--color-text);
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

.global-header__menu-trigger .icon {
  color: var(--color-text);
}

.global-header__menu-panel {
  display: none;
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  min-width: 200px;
  /* Padding (not a gap via `top`) keeps the space between trigger and
     card part of this element's own hoverable box, so moving the pointer
     from the trigger down into the card never crosses a dead zone. */
  padding-top: var(--space-3);
}

.global-header__menu.is-open .global-header__menu-panel,
.global-header__menu:hover .global-header__menu-panel,
.global-header__menu:focus-within .global-header__menu-panel {
  display: block;
}

.global-header__menu-panel__card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  box-shadow: 0 12px 32px rgba(35, 32, 27, 0.12);
  padding: var(--space-2);
}

.global-header__menu-panel a {
  display: block;
  padding: var(--space-2) var(--space-3);
  border-radius: 4px;
  text-decoration: none;
  color: var(--color-text-muted);
  font-size: var(--fs-nav);
}

.global-header__menu-panel a:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

.global-header__menu-panel a.is-current {
  color: var(--color-accent);
  font-weight: 600;
}

.global-header__account {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.global-header__avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--color-accent-tint);
  border: 1px solid var(--color-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-accent);
}

.global-header__account .icon {
  color: var(--color-text-muted);
}

.global-header__account-link {
  display: flex;
  align-items: center;
  min-height: 44px;
  gap: 0.375rem;
  text-decoration: none;
  color: var(--color-text-muted);
  font-size: var(--fs-nav);
  font-weight: 500;
}

.global-header__account-link:hover {
  color: var(--color-text);
}

.global-header__account [data-account-name] {
  font-size: var(--fs-nav);
  font-weight: 500;
  color: var(--color-text);
}

/* The [hidden] attribute is how auth-ui.js toggles guest vs. logged-in
   state; it must win over the display:flex rules above. */
.global-header__account [hidden] {
  display: none !important;
}

/* ---- Reading-column / content primitives ---- */

.reading-column {
  max-width: var(--reading-column-width);
  margin: 0 auto;
}

.kicker {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-family: var(--font-sans);
  font-size: var(--fs-kicker);
  font-weight: 600;
  letter-spacing: 0.6px;
  color: var(--color-text-muted);
}

.kicker .icon {
  color: var(--color-text-muted);
}

.divider {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 0;
}

/* ---- Shared page shell: reading column + page-local anchor wayfinding ----
   Confirmed reused across modules (Scoring Criteria, General Knowledge) —
   see DESIGN_SYSTEM.md §3. */

.page-layout {
  display: flex;
  justify-content: center;
  gap: 3.5rem;
  width: min(calc(100% - 3rem), var(--content-shell-width));
  margin: 0 auto;
  padding: 0.5rem 0 5rem;
}

.page-layout .reading-column {
  flex: none;
  width: var(--reading-column-width);
  max-width: none;
  margin: 0;
}

.anchor-nav {
  flex: none;
  width: var(--anchor-width);
  align-self: flex-start;
  position: sticky;
  top: 50vh;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

.anchor-nav a {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--color-text-faint);
  font-size: var(--fs-anchor);
  font-weight: 400;
}

.anchor-nav__dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--color-border);
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.anchor-nav a:hover {
  color: var(--color-text-muted);
}

.anchor-nav a.is-active {
  color: var(--color-accent);
  font-size: var(--fs-anchor-active);
  font-weight: 700;
}

.anchor-nav a.is-active .anchor-nav__dot {
  width: 7px;
  height: 7px;
  background: var(--color-accent);
}

@media (max-width: 960px) {
  .page-layout {
    flex-direction: column;
    align-items: center;
    width: min(calc(100% - 2.5rem), 800px);
    padding: 1.5rem 0 4rem;
  }

  .page-layout .reading-column {
    width: 100%;
  }

  .anchor-nav {
    display: none;
  }
}

/* ---- Global header — mobile ----
   Not a redesign of mobile navigation (UI_SPEC §11 marks that as its own
   dedicated pass, not yet done); this only stops the header from
   breaking — trigger text wrapping vertically, elements overlapping —
   at narrow viewports, using the same header content and structure. */

@media (max-width: 640px) {
  .global-header {
    padding: 0 1rem;
    gap: 0.75rem;
  }

  .global-header__brand img {
    height: 26px;
  }

  .global-header__nav {
    gap: 0.75rem;
    font-size: 0.9375rem;
    min-width: 0;
  }

  .global-header__nav a,
  .global-header__menu-trigger {
    white-space: nowrap;
  }

  .global-header__menu-panel {
    position: fixed;
    left: 1rem;
    right: 1rem;
    top: var(--header-height);
    min-width: 0;
    transform: none;
  }

  .global-header__account {
    gap: 0.25rem;
  }
}

@media (max-width: 420px) {
  .global-header {
    padding: 0 0.75rem;
    gap: 0.5rem;
  }

  /* The brand logo already links home; the separate "首页" text link is
     redundant at this width and is what was colliding with the rest of
     the header — drop it here rather than shrinking everything further. */
  .global-header__nav > a[href$="index.html"] {
    display: none;
  }
}
