/*
 * Responsible for: how a moving guide looks: the drawn pointer, the ring of a press, the ring round the target, the
 * card: one bordered, tinted box with its heading, the step's sentence and, under them, "Skip" and "Next".
 *
 * Must never: take a press meant for the page beneath it (only the buttons of the card and of the notice can be pressed), move anything
 * of the page, animate anything but transform and opacity, or hold a colour, size or speed of its own beyond the
 * pointer's drawn geometry (values come from tokens.css).
 */

@layer kit {
  .ia-guide,
  .ia-guide * {
    box-sizing: border-box;
  }

  /* Over everything, popups and the notice included, and transparent to every press. */
  .ia-guide {
    position: fixed;
    inset: 0;
    z-index: calc(var(--z-notice) + 10);
    overflow: hidden;
    pointer-events: none;
    font-family: var(--sans);
    color: var(--ink);
    transition: opacity var(--move) var(--ease);
  }

  .ia-guide.is-leaving {
    opacity: 0;
  }

  /* The person has scrolled what the step points at out of sight: the ring and the pointer wait, unseen, until it is back. */
  .ia-guide.is-away .ia-guide-ring,
  .ia-guide.is-away .ia-guide-pointer {
    visibility: hidden;
  }

  /* The ring round the target: white next to it so it shows on dark squares, teal outside so it shows on pale ones. */
  .ia-guide-ring {
    position: fixed;
    left: 0;
    top: 0;
    border-radius: var(--r-md);
    box-shadow:
      0 0 0 2px var(--panel),
      0 0 0 4px var(--accent),
      0 0 0 10px color-mix(in srgb, var(--accent) 24%, transparent);
    opacity: 0;
    transition: opacity var(--move) var(--ease);
  }

  .ia-guide-ring.is-on {
    opacity: 1;
  }

  .ia-guide-ring.is-dim.is-on {
    opacity: 0.35;
  }

  /* The step's sentence, inside the card between its heading and its buttons, in the size of a voice. */
  .ia-guide-bubble {
    color: var(--ink);
    font-size: var(--guide-say);
    font-weight: 600;
    line-height: 1.35;
    opacity: 0;
    transition: opacity var(--move) var(--ease);
  }

  .ia-guide-bubble.is-on {
    opacity: 1;
  }

  /* The pointer. Its tip is the element's origin; the drawing hangs off it. */
  .ia-guide-pointer {
    position: fixed;
    left: 0;
    top: 0;
    width: 0;
    height: 0;
    opacity: 0;
    will-change: transform;
    transition: opacity var(--move) var(--ease);
  }

  .ia-guide-pointer.is-on {
    opacity: 1;
  }

  .ia-guide-art {
    position: absolute;
    left: 0;
    top: 0;
    display: block;
    transform-origin: 0 0;
    transition: transform var(--fast) var(--ease);
  }

  .ia-guide-art.is-down {
    transform: scale(0.84);
  }

  .ia-guide-arrow {
    display: block;
    width: var(--guide-arrow-w);
    max-width: none;
    height: var(--guide-arrow-h);
    margin: calc(var(--guide-arrow-w) * -0.12) 0 0 calc(var(--guide-arrow-w) * -0.12);
    fill: var(--panel);
    stroke: var(--ink);
    stroke-width: 1.2;
    stroke-linejoin: round;
    /* A light halo round the dark edge, then a soft shadow: it reads on every colour of the Map. */
    filter: drop-shadow(0 0 1.5px var(--panel)) drop-shadow(0 0 1.5px var(--panel)) drop-shadow(0 3px 5px color-mix(in srgb, var(--ink) 50%, transparent));
  }

  .ia-guide-fingertip {
    display: block;
    width: var(--guide-finger);
    height: var(--guide-finger);
    margin: calc(var(--guide-finger) / -2) 0 0 calc(var(--guide-finger) / -2);
    border: 5px solid var(--panel);
    border-radius: var(--r-pill);
    background: color-mix(in srgb, var(--ink) 34%, transparent);
    box-shadow: var(--shadow-2);
  }

  .ia-guide-pointer--touch .ia-guide-art.is-down {
    transform: scale(0.8);
  }

  /* The ring that spreads from a press. */
  .ia-guide-ripple {
    position: fixed;
    left: 0;
    top: 0;
    width: 0;
    height: 0;
  }

  .ia-guide-ripple::after {
    content: "";
    position: absolute;
    left: calc(var(--guide-ripple) / -2);
    top: calc(var(--guide-ripple) / -2);
    width: var(--guide-ripple);
    height: var(--guide-ripple);
    border-radius: var(--r-pill);
    border: 3px solid var(--panel);
    box-shadow: 0 0 0 2px var(--accent);
    opacity: 0;
    animation: ia-guide-ripple var(--slow) var(--ease) both;
  }

  @keyframes ia-guide-ripple {
    from { opacity: 0.9; transform: scale(0.3); }
    60% { opacity: 0.6; }
    to { opacity: 0; transform: scale(1.7); }
  }

  @keyframes ia-guide-card-in {
    from { opacity: 0; transform: translateY(var(--s-2)); }
  }

  /* The card: at the foot of the window, above the phone's home bar; just above a target that is down there, and at the top only when there is no room above it. */
  .ia-guide-card {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(var(--s-4) + env(safe-area-inset-bottom));
    width: min(30rem, calc(100% - 2 * var(--s-4)));
    margin-inline: auto;
    /* One box that reads as a box on a white page: a border, a quiet tint, the words first and its buttons inside under them. */
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: var(--s-3);
    padding: var(--s-4);
    border: 2px solid var(--accent);
    border-radius: var(--r-lg);
    background: var(--tint);
    box-shadow: var(--shadow-2);
    animation: ia-guide-card-in var(--move) var(--ease) both;
  }

  .ia-guide-card[data-edge="top"] {
    bottom: auto;
    top: calc(var(--head-h) + var(--s-2) + env(safe-area-inset-top));
  }

  /* Just above what is pointed at, when that is down at the foot: the place is set in the script. */
  .ia-guide-card[data-edge="above"] {
    bottom: auto;
    top: var(--ia-guide-card-top);
  }

  .ia-guide-info {
    min-width: 0;
  }

  .ia-guide-title {
    font-size: var(--t-lg);
    font-weight: 600;
    line-height: 1.3;
  }

  .ia-guide-progress {
    display: flex;
    align-items: center;
    gap: var(--s-2);
    margin-top: var(--s-1);
    color: var(--muted);
    font-size: var(--t-md);
    line-height: 1.2;
  }

  .ia-guide-dots {
    display: inline-flex;
    gap: var(--s-1);
  }

  .ia-guide-dot {
    width: 6px;
    height: 6px;
    border-radius: var(--r-pill);
    background: var(--rule);
  }

  .ia-guide-dot.is-now {
    background: var(--accent);
  }

  .ia-guide-buttons {
    display: flex;
    flex: none;
    justify-content: flex-end;
    gap: var(--s-2);
  }

  /* On the card's tint the quiet button stands on the panel colour, so it still shows as a button. */
  .ia-guide-card .ia-guide-skip {
    background: var(--panel);
    box-shadow: inset 0 0 0 1px var(--rule);
  }

  /* The only pressable things in the guide are the card's two buttons and the notice's two. */
  .ia-guide-skip,
  .ia-guide-next,
  .ia-guide-start,
  .ia-guide-pass {
    appearance: none;
    flex: none;
    min-width: var(--tap);
    min-height: var(--tap);
    margin: 0;
    padding: 0 var(--s-4);
    border: 0;
    border-radius: var(--r-pill);
    font: 600 var(--t-lg) / 1 var(--sans);
    cursor: pointer;
    pointer-events: auto;
  }

  .ia-guide-skip,
  .ia-guide-pass {
    background: var(--tint);
    color: var(--accent-strong);
  }

  .ia-guide-next,
  .ia-guide-start {
    background: var(--accent);
    color: var(--on-accent);
  }

  .ia-guide-skip:hover,
  .ia-guide-pass:hover {
    background: var(--hover);
  }

  .ia-guide-next:hover,
  .ia-guide-start:hover {
    background: var(--accent-strong);
  }

  .ia-guide-skip:focus-visible,
  .ia-guide-next:focus-visible,
  .ia-guide-start:focus-visible,
  .ia-guide-pass:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
  }

  /* The notice: in the middle of the screen, before anything of the guide is drawn. */
  .ia-guide-notice {
    position: fixed;
    /* Centred in the window both ways, inside the phone's safe margins. */
    top: max(var(--s-4), env(safe-area-inset-top));
    right: max(var(--s-4), env(safe-area-inset-right));
    bottom: max(var(--s-4), env(safe-area-inset-bottom));
    left: max(var(--s-4), env(safe-area-inset-left));
    width: auto;
    max-width: 26rem;
    height: fit-content;
    max-height: 100%;
    overflow-y: auto;
    margin: auto;
    padding: var(--s-5);
    border-radius: var(--r-lg);
    background: var(--panel);
    box-shadow: var(--shadow-2), 0 0 0 1px var(--rule);
    pointer-events: auto;
  }

  /* The dimmed screen behind the notice: over the whole window, takes no press, comes in quickly. */
  .ia-guide-dim {
    position: fixed;
    inset: 0;
    background: color-mix(in srgb, var(--ink) var(--guide-dim), transparent);
    pointer-events: none;
    animation: ia-guide-dim-in var(--guide-fade) linear both;
  }

  @keyframes ia-guide-dim-in {
    from { opacity: 0; }
  }

  .ia-guide-notice:focus {
    outline: none;
  }

  .ia-guide-notice-title {
    font-size: var(--t-xl);
    font-weight: 600;
    line-height: 1.25;
  }

  .ia-guide-notice-body {
    margin-top: var(--s-3);
    font-size: var(--t-lg);
    line-height: 1.45;
  }

  .ia-guide-notice-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: var(--s-2);
    margin-top: var(--s-5);
  }

  /* Heard, not seen: the bubble shows the same sentence to the eye. */
  .ia-guide-live {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  @media (prefers-reduced-motion: reduce) {
    .ia-guide-ripple::after,
    .ia-guide-dim,
    .ia-guide-card {
      animation: none;
    }
  }
}
