const { useState, useEffect, useMemo, useRef } = React;

/* ---------- Icons ---------- */
const Icon = {
  search: (p) => <svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" {...p}><circle cx="11" cy="11" r="7" /><path d="m21 21-4.3-4.3" /></svg>,
  bag: (p) => <svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M5 8h14l-1.2 11.2A2 2 0 0 1 15.8 21H8.2a2 2 0 0 1-2-1.8L5 8z" /><path d="M9 8V6a3 3 0 0 1 6 0v2" /></svg>,
  heart: (p) => <svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round" {...p}><path d="M12 21s-7-4.5-9.5-9C1 9 2.5 5 6.5 5c2 0 3.5 1.2 4.5 2.5C12 6.2 13.5 5 15.5 5c4 0 5.5 4 4 7-2.5 4.5-7.5 9-7.5 9z" /></svg>,
  plus: (p) => <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" strokeWidth="2.2" strokeLinecap="round" {...p}><path d="M12 5v14M5 12h14" /></svg>,
  close: (p) => <svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" {...p}><path d="M6 6l12 12M18 6L6 18" /></svg>,
  sort: (p) => <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" {...p}><path d="M3 6h13M3 12h9M3 18h5M17 9l3-3 3 3M20 6v12" /></svg>,
  arrow: (p) => <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" {...p}><path d="M5 12h14M13 6l6 6-6 6" /></svg>,
  chev: (p) => <svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" strokeWidth="1.7" strokeLinecap="round" {...p}><path d="m6 9 6 6 6-6" /></svg>
};

/* ---------- Hero decorative sprinkles ---------- */
function Sprinkles() {
  const sprinkles = useMemo(() => {
    const cols = ['#C04A5B', '#6B8B3D', '#4A55A0', '#C68A1E', '#7A5FA0', '#1A1612'];
    return Array.from({ length: 22 }, (_, i) => ({
      top: 5 + Math.random() * 90,
      left: 5 + Math.random() * 90,
      rot: Math.random() * 180,
      col: cols[i % cols.length]
    }));
  }, []);
  return <>{sprinkles.map((s, i) =>
    <span key={i} className="deco-sprinkle"
    style={{ top: s.top + '%', left: s.left + '%', background: s.col, transform: `rotate(${s.rot}deg)` }} />
    )}</>;
}

/* ---------- Cone illustration ---------- */
function ConeArt() {
  return (
    <svg className="cone-art" viewBox="0 0 320 360" aria-hidden="true">
      <defs>
        <radialGradient id="coneGrad" cx="0.35" cy="0.25" r="0.9">
          <stop offset="0%" stopColor="#f4d9ad" />
          <stop offset="55%" stopColor="#d6a967" />
          <stop offset="100%" stopColor="#9a6e3a" />
        </radialGradient>
        <pattern id="waffle" patternUnits="userSpaceOnUse" width="22" height="22" patternTransform="rotate(8)">
          <path d="M0 0 L22 22 M22 0 L0 22" stroke="rgba(82,52,18,0.28)" strokeWidth="1.4" />
        </pattern>
        <radialGradient id="scoopMint" cx="0.35" cy="0.28" r="0.85">
          <stop offset="0%" stopColor="#f1f6dc" />
          <stop offset="55%" stopColor="#b8d08a" />
          <stop offset="100%" stopColor="#6b8b3d" />
        </radialGradient>
        <radialGradient id="scoopPink" cx="0.35" cy="0.28" r="0.85">
          <stop offset="0%" stopColor="#fdecee" />
          <stop offset="55%" stopColor="#f2a6b0" />
          <stop offset="100%" stopColor="#c04a5b" />
        </radialGradient>
        <radialGradient id="scoopButter" cx="0.35" cy="0.28" r="0.85">
          <stop offset="0%" stopColor="#fbf5e2" />
          <stop offset="55%" stopColor="#f5c76a" />
          <stop offset="100%" stopColor="#c68a1e" />
        </radialGradient>
        <filter id="softShadow" x="-20%" y="-20%" width="140%" height="140%">
          <feGaussianBlur in="SourceAlpha" stdDeviation="6" />
          <feOffset dx="0" dy="10" result="off" />
          <feComponentTransfer><feFuncA type="linear" slope="0.18" /></feComponentTransfer>
          <feMerge><feMergeNode /><feMergeNode in="SourceGraphic" /></feMerge>
        </filter>
      </defs>
      {/* Cone — slightly tilted */}
      <g transform="translate(160 200) rotate(-4)" filter="url(#softShadow)">
        <path d="M-70 -20 L70 -20 L0 140 Z" fill="url(#coneGrad)" />
        <path d="M-70 -20 L70 -20 L0 140 Z" fill="url(#waffle)" />
        <ellipse cx="0" cy="-20" rx="70" ry="14" fill="url(#coneGrad)" />
        <ellipse cx="0" cy="-22" rx="70" ry="6" fill="rgba(82,52,18,0.18)" />
      </g>
      {/* Bottom scoop — butter */}
      <circle cx="160" cy="170" r="72" fill="url(#scoopButter)" filter="url(#softShadow)" />
      {/* Middle scoop — pink, offset */}
      <circle cx="190" cy="115" r="58" fill="url(#scoopPink)" filter="url(#softShadow)" />
      {/* Top scoop — mint */}
      <circle cx="142" cy="80" r="52" fill="url(#scoopMint)" filter="url(#softShadow)" />
      {/* A little drip down the cone */}
      <path d="M118 188 Q116 220 132 232 Q140 222 134 200 Z" fill="url(#scoopButter)" opacity="0.85" />
    </svg>);

}

/* ---------- Nav Dropdown ---------- */
function NavDropdown({ label, items }) {
  const [open, setOpen] = React.useState(false);
  const ref = React.useRef(null);
  const timerRef = React.useRef(null);
  function handleMouseEnter() {clearTimeout(timerRef.current);setOpen(true);}
  function handleMouseLeave() {timerRef.current = setTimeout(() => setOpen(false), 120);}
  return (
    <div className="nav-dropdown" ref={ref} onMouseEnter={handleMouseEnter} onMouseLeave={handleMouseLeave}>
      <button className="nav-dropdown-btn" aria-expanded={open}>
        {label}
        <svg width="10" height="10" viewBox="0 0 10 10" fill="none" style={{ transition: 'transform .2s', transform: open ? 'rotate(180deg)' : 'rotate(0deg)' }}>
          <path d="M1.5 3.5L5 7L8.5 3.5" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
        </svg>
      </button>
      {open &&
      <div className="nav-dropdown-menu">
          {items.map((item) =>
        <a key={item.label} href={item.href} className="nav-dropdown-item">
              {item.label}
            </a>
        )}
        </div>
      }
    </div>);

}

/* ---------- Hero ---------- */
function Hero({ count, todayDate, store, setStore }) {
  return (
    <section className="hero" data-screen-label="01 Hero">
      <div>
        <h1 className="hero-title" style={{ fontSize: "112px" }}>Dagens <span className="pop" style={{ fontSize: "112px" }}>is</span></h1>
        <p className="hero-meta" style={{ marginTop: 24 }}>Vores udvalg skifter med sæson, vejr og humør. Her er de smage, vi har fremstillet i dag - alle på økologisk jerseymælk fra Thise.

        </p>
        <StoreToggle value={store} onChange={setStore} />
      </div>

    </section>);

}

/* ---------- Store toggle ---------- */
const STORE_ICONS = {
  algade:
  <svg viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
      <path d="M3 21h18" />
      <path d="M5 21V10l4-3 4 3" />
      <path d="M13 21V13l4-2 4 2v8" />
      <path d="M8 21v-4M17 21v-4" />
      <path d="M9 7V4" />
    </svg>,

  havnens:
  <svg viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" strokeWidth="1.6" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
      <circle cx="12" cy="5" r="1.6" />
      <path d="M12 7v13" />
      <path d="M9 10h6" />
      <path d="M5 14c0 4 3 6 7 6s7-2 7-6" />
      <path d="M5 14H3M19 14h2" />
    </svg>

};

function StoreToggle({ value, onChange }) {
  const i = STORES.findIndex((s) => s.key === value);
  return (
    <div className="store-toggle" role="tablist" aria-label="Choose a shop">
      <div className="store-toggle-pill" style={{ transform: `translateX(${i * 100}%)` }} />
      {STORES.map((s) =>
      <button
        key={s.key}
        role="tab"
        aria-selected={value === s.key}
        className={'store-toggle-btn' + (value === s.key ? ' on' : '')}
        onClick={() => onChange(s.key)}>
        
          <span className="store-toggle-icon">{STORE_ICONS[s.key]}</span>
          <span className="store-toggle-text">
            <span className="store-toggle-name">{s.name}</span>
            <span className="store-toggle-sub">{s.sub}</span>
          </span>
        </button>
      )}
    </div>);

}

/* ---------- Filter / Search bar ---------- */
function FilterBar({ filter, setFilter, counts }) {
  return (
    <div className="filter-bar" data-screen-label="02 Filter">
      <div className="chip-row">
        {FILTERS.map((f) =>
        <button key={f.key}
        className={'chip ' + (filter === f.key ? 'active' : '')}
        onClick={() => setFilter(f.key)}>
            {f.label}
            <span className="chip-count">{counts[f.key]}</span>
          </button>
        )}
      </div>
    </div>);

}

/* ---------- Scoop face (cartoon expression overlay) ---------- */
function ScoopFace({ kind = 'happy' }) {
  // Faces are drawn on a 100x100 viewBox centered on the scoop.
  // Stroke uses currentColor; parent sets it via CSS.
  const base = {
    fill: 'none', stroke: 'currentColor',
    strokeWidth: 3.2, strokeLinecap: 'round', strokeLinejoin: 'round'
  };
  const cheekFill = 'rgba(244,166,176,0.55)';
  const tongueFill = '#E85A6B';
  switch (kind) {
    case 'tongue': // open mouth + tongue out (like cookie dough reference)
      return (
        <svg className="face" viewBox="0 0 100 100" aria-hidden="true">
          <circle cx="32" cy="42" r="5" fill="currentColor" />
          <circle cx="62" cy="42" r="5" fill="currentColor" />
          {/* open mouth */}
          <path d="M36 60 Q50 76 64 60" {...base} fill="rgba(0,0,0,0.65)" />
          {/* tongue */}
          <path d="M44 66 Q50 82 56 66 Z" fill={tongueFill} />
          {/* cheeks */}
          <circle cx="24" cy="56" r="5" fill={cheekFill} />
          <circle cx="76" cy="56" r="5" fill={cheekFill} />
        </svg>);

    case 'sleepy': // eyes closed, content half-smile (like matcha reference)
      return (
        <svg className="face" viewBox="0 0 100 100" aria-hidden="true">
          <path d="M24 42 Q32 36 40 42" {...base} />
          <path d="M60 42 Q68 36 76 42" {...base} />
          <path d="M38 60 Q50 70 62 60" {...base} />
          <circle cx="22" cy="56" r="5" fill={cheekFill} />
          <circle cx="78" cy="56" r="5" fill={cheekFill} />
        </svg>);

    case 'wink':
      return (
        <svg className="face" viewBox="0 0 100 100" aria-hidden="true">
          <circle cx="34" cy="44" r="5" fill="currentColor" />
          <path d="M58 44 Q66 38 74 44" {...base} />
          <path d="M36 60 Q50 72 64 60" {...base} />
          <circle cx="22" cy="56" r="5" fill={cheekFill} />
          <circle cx="78" cy="56" r="5" fill={cheekFill} />
        </svg>);

    case 'wow': // surprised o-mouth
      return (
        <svg className="face" viewBox="0 0 100 100" aria-hidden="true">
          <circle cx="34" cy="42" r="5" fill="currentColor" />
          <circle cx="66" cy="42" r="5" fill="currentColor" />
          <ellipse cx="50" cy="64" rx="7" ry="9" fill="rgba(0,0,0,0.7)" />
          <circle cx="22" cy="56" r="5" fill={cheekFill} />
          <circle cx="78" cy="56" r="5" fill={cheekFill} />
        </svg>);

    case 'cool': // little smirk, half-lid eyes
      return (
        <svg className="face" viewBox="0 0 100 100" aria-hidden="true">
          <path d="M26 42 L42 42" {...base} />
          <path d="M58 42 L74 42" {...base} />
          <path d="M40 62 Q52 70 62 60" {...base} />
          <circle cx="22" cy="56" r="5" fill={cheekFill} />
          <circle cx="78" cy="56" r="5" fill={cheekFill} />
        </svg>);

    case 'love': // hearts for eyes
      return (
        <svg className="face" viewBox="0 0 100 100" aria-hidden="true">
          {[34, 66].map((cx, i) =>
          <path key={i}
          d={`M${cx - 7} ${42} a4 4 0 0 1 7 -2 a4 4 0 0 1 7 2 q0 6 -7 11 q-7 -5 -7 -11 z`}
          fill={tongueFill} />
          )}
          <path d="M36 60 Q50 72 64 60" {...base} />
          <circle cx="22" cy="56" r="5" fill={cheekFill} />
          <circle cx="78" cy="56" r="5" fill={cheekFill} />
        </svg>);

    case 'happy':
    default:
      return (
        <svg className="face" viewBox="0 0 100 100" aria-hidden="true">
          <circle cx="34" cy="44" r="5" fill="currentColor" />
          <circle cx="66" cy="44" r="5" fill="currentColor" />
          <path d="M36 60 Q50 72 64 60" {...base} />
          <circle cx="22" cy="56" r="5" fill={cheekFill} />
          <circle cx="78" cy="56" r="5" fill={cheekFill} />
        </svg>);

  }
}

/* ---------- Flavor card ---------- */
function FlavorCard({ f, scoopStyle, onOpen }) {
  const visibleTags = f.tags.filter((t) => TAG_META[t]).slice(0, 2);
  return (
    <article className={'card' + (f.sold ? ' soldout' : '')}
    onClick={() => onOpen(f)} tabIndex="0"
    onKeyDown={(e) => {if (e.key === 'Enter' || e.key === ' ') {e.preventDefault();onOpen(f);}}}
    role="button" aria-label={`See more about ${f.name}`}>
      <div className="card-img" style={{ background: f.bg }}>
        {f.img ?
        <img className={'scoop scoop-img ' + scoopStyle} src={f.img} alt={f.name} /> :

        <div className={'scoop ' + scoopStyle}
        style={{ background: `radial-gradient(circle at 35% 30%, ${lighten(f.color)} 0%, ${f.color} 55%, ${f.deep} 100%)` }}>
          </div>
        }
        <div className="badge-stack">
          {visibleTags.map((t) =>
          <span key={t} className={'badge ' + TAG_META[t].cls}>{TAG_META[t].label}</span>
          )}
        </div>
        {f.sold &&
        <div className="soldout-overlay">
            <div className="soldout-tag">Sold out today</div>
          </div>
        }
      </div>
      <div className="card-body">
        <h3 className="card-name">{f.name}</h3>
        <p className="card-desc">{f.desc}</p>
      </div>
    </article>);

}

/* ---------- Flavor modal ---------- */
function FlavorModal({ flavor, scoopStyle, onClose }) {
  // Lock body scroll
  useEffect(() => {
    if (!flavor) return;
    const prev = document.body.style.overflow;
    document.body.style.overflow = 'hidden';
    const onKey = (e) => {if (e.key === 'Escape') onClose();};
    window.addEventListener('keydown', onKey);
    return () => {
      document.body.style.overflow = prev;
      window.removeEventListener('keydown', onKey);
    };
  }, [flavor, onClose]);

  // Sprinkle burst
  const burst = useMemo(() => {
    if (!flavor) return [];
    const cols = ['#C04A5B', '#6B8B3D', '#4A55A0', '#C68A1E', '#7A5FA0', '#F2A6B0'];
    return Array.from({ length: 28 }, (_, i) => ({
      x: 50 + (Math.random() - 0.5) * 60,
      y: 50 + (Math.random() - 0.5) * 60,
      tx: (Math.random() - 0.5) * 420,
      ty: (Math.random() - 0.5) * 420 - 60,
      r: Math.random() * 360,
      d: Math.random() * 0.15,
      col: cols[i % cols.length]
    }));
  }, [flavor && flavor.id]);

  if (!flavor) return null;
  const f = flavor;
  const allTags = f.tags.filter((t) => TAG_META[t]);

  return (
    <div className="modal-back" onClick={onClose} role="dialog" aria-modal="true" aria-label={f.name}>
      <div className="modal" onClick={(e) => e.stopPropagation()}>
        <button className="modal-close" onClick={onClose} aria-label="Close">
          <svg viewBox="0 0 24 24" width="20" height="20" fill="none" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round"><path d="M6 6l12 12M18 6L6 18" /></svg>
        </button>

        <div className="modal-grid">
          {/* Visual side */}
          <div className="modal-visual" style={{ background: f.bg }}>
            <div className="modal-confetti">
              {burst.map((s, i) =>
              <span key={i} className="modal-sprinkle"
              style={{
                left: s.x + '%', top: s.y + '%',
                background: s.col,
                transform: `rotate(${s.r}deg)`,
                '--tx': s.tx + 'px', '--ty': s.ty + 'px',
                animationDelay: s.d + 's'
              }} />
              )}
            </div>
            <div className="modal-scoop-wrap">
              {f.img ?
              <img className="modal-scoop modal-scoop-img" src={f.img} alt={f.name} /> :

              <div className={'modal-scoop ' + scoopStyle}
              style={{ background: `radial-gradient(circle at 35% 30%, rgba(255,255,255,0.65) 0%, ${f.color} 55%, ${f.deep} 100%)` }} />
              }
            </div>
            <div className="modal-tag-row">
              {allTags.map((t) =>
              <span key={t} className={'badge ' + TAG_META[t].cls}>{TAG_META[t].label}</span>
              )}
            </div>
          </div>

          {/* Info side */}
          <div className="modal-info">
            <h2 className="modal-title">{f.name}</h2>
            <p className="modal-long">{f.long || f.desc}</p>

            <div className="modal-section modal-section-two">
              <div>
                <h4>In every scoop</h4>
                <ul className="ing-list">
                  {f.ingredients && f.ingredients.map((ing, i) =>
                  <li key={i}><span className="ing-dot" style={{ background: '#de6ca1' }}></span>{ing}</li>
                  )}
                </ul>
              </div>
              <div>
                <h4>Allergens</h4>
                <div className="allergen-row">
                  {f.allergens && f.allergens.length > 0 ?
                  f.allergens.map((a, i) => <span key={i} className="allergen">{a}</span>) :
                  <span className="allergen allergen-none">None of the usual suspects</span>}
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>);

}

/* Lighten a CSS color string for highlight */
function lighten(c) {
  // Simple: just return white-ish gradient stop. The deep color anchors it.
  return 'rgba(255,255,255,0.65)';
}

/* ---------- Cart drawer ---------- */
function CartDrawer({ open, onClose, items, setItems }) {
  const total = items.reduce((a, i) => a + i.price * i.qty, 0);
  const updateQty = (id, d) => {
    setItems(items.map((i) => i.id === id ? { ...i, qty: Math.max(0, i.qty + d) } : i).filter((i) => i.qty > 0));
  };
  return (
    <>
      <div className={'drawer-back' + (open ? ' open' : '')} onClick={onClose}></div>
      <aside className={'drawer' + (open ? ' open' : '')} data-screen-label="03 Cart">
        <div className="drawer-head">
          <div className="drawer-title">Your scoops</div>
          <button className="icon-btn" onClick={onClose}><Icon.close /></button>
        </div>
        <div className="drawer-list">
          {items.length === 0 ?
          <div className="drawer-empty">
              <div className="drawer-empty-art">∅</div>
              <div style={{ fontFamily: 'Baloo 2', fontWeight: 700, fontSize: 24, color: 'var(--ink)' }}>Nothing scooped yet</div>
              <div style={{ marginTop: 8, fontSize: 13 }}>Pick a flavor — they go fast.</div>
            </div> :
          items.map((i) =>
          <div key={i.id} className="drawer-item">
              <div className="drawer-scoop" style={{ background: `radial-gradient(circle at 35% 30%, rgba(255,255,255,0.6), ${i.color} 60%, ${i.deep})` }} />
              <div>
                <div className="drawer-name">{i.name}</div>
                <div className="drawer-qty">
                  <button className="qty-btn" onClick={() => updateQty(i.id, -1)}>−</button>
                  <span style={{ minWidth: 18, textAlign: 'center' }}>{i.qty}</span>
                  <button className="qty-btn" onClick={() => updateQty(i.id, 1)}>+</button>
                  <span style={{ marginLeft: 6, color: 'var(--ink-mute)' }}>· {i.price} kr each</span>
                </div>
              </div>
              <div className="drawer-price">{i.price * i.qty} kr</div>
            </div>
          )}
        </div>
        {items.length > 0 &&
        <div className="drawer-foot">
            <div className="total-row">
              <div>
                <div className="total-label">Total · {items.reduce((a, i) => a + i.qty, 0)} scoops</div>
                <div className="total-val">{total} kr</div>
              </div>
              <div style={{ fontSize: 12, color: 'var(--ink-mute)', textAlign: 'right', maxWidth: 140 }}>
                Pickup ready in<br /><strong style={{ color: 'var(--ink)' }}>12 minutes</strong>
              </div>
            </div>
            <button className="checkout-btn">Reserve scoops · {total} kr <Icon.arrow style={{ marginLeft: 8 }} /></button>
          </div>
        }
      </aside>
    </>);

}

/* ---------- Footer ---------- */
const SITE_FOOTER_HTML = `<footer class="site-footer">
  <svg class="site-footer-wave" viewBox="0 0 1440 90" preserveAspectRatio="none" aria-hidden="true">
    <path d="M0,60 C240,10 480,100 720,55 C960,10 1200,80 1440,40 L1440,90 L0,90 Z"></path>
  </svg>

  <div class="footer-inner">
    <div class="footer-col">
      <h4>Besøg os</h4>
      <p class="footer-address" style="font-weight: 400">
        <span style="font-weight: 800">Iscafeén</span><br>
        Algade 43D<br>
        4000 Roskilde<br><br>
        <span style="font-weight: 800">Havnevogn</span><br>
        Vindeboder 9,<br>
        4000 Roskilde<br><br>
        Telefon: <a href="tel:+4546361297">46 36 12 97</a><br>
        E-mail: <a href="mailto:is@roskilde-ismejeri.dk">is@roskilde-ismejeri.dk</a>
      </p>
    </div>

    <div class="footer-col">
      <h4>Information</h4>
      <ul>
        <li><a href="jobs.html">Jobs</a></li>
        <li><a href="om-os.html">Om os</a></li>
        <li><a href="kontakt-os.html">Kontakt os</a></li>
        <li><a href="https://www.findsmiley.dk/979393" target="_blank" rel="noopener">Smiley kontrolrapport</a></li>
      </ul>
    </div>

    <div class="footer-col">
      <h4>Åbningstider</h4>
      <ul>
        <li><span style="font-weight: 800">Iscafeén</span>, Algade 43D</li>
        <li>Alle dage <span style="font-style: italic;">10–22</span></li>
        <li style="height: 10px;"></li>
        <li><span style="font-weight: 800">Havnevognen</span>, Vinboderne 9</li>
        <li>Alle dage <span style="font-style: italic;">10–22:30</span></li>
      </ul>
    </div>

    <div class="footer-col footer-social">
      <h4>Følg os</h4>
      <div class="footer-social-icons">
        <a href="https://www.instagram.com/p/DZdWZAciGo6/" target="_blank" rel="noopener" aria-label="Instagram">
          <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M7.0301.084c-1.2768.0602-2.1487.264-2.9111.5634-.7888.3075-1.4575.72-2.1228 1.3877-.6652.6677-1.075 1.3368-1.3802 2.127-.2954.7638-.4956 1.6365-.552 2.914-.0564 1.2775-.0689 1.6882-.0626 4.947.0062 3.2586.0206 3.6671.0825 4.9473.061 1.2765.264 2.1482.5635 2.9107.308.7889.72 1.4573 1.388 2.1228.6679.6655 1.3365 1.0743 2.1285 1.38.7632.295 1.6361.4961 2.9134.552 1.2773.056 1.6884.069 4.9462.0627 3.2578-.0062 3.668-.0207 4.9478-.0814 1.28-.0607 2.147-.2652 2.9098-.5633.7889-.3086 1.4578-.72 2.1228-1.3881.665-.6682 1.0745-1.3378 1.3795-2.1284.2957-.7632.4966-1.636.552-2.9124.056-1.2809.0689-1.6898.0627-4.948-.0062-3.2583-.0207-3.6668-.0814-4.9465-.0607-1.2797-.264-2.1487-.5633-2.9117-.3084-.7889-.72-1.4568-1.3876-2.1228C21.2982 1.33 20.628.9208 19.8378.6165 19.074.321 18.2017.1197 16.9244.0645 15.6471.0093 15.236-.005 11.977.0014 8.718.0076 8.31.0215 7.0301.0839m.1402 21.6932c-1.1693-.0509-1.8043-.2453-2.2271-.408-.5602-.216-.96-.4771-1.3812-.895-.4211-.4178-.6798-.8186-.8987-1.3775-.1644-.4227-.3624-1.057-.4171-2.2263-.0595-1.2645-.072-1.6442-.079-4.848-.007-3.2037.0053-3.583.0607-4.848.0508-1.1683.2463-1.804.4082-2.2266.216-.5608.4762-.96.8954-1.3816.4193-.4217.8186-.6803 1.3783-.8987.4223-.1651 1.0564-.3617 2.2252-.4174 1.2655-.0596 1.6448-.0721 4.848-.0791 3.2032-.007 3.5832.005 4.8493.0608 1.1683.0511 1.8045.2452 2.2266.4084.5604.216.96.4757 1.3814.8954.4213.4197.6802.8189.8989 1.3787.1655.4211.3617 1.0552.4169 2.2238.0596 1.2655.0734 1.6451.0792 4.848.0058 3.2029-.007 3.5832-.0605 4.848-.0511 1.1693-.2456 1.8043-.4082 2.2272-.216.5604-.4763.96-.8957 1.3814-.4194.4213-.8186.6803-1.3783.8987-.4219.165-1.0566.3617-2.2238.4174-1.2655.0596-1.6448.0721-4.8493.0791-3.2045.007-3.5825-.006-4.848-.0608M16.953 5.5864A1.44 1.44 0 1 0 18.39 4.144a1.44 1.44 0 0 0-1.437 1.4424M5.8385 12.012c.0067 3.4032 2.7706 6.1557 6.173 6.1493 3.4026-.0065 6.157-2.7701 6.1506-6.1733-.0065-3.4032-2.771-6.1565-6.174-6.1498-3.403.0067-6.156 2.771-6.1496 6.1738M8 12.0086a4 4 0 1 1 4.008 3.9921A3.9996 3.9996 0 0 1 8 12.0086"/></svg>
        </a>
        <a href="https://www.facebook.com/roskildeismejeri?locale=da_DK" target="_blank" rel="noopener" aria-label="Facebook">
          <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M13.5 21.95v-8.3h2.78l.42-3.23H13.5V8.36c0-.93.26-1.57 1.6-1.57h1.7V3.9c-.3-.04-1.31-.13-2.49-.13-2.46 0-4.15 1.5-4.15 4.27v2.38H7.4v3.23h2.76v8.3h3.34z"/></svg>
        </a>
        <a href="https://www.linkedin.com/company/roskilde-ismejeri/" target="_blank" rel="noopener" aria-label="LinkedIn">
          <svg viewBox="0 0 24 24" aria-hidden="true"><path d="M4.98 3.5a2.5 2.5 0 1 1 0 5 2.5 2.5 0 0 1 0-5zM3 9.5h4v11.5H3V9.5zm6 0h3.83v1.57h.05c.53-1 1.83-2.06 3.77-2.06 4.04 0 4.78 2.66 4.78 6.12V21h-4v-5.3c0-1.26-.02-2.88-1.76-2.88-1.76 0-2.03 1.37-2.03 2.79V21H9V9.5z"/></svg>
        </a>
      </div>
    </div>
  </div>

  <div class="footer-bottom">
    <span>© 2026 Roskilde Ismejeri · Alle rettigheder forbeholdes</span>
    <span><a href="#" data-cc="show-preferencesModal" style="color: inherit; text-decoration: none;">Cookieindstillinger</a> · <a href="privatlivspolitik.html" style="color: inherit; text-decoration: none;">Privatlivspolitik</a></span>
  </div>
</footer>`;
function Footer() {
  return <div data-screen-label="04 Footer" dangerouslySetInnerHTML={{ __html: SITE_FOOTER_HTML }} />;
}

/* ---------- Main App ---------- */
function App() {
  const [t, setTweak] = useTweaks(/*EDITMODE-BEGIN*/{
    "scoopStyle": "solid",
    "density": "comfortable",
    "showSoldOut": true
  } /*EDITMODE-END*/);

  const [filter, setFilter] = useState('all');
  const [store, setStore] = useState('algade');
  const [openFlavor, setOpenFlavor] = useState(null);
  const [cart, setCart] = useState([]);
  const [cartOpen, setCartOpen] = useState(false);
  const [favs, setFavs] = useState(new Set());
  const bagRef = useRef();

  // Read the admin's daily selection + catalog overrides.
  const [adminPicks, setAdminPicks] = useState(() => {
    try {
      const raw = localStorage.getItem('rs_daily_picks');
      return raw ? JSON.parse(raw) : null;
    } catch (_) {return null;}
  });
  const [liveCatalog, setLiveCatalog] = useState(() => getLiveCatalog());
  useEffect(() => {
    const refreshCatalog = () => setLiveCatalog(getLiveCatalog());
    const refreshPicks = () => {
      try {
        const raw = localStorage.getItem('rs_daily_picks');
        setAdminPicks(raw ? JSON.parse(raw) : null);
      } catch (_) {}
    };
    const onStorage = (e) => {
      if (e.key === 'rs_daily_picks') refreshPicks();
      if (e.key === 'rs_catalog') refreshCatalog();
    };
    window.addEventListener('storage', onStorage);
    window.addEventListener('catalogchange', refreshCatalog);
    return () => {
      window.removeEventListener('storage', onStorage);
      window.removeEventListener('catalogchange', refreshCatalog);
    };
  }, []);

  const counts = useMemo(() => {
    const c = { all: liveCatalog.length };
    FILTERS.forEach((f) => {
      if (f.key === 'all') return;
      c[f.key] = liveCatalog.filter((x) => x.tags.includes(f.key)).length;
    });
    return c;
  }, [liveCatalog]);

  const filtered = useMemo(() => {
    // Both shops draw from the full kitchen catalog. The admin's daily picks
    // determine which subset is live at each shop today.
    let r = liveCatalog;
    if (adminPicks && adminPicks[store]) {
      const allowed = new Set(adminPicks[store]);
      r = r.filter((f) => allowed.has(f.id));
      // Preserve admin-chosen ordering for this store
      const ix = new Map(adminPicks[store].map((id, i) => [id, i]));
      r = [...r].sort((a, b) => (ix.get(a.id) ?? 1e9) - (ix.get(b.id) ?? 1e9));
    } else if (!t.showSoldOut) {
      r = r.filter((f) => !f.sold);
    }
    if (filter !== 'all') r = r.filter((f) => f.tags.includes(filter));
    return r;
  }, [filter, store, t.showSoldOut, adminPicks, liveCatalog]);

  const toggleFav = (id) => {
    setFavs((prev) => {
      const n = new Set(prev);
      n.has(id) ? n.delete(id) : n.add(id);
      return n;
    });
  };

  const onAdd = (f, fromRect) => {
    // fly animation
    if (bagRef.current && fromRect) {
      const bagRect = bagRef.current.getBoundingClientRect();
      const dx = bagRect.left + bagRect.width / 2 - (fromRect.left + fromRect.width / 2);
      const dy = bagRect.top + bagRect.height / 2 - (fromRect.top + fromRect.height / 2);
      const el = document.createElement('div');
      el.className = 'fly-puff';
      el.style.left = fromRect.left + fromRect.width / 2 - 20 + 'px';
      el.style.top = fromRect.top + fromRect.height / 2 - 20 + 'px';
      el.style.background = `radial-gradient(circle at 35% 30%, rgba(255,255,255,0.7), ${f.color} 60%, ${f.deep})`;
      el.style.setProperty('--fly-to', `translate(${dx}px, ${dy}px)`);
      document.body.appendChild(el);
      setTimeout(() => el.remove(), 1000);
    }
    setCart((prev) => {
      const ex = prev.find((i) => i.id === f.id);
      if (ex) return prev.map((i) => i.id === f.id ? { ...i, qty: i.qty + 1 } : i);
      return [...prev, { id: f.id, name: f.name, color: f.color, deep: f.deep, price: f.price, qty: 1 }];
    });
  };

  const cartCount = cart.reduce((a, i) => a + i.qty, 0);
  const today = new Date().toLocaleDateString('en-GB', { weekday: 'long', day: 'numeric', month: 'long' });

  return (
    <>
            {/* Nav */}
      <nav className="nav" data-screen-label="00 Nav">
        <div className="nav-inner">
          <a href="index.html" className="brand"><img src="images/logo.webp" alt="Roskilde Ismejeri" /></a>
          <div className="nav-links">
            <a href="menu.html">MENU</a>
            <a href="iscafe.html">ISCAFE</a>
            <a href="havnevogn.html">HAVNEVOGN</a>
            <a href="#" className="active">DAGENS IS</a>
            <NavDropdown label="EVENTS &amp; FEST" items={[
              { label: 'Is til fest og fejring', href: 'fest-og-fejring.html' },
              { label: 'Firma', href: 'firma.html' }
            ]} />
          </div>
        </div>
      </nav>

      <Hero count={adminPicks && adminPicks[store] ? adminPicks[store].length : liveCatalog.filter((f) => !f.sold).length}
      todayDate={today} store={store} setStore={setStore} />

      {/* FilterBar removed */}

      <main className={'grid ' + (t.density === 'dense' ? 'dense' : t.density === 'airy' ? 'airy' : '')}
      data-screen-label="05 Grid">
        {filtered.length === 0 ?
        <div className="empty">
            <div className="empty-title">Nothing matched.</div>
            <p>Try a different flavor — or come back tomorrow. The menu changes daily.</p>
            <button className="chip" style={{ marginTop: 16 }}
          onClick={() => setFilter('all')}>Reset filters</button>
          </div> :
        filtered.map((f) =>
        <FlavorCard key={f.id} f={f} scoopStyle={t.scoopStyle} onOpen={setOpenFlavor} />
        )}
      </main>

      <Footer />

      <CartDrawer open={cartOpen} onClose={() => setCartOpen(false)} items={cart} setItems={setCart} />

      <FlavorModal flavor={openFlavor} scoopStyle={t.scoopStyle} onClose={() => setOpenFlavor(null)} />

      <TweaksPanel title="Tweaks">
        <TweakSection label="Scoop style">
          <TweakRadio
            value={t.scoopStyle}
            onChange={(v) => setTweak('scoopStyle', v)}
            options={[
            { value: 'solid', label: 'Solid' },
            { value: 'striped', label: 'Striped' },
            { value: 'dotted', label: 'Dotted' }]
            } />
          
        </TweakSection>
        <TweakSection label="Grid density">
          <TweakRadio
            value={t.density}
            onChange={(v) => setTweak('density', v)}
            options={[
            { value: 'dense', label: 'Dense' },
            { value: 'comfortable', label: 'Comfy' },
            { value: 'airy', label: 'Airy' }]
            } />
          
        </TweakSection>
        <TweakSection label="Display">
          <TweakToggle label="Show sold out" value={t.showSoldOut} onChange={(v) => setTweak('showSoldOut', v)} />
        </TweakSection>
      </TweaksPanel>
    </>);

}

ReactDOM.createRoot(document.getElementById('root')).render(<App />);