/* === Apple Design System — Core CSS ===
 * Last verified: 2026-04-19
 * Docs: ../references/design-tokens.md
 */

/* ---------- Section A: Tokens ---------- */
:root {
  /* Colors */
  --apple-bg: #FFFFFF;
  --apple-bg-alt: #F5F5F7;
  --apple-bg-dark: #000000;
  --apple-text: #1D1D1F;
  --apple-text-secondary: #6E6E73;
  --apple-text-on-dark: #F5F5F7;
  /* 2026-08-14: was #0071E3 — 4.31:1 on --apple-bg-alt, 0.19 under AA; this
   * exact gap has sat in known-bugs §3.2 since it was measured. #0066CC (the
   * blue apple.com itself uses for links) reads 5.11 there; Euclidean distance
   * to the old value is 25, inside the brand gate's TOL 55. */
  --apple-link: #0066CC;
  --apple-link-hover: #0071E3;   /* old base becomes the hover — still passes on white */
  --apple-divider: #D2D2D7;
  --apple-bg-nav: rgba(251, 251, 253, 0.72);
  --apple-system-green: #34C759;
  --apple-system-orange: #FF9500;
  --apple-system-red: #FF3B30;

  /* Fonts */
  --font-display: "SF Pro Display", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --font-text: "SF Pro Text", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SF Mono", ui-monospace, Menlo, Monaco, "Cascadia Mono", monospace;

  /* Spacing (4px grid) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;
  --space-9: 80px;
  --space-10: 120px;

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-pill: 9999px;

  /* Shadows */
  --shadow-product: 0 20px 60px -20px rgba(0, 0, 0, 0.15);
  --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.04);

  /* Motion */
  --ease-apple: cubic-bezier(0.42, 0, 0.58, 1);
  --ease-apple-out: cubic-bezier(0.25, 1, 0.5, 1);
  --duration-sm: 240ms;
  --duration-md: 400ms;
  --duration-lg: 700ms;
}

/* ---------- Section B: Reset ---------- */
* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-text);
  font-size: 17px;
  line-height: 1.47;
  color: var(--apple-text);
  background: var(--apple-bg);
  -webkit-font-smoothing: antialiased;
}

/* ---------- Section C: Typography ---------- */
h1,
h2,
h3,
h4,
h5 {
  font-family: var(--font-display);
  margin: 0;
}

h1 {
  font-size: 64px;
  line-height: 1.05;
  font-weight: 700;
  letter-spacing: -0.015em;
}

h2 {
  font-size: 48px;
  line-height: 1.08;
  font-weight: 600;
  letter-spacing: -0.01em;
}

h3 {
  font-size: 28px;
  line-height: 1.14;
  font-weight: 500;
  letter-spacing: -0.005em;
}

h4 {
  font-size: 21px;
  line-height: 1.38;
  font-weight: 500;
}

p {
  margin: 0 0 var(--space-4);
}

small,
.apple-caption {
  font-size: 12px;
  line-height: 1.33;
  color: var(--apple-text-secondary);
}

.apple-lead {
  font-size: 21px;
  line-height: 1.38;
}

/* ---------- Section D: Link & Button ---------- */
.apple-link {
  color: var(--apple-link);
  text-decoration: underline;
  text-underline-offset: 0.2em;
  text-decoration-thickness: 1px;
  transition: color var(--duration-sm) var(--ease-apple-out);
}

.apple-link:hover {
  color: var(--apple-link-hover);
}

.apple-link::after {
  content: " \203A";
}

.apple-link--no-arrow::after {
  content: none;
}

/* .apple-button 仅供 Buy/Add to Bag/付费 CTA 用；其它一律 .apple-link */
.apple-button {
  display: inline-block;
  padding: 8px 16px;
  border-radius: var(--radius-pill);
  background: var(--apple-link);
  color: var(--apple-bg);
  font-size: 14px;
  font-weight: 400;
  text-decoration: none;
  transition: background var(--duration-sm) var(--ease-apple-out),
    transform 100ms var(--ease-apple-out);
}

.apple-button:hover {
  background: var(--apple-link-hover);
}

/* 反馈在按下瞬间,不在松开 —— 见 references/motion.md 按压反馈 */
.apple-button:active {
  transform: scale(0.97);
}

.apple-button--secondary {
  background: transparent;
  color: var(--apple-link);
  border: 1px solid var(--apple-link);
}

/* ---------- Section E: Layout ---------- */
.apple-container {
  max-width: 980px;
  margin: 0 auto;
  padding: 0 24px;
}

.apple-container--wide {
  max-width: 1068px;
}

.apple-container--hero {
  max-width: 1280px;
}

.apple-section {
  padding-block: var(--space-9);
}

.apple-section--alt {
  background: var(--apple-bg-alt);
}

.apple-section--dark {
  background: var(--apple-bg-dark);
  color: var(--apple-text-on-dark);
}

.apple-section--dark h1,
.apple-section--dark h2,
.apple-section--dark h3 {
  color: var(--apple-text-on-dark);
}

.apple-hero {
  text-align: center;
  padding-block: var(--space-10);
}

.apple-card {
  background: var(--apple-bg);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  padding: var(--space-5);
}

/* ---------- Section F: Stat ---------- */
.apple-stat {
  text-align: center;
}

.apple-stat-number {
  display: block;
  font-family: var(--font-display);
  font-size: 120px;
  line-height: 1;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.apple-stat-label {
  display: block;
  font-size: 17px;
  color: var(--apple-text-secondary);
  margin-top: var(--space-4);
  max-width: 240px;
  margin-inline: auto;
}

/* ---------- Section G: Nav ---------- */
.apple-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  height: 44px;
  background: var(--apple-bg-nav);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--apple-divider);
}

/* Nav container is 1024px — Apple's actual nav chrome width, narrower than the 1068 content wide container */
.apple-nav-inner {
  max-width: 1024px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
}

.apple-nav a {
  color: var(--apple-text);
  font-size: 12px;
  text-decoration: none;
  margin-right: var(--space-6);
  opacity: 0.8;
  transition: opacity var(--duration-sm);
}

.apple-nav a:hover {
  opacity: 1;
}

/* nav-cascade fix: `.apple-nav a` color + opacity above out-specifies
   `.apple-button` color, dropping nav-CTA buttons to dark text on blue
   at 0.8 opacity (rendered ~3.58:1, fail AA). Mirror the ember/sage
   cross-skill fix to keep the white-on-blue CTA at full opacity. */
.apple-nav a.apple-button { color: #ffffff; opacity: 1; }
.apple-nav a.apple-button:hover { color: #ffffff; opacity: 1; }

/* ---------- Section H: Footer ---------- */
.apple-footer {
  background: var(--apple-bg-alt);
  border-top: 1px solid var(--apple-divider);
  padding-block: var(--space-7);
  font-size: 12px;
  color: var(--apple-text-secondary);
}

.apple-footer-grid {
  max-width: 980px;
  margin: 0 auto;
  padding: 0 24px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--space-6);
}

.apple-footer-group h5 {
  font-size: 12px;
  font-weight: 600;
  color: var(--apple-text);
  margin-bottom: var(--space-3);
}

.apple-footer-group a {
  display: block;
  color: var(--apple-text-secondary);
  text-decoration: none;
  margin-bottom: var(--space-2);
}

.apple-footer-group a:hover {
  text-decoration: underline;
}

.apple-footer-legal {
  max-width: 980px;
  margin: var(--space-6) auto 0;
  padding: var(--space-5) 0 0;
  border-top: 1px solid var(--apple-divider);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-4);
}

/* ---------- Section I: Badge / Quote / Divider / Banner ---------- */
.apple-badge {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--apple-text-secondary);
}

.apple-quote {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 500;
  line-height: 1.3;
  letter-spacing: -0.005em;
  max-width: 720px;
  margin: var(--space-7) auto;
  text-align: center;
}

.apple-quote-cite {
  display: block;
  font-size: 14px;
  color: var(--apple-text-secondary);
  text-align: center;
  margin-top: var(--space-4);
}

.apple-divider {
  border: 0;
  height: 1px;
  background: var(--apple-divider);
  margin: var(--space-7) 0;
}

.apple-banner {
  height: 44px;
  background: var(--apple-bg-alt);
  border-bottom: 1px solid var(--apple-divider);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}

/* ---------- Section J: Form controls ---------- */
.apple-input,
.apple-select,
.apple-textarea {
  width: 100%;
  background: var(--apple-bg-alt);
  border: 1px solid var(--apple-divider);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-family: var(--font-text);
  font-size: 14px;
  color: var(--apple-text);
}

.apple-input:focus,
.apple-select:focus,
.apple-textarea:focus {
  outline: 2px solid var(--apple-link);
  outline-offset: 0;
  border-color: transparent;
}

.apple-radio,
.apple-checkbox {
  accent-color: var(--apple-link);
  width: 18px;
  height: 18px;
}

.apple-label {
  display: block;
  font-size: 13px;
  color: var(--apple-text-secondary);
  margin-bottom: var(--space-2);
}

.apple-toggle {
  appearance: none;
  width: 51px;
  height: 31px;
  background: var(--apple-divider);
  border-radius: var(--radius-pill);
  position: relative;
  cursor: pointer;
  transition: background var(--duration-sm);
}

.apple-toggle::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: var(--apple-bg);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  transition: transform var(--duration-sm) var(--ease-apple-out);
}

.apple-toggle:checked {
  background: var(--apple-system-green);
}

.apple-toggle:checked::before {
  /* 51 (track) − 27 (knob) − 2×2 (padding) = 20px travel */
  transform: translateX(20px);
}

/* ---------- Section K: Option cards ---------- */
.apple-swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--apple-divider);
  cursor: pointer;
}

.apple-swatch--selected {
  border: 2px solid var(--apple-text);
  padding: 2px;
  background-clip: content-box;
}

.apple-option-card {
  border: 1px solid var(--apple-divider);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  cursor: pointer;
  transition: border-color var(--duration-sm);
}

.apple-option-card--selected {
  border: 2px solid var(--apple-text);
}

.apple-segmented {
  display: inline-flex;
  border: 1px solid var(--apple-divider);
  border-radius: var(--radius-pill);
  padding: 2px;
}

.apple-segmented button {
  background: transparent;
  border: 0;
  padding: 6px 16px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  cursor: pointer;
}

.apple-segmented button.is-active {
  background: var(--apple-text);
  color: var(--apple-bg);
}

/* ---------- Section L: Tabs / Carousel / Video / Details / Admonition / Code ---------- */
.apple-tabs {
  display: flex;
  gap: var(--space-6);
  border-bottom: 1px solid var(--apple-divider);
}

.apple-tab {
  background: transparent;
  border: 0;
  padding: var(--space-3) 0;
  font-size: 14px;
  color: var(--apple-text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color var(--duration-sm), border-bottom-color var(--duration-sm);
}

.apple-tab.is-active {
  color: var(--apple-text);
  border-bottom-color: var(--apple-link);
}

.apple-carousel {
  position: relative;
  overflow: hidden;
}

.apple-carousel-viewport {
  display: flex;
  transition: transform var(--duration-md) var(--ease-apple-out);
}

.apple-carousel-dots {
  display: flex;
  gap: var(--space-2);
  justify-content: center;
}

.apple-carousel-dots button {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--apple-divider);
  border: 0;
  cursor: pointer;
}

.apple-carousel-dots button.is-active {
  background: var(--apple-text);
}

.apple-video {
  width: 100%;
  border-radius: var(--radius-md);
}

.apple-video-play {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--duration-sm) var(--ease-apple-out);
}

.apple-video-play:hover {
  transform: scale(1.08);
}

.apple-details {
  border-bottom: 1px solid var(--apple-divider);
  padding: var(--space-4) 0;
}

.apple-details summary {
  cursor: pointer;
  font-size: 17px;
  list-style: none;
  display: flex;
  justify-content: space-between;
}

.apple-details summary::after {
  content: '+';
  font-weight: 300;
  font-size: 24px;
  color: var(--apple-text-secondary);
}

.apple-details[open] summary::after {
  content: '−';
}

.apple-admonition {
  background: var(--apple-bg-alt);
  border-left: 4px solid var(--apple-link);
  padding: var(--space-4);
  margin: var(--space-5) 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.apple-admonition--warning {
  border-left-color: var(--apple-system-orange);
}

.apple-admonition--success {
  border-left-color: var(--apple-system-green);
}

.apple-admonition--info {
  border-left-color: var(--apple-link);
}

.apple-admonition--danger {
  border-left-color: var(--apple-system-red);
}

.apple-code,
pre.apple-code {
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--apple-bg-alt);
  border-radius: var(--radius-md);
  padding: var(--space-5);
  overflow-x: auto;
}

code {
  font-family: var(--font-mono);
  font-size: 0.93em;
  background: var(--apple-bg-alt);
  padding: 2px 4px;
  border-radius: 2px;
}

kbd {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--apple-bg);
  border: 1px solid var(--apple-divider);
  padding: 2px 6px;
  border-radius: 4px;
}

mark {
  background: rgba(0, 113, 227, 0.15);
}

/* Breadcrumbs */
.apple-breadcrumbs {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  font-size: 12px;
  color: var(--apple-text-secondary);
}

.apple-breadcrumbs li::after {
  content: ' \203A';
  margin-left: var(--space-2);
  color: var(--apple-divider);
}

.apple-breadcrumbs li:last-child::after {
  content: none;
}

.apple-breadcrumbs a {
  color: inherit;
  text-decoration: none;
}

.apple-breadcrumbs a:hover {
  text-decoration: underline;
}

/* Search */
.apple-search-trigger {
  background: transparent;
  border: 0;
  cursor: pointer;
  padding: 0;
  color: var(--apple-text);
}

.apple-search-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.97);
  -webkit-backdrop-filter: blur(20px);
  backdrop-filter: blur(20px);
  z-index: 200;
  padding: var(--space-8) var(--space-5);
}

.apple-search-overlay input {
  display: block;
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--apple-divider);
  font-size: 40px;
  font-family: var(--font-display);
  padding: var(--space-4) 0;
  outline: none;
}

/* Table (use sparingly — Apple prefers parallel sections for specs) */
.apple-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-text);
  font-size: 14px;
}

.apple-table th {
  text-align: left;
  padding: 12px 16px;
  font-weight: 600;
  color: var(--apple-text);
  border-bottom: 1px solid var(--apple-divider);
}

.apple-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--apple-divider);
}

/* Reveal target for IntersectionObserver-driven entrance */
.apple-reveal {
  opacity: 0;
  transform: translateY(24px);
  transition:
    opacity var(--duration-lg) var(--ease-apple-out),
    transform var(--duration-lg) var(--ease-apple-out);
}

.apple-reveal.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* ---------- Section M: Responsive + a11y ----------
 * Phone layout. The card grids that overflow at 375px live in each page's
 * embedded <style> (.feat-row, .use-grid, …); the collapse rules below
 * override them at equal specificity via !important, so the rollout is
 * CSS-only and reaches every page that links this sheet. Genuinely wide figures
 * pan via an opt-in .apple-scroll wrapper (strategy A); hero product mocks
 * scale to fit so the whole window stays visible. */
@media (max-width: 734px) {
  /* Type — fluid headings, 16px reading floor. !important so the per-page
     inline font-sizes (style="font-size:96px" on hero headings) scale down
     too — without it an inline size wins over this media query and overflows. */
  h1 { font-size: clamp(34px, 9vw, 40px) !important; line-height: 1.12; }
  h2 { font-size: clamp(27px, 7vw, 32px) !important; }
  h3 { font-size: 21px !important; }
  body { font-size: 16px; }
  .apple-stat-number { font-size: clamp(48px, 15vw, 72px); }

  /* Sections + containers breathe less on a phone */
  .apple-section { padding-block: var(--space-7); }
  .apple-container, .apple-container--wide, .apple-container--hero {
    padding-left: var(--space-4);
    padding-right: var(--space-4);
  }

  /* Collapse page-local multi-column grids so nothing scrolls sideways. The
     full class list is generated from every page's embedded <style>; a class
     absent from a given page is simply inert. Content & label/value rows go to
     one column; compact numeric strips stay two-up. */
  .feat-grid, .feat-row, .use-grid, .use-grid3, .use-tile, .tier-grid, .ref-grid,
  .member-grid, .team-grid, .canon-row, .test-row, .channel-row, .chord-grid,
  .scenarios, .scenario, .post-grid, .pd-sibling__grid, .pd-use__grid,
  .pd-sibling__row, .pd-spec__row, .faq-group, .faq-sum, .log-entry, .log-month,
  .detail-row, .spec-row, .kbd-row, .lineup-row, .lineup-grid, .limit-item,
  .craft-rule, .ship-rule, .quickstart, .palette-split, .overlap-grid, .two-col,
  .featured, .cards-2, .comp-grid, .side-col, .support-grid, .pillar-spine,
  .stat-strip, .glance-strip, .giant-stats, .cadence-stats, .pd-glance,
  .stat-trio, .faq-stats, .kpi-row, .exec-strip, .status-grid, .pagination {
    grid-template-columns: 1fr !important;
  }
  /* inline splits (style="grid-template-columns:2fr 3fr") collapse too */
  [style*="grid-template-columns"] { grid-template-columns: 1fr !important; }
  .apple-footer-grid { grid-template-columns: repeat(2, 1fr); }
  /* children must shrink, or their min-content re-widens the row */
  [class*="grid"] > *, [class*="row"] > *, [class*="strip"] > *,
  [class*="stat"] > *, [class*="glance"] > *, [class*="scenario"] > * { min-width: 0; }
  /* long unbreakable tokens (file paths in <code>, URLs) wrap, not overflow */
  code, kbd { overflow-wrap: anywhere; }

  /* Nav links wrap instead of overflowing (no JS burger on this skill) */
  .apple-nav-inner, .apple-nav-inner > div { flex-wrap: wrap; gap: var(--space-3); row-gap: var(--space-2); }

  /* Opt-in pan wrapper for genuinely wide figures (strategy A): wrap the <svg>
     in <div class="apple-scroll"> to keep a readable width and pan on a phone.
     Hero product mocks scale-to-fit instead — the whole window stays visible,
     and their own overflow:hidden (rounded corners) would fight a pan anyway. */
  .apple-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .apple-scroll > svg { min-width: 720px; }

  /* Wide tables + code blocks pan inside their own box; table columns stay
     aligned (min-width:max-content keeps display:table, parent does the scroll) */
  :is(div, section, figure):has(> table) {
    overflow-x: auto; -webkit-overflow-scrolling: touch;
  }
  .cmp-table { min-width: -webkit-max-content; min-width: max-content; }
  .apple-code { overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

@media (min-width: 735px) and (max-width: 1068px) {
  h1 {
    font-size: 56px;
  }
  .apple-footer-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.apple-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 2px solid var(--apple-link);
  outline-offset: 2px;
  border-radius: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

/* 只管 CSS;JS spring / rAF 动画必须自查 matchMedia,见 references/motion.md */

@media (prefers-reduced-transparency: reduce) {
  .apple-nav,
  .apple-search-overlay {
    background: var(--apple-bg);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
}
