/* The cart to payment transition of a made-up homeware shop, Quillhouse. The whole window is drawn in pixels at one
   of two sizes (wide 680 x 460, tall 440 x 580) and the wrapper scales it to fit the box, height included. The cart
   rows, the total and the button are real elements that change parent: Flip measures them before and after. */
:root {
  --page: #ebe5dc;          /* the table under the window */
  --page-light: #f7f2ea;    /* the window light on it */
  --app: #fbf9f5;           /* the shop page */
  --panel: #fffefb;         /* the cart panel and the payment page */
  --card: #ffffff;          /* a cart row */
  --card-back: #f1ece4;     /* a row at the back of the stack */
  --soft: #f4f0e9;          /* the order summary */
  --ink: #1f1c18;           /* the words */
  --muted: #8a8378;         /* the small words */
  --line: rgba(31, 28, 24, 0.09); /* the hairlines */
  --accent: #b4583a;        /* terracotta: the button and the focus */
  --accent-deep: #8f3f26;   /* its shadow side */
}

* {
  box-sizing: border-box;
}

html {
  touch-action: manipulation;
}

html,
body {
  margin: 0;
  overflow-x: clip;
}

body {
  min-height: 100svh;
  background: var(--page);
  color: var(--ink);
  font-family: 'Mona Sans Variable', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
}

/* the table: warm paper, a window light from the top left and a fine grain */
.stage {
  position: relative;
  height: 100svh;
  min-height: 300px;
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 18% 0%, var(--page-light) 0%, rgba(247, 242, 234, 0) 62%),
    radial-gradient(90% 70% at 100% 100%, #ddd5c9 0%, rgba(221, 213, 201, 0) 70%),
    var(--page);
}

.stage::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: var(--grain, none);
  background-size: 180px;
  opacity: 0.35;
  mix-blend-mode: multiply;
  pointer-events: none;
}

.fit {
  position: absolute;
  left: 50%;
  top: 50%;
  transform-origin: 50% 50%;
  z-index: 1;
}

/* the window */
.app {
  position: relative;
  width: 680px;
  height: 460px;
  border-radius: 22px;
  overflow: hidden;
  background: var(--app);
  box-shadow:
    0 0 0 1px rgba(31, 28, 24, 0.06),
    0 1px 1px rgba(31, 28, 24, 0.04),
    0 8px 18px -6px rgba(60, 44, 28, 0.14),
    0 34px 70px -24px rgba(60, 44, 28, 0.32);
  opacity: 0;
}

.app.is-tall {
  width: 440px;
  height: 580px;
}

/* ---- the shop page ---- */
.shop {
  position: absolute;
  inset: 0;
  padding: 20px 22px;
  transform-origin: 30% 40%;
}

.shop__bar {
  display: flex;
  align-items: center;
  gap: 22px;
  height: 30px;
}

.brand {
  font-family: 'Fraunces Variable', Georgia, serif;
  font-size: 19px;
  font-weight: 560;
  font-variation-settings: 'opsz' 40, 'SOFT' 60;
  letter-spacing: -0.01em;
}

.brand--small {
  font-size: 16px;
}

.shop__nav {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--muted);
}

.bag {
  position: relative;
  margin-left: auto;
  width: 22px;
  height: 22px;
}

.bag svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.4;
  stroke-linejoin: round;
}

.bag__n {
  position: absolute;
  right: -6px;
  top: -4px;
  min-width: 15px;
  height: 15px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 9px;
  font-weight: 650;
  line-height: 15px;
  text-align: center;
}

.shop__hero {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 22px 0 16px;
}

.shop__kicker {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.shop__title {
  font-family: 'Fraunces Variable', Georgia, serif;
  font-size: 30px;
  font-weight: 420;
  font-variation-settings: 'opsz' 96, 'SOFT' 80;
  letter-spacing: -0.02em;
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.tile {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 6px;
  font-size: 12px;
}

.tile__photo {
  grid-column: 1 / -1;
  aspect-ratio: 1 / 1.05;
  border-radius: 12px;
  background-color: #e6dfd4;
  background-size: cover;
  background-position: center;
}

/* the real photos are wider than the square: each one is framed on its object */
span[data-photo="vase"] {
  background-size: auto 150%;
  background-position: 68% 66%;
}
span[data-photo="throw"] {
  background-position: 56% 50%;
}
span[data-photo="carafe"] {
  background-color: #eeeeec;
  background-size: auto 135%;
  background-position: 52% 46%;
}

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

.scrim {
  position: absolute;
  inset: 0;
  background: rgba(36, 28, 20, 0.26);
  -webkit-backdrop-filter: blur(1.5px);
  backdrop-filter: blur(1.5px);
}

/* ---- the panel that grows into the page ---- */
.drawer {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  width: 312px;
  border-radius: 20px 0 0 20px;
  background: var(--panel);
  box-shadow: -1px 0 0 rgba(31, 28, 24, 0.06), -24px 0 48px -20px rgba(40, 28, 18, 0.35);
}

.is-tall .drawer {
  width: 364px;
}

.is-pay .drawer {
  width: 100%;
  border-radius: 0;
  box-shadow: none;
}

/* ---- the cart ---- */
.cart {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 312px;
  padding: 20px 20px 20px;
  display: flex;
  flex-direction: column;
}

.is-tall .cart {
  width: 364px;
}

.is-pay .cart {
  pointer-events: none;
}

.cart__head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  height: 30px;
}

.cart__title {
  font-family: 'Fraunces Variable', Georgia, serif;
  font-size: 20px;
  font-weight: 520;
  font-variation-settings: 'opsz' 40, 'SOFT' 60;
}

.cart__count {
  font-size: 12px;
  color: var(--muted);
}

.close {
  margin-left: auto;
  align-self: center;
  width: 26px;
  height: 26px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  background: var(--soft);
}

.close svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.4;
  stroke-linecap: round;
}

.list {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.is-tall .list {
  margin-top: 18px;
  gap: 12px;
}

/* a row: the li is moved by Flip, the card inside by the hover and the landing, the content by its fade */
.row {
  position: relative;
  height: 64px;
  list-style: none;
}

.row__card {
  position: absolute;
  inset: 0;
  border-radius: 14px;
  background: var(--card);
  box-shadow:
    0 0 0 1px rgba(31, 28, 24, 0.07),
    0 1px 2px rgba(31, 28, 24, 0.05),
    0 6px 14px -8px rgba(60, 44, 28, 0.22);
  overflow: hidden;
}

.row__card::before {
  /* a light edge along the top that catches the window */
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0) 40%);
  opacity: 0.6;
  pointer-events: none;
}

.row__in {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px 0 9px;
}

.row__photo {
  flex: none;
  width: 46px;
  height: 46px;
  border-radius: 10px;
  background-color: #e6dfd4;
  background-size: cover;
  background-position: center;
  box-shadow: inset 0 0 0 1px rgba(31, 28, 24, 0.06);
}

.row__info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.row__name {
  font-size: 13px;
  font-weight: 560;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row__meta {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row__price {
  font-size: 12.5px;
  font-weight: 540;
  font-variant-numeric: tabular-nums;
}

.cart__foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cart__sum {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 12px;
}

.cart__rule {
  height: 1px;
  background: var(--line);
}

.cart__label {
  font-size: 13px;
  font-weight: 540;
}

.cart__note {
  font-size: 11px;
  color: var(--muted);
}

/* the places where the total and the button land */
.slot {
  display: flex;
  justify-content: flex-end;
}

.slot--cart {
  height: 20px;
}

.slot--pay {
  height: 27px;
}

.cta-slot {
  display: block;
  height: 46px;
  margin-top: 6px;
}

/* the total: its digits are columns that roll */
.total {
  display: inline-flex;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.slot--cart .total {
  font-size: 17px;
}

.slot--pay .total {
  font-size: 23px;
  font-weight: 640;
}

.total__c {
  display: inline-block;
  height: 1.15em;
  line-height: 1.15em;
}

.total__d {
  display: inline-block;
  height: 1.15em;
  overflow: hidden;
}

.total__s {
  display: flex;
  flex-direction: column;
  line-height: 1.15em;
}

/* the button: terracotta glaze with a light edge */
.cta {
  display: block;
  width: 100%;
  height: 46px;
  border-radius: 13px;
}

.cta__face {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  overflow: hidden;
  color: #fff;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0) 50%),
    linear-gradient(180deg, var(--accent), var(--accent-deep));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.28),
    inset 0 -1px 0 rgba(0, 0, 0, 0.12),
    0 1px 2px rgba(80, 30, 14, 0.3),
    0 10px 20px -10px rgba(143, 63, 38, 0.7);
}

.cta__sheen {
  position: absolute;
  top: -20%;
  bottom: -20%;
  left: -40%;
  width: 34%;
  background: linear-gradient(100deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.32), rgba(255, 255, 255, 0));
  transform: translateX(-100%) skewX(-16deg);
  pointer-events: none;
}

.cta__labels {
  position: relative;
  display: grid;
  height: 1.3em;
  overflow: hidden;
  font-size: 14px;
  font-weight: 600;
  font-variation-settings: 'wdth' 104;
  letter-spacing: 0.005em;
}

.cta__a,
.cta__b {
  grid-area: 1 / 1;
  line-height: 1.3em;
  text-align: center;
  white-space: nowrap;
}

/* ---- the payment page ---- */
.pay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.is-pay .pay {
  pointer-events: auto;
}

.pay__bar {
  position: absolute;
  left: 24px;
  right: 24px;
  top: 18px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 12px 0 8px;
  border-radius: 15px;
  background: var(--soft);
  font-size: 12px;
  font-weight: 540;
  box-shadow: inset 0 0 0 1px var(--line);
}

.back svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.secure {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--muted);
}

.secure svg {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.3;
}

.form {
  position: absolute;
  left: 28px;
  top: 70px;
  width: 328px;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.is-tall .form {
  left: 20px;
  right: 20px;
  width: auto;
  top: 244px;
}

.form__head {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 6px;
}

.form__title {
  font-family: 'Fraunces Variable', Georgia, serif;
  font-size: 24px;
  font-weight: 460;
  font-variation-settings: 'opsz' 72, 'SOFT' 70;
  letter-spacing: -0.015em;
}

.form__sub {
  font-size: 11.5px;
  color: var(--muted);
}

.is-tall .form__sub {
  display: none;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.field {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  height: 48px;
  padding: 0 14px;
  border-radius: 12px;
  background: #fff;
  box-shadow: inset 0 0 0 1px rgba(31, 28, 24, 0.11), 0 1px 2px rgba(31, 28, 24, 0.04);
}

.field--focus {
  box-shadow: inset 0 0 0 1.5px var(--accent), 0 0 0 4px rgba(180, 88, 58, 0.12);
}

.field__label {
  font-size: 10px;
  color: var(--muted);
  letter-spacing: 0.01em;
}

.field__value {
  position: relative;
  font-size: 13.5px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.caret {
  position: absolute;
  top: 1px;
  bottom: 1px;
  margin-left: 2px;
  width: 1.5px;
  background: var(--accent);
}

.field__card {
  position: absolute;
  right: 12px;
  top: 50%;
  width: 30px;
  height: 20px;
  margin-top: -10px;
  fill: none;
  stroke: rgba(31, 28, 24, 0.4);
  stroke-width: 1.1;
}

.field__card .chip {
  fill: rgba(180, 88, 58, 0.2);
  stroke: var(--accent);
}

.save {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 2px;
}

.switch {
  position: relative;
  width: 28px;
  height: 16px;
  border-radius: 8px;
  background: rgba(31, 28, 24, 0.14);
}

.switch__knob {
  position: absolute;
  left: 2px;
  top: 2px;
  width: 12px;
  height: 12px;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(31, 28, 24, 0.3);
}

/* the order summary, top right */
.summary {
  position: absolute;
  right: 24px;
  top: 70px;
  width: 286px;
  padding: 16px;
}

.is-tall .summary {
  left: 20px;
  right: 20px;
  width: auto;
  top: 62px;
  display: grid;
  grid-template-columns: 1fr 132px;
  grid-template-rows: auto auto;
  column-gap: 16px;
}

.summary__bg {
  position: absolute;
  inset: 0;
  border-radius: 18px;
  background: var(--soft);
  box-shadow: inset 0 0 0 1px var(--line), inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.summary__head {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
  font-weight: 580;
}

.is-tall .summary__head {
  grid-column: 1 / -1;
}

.summary__n {
  font-size: 11px;
  font-weight: 450;
  color: var(--muted);
}

/* the stack: the first row in front, the others behind it, each a little narrower and higher */
.pile {
  position: relative;
  height: calc(64px + 2 * var(--gap, 7px));
  margin: 26px 0 16px;
}

.is-tall .pile {
  margin-bottom: 0;
}

.pile .row {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(2 * var(--gap, 7px));
  z-index: 3;
}

.pile .row:nth-child(2) {
  left: 9px;
  right: 9px;
  top: var(--gap, 7px);
  z-index: 2;
}

.pile .row:nth-child(3) {
  left: 18px;
  right: 18px;
  top: 0;
  z-index: 1;
}

.summary__lines {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.is-tall .summary__lines {
  margin-top: 12px;
  justify-content: flex-end;
}

.line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.summary__rule {
  height: 1px;
  margin-top: 4px;
  background: var(--line);
}

.line--total {
  padding-top: 4px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 580;
}

/* the drawn pointer */
.pointer {
  position: absolute;
  left: 0;
  top: 0;
  width: 26px;
  height: 26px;
  z-index: 5;
  pointer-events: none;
  opacity: 0;
  fill: #fff;
  stroke: #1f1c18;
  stroke-width: 1.3;
  stroke-linejoin: round;
  filter: drop-shadow(0 3px 4px rgba(31, 28, 24, 0.3));
}

@media (hover: hover) {
  .cta:hover .cta__face {
    filter: brightness(1.04);
  }

  .back:hover {
    background: #ece6dd;
  }
}

@media (prefers-reduced-motion: reduce) {
  .pointer {
    display: none;
  }
}

/* the rows behind the first one keep a crisp edge, so the stack reads as layers */
.pile .row:not(:first-child) .row__card {
  box-shadow:
    0 0 0 1px rgba(31, 28, 24, 0.1),
    0 -1px 0 rgba(255, 255, 255, 0.9),
    0 4px 10px -6px rgba(60, 44, 28, 0.25);
}

.list .row {
  z-index: 4;
}
