/**
 * APHELION — the frozen observatory. Room graph:
 *
 *   vestibule ──(bottom-right door)──▶ archive        (the detour: STARGRIP)
 *       │  ▲
 *       │  └─ return door
 *       └──(top of the smooth chimney — WALL-JUMP ONLY)──▶ shaft
 *                                                            │
 *                                       beacon checkpoint ───┤
 *                                                            ▼
 *                                                         orrery (boss)
 *
 *  vestibule: teaches move/jump/attack. The door to the shaft is VISIBLE at
 *    the top of a smooth-walled chimney the base kit cannot climb.
 *  archive:   a tall platforming detour past wisps; STARGRIP gauntlets wait
 *    on the dais at the top.
 *  shaft:     the gate — a tall wall-jump chimney. Beacon checkpoint at the
 *    top, then a hatch in the dome floor of the orrery.
 *  orrery:    the Orrery Warden. Two phases, 10 HP.
 */

export const VIEW = { w: 390, h: 844 };

export type RoomId = 'vestibule' | 'archive' | 'shaft' | 'orrery';

export interface Box { x: number; y: number; w: number; h: number }

export interface Solid extends Box {
  /** 'solid' blocks all sides (and is wall-jumpable); 'oneway' only catches downward feet */
  type: 'solid' | 'oneway';
  tile: 'ground' | 'platform';
}

export interface Door extends Box {
  to: RoomId;
  /** where the player appears in the target room */
  entry: { x: number; y: number };
}

export interface EnemySpawn {
  kind: 'wisp' | 'scuttler';
  min: number;
  max: number;
  /** scuttler: ground line; wisp: hover base line */
  y: number;
}

export interface RoomDef {
  id: RoomId;
  name: string;
  w: number;
  h: number;
  bg: 'bgVestibule' | 'bgArchive' | 'bgShaft' | 'bgBoss';
  /** rgb of the drifting fog layers */
  fog: [number, number, number];
  solids: Solid[];
  doors: Door[];
  enemies: EnemySpawn[];
  /** default spawn / respawn point for the room (feet position) */
  entry: { x: number; y: number };
  /** main floor line, for grounding shadows */
  floorY: number;
}

// the one unlockable -----------------------------------------------------------

/** STARGRIP gauntlets — wall-slide + wall-jump. Lives on the archive dais. */
export const PICKUP = { room: 'archive' as RoomId, x: 200, y: 352 };

/** the shaft's mid-climb checkpoint beacon (feet position on its platform) */
export const BEACON = { room: 'shaft' as RoomId, x: 205, y: 320 };

// rooms ---------------------------------------------------------------------

const W = VIEW.w; // every room is exactly one screen wide; the camera is vertical

export const ROOMS: Record<RoomId, RoomDef> = {
  vestibule: {
    id: 'vestibule',
    name: 'The Vestibule',
    w: W,
    h: 1200,
    bg: 'bgVestibule',
    fog: [150, 185, 215],
    floorY: 1124,
    solids: [
      { x: -30, y: 1124, w: W + 60, h: 96, type: 'solid', tile: 'ground' },
      { x: 236, y: 1022, w: 120, h: 14, type: 'oneway', tile: 'platform' },
      { x: 54, y: 932, w: 120, h: 14, type: 'oneway', tile: 'platform' },
      // the balcony shelf the chimney rises from
      { x: 170, y: 842, w: 220, h: 26, type: 'solid', tile: 'platform' },
      // the chimney: two smooth pillars, 164px apart — wall-jump only.
      // left pillar's flat top is the landing for the shaft door.
      { x: -30, y: 392, w: 116, h: 450, type: 'solid', tile: 'ground' },
      { x: 250, y: 236, w: 140, h: 606, type: 'solid', tile: 'ground' },
    ],
    doors: [
      // top-left, on the left pillar's roof — the VISIBLE, unreachable exit
      { x: 0, y: 292, w: 22, h: 100, to: 'shaft', entry: { x: 40, y: 1624 } },
      // bottom-right at floor level — the way to the archive
      { x: 376, y: 984, w: 14, h: 140, to: 'archive', entry: { x: 34, y: 1424 } },
    ],
    enemies: [
      { kind: 'scuttler', min: 140, max: 330, y: 1124 },
      { kind: 'wisp', min: 60, max: 300, y: 985 },
    ],
    entry: { x: 50, y: 1124 },
  },

  archive: {
    id: 'archive',
    name: 'The Archive',
    w: W,
    h: 1500,
    bg: 'bgArchive',
    fog: [140, 200, 220],
    floorY: 1424,
    solids: [
      { x: -30, y: 1424, w: W + 60, h: 96, type: 'solid', tile: 'ground' },
      // the long zigzag climb up the shelves
      { x: 228, y: 1330, w: 130, h: 14, type: 'oneway', tile: 'platform' },
      { x: 50, y: 1238, w: 120, h: 14, type: 'oneway', tile: 'platform' },
      { x: 236, y: 1146, w: 130, h: 14, type: 'oneway', tile: 'platform' },
      { x: 40, y: 1054, w: 120, h: 14, type: 'oneway', tile: 'platform' },
      { x: 226, y: 962, w: 130, h: 14, type: 'oneway', tile: 'platform' },
      { x: 54, y: 870, w: 120, h: 14, type: 'oneway', tile: 'platform' },
      { x: 230, y: 778, w: 130, h: 14, type: 'oneway', tile: 'platform' },
      { x: 40, y: 686, w: 120, h: 14, type: 'oneway', tile: 'platform' },
      { x: 220, y: 594, w: 140, h: 14, type: 'oneway', tile: 'platform' },
      { x: 60, y: 502, w: 120, h: 14, type: 'oneway', tile: 'platform' },
      // the dais holding the STARGRIP
      { x: 130, y: 404, w: 140, h: 26, type: 'solid', tile: 'platform' },
    ],
    doors: [
      { x: 0, y: 1284, w: 14, h: 140, to: 'vestibule', entry: { x: 352, y: 1124 } },
    ],
    enemies: [
      { kind: 'scuttler', min: 120, max: 330, y: 1424 },
      { kind: 'wisp', min: 60, max: 330, y: 1180 },
      { kind: 'wisp', min: 60, max: 330, y: 745 },
    ],
    entry: { x: 34, y: 1424 },
  },

  shaft: {
    id: 'shaft',
    name: 'The Great Shaft',
    w: W,
    h: 1700,
    bg: 'bgShaft',
    fog: [165, 200, 235],
    floorY: 1624,
    solids: [
      { x: -30, y: 1624, w: W + 60, h: 76, type: 'solid', tile: 'ground' },
      // the shaft proper: two smooth continuous walls, 170px apart, hanging
      // 124px above the entry atrium so the player can walk in underneath.
      { x: 0, y: 360, w: 110, h: 1140, type: 'solid', tile: 'ground' },
      { x: 280, y: 360, w: 110, h: 1140, type: 'solid', tile: 'ground' },
      // small rest ledges jutting into the shaft (pass-through from below)
      { x: 110, y: 1230, w: 64, h: 14, type: 'oneway', tile: 'platform' },
      { x: 216, y: 880, w: 64, h: 14, type: 'oneway', tile: 'platform' },
      { x: 110, y: 540, w: 64, h: 14, type: 'oneway', tile: 'platform' },
      // the beacon platform spanning the shaft mouth, under the dome hatch
      { x: 130, y: 320, w: 150, h: 24, type: 'solid', tile: 'platform' },
    ],
    doors: [
      // bottom-right of the atrium, back down to the vestibule pillar top
      { x: 376, y: 1484, w: 14, h: 140, to: 'vestibule', entry: { x: 40, y: 392 } },
      // the dome hatch above the beacon — jump up through it to the boss
      { x: 140, y: 130, w: 110, h: 40, to: 'orrery', entry: { x: 70, y: 768 } },
    ],
    enemies: [
      { kind: 'wisp', min: 120, max: 270, y: 1110 },
      { kind: 'wisp', min: 120, max: 270, y: 700 },
    ],
    entry: { x: 40, y: 1624 },
  },

  orrery: {
    id: 'orrery',
    name: 'The Orrery',
    w: W,
    h: 844,
    bg: 'bgBoss',
    fog: [205, 175, 140],
    floorY: 768,
    solids: [
      { x: -30, y: 768, w: W + 60, h: 96, type: 'solid', tile: 'ground' },
      // two dodge perches
      { x: 24, y: 600, w: 110, h: 14, type: 'oneway', tile: 'platform' },
      { x: 256, y: 600, w: 110, h: 14, type: 'oneway', tile: 'platform' },
    ],
    doors: [],
    enemies: [],
    entry: { x: 70, y: 768 },
  },
};

export const ROOM_ORDER: RoomId[] = ['vestibule', 'archive', 'shaft', 'orrery'];
