/*
  BusyCal Bookings: a host's cover and page background.

  This file is the fixed half of a host's appearance. The other half is the account's own
  stylesheet, /{handle}/appearance.css, which the server writes from the saved settings and
  which loads after this file. It sets only these variables on :root, from validated values:

    --appearance-cover-display   none or block
    --appearance-cover-visible   1 while the cover shows and 0 otherwise: the same choice
                                 as a number, so section 3 can scale lengths by it
    --appearance-cover-image     none, url() of the host's own cover image, or
                                 var(--appearance-dune) or var(--appearance-coast)
    --appearance-cover-x         the crop's horizontal position, 0% to 100%
    --appearance-cover-y         the crop's vertical position, 0% to 100%
    --appearance-cover-zoom      the crop's zoom, 1 to 2
    --appearance-background      var(--appearance-paper), var(--appearance-sand) or
                                 var(--appearance-mist)

  The three backgrounds are colors in style.css and dark.css, beside the rest of each
  palette, and body takes them there. The two cover drawings, Dune and Coast, are here. They
  are CSS gradients and a host's own cover is a same-origin JPEG, because the Content
  Security Policy allows no inline styles, no data: URIs and nothing from another origin.

  Loaded by every public page that knows its host (templates/base.html) and by Settings ›
  Appearance (templates/host/appearance.html). The editor sets the same variables on its own
  elements while a host tries choices, and in its private previews, which are the real pages.
  Without the account's stylesheet a cover stays hidden and the band's photo keeps its usual
  place.

  Sections:
    1. Cover drawings
    2. The cover
    3. Covers on the public pages
    4. Print
*/

/* ---------- 1. Cover drawings ---------- */

/*
  Each drawing is flat layered shapes, listed from front to back: ellipses centered below
  the frame draw ridges and waves with their top arcs, and a stop at 98.4% softens each edge
  by about 2 px. Sizes and positions are shares of the frame, so a drawing fills every frame
  shape, from the profile's cover to the booking pages' strip and the editor's tiles. The
  sun uses closest-side, which ties its radius to the frame's height, so it stays round.

  The tones are light here. In dark appearance the same scenes move to dusk, following the
  page's theme rather than the visitor's system setting: a host's fixed Light or Dark theme
  wins, as it does for dark.css (data-theme comes from templates/base.html).
*/
:root {
  --dune-sky: #f8ecdf;
  --dune-sky-low: #f2d6bb;
  --dune-sun: #eda077;
  --dune-far: #e8c09b;
  --dune-mid: #d99469;
  --dune-ripple: #e5aa82;
  --dune-near: #c06d47;
  --dune-front: #a5553a;
  --coast-sky: #eef4f5;
  --coast-sky-low: #d3e5e9;
  --coast-sun: #f9efdc;
  --coast-far: #9cc6cc;
  --coast-cliff: #4c878c;
  --coast-cliff-shade: #3a7076;
  --coast-mid: #66a4ad;
  --coast-near: #3c8590;
  --coast-front: #286775;
  --coast-foam: #e6f2f3;

  --appearance-dune:
    radial-gradient(60% 66% at 12% 150%, var(--dune-front) 0 98.4%, transparent 100%),
    radial-gradient(56% 64% at 84% 140%, var(--dune-near) 0 98.4%, transparent 100%),
    radial-gradient(70% 72% at 34% 132%, var(--dune-mid) 0 84%, var(--dune-ripple) 84.8% 86.2%, var(--dune-mid) 87% 98.4%, transparent 100%),
    radial-gradient(130% 68% at 78% 118%, var(--dune-far) 0 98.4%, transparent 100%),
    radial-gradient(circle closest-side at 66% 42%, var(--dune-sun) 0 36%, transparent 37.4%),
    linear-gradient(180deg, var(--dune-sky) 0%, var(--dune-sky-low) 100%);
  --appearance-coast:
    radial-gradient(50% 54% at 14% 146%, var(--coast-front) 0 98.4%, transparent 100%),
    radial-gradient(60% 52% at 78% 136%, var(--coast-near) 0 95.2%, var(--coast-foam) 96% 98.4%, transparent 100%),
    radial-gradient(90% 50% at 40% 124%, var(--coast-mid) 0 95.2%, var(--coast-foam) 96% 98.4%, transparent 100%),
    radial-gradient(14% 40% at 95% 84%, var(--coast-cliff-shade) 0 98.4%, transparent 100%),
    radial-gradient(22% 46% at 88% 80%, var(--coast-cliff) 0 98.4%, transparent 100%),
    linear-gradient(180deg, transparent 0 60%, var(--coast-far) 60% 100%),
    radial-gradient(circle closest-side at 30% 34%, var(--coast-sun) 0 38%, transparent 39.4%),
    linear-gradient(180deg, var(--coast-sky) 0%, var(--coast-sky-low) 60%);
}

/* The dusk tones, for a fixed Dark theme and for Automatic on a dark system. The two rules
   carry the same values; the second applies only where the system asks for dark. */
:root[data-theme="dark"] {
  --dune-sky: #241d22;
  --dune-sky-low: #3c2c29;
  --dune-sun: #d08156;
  --dune-far: #5c3c31;
  --dune-mid: #6e4433;
  --dune-ripple: #7f513d;
  --dune-near: #4f2e20;
  --dune-front: #3d2419;
  --coast-sky: #111c21;
  --coast-sky-low: #1c2f36;
  --coast-sun: #b4c6c1;
  --coast-far: #284b53;
  --coast-cliff: #1f4046;
  --coast-cliff-shade: #183338;
  --coast-mid: #24545d;
  --coast-near: #1c4750;
  --coast-front: #133943;
  --coast-foam: #4a7b82;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --dune-sky: #241d22;
    --dune-sky-low: #3c2c29;
    --dune-sun: #d08156;
    --dune-far: #5c3c31;
    --dune-mid: #6e4433;
    --dune-ripple: #7f513d;
    --dune-near: #4f2e20;
    --dune-front: #3d2419;
    --coast-sky: #111c21;
    --coast-sky-low: #1c2f36;
    --coast-sun: #b4c6c1;
    --coast-far: #284b53;
    --coast-cliff: #1f4046;
    --coast-cliff-shade: #183338;
    --coast-mid: #24545d;
    --coast-near: #1c4750;
    --coast-front: #133943;
    --coast-foam: #4a7b82;
  }
}

/* ---------- 2. The cover ---------- */

/*
  A cover is decorative and hidden from screen readers: a frame (.appearance-cover) that
  clips, and the picture inside it (.appearance-cover-image). Nothing readable or pressable
  ever sits on the picture.

  The picture is sized to cover the frame, placed at the crop's x and y, then scaled by the
  zoom around that same point. The image point at x% y% therefore always sits at the frame's
  x% y%, so one saved crop suits every frame shape, and a zoom of 1 or more never shows the
  frame's edge. A drawing has no size of its own and simply fills the frame, so its position
  matters only once it is zoomed. assets/cover-geometry.js does the same arithmetic for
  dragging and pinching in the editor.

  The frame stays hidden until a stylesheet sets --appearance-cover-display, and its plain
  surface shows while a host's image loads.
*/
.appearance-cover {
  display: var(--appearance-cover-display, none);
  position: relative;
  overflow: hidden;
  isolation: isolate;
  background: var(--surface-3);
}

.appearance-cover-image {
  position: absolute;
  inset: 0;
  background-image: var(--appearance-cover-image, none);
  background-repeat: no-repeat;
  background-size: cover;
  background-position: var(--appearance-cover-x, 50%) var(--appearance-cover-y, 50%);
  transform: scale(var(--appearance-cover-zoom, 1));
  transform-origin: var(--appearance-cover-x, 50%) var(--appearance-cover-y, 50%);
}

/*
  The server saves a host's own image as an opaque JPEG, laying any transparency on white.
  Settings › Appearance shows a chosen file before it is uploaded, so while Your image is
  the cover there, its picture is drawn on white too, whatever the theme: in the editor's
  drag frame, under [data-appearance-editor] with data-cover="custom", and in its private
  previews, whose root element the appearance script marks with the same data-cover.
  Public pages never carry data-cover, and their saved JPEG has no transparency to show.
*/
[data-appearance-editor][data-cover="custom"] .appearance-cover-image,
:root[data-cover="custom"] .appearance-cover-image {
  background-color: #fff;
}

/* ---------- 3. Covers on the public pages ---------- */

/*
  The profile's cover is a rounded picture across the head, 5:2 on phones
  and 4:1 from 640 px, as wide as the cards below it. A hairline keeps a pale picture apart
  from a pale background. The host's 96 px photo overlaps the cover's lower edge by half its
  height: the cover's negative margin takes back those 48 px and the head's 12 px gap.
  Without a photo, or without a cover, the head keeps its usual spacing, since a hidden
  element's margin takes no space.
*/
.appearance-cover--profile {
  justify-self: stretch;
  aspect-ratio: 5 / 2;
  border-radius: var(--radius-xl);
}

.appearance-cover--profile::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--text) 8%, transparent);
  pointer-events: none;
}

.profile-head:has(> .avatar) > .appearance-cover--profile {
  margin-bottom: calc(-1 * (48px + var(--space-3)));
}

/* The photo paints over the cover it overlaps. */
.profile-head > .avatar {
  position: relative;
  z-index: 1;
}

@media (min-width: 640px) {
  .appearance-cover--profile {
    aspect-ratio: 4 / 1;
  }
}

/*
  Booking pages, the booking form, the confirmation and the status cards carry a compact
  strip as the card's first element, above the host band or the status hero. The strip's
  picture is 4:1 at every width, so each step of a booking shows the same part of the host's
  cover on phones and desktops alike: about 98 px high on a 390 px phone, 160 px on a desktop
  status card and 240 px on a booking page in a 1024 px window. A fixed height would show a
  thinner slice the wider the card grows. At 100% zoom a 4:1 cover shows whole, here and in
  the profile's desktop frame.

  The strip is always in the page, and only the account's stylesheet knows whether it shows,
  which no selector can see. So that sheet, and the editor in its private previews, also set
  --appearance-cover-visible, which the band and the hero below the strip take as
  --cover-above. Each length that depends on the strip moves from its usual value to its
  value under the strip by that factor. At 0, which is also its value before any sheet sets
  it and on paper (section 4), the band, the hero and the photo are exactly as style.css
  draws them, so the usual values restated here must follow style.css.

  The strip takes the card's rounded top corners. The band and the hero round their own top
  corners to fit the card when they come first, so under the strip they square them and meet
  the picture's lower edge with no pale notches, and their own shading starts right at that
  edge. On phones the card is square, and so are the strip, the band and the hero.
*/
.appearance-cover--compact {
  aspect-ratio: 4 / 1;
  border-radius: calc(var(--radius-xl) - 1px) calc(var(--radius-xl) - 1px) 0 0;
}

.appearance-cover--compact + .booker-head,
.appearance-cover--compact + .status-hero {
  --cover-above: var(--appearance-cover-visible, 0);
  --band-corner: calc(var(--radius-xl) - 1px);
  border-top-left-radius: calc((1 - var(--cover-above)) * var(--band-corner));
  border-top-right-radius: calc((1 - var(--cover-above)) * var(--band-corner));
}

/*
  On the booking page and the booking form the host's photo rises over the strip, as the
  profile's photo rises over its cover, while the name, the title and Settings stay on the
  band below the picture. The photo grows from 64 to 88 px and 32 px of it overlaps the
  picture; on phones it grows from 48 to 64 px and overlaps by 24 px. The band's top padding
  drops to 16 px so the name sits close under the picture, and the photo's negative top
  margin takes back that padding and the overlap. Its ring grows from 3 to 4 px and stays the
  card's surface edged by the card's line, so in dark appearance it is dark too, never a
  white halo.

  A band without a photo keeps its usual padding under the strip, with no room set aside for
  one. The status cards carry no photo, so only their strip and corners change.
*/
.appearance-cover--compact + .booker-head {
  --band-top: var(--space-8);
  --band-top-under-cover: var(--space-4);
  --photo-size: 64px;
  --photo-size-over-cover: 88px;
  --photo-overlap: 32px;
}

.appearance-cover--compact + .booker-head:has(> .avatar) {
  padding-top: calc(var(--band-top) + var(--cover-above) * (var(--band-top-under-cover) - var(--band-top)));
}

/* Positioned, the photo paints over the strip, which comes before it in the page. */
.appearance-cover--compact + .booker-head > .avatar {
  --photo: calc(var(--photo-size) + var(--cover-above) * (var(--photo-size-over-cover) - var(--photo-size)));
  position: relative;
  width: var(--photo);
  height: var(--photo);
  margin-top: calc(-1 * var(--cover-above) * (var(--band-top-under-cover) + var(--photo-overlap)));
  box-shadow:
    0 0 0 calc(3px + var(--cover-above) * 1px) var(--surface),
    0 0 0 calc(4px + var(--cover-above) * 1px) var(--line);
}

@media (max-width: 639px) {
  .appearance-cover--compact {
    border-radius: 0;
  }

  .appearance-cover--compact + .booker-head,
  .appearance-cover--compact + .status-hero {
    --band-corner: 0px;
  }

  /* style.css's phone padding and photo, and the smaller photo over a cover. */
  .appearance-cover--compact + .booker-head {
    --band-top: var(--space-5);
    --photo-size: 48px;
    --photo-size-over-cover: 64px;
    --photo-overlap: 24px;
  }
}

/* ---------- 4. Print ---------- */

/*
  Paper shows no cover. The account's stylesheet still says whether the screen shows one, so
  the band and the hero are told here that nothing sits above them: they keep their rounded
  corners, and the photo keeps its usual place and size instead of rising over a strip that
  isn't printed.
*/
@media print {
  .appearance-cover {
    display: none;
  }

  .appearance-cover--compact + .booker-head,
  .appearance-cover--compact + .status-hero {
    --cover-above: 0;
  }
}
