/*
 * Components, named after the React components they will become
 * (Page, SiteHeader, Card, Button, Field, Flash, Price). Semantic tokens only.
 */

/* Page: shares the header's width and gutters, so content lines up under the logo */
.page {
  width: 100%;
  max-width: var(--width-page);
  margin-inline: auto;
  padding: var(--space-8) var(--space-4) var(--space-16);
}

.stack > * + * {
  margin-top: var(--space-4);
}

/* SiteHeader: logo bar with the guide's 1px rule */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  max-width: var(--width-page);
  margin-inline: auto;
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-border);
}

.site-header__logo {
  display: block;
  height: 32px;
  width: auto;
}

/* Account links, or the signed-in email and Sign out; wraps on phones */
.site-header__account {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2) var(--space-4);
  font-size: var(--text-small);
}

/* Card */
.card {
  padding: var(--space-6);
  background: var(--color-surface);
  border-radius: var(--radius-md);
}

/* Button */
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap-target);
  padding: var(--space-2) var(--space-6);
  border: 1px solid var(--color-action);
  border-radius: var(--radius-sm);
  text-decoration: none;
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease;
}

.button--primary {
  background: var(--color-action);
  color: var(--color-action-text);
}

.button--primary:hover {
  background: var(--color-emerald-20);
}

.button--secondary {
  background: transparent;
  color: var(--color-action);
}

.button--secondary:hover {
  background: var(--color-emerald-80);
}

.button:disabled {
  opacity: 0.6;
  cursor: progress;
}

.button--block {
  width: 100%;
}

/* Field: label above input, optional hint below */
.field {
  display: grid;
  gap: var(--space-1);
}

.field input,
.field select {
  width: 100%;
  min-height: var(--tap-target);
  padding: var(--space-2) var(--space-3);
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}

.field input:focus-visible,
.field select:focus-visible {
  border-color: var(--color-action);
}

/* A field's own error, popping up under it (the quantity stepper's) */
.field__error {
  color: var(--color-alert);
  font-weight: 700;
  transform-origin: left center;
}

@media (prefers-reduced-motion: no-preference) {
  .field__error {
    animation: field-error-pop 0.4s cubic-bezier(0.3, 1.6, 0.5, 1) both;
  }
}

@keyframes field-error-pop {
  from { scale: 0.4; opacity: 0; }
  to { scale: 1; opacity: 1; }
}

.field__hint {
  color: var(--color-text-muted);
  font-size: var(--text-small);
}

/* Flash: terracotta fails AA as text, so it is the border; text stays charcoal */
.flash {
  padding: var(--space-3) var(--space-4);
  border-left: 4px solid;
  border-radius: var(--radius-sm);
  background: var(--color-surface);
}

.flash--alert {
  border-color: var(--color-alert);
}

.flash--notice {
  border-color: var(--color-notice);
}

.form-errors ul {
  padding-left: var(--space-4);
}

/* Price */
.price {
  color: var(--color-heading);
  font-size: var(--text-h3);
  font-variant-numeric: tabular-nums;
}

/* Auth: narrow, left-aligned column for sign in, sign up and password forms */
.auth {
  max-width: var(--width-form);
}

.auth__links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-6);
}

/* Actions: a row of buttons that wraps on phones */
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
}

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

/* HomeModel: one card per preorderable home */
.home-models {
  display: grid;
  gap: var(--space-4);
  padding: 0;
  list-style: none;
}

.home-model__form {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: var(--space-3);
}

.home-model__quantity-error {
  flex-basis: 100%;
}

/* A visitor's email and names take the form's full width, above Units and Preorder */
.home-model__buyer {
  flex-basis: 100%;
}

/* Stepper: the units between round minus and plus buttons. Without JavaScript the buttons stay hidden and
   the number is typed instead. */
.stepper {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.field .stepper__value {
  width: 4.5rem;
  text-align: center;
  font-size: var(--text-h3);
  font-variant-numeric: tabular-nums;
}

.field .stepper__value:read-only {
  border-color: transparent;
  background: transparent;
  appearance: textfield;
}

.stepper__value::-webkit-inner-spin-button,
.stepper__value::-webkit-outer-spin-button {
  appearance: none;
}

.stepper__button {
  display: grid;
  place-items: center;
  width: var(--tap-target);
  height: var(--tap-target);
  border: 1px solid var(--color-action);
  border-radius: 50%;
  background: var(--color-action);
  color: var(--color-action-text);
  font: inherit;
  font-size: var(--text-h3);
  cursor: pointer;
  transition: transform 120ms ease-out;
}

.stepper__button[hidden] {
  display: none;
}

.stepper__button:hover {
  background: var(--color-emerald-20);
}

.stepper__button:active {
  transform: scale(0.92);
}

.stepper__button:disabled {
  background: transparent;
  color: var(--color-action);
  opacity: 0.4;
  cursor: not-allowed;
}

/* Story: the preorder page's opening, from delivery to leveling, ending on the real home */
.story {
  max-width: 880px;
}

.story__photo {
  width: 100%;
  height: auto;
}

.story__captions {
  display: grid;
  gap: var(--space-2);
  padding: 0;
  list-style: none;
  font-size: var(--text-h3);
  font-weight: 300;
}

.lede {
  font-size: var(--text-h3);
  font-weight: 300;
}

/* Inside: what the home is built from, beside the drawing of the finished home. The drawing is cropped
   to the home here; scenes.css shows its headroom when the parts move. */
.inside__stage {
  display: grid;
  gap: var(--space-8);
  align-items: center;
}

@media (min-width: 720px) {
  .inside__stage {
    grid-template-columns: 2fr 3fr;
  }
}

.inside__scene {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
}

.inside__captions {
  display: grid;
  gap: var(--space-2);
  padding-left: 1.2em;
}

/* PreorderFloat: a bar across the top with a small Preorder button in its corner, shown once the story's own
   button docks there (the preorder-float controller). The page scrolls under it. Hidden, it can't be focused
   or clicked. */
.preorder-float {
  position: fixed;
  z-index: 10;
  inset: 0 0 auto;
  display: flex;
  justify-content: flex-end;
  padding: var(--space-2) var(--space-4);
  background: color-mix(in srgb, var(--color-cream) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--color-border);
  opacity: 0;
  visibility: hidden;
  transition: opacity 200ms ease-out, visibility 0s 200ms;
}

.preorder-float--shown {
  opacity: 1;
  visibility: visible;
  transition: opacity 200ms ease-out;
}

.preorder-float__button {
  padding-inline: var(--space-4);
  font-size: var(--text-small);
  transform-origin: 0 0;
}

/* The story's button, while its copy sits docked in the bar */
.preorder-float__anchor--docked {
  visibility: hidden;
}

/* Landing: the preorder page's hero, one section per system, then the preorder form */
.landing > * + * {
  margin-top: var(--space-16);
}

/* The fixed bar takes no room, so the story still starts at the top */
.landing > .preorder-float + * {
  margin-top: 0;
}

.display {
  font-size: var(--text-display);
}

.eyebrow {
  color: var(--color-text-muted);
  font-size: var(--text-small);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Feature: copy beside its visual on wide screens; stacked on phones */
.feature {
  display: grid;
  gap: var(--space-6);
  align-items: center;
  padding-top: var(--space-12);
  border-top: 1px solid var(--color-border);
}

/* The visual gets the wider column. */
@media (min-width: 720px) {
  .feature {
    grid-template-columns: 2fr 3fr;
    gap: var(--space-12);
    min-height: 70vh;
  }
}

/* Wide screens: the systems, the look inside and the photos break out of the page's column, up to 1400px. */
@media (min-width: 1200px) {
  .feature,
  .inside,
  .step-inside,
  .highlights {
    --width-wide: min(1400px, 100vw - 2 * var(--space-8));
    width: var(--width-wide);
    margin-inline: calc((100% - var(--width-wide)) / 2);
  }
}

/* The system's visual: a loop, a photo or a drawing, at the column's width */
.feature__visual > * {
  display: block;
  width: 100%;
  height: auto;
}

/* Video decoders shift colors slightly, so fade a loop's edges into the page instead of showing a box. */
.feature__visual video {
  mask-image:
    linear-gradient(to right, transparent, #000 4%, #000 96%, transparent),
    linear-gradient(to bottom, transparent, #000 4%, #000 96%, transparent);
  mask-composite: intersect;
}

.feature__visual img {
  border-radius: var(--radius-md);
}

/*
 * Highlights: everything after transport on one board, like a keynote's closing slide. Two columns on
 * phones, where an expanded card takes its whole row; four on wide screens, around the brand tile, where
 * an expanded card fills the board. Cards jiggle on hover, or at random on touch screens (the controller).
 */
.highlights {
  --radius-card: 20px;
  position: relative;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-flow: dense;
  gap: var(--space-3);
  padding-top: var(--space-12);
  border-top: 1px solid var(--color-border);
}

/* The home on the National Mall fills the brand tile, inside a thin frame of its gradient */
.highlights__hero {
  display: grid;
  grid-column: 1 / -1;
  min-height: 200px;
  padding: var(--space-2);
  border-radius: var(--radius-card);
  background: linear-gradient(135deg, var(--color-emerald), var(--color-emerald-20) 50%, var(--color-terracotta));
}

.highlights__hero img {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: cover;
  object-position: 50% 60%;
  border-radius: calc(var(--radius-card) - var(--space-2));
}

.highlights__cell {
  min-width: 0;
}

.highlights__cell--wide,
.highlights__cell:has([aria-expanded="true"]) {
  grid-column: 1 / -1;
}

.highlights__card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  height: 100%;
  padding: var(--space-4);
  border-radius: var(--radius-card);
  background: color-mix(in srgb, var(--color-cream), white 55%);
  box-shadow: 0 1px 2px rgb(46 44 40 / 8%), 0 8px 24px rgb(46 44 40 / 6%);
}

.highlights__copy > * + * {
  margin-top: var(--space-1);
}

.highlights--interactive .highlights__copy {
  padding-right: var(--space-8);
}


.highlights__visual > * {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius-md);
}

.highlights__visual video {
  mask-image:
    linear-gradient(to right, transparent, #000 4%, #000 96%, transparent),
    linear-gradient(to bottom, transparent, #000 4%, #000 96%, transparent);
  mask-composite: intersect;
}

/* The plus sign is the card's only button; it turns into a close mark while the card is expanded. Hidden
   without JavaScript, where every card already shows its copy. Its hit area reaches the 44px tap target. */
.highlights__toggle {
  display: none;
}

.highlights--interactive .highlights__toggle {
  display: block;
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background:
    linear-gradient(var(--color-cream), var(--color-cream)) center / 13px 2px no-repeat,
    linear-gradient(var(--color-cream), var(--color-cream)) center / 2px 13px no-repeat,
    var(--color-emerald);
  cursor: pointer;
  transition: transform 200ms ease-out;
}

.highlights__toggle::before {
  content: "";
  position: absolute;
  inset: -6px;
}

.highlights__toggle:hover {
  background-color: var(--color-emerald-20);
}

.highlights__toggle[aria-expanded="true"] {
  transform: rotate(45deg);
}

@media (min-width: 960px) {
  .highlights {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-auto-rows: 300px;
    gap: var(--space-4);
  }

  .highlights__hero {
    grid-column: 2 / 4;
    grid-row: 1 / 3;
  }

  .highlights__cell--wide {
    grid-column: span 2;
  }

  .highlights__visual {
    flex: 1;
    min-height: 0;
  }

  .highlights__visual > * {
    height: 100%;
    object-fit: cover;
  }

  /* Expanded: the card covers the board, copy beside its visual */
  .highlights__cell:has([aria-expanded="true"]) {
    position: absolute;
    inset: var(--space-12) 0 0;
    z-index: 1;
  }

  .highlights__cell:has([aria-expanded="true"]) .highlights__card {
    display: grid;
    grid-template-columns: 2fr 3fr;
    gap: var(--space-12);
    align-items: center;
    padding: var(--space-12);
  }

  .highlights__cell:has([aria-expanded="true"]) h3 {
    font-size: var(--text-h2);
  }

  .highlights__cell:has([aria-expanded="true"]) .highlights__visual {
    height: 100%;
  }

  .highlights__cell:has([aria-expanded="true"]) .highlights__visual > * {
    object-fit: contain;
  }
}

@keyframes jiggle {
  0%,
  100% {
    transform: none;
  }

  20% {
    transform: rotate(-1.5deg);
  }

  40% {
    transform: rotate(1.5deg);
  }

  60% {
    transform: rotate(-1deg);
  }

  80% {
    transform: rotate(0.5deg);
  }
}

@media screen and (prefers-reduced-motion: no-preference) {
  .highlights__card--jiggle {
    animation: jiggle 450ms ease-in-out;
  }

  @media (hover: hover) {
    .highlights__card:not(:has([aria-expanded="true"])):hover {
      animation: jiggle 450ms ease-in-out;
    }
  }
}

/* StepInside: photos of the real home, each with its caption. On wide screens they stand side by side. */
.step-inside__photos {
  display: grid;
  gap: var(--space-6);
}

.step-inside__photo {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin: 0;
}

.step-inside__photo img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius-md);
}

.step-inside__photo figcaption {
  color: var(--color-text-muted);
  font-size: var(--text-small);
}

@media (min-width: 720px) {
  /* Equal columns: the photos share a shape (3:2), so they match in height uncropped */
  .step-inside__photos {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
}

/* EnergyApp: a drawing of the app's energy view */
.energy-app {
  font-family: var(--font-sans);
}

.energy-app__card {
  fill: var(--color-surface);
}

.energy-app__ring-track,
.energy-app__ring {
  fill: none;
  stroke-width: 28;
}

.energy-app__ring-track {
  stroke: var(--color-emerald-80);
}

.energy-app__ring {
  stroke: var(--color-emerald);
  stroke-linecap: round;
}

.energy-app__big {
  fill: var(--color-emerald);
  font-size: 104px;
  font-weight: 300;
}

.energy-app__text {
  fill: var(--color-text);
  font-size: 46px;
}

.energy-app__muted {
  fill: var(--color-text-muted);
  font-size: 40px;
}

.energy-app__bars rect {
  fill: var(--color-emerald-40);
}

.energy-app__bars .energy-app__bar--now,
.energy-app__accent {
  fill: var(--color-terracotta);
}

.energy-app__rays {
  stroke: var(--color-terracotta);
  stroke-width: 6;
  stroke-linecap: round;
}

.energy-app__rule {
  stroke: var(--color-border);
  stroke-width: 2;
}

.preorder-section {
  padding-top: var(--space-12);
  border-top: 1px solid var(--color-border);
}

/* Footnotes: the preorder terms, small and quiet under the order box */
.preorder-footnotes {
  max-width: 65ch;
  padding-left: var(--space-4);
  color: var(--color-text-muted);
  font-size: var(--text-small);
}

/*
 * Reveal: content fades and rises into place as it scrolls into view. Scroll-driven where the browser
 * supports it; elsewhere the reveal Stimulus controller adds .reveal-fallback and .reveal--shown.
 * Screens only, so print shows every section, and only for visitors who haven't asked for reduced
 * motion; without either, content is simply shown.
 */
@keyframes reveal {
  from {
    opacity: 0;
    transform: translateY(var(--space-6));
  }

  to {
    opacity: 1;
    transform: none;
  }
}

@media screen and (prefers-reduced-motion: no-preference) {
  @supports (animation-timeline: view()) {
    .reveal {
      animation: reveal linear both;
      animation-timeline: view();
      animation-range: entry 0% cover 30%;
    }
  }

  .reveal-fallback .reveal {
    opacity: 0;
    transform: translateY(var(--space-6));
    transition: opacity 600ms ease-out, transform 600ms ease-out;
  }

  .reveal-fallback .reveal.reveal--shown {
    opacity: 1;
    transform: none;
  }
}

/* Shared width: lines content up with .page */
.page-width {
  max-width: var(--width-page);
  margin-inline: auto;
  padding-inline: var(--space-4);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* StaffHeader: green bar with a terracotta rule, so the staff area never passes for the customer site */
.staff-header {
  background: var(--color-action);
  color: var(--color-action-text);
  border-bottom: 3px solid var(--color-accent);
}

.staff-header__bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-6);
  max-width: var(--width-page);
  margin-inline: auto;
  padding: var(--space-3) var(--space-4);
}

.staff-header__brand {
  color: inherit;
  font-size: var(--text-h3);
  text-decoration: none;
}

.staff-header__user {
  margin-left: auto;
  font-size: var(--text-small);
}

.button--on-dark {
  background: transparent;
  border-color: var(--color-action-text);
  color: var(--color-action-text);
}

.button--on-dark:hover {
  background: var(--color-emerald-20);
}

/* Tabs: pill links between sections; the current one is filled */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding-top: var(--space-6);
}

.tabs__tab {
  padding: var(--space-1) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  text-decoration: none;
}

.tabs__tab[aria-current="page"] {
  background: var(--color-action);
  border-color: var(--color-action);
  color: var(--color-action-text);
}

/* Search: one input and a button in a row */
.search {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.search__input {
  flex: 1 1 16rem;
  min-height: var(--tap-target);
  padding: var(--space-2) var(--space-3);
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}

/* Table: scrolls sideways on phones instead of widening the page */
.table-scroll {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-small);
}

.table th,
.table td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--color-border);
  text-align: left;
  vertical-align: top;
}

.table th {
  color: var(--color-text-muted);
  font-weight: inherit;
}

.table__number {
  font-variant-numeric: tabular-nums;
}

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

/* List: a plain list of records inside a card */
.list {
  display: grid;
  gap: var(--space-2);
  padding: 0;
  list-style: none;
}

/* InlineForm: fields side by side, wrapping on phones, with the button on the inputs' baseline */
.inline-form {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: var(--space-3);
}

.list__action {
  display: inline-block;
  margin-left: var(--space-2);
}

/* Smaller text and padding; keeps the tap target height */
.button--small {
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-small);
}

/* HeadingRow: a page heading with its main action on the right */
.heading-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

/* Preorders: the buyer's preorders, with a photo of the home above them on a phone and beside them on a wide screen */
.preorders {
  display: grid;
  gap: var(--space-8);
}

.preorders__photo img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius-md);
}

.preorder__address address {
  font-style: normal;
}

@media (min-width: 960px) {
  .preorders {
    grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
    align-items: start;
  }

  /* Stays in view while a long list of preorders scrolls past */
  .preorders__photo {
    grid-column: 2;
    grid-row: 1;
    position: sticky;
    top: var(--space-8);
  }

  .preorders__list {
    grid-column: 1;
    grid-row: 1;
  }
}
