/* ==========================================================================
   الكشاف — design system
   Tokens, background and shadows carried over from the reference project
   (apps/web/tailwind.config.ts and apps/web/src/app/globals.css), rebuilt as
   plain CSS custom properties.

   Logical properties only. No physical left/right anywhere in this file.
   ========================================================================== */

:root {
  color-scheme: light;

  /* Palette */
  --background: #fafafb;
  --surface: #ffffff;
  --surface-soft: #f3f2f9;
  --primary: #6d28d9;
  --primary-soft: #ede9fe;
  --secondary: #0ea5a4;
  --accent: #f59e0b;
  --text: #18152a;
  --text-muted: #6b6880;
  --border: #ebe9f3;

  /* Feedback — derived from the palette, not new brand colours */
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --success: #067647;
  --success-soft: #ecfdf3;

  /* Shadows */
  --shadow-card: 0 4px 24px -8px rgba(24, 21, 42, 0.1);
  --shadow-card-hover: 0 18px 48px -12px rgba(109, 40, 217, 0.28);
  --shadow-glow: 0 12px 40px -8px rgba(109, 40, 217, 0.45);

  /* Radii */
  --radius-2xl: 1.25rem;
  --radius-3xl: 1.75rem;
  --radius-4xl: 2.25rem;

  /* Type */
  --font-body: 'Tajawal', system-ui, sans-serif;
  --font-display: 'Cairo', system-ui, sans-serif;
  --font-brand: 'Aref Ruqaa', 'Cairo', serif;

  /* Layout */
  --reading-column: 30rem;
  --wide-column: 64rem;
  --touch-target: 2.75rem; /* 44px */
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Fixed background layer — position:fixed on a pseudo-element works on
   iOS/Android unlike background-attachment:fixed which is broken on mobile. */
html::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -2;
  background-color: #e4ddf6;
  background-image:
    linear-gradient(148deg,
      rgba(109, 40, 217, 0.14) 0%,
      transparent 38%,
      rgba(14, 165, 164, 0.11) 100%),
    radial-gradient(ellipse 125rem 100rem at 94% -20%,
      rgba(109, 40, 217, 0.55) 0%,
      rgba(124, 58, 237, 0.28) 34%,
      transparent 58%),
    radial-gradient(ellipse 100rem 85rem at -12% 105%,
      rgba(14, 165, 164, 0.5) 0%,
      rgba(6, 182, 212, 0.2) 36%,
      transparent 56%),
    radial-gradient(ellipse 52rem 44rem at 110% 40%,
      rgba(217, 70, 239, 0.28) 0%,
      transparent 50%),
    radial-gradient(ellipse 66rem 55rem at -8% 48%,
      rgba(124, 58, 237, 0.3) 0%,
      transparent 52%),
    radial-gradient(ellipse 80rem 46rem at 48% -10%,
      rgba(6, 182, 212, 0.22) 0%,
      transparent 52%),
    radial-gradient(ellipse 115rem 75rem at 50% 56%,
      rgba(79, 70, 229, 0.13) 0%,
      transparent 65%),
    radial-gradient(ellipse 75rem 62rem at 115% 110%,
      rgba(14, 165, 164, 0.34) 0%,
      transparent 50%),
    radial-gradient(ellipse 58rem 46rem at -6% -2%,
      rgba(109, 40, 217, 0.24) 0%,
      transparent 50%),
    radial-gradient(circle, rgba(109, 40, 217, 0.14) 1px, transparent 1px);
  background-size: auto, auto, auto, auto, auto, auto, auto, auto, auto, 20px 20px;
}

/* Grain overlay — fixed pseudo-element, same reliable technique */
html::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.72' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)' opacity='1'/%3E%3C/svg%3E");
  opacity: 0.032;
  pointer-events: none;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.75;
  color: var(--text);
  background: transparent;
}

::selection {
  background: rgba(109, 40, 217, 0.18);
}

::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #6d28d9 0%, #0ea5a4 100%);
  border-radius: 999px;
}

h1,
h2,
h3 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.35;
  margin-block: 0 0.5rem;
  text-wrap: balance;
}

h1 {
  font-size: clamp(1.5rem, 1.2rem + 1.4vw, 2rem);
}
h2 {
  font-size: clamp(1.25rem, 1.1rem + 0.8vw, 1.5rem);
}

p {
  margin-block: 0 1rem;
}

a {
  color: var(--primary);
  text-underline-offset: 0.25em;
}
a:hover {
  color: #5b21b6;
}

:where(a, button, input, select, textarea):focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 0.5rem;
}

/* ---- skip link --------------------------------------------------------- */

.skip-link {
  position: absolute;
  inset-block-start: -100%;
  inset-inline-start: 0;
  z-index: 100;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-end-end-radius: var(--radius-2xl);
}
.skip-link:focus {
  inset-block-start: 0;
}

/* ---- shell ------------------------------------------------------------- */

/* Floating pill header, ported from StickyHeader.tsx in the reference project:
   fixed to the top, centred, max-width 3xl, bottom corners rounded, a 1px
   border with no top edge, white at 75% behind a backdrop blur. */
.site-header {
  position: fixed;
  inset-block-start: 0;
  inset-inline: 0;
  z-index: 50;
  margin-inline: auto;
  max-inline-size: 48rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-block: 0.75rem;
  padding-inline: 1.5rem;
  border: 1px solid var(--border);
  border-block-start: 0;
  border-end-start-radius: var(--radius-2xl);
  border-end-end-radius: var(--radius-2xl);
  background: rgba(255, 255, 255, 0.75);
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.wordmark {
  font-family: var(--font-brand);
  font-size: 1.5rem;
  line-height: 1.4;
  text-decoration: none;
  /* Gradient wordmark, as BrandMark.tsx renders it: primary to secondary,
     running toward the inline end. */
  background-image: linear-gradient(to left, var(--primary), var(--primary), var(--secondary));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.site-header__end {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
}

/* The tagline is decoration; it goes first when space runs out. */
.tagline {
  display: none;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
}

.tagline__dot {
  inline-size: 0.375rem;
  block-size: 0.375rem;
  border-radius: 999px;
  background: var(--primary);
  flex: none;
}

@media (min-width: 40rem) {
  .tagline {
    display: inline-flex;
  }
}

.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  align-items: center;
}

.site-nav a,
.site-nav button {
  display: inline-flex;
  align-items: center;
  min-block-size: var(--touch-target);
  padding-inline: 0.75rem;
  border-radius: 999px;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  text-decoration: none;
  color: var(--text-muted);
  background: none;
  border: 0;
  cursor: pointer;
  transition: color 0.15s ease, background-color 0.15s ease;
}
.site-nav a:hover,
.site-nav button:hover {
  color: var(--primary);
  background: var(--primary-soft);
}
.site-nav a[aria-current='page'] {
  color: var(--primary);
  background: var(--primary-soft);
}

.site-main {
  flex: 1;
  inline-size: 100%;
  /* Clear the fixed header. */
  padding-block-start: calc(4.5rem + clamp(1rem, 0.5rem + 2vw, 2.5rem));
  padding-block-end: clamp(1.5rem, 1rem + 3vw, 3.5rem);
  padding-inline: 1.25rem;
}

.site-footer {
  padding-block: 1.5rem;
  padding-inline: 1.25rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  border-block-start: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.55);
}

.site-footer__inner {
  max-inline-size: var(--wide-column);
  margin-inline: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  align-items: center;
  justify-content: space-between;
}

/* ---- containers -------------------------------------------------------- */

.reading-column {
  inline-size: 100%;
  max-inline-size: var(--reading-column);
  margin-inline: auto;
}

.wide-column {
  inline-size: 100%;
  max-inline-size: var(--wide-column);
  margin-inline: auto;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-3xl);
  box-shadow: var(--shadow-card);
  padding: clamp(1.25rem, 1rem + 2vw, 2.25rem);
}

.card--flush {
  padding-inline: clamp(1rem, 0.5rem + 2vw, 2.25rem);
}

.page-head {
  margin-block-end: 1.5rem;
}
.page-head p {
  color: var(--text-muted);
  margin-block-end: 0;
}

/* ---- forms ------------------------------------------------------------- */

.field {
  margin-block-end: 1.125rem;
}

.field__label {
  display: block;
  font-family: var(--font-display);
  font-size: 0.9375rem;
  font-weight: 600;
  margin-block-end: 0.375rem;
}

.field__hint {
  display: block;
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-block-start: 0.25rem;
}

.input,
.select,
.textarea {
  inline-size: 100%;
  min-block-size: var(--touch-target);
  padding-block: 0.625rem;
  padding-inline: 0.875rem;
  font-family: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-2xl);
  text-align: start;
}

.textarea {
  min-block-size: 6rem;
  line-height: 1.7;
  resize: vertical;
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-soft);
  outline: none;
}

.input[aria-invalid='true'],
.select[aria-invalid='true'],
.textarea[aria-invalid='true'] {
  border-color: var(--danger);
}

.input:disabled,
.select:disabled,
.input[readonly] {
  background: var(--surface-soft);
  color: var(--text-muted);
  cursor: not-allowed;
}

.field__error {
  display: block;
  font-size: 0.8125rem;
  color: var(--danger);
  margin-block-start: 0.3125rem;
}

/* A value the user may see but never change. */
.readonly-value {
  display: block;
  min-block-size: var(--touch-target);
  padding-block: 0.625rem;
  padding-inline: 0.875rem;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-2xl);
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

/* ---- buttons ----------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  /* The reference CTA is min-h-[48px]; comfortably over the 44px floor. */
  min-block-size: 3rem;
  padding-block: 0.75rem;
  padding-inline: 1.5rem;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  border: 1px solid transparent;
  /* rounded-2xl in the reference, not a pill. */
  border-radius: var(--radius-2xl);
  cursor: pointer;
  text-decoration: none;
  transition: opacity 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease,
    background-color 0.2s ease;
}

/* Solid primary with the glow shadow, and opacity on hover — the reference
   CTA does not lift or change hue. */
.btn--primary {
  color: #fff;
  background: var(--primary);
  box-shadow: var(--shadow-glow);
}
.btn--primary:hover {
  color: #fff;
  opacity: 0.9;
}
.btn--primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn--quiet {
  color: var(--text);
  background: var(--surface);
  border-color: var(--border);
}
.btn--quiet:hover {
  color: var(--text);
  border-color: var(--primary);
  box-shadow: var(--shadow-card);
}

.btn--danger {
  color: #fff;
  background: var(--danger);
}
.btn--danger:hover {
  color: #fff;
  opacity: 0.9;
}

.btn--block {
  inline-size: 100%;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-block-start: 1.5rem;
}

/* ---- alerts ------------------------------------------------------------ */

.alert {
  padding-block: 0.875rem;
  padding-inline: 1.125rem;
  border-radius: var(--radius-2xl);
  border: 1px solid var(--border);
  margin-block-end: 1.25rem;
  font-size: 0.9375rem;
}
.alert p:last-child {
  margin-block-end: 0;
}

.alert--error {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: rgba(180, 35, 24, 0.24);
}
.alert--success {
  color: var(--success);
  background: var(--success-soft);
  border-color: rgba(6, 118, 71, 0.24);
}
.alert--info {
  color: var(--primary);
  background: var(--primary-soft);
  border-color: rgba(109, 40, 217, 0.2);
}

.alert__list {
  margin-block: 0.5rem 0;
  padding-inline-start: 1.25rem;
}

/* ---- misc -------------------------------------------------------------- */

.muted {
  color: var(--text-muted);
}

.stack > * + * {
  margin-block-start: 1rem;
}

.form-aside {
  margin-block-start: 1.25rem;
  font-size: 0.9375rem;
  color: var(--text-muted);
  text-align: center;
}

.definition-list {
  display: grid;
  gap: 1rem;
  margin: 0;
}

.definition-list dt {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.9375rem;
  margin-block-end: 0.375rem;
}

.definition-list dd {
  margin-inline-start: 0;
}

.error-page {
  text-align: center;
  padding-block: clamp(2rem, 1rem + 6vw, 5rem);
}

.error-page__code {
  font-family: var(--font-brand);
  font-size: clamp(3rem, 2rem + 8vw, 6rem);
  line-height: 1;
  color: var(--primary);
  margin-block-end: 0.5rem;
}

/* Two-column form rows once there is room for them. */
.field-grid {
  display: grid;
  gap: 0 1rem;
}

@media (min-width: 40rem) {
  .field-grid--pair {
    grid-template-columns: 1fr 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ==========================================================================
   Phase 3 — the test runner
   Appended. Nothing above this line is modified.
   ========================================================================== */

/* ---- test catalogue ---------------------------------------------------- */

.test-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.75rem;
}

.test-card {
  display: grid;
  gap: 0.375rem;
  padding-block: 1rem;
  padding-inline: 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-2xl);
  background: var(--surface);
  text-decoration: none;
  color: var(--text);
  min-block-size: var(--touch-target);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.test-card:hover {
  color: var(--text);
  border-color: var(--primary);
  box-shadow: var(--shadow-card);
}

.test-card__name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.0625rem;
}

.test-card__desc {
  font-size: 0.9375rem;
  color: var(--text-muted);
  line-height: 1.7;
}

.test-card__badge {
  justify-self: start;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--danger);
  background: var(--danger-soft);
  border-radius: 999px;
  padding-block: 0.125rem;
  padding-inline: 0.5rem;
}

/* ---- the step screen --------------------------------------------------- */
/* Calm and uncluttered: one question, nothing competing with it. */

.card--step {
  padding-block: clamp(1.25rem, 1rem + 2vw, 2rem);
}

.step__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  justify-content: space-between;
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-block-end: 0.625rem;
}

.progress {
  block-size: 0.25rem;
  border-radius: 999px;
  background: var(--surface-soft);
  overflow: hidden;
  margin-block-end: clamp(1.25rem, 1rem + 2vw, 2rem);
}

.progress__bar {
  block-size: 100%;
  border-radius: 999px;
  background: linear-gradient(to left, var(--primary), var(--secondary));
  transition: inline-size 0.3s ease;
}

.step__prompt {
  font-size: 0.9375rem;
  color: var(--text-muted);
  margin-block-end: 1rem;
}

/* The statement being rated. Large, generous, alone on the screen. */
.step__statement {
  font-size: clamp(1.125rem, 1rem + 0.8vw, 1.375rem);
  line-height: 2;
  margin-block-end: 1.5rem;
  padding-block: 1.25rem;
  padding-inline: 1.25rem;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-2xl);
}

/* A parenthetical clarifier: explanatory, excluded from measurement. Smaller
   and dimmer, deliberately still readable. */
.stem-hint {
  font-size: 0.8em;
  color: var(--text-muted);
  font-style: italic;
}

/* ---- choice step ------------------------------------------------------- */

.choice-grid {
  display: grid;
  gap: 0.75rem;
}

.choice {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  inline-size: 100%;
  min-block-size: var(--touch-target);
  padding-block: 1.125rem;
  padding-inline: 1.25rem;
  font-family: inherit;
  font-size: clamp(1rem, 0.95rem + 0.4vw, 1.125rem);
  line-height: 1.9;
  text-align: start;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-2xl);
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}
.choice:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-card);
}
.choice[aria-pressed='true'],
.choice.is-selected {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: var(--shadow-card);
}

.choice__letter {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  inline-size: 1.75rem;
  block-size: 1.75rem;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
  font-family: var(--font-display);
}

/* ---- rating scale ------------------------------------------------------ */
/*
   Direction is transcribed from the source, not chosen here: the button row
   runs left-to-right so 1 sits at the inline end and 6 at the inline start,
   and the anchors below are ordered to match.
*/
.scale {
  display: flex;
  direction: ltr;
  gap: 0.5rem;
  justify-content: space-between;
  margin-block-end: 0.5rem;
}

.scale__btn {
  flex: 1 1 0;
  min-inline-size: var(--touch-target);
  min-block-size: 3.25rem;
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-2xl);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}
.scale__btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}
.scale__btn.is-selected {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.scale__anchors {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-block-end: 1.25rem;
}

/* ---- step footer ------------------------------------------------------- */

.step__foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-block-start: 1.25rem;
}

.btn--sm {
  min-block-size: var(--touch-target);
  padding-inline: 1rem;
  font-size: 0.875rem;
}

.step__hint {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-block: 0.75rem 0;
}

.step__hint kbd {
  font-family: inherit;
  font-size: 0.8125rem;
  padding-block: 0.0625rem;
  padding-inline: 0.375rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  background: var(--surface-soft);
}

/* Unobtrusive: it appears when a step saves and fades on its own. */
.saved-indicator {
  font-size: 0.8125rem;
  color: var(--success);
  opacity: 0;
  transition: opacity 0.2s ease;
}
.saved-indicator.is-visible {
  opacity: 1;
}

.attempt-shell.is-busy {
  opacity: 0.6;
  pointer-events: none;
}
