/* ---------------------------------------------------------------------------
   Onboarding: the typed welcome on the gate, and the tour that follows it.

   One look for both, so the second reads as the first continuing: the dark of
   the gate, a slow iridescent bloom (violet, blue, pink, a little warm), glass
   for anything that has to sit on top of the app, and the system font at
   display weights. Everything that moves stops under reduced motion.
   --------------------------------------------------------------------------- */

@property --tour-angle {
  syntax: "<angle>";
  inherits: false;
  initial-value: 0deg;
}

@keyframes tour-spin { to { --tour-angle: 360deg; } }
@keyframes tour-caret { 50% { opacity: 0; } }
@keyframes tour-shimmer { to { background-position: -200% 0; } }
@keyframes tour-bloom {
  from { opacity: 0; transform: scale(0.7); }
  to   { opacity: 1; transform: scale(1); }
}
@keyframes tour-breathe {
  from { transform: scale(1) translate3d(-2%, -1%, 0); }
  to   { transform: scale(1.12) translate3d(2%, 2%, 0); }
}

/* The ring of colour around the screen's edge. Shared by the welcome and the
   tour: a conic sweep, blurred, masked down to the border so the middle stays
   dark and readable. */
.intro-glow::after,
.tour-edge {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: conic-gradient(from var(--tour-angle),
    #7c4dff, #3f8cff, #2de1c2, #ffb86b, #ff5fb4, #7c4dff);
  -webkit-mask: radial-gradient(ellipse 120% 120% at 50% 50%, transparent 58%, #000 78%);
          mask: radial-gradient(ellipse 120% 120% at 50% 50%, transparent 58%, #000 78%);
  filter: blur(28px) saturate(1.2);
  animation: tour-spin 9s linear infinite;
}

/* --- the sign-up choice ---------------------------------------------------- */

#auth-form.signup .auth-field,
#auth-form.signup #auth-submit { display: none; }

#auth-manual {
  width: 100%;
  padding: 0.55rem 1rem;
  border-radius: 999px;
  background: linear-gradient(135deg, #7c4dff, #3f8cff);
  border: 1px solid transparent;
  color: #fff;
  font-size: 0.95rem;
}
#auth-manual:hover { filter: brightness(1.15); }

/* --- the typed welcome ----------------------------------------------------- */

#auth-gate.intro { background: #05060f; }
#auth-gate.intro #auth-box { display: none; }

#auth-intro {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* Top-anchored, not centred: a line typed in below must not lift the ones
     above it. */
  justify-content: flex-start;
  padding: 32vh 16px 0;
  color: #f4f4fb;
  text-align: center;
  /* Monospaced, like a terminal: the welcome is something being typed, and in
     a fixed-width face every line can be anchored by its length in ch. */
  font-family: "SF Mono", ui-monospace, Menlo, "JetBrains Mono", Consolas, monospace;
  cursor: text;
}

/* One left edge for every line, like a terminal: the block is as wide as the
   finished welcome and centred once, before a letter is typed, so nothing on
   screen shifts as letters arrive. --intro-len is the welcome's length in
   characters (set by startIntro); ch is exact in a monospaced face. The lines
   below size themselves in em against this, so they share the same ruler. */
.intro-body {
  width: min(100%, calc(var(--intro-len, 28) * 1ch));
  font-size: clamp(1.6rem, 4.2vw, 3.2rem);
  text-align: left;
}
#auth-intro.hidden { display: none; }

.intro-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
/* The bloom in the middle: arrives first, then breathes. */
.intro-glow::before {
  content: "";
  position: absolute;
  inset: -20%;
  background:
    radial-gradient(32% 30% at 38% 42%, rgba(124, 77, 255, 0.42), transparent 70%),
    radial-gradient(30% 28% at 64% 58%, rgba(63, 140, 255, 0.30), transparent 70%),
    radial-gradient(22% 20% at 58% 34%, rgba(255, 95, 180, 0.16), transparent 70%),
    radial-gradient(24% 22% at 40% 66%, rgba(45, 225, 194, 0.12), transparent 70%);
  filter: blur(50px);
  animation:
    tour-bloom 1.4s cubic-bezier(0.22, 1, 0.36, 1) both,
    tour-breathe 14s ease-in-out 1.4s infinite alternate;
}
.intro-glow::after {
  content: "";
  opacity: 0;
  transition: opacity 1.6s ease;
}
#auth-gate.intro .intro-glow::after { opacity: 0.55; }

.intro-welcome {
  position: relative;
  margin: 0 0 1.4rem;
  min-height: 1.2em;
  font-size: 1em;
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1.1;
  background: linear-gradient(100deg, #ffffff 0%, #e6defe 45%, #b7d0ff 100%);
  -webkit-background-clip: text;
          background-clip: text;
  color: transparent;
}

.intro-line {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  align-items: baseline;
  min-height: 1.5em;
  font-size: 0.5em;
  font-weight: 400;
  letter-spacing: 0;
  color: rgba(255, 255, 255, 0.86);
}
.intro-line.hidden { display: none; }
.intro-second { margin-top: 0.5rem; }
.intro-lead { white-space: pre; }

/* The caret that rides the end of whatever is being typed. */
/* A block cursor, the terminal's own: one character wide, sitting on the
   cell the next letter will fill. */
.typing::after {
  content: "";
  display: inline-block;
  width: 1ch;
  height: 1.1em;
  margin-left: 0.08ch;
  vertical-align: -0.2em;
  background: rgba(225, 215, 255, 0.85);
  animation: tour-caret 1s steps(1) infinite;
}
.intro-welcome.typing::after { background: #e6defe; }

/* The ghost is the only thing in flow, so the slot is exactly as wide as the
   words it is showing; the input lies over it. */
.intro-slot {
  position: relative;
  display: inline-block;
  animation: tour-bloom 0.9s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.intro-slot.hidden { display: none; }

/* The ghost: what goes here, said dimly and a little out of focus, with a
   slow light moving through it. Once you type, it goes on carrying your text
   invisibly so the slot keeps your width. A trailing space of room, so the
   caret never sits on the edge and scrolls the first letter away. */
.intro-ghost {
  display: inline-block;
  padding-right: 1ch;
  white-space: pre;
  pointer-events: none;
  background: linear-gradient(90deg,
    rgba(255, 255, 255, 0.28) 0%, rgba(255, 255, 255, 0.28) 40%,
    rgba(214, 200, 255, 0.75) 50%,
    rgba(255, 255, 255, 0.28) 60%, rgba(255, 255, 255, 0.28) 100%);
  background-size: 200% 100%;
  -webkit-background-clip: text;
          background-clip: text;
  color: transparent;
  filter: blur(0.5px);
  animation: tour-shimmer 3.2s linear infinite;
  transition: opacity 0.25s ease;
}
.intro-ghost.filled { opacity: 0; animation: none; }

.intro-slot input {
  position: absolute;
  inset: 0;
  width: 100%;
  min-width: 1ch;
  padding: 0;
  border: 0;
  outline: none;
  background: transparent;
  color: #ffffff;
  font: inherit;
  letter-spacing: inherit;
  caret-color: #c9b8ff;
  caret-shape: block;
  --autofill-bg: #05060f;
  --autofill-text: #fff;
}
.intro-slot input:-webkit-autofill {
  -webkit-text-fill-color: #fff;
  transition: background-color 9999s;
}

/* A hairline under the slot that lights when it has the cursor. */
.intro-slot::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -0.18em;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(185, 160, 255, 0.55), transparent);
  opacity: 0.4;
  transition: opacity 0.3s ease;
}
.intro-slot:focus-within::after { opacity: 1; }
#auth-intro.busy .intro-slot::after { animation: tour-caret 0.8s ease-in-out infinite; opacity: 1; }

.intro-hintrow {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 1.2rem;
  margin: 2.4rem 0 0;
}
.intro-hint {
  min-height: 1.2em;
  margin: 0;
  max-width: 34rem;
  font-size: 0.86rem;
  color: rgba(255, 255, 255, 0.42);
}
.intro-error {
  min-height: 1.2em;
  margin: 0.8rem 0 0;
  font-size: 0.92rem;
  color: #ff9aa9;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.intro-error.shown { opacity: 1; transform: none; }

.intro-back {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  background: none;
  border: 0;
  font-size: 0.82rem;
  color: rgba(255, 255, 255, 0.4);
  cursor: pointer;
}
.intro-back:hover { color: rgba(255, 255, 255, 0.85); }
.intro-back.hidden, .intro-next.hidden { display: none; }

/* The tour's own Next, so the two read as one control: the btw orange, a
   hairline, a low tint. Dim while there is nothing to go on with. */
.intro-next {
  flex: none;
  padding: 0.38rem 1rem;
  border-radius: 9px;
  border: 1px solid rgba(255, 199, 150, 0.25);
  background: transparent;
  color: rgba(255, 226, 198, 0.35);
  font: 600 0.82rem/1.2 -apple-system, BlinkMacSystemFont, sans-serif;
  cursor: default;
  transition: background 0.3s ease, color 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
}
.intro-next:not(:disabled) {
  border-color: rgba(255, 199, 150, 0.55);
  background: rgba(255, 171, 92, 0.16);
  color: #ffe2c6;
  cursor: pointer;
  animation: tour-next 2.2s ease-in-out infinite;
}
.intro-next:not(:disabled):hover { background: rgba(255, 171, 92, 0.28); }

/* Through: the words come apart into light and the bloom swells to meet the
   tour's veil, which opens on the same dark. */
#auth-gate.intro-leaving .intro-welcome,
#auth-gate.intro-leaving .intro-line,
#auth-gate.intro-leaving .intro-hint,
#auth-gate.intro-leaving .intro-back,
#auth-gate.intro-leaving .intro-hintrow {
  opacity: 0;
  filter: blur(14px);
  transform: scale(1.05);
  transition: opacity 0.8s ease, filter 0.8s ease, transform 0.9s cubic-bezier(0.22, 1, 0.36, 1);
}
#auth-gate.intro-leaving .intro-glow::before {
  transform: scale(1.35);
  opacity: 0.9;
  transition: transform 0.9s ease, opacity 0.9s ease;
}

/* --- the tour -------------------------------------------------------------- */

.tour-veil {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #05060f;
  opacity: 1;
  transition: opacity 0.7s ease;
}
.tour-veil::before {
  content: "";
  position: absolute;
  inset: -20%;
  background:
    radial-gradient(32% 30% at 40% 44%, rgba(124, 77, 255, 0.36), transparent 70%),
    radial-gradient(30% 28% at 62% 56%, rgba(63, 140, 255, 0.26), transparent 70%);
  filter: blur(50px);
  animation: tour-breathe 8s ease-in-out infinite alternate;
}
.tour-veil.out { opacity: 0; pointer-events: none; }

/* Over the app, under the tour's own chrome: the app is being played, not
   handed over, so nothing reaches it until the tour ends. */
.tour-shield {
  position: fixed;
  inset: 0;
  z-index: 1900;
  cursor: default;
}

.tour-edge {
  z-index: 1950;
  opacity: 0;
  transition: opacity 1.2s ease;
}
.tour-edge.on { opacity: 0.38; }

/* The tour's own chrome wears the desktop's "btw" colour, rgb(255, 171, 92):
   the colour that already means "beside what you are doing, not part of it",
   which is exactly what a tour over the app is. One hue, a dotted hairline, a
   low tint; the field behind supplies all the colour the screen needs. */
:root {
  --tour-btw: 255, 171, 92;
  --tour-btw-line: rgba(255, 199, 150, 0.55);
  --tour-btw-text: rgba(255, 186, 122, 0.9);
}

.tour-pill {
  position: fixed;
  top: 18px;
  left: 50%;
  z-index: 2100;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.9rem 0.4rem 0.75rem;
  border-radius: 999px;
  border: 1px dotted var(--tour-btw-line);
  font: 500 0.72rem/1 "SF Mono", ui-monospace, Menlo, monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--tour-btw-text);
  background: rgba(74, 43, 18, 0.55);
  -webkit-backdrop-filter: blur(18px);
          backdrop-filter: blur(18px);
  transform: translate(-50%, -140%) scale(0.6);
  opacity: 0;
  transition: transform 0.9s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.5s ease;
}
.tour-pill.on { transform: translate(-50%, 0) scale(1); opacity: 1; }
.tour-pill .spark {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: rgb(var(--tour-btw));
  box-shadow: 0 0 8px rgba(var(--tour-btw), 0.7);
}

.tour-caption {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 2100;
  /* A fixed width, and room for two lines, so the box holds still while a
     line types itself into it rather than growing letter by letter. */
  width: min(640px, calc(100vw - 32px));
  padding: 0.9rem 1.2rem 0.75rem;
  border-radius: 14px;
  border: 1px dotted var(--tour-btw-line);
  color: #fff;
  background: rgba(30, 20, 12, 0.78);
  -webkit-backdrop-filter: blur(18px);
          backdrop-filter: blur(18px);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  transform: translate(-50%, 30px);
  opacity: 0;
  transition: transform 0.7s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.5s ease;
}
.tour-caption.on { transform: translate(-50%, 0); opacity: 1; }
/* Lines turn in and out like a face of the field turning: out to the right
   and away, in from the left. The caption carries the perspective. */
.tour-caption { perspective: 900px; }
.tour-caption .line {
  transform-origin: 50% 50%;
  transition: transform 0.42s cubic-bezier(0.22, 1, 0.36, 1),
              opacity 0.36s ease, filter 0.36s ease;
}
.tour-caption .line.turn-out {
  transform: translateX(70px) rotateY(55deg);
  opacity: 0;
  filter: blur(4px);
  transition: transform 0.26s cubic-bezier(0.55, 0, 1, 0.45),
              opacity 0.22s ease, filter 0.22s ease;
}
.tour-caption .line.turn-in {
  transform: translateX(-70px) rotateY(-55deg);
  opacity: 0;
  filter: blur(4px);
  transition: none;
}
.tour-caption .line {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 2.8em;
  font-size: clamp(1rem, 1.8vw, 1.18rem);
  font-weight: 500;
  letter-spacing: -0.005em;
  line-height: 1.4;
  text-align: center;
}
.tour-caption .bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 0.7rem;
}
.tour-dots { display: flex; gap: 4px; align-items: center; }
.tour-dots i {
  width: 5px;
  height: 5px;
  border-radius: 3px;
  flex: none;
  background: rgba(255, 255, 255, 0.18);
  transition: width 0.4s ease, background 0.4s ease;
}
.tour-dots i.done { background: rgba(var(--tour-btw), 0.45); }
.tour-dots i.now { width: 16px; background: rgb(var(--tour-btw)); }
.tour-dots i.part { margin-left: 6px; }
.tour-buttons { display: flex; gap: 0.4rem; }
.tour-buttons button {
  padding: 0.28rem 0.75rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: transparent;
  color: rgba(255, 255, 255, 0.7);
  font: 500 0.78rem/1.2 -apple-system, BlinkMacSystemFont, sans-serif;
  cursor: pointer;
}
.tour-buttons button:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.tour-buttons button:disabled { opacity: 0.3; cursor: default; background: transparent; }
/* Next is the one to press, so it is the one in colour, and it breathes once
   the line is there to be read. Dimmed while the hand is still busy. */
.tour-buttons button.next {
  padding: 0.28rem 1rem;
  border-color: var(--tour-btw-line);
  background: rgba(var(--tour-btw), 0.16);
  color: #ffe2c6;
  font-weight: 600;
  opacity: 0.45;
  transition: opacity 0.3s ease, box-shadow 0.3s ease, background 0.2s ease;
}
.tour-buttons button.next:hover { background: rgba(var(--tour-btw), 0.28); }
.tour-buttons button.next.ready {
  opacity: 1;
  animation: tour-next 2.2s ease-in-out infinite;
}
@keyframes tour-next {
  0%, 100% { box-shadow: 0 0 0 rgba(var(--tour-btw), 0); }
  50%      { box-shadow: 0 0 14px rgba(var(--tour-btw), 0.45); }
}

/* The ghost hand: a soft lit disc, the size of an iPad pointer. */
.tour-cursor {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 2200;
  width: 22px;
  height: 22px;
  margin: -11px 0 0 -11px;
  border-radius: 50%;
  pointer-events: none;
  background: radial-gradient(circle at 40% 38%, rgba(255, 255, 255, 0.95), rgba(220, 210, 255, 0.7) 45%, rgba(160, 140, 255, 0.25) 70%, transparent 72%);
  box-shadow: 0 0 22px rgba(170, 150, 255, 0.75), 0 0 2px rgba(255, 255, 255, 0.9);
  opacity: 0;
  transition: opacity 0.4s ease, transform 0.9s cubic-bezier(0.65, 0, 0.35, 1);
}
.tour-cursor.on { opacity: 1; }
.tour-cursor.press { scale: 0.75; transition: opacity 0.4s ease, transform 0.9s cubic-bezier(0.65, 0, 0.35, 1), scale 0.12s ease; }
.tour-ripple {
  position: fixed;
  z-index: 2190;
  width: 44px;
  height: 44px;
  margin: -22px 0 0 -22px;
  border-radius: 50%;
  border: 1.5px solid rgba(200, 185, 255, 0.9);
  pointer-events: none;
  animation: tour-ripple 0.7s ease-out forwards;
}
@keyframes tour-ripple {
  from { transform: scale(0.3); opacity: 1; }
  to   { transform: scale(1.6); opacity: 0; }
}

/* Spotlight: everything else dims, the target gets a lit edge. */
.tour-spot {
  position: fixed;
  z-index: 1960;
  border-radius: 14px;
  pointer-events: none;
  outline: 1px dotted rgba(255, 199, 150, 0.8);
  box-shadow: 0 0 0 200vmax rgba(4, 5, 14, 0.62), 0 0 30px 4px rgba(255, 171, 92, 0.22);
  transition: left 0.7s cubic-bezier(0.22, 1, 0.36, 1), top 0.7s cubic-bezier(0.22, 1, 0.36, 1),
              width 0.7s cubic-bezier(0.22, 1, 0.36, 1), height 0.7s cubic-bezier(0.22, 1, 0.36, 1),
              opacity 0.5s ease;
  opacity: 0;
}
.tour-spot.on { opacity: 1; }

.tour-card {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 2100;
  width: min(440px, calc(100vw - 32px));
  padding: 2rem 1.8rem 1.6rem;
  border-radius: 16px;
  border: 1px dotted var(--tour-btw-line);
  color: #fff;
  text-align: center;
  background: rgba(30, 20, 12, 0.82);
  -webkit-backdrop-filter: blur(20px);
          backdrop-filter: blur(20px);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.55);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  transform: translate(-50%, -46%) scale(0.96);
  opacity: 0;
  transition: transform 0.8s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.5s ease;
}
.tour-card.on { transform: translate(-50%, -50%) scale(1); opacity: 1; }
.tour-card h2 {
  margin: 0 0 0.6rem;
  font-size: 1.7rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  color: #fff;
}
.tour-card p { margin: 0 0 1.2rem; color: rgba(255, 255, 255, 0.7); line-height: 1.5; }
.tour-card input {
  width: 100%;
  margin: 0 0 0.4rem;
  padding: 0.6rem 0.8rem;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  font-size: 0.95rem;
}
.tour-card input:focus { outline: 1px solid var(--tour-btw-line); outline-offset: -1px; }
.tour-card .note { min-height: 1.1em; margin: 0 0 0.9rem; font-size: 0.8rem; color: rgba(255, 255, 255, 0.45); }
.tour-card .note.error { color: #ff9aa9; }
.tour-card .go {
  width: 100%;
  padding: 0.65rem 1rem;
  border-radius: 999px;
  border: 1px solid var(--tour-btw-line);
  background: rgba(var(--tour-btw), 0.2);
  color: #ffe2c6;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}
.tour-card .go:hover { background: rgba(var(--tour-btw), 0.32); }

@media (prefers-reduced-motion: reduce) {
  .intro-glow::before, .intro-glow::after, .tour-edge, .tour-veil::before,
  .intro-ghost, .typing::after { animation: none; }
  .tour-cursor { transition: opacity 0.2s ease; }
  .tour-buttons button.next.ready, .intro-next:not(:disabled) { animation: none; }
}

/* The example library's name, for the step that leads into it: the btw
   orange, in a dotted box, so it reads as a stand-in rather than your name. */
.tour-example {
  padding: 0 0.3em;
  border: 1px dotted var(--tour-btw-line);
  border-radius: 0.25em;
  background: rgba(var(--tour-btw), 0.1);
  color: rgb(255, 196, 140);
  text-transform: uppercase;
}
