/* Task 17: the share sheet (ui/share-sheet.js) and the link view
   (views/link.js), both dark. Reuses app.css's tokens and classes (.btn,
   .btn-main, .btn-quiet, .title, .meta, .form-error, .mark, .dark) and
   album.css's gallery and its dark body, and adds only what's new here. No
   inline styles anywhere (the CSP). */

/* ---------- the share sheet: a bottom sheet on phones, a centred card from 600px ---------- */

/* The page behind doesn't scroll while the sheet is open over it. */
:root:has(.share-backdrop) {
  overflow: hidden;
}

.share-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.62);
}

.share-sheet {
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px - env(safe-area-inset-top, 0px));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 24px calc(20px + env(safe-area-inset-right, 0px)) calc(24px + env(safe-area-inset-bottom, 0px))
    calc(20px + env(safe-area-inset-left, 0px));
  border: 1px solid var(--night-line);
  border-bottom: 0;
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -12px 36px rgba(0, 0, 0, 0.5);
}

@media (min-width: 600px) {
  .share-backdrop {
    align-items: center;
    padding: 24px;
  }

  .share-sheet {
    max-height: calc(100vh - 48px);
    max-height: calc(100dvh - 48px);
    padding: 28px;
    border-bottom: 1px solid var(--night-line);
    border-radius: 24px;
  }
}

.share-title {
  font-size: 24px;
  margin: 0 0 8px;
}

.share-line {
  margin: 0 0 18px;
}

.share-error .form-error {
  margin: 0 0 16px;
}

/* The link itself, whole and readable (two lines on a phone), so it can be
   read, selected or long-pressed. */
.share-url {
  display: block;
  width: 100%;
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--night-line);
  border-radius: 16px;
  background: var(--night-btn);
  color: var(--moon);
  font-family: inherit;
  font-size: 16px;
  line-height: 1.4;
  word-break: break-all;
  overflow-x: hidden;
  overflow-y: auto; /* a link longer than two lines scrolls rather than hides */
  resize: none;
}

.share-note {
  margin: 8px 0 0;
}

/* The lines under the link take no room while they have nothing to say. */
.share-note:empty {
  margin: 0;
}

.share-actions {
  display: flex;
  gap: 10px;
  margin: 14px 0 0;
}

/* Every button in the sheet is 56px with one label size, as ui/sheet.js's
   paired buttons are (app.css's .sheet-actions), so Copy link and Share...
   line up side by side. */
.share-actions .btn {
  flex: 1 1 0;
  height: 56px;
  font-size: 17px;
  white-space: nowrap; /* a label never wraps */
}

.share-actions-stack {
  flex-direction: column;
}

.share-actions-stack .btn {
  flex: 0 0 auto;
}

/* A question's answers ignore taps for its first moment (share-sheet-parts.js),
   so a double tap can't answer it; they look as they always do meanwhile. */
.share-arming:disabled {
  opacity: 1;
  cursor: default;
}

/* The QR code: at least 200px square, its own white quiet zone drawn in
   the SVG. The box is night-grey while the code is being made. */
.share-qr-box {
  width: 208px;
  height: 208px;
  margin: 22px auto 4px;
  border-radius: 12px;
  overflow: hidden;
  background: var(--night-btn);
}

/* A wide screen: a wider card, with the link and its buttons beside the
   QR code, so the whole sheet fits a laptop screen without scrolling. */
@media (min-width: 720px) {
  .share-sheet {
    max-width: 640px;
  }

  .share-top {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 208px;
    gap: 24px;
    align-items: start;
  }

  .share-top .share-actions {
    flex-direction: column;
  }

  .share-top .share-actions .btn {
    flex: 0 0 auto;
  }

  .share-top .share-qr-box {
    margin: 0;
  }
}

.share-qr-box[hidden] {
  display: none;
}

.share-qr {
  width: 100%;
  height: 100%;
}

.share-switches {
  margin: 18px 0 0;
  border-top: 1px solid var(--night-line);
}

.share-switch {
  border-bottom: 1px solid var(--night-line);
}

/* The whole row is the switch's label, so all of it is the touch target. */
.share-switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 60px;
  cursor: pointer;
}

.share-switch-label {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
}

.share-switch-help {
  margin: -6px 0 12px;
}

/* A failed save, said right under its switch. */
.share-switch-error .form-error {
  margin: -4px 0 12px;
}

/* A real checkbox (role=switch), drawn as a switch: a moon-grey outline and
   knob when off, filled moon with a night knob when on. */
.share-switch-input {
  -webkit-appearance: none;
  appearance: none;
  position: relative;
  flex: none;
  width: 52px;
  height: 32px;
  margin: 0;
  border: 2px solid var(--moon-quiet);
  border-radius: 16px;
  background: var(--night-btn);
  cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease;
}

.share-switch-input::before {
  content: '';
  position: absolute;
  top: 4px;
  left: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--moon-quiet);
  transition: transform 150ms ease;
}

.share-switch-input:checked {
  border-color: var(--moon);
  background: var(--moon);
}

.share-switch-input:checked::before {
  transform: translateX(20px);
  background: var(--night);
}

.share-off-line {
  margin: 6px 0 8px;
  font-size: 17px;
  font-weight: 600;
}

/* ---------- the link view (/a/:token), gallery.html's third phone ---------- */

.link-page {
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: calc(36px + env(safe-area-inset-bottom, 0px));
}

.link-head {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(36px + env(safe-area-inset-top, 0px)) calc(20px + env(safe-area-inset-right, 0px)) 0
    calc(20px + env(safe-area-inset-left, 0px));
}

.link-from {
  margin: 0;
  font-size: 15px;
  color: var(--moon-quiet);
}

.link-from b {
  color: var(--moon);
  font-weight: 600;
}

.link-head .title {
  margin: 12px 0 0;
  font-size: 31px;
  overflow-wrap: anywhere;
}

.link-safe {
  display: flex;
  gap: 8px;
  margin: 10px 0 0;
  font-size: 15px;
  line-height: 1.38;
  color: var(--moon-quiet);
}

.link-safe b {
  color: var(--moon);
  font-weight: 500;
}

.link-lock {
  flex: none;
  width: 16px;
  height: 16px;
  margin-top: 2px;
  color: var(--moon);
}

.link-count {
  margin: 12px 0 0;
}

.link-add {
  max-width: 360px;
  margin-top: 14px;
  white-space: nowrap;
}

.link-page .gallery-grid {
  margin-top: 14px;
}

.link-end {
  max-width: 480px;
  margin: 0 auto;
  padding: 24px calc(20px + env(safe-area-inset-right, 0px)) 0 calc(20px + env(safe-area-inset-left, 0px));
  text-align: center;
}

.link-end[hidden] {
  display: none;
}

.link-end-line {
  margin: 0;
  font-size: 16px;
  font-weight: 500;
  color: var(--moon);
}

.link-save {
  margin-top: 14px;
  white-space: nowrap;
}

.link-own {
  margin: 18px 0 0;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 15px;
  color: var(--moon-quiet);
}

/* The wordmark, as a link to /about: the mark's own look, no underline. */
.link-own .mark {
  margin-left: 2px;
  font-size: 17px;
  text-decoration: none;
}

/* Opening, a failed first load, and a link that's off. */
.link-status {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(40px + env(safe-area-inset-top, 0px)) calc(20px + env(safe-area-inset-right, 0px)) 0
    calc(20px + env(safe-area-inset-left, 0px));
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 14px;
}

.link-status-title {
  font-size: 24px;
  max-width: 480px;
}

.link-status .btn {
  width: auto;
  padding: 0 28px;
}
