/* Portfolio Studio case-study layouts. Load after portfolio-studio.css, which
   supplies the tokens, base type, .section-heading and .media-caption. */

/* Opening: label, title, lead, compact facts, then the product in use. */
.case-hero { padding-top: 48px; }
.case-hero-label { margin-bottom: 16px; color: var(--color-muted); font-size: .875rem; line-height: 1.5; }
.case-title { font-size: clamp(2rem, calc(1.5rem + 2vw), 2.5rem); font-weight: 800; line-height: 1.15; letter-spacing: -.02em; }
/* Chinese titles keep normal tracking; Latin fragments inside them use .latin-display. */
.case-title:lang(zh) { letter-spacing: normal; }
/* Short English labels use the label face; Chinese labels stay in body Hei. */
.case-hero-label:lang(en), .case-meta dt:lang(en), .case-compare-label:lang(en) { font-family: var(--font-label); letter-spacing: .06em; }
.case-lead { max-width: 30em; margin-top: 16px; font-size: 1.25rem; line-height: 1.65; text-wrap: pretty; }
.case-meta { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(0, 1.4fr); gap: 24px 32px; margin: 40px 0 0; padding-top: 24px; border-top: 1px solid var(--color-border); }
.case-meta dt { color: var(--color-muted); font-size: .875rem; line-height: 1.5; }
.case-meta dd { margin: 4px 0 0; font-weight: 600; line-height: 1.6; }
.case-meta-logo { display: inline-block; width: 24px; height: 24px; margin-right: 8px; vertical-align: -6px; object-fit: contain; }
.case-meta-note { display: block; margin-top: 4px; color: var(--color-muted); font-size: .875rem; font-weight: 400; line-height: 1.5; }
.case-hero-media { margin-top: 40px; }
.case-video { width: 100%; height: auto; aspect-ratio: 16 / 9; border-radius: var(--radius-lg); background: var(--color-text); }
.case-summary { margin-top: 64px; }

/* An interactive prototype can open the case as its product visual (components/relay-prototype.js).
   The station keeps the tablet's 3:2 shape; it shrinks toward 960px on short viewports so as much of
   it as possible sits on the first screen, and grows to the column width when the viewport allows. */
.case-prototype { margin-top: 32px; }
.case-prototype-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 16px; margin-bottom: 12px; }
.case-prototype-head h2 { font-family: var(--font-display-zh); font-size: 1rem; font-weight: 700; line-height: 1.5; }
.case-prototype-head p { color: var(--color-muted); font-size: .875rem; line-height: 1.5; text-wrap: pretty; }
.case-prototype relay-prototype { --relay-station-width: min(100%, max(960px, calc((100vh - 420px) * 1.5))); }
/* The Flashcard Dictionary case opens with a simulated iPhone (components/flashcard-prototype.js);
   the phone scales down so its search screen is on the first screen, never below 700px tall
   (about 0.8× — smaller and the app's 17px text stops being comfortable to read). */
.case-prototype flashcard-prototype { --flashcard-screen-height: clamp(700px, calc(100vh - 220px), 868px); }

/* Headings, figures and item titles use the display stack. Every Chinese glyph
   they contain must be in the Noto Sans SC subset (see fonts/README.md), or it
   falls back to PingFang in the middle of a heading. */
.case-title, .case-chapter-name, .case-section h2, .case-section h3, .case-stat-value,
.case-questions li, .case-card-title, .case-steps strong, .case-principles strong,
.case-legend strong, .case-layer strong { font-family: var(--font-display-zh); }

/* Chapters group the narrative; each section is one argument with its evidence. */
.case-chapter { margin-top: 96px; }
.case-chapter-name { font-size: 1rem; font-weight: 700; }
.case-section + .case-section { margin-top: 80px; }
.case-section:not(.case-split) > * + * { margin-top: 40px; }
.case-split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 48px; align-items: start; }
.case-section h2 { font-size: clamp(1.5rem, calc(1.1rem + 1.2vw), 2rem); font-weight: 700; line-height: 1.3; text-wrap: balance; }
.case-section h3 { margin: 0; font-size: 1.25rem; font-weight: 700; line-height: 1.4; }
.case-prose { max-width: 36em; }
.case-prose > * + * { margin-top: 16px; }
.case-prose ol { padding-left: 1.5em; }
.case-prose li + li { margin-top: 8px; }
.case-prose p, .case-principles p, .case-legend p, .case-card p { text-wrap: pretty; }
.case-prose > .case-button { margin-top: 24px; }
.case-prose b { font-weight: 600; }

/* Data cards: value plus its meaning, kept neutral. */
.case-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.case-split .case-stats, .case-stats--pair { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.case-stat { padding: 24px; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); }
.case-stat-value { display: block; font-size: 2rem; font-weight: 700; line-height: 1.2; }
.case-stat-label { display: block; margin-top: 8px; color: var(--color-muted); font-size: .875rem; line-height: 1.5; }
.case-stats--large .case-stat-value { font-size: 3rem; line-height: 1.1; }

.case-media { padding: 24px; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); }
.case-media img, .case-media video { width: 100%; height: auto; }
/* Screens narrower than the column stay at their own size instead of upscaling. */
.case-media--natural img { width: auto; max-width: 100%; margin-inline: auto; }
.case-stack { display: grid; gap: 24px; }

.case-button { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 10px 20px; border: 1px solid var(--color-control-border); border-radius: var(--radius-md); font-size: .875rem; font-weight: 600; line-height: 1.5; text-decoration: none; }
.case-button:hover { border-color: var(--color-text); text-decoration: underline; text-decoration-thickness: 1px; }

.case-questions, .case-cards, .case-steps, .case-legend, .case-principles { display: grid; margin: 0; padding: 0; list-style: none; }
.case-questions .mono, .case-cards .mono, .case-steps .mono, .case-principles .mono { display: block; color: var(--color-muted); font-weight: 400; }

/* Key statements (questions, principles) sit under an ink rule. */
.case-questions { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 32px; }
.case-questions li { padding-top: 16px; border-top: 1px solid var(--color-text); font-size: 1.125rem; font-weight: 600; line-height: 1.6; }
.case-questions .mono { margin-bottom: 12px; }
.case-principles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 32px 48px; }
.case-principles li { padding-top: 16px; border-top: 1px solid var(--color-text); }
.case-principles .mono { margin-bottom: 8px; }
.case-principles strong { display: block; font-size: 1.125rem; font-weight: 700; line-height: 1.5; }
.case-principles p { margin-top: 8px; }
.case-principles--three { grid-template-columns: repeat(3, minmax(0, 1fr)); }

/* Decision cards: an assumption and what the research showed. */
.case-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.case-cards--three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.case-card { padding: 24px; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); }
.case-card .mono { margin-bottom: 12px; }
.case-card-title { font-size: 1.125rem; font-weight: 700; line-height: 1.5; }
.case-card-assume { margin-top: 12px; color: var(--color-muted); font-size: .875rem; line-height: 1.6; }
.case-card-learn { margin-top: 8px; line-height: 1.6; }
.case-card-learn b { font-weight: 600; }
/* Profile cards (personas): a labelled fact per paragraph. */
.case-card-fact { margin-top: 12px; line-height: 1.6; }
.case-card-fact b { display: block; margin-bottom: 2px; color: var(--color-muted); font-size: .875rem; font-weight: 400; }

.case-steps { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 24px; }
.case-steps--five { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.case-steps li { padding-top: 16px; border-top: 1px solid var(--color-border); }
.case-steps .mono { margin-bottom: 8px; }
.case-steps strong { display: block; font-size: 1.125rem; font-weight: 700; line-height: 1.5; }
.case-steps p { margin-top: 4px; color: var(--color-muted); font-size: .875rem; line-height: 1.6; }

/* Annotated screen: numbered markers on the image match the legend. */
.case-annotated { position: relative; max-width: 987px; margin-inline: auto; }
.case-annotated img { width: 100%; height: auto; }
.case-marker { display: inline-flex; flex: none; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: 50%; background: var(--color-text); color: var(--color-surface); font-family: var(--font-label); font-size: .8125rem; line-height: 1; }
.case-pin { position: absolute; left: var(--x); top: var(--y); width: 28px; height: 28px; transform: translate(-50%, -50%); box-shadow: 0 0 0 2px var(--color-surface); pointer-events: none; }
.case-legend { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 24px 32px; }
.case-legend li { display: grid; grid-template-columns: 24px minmax(0, 1fr); gap: 4px 12px; align-content: start; padding-top: 16px; border-top: 1px solid var(--color-border); }
.case-legend strong { font-weight: 700; line-height: 1.5; }
.case-legend p { grid-column: 2; color: var(--color-muted); font-size: .875rem; line-height: 1.6; }

/* Architecture: the agent drives the existing tagging software. */
.case-layers { display: grid; gap: 8px; }
.case-layer { padding: 20px 24px; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); text-align: center; }
.case-layer strong { display: block; font-weight: 700; }
.case-layer span { display: block; margin-top: 4px; color: var(--color-muted); font-size: .875rem; line-height: 1.6; }
.case-layer--agent { background: var(--color-text); border-color: var(--color-text); color: var(--color-bg); }
.case-layer--agent span { color: var(--color-border); }
.case-layer--base { background: transparent; border-color: var(--color-control-border); }
.case-layer-arrow { color: var(--color-muted); font-size: .875rem; line-height: 1.5; text-align: center; }

/* Before / after: same structure and scale for both states, Before first. */
.case-compare { display: grid; gap: 48px; }
.case-compare-item { display: grid; gap: 16px; padding-top: 16px; border-top: 1px solid var(--color-text); }
.case-compare-label { color: var(--color-muted); font-size: .875rem; line-height: 1.5; }
.case-compare-detail { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px 32px; align-items: center; }
.case-compare-photo { width: auto; max-width: 100%; height: auto; max-height: 240px; border-radius: var(--radius-md); }
.case-compare-detail p { text-wrap: pretty; }

/* Image sets (iterations, steps): equal frames, images contained, never cropped. */
.case-gallery { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.case-gallery figure { display: grid; gap: 8px; align-content: start; min-width: 0; }
.case-gallery .case-media { display: flex; align-items: center; justify-content: center; aspect-ratio: 4 / 3; padding: 16px; }
.case-gallery .case-media img { width: 100%; height: 100%; object-fit: contain; }
.case-gallery .media-caption { margin-top: 0; }
/* Three phone screens side by side: tall frames, the phone fills each. */
.case-gallery--phones { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.case-gallery--phones .case-media { aspect-ratio: 3 / 5; padding: 12px; }
/* Phone screenshots sit in a simulated iPhone: the frame of the Flashcard prototype
   (a 12px bezel, 58px outer and 46px screen radius and a Dynamic Island at 414px wide),
   drawn in container units so the hero's three small phones and a full-column gallery
   phone keep the same proportions. Screens are 402×874 exports at 2x; the grey corner
   fill baked into the exports sits inside the screen radius and never shows. */
.case-phone { --case-phone-screen: 402 / 874; --case-phone-outer: 1 / 2.106; container-type: inline-size; flex: none; width: 100%; margin-inline: auto; }
/* The Android export is 412×874 and draws its own camera cutout, so no island. */
.case-phone--android { --case-phone-screen: 412 / 874; --case-phone-outer: 1 / 2.056; }
.case-phone-screen { position: relative; height: 100%; padding: 3%; border-radius: 24px; background: #1c1c1e; }
.case-media .case-phone img { display: block; width: 100%; height: 100%; aspect-ratio: var(--case-phone-screen); object-fit: cover; object-position: top; border-radius: 18px; }
@supports (width: 1cqw) {
  .case-phone-screen { padding: 2.9cqw; border-radius: 14cqw; box-shadow: inset 0 0 0 .25cqw #48484a, inset 0 0 0 .75cqw #0a0a0a; }
  .case-media .case-phone img { border-radius: 11.1cqw; }
  .case-phone-screen::after { content: ""; position: absolute; top: 5.6cqw; left: 50%; width: 29.5cqw; height: 8.7cqw; transform: translateX(-50%); border-radius: 4.4cqw; background: #000; }
  .case-phone--android .case-phone-screen::after { content: none; }
}
/* In the tall gallery frames the phone fills the height; on its own it keeps the export's size. */
.case-gallery--phones .case-phone { width: auto; height: 100%; aspect-ratio: var(--case-phone-outer); }
.case-media--natural .case-phone { max-width: 440px; }
/* Three phones as the opening image, on the same 16:10 stage as the homepage cover. */
.case-media--phones { display: flex; align-items: center; justify-content: center; gap: 5%; aspect-ratio: 16 / 10; }
.case-media--phones .case-phone { width: auto; height: 90%; aspect-ratio: var(--case-phone-outer); }
/* Two photos per row (e.g. inside a split column); frames stay 4:3. */
.case-gallery--two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
/* Dashboard screens exported from the same 420×250 artboard: equal frames in one
   panel, so a sequence or a before/after pair lines up without cropping. */
.case-screens { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.case-screens--three { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.case-screens img { display: block; width: 100%; height: auto; }

/* Task flow: the rider acts on white, the vehicle on ink; the legend names both
   and each step also names its actor for screen readers. */
.case-flow { display: grid; gap: 8px; max-width: 480px; margin-inline: auto; }
.case-flow-legend { display: flex; justify-content: center; gap: 24px; margin: 0 0 8px; padding: 0; list-style: none; color: var(--color-muted); font-size: .875rem; line-height: 1.5; }
.case-flow-legend li { display: flex; align-items: center; gap: 8px; }
.case-flow-legend li::before { content: ""; width: 16px; height: 16px; border: 1px solid var(--color-control-border); border-radius: var(--radius-sm); background: var(--color-surface); }
.case-flow-legend .case-flow-key--system::before { border-color: var(--color-text); background: var(--color-text); }
.case-flow-node { padding: 10px 16px; border: 1px solid var(--color-control-border); border-radius: var(--radius-md); background: var(--color-surface); font-size: .875rem; font-weight: 600; line-height: 1.5; text-align: center; text-wrap: balance; }
.case-flow-node--system { border-color: var(--color-text); background: var(--color-text); color: var(--color-bg); }
.case-flow-node--decision { border: 1px dashed var(--color-text); background: transparent; color: var(--color-text); }
.case-flow-arrow { color: var(--color-muted); font-size: .875rem; line-height: 1.5; text-align: center; }
.case-flow-branches { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.case-flow-branch { display: grid; gap: 8px; align-content: start; }
.case-flow .media-caption { justify-content: center; margin-top: 8px; text-align: center; }

@media (max-width: 1023px) {
  .case-meta { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .case-split { grid-template-columns: minmax(0, 1fr); gap: 32px; }
  .case-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .case-steps, .case-steps--five, .case-legend, .case-gallery, .case-principles--three { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .case-cards--three { grid-template-columns: minmax(0, 1fr); }
  .case-gallery--phones { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
}

@media (max-width: 767px) {
  .case-hero { padding-top: 32px; }
  .case-lead { font-size: 1.125rem; }
  .case-meta { grid-template-columns: minmax(0, 1fr); gap: 12px; margin-top: 32px; }
  .case-meta > div { display: grid; grid-template-columns: 4em minmax(0, 1fr); column-gap: 12px; align-items: baseline; }
  .case-meta dd { margin: 0; }
  /* English labels outgrow the 4em column; they stack above their values. */
  .case-meta:lang(en) { gap: 16px; }
  .case-meta:lang(en) > div { display: block; }
  .case-meta:lang(en) dd { margin-top: 4px; }
  .case-hero-media { margin-top: 32px; }
  .case-summary { margin-top: 48px; }
  .case-prototype { margin-top: 24px; }
  .case-chapter { margin-top: 64px; }
  .case-section + .case-section { margin-top: 56px; }
  .case-section:not(.case-split) > * + * { margin-top: 32px; }
  .case-stat { padding: 16px; }
  .case-stat-value { font-size: 1.75rem; }
  .case-stats--large .case-stat-value { font-size: 2.25rem; }
  .case-media { padding: 16px; }
  .case-questions, .case-cards, .case-steps, .case-steps--five, .case-legend, .case-principles { grid-template-columns: minmax(0, 1fr); gap: 24px; }
  .case-gallery--phones { grid-template-columns: minmax(0, 1fr); }
  .case-gallery--phones .case-media { aspect-ratio: auto; }
  .case-gallery--phones .case-media > img { max-height: 520px; }
  .case-gallery--phones .case-phone { width: min(100%, 248px); height: auto; aspect-ratio: auto; }
  .case-card { padding: 16px; }
  .case-pin { width: 20px; height: 20px; font-size: .6875rem; }
  .case-compare { gap: 32px; }
  .case-compare-detail { grid-template-columns: minmax(0, 1fr); }
  .case-gallery { gap: 16px 12px; }
  .case-gallery .case-media { padding: 8px; }
  .case-screens, .case-screens--three { grid-template-columns: minmax(0, 1fr); gap: 12px; }
}
