============================================================
 ScriptsCrypt Remote v1.1 — run your scripts from your phone
============================================================

WHAT IT IS
  A small server that runs on your Windows PC/server plus a
  phone-friendly web app. From your phone you can browse your
  script library, view code, and RUN scripts with parameters —
  the script executes on your PC and the output comes back to
  your phone. No app store: it installs as a home-screen web app.

  Files:
    Start-Server.bat          double-click this to start the server
    ScriptsCrypt-Remote.ps1   the server (PowerShell 5.1+)
    wwwroot\                  the phone web app (served by the server)
    scripts\                  put your .ps1 files here (created on first run)

SETUP ON YOUR PC (5 minutes)
  1. Copy this whole folder to your Windows PC/server.
  2. Put your PowerShell scripts in the scripts\ folder
     (or edit Start-Server.bat to pass -ScriptFolder "D:\Scripts").
  3. FIRST RUN: right-click Start-Server.bat -> "Run as administrator".
     (Admin is needed once so Windows allows the web port.
      Alternative: run this once as admin, then run normally:
         netsh http add urlacl url=http://*:8080/ user=YOURNAME)
     After that, just double-click Start-Server.bat normally.
  4. The window prints your server address and AUTH TOKEN.
     Leave the window open — closing it stops the server.
     The window now stays open on errors so you can read them.
  5. Windows Firewall may ask about network access — allow it
     (private networks). If your phone can't connect, run:
         New-NetFirewallRule -DisplayName "ScriptsCrypt Remote" `
           -Direction Inbound -LocalPort 8080 -Protocol TCP `
           -Action Allow -Profile Private

SETUP ON YOUR PHONE (2 minutes)
  1. Same Wi-Fi as the PC: open http://<pc-ip>:8080
     (the server window shows the exact address).
     Away from home: use your PC's Tailscale IP instead —
     install Tailscale (free) on both, zero port forwarding.
  2. Enter the auth token shown in the server window.
     The phone remembers it — you only do this once.
  3. iPhone: Share > Add to Home Screen.
     Android: menu > Add to Home screen / Install app.
     It now behaves like a native app with the lime icon.

OPTIONS
  .\ScriptsCrypt-Remote.ps1 -ScriptFolder "D:\Scripts" -Port 9090 -TimeoutSec 300
    -ScriptFolder   where your .ps1 files live (default: scripts\)
    -Port           web port (default 8080)
    -TimeoutSec     max seconds per script run (default 120)
    -Token          set your own token instead of the generated one
  The token is saved to %APPDATA%\ScriptsCrypt\remote\token.txt
  so it stays the same between restarts. Delete that file to
  generate a fresh one.

WHAT IT DOES
  - Library: recursive scan, search, Automation/Security/Network
    categories, favorites and note indicators (reads your
    desktop ScriptsCrypt favorites.json / notes.json if present).
  - Code view with PowerShell syntax highlighting.
  - Run: scripts with a param() block get a parameter form
    (switches as toggles, defaults pre-filled, mandatory enforced).
  - Output streams back to the phone when the run finishes.

LIMITATIONS (v1)
  - Scripts run as the Windows user running the server, with
    that user's permissions. Interactive scripts (Read-Host,
    confirmation prompts) will hang until the timeout stops them.
  - One run at a time — a second request waits for the first.
  - Very chatty scripts (megabytes of output) may truncate.

SECURITY — READ THIS
  Anyone holding the token can run ARBITRARY scripts as you.
  - Keep the token secret. Regenerate it if it leaks.
  - Do NOT port-forward this to the public internet.
    Use Tailscale or your LAN only.
  - The token is required on every API call; there is no
    anonymous access to running scripts.

TROUBLESHOOTING
  Phone can't connect: PC and phone on the same Wi-Fi? Firewall
    rule added? Server window still open? Try the Tailscale IP.
  "Token was rejected": copy the CURRENT token from the server
    window — it changes only if you delete the token file.
  Script hangs: it is probably waiting for input (Read-Host).
    Wait for the timeout, then remove the prompt from the script.
