<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>{{ title or 'Preview' }}</title>
  <meta name="viewport" content="width=device-width,initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">

  <style>
    :root{
      --ink:#0f1220;
      --muted:#6b7280;
      --line:#ececf3;
      --card:#ffffff;

      /* reference card + buttons */
      --card-tint:#f5f3ff;            /* light purple card bg like screenshot */
      --card-border:#e6e2ff;          /* soft border */
      --btn-purple:#6c5ce7;           /* button color close to ref swatch */
      --btn-purple-hover:#7b6cf1;
      --panel-bg:#efeaff;             /* faint panel tint behind buttons */
    }

    body{ background:#f7f7fb; color:#1f2430; }
    .wrap{ max-width:1100px; margin:28px auto; padding:0 14px; }

    .dl-card{
      background:var(--card-tint);
      border:1px solid var(--card-border);
      border-radius:18px;
      box-shadow:0 10px 22px rgba(16,24,40,.08);
      padding:18px;
    }

    /* left: SQUARE video */
    .vid-box{ position:relative; border-radius:16px; overflow:hidden; }
    .ratio-1x1{ border-radius:16px; }
    .vid-badge{
      position:absolute; right:12px; top:12px;
      background:rgba(0,0,0,.72); color:#fff; font-weight:700; font-size:.8rem;
      padding:.25rem .5rem; border-radius:.5rem; letter-spacing:.3px;
    }
    .vid-play{
      position:absolute; inset:0; display:grid; place-items:center; pointer-events:none;
    }
    .vid-play svg{ filter:drop-shadow(0 8px 18px rgba(0,0,0,.45)); }

    /* right header */
    .top-row{ display:flex; align-items:center; justify-content:space-between; gap:10px; }
    .creator{ display:flex; align-items:center; gap:10px; }
    .avatar{
      width:42px; height:42px; border-radius:999px; background:#e8e9ff; color:#111;
      display:grid; place-items:center; font-weight:800;
    }
    .handle{ color:#6b7280; font-size:.9rem; margin-top:-2px; }

    .share-btn{
      width:42px; height:42px; border-radius:12px;
      background:#fff; border:1px solid var(--line);
      display:grid; place-items:center; cursor:pointer;
      transition:transform .1s ease, box-shadow .15s ease;
    }
    .share-btn:hover{ transform:translateY(-1px); box-shadow:0 8px 18px rgba(0,0,0,.12); }

    .title{ font-weight:800; font-size:1.35rem; margin:.55rem 0 .35rem; }
    .desc{ color:#475569; margin-bottom:.75rem; }

    /* panel + buttons like screenshot */
    .cta-panel{
      background:var(--panel-bg);
      border-radius:14px;
      padding:12px;
    }
    .cta-grid{ display:grid; grid-template-columns:repeat(2,1fr); gap:12px; }
    .cta{
      height:52px;
      background:var(--btn-purple);
      color:#fff;
      font-weight:800;
      border:0;
      border-radius:12px;
      padding:0 14px;
      display:flex; align-items:center; justify-content:center; gap:10px;
      text-decoration:none;
      box-shadow:0 10px 22px rgba(255, 255, 255, 0.35);
      transition:transform .1s ease, box-shadow .15s ease, background .12s ease;
      letter-spacing:.1px;
    }
    .cta:hover{ transform:translateY(-1px); box-shadow:0 14px 26px rgba(108,92,231,.45); background:var(--btn-purple-hover); }
    .cta svg{ filter:drop-shadow(0 2px 0 rgba(0,0,0,.10)); }

    @media (max-width: 992px){
      .cta-grid{ grid-template-columns:1fr; }
    }
  </style>
</head>
<body>
  <div class="wrap">
    <div class="dl-card">
      <div class="row g-3 align-items-stretch">
        <!-- LEFT: 1:1 video -->
        <div class="col-lg-5">
          <div class="vid-box">
            <div class="ratio ratio-1x1">
              <video
                src="{{ url_for('serve_video', file_id=file_id) }}"
                controls playsinline
                style="background:#000; object-fit:cover; width:100%; height:100%;"></video>
            </div>

            {% if duration_str %}
              <div class="vid-badge">{{ duration_str }}</div>
            {% endif %}

            <div class="vid-play" aria-hidden="true">
              <svg width="64" height="64" viewBox="0 0 66 66" fill="none">
                <circle cx="33" cy="33" r="30" fill="white" opacity="0.85"/>
                <path d="M27 22v22l18-11-18-11z" fill="#111827"/>
              </svg>
            </div>
          </div>
        </div>

        <!-- RIGHT: details + buttons -->
        <div class="col-lg-7">
          <div class="top-row">
            <div class="creator">
              <div class="avatar">{{ (uploader_name or 'U')[:1]|upper }}</div>
              <div>
                <div class="fw-bold">{{ uploader_name or 'Unknown User' }}</div>
                <div class="handle">@{{ uploader_handle or 'unknown' }}</div>
              </div>
            </div>

            <button class="share-btn" id="shareBtn" title="Copy share link" aria-label="Copy share link">
              <svg width="18" height="18" viewBox="0 0 24 24" fill="none">
                <path d="M7 12l5-5m0 0l5 5m-5-5v10" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
              </svg>
            </button>
          </div>

          <h3 class="title">{{ title }}</h3>
          <p class="desc">{{ description or "No description available." }}</p>

          <div class="cta-panel">
            <div class="cta-grid">
              <!-- MP4 -->
              <a class="cta" href="{{ url_for('download_video', file_id=file_id) }}">
                <svg width="18" height="18" viewBox="0 0 24 24" fill="none">
                  <path d="M12 3v12m0 0l-4-4m4 4l4-4M5 20h14" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
                </svg>
                MP4 Download{% if size_mb %} - {{ size_mb|int }}MB{% endif %}
              </a>

              <!-- MP3 (placeholder until you wire it) -->
              <a class="cta" href="#" onclick="alert('MP3 coming soon'); return false;">
                <svg width="18" height="18" viewBox="0 0 24 24" fill="none">
                  <path d="M9 18V5l10-2v13" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
                  <circle cx="6" cy="18" r="3" stroke="currentColor" stroke-width="2"/>
                  <circle cx="18" cy="16" r="3" stroke="currentColor" stroke-width="2"/>
                </svg>
                MP3 Download{% if mp3_size_mb %} - {{ mp3_size_mb|int }}MB{% endif %}
              </a>

              <a class="cta" href="{{ url_for('download_video', file_id=file_id) }}">
                <svg width="18" height="18" viewBox="0 0 24 24" fill="none">
                  <path d="M12 5v8m0 0l-3-3m3 3l3-3M5 20h14" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
                </svg>
                Download without Watermark
              </a>

              <a class="cta" href="{{ url_for('index') }}">
                <svg width="18" height="18" viewBox="0 0 24 24" fill="none">
                  <path d="M4 12h16M10 6l-6 6 6 6" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
                </svg>
                Download Another Video
              </a>
            </div>
          </div>

        </div>
      </div>
    </div>
  </div>

  <script>
    // Copy the public video URL to clipboard (share)
    (function(){
      const btn = document.getElementById('shareBtn');
      if(!btn) return;
      btn.addEventListener('click', async () => {
        const link = "{{ url_for('serve_video', file_id=file_id, _external=True) }}";
        try{
          await navigator.clipboard.writeText(link);
          btn.innerHTML = '✓';
          setTimeout(()=> btn.innerHTML =
            '<svg width="18" height="18" viewBox="0 0 24 24" fill="none"><path d="M7 12l5-5m0 0l5 5m-5-5v10" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>'
          , 1200);
        }catch(e){
          alert('Copy failed. Link: ' + link);
        }
      });
    })();
  </script>
</body>
</html>
