/* ==========================================================================
   ui-moments.css: tactile button & control interactions adapted from
   https://github.com/guanmo-ai/ui-moments (MIT License) for Keke Software.
   --------------------------------------------------------------------------
   Controls included:
     - .uim-pill / .uim-arrow-btn   Tactile press pill & clipped icon slide
     - .uim-dl                      Download Ring (pill -> SVG ring -> check)
     - .uim-copy                    Copy Button (clipboard -> check + roll swap)
     - .uim-send                    Paper Plane Send (pullback + launch + return)
     - .uim-ink                     Ink Switch (circular clip-path ink spill)
     - .uim-tabs / .uim-tab-leaf    Leaf Tabs (3D page-flip tab indicator)
     - .uim-plans / .uim-plan-ring  Plan Picker (spring-sliding outline + squash)
     - .uim-hold                    Hold to Confirm (fill + tremble + check)
     - .uim-todo                    Stroke Checklist (drawn check + strike)
     - .uim-bell                    Bell Toggle (pendulum swing + badge / slash)
     - .uim-magnet                  Magnet Grid (pointer-reactive dot matrix)
   ========================================================================== */

:root {
  --uim-spring: cubic-bezier(.3, 1.45, .5, 1);
  --uim-ease: cubic-bezier(.16, 1, .3, 1);
  --uim-press-ease: cubic-bezier(.2, .8, .2, 1);
  --uim-return-ease: cubic-bezier(.2, .9, .34, 1.16);
  --uim-press-dur: 45ms;
}

/* Base interactive pill (from ui-moments/actions.html) */
.uim-pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 46px;
  height: 46px;
  padding: 0 20px;
  border: 1px solid var(--line-strong);
  border-radius: 23px;
  background: var(--raised);
  color: var(--fg);
  box-shadow: var(--uim-shadow);
  font-family: var(--font-text);
  font-size: 0.9375rem;
  font-weight: 500;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition:
    scale .3s var(--uim-spring),
    background-color var(--dur-2) var(--ease-micro),
    color var(--dur-2) var(--ease-micro),
    border-color var(--dur-2) var(--ease-micro),
    opacity var(--uim-press-dur) var(--uim-press-ease);
}

.uim-pill:active {
  scale: .95;
  transition-duration: .1s;
}

@media (hover: hover) and (pointer: fine) {
  .uim-pill:hover {
    background: var(--raised-hover);
    border-color: var(--rail-strong);
  }
}

.uim-pill--primary {
  background: var(--fg);
  border-color: var(--fg);
  color: var(--bg);
}

@media (hover: hover) and (pointer: fine) {
  .uim-pill--primary:hover {
    background: color-mix(in oklab, var(--fg) 88%, var(--bg));
    border-color: color-mix(in oklab, var(--fg) 88%, var(--bg));
  }
}

.uim-pill--vermilion {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--on-brand);
}

@media (hover: hover) and (pointer: fine) {
  .uim-pill--vermilion:hover {
    background: color-mix(in oklab, var(--brand) 90%, #000);
    border-color: color-mix(in oklab, var(--brand) 90%, #000);
  }
}

.uim-pill svg {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Clipped sliding arrow inside static button box */
.uim-arrow-slot {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  overflow: clip;
  flex: none;
}

.uim-arrow-slot svg {
  grid-area: 1 / 1;
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: translate .36s var(--uim-ease);
}

.uim-arrow-slot svg:last-child {
  translate: -140% 140%;
}

@media (hover: hover) and (pointer: fine) {
  :is(.uim-pill, .nav-link, .archive-visit):hover .uim-arrow-slot svg:first-child {
    translate: 140% -140%;
  }
  :is(.uim-pill, .nav-link, .archive-visit):hover .uim-arrow-slot svg:last-child {
    translate: 0 0;
  }
}

/* Vertical text roll swap (.swap from ui-moments/actions.html) */
.uim-swap {
  display: grid;
  overflow: clip;
  line-height: 1.25;
}

.uim-swap > * {
  grid-area: 1 / 1;
  transition: translate .4s var(--uim-spring), opacity .25s;
}

.uim-swap > :last-child {
  translate: 0 115%;
  opacity: 0;
}

[data-done] .uim-swap > :first-child {
  translate: 0 -115%;
  opacity: 0;
}

[data-done] .uim-swap > :last-child {
  translate: 0 0;
  opacity: 1;
}

/* ---------- 1. Copy Button (.uim-copy) ---------- */
.uim-copy[data-done] {
  border-color: var(--fg);
}

.uim-copy-icon {
  display: grid;
  width: 18px;
  height: 18px;
  flex: none;
}

.uim-copy-icon svg {
  grid-area: 1 / 1;
  transition: scale .35s var(--uim-spring), opacity .2s;
}

.uim-copy-icon .check {
  stroke-width: 2.2;
  stroke-dasharray: 18;
  stroke-dashoffset: 18;
  transition: stroke-dashoffset .35s var(--uim-ease) .1s;
}

.uim-copy[data-done] .uim-copy-icon .clip {
  scale: .4;
  opacity: 0;
}

.uim-copy[data-done] .uim-copy-icon .check {
  stroke-dashoffset: 0;
}

/* ---------- 2. Paper Plane Send (.uim-send) ---------- */
.uim-send {
  min-width: 138px;
  background: var(--fg);
  border-color: var(--fg);
  color: var(--bg);
}

.uim-send-plane {
  display: grid;
  width: 18px;
  transition: width .35s var(--uim-spring), margin .35s var(--uim-spring), opacity .2s;
}

.uim-send[data-done] .uim-send-plane {
  width: 0;
  margin-right: -9px;
  opacity: 0;
}

.uim-send[data-done] {
  background: var(--raised);
  color: var(--fg);
  border-color: var(--fg);
}

/* ---------- 3. Download Ring (.uim-dl) ---------- */
.uim-dl {
  position: relative;
  width: var(--dl-width, 152px);
  padding: 0;
  overflow: hidden;
  transition:
    width .45s var(--uim-spring),
    scale .3s var(--uim-spring),
    color .3s,
    background-color .3s,
    border-color .3s;
}

.uim-dl[data-state="loading"],
.uim-dl[data-state="done"] {
  width: 46px;
}

.uim-dl-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding-inline: 16px;
  transition: opacity .2s;
  white-space: nowrap;
}

.uim-dl:not([data-state="idle"]) .uim-dl-label {
  opacity: 0;
}

.uim-dl-ring,
.uim-dl-check {
  position: absolute;
  inset: 0;
  margin: auto;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s .15s;
}

.uim-dl-ring {
  width: 32px;
  height: 32px;
  rotate: -90deg;
}

.uim-dl-ring circle {
  fill: none;
  stroke-width: 3;
}

.uim-dl-ring .track {
  stroke: var(--rail-strong);
}

.uim-dl-ring .bar {
  stroke: var(--brand);
  stroke-linecap: round;
  stroke-dasharray: 81.7;
  stroke-dashoffset: 81.7;
}

.uim-dl--primary .uim-dl-ring .track {
  stroke: color-mix(in oklab, var(--bg) 26%, transparent);
}

.uim-dl--primary .uim-dl-ring .bar {
  stroke: var(--brand);
}

.uim-dl[data-state="loading"] .uim-dl-ring {
  opacity: 1;
}

.uim-dl .uim-dl-check {
  width: 20px;
  height: 20px;
  stroke-width: 2.4;
  stroke-dasharray: 18;
  stroke-dashoffset: 18;
  transition: opacity .2s, stroke-dashoffset .35s var(--uim-ease) .1s;
}

.uim-dl[data-state="done"] {
  background: var(--fg);
  border-color: var(--fg);
  color: var(--bg);
}

.uim-dl[data-state="done"] .uim-dl-check {
  opacity: 1;
  stroke-dashoffset: 0;
}

/* ---------- 4. Ink Switch (.uim-ink) ---------- */
.uim-ink-wrap {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.uim-ink-tag {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--fg-2);
  transition: color var(--dur-2) var(--ease-micro);
}

.uim-ink-tag[data-active] {
  color: var(--fg);
}

.uim-ink {
  position: relative;
  width: 64px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  background: var(--rail);
  overflow: hidden;
  isolation: isolate;
  cursor: pointer;
  flex: none;
  -webkit-tap-highlight-color: transparent;
}

/* Ensure >= 44px touch target via invisible hit area */
.uim-ink::before {
  content: "";
  position: absolute;
  inset: -5px -4px;
}

.uim-ink-fill {
  position: absolute;
  inset: 0;
  background: var(--fg);
  clip-path: circle(0 at 18px 50%);
}

.uim-ink[aria-checked="true"] .uim-ink-fill {
  clip-path: circle(66px at 46px 50%);
}

.uim-ink-knob {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 26px;
  height: 26px;
  border-radius: 13px;
  background: var(--raised);
  box-shadow: var(--uim-shadow);
  transition: translate .52s var(--uim-spring);
}

.uim-ink-knob::after {
  position: absolute;
  inset: 9px;
  content: "";
  border-radius: 50% 50% 50% 50% / 58% 58% 42% 42%;
  background: var(--fg);
  transition: scale .42s var(--uim-spring) .22s;
}

.uim-ink[aria-checked="true"] .uim-ink-knob {
  translate: 28px 0;
  background: var(--bg);
}

.uim-ink[aria-checked="true"] .uim-ink-knob::after {
  scale: 0;
  transition-delay: 0s;
  transition-duration: .2s;
}

.uim-ink-splash i {
  position: absolute;
  top: 50%;
  left: 18px;
  width: 4px;
  height: 4px;
  margin: -2px;
  border-radius: 50%;
  background: var(--fg);
  opacity: 0;
  pointer-events: none;
}

@media (hover: hover) and (pointer: fine) {
  .uim-ink:hover .uim-ink-knob {
    box-shadow: var(--uim-shadow), 0 0 0 3px var(--rail);
  }
}

/* ---------- 5. Leaf Tabs (.uim-tabs) ---------- */
.uim-tabs {
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--rail);
  perspective: 320px;
}

.uim-tab-leaf {
  position: absolute;
  top: 4px;
  left: 4px;
  width: calc((100% - 8px) / 4);
  height: calc(100% - 8px);
  border-radius: 10px;
  background: var(--raised);
  border: 1px solid var(--line-strong);
  box-shadow: var(--uim-shadow);
  transform: translateX(calc(var(--index, 0) * 100%));
  backface-visibility: visible;
  pointer-events: none;
}

.uim-tabs [role="tab"] {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 8px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--fg-2);
  font-family: var(--font-text);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: color .25s .08s;
  -webkit-tap-highlight-color: transparent;
}

.uim-tabs [role="tab"][aria-selected="true"] {
  color: var(--fg);
  font-weight: 600;
}

.uim-tabs [role="tab"]:focus-visible {
  outline-offset: -2px;
}

.uim-tab-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--tab-hue, var(--fg));
  flex: none;
}

/* ---------- 6. Plan Picker (.uim-plans) ---------- */
.uim-plans {
  --plan-gap: 12px;
  --plan-cols: 4;
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--plan-cols), minmax(0, 1fr));
  gap: var(--plan-gap);
  margin: 0;
  padding: 0;
  border: 0;
}

.uim-plans label {
  position: relative;
  display: grid;
  align-content: space-between;
  gap: 10px;
  min-height: 126px;
  padding: 18px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background: var(--raised);
  cursor: pointer;
  transition: background-color .25s var(--ease-micro), border-color .25s var(--ease-micro);
}

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

.uim-plans input:focus-visible + .uim-plan-head {
  text-decoration: underline;
  text-underline-offset: 4px;
}

.uim-plan-ring {
  position: absolute;
  top: 0;
  left: 0;
  width: calc((100% - (var(--plan-cols) - 1) * var(--plan-gap)) / var(--plan-cols));
  height: 100%;
  border: 2px solid var(--fg);
  border-radius: 16px;
  pointer-events: none;
  z-index: 2;
  translate: calc(var(--plan-index, 0) * (100% + var(--plan-gap))) 0;
  transition: translate .5s var(--uim-spring);
}

.uim-plan-ring::after {
  position: absolute;
  top: -10px;
  right: -10px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  content: "✓";
  border-radius: 50%;
  background: var(--brand);
  color: var(--on-brand);
  font-size: 13px;
  font-weight: 700;
}

.uim-plan-ring[data-move] {
  animation: uim-ring-squash .5s var(--uim-ease);
}

@keyframes uim-ring-squash {
  40% { scale: 1.06 .95; }
}

@media (max-width: 56em) {
  .uim-plans {
    --plan-cols: 2;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  /* On 2x2 mobile/tablet grid, ring tracks via JS exact rect transform */
  .uim-plan-ring {
    width: var(--ring-w, calc((100% - var(--plan-gap)) / 2));
    height: var(--ring-h, 126px);
    translate: var(--ring-x, 0px) var(--ring-y, 0px);
  }
}

@media (max-width: 30em) {
  .uim-plans {
    --plan-cols: 1;
    grid-template-columns: 1fr;
  }
  .uim-plan-ring {
    width: 100%;
  }
}

/* ---------- 7. Hold to Confirm (.uim-hold) ---------- */
.uim-hold-wrap {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.uim-hold {
  --active-cursor: pointer;
  position: relative;
  display: inline-grid;
  place-items: center;
  width: var(--hold-width, 256px);
  height: 50px;
  padding: 0 20px;
  border: 1px solid var(--line-strong);
  border-radius: 25px;
  background: var(--raised);
  color: var(--fg);
  font-family: var(--font-text);
  font-size: 0.9375rem;
  font-weight: 500;
  overflow: hidden;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
  transition: width .55s var(--uim-spring), scale .25s var(--uim-spring), background-color .3s, color .3s, border-color .3s;
}

.uim-hold[data-holding] {
  scale: .965;
  border-color: var(--fg);
}

.uim-hold-fill {
  position: absolute;
  inset: 0;
  background: color-mix(in oklab, var(--brand) 22%, transparent);
  transform-origin: left center;
  scale: 0 1;
}

.uim-hold-label {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  transition: opacity .2s, filter .2s;
}

.uim-hold-label svg {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.uim-hold-check {
  position: absolute;
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 24;
  stroke-dashoffset: 24;
  transition: stroke-dashoffset .4s var(--uim-ease) .2s;
}

.uim-hold[data-done] {
  width: 50px;
  padding: 0;
  background: var(--fg);
  border-color: var(--fg);
  color: var(--bg);
}

.uim-hold[data-done] .uim-hold-label {
  opacity: 0;
  filter: blur(3px);
}

.uim-hold[data-done] .uim-hold-fill {
  opacity: 0;
}

.uim-hold[data-done] .uim-hold-check {
  stroke-dashoffset: 0;
}

.uim-hold-hint {
  margin: 0;
  min-height: 1.25em;
  font-size: 0.8125rem;
  color: var(--fg-2);
  opacity: 0;
  transition: opacity .25s;
}

.uim-hold-hint[data-show] {
  opacity: 1;
}

/* ---------- 8. Stroke Checklist (.uim-todo) ---------- */
.uim-todo {
  display: grid;
  gap: 4px;
  margin: 0;
  padding: 0;
  border: 0;
}

.uim-todo label {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: background-color .2s;
}

@media (hover: hover) and (pointer: fine) {
  .uim-todo label:hover {
    background: var(--raise);
  }
}

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

.uim-todo .box {
  display: grid;
  place-items: center;
  flex: none;
  width: 22px;
  height: 22px;
  border: 1.6px solid var(--fg-2);
  border-radius: 6px;
  transition: background-color .25s, border-color .25s;
}

.uim-todo .box svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: var(--bg);
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 18;
  stroke-dashoffset: 18;
  transition: stroke-dashoffset .3s var(--uim-ease) .05s;
}

.uim-todo .text {
  position: relative;
  font-size: 0.9375rem;
  color: var(--fg);
  transition: color .3s;
}

.uim-todo .text::after {
  position: absolute;
  left: -2px;
  right: -2px;
  top: 52%;
  height: 1.5px;
  content: "";
  border-radius: 2px;
  background: currentColor;
  transform: scaleX(0);
  transform-origin: left;
  transition: transform .38s var(--uim-ease) .12s;
}

.uim-todo input:checked + .box {
  background: var(--fg);
  border-color: var(--fg);
  animation: uim-todo-pop .4s var(--uim-spring);
}

.uim-todo input:checked + .box svg {
  stroke-dashoffset: 0;
}

.uim-todo input:checked ~ .text {
  color: var(--fg-2);
}

.uim-todo input:checked ~ .text::after {
  transform: scaleX(1);
}

.uim-todo input:focus-visible + .box {
  outline: 2px solid var(--fg);
  outline-offset: 3px;
}

@keyframes uim-todo-pop {
  0% { scale: .72; }
  60% { scale: 1.14; }
  100% { scale: 1; }
}

/* ---------- 9. Bell Toggle (.uim-bell) ---------- */
.uim-bell-wrap {
  display: inline-flex;
  align-items: center;
  gap: 14px;
}

.uim-bell {
  position: relative;
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background: var(--raised);
  box-shadow: var(--uim-shadow);
  color: var(--fg-2);
  cursor: pointer;
  flex: none;
  transition: color .3s, scale .3s var(--uim-spring), border-color .25s;
}

.uim-bell:active {
  scale: .93;
}

.uim-bell[aria-pressed="true"] {
  color: var(--fg);
  border-color: var(--fg);
}

.uim-bell svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  overflow: visible;
}

.uim-bell .body,
.uim-bell .clapper {
  transform-box: view-box;
  transform-origin: 12px 3px;
}

.uim-bell .slash {
  stroke-dasharray: 26;
  stroke-dashoffset: 26;
  transition: stroke-dashoffset .35s var(--uim-ease);
}

.uim-bell[aria-pressed="false"] .slash {
  stroke-dashoffset: 0;
}

.uim-bell-badge {
  position: absolute;
  top: -6px;
  right: -6px;
  display: grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border: 2px solid var(--bg);
  border-radius: 10px;
  background: var(--brand);
  color: var(--on-brand);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  transition: scale .35s var(--uim-spring);
}

.uim-bell[aria-pressed="false"] .uim-bell-badge {
  scale: 0;
}

/* ---------- 10. Magnet Grid (.uim-magnet) ---------- */
.uim-magnet {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  place-items: center;
  pointer-events: none;
}

.uim-magnet i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: color-mix(in oklab, var(--fg) 55%, var(--bg));
  opacity: calc(.22 + var(--p, 0) * .78);
  transform: translate(var(--x, 0px), var(--y, 0px)) scale(calc(1 + var(--p, 0) * 1.45));
  transition: transform .45s var(--uim-spring), opacity .3s, background-color .3s;
}

.uim-magnet i[data-near] {
  background: var(--brand);
}

/* Reduced motion parity (both OS media query and in-page [data-motion="reduce"]) */
@media (prefers-reduced-motion: reduce) {
  .uim-pill:active,
  .uim-hold[data-holding],
  .uim-bell:active { scale: none; }
  .uim-magnet i { transform: none !important; }
}

:root[data-motion="reduce"] .uim-pill:active,
:root[data-motion="reduce"] .uim-hold[data-holding],
:root[data-motion="reduce"] .uim-bell:active {
  scale: none;
}

:root[data-motion="reduce"] .uim-magnet i {
  transform: none !important;
}
