/* ==========================================================================
   Journal reminders (js/components/nudges.js): one small bubble above the
   assistant's pill, once a day - a quiet title, up to three lines, a close
   button.
   The operator 31.10: "a bubble, not a table - delicate, like the field we
   type a message in", then "make it glass". So it has the composer field's
   shape (.help__input: 22px round, a hairline ring, a small tail toward the
   pill) in glass, as the pill and the composer's dock are made: a thin tint
   over a blur of the page. The lines are plain text, no box and no rule
   between them. No shadow, no glow, no pulse, no gradient, no new colour.
   ========================================================================== */

.nudges {
  --nudges-dur: 260ms; /* the help pill's and hint's */
  --nudges-bg: rgba(49, 49, 54, 0.55); /* the dark field (--tile-2), thinned */
  --nudges-ring: rgba(255, 255, 255, 0.1);
  --nudges-glass: blur(24px) saturate(180%);
  position: fixed;
  right: var(--space-4);
  bottom: calc(var(--space-4) + env(safe-area-inset-bottom) + 44px + 14px);
  /* The page's furniture, like the pill and the hint: under a Modal's backdrop and the drawers. */
  z-index: calc(var(--z-drawer-backdrop) - 1);
  width: min(300px, calc(100vw - 2 * var(--space-4)));
  padding: 10px 6px 10px var(--space-4);
  border-radius: 22px;
  background: var(--nudges-bg);
  -webkit-backdrop-filter: var(--nudges-glass);
  backdrop-filter: var(--nudges-glass);
  box-shadow: 0 0 0 1px var(--nudges-ring);
  color: var(--color-text-primary);
  font-size: var(--fs-footnote);
  line-height: 1.4;
  opacity: 0;
  transform: translateY(8px);
  transform-origin: bottom right;
  transition: opacity var(--nudges-dur) var(--ease-spring), transform var(--nudges-dur) var(--ease-spring);
}

/* Light theme: white glass, a darker hairline. */
:root[data-theme="light"] .nudges {
  --nudges-bg: rgba(255, 255, 255, 0.6);
  --nudges-ring: rgba(0, 0, 0, 0.08);
}

/* A browser without the blur gets the solid field, so the words never sit on a busy page through thin glass. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .nudges {
    --nudges-bg: var(--field-bg);
  }

  :root[data-theme="light"] .nudges {
    --nudges-bg: #ffffff;
  }
}

/* The tail: a small turned square of the same glass, cut to the half below the bubble (glass over glass would show
   a darker seam), its two outer edges ringed; its centre over the pill's (the pill's centre is 38px from the screen's
   edge on a computer and a phone; the bubble's edge 16px). */
.nudges::after {
  content: "";
  position: absolute;
  right: 16px;
  bottom: -6px;
  width: 12px;
  height: 12px;
  border-bottom-right-radius: 3px;
  background: var(--nudges-bg);
  -webkit-backdrop-filter: var(--nudges-glass);
  backdrop-filter: var(--nudges-glass);
  box-shadow: inset -1px -1px 0 0 var(--nudges-ring);
  clip-path: polygon(100% 0, 100% 100%, 0 100%);
  transform: rotate(45deg);
}

.nudges.is-shown {
  opacity: 1;
  transform: none;
}

.nudges__head {
  display: flex;
  align-items: center;
  margin-bottom: 2px;
}

.nudges__title {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  font-size: var(--fs-caption);
  font-weight: var(--fw-medium);
  color: var(--color-text-tertiary);
}

.nudges__x {
  flex: none;
  width: 28px;
  height: 28px;
  margin: -6px 0 -6px 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--color-text-tertiary);
  font: inherit;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.nudges__x:hover {
  color: var(--color-text-primary);
}

.nudges__list {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  list-style: none;
}

.nudges__row {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  width: 100%;
  min-height: 30px;
  padding: 4px 10px 4px 0;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--color-text-secondary);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.nudges__text {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
}

.nudges__chev {
  flex: none;
  color: var(--color-text-tertiary);
  line-height: 1;
}

@media (hover: hover) and (pointer: fine) {
  .nudges__row:hover {
    color: var(--color-text-primary);
  }

  .nudges__row:hover .nudges__chev {
    color: var(--color-text-secondary);
  }
}

.nudges__row:focus-visible,
.nudges__x:focus-visible {
  outline: 2px solid var(--lead);
  outline-offset: 0;
}

/* A finger needs the full 44px, the bubble stays as it is otherwise. */
@media (pointer: coarse) {
  .nudges__row {
    min-height: 44px;
    align-items: center;
  }

  .nudges__x {
    width: 44px;
    height: 44px;
    margin: -12px -6px -12px 0;
  }
}

/* Phone: above the round pill, which sits above the bottom bar (as .help-hint), with the 16px gutter. */
@media (max-width: 880px) {
  .nudges {
    right: max(var(--space-4), calc(50% - 260px));
    bottom: calc(var(--bottom-nav-gap, 8px) + var(--bottom-nav-h, 56px) + 12px + 48px + 14px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .nudges {
    transition-duration: 1ms;
  }
}
