<?php
/*
 * Template Name: CUBBA – 3D Viewer
 * Description: Halaman full-screen untuk CUBBA 3D Model Viewer & PDF
 */
?>
<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
  <meta charset="<?php bloginfo('charset'); ?>">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>CUBBA – 3D Viewer | tombaccomezza.id</title>

  <script type="module" src="https://unpkg.com/@google/model-viewer/dist/model-viewer.min.js"></script>
  <link href="https://fonts.googleapis.com/css2?family=Cormorant+Garamond:wght@300;400;500;600&family=Raleway:wght@200;300;400;500&display=swap" rel="stylesheet">

  <?php wp_head(); ?>

  <style>
    :root {
      --gold:       #C9A84C;
      --gold-light: #E8D08A;
      --gold-dim:   #8A6F32;
      --black:      #000000;
      --dark:       #0A0A0A;
      --dark2:      #111111;
      --white:      #FFFFFF;
      --text-muted: #888888;
      --border:     rgba(201,168,76,0.25);
    }

    *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

    html, body {
      width: 100%; min-height: 100vh;
      background: var(--black);
      color: var(--white);
      font-family: 'Raleway', sans-serif;
      overflow-x: hidden;
    }

    /* ── GRAIN OVERLAY ── */
    body::before {
      content: '';
      position: fixed; inset: 0; z-index: 0;
      background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.04'/%3E%3C/svg%3E");
      pointer-events: none;
      opacity: 0.4;
    }

    /* ── PAGE WRAPPER ── */
    .page-wrapper {
      position: relative; z-index: 1;
      min-height: 100vh;
      display: flex; flex-direction: column;
      align-items: center;
      padding: 52px 24px 40px;
    }

    /* ── LOGO ── */
    .logo-wrap {
      margin-bottom: 44px;
      animation: fadeDown 0.9s ease both;
    }
    .logo-wrap img {
      height: 80px;
      width: auto;
      display: block;
      filter: drop-shadow(0 0 18px rgba(201,168,76,0.3));
    }

    /* ── DIVIDER ── */
    .divider {
      width: 120px; height: 1px;
      background: linear-gradient(90deg, transparent, var(--gold), transparent);
      margin: 0 auto 44px;
      animation: fadeIn 1.2s ease both 0.3s;
    }

    /* ── BUTTON GRID ── */
    .btn-grid {
      width: 100%;
      max-width: 560px;
      display: flex;
      flex-direction: column;
      gap: 14px;
      margin-bottom: 18px;
    }

    /* ── 3D BUTTONS ── */
    .btn-3d {
      position: relative;
      display: flex; align-items: center; justify-content: space-between;
      padding: 16px 24px;
      background: transparent;
      border: 1px solid var(--border);
      color: var(--gold-light);
      font-family: 'Raleway', sans-serif;
      font-size: 13px;
      font-weight: 400;
      letter-spacing: 0.18em;
      text-transform: uppercase;
      cursor: pointer;
      transition: border-color 0.3s, background 0.3s, color 0.3s;
      overflow: hidden;
      animation: fadeUp 0.7s ease both;
    }
    .btn-3d:nth-child(1) { animation-delay: 0.15s; }
    .btn-3d:nth-child(2) { animation-delay: 0.25s; }
    .btn-3d:nth-child(3) { animation-delay: 0.35s; }
    .btn-3d:nth-child(4) { animation-delay: 0.45s; }

    .btn-3d::before {
      content: '';
      position: absolute; inset: 0;
      background: linear-gradient(90deg, transparent, rgba(201,168,76,0.06), transparent);
      transform: translateX(-100%);
      transition: transform 0.5s ease;
    }
    .btn-3d:hover::before { transform: translateX(100%); }
    .btn-3d:hover {
      border-color: var(--gold);
      background: rgba(201,168,76,0.05);
      color: var(--gold);
    }

    .btn-3d .btn-label { flex: 1; text-align: left; }
    .btn-3d .btn-icon {
      font-size: 16px;
      opacity: 0.5;
      transition: opacity 0.3s, transform 0.3s;
    }
    .btn-3d:hover .btn-icon { opacity: 1; transform: rotate(15deg); }

    /* ── PDF BUTTON ── */
    .btn-pdf {
      display: flex; align-items: center; justify-content: space-between;
      padding: 16px 24px;
      background: transparent;
      border: 1px solid rgba(255,255,255,0.12);
      color: var(--text-muted);
      font-family: 'Raleway', sans-serif;
      font-size: 13px;
      font-weight: 400;
      letter-spacing: 0.18em;
      text-transform: uppercase;
      text-decoration: none;
      cursor: pointer;
      transition: border-color 0.3s, color 0.3s, background 0.3s;
      animation: fadeUp 0.7s ease both 0.55s;
    }
    .btn-pdf:hover {
      border-color: rgba(255,255,255,0.35);
      color: var(--white);
      background: rgba(255,255,255,0.03);
    }
    .btn-pdf .btn-icon { opacity: 0.4; transition: opacity 0.3s; }
    .btn-pdf:hover .btn-icon { opacity: 1; }

    /* ── NOTIFICATION ── */
    .notification {
      margin-top: 52px;
      max-width: 520px;
      text-align: center;
      padding: 20px 28px;
      border-top: 1px solid var(--border);
      animation: fadeIn 1s ease both 0.8s;
    }
    .notification p {
      font-family: 'Cormorant Garamond', serif;
      font-size: 13px;
      font-weight: 300;
      font-style: italic;
      color: var(--gold-dim);
      letter-spacing: 0.04em;
      line-height: 1.8;
    }
    .notification .ar-icon {
      display: inline-block;
      margin-right: 6px;
      opacity: 0.7;
    }

    /* ════════════════════════════════════
       MODAL
    ════════════════════════════════════ */
    #modal-3d {
      display: none;
      position: fixed; inset: 0; z-index: 99999;
      background: #000;
    }
    #modal-3d.active { display: block; }

    .modal-close {
      position: absolute; top: 16px; right: 16px; z-index: 100001;
      background: rgba(0,0,0,0.6);
      border: 1px solid rgba(201,168,76,0.4);
      color: var(--gold-light);
      font-family: 'Raleway', sans-serif;
      font-size: 11px;
      letter-spacing: 0.15em;
      text-transform: uppercase;
      padding: 8px 18px;
      cursor: pointer;
      transition: background 0.2s, border-color 0.2s;
      backdrop-filter: blur(4px);
    }
    .modal-close:hover {
      background: rgba(201,168,76,0.15);
      border-color: var(--gold);
    }

    model-viewer {
      width: 100%; height: 100vh;
      background-color: #000;
      display: block;
    }

    /* ── ANIMATIONS ── */
    @keyframes fadeDown {
      from { opacity: 0; transform: translateY(-20px); }
      to   { opacity: 1; transform: translateY(0); }
    }
    @keyframes fadeUp {
      from { opacity: 0; transform: translateY(16px); }
      to   { opacity: 1; transform: translateY(0); }
    }
    @keyframes fadeIn {
      from { opacity: 0; }
      to   { opacity: 1; }
    }

    /* ── RESPONSIVE ── */
    @media (max-width: 480px) {
      .page-wrapper { padding: 40px 16px 32px; }
      .logo-wrap img { height: 60px; }
      .btn-3d, .btn-pdf { font-size: 11px; padding: 14px 18px; }
      .notification p { font-size: 12px; }
    }
  </style>
</head>

<body>

<!-- ── MAIN PAGE ── -->
<div class="page-wrapper">

  <!-- Logo -->
  <div class="logo-wrap">
    <img src="https://tombaccomezza.id/wp-content/uploads/2026/05/CUBBA-Logo.png" alt="CUBBA Logo">
  </div>

  <div class="divider"></div>

  <!-- Button Grid -->
  <div class="btn-grid">

    <button class="btn-3d" onclick="openViewer('https://tombaccomezza.id/wp-content/uploads/2026/05/CUBBA-50gr.glb')">
      <span class="btn-label">CUBBA 50 gr</span>
      <span class="btn-icon">⬡</span>
    </button>

    <button class="btn-3d" onclick="openViewer('https://tombaccomezza.id/wp-content/uploads/2026/05/CUBBA-50gr-UAE.glb')">
      <span class="btn-label">CUBBA 50 gr – UAE Edition</span>
      <span class="btn-icon">⬡</span>
    </button>

    <button class="btn-3d" onclick="openViewer('https://tombaccomezza.id/wp-content/uploads/2026/05/CUBBA-250gr.glb')">
      <span class="btn-label">CUBBA 250 gr</span>
      <span class="btn-icon">⬡</span>
    </button>

    <button class="btn-3d" onclick="openViewer('https://tombaccomezza.id/wp-content/uploads/2026/05/CUBBA-250gr-UAE.glb')">
      <span class="btn-label">CUBBA 250 gr – UAE Edition</span>
      <span class="btn-icon">⬡</span>
    </button>

    <a class="btn-pdf"
       href="https://tombaccomezza.id/wp-content/uploads/2026/05/CUBBA-PDFs.pdf"
       target="_blank" rel="noopener">
      <span class="btn-label">CUBBA – PDF Layouts</span>
      <span class="btn-icon">↗</span>
    </a>

  </div>

  <!-- Notification -->
  <div class="notification">
    <p>
      <span class="ar-icon">◈</span>
      Created for Previewing the 3D MockUp. This 3D MockUp can also be accessed as
      Augmented Reality (AR) on AR-supported mobile devices.
    </p>
  </div>

</div><!-- /.page-wrapper -->


<!-- ── 3D VIEWER MODAL ── -->
<div id="modal-3d">
  <button class="modal-close" onclick="closeViewer()">✕ &nbsp;Close</button>
  <model-viewer
    id="model-viewer"
    src=""
    alt="CUBBA 3D Model"
    ar
    shadow-intensity="1"
    camera-controls
    auto-rotate
    autoplay
    interaction-prompt="auto"
    min-camera-orbit="auto auto 50%"
    max-camera-orbit="auto auto 200%"
  ></model-viewer>
</div>


<script>
  const modal      = document.getElementById('modal-3d');
  const modelViewer = document.getElementById('model-viewer');

  function openViewer(glbUrl) {
    modelViewer.setAttribute('src', glbUrl);
    modal.classList.add('active');
    document.body.style.overflow = 'hidden';
  }

  function closeViewer() {
    modal.classList.remove('active');
    modelViewer.removeAttribute('src');
    document.body.style.overflow = '';
  }

  // Toggle auto-rotate & animasi saat model diklik
  modelViewer.addEventListener('click', function() {
    if (modelViewer.hasAttribute('auto-rotate')) {
      modelViewer.removeAttribute('auto-rotate');
      modelViewer.pause();
    } else {
      modelViewer.setAttribute('auto-rotate', '');
      modelViewer.play();
    }
  });

  // Tutup dengan ESC
  document.addEventListener('keydown', function(e) {
    if (e.key === 'Escape') closeViewer();
  });
</script>

<?php wp_footer(); ?>

</body>
</html>