/* Registration as a calm, one-screen-at-a-time setup, and the personalised welcome after login.
   Loaded only by register.ejs and welcome.ejs, on top of styles.css. */
:root {
  --setup-ease: cubic-bezier(.22, 1, .36, 1);
  --setup-glow: rgba(29, 158, 117, .10);
}
@media (prefers-color-scheme: dark) {
  :root { --setup-glow: rgba(29, 158, 117, .16); }
}

/* The setup owns the whole screen: its own slim bar replaces the site nav. */
body:has(.setup) > .nav { display: none; }
body:has(.setup) { background: var(--surface); }

.setup {
  flex: 1; display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; width: 100%;
  background: radial-gradient(120% 60% at 50% -10%, var(--setup-glow), transparent 60%), var(--surface);
}

/* ---------- Top bar: Back, wordmark, language, progress ---------- */
.setup-bar {
  position: sticky; top: 0; z-index: 10; display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center;
  gap: 8px; padding: 14px 20px 12px; padding-top: max(14px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--surface) 82%, transparent); backdrop-filter: blur(16px) saturate(160%); -webkit-backdrop-filter: blur(16px) saturate(160%);
}
.setup-progress { position: absolute; left: 0; right: 0; top: 0; height: 3px; background: var(--border); overflow: hidden; }
.setup-progress span { display: block; height: 100%; background: var(--accent); transform-origin: left center; transform: scaleX(0); transition: transform 450ms var(--setup-ease); }
.setup-back {
  justify-self: start; display: inline-flex; align-items: center; gap: 4px; background: none; border: 0; padding: 6px 8px 6px 0; cursor: pointer;
  color: var(--accent); font-size: 15px; font-weight: 500;
}
.setup-back span { font-size: 22px; line-height: 1; margin-top: -2px; }
.setup-back:hover { color: var(--accent-hover); }
.setup-mark { grid-column: 2; font-weight: 700; font-size: 15px; color: var(--text); letter-spacing: -.01em; text-decoration: none !important; opacity: 0; transition: opacity .3s; }
.setup-mark span, .hello-mark span { color: var(--accent); }
.setup[data-at]:not([data-at="0"]) .setup-mark { opacity: 1; }
.setup-lang { grid-column: 3; justify-self: end; display: flex; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 99px; padding: 2px; }
.setup-lang a { font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 99px; color: var(--text-2); text-decoration: none !important; }
.setup-lang a.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(13, 17, 23, .08); }

/* ---------- Screens ---------- */
.screens { flex: 1; display: grid; width: 100%; max-width: 560px; margin: 0 auto; padding: 0 20px; }
.screen { grid-area: 1 / 1; display: flex; flex-direction: column; min-width: 0; min-height: 100%; }
.screen-body { padding: 28px 0 8px; }
.eyebrow { font-size: 12.5px; font-weight: 600; letter-spacing: .02em; color: var(--accent-ink); margin-bottom: 10px; }
.screen h2 { font-size: clamp(28px, 7vw, 38px); font-weight: 700; letter-spacing: -.028em; line-height: 1.12; overflow-wrap: anywhere; }
.screen .lead { font-size: 16px; color: var(--text-2); line-height: 1.5; margin: 10px 0 28px; max-width: 46ch; }
.screen .errors { font-size: 14px; }
.screen-foot { margin-top: auto; padding: 20px 0 32px; }
.btn-xl { width: 100%; min-height: 52px; padding: 14px 24px; border-radius: 14px; font-size: 16px; font-weight: 600; }

/* Larger, calmer fields; 16px text also stops iOS zooming in on focus. */
.setup .field { margin-bottom: 18px; }
.setup .field > span { font-size: 13.5px; margin-bottom: 7px; color: var(--text); }
.setup .field input:not([type=radio]):not([type=checkbox]):not([type=range]), .setup .field select, .setup .field textarea {
  padding: 13px 14px; font-size: 16px; border-radius: 12px; background: var(--surface-2);
}
.setup .field small { font-size: 12.5px; }
.opt { font-weight: 400; color: var(--muted); font-size: 12.5px; }
.pw { position: relative; display: block; }
.setup .pw input { padding-right: 76px !important; }
.pw-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: 0; background: none; cursor: pointer;
  padding: 8px 10px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--accent);
}
.pw-toggle:hover { background: var(--accent-soft); }

/* Sector cards */
.sector-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 22px; }
.sector-card {
  position: relative; display: flex; flex-direction: column; gap: 4px; min-height: 128px; padding: 16px; border: 1.5px solid var(--border); border-radius: 16px;
  background: var(--surface); cursor: pointer; transition: border-color .15s, background .15s, transform .15s var(--setup-ease);
}
.sector-card input { position: absolute; opacity: 0; pointer-events: none; }
.sector-card .ic { font-size: 28px; line-height: 1; margin-bottom: 8px; }
.sector-card .nm { font-size: 15px; font-weight: 650; line-height: 1.25; overflow-wrap: anywhere; }
.sector-card .ds { font-size: 12.5px; color: var(--muted); line-height: 1.4; }
.sector-card .tick { position: absolute; top: 12px; right: 12px; width: 22px; height: 22px; border-radius: 50%; border: 1.5px solid var(--border-strong); transition: all .15s; }
.sector-card:hover { border-color: var(--border-strong); }
.sector-card:active { transform: scale(.98); }
.sector-card:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.sector-card:has(input:checked) .tick { background: var(--accent); border-color: var(--accent); box-shadow: inset 0 0 0 4px var(--accent-soft); }
.sector-card:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.sector-card.off { cursor: default; opacity: .5; border-style: dashed; }
.sector-card.off:active { transform: none; }

/* First need: details appear once a title is typed (always shown without JavaScript) */
@media (scripting: enabled) {
  .need-more { display: grid; grid-template-rows: 0fr; opacity: 0; transition: grid-template-rows .35s var(--setup-ease), opacity .25s; }
  .need-more > * { overflow: hidden; min-height: 0; }
  .need-more.open { grid-template-rows: 1fr; opacity: 1; }
  .need-more:not(.open) { visibility: hidden; }
}
.need-more { margin: 0 -4px; padding: 0 4px; }
.need-more .field:first-child { margin-top: 2px; }

/* Plan cards: two compact choices */
.plan-h { margin: 8px 0 8px; font-size: 13.5px; color: var(--text); }
.plan-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.plan-card {
  position: relative; display: flex; flex-direction: column; gap: 3px; padding: 14px; border: 1.5px solid var(--border); border-radius: 14px;
  background: var(--surface); cursor: pointer; transition: border-color .15s, background .15s;
}
.plan-card input { position: absolute; opacity: 0; pointer-events: none; }
.plan-card .t { font-weight: 650; font-size: 15px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.plan-card .rec { margin-left: 0; }
.plan-card .p { font-weight: 700; color: var(--accent-ink); font-size: 13.5px; }
.plan-card .d { font-size: 12px; color: var(--muted); line-height: 1.45; }
.plan-card:hover { border-color: var(--border-strong); }
.plan-card:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.plan-card:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.setup .fine { margin-top: 14px; }

/* ---------- Greeting ---------- */
.screen-hello { justify-content: center; text-align: center; }
.hello { display: flex; flex-direction: column; align-items: center; justify-content: center; flex: 1; padding: 24px 0 40px; min-height: calc(100dvh - 140px); }
.hello-words { display: grid; font-size: clamp(52px, 15vw, 96px); font-weight: 700; letter-spacing: -.045em; line-height: 1.05; }
.hello-words span {
  grid-area: 1 / 1; padding: 0 .04em .08em;
  background: linear-gradient(120deg, var(--text) 10%, var(--accent) 90%); -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: hello-swap 7s var(--setup-ease) infinite both;
}
.hello-words span + span { animation-delay: -3.5s; }
@keyframes hello-swap {
  0%, 42% { opacity: 1; transform: none; }
  50%, 92% { opacity: 0; transform: translateY(-.12em) scale(.98); }
  100% { opacity: 1; transform: none; }
}
.hello-mark { font-size: 19px; font-weight: 700; letter-spacing: -.01em; margin-top: 18px; }
.hello-line { font-size: 16.5px; color: var(--text-2); max-width: 30ch; margin: 10px auto 0; line-height: 1.5; }
.hello-cta { width: 100%; max-width: 360px; margin-top: 40px; }
.hello-cta .switch { font-size: 14px; margin-top: 16px; }
.hello > * { animation: rise .8s var(--setup-ease) both; }
.hello > :nth-child(2) { animation-delay: .12s; }
.hello > :nth-child(3) { animation-delay: .22s; }
.hello > :nth-child(4) { animation-delay: .34s; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }

/* ---------- One screen at a time (with JavaScript) ---------- */
@media (scripting: enabled) {
  .screen:not(.cur):not(.leaving) { display: none; }
  .screen.leaving { pointer-events: none; }
}
/* Without JavaScript every screen shows, stacked as one long form; only the final button is needed. */
@media (scripting: none) {
  .setup-back, .setup-progress, .pw-toggle, [data-next] { display: none !important; }
  .setup-mark { opacity: 1; }
  .screen + .screen { border-top: 1px solid var(--border); margin-top: 8px; }
  .screen:not(:last-child) .screen-foot { display: none; }
  .hello { min-height: 0; padding: 40px 0 24px; }
  .hello-cta { margin-top: 20px; }
}

/* ---------- Phones: the primary button stays within reach ---------- */
@media (max-width: 600px) {
  .screens { padding: 0 16px; }
  .setup-bar { padding-left: 16px; padding-right: 16px; }
  .screen-body { padding-top: 20px; }
  .screen .lead { margin-bottom: 22px; }
  .screen:not(.screen-hello) .screen-foot {
    position: sticky; bottom: 0; z-index: 5; margin: auto -16px 0; padding: 14px 16px; padding-bottom: max(16px, env(safe-area-inset-bottom));
    background: linear-gradient(to bottom, transparent, var(--surface) 26%);
  }
  .setup .g2 { grid-template-columns: minmax(0, 1fr); gap: 0; }
}
@media (max-width: 380px) {
  .sector-cards, .plan-cards { grid-template-columns: minmax(0, 1fr); }
  .sector-card { min-height: 0; }
}

/* ---------- Welcome after login ---------- */
.welcome {
  position: fixed; inset: 0; display: grid; place-items: center; overflow: hidden; padding: 24px 16px; text-align: center;
  background: radial-gradient(80% 60% at 20% 10%, rgba(29, 158, 117, .16), transparent 60%),
              radial-gradient(70% 60% at 90% 100%, rgba(29, 158, 117, .12), transparent 60%), var(--surface);
}
.welcome-bg { position: absolute; inset: -15%; display: grid; place-items: center; pointer-events: none; animation: bg-in 1.6s var(--setup-ease) both; }
.welcome-bg img { width: min(120vmax, 1400px); max-width: none; height: auto; filter: blur(48px) saturate(1.4); opacity: .22; }
.welcome-bg span { font-size: min(70vmax, 900px); font-weight: 800; letter-spacing: -.06em; line-height: 1; color: var(--accent); opacity: .06; filter: blur(6px); white-space: nowrap; }
@keyframes bg-in { from { opacity: 0; transform: scale(1.15); } }
.welcome-in { position: relative; display: flex; flex-direction: column; align-items: center; width: 100%; max-width: 440px; }
.welcome-logo {
  width: 136px; height: 136px; border-radius: 34px; display: grid; place-items: center; overflow: hidden; margin-bottom: 28px;
  background: #fff; box-shadow: 0 1px 2px rgba(13, 17, 23, .06), 0 18px 50px rgba(13, 17, 23, .14);
  animation: logo-in .9s var(--setup-ease) both;
}
.has-logo .welcome-logo { padding: 18px; }
.welcome-logo img { width: 100%; height: 100%; object-fit: contain; }
.no-logo .welcome-logo { background: linear-gradient(145deg, #34C496, #1D9E75 55%, #0F6E56); box-shadow: 0 18px 50px rgba(29, 158, 117, .35), inset 0 1px 0 rgba(255, 255, 255, .25); }
.welcome-logo span { color: #fff; font-size: 54px; font-weight: 700; letter-spacing: -.03em; }
@keyframes logo-in { from { opacity: 0; transform: scale(.82); } }
.welcome h1 { font-size: clamp(28px, 7vw, 40px); font-weight: 700; letter-spacing: -.028em; line-height: 1.12; overflow-wrap: anywhere; animation: rise .8s .15s var(--setup-ease) both; }
.welcome-co { font-size: 17px; color: var(--text-2); margin-top: 8px; overflow-wrap: anywhere; animation: rise .8s .25s var(--setup-ease) both; }
.welcome-line { width: 160px; height: 3px; border-radius: 99px; background: color-mix(in srgb, var(--text) 10%, transparent); overflow: hidden; margin-top: 32px; animation: rise .6s .35s var(--setup-ease) both; }
.welcome-line span { display: block; height: 100%; background: var(--accent); border-radius: inherit; transform-origin: left center; animation: fill 1.8s .3s cubic-bezier(.4, 0, .2, 1) both; }
@keyframes fill { from { transform: scaleX(0); } to { transform: scaleX(1); } }
/* Returning users: the same hello in one second, so logging in doesn't cost two. */
.quick .welcome-bg { animation-duration: .8s; }
.quick .welcome-logo { animation-duration: .5s; }
.quick h1, .quick .welcome-co, .quick .welcome-line, .quick .welcome-note, .quick .welcome-go { animation-duration: .45s; animation-delay: .05s; }
.quick .welcome-line span { animation: fill .75s .1s var(--setup-ease) both; }
.welcome-note { font-size: 13px; color: var(--muted); margin-top: 10px; animation: rise .6s .4s var(--setup-ease) both; }
.welcome-go { max-width: 280px; margin-top: 36px; animation: rise .6s .5s var(--setup-ease) both; }
@media (prefers-color-scheme: dark) {
  .welcome-bg img { opacity: .28; }
  .welcome-logo { box-shadow: 0 18px 50px rgba(0, 0, 0, .45); }
}

/* ---------- Preferences ---------- */
@media (prefers-reduced-motion: reduce) {
  .hello-words span { animation: none; }
  .hello-words span + span { display: none; }
  .hello > *, .welcome-bg, .welcome-logo, .welcome h1, .welcome-co, .welcome-line, .welcome-note, .welcome-go { animation: fade-in .3s ease both !important; }
  .welcome-line span { animation: none; transform: none; }
  .setup-progress span { transition: none; }
  @keyframes fade-in { from { opacity: 0; } }
}
@media (prefers-reduced-transparency: reduce) {
  .setup-bar { background: var(--surface); backdrop-filter: none; -webkit-backdrop-filter: none; }
  .welcome-bg { display: none; }
}
