// Direction D — WXG Authentic
// Closely matches WXG's actual visual language:
//  • Authentic recreated logo (W X G with amber square)
//  • title--square treatment: bold heading + amber underline square
//  • Sharp corners only (no border-radius)
//  • Skyline progress bar built from the WXG project list (each
//    completed question = next building lit up in amber)
//  • City-line motif at the bottom of every screen
//  • Hebrew RTL throughout

const D_TYPE = WXG_FONT;
const D_MONO = WXG_MONO;

// ─────────────────────────────────────────────────────────────
// Authentic WXG wordmark (recreated from the careers logo SVG path data)
// ─────────────────────────────────────────────────────────────
function WXGAuthentic({ height = 56, color = '#4D4D4D', accent = '#FCAF17' }) {
  // Original viewBox 0 0 426 122 — keep aspect
  const w = height * (426 / 122);
  return (
    <svg width={w} height={height} viewBox="0 0 426 122" fill="none" xmlns="http://www.w3.org/2000/svg" aria-label="WXG">
      <path d="m322.744 59.065-1.014 12.203h47.371c-.62 6.802-1.943 13.812-6.014 19.971-7.605 11.453-21.826 18.288-38.04 18.288-14.749 0-27.245-4.726-36.139-13.653-8.376-8.419-12.99-20.23-12.99-33.25s4.304-25.99 12.11-34.9c8.535-9.736 20.88-14.879 35.695-14.879 21.031 0 38.024 11.52 43.292 29.35l1.014 3.417h13.031l-1.834-6.143c-3.492-11.578-10.511-21.339-20.301-28.224C349.059 4.293 336.831.618 323.548.618c-18.476 0-34.021 6.56-44.95 18.97-9.841 11.162-15.26 26.449-15.26 43.036s5.955 30.908 16.767 41.685c11.365 11.32 26.843 17.296 44.774 17.296 14.364 0 30.495-6.135 40.126-15.229 11.315-10.269 16.583-23.789 16.583-42.543v-4.76H322.76l-.016-.008Z" fill={color}/>
      <path d="M425.941 90.01h-31.595v31.595h31.595V90.009Z" fill={accent}/>
      <path d="M152.682,0.618L139.042,0.628C138.175,0.628 137.408,1.05 136.849,1.366L136.674,1.466C136.04,1.789 135.423,2.187 134.864,2.643C133.505,3.738 132.412,5.157 131.612,6.857C131.178,7.778 130.836,8.682 130.561,9.628C130.419,10.101 130.302,10.574 130.186,11.097L129.679,13.36C129.608,13.666 129.536,13.978 129.46,14.299C129.413,14.514 129.363,14.729 129.314,14.944L128.71,17.526L128.422,18.726C128.335,19.09 128.248,19.451 128.167,19.807L127.834,21.192L127.208,23.839L127.017,24.659C126.867,25.282 126.716,25.913 126.575,26.543L125.707,30.193C125.568,30.797 125.426,31.398 125.285,31.996L124.74,34.333L124.315,36.141L124.085,37.13C123.917,37.838 123.75,38.542 123.589,39.252L122.08,45.682C121.932,46.325 121.78,46.972 121.626,47.622C121.518,48.077 121.411,48.533 121.304,48.992C121.145,49.682 120.987,50.369 120.82,51.057L115.542,73.48C115.24,74.741 114.944,76.003 114.653,77.267L114.379,78.436C114.147,79.428 113.914,80.419 113.69,81.386C113.558,81.943 113.426,82.509 113.295,83.074L113.015,84.248L112.689,85.621L112.364,86.993L110.655,94.277C110.547,94.752 110.436,95.225 110.321,95.696L110.254,95.986L85.169,0.619L68.031,0.619L42.563,95.48L23.307,11.67L23.248,11.396L23.115,11.156C22.944,10.846 22.81,10.517 22.715,10.176C20.963,3.896 17.344,1.566 14.617,0.72L14.317,0.628L0.557,0.628L0.557,12.268L9.555,12.268L33.956,116.21L50.285,116.21L76.655,20.345L102.032,116.21L118.435,116.21L143.362,12.265L152.682,12.255L152.682,0.618Z" fill={color}/>
      <path d="M152.369 116.211h17.757l9.23-11.623h-.133l29.035-36.758 29.027 36.758h-.15l9.246 11.623h16.79v-11.623h-9.388l-37.35-47.385-.009-.008 34.435-44.947h11.29V.618h-18.733l-3.531 4.529c-1.487 1.908-2.368 3.045-2.866 3.808l-.042-.033L208.25 46.75a28224.72 28224.72 0 0 1-27.905-36.783l.016-.025-7.277-9.324-20.715.015V12.27l13.263-.014 34.418 44.946-37.334 47.385h-10.347v11.623Z" fill={color}/>
    </svg>
  );
}

// Even simpler: just W X amber-square G mark for tight spaces
function WXGCompact({ height = 32, color = '#4D4D4D', accent = '#FCAF17' }) {
  const w = height * 2.6;
  return (
    <svg width={w} height={height} viewBox="0 0 156 60" fill="none" aria-label="WXG">
      <text x="0" y="48" fontFamily="'Heebo','Helvetica Neue',sans-serif" fontWeight="900" fontSize="56" letterSpacing="-2.5" fill={color}>WX</text>
      <text x="84" y="48" fontFamily="'Heebo','Helvetica Neue',sans-serif" fontWeight="900" fontSize="56" letterSpacing="-2.5" fill={color}>G</text>
      <rect x="132" y="32" width="20" height="20" fill={accent} />
    </svg>
  );
}

// ─────────────────────────────────────────────────────────────
// title--square treatment: bold + amber square underline accent
// ─────────────────────────────────────────────────────────────
function TitleSquare({ children, size = 64, color = WXG.ink, accent = WXG.amber, square = true }) {
  return (
    <h1 style={{
      fontFamily: D_TYPE, fontWeight: 800, fontSize: size,
      lineHeight: 1.05, letterSpacing: '-0.02em',
      margin: 0, color, position: 'relative', display: 'inline-block',
    }}>
      {children}
      {square && (
        <span aria-hidden="true" style={{
          display: 'inline-block', width: size * 0.18, height: size * 0.18,
          background: accent, marginInlineStart: size * 0.12,
          verticalAlign: 'baseline', transform: `translateY(${size * 0.02}px)`,
        }} />
      )}
    </h1>
  );
}

// ─────────────────────────────────────────────────────────────
// Skyline Progress Bar — buildings = WXG project portfolio
// Each step "builds" the next iconic structure
// ─────────────────────────────────────────────────────────────
const WXG_PROJECTS = [
  { name: 'קמפוס דיסקונט',         shape: 'tower',   h: 0.55 },
  { name: 'מגדל הספירלה',           shape: 'spiral',  h: 0.92 },
  { name: 'עזריאלי שרונה',           shape: 'tower',   h: 0.78 },
  { name: 'מידטאון ירושלים',        shape: 'block',   h: 0.45 },
  { name: 'כיכר המדינה',            shape: 'tower',   h: 0.85 },
  { name: 'ארלוזרוב 17',             shape: 'block',   h: 0.50 },
  { name: 'מגדלי גינדי',            shape: 'tower',   h: 0.72 },
];

// ─────────────────────────────────────────────────────────────
// Linear skyline — uses the actual WXG city-line SVG path.
// Desktop: a single flattened path (window.WXG_CITY_PATH).
// Mobile : a richer multi-path SVG with windows + accent squares
//          (window.WXG_CITY_MOBILE_INNER), classified into:
//            .wxg-base — main outline
//            .wxg-lit  — overlay duplicate (revealed by progress)
//            .wxg-dot  — small accent squares (revealed by progress)
// As progress advances, an amber overlay is revealed left-to-right
// via an animated <clipPath>.
// ─────────────────────────────────────────────────────────────
const CITY_PATH = (typeof window !== 'undefined' && window.WXG_CITY_PATH) || '';
const CITY_DETAILS = (typeof window !== 'undefined' && window.WXG_CITY_DETAILS) || [];
const CITY_VB = (typeof window !== 'undefined' && window.WXG_CITY_VIEWBOX) || '0 0 3341 366';
const CITY_VB_W = parseFloat(CITY_VB.split(/\s+/)[2]) || 3341;
const CITY_VB_H = parseFloat(CITY_VB.split(/\s+/)[3]) || 366;

const CITY_M_INNER = (typeof window !== 'undefined' && window.WXG_CITY_MOBILE_INNER) || '';
const CITY_M_VB = (typeof window !== 'undefined' && window.WXG_CITY_MOBILE_VIEWBOX) || '0 0 4332 1208';
const CITY_M_VB_W = parseFloat(CITY_M_VB.split(/\s+/)[2]) || 4332;
const CITY_M_VB_H = parseFloat(CITY_M_VB.split(/\s+/)[3]) || 1208;

function SkylineProgress({ current, total, mobile, dark = false }) {
  const accent = WXG.amber;
  const ground = dark ? '#0a0a0a' : '#FAF8F4';
  const groundLine = dark ? '#2a2a2a' : '#CDCDCD';
  const lineUnlit = dark ? '#3a3a3a' : '#A8A8A8';
  const labelColor = dark ? '#888' : WXG.slate;

  // Continuous progress 0..1 across the whole survey.
  const progress = current === 0 ? 0
                 : current > total ? 1
                 : current / (total + 1);

  // Render at a fixed display height; SVG scales the path to fit.
  const H = mobile ? 64 : 100;             // visual skyline height (px)
  const padBottom = 6;                     // breathing room below baseline

  // Stable IDs (one for desktop, one for mobile) so multiple
  // SkylineProgress instances on a page don't collide.
  const clipId = React.useMemo(
    () => 'wxg-skyline-clip-' + Math.random().toString(36).slice(2, 8), []);

  // Baseline depends on which SVG we're rendering.
  const VB_W = mobile ? CITY_M_VB_W : CITY_VB_W;
  const VB_H = mobile ? CITY_M_VB_H : CITY_VB_H;
  const baselineY = mobile ? 1180 : CITY_VB_H;   // mobile baseline ~ y=1180 in 1208 viewBox

  return (
    <div style={{
      position: 'relative', background: ground,
      borderTop: `1px solid ${groundLine}`,
      borderBottom: `1px solid ${groundLine}`,
      padding: mobile ? '10px 16px 0' : '16px 36px 0',
      overflow: 'hidden',
    }}>
      <div style={{
        position: 'relative', height: H + padBottom, width: '100%',
      }}>
        <svg width="100%" height={H + padBottom}
          viewBox={`0 0 ${VB_W} ${VB_H + padBottom * (VB_H / H)}`}
          preserveAspectRatio="xMidYMax meet"
          style={{ display: 'block', overflow: 'visible' }}>
          <defs>
            <clipPath id={clipId}>
              <rect x="0" y="0"
                width={progress * VB_W} height={VB_H + 50}
                style={{ transition: 'width 700ms cubic-bezier(.2,.8,.2,1)' }} />
            </clipPath>
          </defs>

          {mobile ? (
            // ── Mobile: render the rich multi-path SVG.
            // Layer 1: muted gray base (full width, always visible).
            // Layer 2: amber overlay paths + accent squares, clipped by progress.
            <React.Fragment>
              <g style={{ color: lineUnlit }}
                fill="none" strokeWidth="36"
                strokeLinejoin="miter" strokeLinecap="square"
                dangerouslySetInnerHTML={{
                  __html: CITY_M_INNER
                    // Base layer: hide the .wxg-lit duplicate paths and the .wxg-dot fills
                    .replace(/class="wxg-lit" fill="none" stroke="currentColor"/g,
                             'class="wxg-lit" fill="none" stroke="none"')
                    .replace(/class="wxg-dot" fill="currentColor"/g,
                             'class="wxg-dot" fill="none"')
                }} />
              <g clipPath={`url(#${clipId})`}
                style={{ color: accent }}
                fill="none" strokeWidth="48"
                strokeLinejoin="miter" strokeLinecap="square"
                dangerouslySetInnerHTML={{
                  __html: CITY_M_INNER
                    // Lit layer: hide the .wxg-base outline (we use the lit duplicate)
                    .replace(/class="wxg-base" fill="none" stroke="currentColor"/g,
                             'class="wxg-base" fill="none" stroke="none"')
                }} />
            </React.Fragment>
          ) : (
            // ── Desktop: single flattened path + inner detail paths.
            <React.Fragment>
              <path d={CITY_PATH} fill="none" stroke={lineUnlit}
                strokeWidth="6"
                strokeLinejoin="miter" strokeLinecap="square" />
              {CITY_DETAILS.map((d, i) => (
                <path key={'bd' + i} d={d} fill="none" stroke={lineUnlit}
                  strokeWidth="4" strokeLinejoin="miter" strokeLinecap="round" />
              ))}
              <g clipPath={`url(#${clipId})`}>
                <path d={CITY_PATH} fill="none" stroke={accent}
                  strokeWidth="7"
                  strokeLinejoin="miter" strokeLinecap="square" />
                {CITY_DETAILS.map((d, i) => (
                  <path key={'ad' + i} d={d} fill="none" stroke={accent}
                    strokeWidth="5" strokeLinejoin="miter" strokeLinecap="round" />
                ))}
              </g>
            </React.Fragment>
          )}

          {/* baseline (ground) */}
          <line x1="0" y1={baselineY + 2} x2={VB_W} y2={baselineY + 2}
            stroke={groundLine} strokeWidth={mobile ? 6 : 4} />

          {/* amber progress fill on the baseline */}
          <line x1="0" y1={baselineY + 2}
            x2={progress * VB_W} y2={baselineY + 2}
            stroke={accent} strokeWidth={mobile ? 10 : 7}
            style={{ transition: 'all 700ms cubic-bezier(.2,.8,.2,1)' }} />

          {/* amber square marker traveling along the baseline */}
          {progress > 0 && (
            <rect
              x={progress * VB_W - (mobile ? 32 : 22)}
              y={baselineY - (mobile ? 24 : 16)}
              width={mobile ? 40 : 28}
              height={mobile ? 40 : 28}
              fill={accent}
              style={{ transition: 'all 700ms cubic-bezier(.2,.8,.2,1)' }} />
          )}
        </svg>
      </div>

      {/* metadata strip removed */}
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// Direction D — the screens
// ─────────────────────────────────────────────────────────────
function D_Frame({ children }) {
  return (
    <div dir="rtl" style={{
      width: '100%', height: '100%', position: 'relative',
      background: WXG.paper, color: WXG.ink,
      fontFamily: D_TYPE, overflow: 'hidden',
      display: 'flex', flexDirection: 'column',
    }}>{children}</div>
  );
}

function D_Header({ mobile }) {
  const px = mobile ? 16 : 36;
  return (
    <header style={{
      padding: `${mobile ? 16 : 22}px ${px}px`,
      display: 'flex', alignItems: 'center', justifyContent: 'space-between',
      borderBottom: `1px solid ${WXG.rule}`, background: WXG.paper,
      position: 'relative', zIndex: 5,
    }}>
      <WXGAuthentic height={mobile ? 36 : 44} />
      <div style={{
        display: 'flex', alignItems: 'center', gap: mobile ? 10 : 18,
        fontFamily: D_TYPE, fontSize: mobile ? 12 : 14, color: WXG.slate,
      }}>
        <span style={{ width: 8, height: 8, background: WXG.amber }} />
        <span>סקר שביעות רצון לקוחות</span>
        {!mobile && <span style={{ color: WXG.rule }}>·</span>}
        {!mobile && <span style={{ fontFamily: D_MONO, fontSize: 11, letterSpacing: 1.4, textTransform: 'uppercase' }}>2026 · 05 · 19</span>}
      </div>
    </header>
  );
}

function D_ProjectStrip({ mobile }) {
  const px = mobile ? 16 : 36;
  return (
    <div style={{
      padding: `${mobile ? 12 : 16}px ${px}px`,
      borderBottom: `1px solid ${WXG.rule}`,
      background: WXG.paperWarm,
      display: 'flex', justifyContent: 'center',
    }}>
      <div style={{
        width: '100%', maxWidth: mobile ? 320 : 760,
        display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start',
        gap: mobile ? 16 : 36,
      }}>
      {[
        ['פרויקט',     'מגדלי יבנה צפון'],
        ['אבן דרך',    'אחת לשנה'],
      ].map(([k, v]) => (
        <div key={k} style={{ position: 'relative' }}>
          <div style={{ fontFamily: D_MONO, fontSize: 9.5, letterSpacing: 1.4,
            color: WXG.slateLight, textTransform: 'uppercase', marginBottom: 3 }}>{k}</div>
          <div style={{ fontSize: mobile ? 13 : 15, color: WXG.ink, fontWeight: 600 }}>{v}</div>
        </div>
      ))}
      </div>
    </div>
  );
}

function D_Intro({ mobile, onStart }) {
  const px = mobile ? 20 : 56;
  return (
    <div style={{
      flex: 1, padding: mobile ? `28px ${px}px` : `48px ${px}px`,
      display: 'flex', flexDirection: 'column', justifyContent: 'center',
      gap: mobile ? 24 : 56, position: 'relative', overflow: 'hidden',
    }}>
      {/* squares motif background */}
      <div style={{ position: 'absolute', top: 24, insetInlineEnd: 24, opacity: 0.5, pointerEvents: 'none' }}>
        <SquaresMotif color={WXG.amber} opacity={0.18} size={300} />
      </div>

      {/* Faint linear-skyline backdrop, full-width behind everything */}
      <svg style={{
        position: 'absolute', insetInline: 0, bottom: 0, width: '100%',
        height: mobile ? 180 : 280, opacity: 0.18, pointerEvents: 'none',
      }} viewBox={typeof CITY_VIEWBOX !== 'undefined' ? CITY_VIEWBOX : '0 0 3341 366'}
        preserveAspectRatio="xMidYMax meet">
        <path d={typeof CITY_PATH !== 'undefined' ? CITY_PATH : ''}
          fill="none" stroke={WXG.slateLight}
          strokeWidth="5" strokeLinejoin="miter" strokeLinecap="square" />
        {CITY_DETAILS.map((d, i) => (
          <path key={i} d={d} fill="none" stroke={WXG.slateLight}
            strokeWidth="3" strokeLinejoin="miter" strokeLinecap="round" />
        ))}
      </svg>

      <div style={{ position: 'relative', zIndex: 2, maxWidth: 720,
        display: 'flex', flexDirection: 'column', alignItems: 'flex-start' }}>
        <h1 style={{
          fontFamily: D_TYPE, fontWeight: 800, fontSize: mobile ? 40 : 76,
          lineHeight: 1.02, letterSpacing: '-0.02em',
          margin: 0, color: WXG.ink,
        }}>
          הקשבה היא חלק<br />מההנדסה שלנו
          <span aria-hidden="true" style={{
            display: 'inline-block', width: mobile ? 14 : 20, height: mobile ? 14 : 20,
            background: WXG.amber, marginInlineStart: mobile ? 10 : 14,
            transform: 'translateY(-4px)',
          }} />
        </h1>

        <p style={{
          fontSize: mobile ? 15 : 19, lineHeight: 1.6, color: WXG.slate,
          marginTop: mobile ? 20 : 32, maxWidth: 540, fontWeight: 400,
        }}>
          חמש שאלות קצרות שמלוות אותך לאורך הסקר —
          ובמקביל, קו האופק של הפרויקטים שלנו נבנה איתך, אבן אחר אבן.
        </p>

        <div style={{ marginTop: mobile ? 32 : 48, display: 'flex',
          flexDirection: mobile ? 'column' : 'row',
          alignItems: mobile ? 'stretch' : 'center', gap: mobile ? 14 : 24 }}>
          <button onClick={onStart} style={{
            background: WXG.ink, color: WXG.paper, border: 'none', cursor: 'pointer',
            fontFamily: D_TYPE, fontSize: mobile ? 16 : 17, fontWeight: 700,
            padding: mobile ? '16px 28px' : '18px 32px',
            display: 'inline-flex', alignItems: 'center', gap: 14,
            borderRadius: 0, transition: 'all .2s', justifyContent: 'center',
          }}
          onMouseOver={e => { e.currentTarget.style.background = WXG.amber; e.currentTarget.style.color = WXG.ink; }}
          onMouseOut={e => { e.currentTarget.style.background = WXG.ink; e.currentTarget.style.color = WXG.paper; }}>
            <span>התחלת הסקר</span>
            <span style={{ width: 14, height: 14, background: WXG.amber }} />
          </button>
          <span style={{ fontFamily: D_MONO, fontSize: 11, letterSpacing: 1.4,
            color: WXG.slateLight, textTransform: 'uppercase' }}>
            5 שאלות · ~2 דקות · אנונימי
          </span>
        </div>

        {/* stats removed per request */}
      </div>
    </div>
  );
}

function D_Rating({ q, value, onChange, mobile }) {
  return (
    <div style={{ width: '100%' }}>
      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(5, 1fr)', gap: mobile ? 6 : 10 }}>
        {Array.from({ length: 5 }, (_, i) => {
          const n = i + 6;
          const active = value === n;
          const filled = value != null && n <= value;
          return (
            <button key={n} onClick={() => onChange(n)} style={{
              aspectRatio: '1', borderRadius: 0,
              border: `1.5px solid ${active ? WXG.ink : WXG.rule}`,
              background: filled ? (n >= 9 ? WXG.amber : n >= 7 ? WXG.amberMid : WXG.paper) : WXG.paper,
              color: filled && n >= 9 ? WXG.ink : active ? WXG.ink : filled ? WXG.ink : WXG.slate,
              fontFamily: D_TYPE, fontSize: mobile ? 18 : 26, fontWeight: 700,
              cursor: 'pointer', transition: 'all 200ms cubic-bezier(.2,.8,.2,1)',
              transform: active ? 'translateY(-2px)' : 'translateY(0)',
              position: 'relative',
            }}>
              {n}
              {active && <span style={{
                position: 'absolute', bottom: -6, insetInlineStart: -6,
                width: 10, height: 10, background: WXG.amber,
              }} />}
            </button>
          );
        })}
      </div>
      <div style={{ marginTop: 16, display: 'flex', justifyContent: 'space-between',
        fontFamily: D_TYPE, fontSize: mobile ? 14 : 20, color: WXG.slate, fontWeight: 500 }}>
        <span>{q.minLabel} →</span>
        <span>← {q.maxLabel}</span>
      </div>
    </div>
  );
}

function D_Choice({ q, value, onChange, mobile }) {
  return (
    <div style={{ display: 'grid', gap: mobile ? 8 : 10 }}>
      {q.options.map((o, i) => {
        const active = value === o;
        return (
          <button key={o} onClick={() => onChange(o)} style={{
            display: 'flex', alignItems: 'center', gap: mobile ? 14 : 18,
            padding: mobile ? '14px 16px' : '18px 22px',
            background: WXG.paper,
            color: WXG.ink, textAlign: 'right',
            border: `1.5px solid ${active ? WXG.ink : WXG.rule}`,
            fontFamily: D_TYPE, fontSize: mobile ? 15 : 17, fontWeight: active ? 600 : 500,
            cursor: 'pointer', borderRadius: 0,
            transition: 'all 200ms', position: 'relative',
          }}
          onMouseEnter={e => { if (!active) e.currentTarget.style.borderColor = WXG.slate; }}
          onMouseLeave={e => { if (!active) e.currentTarget.style.borderColor = WXG.rule; }}>
            <span style={{
              width: 18, height: 18,
              border: `1.5px solid ${active ? WXG.ink : WXG.rule}`,
              background: active ? WXG.amber : 'transparent',
              flexShrink: 0,
            }} />
            <span style={{ flex: 1 }}>{o}</span>
            <span style={{ fontFamily: D_MONO, fontSize: 11, letterSpacing: 1.2,
              color: active ? WXG.ink : WXG.slateLight }}>
              {String(i + 1).padStart(2, '0')}
            </span>
          </button>
        );
      })}
    </div>
  );
}

function D_Text({ q, value, onChange, mobile }) {
  return (
    <div>
      <textarea value={value || ''} onChange={e => onChange(e.target.value)}
        placeholder={q.placeholder} dir="rtl" rows={mobile ? 6 : 7}
        style={{
          width: '100%', resize: 'vertical', borderRadius: 0,
          background: WXG.paper, border: `1.5px solid ${WXG.rule}`,
          padding: mobile ? 16 : 20, fontFamily: D_TYPE, fontSize: mobile ? 15 : 17,
          color: WXG.ink, lineHeight: 1.6, outline: 'none',
          boxSizing: 'border-box', transition: 'border .15s',
        }}
        onFocus={e => e.currentTarget.style.borderColor = WXG.ink}
        onBlur={e => e.currentTarget.style.borderColor = WXG.rule} />
      <div style={{ marginTop: 10, display: 'flex', justifyContent: 'space-between',
        fontFamily: D_MONO, fontSize: 10.5, letterSpacing: 1.4, color: WXG.slateLight, textTransform: 'uppercase' }}>
        <span>{(value || '').length} / 500</span>
        <span>אנונימי · מאובטח</span>
      </div>
    </div>
  );
}

function D_Question({ s, mobile }) {
  const q = s.currentQ;
  if (!q) return null;
  const px = mobile ? 20 : 56;
  return (
    <div style={{ flex: 1, padding: mobile ? `28px ${px}px 24px` : `40px ${px}px 32px`,
      display: 'flex', flexDirection: 'column', gap: mobile ? 24 : 32,
      maxWidth: 1100, alignSelf: 'center', width: '100%' }}>

      <div style={{ display: 'flex', alignItems: 'flex-start', gap: mobile ? 16 : 24 }}>
        <div style={{
          fontFamily: D_TYPE, fontWeight: 800,
          fontSize: mobile ? 56 : 96, lineHeight: 0.85,
          color: WXG.ink, letterSpacing: '-0.04em',
          position: 'relative', flexShrink: 0,
        }}>
          {String(s.qIdx + 1).padStart(2, '0')}
          <span style={{ position: 'absolute', bottom: 6, insetInlineEnd: -16,
            width: 12, height: 12, background: WXG.amber }} />
        </div>
        <div style={{ flex: 1, paddingTop: mobile ? 6 : 14 }}>
          <h2 style={{
            fontFamily: D_TYPE, fontWeight: 700,
            fontSize: mobile ? 22 : 32, lineHeight: 1.25, letterSpacing: '-0.01em',
            margin: 0, color: WXG.ink, textWrap: 'pretty',
          }}>
            {q.text}
          </h2>
        </div>
      </div>

      <div style={{ paddingInlineStart: mobile ? 0 : 100 }}>
        {q.kind === 'rating' && <D_Rating q={q} value={s.answers[q.id]} onChange={v => s.setAnswer(q.id, v)} mobile={mobile} />}
        {q.kind === 'choice' && <D_Choice q={q} value={s.answers[q.id]} onChange={v => s.setAnswer(q.id, v)} mobile={mobile} />}
        {q.kind === 'text'   && <D_Text   q={q} value={s.answers[q.id]} onChange={v => s.setAnswer(q.id, v)} mobile={mobile} />}
      </div>
    </div>
  );
}

function D_Thanks({ s, mobile }) {
  const px = mobile ? 20 : 56;
  return (
    <div style={{ flex: 1, padding: mobile ? `22px ${px}px 18px` : `32px ${px}px 24px`,
      display: 'flex', flexDirection: 'column', justifyContent: 'center',
      maxWidth: 1100, alignSelf: 'center', width: '100%', minHeight: 0, overflow: 'auto' }}>
      <h1 style={{
        fontFamily: D_TYPE, fontWeight: 800,
        fontSize: mobile ? 32 : 56, lineHeight: 1, letterSpacing: '-0.025em',
        margin: 0, color: WXG.ink,
      }}>
        תודה שבנית איתנו
        <span aria-hidden="true" style={{
          display: 'inline-block', width: mobile ? 12 : 18, height: mobile ? 12 : 18,
          background: WXG.amber, marginInlineStart: mobile ? 10 : 14,
          verticalAlign: 'baseline',
        }} />
      </h1>

      <p style={{ fontSize: mobile ? 13 : 16, color: WXG.slate, marginTop: 12,
        maxWidth: 640, lineHeight: 1.5 }}>
        הסקר הבא יישלח בהגעתו של הפרויקט לאבן הדרך הבאה,
        מודים לכם על שיתוף הפעולה.
      </p>

      <button onClick={s.restart} style={{
        marginTop: mobile ? 16 : 22, alignSelf: 'flex-start',
        background: 'transparent', color: WXG.ink,
        border: `1.5px solid ${WXG.ink}`, padding: mobile ? '10px 18px' : '11px 22px', cursor: 'pointer',
        fontFamily: D_TYPE, fontSize: mobile ? 13 : 14, fontWeight: 600, borderRadius: 0,
        display: 'inline-flex', alignItems: 'center', gap: 10,
      }}
      onMouseOver={e => { e.currentTarget.style.background = WXG.ink; e.currentTarget.style.color = WXG.paper; }}
      onMouseOut={e => { e.currentTarget.style.background = 'transparent'; e.currentTarget.style.color = WXG.ink; }}>
        <span>חזרה להתחלה</span>
        <span style={{ width: 8, height: 8, background: WXG.amber }} />
      </button>
    </div>
  );
}

function D_Footer({ s, mobile }) {
  const px = mobile ? 16 : 36;
  if (s.page === 0 || s.page > s.total) {
    return (
      <footer style={{ padding: `${mobile ? 12 : 16}px ${px}px`,
        borderTop: `1px solid ${WXG.rule}`,
        fontFamily: D_MONO, fontSize: 10, letterSpacing: 1.4, color: WXG.slateLight,
        textTransform: 'uppercase', display: 'flex', justifyContent: 'space-between', background: WXG.paper }}>
        <span>© WXG · WAXMAN GROUP · 2026</span>
      </footer>
    );
  }
  return (
    <footer style={{ padding: `${mobile ? 12 : 18}px ${px}px`,
      borderTop: `1px solid ${WXG.rule}`, background: WXG.paper,
      display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 12 }}>
      <button onClick={s.goPrev} disabled={s.page <= 1} style={{
        background: 'transparent', color: s.page <= 1 ? WXG.rule : WXG.slate,
        border: 'none', cursor: s.page <= 1 ? 'default' : 'pointer',
        fontFamily: D_TYPE, fontSize: mobile ? 14 : 15, fontWeight: 600, padding: 0,
        display: 'inline-flex', alignItems: 'center', gap: 8,
      }}>← חזרה</button>
      <button onClick={s.goNext} disabled={!s.currentAnswered} style={{
        background: s.currentAnswered ? WXG.ink : WXG.ruleLight,
        color: s.currentAnswered ? WXG.paper : WXG.slateLight,
        border: 'none', cursor: s.currentAnswered ? 'pointer' : 'not-allowed',
        fontFamily: D_TYPE, fontSize: mobile ? 14 : 16, fontWeight: 700,
        padding: mobile ? '12px 22px' : '14px 28px',
        display: 'inline-flex', alignItems: 'center', gap: 12, borderRadius: 0,
        transition: 'all .2s',
      }}
      onMouseOver={e => { if (s.currentAnswered) { e.currentTarget.style.background = WXG.amber; e.currentTarget.style.color = WXG.ink; } }}
      onMouseOut={e => { if (s.currentAnswered) { e.currentTarget.style.background = WXG.ink; e.currentTarget.style.color = WXG.paper; } }}>
        <span>{s.page === s.total ? 'מסירת הסקר' : 'הבא'}</span>
        <span style={{ width: 12, height: 12, background: s.currentAnswered ? WXG.amber : 'transparent', border: s.currentAnswered ? 'none' : `1px solid ${WXG.slateLight}` }} />
      </button>
    </footer>
  );
}

function DirectionD({ mobile = false, initialPage = 0, initialAnswers = null }) {
  const s = useSurvey({ initialPage, initialAnswers });
  return (
    <D_Frame>
      <D_Header mobile={mobile} />
      {(s.page > 0 && s.page <= s.total) && <D_ProjectStrip mobile={mobile} />}
      <SkylineProgress current={s.page} total={s.total} mobile={mobile} />
      <div style={{ flex: 1, display: 'flex', flexDirection: 'column', overflow: 'auto' }}>
        <div key={s.page} style={{
          flex: 1, display: 'flex', flexDirection: 'column',
          animation: `wxg-slide-${s.direction > 0 ? 'next' : 'prev'} 480ms cubic-bezier(.2,.8,.2,1)`,
        }}>
          {s.page === 0 && <D_Intro mobile={mobile} onStart={s.goNext} />}
          {s.page > 0 && s.page <= s.total && <D_Question s={s} mobile={mobile} />}
          {s.page > s.total && <D_Thanks s={s} mobile={mobile} />}
        </div>
      </div>
      <D_Footer s={s} mobile={mobile} />
    </D_Frame>
  );
}

window.DirectionD = DirectionD;
