/* ============================================================================
   Notely interaction layer
   ----------------------------------------------------------------------------
   Click reticle, morph cursor, and the ring-field stage. The reticle and cursor
   are shared by every page; the ring field is landing-only and is opted into by
   [data-ring-field] on the section that hosts it.
   ========================================================================== */

/* --- tokens --------------------------------------------------------------- */
html {
  /* The cursor ink is the page accent in each theme, so the reticle belongs to
     the surface it lands on rather than being a fixed colour. */
  --n-cursor-ink: #8fe8f8;
}
html[data-theme='light'] {
  --n-cursor-ink: #1f6fb5;
}

/* --- click reticle -------------------------------------------------------- */
.n-click-fx {
  position: fixed;
  z-index: 2147483000;
  pointer-events: none;
  will-change: opacity;
  contain: layout style;
  mix-blend-mode: normal;
}
.n-click-fx svg {
  display: block;
  overflow: visible;
}

/* --- morph cursor (landing only) ------------------------------------------ */
.n-morph-cursor {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 2147482900;
  pointer-events: none;
  border: 1.5px solid var(--n-cursor-ink);
  opacity: 0;
  will-change: left, top, width, height, border-radius, opacity;
  /* The copy grows out of the pointer and settles onto the target: a spring-ish
     curve on the box, a faster one on opacity so the new shape is visible
     immediately rather than fading up mid-flight. */
  transition:
    left 300ms cubic-bezier(0.22, 1, 0.28, 1),
    top 300ms cubic-bezier(0.22, 1, 0.28, 1),
    width 300ms cubic-bezier(0.22, 1, 0.28, 1),
    height 300ms cubic-bezier(0.22, 1, 0.28, 1),
    border-radius 300ms cubic-bezier(0.22, 1, 0.28, 1),
    opacity 140ms ease,
    background-color 220ms ease,
    border-color 220ms ease;
  box-sizing: border-box;
}

.n-morph-cursor__dot {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 4px;
  height: 4px;
  margin: -2px 0 0 -2px;
  border-radius: 50%;
  background: var(--n-cursor-ink);
  transition: opacity 200ms ease;
}

/* Over a control the ring BECOMES the control: same width, same height, same
   radius, sitting exactly on top of the original. Only the colour moves — a
   slightly darker ink and a barely-there wash — so it reads as the cursor
   settling onto the button, not as a second button appearing. No padding and no
   clamp: an inexact copy is the thing this replaces. */
.n-morph-cursor.is-over {
  background: color-mix(in srgb, var(--n-cursor-ink) 12%, transparent);
  border-color: color-mix(in srgb, var(--n-cursor-ink) 62%, #000 38%);
}

html[data-morph-cursor] button,
html[data-morph-cursor] [role='button'],
html[data-morph-cursor] .n-btn {
  /* Hide the native pointer only where the custom cursor morphs into a button. */
  cursor: none;
}
html[data-morph-cursor] input,
html[data-morph-cursor] textarea,
html[data-morph-cursor] select {
  /* Text fields keep the caret cursor: a ring over a text field is hostile. */
  cursor: auto;
}

/* --- ring field -----------------------------------------------------------
   The field is the page's own surface, not a section backdrop: a fixed,
   viewport-sized canvas that every section scrolls over. It stays put while the
   page moves, so the cursor is always pulling the same continuous field, and it
   never appears above content.

   The layering is done with a stack of two contexts, not with z-index races
   against arbitrary content:

     the page paints `--n-field-paper` (the theme's page colour) as a fixed
     backdrop, then the field at z-index 0, then all content in a context
     above it. Nothing in a section can out-rank the field and nothing in the
     field can out-rank a glyph.
   -------------------------------------------------------------------------- */

.n-ringfield__layer {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 1;
  /* A field that stays put while the page moves must not be allowed to become
     a scroll surface of its own on iOS, and it must not build a layer that
     stretches the page. */
  contain: strict;

  /* The field is BEHIND everything: that is what z-index 0 and the content
     context below guarantee. This mask is not about stacking, it is about
     legibility. The field runs at full weight in the page margins and is held at
     zero across the reading column, because the rule is that the field must
     never come over text, and a dot behind a glyph fails that rule at any
     opacity. It stays felt in the gutters, behind the rules and between blocks,
     which is what keeps the page reading as one calm surface.

     Percentages, not vw: inside mask-image a vw length resolves against the
     gradient box, and a clamp() there collapsed to its minimum and put dots
     straight through the column. Landing text begins at x=120 of 1440, so 7%
     (101px) is clear and 12% (173px) is fully veiled. */
  -webkit-mask-image: linear-gradient(
    to right,
    #000 0,
    #000 7%,
    rgba(0, 0, 0, 0) 12%,
    rgba(0, 0, 0, 0) 88%,
    #000 93%,
    #000 100%
  );
  mask-image: linear-gradient(
    to right,
    #000 0,
    #000 7%,
    rgba(0, 0, 0, 0) 12%,
    rgba(0, 0, 0, 0) 88%,
    #000 93%,
    #000 100%
  );
}
html[data-theme='light'] .n-ringfield__layer {
  /* The light ramp is blue-on-paper, which carries more weight without reading
     as dirt on the page, so it runs slightly below full ink. */
  opacity: 0.78;
}

.n-ringfield__canvas {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* The content sits in one context above the field, so no section has to be
   individually lifted and no section can accidentally sit under the dots. This
   is what keeps the field behind every heading, card and button.

   Only real page furniture is listed. A `body > :not(.n-ringfield__layer)`
   selector would also catch our own fixed overlays (the cursor, the reticle) and
   re-position them as `relative`, which is exactly the bug that made the cursor
   drift down the page. */
body:has(> .n-ringfield__layer) {
  isolation: isolate;
}
body:has(> .n-ringfield__layer) > #root,
body:has(> .n-ringfield__layer) > main,
body:has(> .n-ringfield__layer) > header,
body:has(> .n-ringfield__layer) > footer,
body:has(> .n-ringfield__layer) > .n-header,
body:has(> .n-ringfield__layer) > .n-footer {
  position: relative;
  z-index: 1;
}

.n-shell main,
.n-shell .n-header,
.n-shell .n-footer {
  position: relative;
  z-index: 1;
}

/* TEXT IS NEVER DRAWN OVER. The field is behind every section, and most
   sections are transparent — so "behind" is not enough on its own: a dot can
   still land under a word and compete with it.

   The rule is therefore positive, not incidental. The field is masked out of
   exactly the column that carries running text, and shows through in the
   margins, the rules, the gaps between blocks — the places where there is
   nothing to read. That is why the page behind the type is perfectly flat and
   the field is still felt everywhere the eye is not fixed.

   The mask is one vertical band, not a stack of per-paragraph holes: bands per
   paragraph would flicker as text reflows and cost a repaint per scroll. The
   band lives on the base .n-ringfield__layer rule above. */

/* The workspace is mostly panes, not a reading column: it has no single gutter
   band, and a silhouette of every card would be noise. There the field stays at
   the page edges only, which is the one place the app never puts text. */
body:has(> .n-ringfield__layer):not(:has(.n-shell)) .n-ringfield__layer,
html:not(.n-shell) body:has(> .n-ringfield__layer) .n-ringfield__layer {
  -webkit-mask-image: linear-gradient(
    to right,
    #000 0,
    #000 1%,
    transparent 5%,
    transparent 95%,
    #000 99%,
    #000 100%
  );
  mask-image: linear-gradient(
    to right,
    #000 0,
    #000 1%,
    transparent 5%,
    transparent 95%,
    #000 99%,
    #000 100%
  );
}

.n-shell main > section {
  position: relative;
  z-index: 1;
}

/* --- reduced motion ------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .n-morph-cursor {
    display: none !important;
  }
  html[data-morph-cursor],
  html[data-morph-cursor] a,
  html[data-morph-cursor] button,
  html[data-morph-cursor] [role='button'] {
    cursor: auto;
  }
  .n-ringfield__layer {
    opacity: 0.3;
  }
}

/* A touch device has no hover, so the morph cursor and reticle are noise. */
@media (pointer: coarse) {
  .n-morph-cursor {
    display: none !important;
  }
}

/* --- peek mascot ----------------------------------------------------------
   The subject sits at the top edge of the landing page's chat preview, rising
   out of it: the ball is clipped by the preview's own top edge, so it reads as
   something inside the window looking out rather than a sticker on the page.

   THE BALL DOES NOT MOVE. Its translate is set once, by the layout; the only
   motion is the eyes (driven by the pointer) and a 4px breathing bob on the
   inner element, which is a vertical offset, not a rotation. The user was
   explicit about this: the goola must not spin or turn. So there is no
   rotate/rotateY/scaleY anywhere below, and no transform-origin tricks — a ball
   that visibly turns would be the wrong object entirely.

   Everything here is drawn with gradients so it stays crisp at any DPR and can
   be hidden behind prefers-reduced-motion without leaving a hole.
   -------------------------------------------------------------------------- */

.n-peek {
  position: absolute;
  /* Centre of the ball sits exactly on the window's top edge, so half of it is
     inside the preview and half of it is above it: peeking. */
  /* The ball's centre hangs 14px ABOVE the shell's top edge, not on it: on the
     edge it covered the last row of the spec list, and the point is that it is
     peeking over the window, not pasted on the page above it. */
  top: -52px;
  left: 50%;
  z-index: 3;
  width: 76px;
  height: 76px;
  margin-left: -38px;
  /* Above the window chrome, but the shell itself clips nothing — this element
     is the thing that must be allowed to hang over the top border. */
  pointer-events: none;
}

.n-peek__ball {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  /* Bright aurora glass that picks up Notely's cyan/blue identity. */
  background:
    radial-gradient(58% 48% at 30% 22%, rgba(255, 255, 255, 0.95), transparent 58%),
    radial-gradient(48% 42% at 72% 76%, rgba(31, 111, 181, 0.95), transparent 72%),
    radial-gradient(90% 90% at 35% 30%, #8fe8f8 0%, #38b9e6 38%, #2467b7 72%, #604acb 100%);
  box-shadow:
    0 18px 34px -16px rgba(14, 103, 169, 0.48),
    0 0 28px rgba(143, 232, 248, 0.28),
    inset 0 0 0 1px rgba(255, 255, 255, 0.5),
    inset 0 -10px 18px -8px rgba(18, 66, 128, 0.38);
  /* The breathing bob: translateY only. Never a rotation. */
  animation: n-peek-bob 5.2s ease-in-out infinite;
  will-change: transform;
}

@keyframes n-peek-bob {
  0%, 100% { transform: translate3d(0, 0, 0); }
  50%      { transform: translate3d(0, -4px, 0); }
}

.n-peek__gloss {
  position: absolute;
  top: 9%;
  left: 17%;
  width: 40%;
  height: 30%;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 40%, rgba(255, 255, 255, 0.62), transparent 70%);
  filter: blur(1px);
}

.n-peek__eyes {
  position: absolute;
  top: 46%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  gap: 9px;
  /* Slight downward cast: it is peeking over an edge, so it is looking down at
     you, and that is what makes it read as "peeking" and not "floating". */
  margin-top: 3px;
}

.n-peek__eye {
  position: relative;
  width: 14px;
  height: 16px;
  border-radius: 50%;
  background: #f2f8ff;
  box-shadow: 0 0 10px -2px rgba(143, 232, 248, 0.5);
  overflow: hidden;
}

/* The pupils are the ONLY things the pointer drives. They translate inside the
   whites, clamped to stay fully inside — an eye that can leave its socket is
   the tell that gives cheap mascots away. */
.n-peek__pupil {
  position: absolute;
  top: 50%;
  left: 50%;
  /* Nearly the size of the socket: at this scale a small pupil reads as a
     beady eye rather than as the dark marble's clean white eyes, which is what
     the workspace sprite actually shows. */
  width: 11px;
  height: 12px;
  margin: -6px 0 0 -5.5px;
  border-radius: 50%;
  background: #0a0d14;
  will-change: transform;
}

.n-peek__shadow {
  position: absolute;
  left: 50%;
  bottom: -9px;
  width: 54px;
  height: 12px;
  margin-left: -27px;
  border-radius: 50%;
  background: radial-gradient(ellipse at 50% 50%, rgba(0, 0, 0, 0.5), transparent 72%);
  filter: blur(4px);
}

/* The landing page has to stop clipping it: the shell is the window the orb
   hangs out of, so nothing on the way up may hide it. */
.n-app-shell { overflow: visible; }

html[data-theme='light'] .n-peek__ball {
  /* On paper the dark capsule still wins — it is a glass object, and the light
     theme's whole point is that things sitting on it have edges. Only the
     shadow softens, because a hard one reads as ink on the page. */
  box-shadow:
    0 16px 30px -18px rgba(10, 13, 20, 0.42),
    inset 0 0 0 1px rgba(255, 255, 255, 0.2),
    inset 0 -10px 18px -8px rgba(0, 0, 0, 0.75);
}

@media (prefers-reduced-motion: reduce) {
  .n-peek__ball { animation: none; }
}
