/* ULFS2 registry v4. Self-hosted fonts (SIL OFL 1.1, licenses in fonts/). No request to Google: student IPs stay private. */

/* ---------- fonts ---------- */
@font-face { font-family: "IBM Plex Sans Arabic"; font-style: normal; font-weight: 400; font-display: swap;
  src: url(fonts/ibm-plex-sans-arabic-arabic-400-normal.woff2) format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FEFC; }
@font-face { font-family: "IBM Plex Sans Arabic"; font-style: normal; font-weight: 500; font-display: swap;
  src: url(fonts/ibm-plex-sans-arabic-arabic-500-normal.woff2) format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FEFC; }
@font-face { font-family: "IBM Plex Sans Arabic"; font-style: normal; font-weight: 700; font-display: swap;
  src: url(fonts/ibm-plex-sans-arabic-arabic-700-normal.woff2) format("woff2");
  unicode-range: U+0600-06FF, U+0750-077F, U+0870-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FEFC; }
@font-face { font-family: "Inter"; font-style: normal; font-weight: 400; font-display: swap;
  src: url(fonts/inter-latin-400-normal.woff2) format("woff2"); }
@font-face { font-family: "Inter"; font-style: normal; font-weight: 600; font-display: swap;
  src: url(fonts/inter-latin-600-normal.woff2) format("woff2"); }
@font-face { font-family: "Inter"; font-style: normal; font-weight: 700; font-display: swap;
  src: url(fonts/inter-latin-700-normal.woff2) format("woff2"); }
@font-face { font-family: "Inter"; font-style: normal; font-weight: 800; font-display: swap;
  src: url(fonts/inter-latin-800-normal.woff2) format("woff2"); }

/* ---------- theme tokens: dark is the default ---------- */
:root {
  color-scheme: dark;
  --bg:          #04070A;
  --text:        #F2FBFC;
  --muted:       #9FB0B8;
  --faint:       #7A8D94;
  --foot:        #6A7D84;
  --accent:      #15B9CE;
  --accent-text: #15B9CE;
  --on-accent:   #021417;
  --solid:       #15B9CE;
  --btn-glow:    rgba(21,185,206,.35);
  --orb1: rgba(21,185,206,.38); --orb2: rgba(11,94,107,.55); --orb3: rgba(30,111,217,.20);
  --glass:       rgba(255,255,255,.055);
  --glass-line:  rgba(255,255,255,.11);
  --glass-hi:    rgba(255,255,255,.16);
  --glass-shadow:0 20px 50px rgba(0,0,0,.35);
  --chip:        rgba(255,255,255,.07);
  --chip-line:   rgba(255,255,255,.10);
  --field:       rgba(0,0,0,.28);
  --field-line:  rgba(21,185,206,.38);
  --ring:        rgba(21,185,206,.20);
  --sub-surface: rgba(0,0,0,.20);
  --sub-line:    rgba(255,255,255,.08);
  --error:       #FF5A69;
  --error-ring:  rgba(255,90,105,.18);
  --warn:        #FFD60A;
  --ok:          #30D158;
  --fill-grad:   #0B7285, #15B9CE, #6FE3F0;
  --fill-glow:   0 0 14px rgba(21,185,206,.7);
  --track-bg:    rgba(255,255,255,.07);
  --font:  "IBM Plex Sans Arabic", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --latin: "Inter", "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", sans-serif;
  --ease: cubic-bezier(.32,.72,0,1);
  --r-card: 28px; --r-field: 15px; --r-btn: 18px;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #EEF4F6; --text: #0A1316; --muted: #4B5E65; --faint: #5E7178; --foot: #6B8087;
    --accent: #15B9CE; --accent-text: #0B7285; --on-accent: #FFFFFF; --solid: #0B7285; --btn-glow: rgba(11,114,133,.30);
    --orb1: rgba(21,185,206,.32); --orb2: rgba(127,216,228,.55); --orb3: rgba(156,196,255,.38);
    --glass: rgba(255,255,255,.58); --glass-line: rgba(255,255,255,.95); --glass-hi: #FFFFFF;
    --glass-shadow: 0 20px 50px rgba(11,114,133,.14);
    --chip: rgba(255,255,255,.60); --chip-line: rgba(255,255,255,.90);
    --field: rgba(255,255,255,.75); --field-line: rgba(11,114,133,.32); --ring: rgba(21,185,206,.22);
    --sub-surface: rgba(255,255,255,.50); --sub-line: rgba(11,114,133,.12);
    --error: #C4192C; --error-ring: rgba(196,25,44,.14); --warn: #8A6100; --ok: #1E8E3E;
    --fill-grad: #0B7285, #15B9CE, #5ED9E8; --fill-glow: 0 0 10px rgba(21,185,206,.45);
    --track-bg: rgba(255,255,255,.60);
  }
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #EEF4F6; --text: #0A1316; --muted: #4B5E65; --faint: #5E7178; --foot: #6B8087;
  --accent: #15B9CE; --accent-text: #0B7285; --on-accent: #FFFFFF; --solid: #0B7285; --btn-glow: rgba(11,114,133,.30);
  --orb1: rgba(21,185,206,.32); --orb2: rgba(127,216,228,.55); --orb3: rgba(156,196,255,.38);
  --glass: rgba(255,255,255,.58); --glass-line: rgba(255,255,255,.95); --glass-hi: #FFFFFF;
  --glass-shadow: 0 20px 50px rgba(11,114,133,.14);
  --chip: rgba(255,255,255,.60); --chip-line: rgba(255,255,255,.90);
  --field: rgba(255,255,255,.75); --field-line: rgba(11,114,133,.32); --ring: rgba(21,185,206,.22);
  --sub-surface: rgba(255,255,255,.50); --sub-line: rgba(11,114,133,.12);
  --error: #C4192C; --error-ring: rgba(196,25,44,.14); --warn: #8A6100; --ok: #1E8E3E;
  --fill-grad: #0B7285, #15B9CE, #5ED9E8; --fill-glow: 0 0 10px rgba(21,185,206,.45);
  --track-bg: rgba(255,255,255,.60);
}

/* logo + theme icon follow the active theme */
/* (.top prefix raises specificity above .logo { display: grid }) */
.top .lg-light, .top .ic-sun { display: none; }
:root[data-theme="light"] .top .lg-dark, :root[data-theme="light"] .top .ic-moon { display: none; }
:root[data-theme="light"] .top .lg-light, :root[data-theme="light"] .top .ic-sun { display: grid; }
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) .top .lg-dark, :root:not([data-theme="dark"]) .top .ic-moon { display: none; }
  :root:not([data-theme="dark"]) .top .lg-light, :root:not([data-theme="dark"]) .top .ic-sun { display: grid; }
}

/* ---------- base ---------- */
* { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 400 16px/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh; min-height: 100dvh;
  transition: background-color .35s var(--ease), color .35s var(--ease);
}
html[lang="fr"] body, html[lang="en"] body { font-family: var(--latin); }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
::selection { background: rgba(21,185,206,.35); }

/* ---------- animated light background (gradients, no blur filter: cheap on weak phones) ---------- */
.bg { position: fixed; inset: 0; overflow: hidden; z-index: 0; pointer-events: none; }
.orb { position: absolute; border-radius: 50%; will-change: transform; animation: drift 18s ease-in-out infinite alternate; }
.o1 { width: 70vmax; height: 70vmax; top: -25vmax; right: -30vmax; background: radial-gradient(circle, var(--orb1), transparent 68%); }
.o2 { width: 60vmax; height: 60vmax; bottom: -20vmax; left: -28vmax; background: radial-gradient(circle, var(--orb2), transparent 68%); animation-duration: 22s; }
.o3 { width: 40vmax; height: 40vmax; top: 35%; right: -10vmax; background: radial-gradient(circle, var(--orb3), transparent 68%); animation-duration: 14s; }
@keyframes drift { to { transform: translate3d(3vmax, 4vmax, 0) scale(1.08); } }

/* ---------- layout ---------- */
main {
  position: relative; z-index: 1;
  width: 100%; max-width: 560px; margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column;
}
@media (min-width: 1024px) {
  main { max-width: 640px; padding-top: 48px; }
  h1 { font-size: 38px !important; }
  .card { padding: 28px 26px !important; }
}

/* ---------- header ---------- */
.top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.logo { display: grid; place-items: center; }
.bname { font: 700 15px/1 var(--latin); letter-spacing: .5px; direction: ltr; }
.ctrls { display: flex; gap: 8px; align-items: center; }

.seg, .tg {
  background: var(--chip); border: 1px solid var(--chip-line);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
}
.seg { display: flex; padding: 3px; border-radius: 14px; direction: ltr; }
.seg button {
  min-width: 40px; min-height: 38px; padding: 0 8px;
  border: 0; border-radius: 11px; background: transparent; color: var(--muted);
  font: 600 13px/1 var(--latin); cursor: pointer;
  transition: background-color .25s var(--ease), color .25s var(--ease), transform .2s var(--ease);
}
.seg button[lang="ar"] { font-family: var(--font); font-size: 15px; }
.seg button[aria-pressed="true"] { background: var(--solid); color: var(--on-accent); }
.tg {
  width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center;
  color: var(--accent-text); cursor: pointer;
  transition: transform .2s var(--ease);
}
.seg button:active, .tg:active { transform: scale(.94); }

/* ---------- headline ---------- */
h1 { font-weight: 800; font-size: clamp(26px, 7vw, 34px); line-height: 1.25; margin-top: 26px; letter-spacing: -.3px; }
[dir="rtl"] h1 { line-height: 1.45; letter-spacing: 0; }
.tagline { margin-top: 4px; font-size: 16px; font-weight: 500; color: var(--accent-text); }

/* ---------- progress ---------- */
.prog { margin-top: 20px; }
.prow { display: flex; justify-content: space-between; font-weight: 600; font-size: 12px; margin-bottom: 7px; color: var(--muted); }
.prow .num { color: var(--accent-text); direction: ltr; unicode-bidi: isolate; }
.track { height: 10px; border-radius: 10px; overflow: hidden; position: relative; background: var(--track-bg); border: 1px solid var(--chip-line); }
.fill {
  position: absolute; top: 0; bottom: 0; left: 0; width: 0; border-radius: 10px; overflow: hidden;
  background: linear-gradient(90deg, var(--fill-grad)); box-shadow: var(--fill-glow);
  transition: width .6s var(--ease);
}
[dir="rtl"] .fill { left: auto; right: 0; background: linear-gradient(270deg, var(--fill-grad)); }
.fill::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.55), transparent);
  animation: shine 2.4s infinite;
}
[dir="rtl"] .fill::after { animation-direction: reverse; }
@keyframes shine { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

/* ---------- glass card ---------- */
.glass {
  background: var(--glass); border: 1px solid var(--glass-line);
  -webkit-backdrop-filter: blur(24px) saturate(170%); backdrop-filter: blur(24px) saturate(170%);
  box-shadow: inset 0 1px 0 var(--glass-hi), var(--glass-shadow);
}
.card { margin-top: 16px; border-radius: var(--r-card); padding: 20px 18px; }

/* ---------- fields ---------- */
.field { margin: 0 0 16px; border: 0; padding: 0; min-width: 0; }
label, legend { display: block; font-weight: 600; font-size: 14px; margin-bottom: 7px; }
legend { padding: 0; }
.opt  { color: var(--faint); font-weight: 400; font-size: 12px; }
.hint { color: var(--faint); font-size: 12px; margin-top: 6px; }
.warn { color: var(--warn); font-size: 12px; margin-bottom: 8px; }
.counter { text-align: end; }
.num { font-family: var(--latin); font-variant-numeric: tabular-nums; }

input:not([type="checkbox"]):not([type="radio"]), select, textarea {
  width: 100%; display: block;
  background: var(--field); color: var(--text);
  border: 1.5px solid var(--field-line); border-radius: var(--r-field);
  font-size: 16px; /* 16px prevents iOS zoom on focus */
  outline: none; -webkit-appearance: none; appearance: none;
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease), background-color .35s var(--ease);
}
input:not([type="checkbox"]):not([type="radio"]), select { height: 50px; padding: 0 14px; }
textarea { padding: 12px 14px; resize: vertical; min-height: 88px; line-height: 1.6; }
::placeholder { color: var(--faint); opacity: 1; }
input[type="date"] { min-width: 0; }
input[type="date"]::-webkit-date-and-time-value { text-align: start; }
input[type="date"]::-webkit-calendar-picker-indicator { opacity: .75; cursor: pointer; }

select {
  cursor: pointer; padding-inline-end: 40px !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%2315B9CE' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 16px center;
}
[dir="rtl"] select { background-position: left 16px center; }
select:disabled { color: var(--faint); cursor: not-allowed; opacity: .75; }
select option { background: var(--bg); color: var(--text); }

input:focus, select:focus, textarea:focus { border-color: var(--accent) !important; box-shadow: 0 0 0 4px var(--ring); }
[aria-invalid="true"] { border-color: var(--error) !important; box-shadow: 0 0 0 4px var(--error-ring); }

.ltr { direction: ltr; text-align: left; }
[dir="rtl"] .ltr { text-align: right; }
[dir="rtl"] .ltr::placeholder { text-align: right; }

.row { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 12px; }
@media (max-width: 380px) { .row { grid-template-columns: minmax(0,1fr); gap: 0; } }

/* error text: collapses to nothing until needed */
.msg { color: var(--error); font-size: 12px; font-weight: 500; max-height: 0; opacity: 0; overflow: hidden;
       transition: max-height .3s var(--ease), opacity .25s var(--ease), margin .3s var(--ease); }
.msg.on { max-height: 60px; opacity: 1; margin-top: 6px; }
.consent-msg.on { margin: -8px 0 14px; }

/* ---------- gender: two big buttons ---------- */
.choice { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.opt-btn {
  position: relative; margin: 0; height: 50px; display: grid; place-items: center;
  border: 1.5px solid var(--field-line); border-radius: var(--r-field); background: var(--field);
  font-weight: 600; font-size: 15px; cursor: pointer;
  transition: border-color .2s var(--ease), background-color .25s var(--ease), color .2s var(--ease), transform .2s var(--ease), box-shadow .2s var(--ease);
}
.opt-btn input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.opt-btn:active { transform: scale(.97); }
.opt-btn:has(input:focus-visible) { box-shadow: 0 0 0 4px var(--ring); }
.opt-btn:has(input:checked) { border-color: var(--solid); background: var(--solid); color: var(--on-accent); }
#gender[aria-invalid="true"] .opt-btn { border-color: var(--error); }
#gender[aria-invalid="true"] { box-shadow: none; }

/* ---------- consent ---------- */
.consent {
  position: relative; display: flex; gap: 12px; align-items: flex-start;
  padding: 14px; margin: 4px 0 16px; border-radius: 16px;
  background: var(--sub-surface); border: 1px solid var(--sub-line);
  font-size: 13px; font-weight: 400; line-height: 1.7; color: var(--muted); cursor: pointer;
}
.consent input { position: absolute; opacity: 0; width: 22px; height: 22px; margin: 2px 0 0; cursor: pointer; }
.box {
  width: 22px; height: 22px; flex-shrink: 0; margin-top: 2px; border-radius: 7px;
  display: grid; place-items: center; border: 1.5px solid var(--accent-text); color: transparent;
  transition: background-color .2s var(--ease), color .2s var(--ease), transform .2s var(--ease);
}
.box svg path { stroke-dasharray: 24; stroke-dashoffset: 24; transition: stroke-dashoffset .3s var(--ease); }
.consent input:checked + .box { background: var(--solid); color: var(--on-accent); }
.consent input:checked + .box svg path { stroke-dashoffset: 0; }
.consent input:focus-visible + .box { box-shadow: 0 0 0 4px var(--ring); }
.consent.bad .box { border-color: var(--error); }

.del { margin: -4px 0 18px; font-size: 12px; color: var(--muted); }
.del a { color: var(--accent-text); text-decoration: underline; text-underline-offset: 3px; font-family: var(--latin);
         direction: ltr; unicode-bidi: isolate; display: inline-block; white-space: nowrap; }

.ts { margin-bottom: 16px; min-height: 65px; display: flex; justify-content: center; }

/* ---------- button ---------- */
.btn {
  position: relative; width: 100%; height: 56px; border: 0; border-radius: var(--r-btn);
  background: var(--solid); color: var(--on-accent);
  font: 700 17px/1 var(--font); cursor: pointer;
  box-shadow: 0 10px 30px var(--btn-glow), inset 0 1px 0 rgba(255,255,255,.4);
  transition: transform .2s var(--ease), filter .2s var(--ease), opacity .2s var(--ease);
}
html[lang="fr"] .btn, html[lang="en"] .btn { font-family: var(--latin); }
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: scale(.98); }
.btn[aria-busy="true"] { cursor: progress; }
.btn[aria-busy="true"] .btn-label { opacity: 0; }
.spinner {
  position: absolute; inset: 0; margin: auto; width: 22px; height: 22px; border-radius: 50%;
  border: 2.5px solid currentColor; border-right-color: transparent; opacity: 0;
}
.btn[aria-busy="true"] .spinner { opacity: 1; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#status { margin-top: 14px; font-size: 14px; min-height: 22px; text-align: center; }
#status.ok  { color: var(--ok); }
#status.err { color: var(--error); }

/* ---------- success ---------- */
.ok { display: flex; flex-direction: column; align-items: center; text-align: center; margin-top: 12vh; padding: 40px 22px; outline: none;
      animation: rise .6s var(--ease) both; }
.check { width: 96px; height: 96px; border-radius: 50%; display: grid; place-items: center;
         background: rgba(21,185,206,.14); border: 1.5px solid rgba(21,185,206,.6); box-shadow: 0 0 40px rgba(21,185,206,.35);
         animation: pop .6s .1s var(--ease) both; }
.check svg { width: 46px; height: 46px; }
.check path { stroke: var(--accent-text); stroke-width: 5; fill: none; stroke-linecap: round; stroke-linejoin: round;
              stroke-dasharray: 60; stroke-dashoffset: 60; animation: draw .7s .35s var(--ease) forwards; }
.ok h2 { font-weight: 800; font-size: 26px; margin-top: 22px; }
.ok p  { color: var(--muted); font-size: 15px; margin-top: 8px; }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes pop  { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes rise { from { transform: translateY(18px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- entrance ---------- */
.ready #formView > * { animation: rise .55s var(--ease) both; }
.ready #formView > :nth-child(2) { animation-delay: .04s; }
.ready #formView > :nth-child(3) { animation-delay: .08s; }
.ready #formView > :nth-child(4) { animation-delay: .12s; }

/* ---------- footer ---------- */
.foot { margin-top: auto; padding-top: 32px; text-align: center; font: 700 11px/1 var(--latin); letter-spacing: 3px; color: var(--foot); direction: ltr; }

/* ---------- fallback when app.js never runs ---------- */
.fallback { display: none; margin-top: 40px; padding: 18px; border-radius: 18px; border: 1px solid var(--error); color: var(--text); font-size: 14px; line-height: 1.8; }
.fallback p + p { margin-top: 8px; }
html:not(.ready) .fallback { display: block; opacity: 0; animation: appear .3s 6s forwards; }
html:not(.ready) #formView, html:not(.ready) .ctrls { visibility: hidden; }
@keyframes appear { to { opacity: 1; } }

/* ---------- comfort and weak devices ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  .check path { stroke-dashoffset: 0; }
}
@media (max-width: 400px) {
  .seg, .tg { -webkit-backdrop-filter: none; backdrop-filter: none; }
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .glass { background: var(--bg); }
}
