/* === FUENTES LOCALES + FALLBACKS PERFECTOS === */
@font-face {
  font-family: 'Syncopate';
  src: local('Arial Black'), local('Arial Narrow'), local('Impact');
  font-weight: 700;
  font-style: normal;
  unicode-range: U+000-5FF; /* Solo caracteres latinos */
}
@font-face {
  font-family: 'Syncopate';
  src: local('Arial'), local('Helvetica'), local('sans-serif');
  font-weight: 400;
  font-style: normal;
}

/* Inter → fallback casi idéntico con fuentes del sistema */
@font-face {
  font-family: 'Inter';
  src: local('Segoe UI'), local('Roboto'), local('Helvetica Neue'), local('Arial'), local('sans-serif');
  font-weight: 300 400 500 600 700;
  font-style: normal;
}
  * { margin: 0; padding: 0; box-sizing: border-box; }

  html, body { 
      height: 100%; 
      overflow: hidden; 
      font-family: 'Inter', sans-serif; 
      background: #050505; 
      color: #fff;
      transition: background 0.4s ease, color 0.4s ease;
  }

  canvas { display: block; width: 100vw; height: 100vh; }

  /* Global Loader */
  #global-loader {
      position: fixed;
      inset: 0;
      background: rgba(5, 5, 5, 0.95);
      display: none; /* Hidden by default */
      align-items: center;
      justify-content: center;
      flex-direction: column;
      z-index: 100;
      transition: opacity 0.5s ease;
  }

  .spinner {
      width: 50px;
      height: 50px;
      border: 3px solid rgba(255,255,255,0.1);
      border-radius: 50%;
      border-top-color: #fff;
      animation: spin 1s ease-in-out infinite;
      margin-bottom: 1rem;
  }

  /* Glassmorphism base */
  .glass { 
      background: rgba(10, 10, 10, 0.85);
      backdrop-filter: blur(16px);
      -webkit-backdrop-filter: blur(16px);
      border: 1px solid rgba(255, 255, 255, 0.1);
      box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
      border-radius: 8px;
      transition: all 0.3s ease;
  }

  /* UI Layer */
  #ui-layer {
      position: absolute;
      inset: 0;
      pointer-events: none;
      z-index: 10;
      padding: 2rem;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
  }
  @media (min-width: 768px) { #ui-layer { padding: 3rem 4rem; } }

  /* Header */
  header {
      display: flex;
      flex-direction: column;
      gap: 1.5rem;
      pointer-events: auto;
  }
  @media (min-width: 768px) {
      header { 
          flex-direction: row; 
          justify-content: space-between; 
          align-items: center; 
      }
  }

  h1 {
      font-family: 'Syncopate', sans-serif;
      font-size: 2.8rem;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: -0.05em;
      mix-blend-mode: difference;
      color: white;
  }
  @media (min-width: 768px) { h1 { font-size: 3.8rem; } }

  /* Wallet Input + EXPLORE Button */
  .wallet-group {
      display: flex;
      background: rgba(10,10,10,0.85);
      border: 1px solid rgba(255,255,255,0.1);
      border-radius: 8px;
      overflow: hidden;
      transition: border 0.3s ease;
  }
  .wallet-group:hover { border-color: rgba(255,255,255,0.4); }

  #wallet-input {
      background: transparent;
      border: none;
      color: white;
      padding: 0.75rem 1rem;
      font-family: 'Courier New', monospace;
      font-size: 0.75rem;
      width: 180px;
      outline: none;
      transition: color 0.4s ease;
  }
  @media (min-width: 768px) { #wallet-input { width: 260px; } }

  #wallet-input::placeholder { 
      color: #666; 
      opacity: 1; 
      transition: color 0.4s ease;
  }

  /* FIX MODO CLARO: texto y placeholder contrastado WCAG */
  .light #wallet-input {
      color: #111 !important;
  }
  .light #wallet-input::placeholder {
      color: #444 !important; /* Más oscuro para contraste */
  }

  /* Botón EXPLORE */
  #load-btn {
      background: white;
      color: black;
      border: none;
      padding: 0.75rem 1.8rem;
      font-weight: bold;
      text-transform: uppercase;
      letter-spacing: 0.1em;
      font-size: 0.75rem;
      cursor: pointer;
      display: flex;
      align-items: center;
      gap: 0.5rem;
      transition: background 0.3s ease;
  }
  #load-btn:hover { background: #e0e0e0; }

  /* Control Buttons */
  .ctrl-btn {
      width: 40px;
      height: 40px;
      background: rgba(10,10,10,0.85);
      border: 1px solid rgba(255,255,255,0.1);
      border-radius: 8px;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      transition: all 0.3s ease;
  }
  .ctrl-btn:hover { 
      background: rgba(255,255,255,0.15); 
      transform: translateY(-2px);
  }

  .ctrl-btn svg {
      width: 20px;
      height: 20px;
      stroke: #ffffff;
      fill: none;
      stroke-width: 1.5;
      transition: stroke 0.4s ease;
  }

  #help-btn {
      font-family: 'Inter', sans-serif;
      font-weight: 900;
      font-size: 1.5rem;
      line-height: 1;
      color: #ffffff !important;
      transition: color 0.4s ease;
  }

  /* Loader Small */
  .loader {
      width: 16px;
      height: 16px;
      border: 2px solid rgba(255,255,255,0.1);
      border-left-color: white;
      border-radius: 50%;
      animation: spin 0.8s linear infinite;
  }
  @keyframes spin { to { transform: rotate(360deg); } }

  /* Panels */
  #settings-panel {
    position: absolute;
    top: 9rem;
    right: 2rem;
    background: rgba(10,10,10,0.95);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,0.1);
    padding: 1.5rem;
    border-radius: 12px;
    width: 280px;
    pointer-events: auto;
    z-index: 40;

    /* Estado inicial oculto */
    opacity: 0;
    visibility: hidden;
    transform: translateY(-20px);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);

    flex-direction: column;
    gap: 1rem;
}

/* Estado visible */
#settings-panel.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}
  #help-panel {
      position: absolute;
      bottom: 5rem;
      left: 50%;
      transform: translateX(-50%);
      background: rgba(10,10,10,0.95);
      backdrop-filter: blur(12px);
      border: 1px solid rgba(255,255,255,0.1);
      padding: 1.2rem 2.5rem;
      border-radius: 12px;
      pointer-events: none;
      opacity: 0;
      transition: opacity 0.4s ease;
      z-index: 30;
  }
  #help-panel.visible { opacity: 1; pointer-events: auto; }

  /* Color Picker */
  .color-wrapper {
      width: 32px;
      height: 32px;
      border-radius: 50%;
      overflow: hidden;
      border: 2px solid #555;
      cursor: pointer;
      transition: transform 0.2s ease;
  }
  .color-wrapper:hover { transform: scale(1.15); }
  input[type="color"] { 
      opacity: 0; 
      width: 48px; 
      height: 48px; 
      cursor: pointer; 
      transform: translate(-8px, -8px); 
  }

  /* Grids & Buttons */
  .grid { display: grid; gap: 0.5rem; margin-top: 0.5rem; }
  .grid-3 { grid-template-columns: 1fr 1fr 1fr; }
  .grid-2 { grid-template-columns: 1fr 1fr; }

  .grid-btn {
      padding: 0.75rem;
      background: #222;
      border: 1px solid #444;
      color: white;
      text-transform: uppercase;
      font-size: 0.68rem;
      cursor: pointer;
      border-radius: 6px;
      transition: all 0.2s ease;
  }
  .grid-btn:hover { background: #333; transform: translateY(-2px); }

  .action-row {
      display: grid;
      grid-template-columns: 1fr auto;
      gap: 0.5rem;
      margin-top: 1rem;
  }

  #export-btn, #share-btn {
      padding: 0.9rem;
      background: white;
      color: black;
      border: none;
      border-radius: 8px;
      font-weight: bold;
      text-transform: uppercase;
      cursor: pointer;
      transition: all 0.3s ease;
      display: flex;
      align-items: center;
      justify-content: center;
  }
  #share-btn {
      width: 3rem; /* Square button */
  }

  #export-btn:hover, #share-btn:hover { background: #f0f0f0; transform: translateY(-2px); }

  /* Details Modal */
  #details-modal {
      position: fixed;
      top: 0; right: 0;
      width: 100%;
      max-width: 420px;
      height: 100%;
      background: #0a0a0a;
      border-left: 1px solid #333;
      transform: translateX(100%);
      transition: transform 0.5s cubic-bezier(0.77, 0, 0.18, 1);
      z-index: 50;
      overflow-y: auto;
      padding: 6rem 2rem 2rem;
  }
  #details-modal.visible { transform: translateX(0); }

  /* Language Button */
  #lang-btn {
      font-weight: bold;
      font-size: 0.8rem;
      color: white !important;
      transition: color 0.4s ease;
  }

  /* TEMA CLARO — 100% CONSISTENTE */
  .light { 
      background: #f8f8f8 !important; 
      color: #111 !important; 
  }

  .light .glass,
  .light .wallet-group,
  .light .ctrl-btn,
  .light #settings-panel,
  .light #help-panel,
  .light #details-modal {
      background: rgba(255,255,255,0.95) !important;
      border-color: rgba(0,0,0,0.1) !important;
  }

  .light .ctrl-btn svg,
  .light #help-btn,
  .light #lang-btn {
      stroke: #111111 !important;
      color: #111111 !important;
  }

  .light #load-btn,
  .light #export-btn,
  .light #share-btn { 
      background: #111 !important; 
      color: white !important; 
  }

  .light .grid-btn { 
      background: #222; 
      color: white; 
  }

  /* Mobile */
  @media (max-width: 768px) {
      h1 { font-size: 2.3rem; }
      #wallet-input { width: 140px; }
      #settings-panel { 
          width: 90%; 
          right: 5%; 
          left: 5%; 
      }
  }

  @media (max-width: 768px) {
      /* Controles táctiles flotantes */
      #mobile-controls {
          position: fixed;
          bottom: 2rem;
          left: 50%;
          transform: translateX(-50%);
          display: grid;
          grid-template-columns: repeat(3, 70px);
          grid-template-rows: repeat(3, 70px);
          gap: 12px;
          z-index: 100;
          pointer-events: auto;
      }
      .mobile-btn {
          background: rgba(10,10,10,0.8);
          backdrop-filter: blur(12px);
          border: 1px solid rgba(255,255,255,0.15);
          border-radius: 50%;
          display: flex;
          align-items: center;
          justify-content: center;
          font-size: 1.8rem;
          color: white;
      }
      /* Ocultar en desktop */
      @media (min-width: 769px) { #mobile-controls { display: none; } }
  }

  .light #settings-panel,
  .light #help-panel {
      color: #111 !important;
  }

  .light .grid-btn {
      background: #333 !important;
      color: #fff !important;
      border: 1px solid #555;
  }

  .light .grid-btn:hover {
      background: #444 !important;
  }

  /* Botón activo (el que está seleccionado) */
  .grid-btn.active,
  .grid-btn:active {
      background: #00d4ff !important;
      color: black !important;
      transform: scale(0.95);
      box-shadow: 0 0 15px rgba(0, 212, 255, 0.6);
      font-weight: bold;
  }

  /* Efecto pressed suave */
  .grid-btn:active {
      transition: all 0.1s ease;
  }

  /* Fix brillo excesivo en NFTs (sobre todo videos e imágenes claras) */
  canvasMesh-material {
      toneMapped: true !important;
  }

  /* Suavizar luces RectAreaLight para evitar quemados */
  rectLight-intensity {
      intensity: 2.2; /* bajamos de 3.5 → 2.2 */
  }

  #mode-selector {
    background: rgba(10,10,10,0.85);
    border-left: 1px solid rgba(255,255,255,0.1);
    color: white;
    padding: 0.75rem 0.5rem;
    font-family: 'Inter', sans-serif;
    font-size: 0.75rem;
    cursor: pointer;
    transition: background 0.3s ease;
}

#mode-selector:hover {
    background: rgba(255,255,255,0.15);
}

.light #mode-selector {
    background: rgba(255,255,255,0.95) !important;
    color: #111 !important;
}