/* The Share Builder.
 *
 * Same visual language as the rest of the watch page: white surface, 14px
 * corners, one green accent, system type. The only place that goes dark is the
 * preview stage, because a card is a picture and a picture needs a mat.
 */

.sb {
  width: min(1080px, calc(100vw - 40px));
  max-width: none;
  max-height: min(880px, calc(100vh - 40px));
  padding: 0;
  border: 0;
  border-radius: 18px;
  background: var(--app-bg, #fff);
  color: var(--app-fg, #0f0f10);
  box-shadow: 0 30px 90px rgba(0, 0, 0, .35);
  overflow: hidden;
}
.sb::backdrop {
  background: rgba(6, 8, 12, .62);
}

.sb__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--app-line, rgba(0, 0, 0, .12));
}
.sb__title {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: .01em;
}
.sb__close {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 999px;
  background: var(--app-hover, rgba(0, 0, 0, .06));
  color: inherit;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.sb__close:hover { background: rgba(0, 0, 0, .12); }

.sb__body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 388px;
  gap: 0;
  max-height: calc(min(880px, 100vh - 40px) - 71px);
}

/* ---- Preview ------------------------------------------------------------ */

.sb__stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 22px;
  background: #14161c;
  /* Both matter. A grid item defaults to min-width:auto, so one long line in
     the status text below sets a min-content width that pushes the whole stage
     past the edge of the dialog — where `overflow: hidden` then clips it. */
  min-height: 0;
  min-width: 0;
}

/* The canvas is always painted at full export resolution and scaled down here,
   which is why switching template is instant and exporting needs no re-render.
   The frame owns the aspect ratio so the picture never distorts. */
.sb__frame {
  --sb-preview-h: min(640px, calc(min(880px, 100vh - 40px) - 160px));
  display: grid;
  place-items: center;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 18px 44px rgba(0, 0, 0, .45);
  background: #0b0c0f;
}
.sb__frame[data-format="story"]     { height: var(--sb-preview-h); aspect-ratio: 9 / 16; }
.sb__frame[data-format="post"]      { height: var(--sb-preview-h); aspect-ratio: 4 / 5; }
.sb__frame[data-format="square"]    { height: var(--sb-preview-h); aspect-ratio: 1 / 1; }
.sb__frame[data-format="landscape"] {
  width: min(100%, calc(var(--sb-preview-h) * 16 / 9));
  height: auto;
  aspect-ratio: 16 / 9;
}
.sb__canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.sb__note {
  margin: 0;
  /* Stretched rather than content-sized: a flex column centres its children,
     and a long sentence sized by its content runs past the padding on a phone. */
  align-self: stretch;
  max-width: 100%;
  overflow-wrap: anywhere;
  min-height: 18px;
  font-size: 12.5px;
  line-height: 1.35;
  text-align: center;
  color: rgba(255, 255, 255, .70);
}
.sb__note[data-tone="warn"] { color: #ffce6b; }

/* ---- Controls ----------------------------------------------------------- */

.sb__controls {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px;
  overflow-y: auto;
  border-left: 1px solid var(--app-line, rgba(0, 0, 0, .12));
  min-height: 0;
}

.sb__group { display: grid; gap: 9px; }
.sb__label {
  margin: 0;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .10em;
  text-transform: uppercase;
  color: var(--app-dim, #606069);
}

.sb__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
/* Templates scroll sideways rather than growing the column: ten of them wrapped
   is most of the panel before anybody has chosen a format. */
.sb__chips--templates {
  flex-wrap: nowrap;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
  scroll-snap-type: x proximity;
}
.sb__chips--templates .sb__chip { flex: 0 0 auto; scroll-snap-align: start; }

.sb__chip {
  display: grid;
  gap: 2px;
  min-height: 46px;
  padding: 8px 14px;
  border: 1px solid var(--app-line, rgba(0, 0, 0, .12));
  border-radius: 12px;
  background: #fff;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.sb__chip:hover:not(:disabled) { background: var(--app-hover, rgba(0, 0, 0, .06)); }
.sb__chip.is-on {
  border-color: var(--app-accent, #22d37a);
  background: rgba(34, 211, 122, .12);
}
.sb__chip:disabled {
  opacity: .45;
  cursor: not-allowed;
}
.sb__chip:focus-visible {
  outline: 3px solid rgba(34, 211, 122, .55);
  outline-offset: 2px;
}
.sb__chip-label { font-size: 13.5px; font-weight: 700; white-space: nowrap; }
.sb__chip-sub {
  font-size: 11px;
  color: var(--app-dim, #606069);
  white-space: nowrap;
  max-width: 168px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sb__toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
}
.sb__toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  cursor: pointer;
}
.sb__toggle-input {
  width: 17px;
  height: 17px;
  accent-color: var(--app-accent, #22d37a);
  cursor: pointer;
}

.sb__actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 2px;
}
.sb__btn {
  min-height: 46px;
  padding: 0 16px;
  border: 1px solid var(--app-line, rgba(0, 0, 0, .12));
  border-radius: 12px;
  background: #fff;
  color: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.sb__btn:hover:not(:disabled) { background: var(--app-hover, rgba(0, 0, 0, .06)); }
.sb__btn:disabled { opacity: .55; cursor: progress; }
.sb__btn--primary {
  grid-column: 1 / -1;
  border-color: transparent;
  background: var(--app-accent, #22d37a);
  color: #04150c;
}
.sb__btn--primary:hover:not(:disabled) { background: #1cbd6c; }
.sb__btn:focus-visible {
  outline: 3px solid rgba(34, 211, 122, .55);
  outline-offset: 2px;
}

/* ---- Your push ---------------------------------------------------------- */

.sb__push {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--app-line, rgba(0, 0, 0, .12));
  border-radius: 14px;
  background: rgba(34, 211, 122, .07);
}
.sb__push-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.sb__push-cell { display: grid; gap: 1px; }
.sb__push-value { font-size: 21px; font-weight: 800; line-height: 1.1; }
.sb__push-label { font-size: 11px; color: var(--app-dim, #606069); }
.sb__push-note {
  margin: 0;
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--app-dim, #606069);
}

/* ---- Phones ------------------------------------------------------------- */
/* Sharing happens on a phone. The sheet fills the screen, the preview keeps the
   top half, and the controls scroll under it with touch-sized targets. */
@media (max-width: 880px) {
  .sb {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border-radius: 0;
  }
  .sb__body {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    max-height: calc(100dvh - 71px);
  }
  .sb__stage { padding: 14px; }
  .sb__frame { --sb-preview-h: min(38dvh, 340px); }
  .sb__frame[data-format="landscape"] { width: min(100%, calc(var(--sb-preview-h) * 16 / 9)); }
  .sb__controls {
    border-left: 0;
    border-top: 1px solid var(--app-line, rgba(0, 0, 0, .12));
    padding: 16px 14px calc(16px + env(safe-area-inset-bottom));
    gap: 16px;
  }
  .sb__chip { min-height: 50px; }
  .sb__btn { min-height: 50px; }
  /* The buttons stay in reach while the controls scroll under them. They need a
     surface of their own to do that: a transparent sticky row lets the toggles
     underneath show through it, which reads as two overlapping panels. */
  .sb__actions {
    position: sticky;
    bottom: calc(-1 * env(safe-area-inset-bottom));
    z-index: 2;
    margin: 0 -14px;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
    background: var(--app-bg, #fff);
    border-top: 1px solid var(--app-line, rgba(0, 0, 0, .12));
    box-shadow: 0 -10px 24px rgba(0, 0, 0, .06);
  }
}

/* Landscape phones have no room for a stage at all; the controls take over and
   the preview shrinks to a strip rather than pushing the buttons off screen. */
@media (max-width: 880px) and (max-height: 520px) {
  .sb__frame { --sb-preview-h: 150px; }
}

@media (prefers-reduced-motion: no-preference) {
  .sb[open] { animation: sb-in .16s ease-out; }
  @keyframes sb-in {
    from { opacity: 0; transform: translateY(8px) scale(.99); }
    to { opacity: 1; transform: none; }
  }
}

/* A switch with nothing behind it yet — the QR before a personalized link
   exists. Dimmed rather than removed: it says the feature is there and what it
   takes to have it. */
.sb__toggle.is-disabled { opacity: .45; cursor: not-allowed; }
.sb__toggle.is-disabled .sb__toggle-input { cursor: not-allowed; }

/* ---- Send it to ----------------------------------------------------------
   Deliberately plainer than the Share button above it. The sheet is the route
   that carries the PICTURE — and the only one that reaches Instagram, TikTok
   and Snapchat, none of which let a website post to them. These carry the
   link, which is the half that holds the attribution. */
.sb__targets {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}
.sb__target {
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid var(--app-line, rgba(0, 0, 0, .12));
  border-radius: 999px;
  background: #fff;
  color: inherit;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}
.sb__target:hover:not(:disabled) { background: var(--app-hover, rgba(0, 0, 0, .06)); }
.sb__target:focus-visible {
  outline: 3px solid rgba(34, 211, 122, .55);
  outline-offset: 2px;
}
/* The one that carries the card rather than the link. */
.sb__target--stories {
  border-color: transparent;
  background: rgba(34, 211, 122, .16);
}
.sb__target--stories:hover { background: rgba(34, 211, 122, .26); }

@media (max-width: 880px) {
  .sb__target { min-height: 44px; }
}
