/* Share sheet (share.js): bottom sheet on phones, centered panel on wider screens */
html.sh-open { overflow: hidden; }

.share-sheet {
  width: min(460px, calc(100vw - 32px));
  max-height: min(88vh, 860px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-3);
  background: var(--white);
  color: var(--ink);
  box-shadow: var(--shadow-2);
  overflow: hidden;
  font-family: var(--f-ui);
}
.share-sheet[open] { display: flex; flex-direction: column; animation: sh-in var(--d-2) var(--ease-out); }
.share-sheet::backdrop { background: color-mix(in oklab, var(--night) 55%, transparent); backdrop-filter: blur(2px); }
@keyframes sh-in { from { opacity: 0; transform: translateY(12px) scale(.98); } }

.sh-grip { display: none; }
.sh-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s-3); padding: var(--s-4) var(--s-5) var(--s-2); }
.sh-head h2:focus { outline: none; }
.sh-head h2 { margin: 0; font-family: var(--f-ui); font-size: var(--t-lg); font-weight: 600; }
.sh-close {
  display: grid; place-items: center; width: 44px; height: 44px; margin-inline-end: calc(var(--s-3) * -1);
  border: 0; border-radius: var(--r-pill); background: transparent; color: var(--ink-60); cursor: pointer;
}
.sh-close:hover { background: var(--paper-2); color: var(--ink); }
.sh-scroll { overflow-y: auto; padding: var(--s-2) var(--s-5) var(--s-5); overscroll-behavior: contain; }

/* quote image preview */
.sh-card { margin: 0 0 var(--s-4); }
.sh-canvas { display: grid; place-items: center; padding: var(--s-3); border-radius: var(--r-3); background: var(--paper-2); }
.sh-canvas canvas { display: block; max-width: 100%; max-height: 32vh; width: auto; height: auto; border-radius: var(--r-2); box-shadow: var(--shadow-1); }
.sh-sizes { display: flex; justify-content: center; gap: var(--s-1); margin-top: var(--s-3); }
.sh-sizes button {
  min-height: 36px; padding: 0 var(--s-4); border: 1px solid var(--line-2); border-radius: var(--r-pill);
  background: transparent; color: var(--ink-60); font: inherit; font-size: var(--t-sm); cursor: pointer;
}
.sh-sizes button[aria-checked="true"] { background: var(--ink); border-color: var(--ink); color: var(--paper); }

/* quote text when there is no image */
.sh-quote { margin: 0 0 var(--s-4); padding: var(--s-3) var(--s-4); border-inline-start: 3px solid var(--sky); border-radius: var(--r-2); background: var(--paper-2); }
.sh-quote p { margin: 0; font-family: var(--f-read); font-size: var(--t-md); line-height: 1.9; display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
.sh-quote cite { display: block; margin-top: var(--s-2); font-style: normal; font-size: var(--t-xs); color: var(--ink-60); }
.sh-quote cite:empty { display: none; }

/* clip editor */
.sh-clip { margin-bottom: var(--s-4); }
.sh-clip-row { display: grid; grid-template-columns: 1fr auto 1fr auto; gap: var(--s-2); align-items: end; }
.sh-time { display: grid; gap: var(--s-1); font-size: var(--t-xs); color: var(--ink-60); }
.sh-time input {
  width: 100%; min-height: 44px; padding: 0 var(--s-3); border: 1px solid var(--line-2); border-radius: var(--r-2);
  background: var(--white); color: var(--ink); font: 500 var(--t-md) var(--f-ui); text-align: center;
}
.sh-time input:focus-visible { outline: 2px solid var(--sky); outline-offset: 1px; }
.sh-now {
  min-height: 44px; padding: 0 var(--s-3); border: 1px solid var(--line-2); border-radius: var(--r-2);
  background: var(--paper-2); color: var(--sky-ink); font: inherit; font-size: var(--t-sm); cursor: pointer;
}
.sh-clip-len { margin: var(--s-2) 0 0; font-size: var(--t-xs); }
.sh-clip-len.is-err { color: var(--danger); }

/* targets */
.sh-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s-2) var(--s-1); }
.sh-t {
  display: grid; justify-items: center; align-content: start; gap: 6px; min-height: 44px; padding: var(--s-2) 2px;
  border: 0; border-radius: var(--r-3); background: transparent; color: var(--ink-80);
  font: inherit; font-size: var(--t-xs); line-height: 1.3; text-align: center; cursor: pointer;
}
.sh-t[hidden] { display: none; }
.sh-t:hover .sh-ic, .sh-t:focus-visible .sh-ic { transform: translateY(-2px); }
.sh-t:focus-visible { outline: 2px solid var(--sky); outline-offset: 2px; }
.sh-ic {
  display: grid; place-items: center; width: 48px; height: 48px; border-radius: var(--r-pill);
  background: var(--paper-2); color: var(--ink); transition: transform var(--d-1) var(--ease-out);
}
.sh-ic-whatsapp { background: #25D366; color: #fff; }
.sh-ic-x { background: #000; color: #fff; }
.sh-ic-telegram { background: #229ED9; color: #fff; }
.sh-ic-facebook { background: #1877F2; color: #fff; }
.sh-ic-linkedin { background: #0A66C2; color: #fff; }
.sh-ic-native, .sh-ic-image { background: var(--sky); color: var(--white); }
.sh-ic-download { background: var(--ink); color: var(--paper); }

.sh-link {
  display: flex; align-items: center; gap: var(--s-2); margin-top: var(--s-4); padding: 4px 4px 4px var(--s-3);
  border: 1px solid var(--line-2); border-radius: var(--r-pill); background: var(--paper);
}
.sh-link .sh-ic { width: 32px; height: 32px; background: transparent; color: var(--ink-60); flex: none; }
.sh-link input { flex: 1; min-width: 0; border: 0; background: transparent; color: var(--ink-60); font: var(--t-sm) var(--f-ui); text-overflow: ellipsis; }
.sh-link input:focus { outline: none; }
.sh-link .btn { flex: none; min-height: 40px; border-radius: var(--r-pill); }

/* floating button for a text selection */
.sh-fab {
  position: fixed; top: 0; left: 0; z-index: 90;
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 var(--s-4);
  border: 0; border-radius: var(--r-pill); background: var(--ink); color: var(--paper);
  font: 500 var(--t-sm) var(--f-ui); box-shadow: var(--shadow-2); cursor: pointer;
  animation: sh-fab var(--d-1) var(--ease-out);
}
.sh-fab[hidden] { display: none; }
.sh-fab .icon { color: var(--sky); }
@keyframes sh-fab { from { opacity: 0; } }

/* page hooks: shared clip range, shared tweet, result share link */
.transcript-chunk.in-clip { background: color-mix(in oklab, var(--sky) 12%, transparent); box-shadow: inset -3px 0 0 var(--sky); }
.tw-card.is-target, .tw-card:target { outline: 2px solid var(--sky); outline-offset: 4px; }
.share-btn { display: inline-flex; align-items: center; gap: 4px; border: 0; background: none; font: inherit; cursor: pointer; min-height: 44px; }
.rag-saved-note { margin-top: var(--s-5); font-size: var(--t-xs); text-align: center; }

@media (max-width: 640px) {
  .share-sheet {
    width: 100%; max-width: 100%; max-height: 92vh; margin: auto 0 0;
    border-radius: 18px 18px 0 0; border-bottom: 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .share-sheet[open] { animation-name: sh-up; }
  @keyframes sh-up { from { transform: translateY(100%); } }
  .sh-grip { display: block; width: 40px; height: 4px; margin: 10px auto 0; border-radius: 4px; background: var(--line-2); }
  .sh-head { padding-top: var(--s-2); }
  .sh-canvas canvas { max-height: 34vh; }
  .sh-clip-row { grid-template-columns: 1fr auto; }
}

@media (prefers-reduced-motion: reduce) {
  .share-sheet[open], .sh-fab { animation: none; }
  .sh-ic { transition: none; }
}

/* episode player bar: the clip sheet also copies a timed link, so the copy button yields on narrow phones */
@media (max-width: 400px) {
  .player-bar #copyAtTime { display: none; }
  .player-bar #clipBtn span { display: none; }
}

/* ── Designed sheet: night header with girih + what is being shared, tiles, link bar ── */
.share-sheet { border: 0; border-radius: 22px; box-shadow: 0 40px 90px -30px rgba(3, 16, 26, .55), 0 0 0 1px color-mix(in oklab, var(--sky) 18%, transparent); }
.sh-head { position: relative; isolation: isolate; overflow: hidden; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: var(--s-3);
  padding: var(--s-5); background: linear-gradient(160deg, var(--night-2), var(--night)); color: var(--on-night); }
.sh-head .girih { opacity: .12; }
.sh-badge { display: grid; place-items: center; inline-size: 44px; block-size: 44px; border-radius: 14px; background: var(--sky); color: var(--night); }
.sh-head-t { min-inline-size: 0; }
.sh-head h2 { color: var(--on-night); font-size: var(--t-md); }
.sh-sub { margin: 2px 0 0; color: var(--on-night-2); font-size: var(--t-xs); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sh-sub:empty { display: none; }
.sh-head .sh-close { color: var(--on-night-2); background: color-mix(in oklab, var(--white) 8%, transparent); }
.sh-head .sh-close:hover { color: var(--on-night); background: color-mix(in oklab, var(--white) 16%, transparent); }
.sh-scroll { padding: var(--s-5); }
.sh-grid { gap: var(--s-2); }
.sh-t { gap: 8px; padding: var(--s-3) 2px var(--s-2); border: 1px solid var(--line); border-radius: 16px; background: var(--paper);
  transition: border-color var(--d-1), background var(--d-1), transform var(--d-1) var(--ease-out); }
.sh-t:hover { border-color: color-mix(in oklab, var(--sky) 45%, var(--line)); background: var(--white); transform: translateY(-2px); }
.sh-t:hover .sh-ic, .sh-t:focus-visible .sh-ic { transform: none; }
.sh-t:active { transform: scale(.97); }
.sh-t .sh-ic { width: 42px; height: 42px; border-radius: 13px; }
.sh-ic-email, .sh-ic-text { background: var(--sky-10); color: var(--sky-deep); }
.sh-link { margin-top: var(--s-5); padding: 5px; padding-inline-start: var(--s-3); border-color: var(--line); background: var(--paper-2); }
.sh-link:focus-within { border-color: var(--sky); }
.sh-link .btn { padding-inline: 1.2em; }
@media (max-width: 640px) {
  .share-sheet { border-radius: 22px 22px 0 0; }
  .sh-head { padding-top: var(--s-5); }
  .sh-head::before { content: ""; position: absolute; inset-block-start: 8px; inset-inline-start: 50%; translate: 50% 0; inline-size: 40px; block-size: 4px; border-radius: 4px; background: color-mix(in oklab, var(--white) 25%, transparent); }
}
@media (prefers-reduced-motion: reduce) { .sh-t { transition: none; } .sh-t:hover { transform: none; } }
/* English pages: the sheet follows the document direction; the few physical offsets above are mirrored here */
:root[dir="ltr"] .transcript-chunk.in-clip { box-shadow: inset 3px 0 0 var(--sky); }
@media (max-width: 640px) { :root[dir="ltr"] .sh-head::before { translate: -50% 0; } }
