// LOUD direction — toxic yellow, manifesto, marquees
const { useState, useEffect, useRef } = React;

const LANG_NAMES = { tr: "TR", en: "EN", ru: "RU" };

function useTimer() {
  const [t, setT] = useState(0);
  useEffect(() => {
    const start = Date.now();
    const i = setInterval(() => setT(Math.floor((Date.now() - start) / 1000)), 100);
    return () => clearInterval(i);
  }, []);
  const m = Math.floor(t / 60).toString().padStart(2, '0');
  const s = (t % 60).toString().padStart(2, '0');
  const ms = (t % 1000).toString().padStart(2, '0');
  return `${m}:${s}:${ms}`;
}

function LangSwitcher({ lang, setLang }) {
  return (
    <div style={{ display: 'flex', gap: 4, fontFamily: 'var(--mono)', fontSize: 13, fontWeight: 700, letterSpacing: '0.05em' }}>
      {['tr', 'en', 'ru'].map(l => (
        <button
          key={l}
          onClick={() => setLang(l)}
          style={{
            background: lang === l ? 'var(--ink)' : 'transparent',
            color: lang === l ? 'var(--yellow)' : 'var(--ink)',
            border: '2px solid var(--ink)',
            padding: '6px 10px',
            cursor: 'pointer',
            fontFamily: 'inherit',
            fontWeight: 700,
            letterSpacing: 'inherit'
          }}
        >{LANG_NAMES[l]}</button>
      ))}
    </div>
  );
}

function BananaLogo({ size = 56, onClick }) {
  // Real logo PNG. Black artwork on transparent — invert/recolor via filter on dark surfaces.
  return (
    <img
      onClick={onClick}
      src="assets/logo.png"
      alt="Muzdolabi"
      width={size} height={size}
      style={{
        cursor: onClick ? 'pointer' : 'default',
        display: 'block',
        objectFit: 'contain',
        filter: 'var(--logo-filter, none)'
      }}
    />
  );
}

function Marquee({ items, speed = 30, direction = 'left', big = false }) {
  const content = items.concat(items).concat(items);
  return (
    <div style={{ overflow: 'hidden', display: 'flex', whiteSpace: 'nowrap', borderTop: '3px solid var(--ink)', borderBottom: '3px solid var(--ink)', background: 'var(--ink)', color: 'var(--yellow)' }}>
      <div style={{
        display: 'inline-flex',
        animation: `marquee-${direction} ${speed}s linear infinite`,
        gap: big ? 64 : 32,
        padding: big ? '20px 32px' : '12px 16px',
        fontFamily: 'var(--display)',
        fontWeight: 900,
        fontSize: big ? 64 : 18,
        letterSpacing: big ? '-0.02em' : '0.05em',
        textTransform: 'uppercase'
      }}>
        {content.map((it, i) => (
          <span key={i} style={{ display: 'inline-flex', alignItems: 'center', gap: big ? 64 : 32 }}>
            <span>{it}</span>
            <span style={{ opacity: 0.5 }}>★</span>
          </span>
        ))}
      </div>
    </div>
  );
}

function Hero({ t, lang }) {
  const timer = useTimer();
  return (
    <section className="hero-section" style={{ background: 'var(--yellow)', color: 'var(--ink)', borderBottom: '3px solid var(--ink)', position: 'relative' }}>
      <div style={{ padding: '24px 40px', display: 'flex', justifyContent: 'space-between', alignItems: 'center', fontFamily: 'var(--mono)', fontSize: 12, fontWeight: 700, letterSpacing: '0.08em', borderBottom: '2px dashed var(--ink)' }}>
        <span>● MUZDOLABI / DEVELOPMENT</span>
        <span>{t.timer_label} <strong style={{ background: 'var(--ink)', color: 'var(--yellow)', padding: '2px 8px' }}>{timer}</strong> — {t.timer_suffix}</span>
        <span>İSTANBUL · 41.0082°N</span>
      </div>

      <div style={{ padding: '60px 40px 40px' }}>
        <div style={{ fontFamily: 'var(--mono)', fontSize: 13, fontWeight: 700, letterSpacing: '0.1em', marginBottom: 24, display: 'flex', alignItems: 'center', gap: 12 }}>
          <span style={{ width: 40, height: 2, background: 'var(--ink)' }}></span>
          {t.hero_pre}
        </div>
        <h1 style={{
          fontFamily: 'var(--display)',
          fontWeight: 900,
          fontSize: 'clamp(64px, 9vw, 168px)',
          lineHeight: 0.88,
          letterSpacing: '-0.04em',
          margin: 0,
          textTransform: 'uppercase',
          textWrap: 'balance'
        }}>
          {t.hero_main}
        </h1>
        <div style={{ display: 'flex', alignItems: 'flex-end', justifyContent: 'space-between', marginTop: 48, gap: 40, flexWrap: 'wrap' }}>
          <p style={{ fontFamily: 'var(--display)', fontWeight: 500, fontSize: 28, lineHeight: 1.2, maxWidth: 560, margin: 0 }}>
            {t.hero_sub}
          </p>
          <a href="#contact" style={{
            background: 'var(--ink)',
            color: 'var(--yellow)',
            padding: '24px 36px',
            fontFamily: 'var(--display)',
            fontWeight: 900,
            fontSize: 22,
            letterSpacing: '0.02em',
            textDecoration: 'none',
            textTransform: 'uppercase',
            display: 'inline-flex',
            alignItems: 'center',
            gap: 16,
            border: '3px solid var(--ink)'
          }}>
            {t.hero_cta} <span style={{ display: 'inline-block', transform: 'rotate(-45deg)', fontSize: 24 }}>→</span>
          </a>
        </div>
      </div>

      <Marquee items={t.industries} speed={40} big />
    </section>
  );
}

function Services({ t }) {
  const items = [
    { n: '🍌', title: t.s1_title, desc: t.s1_desc },
    { n: '🍌🍌', title: t.s2_title, desc: t.s2_desc },
    { n: '🍌🍌🍌', title: t.s3_title, desc: t.s3_desc }
  ];
  return (
    <section style={{ background: 'var(--ink)', color: 'var(--yellow)', padding: '100px 40px', borderBottom: '3px solid var(--ink)' }}>
      <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'baseline', marginBottom: 64, flexWrap: 'wrap', gap: 24 }}>
        <h2 style={{ fontFamily: 'var(--display)', fontWeight: 900, fontSize: 'clamp(48px, 6vw, 100px)', margin: 0, letterSpacing: '-0.03em', textTransform: 'uppercase', lineHeight: 0.9 }}>
          {t.services_title}
        </h2>
        <span style={{ fontFamily: 'var(--mono)', fontSize: 14, fontWeight: 700, letterSpacing: '0.1em' }}>{t.services_kicker}</span>
      </div>
      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 0, border: '2px solid var(--yellow)' }}>
        {items.map((it, i) => (
          <div key={i} style={{
            padding: 40,
            borderRight: i < 2 ? '2px solid var(--yellow)' : 'none',
            display: 'flex',
            flexDirection: 'column',
            justifyContent: 'space-between',
            minHeight: 360
          }}>
            <div style={{ fontFamily: 'var(--mono)', fontSize: 14, fontWeight: 700, letterSpacing: '0.1em' }}>{it.n}</div>
            <div>
              <h3 style={{ fontFamily: 'var(--display)', fontWeight: 900, fontSize: 72, margin: '0 0 16px', letterSpacing: '-0.03em', lineHeight: 0.9 }}>{it.title}</h3>
              <p style={{ fontFamily: 'var(--display)', fontWeight: 400, fontSize: 18, lineHeight: 1.4, margin: 0, maxWidth: 320 }}>{it.desc}</p>
            </div>
          </div>
        ))}
      </div>
    </section>
  );
}

function Work({ t, lang }) {
  return (
    <section id="work" style={{ background: 'var(--yellow)', color: 'var(--ink)', padding: '100px 40px', borderBottom: '3px solid var(--ink)' }}>
      <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'baseline', marginBottom: 64, flexWrap: 'wrap', gap: 24 }}>
        <h2 style={{ fontFamily: 'var(--display)', fontWeight: 900, fontSize: 'clamp(48px, 6vw, 100px)', margin: 0, letterSpacing: '-0.03em', textTransform: 'uppercase', lineHeight: 0.9 }}>
          {t.work_title}
        </h2>
        <span style={{ fontFamily: 'var(--mono)', fontSize: 14, fontWeight: 700, letterSpacing: '0.1em' }}>{t.work_kicker} — 06</span>
      </div>
      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(12, 1fr)', gap: 16 }}>
        {window.PORTFOLIO.map((p, i) => {
          // editorial layout: vary spans
          const spans = [
            { col: 'span 7', tall: false },
            { col: 'span 5', tall: true },
            { col: 'span 5', tall: false },
            { col: 'span 7', tall: false },
            { col: 'span 6', tall: false },
            { col: 'span 6', tall: false }
          ];
          const sp = spans[i] || { col: 'span 6', tall: false };
          const isTall = p.aspect === 'tall';
          return (
            <a key={p.id} href={p.url} target="_blank" rel="noopener" className="work-card" style={{
              gridColumn: sp.col,
              border: '3px solid var(--ink)',
              background: 'var(--cream)',
              textDecoration: 'none',
              color: 'var(--ink)',
              display: 'flex',
              flexDirection: 'column',
              minHeight: isTall ? 720 : 480,
              position: 'relative',
              overflow: 'hidden'
            }}>
              <div style={{ padding: '20px 24px', display: 'flex', justifyContent: 'space-between', borderBottom: '3px solid var(--ink)', fontFamily: 'var(--mono)', fontSize: 12, fontWeight: 700, letterSpacing: '0.08em', textTransform: 'uppercase' }}>
                <span>{'🍌'.repeat(i+1)} / {p.industry[lang]}</span>
                <span>{p.year}</span>
              </div>
              <div style={{
                flex: 1,
                background: '#fff',
                display: 'flex',
                alignItems: isTall ? 'flex-start' : 'center',
                justifyContent: 'center',
                padding: isTall ? '24px' : '32px',
                overflow: 'hidden'
              }}>
                <img src={p.image} alt={p.name} style={{
                  width: isTall ? 'auto' : '100%',
                  height: isTall ? '100%' : 'auto',
                  maxWidth: '100%',
                  maxHeight: '100%',
                  objectFit: 'contain',
                  border: '2px solid var(--ink)',
                  display: 'block'
                }} />
              </div>
              <div style={{ padding: '24px', borderTop: '3px solid var(--ink)', display: 'flex', justifyContent: 'space-between', alignItems: 'flex-end', gap: 24 }}>
                <div>
                  <h3 style={{ fontFamily: 'var(--display)', fontWeight: 900, fontSize: 36, margin: '0 0 6px', letterSpacing: '-0.02em', textTransform: 'uppercase', lineHeight: 0.95 }}>{p.name}</h3>
                  <p style={{ fontFamily: 'var(--display)', fontWeight: 400, fontSize: 15, lineHeight: 1.4, margin: 0, maxWidth: 400 }}>{p.desc[lang]}</p>
                </div>
                <span style={{ fontFamily: 'var(--mono)', fontSize: 12, fontWeight: 700, letterSpacing: '0.08em', whiteSpace: 'nowrap', borderBottom: '2px solid var(--ink)' }}>{t.visit} ↗</span>
              </div>
            </a>
          );
        })}
      </div>
    </section>
  );
}

function Enjoy({ t }) {
  return (
    <section style={{ background: 'var(--yellow)', color: 'var(--ink)', padding: '120px 40px', borderTop: '3px solid var(--ink)', borderBottom: '3px solid var(--ink)' }}>
      <div style={{ fontFamily: 'var(--mono)', fontSize: 13, fontWeight: 700, letterSpacing: '0.12em', marginBottom: 32, display: 'flex', alignItems: 'center', gap: 12 }}>
        <span style={{ width: 40, height: 2, background: 'var(--ink)' }}></span>
        {t.enjoy_kicker}
      </div>
      <h2 style={{ fontFamily: 'var(--display)', fontWeight: 900, fontSize: 'clamp(72px, 11vw, 220px)', margin: '0 0 32px', letterSpacing: '-0.045em', textTransform: 'uppercase', lineHeight: 0.85, textWrap: 'balance' }}>
        {t.enjoy_main}
      </h2>
      <p style={{ fontFamily: 'var(--display)', fontWeight: 500, fontSize: 'clamp(20px, 2vw, 28px)', lineHeight: 1.3, maxWidth: 760, margin: 0 }}>
        {t.enjoy_sub}
      </p>
    </section>
  );
}

function BananaClicker({ t }) {
  const [count, setCount] = useState(0);
  const [shake, setShake] = useState(0);
  const [open, setOpen] = useState(false);
  const [sent, setSent] = useState(false);
  const [status, setStatus] = useState('idle');
  const [error, setError] = useState('');
  const [form, setForm] = useState({ name: '', email: '', what: '', company: '' });

  const need = 5;
  const taunt = t.banana_taunts[Math.min(count, t.banana_taunts.length - 1)];

  const onClick = () => {
    const n = count + 1;
    setCount(n);
    setShake(s => s + 1);
    if (n >= need) {
      setTimeout(() => setOpen(true), 250);
    }
  };

  const submit = async (e) => {
    e.preventDefault();
    setStatus('sending');
    setError('');

    try {
      const response = await fetch('/api/leads', {
        method: 'POST',
        headers: { 'Content-Type': 'application/json' },
        body: JSON.stringify({
          ...form,
          language: document.documentElement.lang || '',
          page: window.location.pathname
        })
      });
      const result = await response.json().catch(() => ({}));

      if (!response.ok || !result.ok) {
        throw new Error(result.error || 'Request failed');
      }

      setSent(true);
      setStatus('sent');
      setForm({ name: '', email: '', what: '', company: '' });
    } catch (err) {
      setStatus('error');
      setError(true);
    }
  };

  const close = () => {
    setOpen(false);
    setCount(0);
    setSent(false);
    setStatus('idle');
    setError('');
    setForm({ name: '', email: '', what: '', company: '' });
  };

  return (
    <section className="banana-section" style={{ background: 'var(--ink)', color: 'var(--yellow)', padding: '60px 40px 72px', borderBottom: '3px solid var(--ink)', position: 'relative', overflow: 'hidden' }}>
      <style>{`
        @keyframes banana-shake {
          0%,100% { transform: rotate(0deg) scale(1); }
          15% { transform: rotate(-8deg) scale(1.06); }
          30% { transform: rotate(7deg) scale(1.08); }
          45% { transform: rotate(-5deg) scale(1.04); }
          60% { transform: rotate(4deg) scale(1.02); }
          75% { transform: rotate(-2deg) scale(1.01); }
        }
        .big-banana-btn { animation: banana-shake 0.5s ease; }
        .big-banana-btn:hover img { transform: scale(1.04) rotate(-3deg); }
        .big-banana-btn img { transition: transform 0.2s ease; filter: invert(1) sepia(1) saturate(15) hue-rotate(355deg) brightness(1.15); }
      `}</style>
      <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'baseline', marginBottom: 32, flexWrap: 'wrap', gap: 16 }}>
        <h2 style={{ fontFamily: 'var(--display)', fontWeight: 900, fontSize: 'clamp(40px, 5.5vw, 88px)', margin: 0, letterSpacing: '-0.03em', textTransform: 'uppercase', lineHeight: 0.9 }}>
          {t.banana_title}
        </h2>
        <span style={{ fontFamily: 'var(--mono)', fontSize: 13, fontWeight: 700, letterSpacing: '0.1em' }}>{t.banana_sub}</span>
      </div>

      <div className="banana-grid" style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 48, alignItems: 'center' }}>
        <button
          key={shake}
          onClick={onClick}
          className="big-banana-btn"
          style={{
            background: 'transparent',
            border: 'none',
            cursor: 'pointer',
            padding: 0,
            justifySelf: 'end'
          }}
        >
          <img src="assets/logo.png" alt="banana" style={{ width: 'clamp(220px, 26vw, 360px)', height: 'auto', display: 'block' }}/>
        </button>

        <div style={{ display: 'flex', flexDirection: 'column', gap: 20, alignItems: 'flex-start' }}>
          <div style={{ fontFamily: 'var(--mono)', fontSize: 12, fontWeight: 700, letterSpacing: '0.12em' }}>{t.banana_count}</div>
          <div style={{
            display: 'flex',
            gap: 'clamp(6px, 0.8vw, 12px)',
            fontSize: 'clamp(36px, 4.5vw, 64px)',
            lineHeight: 1
          }}>
            {Array.from({ length: need }).map((_, i) => (
              <span key={i} style={{
                opacity: i < count ? 1 : 0.15,
                filter: i < count ? 'none' : 'grayscale(1)',
                transform: i < count ? `rotate(${(i % 2 ? -1 : 1) * 6}deg)` : 'none',
                transition: 'all 0.25s ease'
              }}>🍌</span>
            ))}
          </div>
          <div style={{ fontFamily: 'var(--display)', fontSize: 22, fontWeight: 900, letterSpacing: '-0.02em', opacity: 0.6 }}>
            {count}/{need}
          </div>
          <div style={{
            fontFamily: 'var(--display)',
            fontWeight: 900,
            fontSize: 'clamp(28px, 3.6vw, 56px)',
            letterSpacing: '-0.03em',
            textTransform: 'uppercase',
            lineHeight: 1
          }}>
            {taunt}
          </div>
        </div>
      </div>

      {open && (
        <div className="lead-modal-backdrop" onClick={close} style={{
          position: 'fixed', inset: 0,
          background: 'rgba(10,10,10,0.92)',
          zIndex: 9999,
          display: 'flex', alignItems: 'center', justifyContent: 'center',
          padding: 24
        }}>
          <div className="lead-modal-card" onClick={(e) => e.stopPropagation()} style={{
            background: 'var(--yellow)',
            color: 'var(--ink)',
            border: '4px solid var(--ink)',
            padding: 'clamp(32px, 4vw, 56px)',
            maxWidth: 720, width: '100%',
            position: 'relative',
            boxShadow: '12px 12px 0 var(--ink)'
          }}>
            <button onClick={close} style={{
              position: 'absolute', top: 16, right: 16,
              background: 'var(--ink)', color: 'var(--yellow)',
              border: 'none', padding: '8px 14px',
              fontFamily: 'var(--mono)', fontSize: 12, fontWeight: 700, letterSpacing: '0.1em',
              cursor: 'pointer'
            }}>{t.form_close} ✕</button>

            {!sent ? (
              <React.Fragment>
                <h3 style={{ fontFamily: 'var(--display)', fontWeight: 900, fontSize: 'clamp(32px, 4vw, 56px)', margin: '0 0 16px', letterSpacing: '-0.03em', textTransform: 'uppercase', lineHeight: 0.95 }}>
                  {t.form_title}
                </h3>
                <p style={{ fontFamily: 'var(--display)', fontSize: 18, margin: '0 0 32px', lineHeight: 1.3 }}>{t.form_sub}</p>
                <form onSubmit={submit} style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
                  <input
                    type="text"
                    name="company"
                    value={form.company}
                    onChange={e => setForm({...form, company: e.target.value})}
                    tabIndex="-1"
                    autoComplete="off"
                    aria-hidden="true"
                    style={honeypotStyle}
                  />
                  <label style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
                    <span style={{ fontFamily: 'var(--mono)', fontSize: 11, fontWeight: 700, letterSpacing: '0.15em', textTransform: 'uppercase' }}>{t.form_name}</span>
                    <input required value={form.name} onChange={e => setForm({...form, name: e.target.value})} style={fieldStyle}/>
                  </label>
                  <label style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
                    <span style={{ fontFamily: 'var(--mono)', fontSize: 11, fontWeight: 700, letterSpacing: '0.15em', textTransform: 'uppercase' }}>{t.form_email}</span>
                    <input required type="email" value={form.email} onChange={e => setForm({...form, email: e.target.value})} style={fieldStyle}/>
                  </label>
                  <label style={{ display: 'flex', flexDirection: 'column', gap: 6 }}>
                    <span style={{ fontFamily: 'var(--mono)', fontSize: 11, fontWeight: 700, letterSpacing: '0.15em', textTransform: 'uppercase' }}>{t.form_what}</span>
                    <textarea required rows={4} placeholder={t.form_what_ph} value={form.what} onChange={e => setForm({...form, what: e.target.value})} style={{...fieldStyle, resize: 'vertical', fontFamily: 'var(--display)'}}/>
                  </label>
                  <button type="submit" disabled={status === 'sending'} style={{
                    background: 'var(--ink)', color: 'var(--yellow)',
                    border: 'none', padding: '20px 32px',
                    fontFamily: 'var(--display)', fontWeight: 900, fontSize: 24,
                    letterSpacing: '0.02em', textTransform: 'uppercase',
                    cursor: status === 'sending' ? 'wait' : 'pointer', marginTop: 8,
                    opacity: status === 'sending' ? 0.72 : 1,
                    display: 'inline-flex', alignItems: 'center', justifyContent: 'center', gap: 12
                  }}>{status === 'sending' ? (t.form_sending || 'SENDING...') : t.form_send} <span style={{ display: 'inline-block', transform: 'rotate(-45deg)' }}>→</span></button>
                  {error && (
                    <p style={{ fontFamily: 'var(--mono)', fontSize: 12, fontWeight: 700, lineHeight: 1.4, margin: 0 }}>
                      {t.form_error || window.I18N.en.form_error}
                    </p>
                  )}
                </form>
              </React.Fragment>
            ) : (
              <div style={{ textAlign: 'center', padding: '32px 0' }}>
                <div style={{ fontSize: 80, marginBottom: 16 }}>🍌</div>
                <h3 style={{ fontFamily: 'var(--display)', fontWeight: 900, fontSize: 40, margin: 0, letterSpacing: '-0.02em', textTransform: 'uppercase' }}>
                  {t.form_thanks}
                </h3>
              </div>
            )}
          </div>
        </div>
      )}
    </section>
  );
}

const fieldStyle = {
  background: 'transparent',
  border: '3px solid var(--ink)',
  padding: '14px 16px',
  fontFamily: "'JetBrains Mono', monospace",
  fontSize: 16,
  fontWeight: 500,
  color: 'var(--ink)',
  outline: 'none',
  width: '100%'
};

const honeypotStyle = {
  position: 'absolute',
  left: '-10000px',
  top: 'auto',
  width: 1,
  height: 1,
  opacity: 0,
  pointerEvents: 'none'
};

function Contact({ t }) {
  return (
    <section id="contact" style={{ background: 'var(--ink)', color: 'var(--yellow)', padding: '120px 40px', borderBottom: '3px solid var(--ink)' }}>
      <div style={{ textAlign: 'center', maxWidth: 1200, margin: '0 auto' }}>
        <h2 style={{ fontFamily: 'var(--display)', fontWeight: 900, fontSize: 'clamp(72px, 12vw, 200px)', margin: '0 0 32px', letterSpacing: '-0.04em', textTransform: 'uppercase', lineHeight: 0.85 }}>
          {t.cta_title}
        </h2>
        <p style={{ fontFamily: 'var(--display)', fontWeight: 400, fontSize: 24, margin: '0 0 48px' }}>{t.cta_sub}</p>
        <a href="mailto:info@muzdolabi.com" style={{
          display: 'inline-block',
          background: 'var(--yellow)',
          color: 'var(--ink)',
          padding: '32px 56px',
          fontFamily: 'var(--display)',
          fontWeight: 900,
          fontSize: 'clamp(28px, 4vw, 56px)',
          letterSpacing: '-0.02em',
          textDecoration: 'none',
          border: '4px solid var(--yellow)'
        }}>{t.cta_button} ↗</a>
      </div>
    </section>
  );
}

function Footer({ t, lang, setLang }) {
  return (
    <footer style={{ background: 'var(--ink)', color: 'var(--yellow)', padding: '40px', display: 'flex', justifyContent: 'space-between', alignItems: 'center', flexWrap: 'wrap', gap: 24, fontFamily: 'var(--mono)', fontSize: 12, fontWeight: 700, letterSpacing: '0.08em', textTransform: 'uppercase' }}>
      <div style={{ display: 'flex', alignItems: 'center', gap: 16, '--logo-filter': 'invert(1) sepia(1) saturate(10) hue-rotate(355deg) brightness(1.1)' }}>
        <BananaLogo size={56}/>
        <span>MUZDOLABI DEVELOPMENT © {t.footer_year}</span>
      </div>
      <span>{t.footer_holding}</span>
      <LangSwitcher lang={lang} setLang={setLang}/>
    </footer>
  );
}

function EasterEgg({ t, onClose }) {
  return (
    <div onClick={onClose} style={{
      position: 'fixed', inset: 0, background: 'var(--yellow)', zIndex: 9999,
      display: 'flex', alignItems: 'center', justifyContent: 'center', cursor: 'pointer',
      animation: 'flash 0.4s steps(2) infinite'
    }}>
      <style>{`@keyframes flash { 0%,49%{background:var(--yellow);color:var(--ink)} 50%,100%{background:var(--ink);color:var(--yellow)} }`}</style>
      <div style={{ textAlign: 'center' }}>
        <div style={{ fontSize: 200 }}>🍌</div>
        <div style={{ fontFamily: 'var(--display)', fontWeight: 900, fontSize: 80, letterSpacing: '-0.03em' }}>POTASSIUM++</div>
        <div style={{ fontFamily: 'var(--mono)', fontSize: 16, fontWeight: 700, letterSpacing: '0.2em', marginTop: 16 }}>CLICK ANYWHERE TO CLOSE</div>
      </div>
    </div>
  );
}

function LoudSite() {
  const tweaks = window.LOUD_DEFAULTS;
  const [lang, setLang] = useState(() => window.detectLang());
  const [showEgg, setShowEgg] = useState(false);
  const [bananaCount, setBananaCount] = useState(0);
  const t = window.I18N[lang];

  // Apply yellow intensity (0..1 mixing yellow with white) and mono toggle
  const yellow = tweaks.yellow || '#FFD800';

  useEffect(() => {
    document.documentElement.lang = lang;
  }, [lang]);

  const handleBanana = () => {
    const n = bananaCount + 1;
    setBananaCount(n);
    if (n >= 3) {
      setShowEgg(true);
      setBananaCount(0);
    }
  };

  return (
    <div style={{
      '--yellow': yellow,
      '--ink': '#0a0a0a',
      '--cream': '#fffbe6',
      '--display': "'Archivo', 'Helvetica Neue', sans-serif",
      '--mono': "'JetBrains Mono', 'Courier New', monospace",
      background: 'var(--yellow)',
      minHeight: '100vh',
      color: 'var(--ink)'
    }}>
      <style>{`
        @keyframes marquee-left { from{transform:translateX(0)} to{transform:translateX(-33.333%)} }
        @keyframes marquee-right { from{transform:translateX(-33.333%)} to{transform:translateX(0)} }
        a.work-card { transition: transform 0.2s ease; }
        a.work-card:hover { transform: translate(-4px, -4px); box-shadow: 8px 8px 0 var(--ink); }
        ::selection { background: var(--ink); color: var(--yellow); }
        html, body, #root { max-width: 100%; overflow-x: hidden; }
        h1, h2, h3, p, a, span, button { overflow-wrap: anywhere; }

        @media (max-width: 760px) {
          nav {
            padding: 12px 16px !important;
            flex-wrap: wrap;
            gap: 12px;
            align-items: flex-start !important;
          }
          nav > div:first-child {
            gap: 10px !important;
            min-width: 0;
          }
          nav > div:first-child img {
            width: 56px !important;
            height: 56px !important;
          }
          nav > div:first-child > div {
            font-size: 18px !important;
          }
          nav > div:last-child {
            width: 100%;
            justify-content: space-between;
            gap: 10px !important;
            flex-wrap: wrap;
            font-size: 11px !important;
          }
          nav a {
            white-space: nowrap;
          }
          nav button {
            padding: 5px 8px !important;
          }
          .hero-section {
            padding-left: 0 !important;
            padding-right: 0 !important;
          }
          .hero-section > div:first-child {
            padding: 12px 16px !important;
            align-items: flex-start !important;
            flex-direction: column;
            gap: 8px;
            letter-spacing: 0.04em !important;
          }
          .hero-section > div:nth-child(2) {
            padding: 40px 16px 28px !important;
          }
          .hero-section h1 {
            font-size: clamp(42px, 14vw, 64px) !important;
            line-height: 0.92 !important;
            letter-spacing: 0 !important;
          }
          .hero-section p {
            font-size: 22px !important;
          }
          .hero-section a {
            width: 100%;
            justify-content: center;
            padding: 18px 22px !important;
            font-size: 18px !important;
          }
          #services > section,
          #work,
          #manifesto > section,
          #contact,
          .banana-section {
            padding: 64px 16px !important;
          }
          #services > section > div:first-child,
          #work > div:first-child {
            margin-bottom: 32px !important;
          }
          #services > section > div:last-child {
            grid-template-columns: 1fr !important;
          }
          #services > section > div:last-child > div {
            min-height: 0 !important;
            padding: 24px !important;
            border-right: 0 !important;
            border-bottom: 2px solid var(--yellow);
            gap: 28px;
          }
          #services > section > div:last-child > div:last-child {
            border-bottom: 0;
          }
          #services h3 {
            font-size: 48px !important;
            letter-spacing: 0 !important;
          }
          #work > div:last-child {
            grid-template-columns: 1fr !important;
          }
          #work a.work-card {
            grid-column: 1 / -1 !important;
            min-height: auto !important;
          }
          #work a.work-card > div:first-child {
            padding: 14px 16px !important;
            gap: 12px;
          }
          #work a.work-card > div:nth-child(2) {
            min-height: 240px;
            padding: 16px !important;
          }
          #work a.work-card > div:last-child {
            flex-direction: column;
            align-items: flex-start !important;
            gap: 16px !important;
            padding: 20px !important;
          }
          #work a.work-card h3 {
            font-size: 28px !important;
            letter-spacing: 0 !important;
          }
          #manifesto h2,
          #contact h2 {
            font-size: clamp(44px, 14vw, 72px) !important;
            letter-spacing: 0 !important;
          }
          .banana-grid {
            grid-template-columns: 1fr !important;
            gap: 28px !important;
            text-align: center;
          }
          .big-banana-btn {
            justify-self: center !important;
          }
          .big-banana-btn img {
            width: min(70vw, 280px) !important;
          }
          .banana-grid > div {
            align-items: center !important;
          }
          .lead-modal-backdrop {
            align-items: flex-start !important;
            overflow-y: auto;
            padding: 16px !important;
          }
          .lead-modal-card {
            width: calc(100vw - 32px) !important;
            max-width: 100% !important;
            padding: 72px 18px 24px !important;
            box-shadow: 6px 6px 0 var(--ink) !important;
          }
          #contact a {
            width: 100%;
            padding: 22px 16px !important;
            font-size: 24px !important;
          }
          footer {
            padding: 28px 16px !important;
            align-items: flex-start !important;
          }
        }
      `}</style>

      {showEgg && <EasterEgg t={t} onClose={() => setShowEgg(false)}/>}

      {/* Top nav */}
      <nav style={{ position: 'sticky', top: 0, zIndex: 50, background: 'var(--yellow)', borderBottom: '3px solid var(--ink)', padding: '16px 40px', display: 'flex', justifyContent: 'space-between', alignItems: 'center' }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 16 }} onClick={handleBanana}>
          <BananaLogo size={72}/>
          <div style={{ fontFamily: 'var(--display)', fontWeight: 900, fontSize: 22, letterSpacing: '-0.02em', textTransform: 'uppercase', lineHeight: 1 }}>
            MUZDOLABI<br/><span style={{ fontSize: 12, letterSpacing: '0.15em', fontWeight: 700 }}>DEVELOPMENT</span>
          </div>
        </div>
        <div style={{ display: 'flex', alignItems: 'center', gap: 32, fontFamily: 'var(--mono)', fontSize: 13, fontWeight: 700, letterSpacing: '0.08em' }}>
              <a href="#work" style={{ color: 'inherit', textDecoration: 'none' }}>{t.nav_work}</a>
          <a href="#services" style={{ color: 'inherit', textDecoration: 'none' }}>{t.nav_services}</a>
          <a href="#manifesto" style={{ color: 'inherit', textDecoration: 'none' }}>{t.nav_manifesto}</a>
          <a href="#contact" style={{ color: 'inherit', textDecoration: 'none' }}>{t.nav_contact}</a>
          <LangSwitcher lang={lang} setLang={setLang}/>
        </div>
      </nav>

      <Hero t={t} lang={lang}/>
      <div id="services"><Services t={t}/></div>
      <Work t={t} lang={lang}/>
      <Marquee items={[t.industry_any, ...t.industries.slice(0,6)]} speed={50} big/>
      <div id="manifesto"><Enjoy t={t}/></div>
      <BananaClicker t={t}/>
      <Contact t={t}/>
      <Footer t={t} lang={lang} setLang={setLang}/>

      {/* tiny easter-egg hint */}
      <div style={{ position: 'fixed', bottom: 16, left: 16, fontFamily: 'var(--mono)', fontSize: 10, fontWeight: 700, letterSpacing: '0.1em', color: 'var(--ink)', opacity: 0.4, pointerEvents: 'none' }}>
        {t.egg_hint} ×{3 - bananaCount}
      </div>
    </div>
  );
}

window.LoudSite = LoudSite;
window.LOUD_DEFAULTS = /*EDITMODE-BEGIN*/{
  "yellow": "#FFD800"
}/*EDITMODE-END*/;
