<script lang="ts">
  interface Props {
    onclose: () => void;
  }

  let { onclose }: Props = $props();
</script>

<div
  class="modal-overlay"
  role="button"
  tabindex="0"
  onclick={onclose}
  onkeydown={(e) => e.key === "Enter" && onclose()}
>
  <div
    class="modal-content"
    role="dialog"
    aria-labelledby="modal-title"
    tabindex="-1"
    onclick={(e) => e.stopPropagation()}
    onkeydown={(e) => e.stopPropagation()}
  >
    <h1 id="modal-title">Random Sample Generator and Processor</h1>
    <div class="modal-columns">
      <div class="modal-column gif-column">
        <img src="/tutorial.gif" alt="Tutorial showing how to use RSGP" class="tutorial-gif" />
      </div>
      <div class="modal-column text-column">
        <ol>
          <li class="description">
            Generate new samples using a diverse collection of synth engines.
          </li>
          <li class="description">
            Process samples using a growing list of tools and effects.
          </li>
          <li class="description">Export your samples as WAV files.</li>
        </ol>
      </div>
    </div>
    <p class="modal-footer">
      Created by <a
        href="https://raphaelforment.fr"
        target="_blank"
        rel="noopener noreferrer">Raphaël Forment (BuboBubo)</a
      >
      • Licensed under <a
        href="https://www.gnu.org/licenses/gpl-3.0.html"
        target="_blank"
        rel="noopener noreferrer">GPL 3.0</a
      >
    </p>
    <button class="modal-close" onclick={onclose}>Start</button>
  </div>
</div>

<style>
  .modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    animation: fadeIn 0.2s ease-out;
  }

  @keyframes fadeIn {
    from {
      opacity: 0;
    }
    to {
      opacity: 1;
    }
  }

  @keyframes slideIn {
    from {
      opacity: 0;
      transform: translateY(-20px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .modal-content {
    background-color: #000;
    border: 2px solid #fff;
    padding: 1.25rem;
    max-width: 800px;
    width: calc(100% - 2rem);
    color: #fff;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideIn 0.3s ease-out;
    box-shadow: 0 8px 32px rgba(255, 255, 255, 0.1);
  }

  .modal-content h1 {
    margin: 0 0 1.575rem 0;
    font-size: 1.25rem;
    font-weight: bold;
    letter-spacing: 0.02em;
    text-align: center;
  }

  .modal-columns {
    display: flex;
    flex-direction: column;
    gap: 1.575rem;
    margin-bottom: 1.575rem;
  }

  .modal-column {
    flex: 1;
  }

  .gif-column {
    flex: 0 0 auto;
    max-width: 420px;
  }

  .text-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  .text-column ol {
    display: flex;
    flex-direction: column;
    justify-content: space-evenly;
    height: 100%;
    margin: 0;
    padding-left: 2rem;
  }

  .modal-content .description {
    margin: 0;
    line-height: 1.6;
    color: #e0e0e0;
    font-size: 0.875rem;
  }

  .tutorial-gif {
    width: 100%;
    max-width: 100%;
    height: auto;
    border: 1px solid #444;
  }

  .text-column ol li {
    margin-bottom: 0;
  }

  .modal-footer {
    margin: 0 0 1.575rem 0;
    font-size: 0.75rem;
    color: #bbb;
    text-align: center;
  }

  .modal-footer a {
    color: #646cff;
    text-decoration: none;
    transition: color 0.2s ease;
  }

  .modal-footer a:hover {
    color: #8891ff;
    text-decoration: underline;
  }

  .modal-close {
    margin-top: 0;
    width: 100%;
    padding: 0.75rem;
    font-size: 1rem;
    background-color: #fff;
    color: #000;
    border: 2px solid #fff;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }

  .modal-close:hover {
    background-color: #000;
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(255, 255, 255, 0.2);
  }

  .modal-close:active {
    transform: translateY(0);
    box-shadow: 0 2px 6px rgba(255, 255, 255, 0.1);
  }

  @media (min-width: 480px) {
    .modal-content {
      padding: 1.75rem;
      width: calc(100% - 3rem);
    }

    .modal-content h1 {
      font-size: 1.5rem;
      margin: 0 0 1.575rem 0;
    }

    .modal-content .description {
      font-size: 0.9375rem;
    }
  }

  @media (min-width: 768px) {
    .modal-content {
      padding: 2.5rem;
    }

    .modal-content h1 {
      font-size: 1.75rem;
      margin: 0 0 2.1rem 0;
    }

    .modal-columns {
      flex-direction: row;
      gap: 2.1rem;
      margin-bottom: 2.1rem;
    }

    .modal-content .description {
      margin: 0;
      font-size: 1rem;
      line-height: 1.7;
    }

    .modal-footer {
      margin: 0 0 2.1rem 0;
      font-size: 0.875rem;
    }

    .modal-close {
      margin-top: 0;
      padding: 0.875rem;
      font-size: 1.125rem;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .modal-overlay,
    .modal-content {
      animation: none;
    }

    .modal-close {
      transition: none;
    }
  }
</style>
