<!DOCTYPE html>

<html lang="en">

<head>

  <meta charset="UTF-8" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0" />

  <title>Dorianell's — Friday Pizza Drop</title>

  <link rel="preconnect" href="https://fonts.googleapis.com">

  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>

  <link href="https://fonts.googleapis.com/css2?family=Courier+Prime:ital,wght@0,400;0,700;1,400&family=Fraunces:opsz,wght@9..144,700;9..144,900&display=swap" rel="stylesheet">

  <style>

    :root {

      --paper: #F4EFE6;

      --card: #FAF7F2;

      --ink: #161513;

      --ink-muted: #57524A;

      --bakery-red: #B8332A;

      --bakery-green: #2B593F;

      --border: #161513;

    }


    * {

      box-sizing: border-box;

    }


    body {

      margin: 0;

      padding: 20px 14px 48px;

      background-color: var(--paper);

      background-image: radial-gradient(rgba(22, 21, 19, 0.06) 1px, transparent 0);

      background-size: 18px 18px;

      color: var(--ink);

      font-family: 'Courier Prime', monospace;

      line-height: 1.5;

    }


    .bakery-box {

      max-width: 560px;

      margin: 0 auto;

      background: var(--card);

      border: 3px solid var(--border);

      box-shadow: 7px 7px 0px var(--ink);

      padding: 26px 22px;

      position: relative;

    }


    .inner-border {

      border: 1.5px dashed rgba(22, 21, 19, 0.35);

      padding: 22px 18px;

    }


    .header {

      text-align: center;

      border-bottom: 2px solid var(--ink);

      padding-bottom: 18px;

      margin-bottom: 20px;

    }


    .logo-img {

      max-width: 270px;

      width: 82%;

      height: auto;

      display: block;

      margin: 0 auto 8px;

      mix-blend-mode: multiply;

    }


    .est-tag {

      display: inline-block;

      font-size: 0.78rem;

      font-weight: 700;

      letter-spacing: 0.14em;

      text-transform: uppercase;

      border-top: 1px solid var(--ink);

      border-bottom: 1px solid var(--ink);

      padding: 3px 10px;

      margin-top: 4px;

    }


    .drop-title {

      font-family: 'Fraunces', serif;

      font-weight: 900;

      font-size: 1.55rem;

      line-height: 1.15;

      margin: 14px 0 8px;

      text-align: center;

    }


    .ticket-box {

      background: #EFE9DD;

      border: 2px solid var(--ink);

      padding: 14px 16px;

      margin: 16px 0;

    }


    .ticket-label {

      font-size: 0.75rem;

      font-weight: 700;

      text-transform: uppercase;

      letter-spacing: 0.08em;

      color: var(--bakery-red);

      margin-bottom: 4px;

    }


    .pizza-desc {

      font-size: 1.02rem;

      font-weight: 700;

      margin: 0 0 10px;

    }


    .pickup-time {

      font-size: 0.88rem;

      color: var(--ink-muted);

      margin: 0;

      border-top: 1px dashed rgba(22, 21, 19, 0.3);

      padding-top: 8px;

    }


    .slots-banner {

      text-align: center;

      margin: 18px 0;

    }


    .slot-badge {

      display: inline-block;

      background: var(--bakery-green);

      color: #FFF;

      font-weight: 700;

      font-size: 0.95rem;

      padding: 6px 14px;

      letter-spacing: 0.05em;

      text-transform: uppercase;

      border: 2px solid var(--ink);

    }


    .slot-badge.sold-out {

      background: var(--bakery-red);

    }


    .karma-intro {

      font-size: 0.9rem;

      background: #FFFDF9;

      border-left: 4px solid var(--bakery-red);

      padding: 10px 12px;

      margin-bottom: 18px;

    }


    label {

      display: block;

      font-weight: 700;

      font-size: 0.85rem;

      text-transform: uppercase;

      margin-bottom: 5px;

      letter-spacing: 0.04em;

    }


    input, select, textarea {

      width: 100%;

      font-family: 'Courier Prime', monospace;

      font-size: 1rem;

      padding: 10px 12px;

      border: 2px solid var(--ink);

      background: #FFF;

      color: var(--ink);

      margin-bottom: 14px;

      border-radius: 0;

    }


    input:focus, select:focus, textarea:focus {

      outline: none;

      background: #FFFDF7;

      box-shadow: 3px 3px 0px var(--ink);

    }


    .btn-claim {

      width: 100%;

      background: var(--ink);

      color: var(--card);

      font-family: 'Fraunces', serif;

      font-size: 1.15rem;

      font-weight: 700;

      padding: 14px;

      border: 2px solid var(--ink);

      cursor: pointer;

      letter-spacing: 0.03em;

      transition: transform 0.08s ease;

    }


    .btn-claim:hover:not(:disabled) {

      background: var(--bakery-red);

      border-color: var(--ink);

    }


    .btn-claim:active:not(:disabled) {

      transform: translate(2px, 2px);

    }


    .btn-claim:disabled {

      opacity: 0.55;

      cursor: not-allowed;

    }


    .status-msg {

      margin-top: 14px;

      padding: 12px;

      font-weight: 700;

      text-align: center;

      border: 2px solid var(--ink);

      display: none;

    }


    .status-msg.success {

      display: block;

      background: #E3F1E8;

      color: var(--bakery-green);

    }


    .status-msg.error {

      display: block;

      background: #FBE9E7;

      color: var(--bakery-red);

    }


    .karma-wall {

      margin-top: 28px;

      border-top: 2px solid var(--ink);

      padding-top: 18px;

    }


    .wall-heading {

      font-family: 'Fraunces', serif;

      font-size: 1.2rem;

      margin: 0 0 12px;

      text-align: center;

    }


    .karma-item {

      background: #FFF;

      border: 1.5px solid var(--ink);

      padding: 10px 12px;

      margin-bottom: 10px;

      position: relative;

    }


    .karma-slot-tag {

      font-size: 0.72rem;

      font-weight: 700;

      text-transform: uppercase;

      color: var(--bakery-red);

    }


    .karma-neighbor {

      font-weight: 700;

      font-size: 0.98rem;

    }


    .karma-pledge-text {

      font-size: 0.9rem;

      font-style: italic;

      color: var(--ink-muted);

      margin-top: 3px;

    }


    .footer {

      text-align: center;

      margin-top: 24px;

      font-size: 0.78rem;

      color: var(--ink-muted);

    }


    .footer a {

      color: var(--ink);

      font-weight: 700;

    }

  </style>

</head>

<body>


  <div class="bakery-box">

    <div class="inner-border">

      <div class="header">

        <img src="dorianells.png" alt="Dorianell's" class="logo-img" />

        <div class="est-tag">Neighborhood Oven • Friday Drop</div>

      </div>


      <div id="loading" style="text-align:center; padding: 20px 0;">

        Checking the oven...

      </div>


      <div id="app-content" style="display:none;">

        <h1 class="drop-title" id="drop-title">Friday Night Pizza Drop</h1>


        <div class="ticket-box">

          <div class="ticket-label">On The Peel This Friday:</div>

          <p class="pizza-desc" id="pizza-desc"></p>

          <p class="pickup-time" id="pickup-time"></p>

        </div>


        <div class="slots-banner">

          <span class="slot-badge" id="slot-badge">Loading slots...</span>

        </div>


        <div id="claim-section">

          <div class="karma-intro">

            <strong>The Only Catch (Good Karma Rule):</strong> No cash accepted. To claim one of this week's extra pies, pledge one good deed you'll pay forward this week.

          </div>


          <form id="claim-form">

            <label for="name">Your Name</label>

            <input type="text" id="name" placeholder="e.g., Mike S." required />


            <label for="phone">Mobile Number (for Friday pickup text)</label>

            <input type="tel" id="phone" placeholder="(630) 555-0199" required />


            <label for="karma-select">Your Good Karma Pledge</label>

            <select id="karma-select" required>

              <option value="">-- Choose a good deed or write your own --</option>

              <option value="Drop off groceries or donate $10 to the local food pantry">Donate $10 or drop food at the local pantry</option>

              <option value="Buy coffee for the person behind me in line">Buy coffee for the person behind me in line</option>

              <option value="Bring in a neighbor's trash cans or clear their walk">Bring in a neighbor's trash cans / help with yardwork</option>

              <option value="Leave an extra generous tip for a local service worker">Leave a big tip for a local delivery/service worker</option>

              <option value="CUSTOM">Write my own Good Karma pledge...</option>

            </select>


            <div id="custom-karma-wrap" style="display:none;">

              <label for="custom-karma">Your Custom Pledge</label>

              <input type="text" id="custom-karma" placeholder="What good deed are you doing this week?" />

            </div>


            <button type="submit" class="btn-claim" id="submit-btn">Claim My Friday Pie</button>

          </form>

        </div>


        <div id="status-msg" class="status-msg"></div>


        <div class="karma-wall">

          <h2 class="wall-heading">This Week's Karma Wall</h2>

          <div id="karma-list">

            <p style="text-align:center; font-size:0.88rem; color:var(--ink-muted);">No pies claimed yet—grab the first slot above!</p>

          </div>

        </div>

      </div>


      <div class="footer">

        Baked in the spirit of <a href="https://www.dorianells.com" target="_blank">Dorianell's</a> • A project by <a href="https://blog.jakeparrillo.com" target="_blank">Jake Parrillo</a>

      </div>

    </div>

  </div>


  <script>

    // PASTE YOUR GOOGLE APPS SCRIPT WEB APP URL BELOW:

    const SCRIPT_URL = 'https://script.google.com/macros/s/AKfycbzvKqdwBYC2Ddb9p08nUzjyYyv99ORxKk7em4sjm4pwYAJeAdKvUC_gvcMxj2ktrA/exec';


    const karmaSelect = document.getElementById('karma-select');

    const customKarmaWrap = document.getElementById('custom-karma-wrap');

    const customKarmaInput = document.getElementById('custom-karma');


    karmaSelect.addEventListener('change', () => {

      if (karmaSelect.value === 'CUSTOM') {

        customKarmaWrap.style.display = 'block';

        customKarmaInput.required = true;

      } else {

        customKarmaWrap.style.display = 'none';

        customKarmaInput.required = false;

      }

    });


    async function loadDropData() {

      try {

        const res = await fetch(SCRIPT_URL);

        const data = await res.json();


        document.getElementById('loading').style.display = 'none';

        document.getElementById('app-content').style.display = 'block';


        document.getElementById('drop-title').textContent = data.title;

        document.getElementById('pizza-desc').textContent = data.description;

        document.getElementById('pickup-time').textContent = data.pickup;


        const badge = document.getElementById('slot-badge');

        const claimSection = document.getElementById('claim-section');


        if (data.status !== 'OPEN' || data.remainingSlots <= 0) {

          badge.textContent = 'Sold Out For This Friday';

          badge.classList.add('sold-out');

          claimSection.style.display = 'none';

        } else {

          const pieWord = data.remainingSlots === 1 ? 'Pie' : 'Pies';

          badge.textContent = `${data.remainingSlots} of ${data.totalSlots} ${pieWord} Left`;

          badge.classList.remove('sold-out');

          claimSection.style.display = 'block';

        }


        renderKarmaWall(data.claims);

      } catch (err) {

        document.getElementById('loading').textContent = 'Could not load oven status. Please refresh.';

      }

    }


    function renderKarmaWall(claims) {

      const list = document.getElementById('karma-list');

      if (!claims || claims.length === 0) {

        list.innerHTML = '<p style="text-align:center; font-size:0.88rem; color:var(--ink-muted);">No pies claimed yet—grab the first slot above!</p>';

        return;

      }


      list.innerHTML = claims.map((c, idx) => `

        <div class="karma-item">

          <div class="karma-slot-tag">Pie #${idx + 1} Claimed</div>

          <div class="karma-neighbor">${escapeHtml(c.name)}</div>

          <div class="karma-pledge-text">"${escapeHtml(c.karma)}"</div>

        </div>

      `).join('');

    }


    function escapeHtml(str) {

      return String(str).replace(/[&<>"']/g, m => ({

        '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;'

      }[m]));

    }


    document.getElementById('claim-form').addEventListener('submit', async (e) => {

      e.preventDefault();

      const btn = document.getElementById('submit-btn');

      const statusMsg = document.getElementById('status-msg');


      const name = document.getElementById('name').value.trim();

      const phone = document.getElementById('phone').value.trim();

      const karma = karmaSelect.value === 'CUSTOM'

        ? customKarmaInput.value.trim()

        : karmaSelect.value;


      btn.disabled = true;

      btn.textContent = 'Locking in your pie...';

      statusMsg.className = 'status-msg';

      statusMsg.style.display = 'none';


      try {

        const res = await fetch(SCRIPT_URL, {

          method: 'POST',

          body: JSON.stringify({ name, phone, karma })

        });

        const result = await res.json();


        if (result.success) {

          statusMsg.textContent = result.message;

          statusMsg.classList.add('success');

          document.getElementById('claim-form').reset();

          customKarmaWrap.style.display = 'none';

          await loadDropData();

        } else {

          statusMsg.textContent = result.message;

          statusMsg.classList.add('error');

          await loadDropData();

        }

      } catch (err) {

        statusMsg.textContent = 'Network error. Please try again.';

        statusMsg.classList.add('error');

      } finally {

        btn.disabled = false;

        btn.textContent = 'Claim My Friday Pie';

      }

    });


    loadDropData();

  </script>

</body>

</html>