/* The Rucy page: one typeface, one size, two weights, and the page's two inks. */

:root {
  color-scheme: dark;
  --bg: #151516;
  --fg: #e8e8ea;
  --dim: #8f8f96;
  /* Apple's Messages blue, a shade deeper than the app's own (#007aff) so that white 12px
     text on it keeps a 4.5:1 contrast. The same in both themes. Used for Rucy's side of
     the sample conversation and for the "Get Rucy" buttons that lead out of it. */
  --imessage: #0071e3;
  --on-imessage: #fdfcfc;
  /* Renders in Berkeley Mono where it is installed; web font files are not wired in yet. */
  --mono: "Berkeley Mono", "BerkeleyMono", ui-monospace, "SF Mono", SFMono-Regular, Menlo, Monaco,
    "Cascadia Mono", Consolas, "Liberation Mono", monospace;
}

/* Light theme. The page follows the system setting until the reader uses the toggle,
   which sets data-theme on <html> (see theme.js) and then wins in both directions. */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f7f7f8;
    --fg: #19191b;
    --dim: #6e6e76;
  }
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f7f7f8;
  --fg: #19191b;
  --dim: #6e6e76;
}

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

html {
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 40px;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 20px;
  font-weight: 400;
  font-variant-ligatures: none;
}

@media (max-width: 560px) {
  body {
    padding: 24px 16px;
  }
}

::selection {
  background: var(--fg);
  color: var(--bg);
}

.page {
  max-width: 480px;
}

.masthead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 2ch;
  margin: 0 0 100px;
  text-transform: uppercase;
  line-height: 18px;
}

/* Theme toggle: a bracketed word, like the rest of the page's syntax. */
.theme-toggle {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  line-height: inherit;
  text-transform: inherit;
  cursor: pointer;
}

.theme-toggle:hover {
  background: var(--fg);
  color: var(--bg);
}

.theme-toggle:focus-visible {
  outline: 1px solid var(--fg);
  outline-offset: 2px;
}

.masthead p {
  margin: 0;
}

/* A one-line page header written as a sentence, so it keeps its own capitals. */
.masthead__title {
  text-transform: none;
}

h1,
h2 {
  margin: 20px 0;
  font-size: inherit;
  line-height: inherit;
  font-weight: 700;
  text-transform: uppercase;
}

p {
  margin: 20px 0;
}

.mark {
  color: var(--dim);
  font-weight: 400;
}

ul {
  margin: 20px 0;
  padding: 0;
  list-style: none;
}

/* "- " hangs in the margin of each item so wrapped lines align with the text. */
li {
  padding-left: 2ch;
  text-indent: -2ch;
  overflow-wrap: anywhere;
}

a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
}

a:hover {
  background: var(--fg);
  color: var(--bg);
  text-decoration: none;
}

a:focus-visible {
  outline: 1px solid var(--fg);
  outline-offset: 2px;
}

/* The brand's own inks. No greys: text is white on black, and every mark takes the
   second ink. */

html.brand {
  --bg: #090808;
  --fg: #fdfcfc;
  --olive: #9e9534;
  --red: #d83241;
  --rubric: var(--olive);
  --swirl: var(--olive);
  /* Carts that come back, in the Rucy story. Not a brand-kit colour: the story needs the
     opposite of the red. Lighter on black, darker on white, for the same weight as the red. */
  --recovered: #3fbf6f;
}

/* The light theme is set on paper, not on white: a warm off-white page and a soft black
   ink, in place of the brand's white and black. That lowers the contrast between them
   from about 20:1 to about 15:1 and takes the glare off the large areas. */
@media (prefers-color-scheme: light) {
  html.brand:not([data-theme="dark"]) {
    --bg: #f5f3ee;
    --fg: #1d1b18;
    --rubric: var(--red);
    /* Olive is under 3:1 on the paper, too faint for thin characters. There the swirl is
       printed in olive shaded with the brand black (60% olive, 40% #090808): about 6:1. */
    --swirl: #625d22;
    --recovered: #1f7a43;
  }
}

html.brand[data-theme="light"] {
  --bg: #f5f3ee;
  --fg: #1d1b18;
  --rubric: var(--red);
  --swirl: #625d22; /* shaded olive, see the note above */
  --recovered: #1f7a43;
}

/* On the Rucy page the accent ink is the Messages blue in both themes, in place of the
   olive and red: the marks and ornaments, selected text, a link under the pointer, and
   the mark at the foot of the page all take it. The animation keeps its own colours. */
html.brand[data-variant="rucy"]:root {
  --rubric: var(--imessage);
}

/* On the Rucy page's paper, text on the blue is the page's own paper, not a second
   white, and the conversation's grey is warmed to sit on it. */
@media (prefers-color-scheme: light) {
  html.brand[data-variant="rucy"]:root:not([data-theme="dark"]) {
    --on-imessage: #f5f3ee;
  }

  html.brand[data-variant="rucy"]:root:not([data-theme="dark"]) .thread {
    --bubble: #e7e3db;
  }
}

html.brand[data-variant="rucy"]:root[data-theme="light"] {
  --on-imessage: #f5f3ee;
}

html.brand[data-variant="rucy"]:root[data-theme="light"] .thread {
  --bubble: #e7e3db;
}

/* The ring round the hole is drawn in the brand's own olive in both themes. The shaded
   olive above is for thin characters on white; the ring is solid blocks beside a black
   disc and reads without it. */
html.brand[data-variant="rucy"] .story {
  --swirl: var(--olive);
}

.brand .mark,
.brand .syn {
  color: var(--rubric);
}

/* Selected text takes the cursor's ink: olive on a dark page, red on a light one. */
.brand ::selection {
  background: var(--rubric);
  color: var(--bg);
}

.brand a:hover,
.brand .theme-toggle:hover {
  background: var(--rubric);
  color: var(--bg);
}

.brand a:hover .syn,
.brand .theme-toggle:hover .syn {
  color: inherit;
}

/* The mark signs the page off. Drawn as a mask so it takes the rubric ink. */
.colophon {
  margin: 60px 0 0;
}

.colophon__mark {
  display: block;
  width: 34px;
  height: 24px;
  background: var(--rubric);
  -webkit-mask: url("logos/mark-olive.png") left center / contain no-repeat;
  mask: url("logos/mark-olive.png") left center / contain no-repeat;
}

/* A name set beside the mark, on its centre line. */
.colophon--named {
  display: flex;
  align-items: center;
  gap: 1ch;
}

/* The story: a stage where the cart animation plays as the page scrolls. The animation
   itself comes from its own script; the captions are ordinary text here so they follow
   the type and theme. */

/* Headings here are highlighted runs instead of lines with # marks: the page's two inks
   swapped, the same 18px block as the caption over the animation. Each line of a wrapped
   heading gets its own block, with a 2px seam between them. */
.hl {
  padding: 2px 10px;
  background: var(--fg);
  color: var(--bg);
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

/* List markers: a dagger and a space, two characters wide, which is what the list's
   hanging indent allows. */
.bullet::before {
  content: "\2020\0020";
}

/* A heading at the caption's size: the same block, 18px type in a 26px line, and 16px in
   22px on a phone, where the caption is set smaller too. */
.hl--big {
  display: inline-block;
  padding: 0 12px;
  font-size: 18px;
  line-height: 26px;
}

@media (max-width: 560px) {
  .hl--big {
    padding: 0 10px;
    font-size: 16px;
    line-height: 22px;
  }
}

.beat > :first-child {
  margin-top: 0;
}

.story {
  display: none;
}

@media (min-width: 1120px) {
  /* Each beat of the story gets most of a screen of scroll, but only while the stage is
     there to fill it. On a narrower window, or when the animation could not start, the
     beats close up into ordinary sections. */
  .beat {
    min-height: 75vh;
  }

  .no-story .beat {
    min-height: 0;
  }

  .story {
    display: block;
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: 600px;
    overflow: hidden;
  }

  .story__stage {
    position: absolute;
    inset: 0;
  }

  .story__stage canvas {
    display: block;
    width: 100%;
    height: 100%;
  }

  /* Along the top of the stage, like a title over the picture. The animation keeps the
     top 80px clear for them. The counter is 18px tall, level with the masthead's first
     line; the caption is set larger, below. */
  .story__caption,
  .story__count {
    position: absolute;
    top: 40px;
    margin: 0;
    line-height: 18px;
    text-transform: uppercase;
  }

  /* The title of the picture, half as large again as the page's type. It is raised 4px
     so its taller block stays centred on the line of the counter and button beside it,
     and it stops short of them: a long caption wraps to a second line instead. */
  .story__caption {
    top: 36px;
    left: 40px;
    max-width: calc(100% - 279px);
    padding: 0 12px;
    background: var(--fg);
    color: var(--bg);
    font-size: 18px;
    line-height: 26px;
    font-weight: 700;
  }

  .story__caption:empty {
    display: none;
  }

  .story__count {
    right: 40px;
  }
}

/* ---- "Column" layout (?layout=column; rucy-page.js sets .is-column) ----
 * One centred column at every window width, and no text column beside the picture. From
 * the top of the column down: the caption, the current beat's few lines of text under
 * it, then the animation. Text is set from the column's left edge. The stage holds the
 * window for as long as the five beats take; their sections are emptied by the script
 * and stay behind only as lengths of scroll. When they end the stage is carried off and
 * the rest of the page follows in the same column.
 */
.beat__context > :first-child,
.context__item > :first-child {
  margin-top: 0;
}

html.is-column {
  --gutter: 40px; /* the page's side margin: body padding in this stylesheet */
  /* The column: three quarters as wide as the window is tall, which is the shape the
     animation is drawn for, but no narrower than the text needs and no wider than fits. */
  --col: min(max(480px, 75vh), calc(100vw - 2 * var(--gutter)));
  --head-top: 36px; /* where the caption sits in the stage */
  --head-line: 26px; /* the height of one line of the caption, and of the counter and button */
  --row-gap: 12px; /* the space under the caption and under the counter, the same for both */
  --stage-foot: 0px; /* kept clear at the bottom of the picture */
}

html.is-column .page {
  max-width: var(--col);
  margin: 0 auto;
}

/* Running text keeps a readable line length inside a wider column. */
html.is-column main > :not(.beats),
html.is-column .colophon {
  max-width: 480px;
}

html.is-column .masthead {
  margin-bottom: 40px;
}

html.is-column .story {
  display: block;
  position: sticky;
  top: 0;
  right: auto;
  bottom: auto;
  left: auto;
  z-index: 1;
  height: 100vh;
  height: 100svh;
  overflow: hidden;
  background: var(--bg);
}

/* The picture's box starts under the text. --text-foot is how far down the lowest
   beat's text reaches, measured by the script, so the picture does not move from beat to
   beat. The box begins 50px above that because the animation leaves that much and more
   clear at its own top. */
html.is-column .story__stage {
  position: absolute;
  inset: calc(var(--text-foot, 230px) - 50px) 0 var(--stage-foot) 0;
}

html.is-column .story__stage canvas {
  display: block;
  width: 100%;
  height: 100%;
}

html.is-column .story__caption {
  position: absolute;
  top: var(--head-top);
  left: 0;
  max-width: 100%;
  margin: 0;
  padding: 0 12px;
  background: var(--fg);
  color: var(--bg);
  font-size: 18px;
  line-height: 26px;
  font-weight: 700;
  text-transform: uppercase;
}

html.is-column .story__caption:empty {
  display: none;
}

/* A caption may be written with line breaks, one sentence to a line, and may mark words,
   which are set in the brand's red. */
.story__caption {
  white-space: pre-line;
}

.story__mark {
  color: var(--red, #d83241);
}

/* The second kind of mark: the green of the carts that come back. The caption's block
   is the reverse of the page (white on a dark page, black on a light one), so the green
   is the reverse too: the darker one on the white block, the lighter on the black. */
.story__mark--good {
  color: #1f7a43;
}

/* The same green for words in running text, which stands on the page itself and not on
   a reversed block: the page's own green, lighter on a dark page and darker on a light. */
.mark-good {
  color: var(--recovered, #1f7a43);
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .story__mark--good {
    color: #3fbf6f;
  }
}

:root[data-theme="light"] .story__mark--good {
  color: #3fbf6f;
}

/* The counter sits in the column's top right corner, on the caption's line, with its
   foot level with the foot of the caption's first line, so what stands under each of
   them is the same distance below. */
html.is-column .story__count {
  position: absolute;
  top: calc(var(--head-top) + var(--head-line) - 18px);
  right: 0;
  margin: 0;
  line-height: 18px;
  text-transform: uppercase;
}

/* The text layer lies over the stage and sticks with it. It takes no space of its own,
   and only the lines on show take clicks. */
html.is-column .context {
  position: sticky;
  top: 0;
  z-index: 2;
  height: 100vh;
  height: 100svh;
  margin-top: -100vh;
  margin-top: -100svh;
  pointer-events: none;
}

/* Each beat's text starts one --row-gap under the caption it belongs to. The script sets
   that height on each, since a caption may run to two lines; this is where it falls under
   a caption of one line. */
html.is-column .context__item {
  position: absolute;
  top: calc(var(--head-top) + var(--head-line) + var(--row-gap));
  left: 0;
  width: 100%;
  opacity: 0;
  transition: opacity 0.25s linear;
}

html.is-column .context__item.is-on {
  opacity: 1;
  pointer-events: auto;
}

/* A heading that only repeats the caption above it is kept for screen readers, which do
   not hear the caption, and taken out of sight. */
html.is-column .context__item .is-echo {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

html.is-column .context__item .is-echo + * {
  margin-top: 0;
}

/* Each emptied section is the length of scroll its beat lasts, and every beat lasts the
   same: 85% of the window's height. The first beat begins at the very top of the page,
   before the stage has reached the top of the window, so its section is shorter by that
   lead (--story-lead, measured by the script). */
html.is-column .beat {
  min-height: 85vh;
  min-height: 85svh;
}

html.is-column .beat--first {
  min-height: calc(85vh - var(--story-lead, 0px));
  min-height: calc(85svh - var(--story-lead, 0px));
}

html.is-column .after-story {
  margin-top: 60px;
}

html.is-column .after-story > .beat__rest > :first-child {
  margin-top: 0;
}

/* On a wide window the button belongs to the column too: it sits at the column's right
   edge, under the counter, which has the corner on the caption's line. With only the
   counter beside it the caption has nearly the whole line and seldom wraps. The four
   make two rows: caption and counter, then the beat's text and the button, with the
   same gap between the rows on both sides. The text stops short of the button. Once the
   stage has reached the top of the window the button is fixed there for the rest of the
   page; before that (.at-top, set by the script) it is placed on the page itself, so it
   rides up with the stage. */
@media (min-width: 1120px) {
  html.is-column .cta--pinned {
    top: calc(var(--head-top) + var(--head-line) + var(--row-gap));
    right: calc((100% - var(--col)) / 2);
  }

  html.is-column.at-top .cta--pinned {
    position: absolute;
    top: calc(var(--story-lead, 0px) + var(--head-top) + var(--head-line) + var(--row-gap));
  }

  html.is-column .context__item {
    width: calc(100% - 130px);
  }

  /* A caption of more than one line (the script marks it) stops short of the button,
     which stands beside its second line. */
  html.is-column .story__caption.is-multi {
    max-width: calc(100% - 130px);
  }

  html.is-column .story__caption {
    max-width: calc(100% - 48px);
  }

  /* Running text stops short of the button, which stays over the column's right edge
     as the page scrolls on. */
  html.is-column main > :not(.beats),
  html.is-column .colophon {
    max-width: min(480px, calc(var(--col) - 130px));
  }
}

/* Below that width the button is the bar along the bottom, as wide as the column, and
   the picture stops above it. A caption may run to two lines here as well. */
@media (max-width: 1119px) {
  html.is-column {
    --head-top: 24px;
    --stage-foot: 72px;
  }

  html.is-column .story__caption {
    max-width: calc(100% - 48px);
  }

  html.is-column .cta--pinned {
    top: auto;
    right: calc((100% - var(--col)) / 2);
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    left: calc((100% - var(--col)) / 2);
    padding: 9px 10px;
    font-size: 16px;
    line-height: 22px;
    text-align: center;
    box-shadow: 0 0 0 16px var(--bg), 0 16px 0 16px var(--bg);
  }

  html.is-column[data-variant="rucy"] body {
    padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px));
  }
}

@media (max-width: 560px) {
  html.is-column {
    --gutter: 16px;
    --head-top: 16px;
    --head-line: 22px;
  }

  html.is-column .masthead {
    margin-bottom: 24px;
  }

  html.is-column .story__caption {
    padding: 0 10px;
    font-size: 16px;
    line-height: 22px;
  }
}

.story__hint {
  display: none;
}

/* A sample conversation in the copy, set as an iMessage thread seen from the sending
   side: Rucy's texts are blue blocks on the right, the shopper's replies grey ones on the
   left. Square corners, the page's own type. Neither colour is from the brand kit; they
   are Apple's, there to name the channel at a glance. The blue is a shade deeper than
   the Messages app's (#007aff), so white 12px text on it keeps a 4.5:1 contrast. */
.thread {
  --bubble: #262629;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 20px 0;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .thread {
    --bubble: #e9e9eb;
  }
}

:root[data-theme="light"] .thread {
  --bubble: #e9e9eb;
}

.thread__channel {
  margin: 0;
  text-align: center;
}

.msg {
  align-self: flex-start;
  max-width: 80%;
  margin: 0;
  padding: 10px 14px;
  background: var(--bubble);
  color: var(--fg);
  overflow-wrap: anywhere;
}

.msg--rucy {
  align-self: flex-end;
  background: var(--imessage);
  color: var(--on-imessage);
}

/* The examples: one conversation per use, picked with tabs. A tab is a word in brackets,
   like the page's other switches, and the chosen one is a block like a small heading.
   The panels are laid over each other in one grid cell and all but the chosen one are
   made invisible, so the box is always as tall as the tallest conversation and nothing
   below it moves when the tab changes. That only applies once the script has set
   .is-tabbed; before that, and without the script, the conversations follow one another. */
.cases__tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 1ch;
  margin: 20px 0;
}

.cases__tabs[hidden] {
  display: none;
}

.cases__tab {
  position: relative;
  margin: 0;
  padding: 0 2ch;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-weight: 700;
  line-height: 18px;
  text-transform: uppercase;
  cursor: pointer;
}

.cases__tab::before,
.cases__tab::after {
  position: absolute;
  top: 0;
  color: var(--rubric, currentColor);
  font-weight: 400;
}

.cases__tab::before {
  content: "[";
  left: 0;
}

.cases__tab::after {
  content: "]";
  right: 0;
}

.cases__tab:hover {
  background: var(--rubric, var(--fg));
  color: var(--bg);
}

.cases__tab:hover::before,
.cases__tab:hover::after {
  color: inherit;
}

.cases__tab[aria-selected="true"] {
  background: var(--fg);
  color: var(--bg);
}

.cases__tab[aria-selected="true"]::before,
.cases__tab[aria-selected="true"]::after {
  content: none;
}

.cases__tab:focus-visible {
  outline: 1px solid var(--fg);
  outline-offset: 2px;
}

.cases__panel > :first-child {
  margin-top: 0;
}

.cases.is-tabbed .cases__panels {
  display: grid;
}

.cases.is-tabbed .cases__panel {
  grid-area: 1 / 1;
  min-width: 0;
}

.cases.is-tabbed .cases__panel[data-off] {
  visibility: hidden;
}

/* The Get Rucy button: a filled block in the blue of Rucy's messages in the sample
   conversation, in both themes. It is always on screen; see .cta--pinned for where. */
.cta {
  display: inline-block;
  padding: 20px 40px;
  background: var(--imessage);
  color: var(--on-imessage);
  font-size: 18px; /* the size of the caption over the animation */
  line-height: 26px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-decoration: none;
}

.cta:hover,
.brand .cta:hover {
  background: var(--fg);
  color: var(--bg);
}

.cta:focus-visible {
  outline-offset: 4px;
}

/* The same button set in the running text: the size of the type around it, in a block
   as tall as a small heading's. */
.cta--inline {
  padding: 0 10px;
  font-size: inherit;
  line-height: 18px;
  letter-spacing: 0;
}

/* Where it sits. On a wide window it is a small block in the top right corner, on the
   line of the caption and the beat counter, which moves over to make room for it. On a
   phone it is a bar along the bottom, under the thumb, and the page gets room at its
   foot so the bar never covers the last lines. */
.cta--pinned {
  position: fixed;
  z-index: 10;
  top: 36px; /* the same block as the caption: 26px tall, centred on the counter's line */
  right: 40px;
  padding: 0 12px;
  letter-spacing: 0;
}

@media (min-width: 1120px) {
  /* Clear of the button: its 8 characters at 18px and 24px of padding come to 110px,
     then a 14px gap. */
  .story__count {
    right: 164px;
  }
}

@media (max-width: 699px) {
  .cta--pinned {
    top: auto;
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    left: 16px;
    padding: 9px 10px;
    font-size: 16px; /* the caption's size in the narrow layouts */
    line-height: 22px;
    text-align: center;
    /* A band of the page's own colour around the bar, so text passing behind it does
       not show at its sides or under it. */
    box-shadow: 0 0 0 16px var(--bg), 0 16px 0 16px var(--bg);
  }

  html[data-variant="rucy"] body {
    padding-bottom: calc(88px + env(safe-area-inset-bottom, 0px));
  }
}

/* Who is speaking, for screen readers; the > and < markers carry it visually. */
.sr-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
