{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://portal.example/schemas/game.manifest.schema.json",
  "title": "game.manifest.json — browser game build manifest (schemaVersion 1.0)",
  "description": "Describes ONE immutable browser build of a game: engine/runtime, sizes, language packs, compatibility, features. Rights fields are informational claims only; the portal never trusts them without an admin decision.",
  "type": "object",
  "required": ["schemaVersion", "gameId", "title", "version", "developer", "engine", "build", "localization"],
  "additionalProperties": false,
  "properties": {
    "schemaVersion": { "const": "1.0" },
    "gameId": { "type": "string", "pattern": "^[a-z0-9][a-z0-9-]{1,79}$", "description": "Stable slug of the game (same across versions)." },
    "title": { "type": "string", "minLength": 1, "maxLength": 200 },
    "version": { "type": "string", "minLength": 1, "maxLength": 50, "description": "Game version as published by the developer." },
    "developer": {
      "type": "object", "required": ["name"], "additionalProperties": false,
      "properties": {
        "name": { "type": "string", "minLength": 1, "maxLength": 200 },
        "url": { "type": "string", "format": "uri" },
        "patreon": { "type": "string", "format": "uri" }
      }
    },
    "engine": {
      "type": "object", "required": ["name", "version"], "additionalProperties": false,
      "properties": {
        "name": { "enum": ["renpy", "rpgmaker-mv", "rpgmaker-mz", "unity", "godot", "html5", "twine", "tyranobuilder", "other"] },
        "version": { "type": "string", "maxLength": 50 },
        "runtimeId": { "type": ["string", "null"], "maxLength": 120, "description": "Shared runtime folder id, e.g. renpy-8.5.2-5570752ae6 (null if the build is self-contained)." }
      }
    },
    "build": {
      "type": "object", "required": ["type", "entryPoint", "sizeBytes", "progressiveLoading", "defaultLanguage"], "additionalProperties": false,
      "properties": {
        "type": { "enum": ["webassembly", "html5", "external-iframe"] },
        "buildId": { "type": "string", "pattern": "^[0-9a-f]{8,64}$" },
        "entryPoint": { "type": "string", "pattern": "^[^/\\\\][^\\\\]*$", "maxLength": 200 },
        "sizeBytes": { "type": "integer", "minimum": 0 },
        "initialDownloadBytes": { "type": ["integer", "null"], "minimum": 0, "description": "Measured bytes transferred before the first game screen (compressed)." },
        "progressiveLoading": { "type": "boolean" },
        "defaultLanguage": { "type": "string", "pattern": "^[a-z]{2,3}(-[a-z0-9]{2,8})*$" },
        "files": {
          "type": "array", "maxItems": 20000,
          "items": {
            "type": "object", "required": ["path", "size"], "additionalProperties": false,
            "properties": {
              "path": { "type": "string", "maxLength": 400 },
              "size": { "type": "integer", "minimum": 0 },
              "sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" }
            }
          }
        }
      }
    },
    "localization": {
      "type": "object", "required": ["mode", "languages"], "additionalProperties": false,
      "properties": {
        "mode": { "enum": ["external-language-packs", "embedded", "none"] },
        "languageParameter": { "type": "string", "pattern": "^[a-zA-Z_][a-zA-Z0-9_]{0,30}$", "default": "lang" },
        "languages": {
          "type": "array", "minItems": 1, "maxItems": 100,
          "items": {
            "type": "object", "required": ["code", "name", "nativeName", "type", "runtimeCode", "package", "verified"], "additionalProperties": false,
            "properties": {
              "code": { "type": "string", "pattern": "^[a-z]{2,3}(-[a-z0-9]{2,8})*$", "description": "Portal language code (pt-br, zh-hans)." },
              "name": { "type": "string", "maxLength": 80 },
              "nativeName": { "type": "string", "maxLength": 80 },
              "type": { "enum": ["original", "translation"] },
              "runtimeCode": { "type": "string", "maxLength": 20, "description": "Value the build expects in ?<languageParameter>=…" },
              "package": { "type": ["string", "null"], "maxLength": 300, "description": "Relative path of the language pack (null for the original / embedded)." },
              "packageSizeBytes": { "type": "integer", "minimum": 0 },
              "packageSha256": { "type": ["string", "null"], "pattern": "^[0-9a-f]{64}$" },
              "verified": { "type": "boolean", "description": "Claimed by the tool/translator; the portal requires its own review." },
              "translator": { "type": "string", "maxLength": 200 }
            }
          }
        }
      }
    },
    "compatibility": {
      "type": "object", "additionalProperties": false,
      "properties": {
        "desktop": { "$ref": "#/$defs/browsers" },
        "mobile": {
          "type": "object", "additionalProperties": false,
          "properties": { "android": { "$ref": "#/$defs/state" }, "ios": { "$ref": "#/$defs/state" } }
        },
        "recommendedOrientation": { "enum": ["landscape", "portrait", "any"] }
      }
    },
    "features": {
      "type": "object", "additionalProperties": false,
      "properties": {
        "fullscreen": { "type": "boolean" },
        "localSaves": { "type": "boolean" },
        "cloudSaves": { "type": "boolean" },
        "saveExport": { "type": "boolean" },
        "saveImport": { "type": "boolean" },
        "statusEvents": { "type": "boolean", "description": "The build posts renpyweb status messages (loading progress, running, error) to the parent." }
      }
    },
    "messaging": {
      "type": "object", "additionalProperties": false,
      "properties": {
        "protocol": { "enum": ["renpyweb/1", "none"] },
        "allowedParentOrigins": { "type": "array", "items": { "type": "string" }, "maxItems": 20 }
      }
    },
    "rights": {
      "type": "object", "additionalProperties": false,
      "description": "Claims only. The portal admin must confirm rights separately.",
      "properties": {
        "status": { "enum": ["pending", "licensed", "open-license", "authorized-embed", "restricted", "expired", "blocked"] },
        "translationAllowed": { "type": "boolean" },
        "modificationAllowed": { "type": "boolean" },
        "webPortAllowed": { "type": "boolean" },
        "hostingAllowed": { "type": "boolean" },
        "redistributionAllowed": { "type": "boolean" },
        "advertisingAllowed": { "type": "boolean" },
        "subscriptionMonetizationAllowed": { "type": "boolean" },
        "evidence": { "type": "string", "maxLength": 1000 }
      }
    },
    "generator": {
      "type": "object", "additionalProperties": true,
      "properties": { "name": { "type": "string" }, "version": { "type": "string" }, "builtAt": { "type": "string" } }
    }
  },
  "$defs": {
    "state": { "enum": ["verified", "emulated", "untested", "broken"] },
    "browsers": {
      "type": "object", "additionalProperties": false,
      "properties": {
        "edge": { "$ref": "#/$defs/state" }, "chrome": { "$ref": "#/$defs/state" },
        "firefox": { "$ref": "#/$defs/state" }, "safari": { "$ref": "#/$defs/state" }
      }
    }
  }
}
