/* Guest view of a shared page: header line, the sandboxed frame, a bottom bar and the comment sheet. From 320 px up.
   Every rule sits under .share-guest, because `stylesheet_link_tag :app` also loads this file.
   The colour tokens come from share/palette.css. */
.share-guest {
  color-scheme: light dark;
  margin: 0;
  block-size: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  font: 1rem/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;

  .share-guest__bar {
    flex: none;
    display: flex;
    flex-direction: column;
    gap: .25rem;
    padding: .5rem max(1ch, env(safe-area-inset-left)) .5rem max(1ch, env(safe-area-inset-right));
    padding-block-start: max(.5rem, env(safe-area-inset-top));
    border-block-end: 1px solid var(--line);
    background: var(--panel);
  }

  .share-guest__title {
    font-size: .95rem;
    line-height: 1.25;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .share-guest__tags {
    display: flex;
    flex-wrap: wrap;
    gap: .5ch;
  }

  .share-guest__tag {
    font-size: .8rem;
    padding: .05rem .6em;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--paper);
  }

  .share-guest__tag--accent {
    border-color: var(--accent);
    background: var(--accent-wash);
  }

  /* Shown on an older version only: a link to the guest view without ?v=. */
  .share-guest__newer {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    column-gap: 1ch;
    min-block-size: 2.75rem;
    align-content: center;
    padding: .25rem 1ch;
    border: 1px solid var(--accent);
    border-radius: .5rem;
    background: var(--accent-wash);
    color: inherit;
    text-decoration: none;

    span {
      font-size: .85rem;
      text-decoration: underline;
    }
  }

  .share-guest__frame {
    flex: 1 1 0;
    min-block-size: 0;
    inline-size: 100%;
    border: 0;
    display: block;
    background: #fff;
  }

  .share-guest__gone {
    margin: auto;
    padding: 2rem 2ch;
    max-inline-size: 40ch;

    h1 {
      font-size: 1.375rem;
      line-height: 1.2;
    }
  }

  /* Wraps frame, dock and sheet for the script; adds no box of its own. */
  .share-guest__view {
    display: contents;
  }

  /* Bottom bar, in thumb reach: the hint or "Markierung kommentieren" above a row of the comment count, the
     mode switch and the page comment. Without the script only the count and "Kommentieren" show. */
  .share-guest__dock {
    flex: none;
    display: grid;
    gap: .35rem;
    padding: .35rem max(1ch, env(safe-area-inset-right)) max(.4rem, env(safe-area-inset-bottom)) max(1ch, env(safe-area-inset-left));
    border-block-start: 1px solid var(--line);
    background: var(--panel);
  }

  .share-guest__dock-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1ch;
  }

  .share-guest__dock svg {
    flex: none;
    inline-size: 1.35rem;
    block-size: 1.35rem;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .share-guest__count,
  .share-guest__whole {
    display: inline-flex;
    align-items: center;
    gap: .4ch;
    min-block-size: 2.75rem;
    min-inline-size: 2.75rem;
    justify-content: center;
    color: inherit;
    font-weight: 600;
    text-decoration: none;
    border-radius: .5rem;
  }

  .share-guest__whole {
    color: var(--accent);
  }

  /* With the switch, the page comment is an icon on a phone: the switch needs the room. */
  @media (max-width: 30rem) {
    [data-bridge=ready] .share-guest__whole span {
      position: absolute;
      inline-size: 1px;
      block-size: 1px;
      overflow: hidden;
      clip-path: inset(50%);
      white-space: nowrap;
    }
  }

  .share-guest__hint {
    margin: 0;
    font-size: .85rem;
    line-height: 1.3;
    color: var(--muted);
    text-align: center;
  }

  .share-guest__mark {
    inline-size: 100%;
    animation: share-guest-rise .16s ease-out;
  }

  /* The mode switch: two segments, the current one filled. */
  .share-guest__modes {
    display: flex;
    margin: 0;
    padding: 3px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--paper);

    legend {
      position: absolute;
      inline-size: 1px;
      block-size: 1px;
      overflow: hidden;
      clip-path: inset(50%);
      white-space: nowrap;
    }

    label {
      display: inline-flex;
      align-items: center;
      gap: .45ch;
      min-block-size: calc(2.75rem - 8px);
      padding-inline: .8rem .95rem;
      border-radius: 999px;
      font-weight: 600;
      color: var(--muted);
      cursor: pointer;
      transition: background-color .15s ease, color .15s ease;
      -webkit-tap-highlight-color: transparent;
    }

    label:has(:checked) {
      background: var(--accent);
      color: #fff;
    }

    label:has(:focus-visible) {
      outline: 2px solid var(--accent);
      outline-offset: 2px;
    }

    input {
      position: absolute;
      opacity: 0;
      pointer-events: none;
    }

    .share-guest__fill {
      fill: currentColor;
      stroke: none;
    }
  }

  @keyframes share-guest-rise {
    from { opacity: 0; transform: translateY(.35rem); }
  }

  @media (prefers-reduced-motion: reduce) {
    .share-guest__mark { animation: none; }
    .share-guest__modes label { transition: none; }
  }

  .share-guest__button,
  input[type=submit] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-block-size: 2.75rem;
    padding: .4em 1.1em;
    border: 0;
    border-radius: .5rem;
    background: var(--accent);
    color: #fff;
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
  }

  /* The sheet. Hidden until a fragment inside it is the target, so it opens without a script. */
  .share-guest__sheet {
    display: none;
    position: fixed;
    inset: auto 0 0;
    margin-inline: auto;
    box-sizing: border-box;
    inline-size: 100%;
    max-inline-size: 40rem;
    /* --share-keyboard: what a phone's keyboard covers (the script sets it), so the field stays above it. */
    inset-block-end: var(--share-keyboard, 0px);
    max-block-size: calc(85dvh - var(--share-keyboard, 0px));
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: .75rem max(1ch, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1ch, env(safe-area-inset-left));
    border: 1px solid var(--line);
    border-radius: 1rem 1rem 0 0;
    background: var(--paper);
    box-shadow: 0 -.5rem 2rem rgb(0 0 0 / .2);

    &:target,
    &:has(:target),
    &.share-guest__sheet--open {
      display: block;
    }

    h2 {
      font-size: 1.15rem;
      margin: 0;
    }

    h3 {
      font-size: .85rem;
      margin: 1rem 0 .3rem;
      text-transform: uppercase;
      letter-spacing: .04em;
    }
  }

  /* Composing on a phone: the sheet holds the composer alone, so cut-out, quote and field share the screen. */
  @media (max-width: 63.99rem) {
    [data-state=composing] .share-guest__sheet > :not(.share-guest__sheet-head, .share-guest__compose) {
      display: none;
    }

    [data-state=composing] .share-guest__compose h3 {
      margin-block-start: .5rem;
    }
  }

  /* Wide screens: the sheet is a side panel and the page gives it room, so the frame stays fully usable. */
  @media (min-width: 64rem) {
    &:has(.share-guest__sheet:is(:target, :has(:target), .share-guest__sheet--open)) {
      padding-inline-end: 26rem;
    }

    .share-guest__sheet {
      inset: 0 0 0 auto;
      inline-size: 26rem;
      max-block-size: none;
      border-radius: 0;
      border-block: 0;
      border-inline-end: 0;
      box-shadow: none;
    }
  }

  .share-guest__sheet-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1ch;

    a {
      color: var(--accent);
    }
  }

  .share-guest__error {
    padding: .5rem .75rem;
    border-radius: .5rem;
    border: 1px solid #b42318;
    background: color-mix(in oklab, #b42318 10%, var(--paper));
  }

  .share-guest__comment {
    margin-block: .6rem;
    padding: .7rem .8rem;
    border: 1px solid var(--line);
    border-radius: .75rem;
    scroll-margin-block-start: 1rem;

    &:target {
      border-color: var(--accent);
    }
  }

  .share-guest__comment-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .4rem .6rem;

    small {
      font-size: .8rem;
      opacity: .75;
    }
  }

  .share-guest__num {
    display: inline-grid;
    place-items: center;
    min-inline-size: 1.6rem;
    block-size: 1.6rem;
    border-radius: 99rem;
    background: var(--ink);
    color: var(--paper);
    font-size: .8rem;
    font-weight: 700;
  }

  .share-guest__chip {
    font-size: .8rem;
    font-weight: 600;

    &[data-state=resolved] {
      color: #2e7d32;
    }

    &[data-state=outdated] {
      opacity: .75;
    }
  }

  .share-guest__text {
    margin: .4rem 0;
    white-space: pre-line;
    overflow-wrap: anywhere;
  }

  .share-guest__reply {
    margin-block: .4rem;
    padding: .4rem .7rem;
    border-inline-start: 4px solid var(--line);
    border-radius: .5rem;
    background: var(--panel);
    overflow-wrap: anywhere;
  }

  .share-guest__note {
    font-size: .85rem;
    opacity: .8;
  }

  .share-guest__plain {
    min-block-size: 2.75rem;
    padding: .4em 0;
    border: 0;
    background: none;
    color: var(--accent);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
  }

  .share-guest__reply-form {
    display: flex;
    gap: .5ch;
    align-items: flex-end;
  }

  textarea {
    flex: 1 1 auto;
    box-sizing: border-box;
    inline-size: 100%;
    min-inline-size: 0;
    padding: .5rem;
    border: 1px solid var(--line);
    border-radius: .5rem;
    background: var(--paper);
    color: inherit;
    font: inherit;
    resize: vertical;
  }

  .share-guest__compose {
    form {
      display: grid;
      gap: .4rem;
      justify-items: start;
    }
  }

  /* The cut-out of a drawn region: a scaled copy of the frame's page, clipped to the box. */
  .share-guest__cutout {
    position: relative;
    overflow: hidden;
    max-inline-size: 100%;
    border: 2px solid var(--accent);
    border-radius: .5rem;
    background: #fff;
    box-shadow: 0 .25rem .9rem rgb(0 0 0 / .12);

    iframe {
      position: absolute;
      inset: 0 auto auto 0;
      border: 0;
      transform-origin: 0 0;
      pointer-events: none;
    }
  }

  /* A region in the comment list: its cut-out in place of the text. Until located the box is collapsed, never
     display: none, so the copy lays out at the frame's size. Once located it keeps its size, also while the copy
     is unloaded off screen. */
  .share-guest__cutout--listed {
    flex: 0 1 auto;
    margin-block-start: .3rem;
    border-width: 1px;
    border-color: var(--line);
    box-shadow: none;
  }

  .share-guest__cutout--listed:not([data-located]) {
    position: absolute;
    inline-size: 1px;
    block-size: 1px;
    border: 0;
    opacity: 0;
    pointer-events: none;
  }

  [data-bridge=ready] .share-guest__cutout--listed {
    cursor: pointer;
  }

  .share-guest__place:has(.share-guest__cutout--listed[data-located]) .share-guest__spot {
    display: none;
  }

  /* The quoted block in the composer, and a comment's spot in the list. */
  .share-guest__quote {
    justify-self: stretch;
    margin: 0;
    padding: .4rem .7rem;
    border-inline-start: 4px solid var(--accent);
    border-radius: .5rem;
    background: var(--panel);
    overflow-wrap: anywhere;

    small {
      display: block;
      font-weight: 600;
      opacity: .8;
    }

    small:empty {
      display: none;
    }
  }

  .share-guest__place {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    column-gap: 1ch;
  }

  .share-guest__spot {
    flex: 1 1 20ch;
    margin: .3rem 0 0;
    padding-inline-start: .6rem;
    border-inline-start: 3px solid var(--line);
    font-size: .85rem;
    overflow-wrap: anywhere;
  }

  [data-bridge=ready] .share-guest__spot {
    cursor: pointer;
  }

  .share-guest__lost {
    margin: .3rem 0 0;
    font-size: .85rem;
    color: #b42318;
  }

  [hidden] {
    display: none !important;
  }
}
