/* cargo.supply: the app-look pages (#287). The home page, and the cargo and item pages the
   Worker renders (worker/render.ts). They are laid out like the iPhone app at phone width,
   in a centred phone-width column on wider screens. Every value comes from tokens.css,
   which mirrors cargo/AppTheme.swift; do not write colours or sizes here that the app does
   not have. Plain CSS, no build step. Each page links tokens.css itself, before this file
   (not an @import here, which would chain two blocking requests). */

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

html {
  -webkit-text-size-adjust: 100%;
  color-scheme: light;
}

body {
  margin: 0;
  background: var(--app-background);
  color: var(--app-text);
  font: var(--app-type-body);
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

a:focus-visible {
  outline: 2px solid var(--app-brown);
  outline-offset: 2px;
  border-radius: 6px;
}

.skip {
  position: absolute;
  left: var(--app-header-gutter);
  top: -100px;
  z-index: 20;
  padding: 8px 12px;
  border-radius: var(--app-radius-pill);
  background: var(--app-card);
  box-shadow: var(--app-card-shadow);
}

.skip:focus {
  top: 8px;
}

/* The phone: one column, the width of an iPhone, centred on anything wider. */
.phone {
  max-width: var(--app-column);
  min-height: 100dvh;
  margin: 0 auto;
  position: relative;
}

/* ---- Glass ---- */

.glass {
  background: var(--app-glass-sheen), var(--app-glass-fill);
  -webkit-backdrop-filter: var(--app-glass-blur);
  backdrop-filter: var(--app-glass-blur);
  box-shadow: inset 0 0 0 1px var(--app-glass-edge), var(--app-glass-shadow);
}

/* Home and profile's full-width glass bar (glassBarBackground, homeHeaderHeight tall).
   The app's bar has no controls; the web adds the mark and the one way into the app. */
.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  height: var(--app-home-header);
  padding: 0 var(--app-header-gutter);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--app-glass-sheen), var(--app-glass-fill);
  -webkit-backdrop-filter: var(--app-glass-blur);
  backdrop-filter: var(--app-glass-blur);
}

.bar-mark {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: var(--app-tap);
  font: var(--app-type-pill);
  font-weight: 700;
}

.bar-mark svg {
  width: 20px;
  height: 20px;
  fill: var(--app-text);
}

/* The header row on a pushed screen (cargo, item): GlassHeader with the .fade backdrop.
   Controls are their own glass circles and pills; behind them a blur that fades out. */
.header {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: var(--app-header-top) var(--app-header-gutter) var(--app-header-gap);
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: calc(var(--app-header-row) + var(--app-header-top) + var(--app-header-gap));
}

/* HeaderScrollFade: the same frosted material as the glass, solid for the top half, then
   fading to clear (the gradient is a mask, so only its alpha counts). */
.header::before {
  content: "";
  position: absolute;
  inset: 0 0 -12px;
  z-index: -1;
  background: var(--app-glass-fill);
  -webkit-backdrop-filter: var(--app-glass-blur);
  backdrop-filter: var(--app-glass-blur);
  -webkit-mask-image: linear-gradient(#000 50%, transparent);
  mask-image: linear-gradient(#000 50%, transparent);
}

/* Circle button: 36pt, glass. Back, share and "..." in the app; here only back (home). */
.circle {
  flex: none;
  width: var(--app-header-row);
  height: var(--app-header-row);
  border-radius: 50%;
  display: grid;
  place-items: center;
}

.circle svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: var(--app-text);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Title pill: the cargo's name in a glass capsule next to the back button (17 medium, as
   in the app). It is the page's h1, so the default heading margins are reset or they grow
   the header row past 36pt. A name that fits is one line, as in the app. The app cuts a
   longer name off (lineLimit 1) and the owner can open Edit to read it; a web visitor has
   no Edit, so here a long name wraps inside the pill instead and is never cut off. */
.title-pill {
  margin: 0;
  min-width: 0;
  min-height: var(--app-header-row);
  padding: 6px 14px;
  border-radius: calc(var(--app-header-row) / 2);
  display: inline-flex;
  align-items: center;
  font: var(--app-type-header-title);
  overflow-wrap: anywhere;
}

/* A 36pt control (header circle, small pill) keeps its 36pt look but gets a 44px hit area. */
.circle,
.button.small {
  position: relative;
}

.circle::after,
.button.small::after {
  content: "";
  position: absolute;
  inset: -4px;
}

/* ---- Buttons ---- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 24px;
  border-radius: var(--app-radius-pill);
  background: var(--app-brown);
  color: var(--app-card);
  font: var(--app-type-button);
}

.button.secondary {
  background: var(--app-card);
  color: var(--app-text);
  box-shadow: inset 0 0 0 1px var(--app-hairline);
}

.button.small {
  min-height: 36px;
  padding: 0 16px;
  font: var(--app-type-pill);
  font-weight: 700;
}

/* ---- Intro (the onboarding layout: mark, big lowercase title, one line) ---- */

.intro {
  padding: 24px var(--app-sheet-gutter) 20px;
}

.intro h1 {
  margin: 0 0 8px;
  font: var(--app-type-flow-title);
  letter-spacing: -0.02em;
}

.intro p {
  margin: 0;
  color: var(--app-text-2);
  font: var(--app-type-body);
  max-width: 34ch;
}

/* Until the App Store listing is live the home page says so in plain caption text, not in a
   glass pill that looks like a control. With a listing, this becomes a .button "get the app". */
.intro .store {
  margin-top: 12px;
  font: var(--app-type-caption);
  color: var(--app-placeholder);
}

/* ---- The item grid (DiscoveryGrid of ItemCards): two staggered columns, 8pt gutters ----
   Two independent columns, as the app builds them: the markup puts each card in its column
   (render.ts alternates 1,3,5 | 2,4,6, so newest-first reads across the top as in the app).
   CSS multi-column would fill the left column first and break that order. */

.grid {
  display: flex;
  align-items: flex-start;
  gap: var(--app-gutter);
  padding: 0 var(--app-gutter);
}

.grid-col {
  flex: 1 1 0;
  min-width: 0;
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--app-gutter);
}

/* ItemCard: white, 12pt corners, 12pt padding, photo fit (never cropped) on the white
   backdrop with 8pt corners, then title (12 medium) and brand (12, #999). */
.card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: var(--app-card-padding);
  background: var(--app-card);
  border-radius: var(--app-radius-card);
  box-shadow: var(--app-card-shadow);
}

.card-pic {
  display: block;
  aspect-ratio: 0.8;
  background: var(--app-image-backdrop);
  border-radius: var(--app-radius-image);
  overflow: hidden;
}

.card-pic img,
.card-pic svg {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* No photo: the app's placeholderImage (CategoryDetailView), a "photo" glyph centred on the
   white backdrop, so the well never reads as a skeleton still loading. The glyph is
   textSecondary at half strength, as the app draws its other no-picture glyphs; it is
   decorative (aria-hidden), the title under it says what the item is. */
.card-pic.empty {
  display: grid;
  place-items: center;
}

.card-pic.empty svg {
  width: 40px;
  height: 40px;
  fill: none;
  stroke: color-mix(in srgb, var(--app-text-2) 50%, transparent);
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.hero .card-pic.empty svg {
  width: 56px;
  height: 56px;
}

.card-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.card-title {
  font: var(--app-type-card);
  color: var(--app-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-sub {
  font: var(--app-type-card-sub);
  /* placeholder (#666666, 5.74:1 on white), not the app's #999 (2.85:1, fails AA; #667). */
  color: var(--app-placeholder);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* The home page's feature tiles: what the app does, not products. They are not links, so
   they drop the ItemCard chrome (no white card, no shadow, no press effect): the drawing
   sits in a quiet subtleFill well and the text runs under it, wrapping to as many lines as
   the sentence needs. Every well is the same short 4:3 (#671): tall staggered grey blocks
   read as the loading skeleton, so the drawing fills most of a low well instead. */
.feature {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 8px;
}

.feature .card-pic {
  aspect-ratio: 4 / 3;
  background: var(--app-subtle);
  border-radius: var(--app-radius-card);
}

.feature .card-text {
  padding: 0 4px;
}

.feature .card-title,
.feature .card-sub {
  white-space: normal;
  overflow: visible;
}

/* The ink drawings on the home tiles: illustrationInk lines in the subtleFill well. Each
   drawing's viewBox is a 128x96 (4:3) window centred on it, so all six share one scale. */
.ink {
  padding: 6%;
  fill: none;
  stroke: var(--app-ink);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.ink .fill {
  fill: var(--app-ink);
  stroke: none;
}

/* ---- Footer: the policy links, quiet, above the floating pill ---- */

.foot {
  padding: 24px var(--app-sheet-gutter) 120px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  font: var(--app-type-caption);
  color: var(--app-placeholder);
}

/* The home page's "cargo, from Cargo Supply" gets a row of its own above the links, so the
   links share one line at every width instead of wrapping one of them alone (#671). */
.foot-line {
  flex-basis: 100%;
}

.foot a {
  color: var(--app-text-2);
  min-height: var(--app-tap);
  display: inline-flex;
  align-items: center;
}

.foot a:hover {
  text-decoration: underline;
}

/* A page with no floating pill (home, until there is an App Store link) needs no room for it. */
.foot.no-dock {
  padding-bottom: 32px;
}

/* ---- The floating pill at the bottom: where the app has its nav, the web has the way in ---- */

.dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 10;
  display: flex;
  justify-content: center;
  padding: 0 20px;
  pointer-events: none;
}

.dock-pill {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  max-width: 400px;
  padding: 6px 6px 6px 16px;
  border-radius: var(--app-radius-pill);
  font: var(--app-type-caption);
  font-weight: 600;
}

/* textPrimary, not textSecondary: over a dark photo the glass composites to about #a1a1a1,
   where #424242 is 3.9:1 and #1e1e1e is 6.5:1. */
.dock-pill .soon {
  padding-right: 10px;
  color: var(--app-text);
}

/* ---- Cargo and item pages (worker/render.ts) ---- */

.page-head {
  padding: 8px var(--app-header-gutter) 16px;
}

.owner {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  font: var(--app-type-caption);
  color: var(--app-text-2);
}

.avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--app-brown);
  color: var(--app-card);
  font: var(--app-type-avatar);
}

.page-head .desc {
  margin: 8px 0 0;
  font: var(--app-type-body);
  color: var(--app-text-2);
}

.empty {
  padding: 40px var(--app-sheet-gutter);
  text-align: center;
  color: var(--app-text-2);
}

/* The item page: the photo full width on white (imageBackdrop, never cropped), then the
   owner's avatar, title, brand and where it is saved, as on the app's item screen. */
.hero {
  background: var(--app-image-backdrop);
  padding: 24px var(--app-header-gutter);
}

.hero .card-pic {
  aspect-ratio: 1;
}

.item-text {
  padding: 16px var(--app-header-gutter) 0;
}

.item-text h1 {
  margin: 8px 0 4px;
  font: var(--app-type-item-title);
}

.item-text .brand {
  margin: 0 0 8px;
  font: var(--app-type-body);
  color: var(--app-text-2);
}

.item-text .price {
  margin: 0 0 12px;
  font: var(--app-type-section);
  color: var(--app-brown);
}

.item-text .in-cargo a {
  font-weight: 600;
  color: var(--app-brown);
}

/* An inline link in a 13pt row: pad its hit area to 44px without moving the text. */
.item-text .in-cargo a,
.more a {
  display: inline-block;
  padding: 12px 0;
  margin: -12px 0;
}

/* The closing row under a cargo's grid when the page shows only a preview of its items. */
.more {
  margin: 8px 0 0;
  padding: 12px var(--app-header-gutter);
  text-align: center;
  font: var(--app-type-caption);
  color: var(--app-text-2);
}

.more a {
  margin-left: 4px;
  font-weight: 600;
  color: var(--app-brown);
}

/* ---- The 404 page (site/404.html): every unknown path, and a share link to a cargo or item
   that is private, archived or gone (the Worker answers those with this page). ---- */

.lost {
  padding: 48px var(--app-sheet-gutter) 24px;
}

.lost h1 {
  margin: 0 0 8px;
  font: var(--app-type-question);
}

.lost p {
  margin: 0 0 24px;
  font: var(--app-type-body);
  color: var(--app-text-2);
  max-width: 34ch;
}

/* ---- The profile page (/u/<username>, #628): the app's profile of someone else ---- */

/* Hero: the 76pt picture, then name (23 bold), @handle (13.5) and the three counts, top aligned,
   16pt from the edges and 16pt apart, as profileHero. */
.profile-hero {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 8px var(--app-header-gutter) 0;
}

.profile-pic {
  flex: none;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  overflow: hidden;
  box-shadow: var(--app-avatar-shadow);
}

.profile-pic img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-pic.initial {
  display: grid;
  place-items: center;
  background: var(--app-avatar-fill);
  color: var(--app-card);
  font: var(--app-type-profile-initial);
}

.profile-text {
  min-width: 0;
}

.profile-text h1 {
  margin: 0;
  font: var(--app-type-profile-name);
  overflow-wrap: anywhere;
}

.profile-text .handle {
  margin: 3px 0 0;
  font: var(--app-type-profile-handle);
  color: var(--app-text-2);
}

/* statPair: the number 13 bold in textPrimary, the word 13 in textSecondary, 14pt apart. */
.stats {
  margin: 7px 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  font: var(--app-type-caption);
  color: var(--app-text-2);
}

.stats b {
  font-weight: 700;
  color: var(--app-text);
}

/* The bio: the app keeps it in edit profile only; the web shows it once, under the hero. */
.bio {
  margin: 12px var(--app-header-gutter) 0;
  font: var(--app-type-body);
  color: var(--app-text-2);
  white-space: pre-line;
  overflow-wrap: anywhere;
}

/* The cargos grid: two equal columns, 8pt apart and from the edge, 20pt under the hero. */
.cargo-grid {
  list-style: none;
  margin: 20px 0 0;
  padding: 0 var(--app-gutter);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--app-gutter);
}

/* CategoryCard: white, 12pt corners, the cover 120pt tall fit on white with 12pt corners,
   then the name (12 medium) and "N items" (12, primaryBrown). */
.cargo-card {
  display: flex;
  flex-direction: column;
  height: 185px;
  background: var(--app-card);
  border-radius: var(--app-radius-card);
  box-shadow: var(--app-card-shadow);
  overflow: hidden;
}

.cargo-pic {
  display: block;
  height: 120px;
  flex: none;
  background: var(--app-image-backdrop);
  border-radius: var(--app-radius-card);
  overflow: hidden;
}

.cargo-pic img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.cargo-pic.empty {
  background: var(--app-subtle);
}

.cargo-card .card-text {
  padding: 0 12px 12px;
  margin-top: auto;
}

.cargo-count {
  font: var(--app-type-card-sub);
  color: var(--app-brown);
}

/* EmptyStateView's words, without the figure: "no cargos yet", one line under it. */
.empty-state {
  padding: 48px var(--app-sheet-gutter) 0;
  text-align: center;
}

.empty-title {
  margin: 0 0 6px;
  font: var(--app-type-empty-title);
}

.empty-line {
  margin: 0;
  font: var(--app-type-body);
  color: var(--app-text-2);
}

@media (prefers-reduced-motion: no-preference) {
  .button,
  .card {
    transition: transform 160ms ease;
  }

  .button:active,
  a.card:active {
    transform: scale(0.97);
  }
}
