/* =============================================================================
   Elemental — engineering notes
   Shared stylesheet for /engineering/ and /zh/engineering/.

   One file, both languages. Language-specific typography is scoped with
   html[lang="zh-Hans"] at the bottom rather than duplicated per page, so a change
   to the design can never drift between the English and Chinese pages.

   Design tokens mirror the product page so the two halves of the site match.
   ========================================================================== */

:root {
  color-scheme: light;

  --paper: #f7f3e9;
  --paper-deep: #f0ead9;
  --card: #fffdf8;
  --ink: #1a1915;
  --ink-soft: #6c6a60;
  --ink-faint: #96938a;
  --line: #e3dbc9;
  --line-soft: #ede6d7;
  --green: #2f5d4f;
  --tan: #b3854e;

  /* Latin families first, CJK families after: each script falls through to its
     own best face without needing a per-language stack. */
  --serif: ui-serif, "New York", "Iowan Old Style", "Palatino Linotype", Georgia,
    "Songti SC", "STSong", "Noto Serif CJK SC", "Source Han Serif SC", "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans SC", "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --shell: 1140px;
  --gutter: clamp(20px, 5vw, 44px);
}

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

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

img {
  max-width: 100%;
}

a {
  color: var(--green);
  text-underline-offset: 0.18em;
}

:focus-visible {
  outline: 3px solid var(--green);
  outline-offset: 4px;
  border-radius: 3px;
}

.grain {
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  opacity: 0.05;
  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.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='160' height='160' filter='url(%23n)'/%3E%3C/svg%3E");
}

.skip {
  position: absolute;
  left: -9999px;
}

.skip:focus {
  left: 16px;
  top: 16px;
  z-index: 20;
  padding: 10px 16px;
  background: var(--ink);
  color: var(--paper);
  border-radius: 8px;
  text-decoration: none;
}

.shell {
  width: min(100% - (var(--gutter) * 2), var(--shell));
  margin-inline: auto;
}

/* ---------------------------------------------------------------- top bar -- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--paper) 84%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  border-bottom: 1px solid transparent;
  transition: border-color 0.3s ease;
}

.topbar.is-stuck {
  border-bottom-color: var(--line);
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 18px;
  height: 68px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
  flex: none;
}

.brand img {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.brand span {
  font-family: var(--serif);
  font-size: 1.2rem;
}

.crumb {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  font-size: 0.9rem;
  color: var(--ink-soft);
  text-decoration: none;
}

.crumb::before {
  content: "/";
  color: var(--line);
}

.crumb:hover {
  color: var(--ink);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 7px 15px 7px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.7);
  font-size: 0.8rem;
  color: var(--ink-soft);
  white-space: nowrap;
  flex: none;
}

.pill::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--tan);
  flex: none;
  box-shadow: 0 0 0 3px rgba(179, 133, 78, 0.18);
}

.lang {
  display: flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.78rem;
  flex: none;
}

.lang a {
  padding: 3px 11px;
  border-radius: 999px;
  text-decoration: none;
  color: var(--ink-soft);
  transition: color 0.2s ease;
}

.lang a[aria-current] {
  background: var(--ink);
  color: var(--paper);
}

/* ------------------------------------------------------------------- hero -- */

.hero {
  position: relative;
  padding: clamp(48px, 7vw, 84px) 0 clamp(34px, 4vw, 50px);
  overflow: hidden;
}

.hero::before {
  content: "";
  position: absolute;
  top: -40%;
  right: -12%;
  width: 64%;
  aspect-ratio: 1;
  background: radial-gradient(circle, rgba(47, 93, 79, 0.15), rgba(47, 93, 79, 0) 62%);
  pointer-events: none;
}

.hero-inner {
  position: relative;
  max-width: 760px;
}

.app-icon {
  display: block;
  width: 62px;
  height: 62px;
  margin: 0 0 20px;
  border: 1px solid var(--line);
  border-radius: 15px;
}

.eyebrow {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--green);
  margin: 0 0 16px;
}

h1,
h2,
h3 {
  font-family: var(--serif);
  font-weight: 500;
  margin: 0;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

h1 {
  font-size: clamp(2.5rem, 6vw, 4.1rem);
  line-height: 1.02;
  margin-bottom: 18px;
}

.lede {
  font-size: clamp(1.04rem, 1.4vw, 1.18rem);
  line-height: 1.62;
  color: var(--ink-soft);
  max-width: 52ch;
  margin: 0 0 26px;
}

.status {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  margin: 0;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.status .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--tan);
  box-shadow: 0 0 0 3px rgba(179, 133, 78, 0.18);
  flex: none;
}

.status strong {
  font-weight: 650;
  color: var(--ink);
}

.status span + span::before {
  content: "·";
  margin-right: 14px;
  color: var(--line);
}

/* ------------------------------------------------------------------ facts -- */

.facts {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  margin: clamp(30px, 4vw, 44px) 0 0;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
}

.facts > div {
  padding: 16px 18px;
  background: var(--card);
}

.facts dt {
  margin: 0 0 6px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.facts dd {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.5;
}

/* ----------------------------------------------------------- layout + toc -- */

.layout {
  display: grid;
  grid-template-columns: 208px minmax(0, 1fr);
  gap: clamp(32px, 5vw, 64px);
  padding: clamp(46px, 6vw, 76px) 0 0;
  align-items: start;
}

.toc {
  position: sticky;
  top: 92px;
}

.toc-title {
  margin: 0 0 14px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.toc ol {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 2px;
  counter-reset: toc;
}

.toc a {
  display: flex;
  gap: 10px;
  padding: 7px 10px 7px 12px;
  border-left: 2px solid var(--line);
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 0.88rem;
  line-height: 1.45;
  transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.toc a:hover {
  color: var(--ink);
  background: color-mix(in srgb, var(--card) 70%, transparent);
}

.toc a[aria-current="true"] {
  border-left-color: var(--green);
  color: var(--ink);
  font-weight: 550;
}

.toc .n {
  font-variant-numeric: tabular-nums;
  color: var(--ink-faint);
  font-size: 0.78rem;
  padding-top: 2px;
  flex: none;
}

/* --------------------------------------------------------------- sections -- */

.body > section {
  padding-bottom: clamp(40px, 5vw, 62px);
  scroll-margin-top: 92px;
}

/* Belt and braces: never let a wide child push the column past the viewport. */
.toc,
.body {
  min-width: 0;
}

.body > section + section {
  padding-top: clamp(40px, 5vw, 62px);
  border-top: 1px solid var(--line-soft);
}

.sec {
  display: block;
  margin-bottom: 10px;
  font-family: var(--sans);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: var(--ink-faint);
}

h2 {
  font-size: clamp(1.5rem, 2.8vw, 2rem);
  line-height: 1.18;
  margin-bottom: 18px;
}

h3 {
  font-size: 1.08rem;
  letter-spacing: -0.01em;
  margin: 30px 0 10px;
}

.body p {
  margin: 0 0 16px;
  max-width: 68ch;
}

.body p:last-child {
  margin-bottom: 0;
}

.body ul,
.body ol {
  margin: 0 0 16px;
  padding-left: 1.3rem;
  max-width: 68ch;
}

.body li + li {
  margin-top: 9px;
}

.body strong {
  font-weight: 650;
}

.body em {
  font-style: italic;
}

code {
  font-family: var(--mono);
  font-size: 0.88em;
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--card);
}

/* ----------------------------------------------------------------- device -- */

.device {
  position: relative;
  width: 100%;
  padding: 10px;
  border-radius: 46px;
  background: linear-gradient(152deg, #55554b 0%, #191913 46%, #35352d 100%);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.35),
    0 1px 0 rgba(255, 255, 255, 0.3) inset,
    0 42px 70px -30px rgba(24, 32, 26, 0.5),
    0 14px 26px -18px rgba(24, 32, 26, 0.3);
}

.device img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 37px;
}

.device::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 46px;
  pointer-events: none;
  background: linear-gradient(118deg, rgba(255, 255, 255, 0.15), rgba(255, 255, 255, 0) 38%);
}

.rail {
  display: flex;
  gap: clamp(14px, 2vw, 22px);
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  margin: 26px 0 0;
  padding: 4px 2px 22px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
  -webkit-overflow-scrolling: touch;
}

.rail figure {
  flex: 0 0 auto;
  width: min(196px, 56vw);
  margin: 0;
  scroll-snap-align: center;
}

.rail figcaption {
  margin-top: 13px;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--ink-faint);
  text-align: center;
}

/* ------------------------------------------------------------------ steps -- */

.steps {
  counter-reset: step;
  list-style: none;
  margin: 22px 0 0;
  padding: 0;
  max-width: 68ch;
}

.steps li {
  position: relative;
  margin: 0;
  padding: 0 0 18px 44px;
  border-left: 1px solid var(--line);
}

.steps li:last-child {
  padding-bottom: 0;
  border-left-color: transparent;
}

.steps li::before {
  counter-increment: step;
  content: counter(step, decimal-leading-zero);
  position: absolute;
  left: -19px;
  top: 0;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--card);
  color: var(--green);
  font-size: 0.72rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.steps b {
  display: block;
  font-weight: 650;
  margin-bottom: 2px;
}

.steps span {
  color: var(--ink-soft);
  font-size: 0.95rem;
}

/* ---------------------------------------------------------------- metrics -- */

.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  margin: 24px 0 4px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
}

.metrics > div {
  padding: 20px 18px;
  background: var(--card);
}

.metrics b {
  display: block;
  font-family: var(--serif);
  font-size: clamp(1.9rem, 3.6vw, 2.6rem);
  font-weight: 500;
  line-height: 1;
  color: var(--green);
  font-variant-numeric: tabular-nums;
}

.metrics span {
  display: block;
  margin-top: 8px;
  font-size: 0.84rem;
  line-height: 1.45;
  color: var(--ink-soft);
}

/* ------------------------------------------------------------------- note -- */

.note {
  margin: 24px 0 0;
  padding: 18px 22px;
  border-left: 3px solid var(--green);
  background: color-mix(in srgb, var(--green) 6%, transparent);
  max-width: 68ch;
}

.note p {
  margin: 0;
}

/* ------------------------------------------------------------ boundaries -- */

.boundaries {
  margin-top: 18px;
  max-width: none;
  columns: 2;
  column-gap: 36px;
  padding-left: 1.2rem;
}

.boundaries li {
  break-inside: avoid;
  font-size: 0.96rem;
}

/* ----------------------------------------------------------------- links -- */

.links {
  list-style: none;
  margin: 18px 0 0;
  padding: 0;
  display: grid;
  gap: 8px;
  font-size: 0.95rem;
}

.page-footer {
  margin-top: clamp(48px, 6vw, 72px);
  padding: 26px 0 54px;
  border-top: 1px solid var(--line);
  font-size: 0.86rem;
  color: var(--ink-faint);
  display: grid;
  gap: 8px;
}

/* ----------------------------------------------------------------- reveal -- */

.js .reveal {
  opacity: 0;
  transform: translateY(18px);
  transition:
    opacity 0.7s var(--ease) var(--d, 0ms),
    transform 0.7s var(--ease) var(--d, 0ms);
}

.js .reveal.is-visible {
  opacity: 1;
  transform: none;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .js .reveal {
    opacity: 1;
    transform: none;
    transition: none;
  }
}

/* =========================================================================
   Chinese typography.
   CJK glyphs are denser than Latin at the same size, and Chinese has no true
   italic form, so sizes, leading, tracking and emphasis all need adjusting.
   ========================================================================= */

html[lang="zh-Hans"] body {
  font-size: 16.5px;
  line-height: 1.85;
}

html[lang="zh-Hans"] h1,
html[lang="zh-Hans"] h2,
html[lang="zh-Hans"] h3 {
  letter-spacing: 0;
}

html[lang="zh-Hans"] h1 {
  font-size: clamp(2rem, 4.6vw, 3.1rem);
  line-height: 1.2;
}

html[lang="zh-Hans"] h2 {
  font-size: clamp(1.34rem, 2.5vw, 1.72rem);
  line-height: 1.36;
}

html[lang="zh-Hans"] .lede {
  max-width: 34em;
}

html[lang="zh-Hans"] .body p,
html[lang="zh-Hans"] .body ul,
html[lang="zh-Hans"] .body ol,
html[lang="zh-Hans"] .steps,
html[lang="zh-Hans"] .note {
  max-width: 40em;
}

html[lang="zh-Hans"] .boundaries {
  max-width: none;
}

/* No synthesised obliques on CJK glyphs. */
html[lang="zh-Hans"] .body em {
  font-style: normal;
  font-weight: 650;
  color: var(--green);
}

html[lang="zh-Hans"] .eyebrow,
html[lang="zh-Hans"] .toc-title,
html[lang="zh-Hans"] .facts dt,
html[lang="zh-Hans"] .sec {
  text-transform: none;
  letter-spacing: 0.2em;
}

/* --------------------------------------------------------------- narrow -- */

@media (max-width: 1000px) {
  /* minmax(0, 1fr), not 1fr: a bare 1fr track has an automatic minimum of
     min-content, and the screenshot rail's min-content is its full flex row
     (~1040px). That would blow the whole column past the viewport on a phone. */
  .layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 34px;
  }

  .toc {
    position: static;
    padding: 20px 22px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--card);
  }

  .toc ol {
    grid-template-columns: repeat(2, 1fr);
    gap: 2px 20px;
  }

  .toc a {
    border-left: 0;
    padding: 6px 0;
  }

  .toc a[aria-current="true"] {
    color: var(--green);
  }

  .facts,
  .metrics {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 720px) {
  .crumb {
    display: none;
  }

  .boundaries {
    columns: 1;
  }
}

@media (max-width: 620px) {
  .nav-links-hide,
  .topbar .pill {
    display: none;
  }

  .topbar-inner {
    justify-content: space-between;
  }

  .facts,
  .metrics,
  .toc ol {
    grid-template-columns: 1fr;
  }

  .status {
    display: grid;
    gap: 4px;
  }

  .status span + span::before {
    content: none;
  }
}

/* ================================================================= print ==
   A technical case study is exactly the kind of page a reviewer prints or
   saves as PDF, so the print path is designed rather than left to the browser.
   ========================================================================= */

@media print {
  :root {
    --paper: #fff;
    --card: #fff;
    --paper-deep: #fff;
  }

  body {
    background: #fff;
    font-size: 10.5pt;
    line-height: 1.5;
  }

  .grain,
  .topbar,
  .toc,
  .skip,
  .rail::-webkit-scrollbar {
    display: none !important;
  }

  .shell {
    width: 100%;
    max-width: none;
  }

  .layout {
    display: block;
    padding-top: 20pt;
  }

  .js .reveal {
    opacity: 1 !important;
    transform: none !important;
  }

  .hero {
    padding: 0 0 14pt;
  }

  .hero::before {
    display: none;
  }

  .facts,
  .metrics {
    border-color: #bbb;
    background: #bbb;
  }

  .facts > div,
  .metrics > div {
    border: 0;
  }

  section,
  .steps li,
  .rail figure {
    break-inside: avoid;
  }

  .body > section + section {
    padding-top: 16pt;
    border-top: 1px solid #ccc;
  }

  .device {
    background: #222;
    box-shadow: none;
  }

  /* Three across rather than five: at five columns each frame is barely 1.5in
     wide on Letter, which is too small to read once printed. */
  .rail {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12pt;
    overflow: visible;
    padding: 0;
    margin-top: 12pt;
  }

  .rail figure {
    width: auto;
  }

  a {
    color: #000;
  }

  .body a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: 0.85em;
    color: #555;
  }
}
