/* The keep page is for understanding: its top in the keep's own color, with the title circled like a note on a
   board, then what Keepazoid wrote about it */

@layer components {
  .keep-hero {
    padding-bottom: 96px;
    border-radius: 0 0 64px 64px;
    background: var(--tint);
    box-shadow: 0 48px 160px rgb(0 0 0 / 8%);
    color: var(--tint-ink);

    @media (max-width: 699px) {
      padding-bottom: 32px;
      border-radius: 0 0 40px 40px;
    }
  }

  /* The keep's own line, under the site's header: where it is on the left, and on the right what can be done
     with it, the icons' marks ending on the column's edge */
  .keep-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    width: min(var(--page-width), 100% - 2 * var(--page-padding));
    min-height: 44px;
    margin-inline: auto;
  }

  .keep-bar__actions {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-inline: auto -10px;
  }

  .keep-bar__action {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    color: var(--tint-ink);
    transition: color 150ms ease, scale 160ms var(--ease-out-expo);

    .icon {
      width: 22px;
      height: 22px;
      stroke-width: 1.9;
    }

    @media (hover: hover) and (pointer: fine) {
      &:hover {
        color: color-mix(in srgb, var(--tint-ink) 70%, var(--tint));
      }
    }

    &:active {
      scale: 0.88;
    }

    @media (prefers-reduced-motion: reduce) {
      transition: none;

      &:active {
        scale: none;
      }
    }
  }

  /* Text on the left with its actions under it, the picture on the right; one column on a phone */
  .keep-hero__body {
    display: grid;
    grid-template-columns: minmax(0, 600px) minmax(0, 540px);
    grid-template-areas: "text picture" "actions picture";
    align-items: start;
    justify-content: space-between;
    column-gap: 32px;
    width: min(var(--page-width), 100% - 2 * var(--page-padding));
    margin-inline: auto;
    padding-top: 40px;

    &:not(:has(.keep-hero__picture)) {
      grid-template-areas: "text" "actions";
      grid-template-columns: minmax(0, 720px);
      justify-content: start;
    }

    @media (max-width: 899px) {
      grid-template-columns: minmax(0, 1fr);
      grid-template-areas: "text" "picture" "actions";
      padding-top: 8px;
    }
  }

  .keep-hero__text {
    grid-area: text;
    min-width: 0;
  }

  .breadcrumb {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    min-height: 44px;
    font: 400 var(--text-label) / 1.3 var(--font-mono);
    letter-spacing: 0.04em;
    text-transform: uppercase;

    a {
      text-decoration: underline 1px;
      text-underline-offset: 3px;
    }

    span {
      min-width: 0;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }

    span[aria-hidden] {
      flex-shrink: 0;
      opacity: 0.45;
    }
  }

  /* Big, and bigger the shorter it is; a short one gets a circle drawn around it */
  .keep-title {
    position: relative;
    display: inline-block;
    max-width: 100%;
    font-size: var(--keep-title-size);
    line-height: 0.88;
    font-weight: 600;
    letter-spacing: -0.06em;
    overflow-wrap: anywhere;

    span {
      position: relative;
    }
  }

  /* Pulled left a touch, so the first letter's curve lines up with the text below it */
  .keep-title--short {
    --keep-title-size: var(--text-hero);

    margin: 30px 0 44px -0.075em;
    line-height: 0.85;

    @media (max-width: 699px) {
      margin: 24px 0 28px -0.06em;
      line-height: 0.88;
    }
  }

  .keep-title--medium {
    --keep-title-size: calc(72 * var(--pt));

    margin: 16px 0 4px;
    line-height: 0.95;
    letter-spacing: -0.05em;

    @media (max-width: 699px) {
      --keep-title-size: calc(44 * var(--pt));
    }
  }

  .keep-title--long {
    --keep-title-size: calc(48 * var(--pt));

    margin: 16px 0 4px;
    line-height: 1.04;
    letter-spacing: -0.04em;

    @media (max-width: 699px) {
      --keep-title-size: calc(32 * var(--pt));
    }
  }

  /* Placed as in the design: a 613 by 176 circle around a 477 by 102 title */
  .keep-title__scribble {
    position: absolute;
    top: -33.3%;
    left: -8.4%;
    width: 128.5%;
    height: 172.5%;
    overflow: visible;
    fill: none;
    stroke: currentColor;
    stroke-width: 4.5;
    stroke-linecap: round;
    stroke-linejoin: round;

    /* Closer in on a phone, a 352 by 106 circle around a 270 by 60 title, so it stays on the screen */
    @media (max-width: 699px) {
      top: -33%;
      left: -5.9%;
      width: 130%;
      height: 177%;
      stroke-width: 3.2;
    }
  }

  .facts {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 12px;
    padding-top: 24px;

    @media (max-width: 699px) {
      gap: 8px;
      padding-top: 16px;
    }
  }

  .fact {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    height: 32px;
    padding: 0 16px 0 12px;
    border-radius: 40px;
    background: color-mix(in srgb, currentColor 8%, transparent);
    font: 500 var(--text-label) / 1.3 var(--font-mono);
    letter-spacing: 0.06em;
    text-transform: uppercase;

    .icon {
      width: 15px;
      height: 15px;
      stroke-width: 1.8;
    }

    > span:last-child {
      min-width: 0;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }

    @media (max-width: 699px) {
      padding: 0 14px 0 11px;
    }
  }

  .keep-hero__description {
    max-width: 480px;
    padding-top: 28px;
    font: 400 var(--text-prose) / 1.7 var(--font-mono);

    @media (max-width: 699px) {
      padding-top: 18px;
    }
  }

  .keep-hero__actions {
    grid-area: actions;
    position: relative;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    padding-top: 40px;

    .btn {
      --btn-border: var(--tint-ink);
      --btn-hover-background: color-mix(in srgb, var(--tint-ink) 8%, transparent);
      --btn-color: var(--tint-ink);
    }

    .btn--primary {
      --btn-background: var(--tint-ink);
      --btn-hover-background: color-mix(in srgb, var(--tint-ink) 86%, var(--tint));
      --btn-color: var(--tint-ink-inverse);
    }

    /* The one action fills the row on a phone */
    @media (max-width: 899px) {
      padding-top: 24px;

      .keep-hero__open {
        flex: 1 0 100%;
        order: -1;
      }
    }
  }

  /* A print pinned to the board, with the price when saved on a sticker over its corner */
  .keep-hero__picture {
    grid-area: picture;
    position: relative;
    padding: 4px 0 40px;

    @media (max-width: 899px) {
      padding: 28px 0 40px;
    }
  }

  .picture {
    position: relative;
    aspect-ratio: 540 / 284;
    overflow: clip;
    rotate: 2deg;
    transform-origin: 0 0;
    border: 1px solid rgb(0 0 0 / 10%);
    border-radius: 24px;
    background: color-mix(in srgb, currentColor 12%, transparent);
    box-shadow: var(--shadow-picture);

    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }

    @media (max-width: 699px) {
      rotate: 1.6deg;
      border-radius: 20px;
    }
  }

  .picture--cover img {
    object-fit: contain;
  }

  .picture__duration {
    position: absolute;
    right: 12px;
    bottom: 12px;
    padding: 4px 8px;
    border-radius: 8px;
    background: rgb(14 17 19 / 75%);
    color: #fbfaf4;
    font: 500 var(--text-label) / 1.3 var(--font-mono);
    font-variant-numeric: tabular-nums;
  }

  .price-sticker {
    position: relative;
    display: inline-flex;
    flex-direction: column;
    gap: 6px;
    rotate: -4deg;
    transform-origin: 0 0;
    padding: 18px 24px 18px 22px;
    border: 1px solid rgb(0 0 0 / 10%);
    border-radius: 20px;
    background: #fbfaf4;
    box-shadow: var(--shadow-sticker);
    color: #0e1113;

    .picture + & {
      position: absolute;
      bottom: 6px;
      left: -32px;
    }

    @media (max-width: 699px) {
      gap: 4px;
      padding: 14px 18px 14px 16px;
      border-radius: 18px;

      .picture + & {
        left: -6px;
        bottom: 8px;
      }
    }
  }

  .price-sticker__price {
    display: flex;
    align-items: baseline;
    gap: 6px;
    font-size: var(--text-button);
    font-weight: 500;
    letter-spacing: -0.02em;

    strong {
      font-size: calc(40 * var(--pt));
      line-height: 1.05;
      font-weight: 600;
      letter-spacing: -0.045em;
      font-variant-numeric: tabular-nums;

      @media (max-width: 699px) {
        font-size: calc(32 * var(--pt));
      }
    }
  }

  .price-sticker__label {
    color: #57606a;
    font: 400 var(--text-label) / 1.3 var(--font-mono);
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  /* What Keepazoid wrote, on the page itself */
  .keep-body {
    width: min(var(--page-width), 100% - 2 * var(--page-padding));
    margin-inline: auto;
    padding-bottom: 96px;
  }

  .section {
    padding-top: 96px;

    &:first-child {
      padding-top: 112px;
    }

    @media (max-width: 699px) {
      padding-top: 56px;

      &:first-child {
        padding-top: 48px;
      }
    }
  }

  .keep-body__summary {
    max-width: 820px;
    padding-top: 28px;
    font: 400 var(--text-prose) / 1.7 var(--font-mono);

    @media (max-width: 699px) {
      padding-top: 20px;
    }
  }

  /* Key points as notes pinned beside each other, each with a dot in the keep's color */
  .points {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr));
    gap: 16px;
    padding-top: 32px;

    @media (max-width: 699px) {
      gap: 14px;
      padding-top: 24px;
    }
  }

  .point {
    display: flex;
    flex-direction: column;
    gap: 16px;
    rotate: var(--point-tilt, 0deg);
    padding: 24px 26px 28px;
    border: 1px solid var(--color-line);
    border-radius: 24px;
    background: color-mix(in srgb, var(--color-ink) 2.5%, transparent);
    font-size: var(--text-point);
    line-height: 1.29;
    font-weight: 600;
    letter-spacing: -0.025em;

    &:nth-child(3n + 1) { --point-tilt: -1.4deg; }
    &:nth-child(3n + 2) { --point-tilt: 1deg; }
    &:nth-child(3n + 3) { --point-tilt: -0.6deg; }

    &::before {
      content: "";
      width: 8px;
      height: 8px;
      border-radius: 50%;
      background: var(--tint);
    }

    @media (max-width: 699px) {
      gap: 12px;
      padding: 20px 22px 22px;
      border-radius: 22px;
      line-height: 1.32;
      letter-spacing: -0.02em;
    }
  }

  .keep-body__credit {
    padding-top: 36px;
    color: var(--color-ink-secondary);
    font: 400 var(--text-label) / 1.67 var(--font-mono);

    @media (max-width: 699px) {
      padding-top: 24px;
    }
  }

  /* Specifications beside the details board */
  .keep-body__facts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr));
    gap: 56px 48px;
  }

  .specifications {
    display: grid;
    gap: 10px;
    padding-top: 28px;

    li {
      display: grid;
      grid-template-columns: 7px minmax(0, 1fr);
      gap: 14px;
      font: 400 var(--text-spec) / 1.69 var(--font-mono);

      &::before {
        content: "";
        width: 7px;
        height: 7px;
        margin-top: 10px;
        border-radius: 50%;
        background: currentColor;
      }
    }

    @media (max-width: 699px) {
      gap: 8px;
      padding-top: 20px;

      li {
        grid-template-columns: 6px minmax(0, 1fr);
        gap: 12px;

        &::before {
          width: 6px;
          height: 6px;
        }
      }
    }
  }

  /* On a board tinted with the keep's color */
  .details {
    margin-top: 28px;
    padding: 8px 32px;
    border: 1px solid var(--color-line);
    border-radius: 32px;
    background: color-mix(in srgb, var(--tint) var(--tint-wash, 26%), var(--color-paper));

    @media (max-width: 699px) {
      margin-top: 20px;
      padding: 4px 22px;
      border-radius: 26px;
    }
  }

  .details__row {
    display: flex;
    align-items: baseline;
    gap: 16px;
    padding: 16px 0;

    & + & {
      border-top: 1px solid var(--color-line);
    }

    dt {
      flex: 0 0 120px;
      color: var(--color-ink-label);
      font: 400 var(--text-label) / 1.3 var(--font-mono);
      letter-spacing: 0.06em;
      text-transform: uppercase;
    }

    dd {
      min-width: 0;
      font-size: var(--text-detail);
      line-height: 1.41;
      font-weight: 500;
      letter-spacing: -0.01em;
      overflow-wrap: anywhere;
    }

    @media (max-width: 699px) {
      gap: 12px;
      padding: 13px 0;

      dt {
        flex-basis: 96px;
      }
    }
  }

  .details__link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: underline 1px;
    text-underline-offset: 4px;

    .icon {
      width: 14px;
      height: 14px;
      stroke-width: 2.2;
    }
  }

  .topics {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    padding-top: 28px;

    .btn {
      min-height: 54px;
      white-space: normal;
      text-align: start;
      overflow-wrap: anywhere;
    }

    @media (max-width: 699px) {
      gap: 10px;
      padding-top: 20px;

      .btn {
        min-height: 46px;
        padding: 0 16px;
        font-size: var(--text-control);
      }
    }
  }

  /* Reading, or couldn't read */
  .note {
    display: grid;
    justify-items: start;
    gap: 16px;
    margin-top: 72px;
    padding: 24px 28px;
    border-radius: 24px;
    background: var(--color-note);
    color: var(--color-note-ink);
    font: 400 var(--text-spec) / 1.69 var(--font-mono);

    @media (max-width: 699px) {
      margin-top: 40px;
      padding: 20px 22px;
    }
  }

  /* On a phone, Open waits at the foot of the screen once the one at the top has scrolled away */
  .sticky-action {
    display: none;
  }

  @media (max-width: 699px) {
    .sticky-action {
      position: fixed;
      z-index: 20;
      right: var(--page-padding);
      bottom: calc(24px + env(safe-area-inset-bottom));
      left: var(--page-padding);
      display: flex;
      opacity: 0;
      translate: 0 12px;
      pointer-events: none;
      transition: opacity 200ms ease, translate 260ms var(--ease-out-expo);
    }

    .sticky-action--visible {
      opacity: 1;
      translate: 0 0;
      pointer-events: auto;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .sticky-action {
      translate: none;
    }
  }
}
