Desarrollo tempranoPre-1.0: la sintaxis puede cambiar.Historial de versionesGitHub
Pixel 3D

Glowtide Aquarium

Crea un pequeño océano feliz: alimenta peces y criaturas, recoge perlas y amplía un hogar submarino luminoso.

Recoge la ostra para empezar; después alimenta a tus amigos y ahorra perlas para nuevos habitantes y mejoras.

Abrir el acuario en otra pestaña
Glowtide Aquarium

Cargando juego…

Licencia del juego

Ver código fuente
idle_aquarium.rune
#!RUNE
import "models.rune"
import "music.rune"
import "logic.rune"
import "care.rune"
import "critters.rune"
import "upgrades.rune"
import "shell.rune"

@App
name = Glowtide Aquarium
type = pixel-3d
runtime = hybrid
scene = aquarium
resolution = [640,400]
tick_rate = 30
port = 3036
shell = aquarium_cabinet

@Perspective/aquarium
fov = 58

@Scene/aquarium
logic = aquarium
map = lagoon
world = world
camera = camera
perspective = aquarium
lights = lights
things = ["tank","reef","garden","residents","feet","critter_food","nets","bubbles","food","treasure","visitor"]
controls = aquarium
persistence = {
    "key": "glowtide-aquarium-v1",
    "state": "progress",
    "interval_ticks": 150,
    "revision": "save_revision"
}
click_to_start = false
mouse_look = false
ui = ui
tv = aquarium

@TV/aquarium
initial_focus = toggle_menu
summary = [{"path":"progress.pearls","label":"PEARLS"},{"path":"alive_count","label":"FRIENDS"}]
modes = [
    {
        "id": "tank",
        "label": "TANK VIEW",
        "kind": "action",
        "action": "orbit_view",
        "bounds": {"origin":[20,30,2],"extent":[9,4.5,8],"scale":"tank_scale"}
    },
    {
        "id": "friends",
        "label": "FRIENDS",
        "kind": "cycle",
        "action": "inspect_resident",
        "groups": ["fish","crabs"],
        "targets": "residents"
    }
]

@Map/lagoon
sky = {
    "seed": 73,
    "zenith": "#080d2c",
    "horizon": "#123c65",
    "below": "#071b31",
    "cloud": "#245075",
    "speed": 0.025
}
legend = {".":{}}
grid:
    "..."
    "..."
    "..."

@Page/aquarium
logic = aquarium
view:
    canvas data-rune-pixel-3d=true

@Controls/aquarium
keys:
    ArrowLeft -> left
    ArrowRight -> right
    KeyA -> left
    KeyD -> right
commands:
    Space -> feed
    Digit1 -> buy_fish
    Digit2 -> grow_reef
    Digit3 -> grow_tank
    Tab -> toggle_menu
    KeyC -> collect_treasure
    KeyL -> cycle_lights
    KeyP -> host.pause
    KeyF -> host.fullscreen
    KeyM -> host.mute
gamepad:
    Button0 -> {"command":"feed"}
    Button2 -> {"command":"collect_treasure"}
    Button4 -> left
    Button5 -> right
    Button9 -> {"command":"host.pause"}
    Button3 -> {"command":"toggle_menu"}
care.rune
@Type/AquariumLife
state:
    age = 0
    hunger = 0
    dead = false
    lifespan = 2700
    starvation = 900
    cause = ""

action advance(seconds):
    stop when dead
    age += seconds
    hunger = min(starvation,hunger+seconds)
    if age>=lifespan || hunger>=starvation:
        dead = true
        cause = hunger>=starvation ? "Hunger" : "Old age"

action nourish(amount):
    stop when dead
    hunger = max(0,hunger-amount)

@Module/AquariumCare
exports = ["restore","advance","nourish"]

action restore(buddy,id,starvation):
    buddy.care = AquariumLife(id,{"age":buddy.age,"hunger":buddy.hunger,"dead":buddy.dead,"lifespan":buddy.lifespan,"starvation":starvation,"cause":buddy.cause})

action advance(buddy):
    buddy.care.age = buddy.age
    buddy.care.hunger = buddy.hunger
    buddy.care.dead = buddy.dead
    buddy.care.lifespan = buddy.lifespan
    call buddy.care.advance 1
    call sync buddy

action nourish(buddy,amount):
    buddy.care.hunger = buddy.hunger
    call buddy.care.nourish amount
    call sync buddy

action sync(buddy):
    buddy.age = buddy.care.age
    buddy.hunger = buddy.care.hunger
    buddy.dead = buddy.care.dead
    buddy.cause = buddy.care.cause
critters.rune
@Logic/aquarium
state:
    garden = []
    feet = []
    obstacles = []
    floral_models = ["aqua/blossom","aqua/fan","aqua/lily"]
    floral_names = ["Sunburst bloom","Violet sea fan","Moon lily"]
    floral_prices = [35,55,75]
    critter_models = ["aqua/crab","aqua/hermit","aqua/shrimp","aqua/snail"]
    critter_names = ["Sunset crab","Hermit crab","Cherry shrimp","Moon snail"]
    critter_prices = [45,65,55,40]
    walking = [[1,0],[1,1],[0,1],[-1,1],[-1,0],[-1,-1],[0,-1],[1,-1]]
    floor_clear = false
    floor_slot = -1
    floor_x = 0
    floor_y = 0
    shop_error = ""
    critter_food = []
    critter_dead_count = 0
    critter_hungry_count = 0
    remaining_critters = []

action prepare_critter(critter,index):
    critter.name = critter.name ? critter.name : ["Pebble","Shelly","Cherry","Moonbeam"][critter.kind]+(index>0 ? " "+(index+1) : "")
    critter.age = critter.age ? critter.age : 0
    critter.hunger = critter.hunger ? critter.hunger : 0
    critter.lifespan = critter.lifespan ? critter.lifespan : 5400+critter.kind*1800
    critter.base_lifespan = critter.base_lifespan ? critter.base_lifespan : critter.lifespan
    if !critter.dead:
        critter.lifespan = floor(critter.base_lifespan*(1+progress.life_level*0.1))
    critter.dead = critter.dead ? true : false
    critter.cause = critter.cause ? critter.cause : ""
    local care_id = critter.care ? critter.care.id : "critter-"+progress.next_id
    if !critter.care:
        progress.next_id += 1
    call care.restore critter, care_id, 1800

action update_critter_life:
    for critter, index in progress.critters:
        if !critter.dead:
            call care.advance critter
            if critter.dead:
                local crab = crabs[index]
                crab.moving = false
                if crab.target>=0:
                    local pellet = critter_food[crab.target]
                    pellet.owner = -1
                    pellet.chewing = false
                crab.target = -1
                if selected_critter==index:
                    keyboard_open = false
                notice = critter.name+" has passed on. Tap to retrieve from the sand."

action inspect_resident(index):
    if index<fish.length:
        call inspect_fish index
        stop when true
    if index>=fish.length && index<fish.length+crabs.length:
        call inspect_critter index-fish.length
        stop when true
    if index>=fish.length+crabs.length:
        call inspect_fish fish_style[index-fish.length-crabs.length].owner

action inspect_critter(index):
    stop when reset_open || shop!=""
    if index<0 || index>=crabs.length || floor(index)!=index:
        notice = "That critter is no longer in this lagoon."
        call update_labels
        stop when true
    if progress.critters[index].dead:
        nets = [{"x":crabs[index].x,"y":crabs[index].y,"z":crabs[index].z,"model":"aqua/net","visible":true}]
        net_ticks = 30
        notice = progress.critters[index].name+" retrieved with the net."
        remaining_critters = []
        for critter, ci in progress.critters:
            if ci!=index:
                remaining_critters.push(critter)
        progress.critters = remaining_critters
        profile_open = false
        keyboard_open = false
        selected_critter = -1
        call build_critters
        call animate
        call update_labels
        stop when true
    selected_critter = index
    selected_fish = -1
    profile_open = true
    menu_open = false
    keyboard_open = false
    name_error = ""
    call update_labels

action scatter_critter_food:
    critter_food = []
    for crab, index in crabs:
        crab.target = -1
        crab.munch = 0
        if !progress.critters[index].dead:
            for serving in range(0,2):
                local x = crab.x+cos(crab.angle)*0.4
                local y = crab.y+sin(crab.angle)*0.4
                call check_floor x, y, 0
                if !floor_clear:
                    x = crab.x
                    y = crab.y
                critter_food.push({"x":x,"y":y,"z":3.5+serving*0.4,"model":"aqua/algae","visible":true,"scale":1.8,"owner":-1,"chewing":false})

action eat_critter_food:
    for pellet in critter_food:
        if fed_ticks==0:
            pellet.visible = false
            pellet.owner = -1
        if pellet.visible && !pellet.chewing:
            pellet.z = max(2.2,pellet.z-0.012)
    for crab, index in crabs:
        if crab.target>=0:
            local pellet = critter_food[crab.target]
            if !pellet.visible || progress.critters[index].dead:
                crab.target = -1
                crab.munch = 0
            if pellet.visible && !progress.critters[index].dead && pellet.z<=2.25 && (pellet.x-crab.x)*(pellet.x-crab.x)+(pellet.y-crab.y)*(pellet.y-crab.y)<0.36:
                pellet.chewing = true
                crab.munch += 1
                pellet.scale = 1.8*(1-crab.munch/240)
                if crab.munch>=120:
                    pellet.visible = false
                    pellet.owner = -1
                    pellet.chewing = false
                    local critter = progress.critters[index]
                    save_revision += 1
                    call care.nourish critter, 600
                    crab.target = -1
                    crab.munch = 0

action build_garden:
    progress.florals = progress.florals ? progress.florals : [{"kind":0,"slot":-1}]
    garden = []
    for floral in progress.florals:
        if floral.slot>=0:
            garden.push({"x":20+(12+(floral.slot%9)*2-20)*tank_scale,"y":30+(26.5+floor(floral.slot/9)*1.7-30)*tank_scale,"z":2,"model":floral_models[floral.kind],"scale":tank_scale})
    call build_obstacles

action build_obstacles:
    obstacles = []
    for plant in reef:
        obstacles.push({"x":plant.x,"y":plant.y,"radius":0.65*(plant.scale ? plant.scale : 1)+0.5})
    for plant in garden:
        obstacles.push({"x":plant.x,"y":plant.y,"radius":0.9*tank_scale})
    obstacles.push({"x":24,"y":28.4,"radius":1.45})

action check_floor(x,y,clearance):
    floor_clear = abs(x-20)<=7.8*tank_scale && abs(y-30)<=3.7*tank_scale
    for obstacle in obstacles:
        if (x-obstacle.x)*(x-obstacle.x)+(y-obstacle.y)*(y-obstacle.y)<(obstacle.radius+clearance)*(obstacle.radius+clearance):
            floor_clear = false

action find_floor(clearance):
    floor_slot = -1
    local landing = clearance<0.4
    for slot in range(0,landing ? 91 : 45):
        local x = 20+((landing ? 12.5+(slot%13)*1.25 : 12+(slot%9)*2)-20)*tank_scale
        local y = 30+((landing ? 26.7+floor(slot/13)*1.05 : 26.5+floor(slot/9)*1.7)-30)*tank_scale
        call check_floor x, y, clearance
        for crab in crabs:
            if (x-crab.x)*(x-crab.x)+(y-crab.y)*(y-crab.y)<1.4:
                floor_clear = false
        if floor_clear:
            floor_slot = slot
            floor_x = x
            floor_y = y
            stop when true

action build_critters:
    save_revision += 1
    residents_dirty = true
    progress.critters = progress.critters ? progress.critters : [{"kind":0}]
    crabs = []
    feet = []
    critter_food = []
    for critter, index in progress.critters:
        call prepare_critter critter, index
        call find_floor 0.15
        if floor_slot>=0:
            call spawn_critter critter.kind, index
        if floor_slot<0:
            notice = "Some critters need more clear sand. Expand your lagoon."

action clear_critter_paths:
    for crab in crabs:
        call check_floor crab.x, crab.y, 0.12
        if !floor_clear:
            call find_floor 0.15
            if floor_slot>=0:
                crab.x = floor_x
                crab.y = floor_y
            if floor_slot<0:
                notice = "Some critters need more clear sand. Expand your lagoon."

action spawn_critter(kind,index):
    residents_dirty = true
    local speed = kind==3 ? 0.009 : kind==2 ? 0.045 : 0.028
    crabs.push({"x":floor_x,"y":floor_y,"z":2.12,"model":critter_models[kind],"kind":kind,"angle":0,"scale":0.8,"direction":index%8,"stride":0,"moving":false,"rest":index*11,"burst":90+index*13,"speed":speed,"target":-1,"munch":0})
    for side in range(0,2):
        feet.push({"x":floor_x,"y":floor_y,"z":2.12,"model":kind==2 ? "aqua/shrimp_feet" : "aqua/crab_feet","scale":0.8,"angle":0,"visible":kind!=3})

action move_critters:
    for crab, index in crabs:
        crab.moving = false
        if crab.target>=0 && !critter_food[crab.target].visible:
            crab.target = -1
        if crab.target<0 && !progress.critters[index].dead:
            local nearest = 10000
            for pellet, pi in critter_food:
                if pellet.visible && pellet.owner<0 && pellet.z<=2.25:
                    local distance = (pellet.x-crab.x)*(pellet.x-crab.x)+(pellet.y-crab.y)*(pellet.y-crab.y)
                    if distance<nearest:
                        nearest = distance
                        crab.target = pi
            if crab.target>=0:
                local pellet = critter_food[crab.target]
                pellet.owner = index
        crab.rest = max(0,crab.rest-1)
        if !progress.critters[index].dead && (crab.rest==0 || crab.target>=0):
            crab.burst -= 1
            if crab.burst<=0 && crab.target<0:
                crab.rest = 30+(index*17+ticks)%90
                crab.burst = 60+(index*23+ticks)%120
                crab.direction = (crab.direction+1+index%3)%8
            if crab.target>=0:
                local pellet = critter_food[crab.target]
                local dx = pellet.x-crab.x
                local dy = pellet.y-crab.y
                crab.direction = dx>0.15 ? (dy>0.15 ? 1 : dy< -0.15 ? 7 : 0) : dx< -0.15 ? (dy>0.15 ? 3 : dy< -0.15 ? 5 : 4) : (dy>0 ? 2 : 6)
            if (crab.rest==0 || crab.target>=0) && crab.munch==0:
                for attempt in range(0,8):
                    local direction = walking[crab.direction]
                    local step = crab.speed/(direction[0]!=0 && direction[1]!=0 ? sqrt(2) : 1)
                    local x = crab.x+direction[0]*step
                    local y = crab.y+direction[1]*step
                    call check_floor x, y, 0.12
                    for other, oi in crabs:
                        if oi!=index && (x-other.x)*(x-other.x)+(y-other.y)*(y-other.y)<0.45:
                            floor_clear = false
                    if floor_clear:
                        crab.x = x
                        crab.y = y
                        crab.angle = crab.direction*45
                        crab.stride += crab.speed*150
                        crab.moving = true
                        stop when true
                    crab.direction = (crab.direction+1)%8
                if !crab.moving:
                    crab.rest = 15

action count_critters:
    critter_dead_count = 0
    critter_hungry_count = 0
    for critter in progress.critters:
        if critter.dead:
            critter_dead_count += 1
        if !critter.dead && critter.hunger>=840:
            critter_hungry_count += 1

action animate_feet:
    for crab, index in crabs:
        local critter = progress.critters[index]
        crab.model = critter.dead ? "aqua/dead_critter" : critter_models[crab.kind]
        crab.scale = 0.8*(crab.munch>0 ? 1+sin(crab.munch*18)*0.03 : 1)
        crab.z = 2.12+(crab.moving && crab.kind!=3 ? abs(sin(crab.stride*2))*0.025 : 0)
        for side in range(0,2):
            local leg = feet[index*2+side]
            leg.visible = !critter.dead && crab.kind!=3
            local swing = crab.moving ? sin(crab.stride+(side==0 ? 0 : 180)) : 0
            local offset = side==0 ? -0.12 : 0.12
            leg.x = crab.x-cos(crab.angle)*swing*0.065-sin(crab.angle)*offset
            leg.y = crab.y-sin(crab.angle)*swing*0.065+cos(crab.angle)*offset
            leg.z = 2.1+max(0,swing)*0.07
            leg.angle = crab.angle+(side==0 ? 0 : 180)

action open_flower_shop:
    shop = "flowers"
    call open_shop

action open_critter_shop:
    shop = "critters"
    call open_shop

action open_shop:
    menu_open = false
    profile_open = false
    keyboard_open = false
    reset_open = false
    shop_index = 0
    shop_error = ""
    call update_labels
    call shop_move 0

action close_shop:
    shop = ""
    call update_labels

action shop_move(direction):
    stop when shop==""
    local count = ui.grid.items.length
    shop_index = (shop_index+direction+count)%count
    for i in range(0,count):
        stop when !ui.grid.items[shop_index].disabled
        shop_index = (shop_index+(direction<0 ? count-1 : 1))%count
    call update_labels

action buy_floral(kind):
    if kind<0 || kind>=3 || floor(kind)!=kind:
        notice = "Choose a floral variety from the picker."
        shop_error = notice
        call update_labels
        stop when true
    if garden.length>=12 || progress.pearls<floral_prices[kind]:
        notice = garden.length>=12 ? "Your floral garden has all 12 blossoms." : "Save a few more pearls for this bloom."
        shop_error = notice
        call update_labels
        stop when true
    call find_floor 0.4
    if floor_slot<0:
        notice = "No clear planting spot. Expand the tank for more room."
        shop_error = notice
        call update_labels
        stop when true
    progress.pearls -= floral_prices[kind]
    save_revision += 1
    progress.florals.push({"kind":kind,"slot":floor_slot})
    call build_garden
    shop = ""
    notice = floral_names[kind]+" planted! Your garden stays rooted in place."
    call update_labels

action buy_critter(kind):
    if kind<0 || kind>=4 || floor(kind)!=kind:
        notice = "Choose a critter variety from the picker."
        shop_error = notice
        call update_labels
        stop when true
    if progress.critters.length>=12 || progress.pearls<critter_prices[kind]:
        notice = progress.critters.length>=12 ? "All 12 bottom critter spaces are filled." : "Save a few more pearls for this critter."
        shop_error = notice
        call update_labels
        stop when true
    call find_floor 0.15
    if floor_slot<0:
        notice = "No clear landing spot. Expand the tank for more room."
        shop_error = notice
        call update_labels
        stop when true
    progress.pearls -= critter_prices[kind]
    save_revision += 1
    progress.critters.push({"kind":kind})
    call prepare_critter progress.critters[progress.critters.length-1], progress.critters.length-1
    call spawn_critter kind, crabs.length
    call animate
    shop = ""
    notice = critter_names[kind]+" joined your sandy neighborhood!"
    call update_labels

action shop_labels:
    ui.buttons = []
    ui.grid = {"layout":"sidebar","columns":1,"title":shop=="flowers" ? "Floral garden" : "Sandy neighbors",
        "subtitle":pearl_label,"footer":shop_error ? shop_error : "CHOOSE A VARIETY / TAP AWAY TO CLOSE","width":302,"rowHeight":40,"padding":12,"gap":8,"textScale":2,
        "dismissAction":"close_shop","moveAction":"shop_move","closeOnActivate":false,"items":[]}
    if shop=="flowers":
        for kind in range(0,3):
            ui.grid.items.push({"label":floral_names[kind],"sub":floral_prices[kind]+" pearls / "+garden.length+" of 12 planted","action":"buy_floral","args":[kind],"selected":shop_index==kind,"disabled":garden.length>=12 || progress.pearls<floral_prices[kind]})
    if shop=="critters":
        for kind in range(0,4):
            ui.grid.items.push({"label":critter_names[kind],"sub":critter_prices[kind]+" pearls / "+progress.critters.length+" of 12 neighbors","action":"buy_critter","args":[kind],"selected":shop_index==kind,"disabled":progress.critters.length>=12 || progress.pearls<critter_prices[kind]})
    if shop=="fish" || shop=="care":
        call upgrade_labels
logic.rune
@Logic/aquarium
modules = {"care":"AquariumCare"}
types = ["AquariumLife"]
state:
    save_revision = 0
    residents_dirty = true
    label_second = -1
    label_revision = -1
    label_eaten = -1
    label_feed = -1
    label_treasure = -1
    label_fed = false
    progress = {
        "pearls": 30,
        "fish": 3,
        "reef": 0,
        "earned": 0,
        "income_remainder": 0,
        "food_level": 0,
        "life_level": 0,
        "palette": 0,
        "tank": 0,
        "next_id": 1,
        "florals": [{"kind": 0, "slot": -1}],
        "critters": [{"kind": 0}],
        "buddies": [
            {
                "name": "Sunny",
                "age": 0,
                "kind": 0,
                "hunger": 0,
                "lifespan": 2700,
                "dead": false,
                "death_age": 0,
                "death_z": 6,
                "bites": 0,
                "cause": ""
            },
            {
                "name": "Bubbles",
                "age": 0,
                "kind": 1,
                "hunger": 0,
                "lifespan": 3600,
                "dead": false,
                "death_age": 0,
                "death_z": 6,
                "bites": 0,
                "cause": ""
            },
            {
                "name": "Indigo",
                "age": 0,
                "kind": 2,
                "hunger": 0,
                "lifespan": 4500,
                "dead": false,
                "death_age": 0,
                "death_z": 6,
                "bites": 0,
                "cause": ""
            }
        ]
    }
    reset_open = false
    shop = ""
    shop_index = 0
    surviving_buddies = []
    cleanup_index = -1
    alive_count = 3
    dead_count = 0
    hungry_count = 0
    nets = []
    net_ticks = 0
    menu_open = false
    menu_index = 0
    profile_open = false
    profile_hidden = true
    quick_hidden = false
    selected_fish = -1
    selected_critter = -1
    residents = []
    profile_name = ""
    profile_species = ""
    profile_age = ""
    name_error = ""
    name_draft = ""
    if selected_critter<0 && selected_fish==index:
        keyboard_open = false
    friend_names = ["Sunny", "Bubbles", "Indigo", "Mochi", "Peaches", "Ripple", "Coral", "Sprout"]
    species_names = [
        "Clownfish",
        "Blue tang",
        "Royal gramma",
        "Pufferfish",
        "Angelfish",
        "Butterflyfish",
        "Neon tetra",
        "Lionfish"
    ]
    tank_scale = 0.75
    tank_capacity = 18
    tank_cost = 600
    tank_locked = true
    tank_label = ""
    eaten = 0
    snack_label = ""
    status = "playing"
    ticks = 0
    fed_ticks = 0
    feed_cooldown = 0
    treasure_ticks = 600
    party = false
    orbit = 0
    orbit_target = 0
    world = null
    camera = {"x": 20, "y": 3, "z": 12.75, "angle": 90, "pitch": -20}
    tank = [{"x": 20, "y": 30, "z": 2, "model": "aqua/tank"}]
    fish = []
    crabs = []
    reef = []
    bubbles = []
    food = []
    treasure = []
    visitor = []
    lights = []
    species = [
        "aqua/clown",
        "aqua/tang",
        "aqua/royal",
        "aqua/puffer",
        "aqua/angel",
        "aqua/butterfly",
        "aqua/neon",
        "aqua/lion"
    ]
    food_models = ["aqua/food", "aqua/flake", "aqua/algae"]
    light_colors = ["#36e9ee", "#ff5db5", "#a77cff"]
    light_names = ["LAGOON GLOW", "CANDY SUNSET", "MOON JELLY"]
    fish_cost = 45
    reef_cost = 30
    income = 1.5
    fish_full = false
    reef_full = false
    fish_locked = false
    reef_locked = false
    feed_locked = false
    feed_cost = 4
    treasure_locked = false
    pearl_label = ""
    income_label = ""
    fish_label = ""
    reef_label = ""
    feed_label = ""
    treasure_label = ""
    lighting_label = ""
    collection_label = ""
    event_label = ""
    notice = "Welcome home! Your fish earn pearls just by swimming."
    ui = {"meters": [], "objective": "", "detail": "", "prompt": "", "notice": "", "panel": null}

action initialize:
    music.stop
    music.play "glowtide_drift"
    world = voxel_world(40, 40, 24, ["aqua/sand"], {"renderDistance": 48})
    progress.pearls = clamp(floor(progress.pearls),0,100000)
    # Save restoration accepts integers; the remainder is stored in half-pearl units.
    progress.income_remainder = progress.income_remainder==1 ? 1 : 0
    progress.food_level = progress.food_level ? clamp(floor(progress.food_level),0,3) : 0
    progress.life_level = progress.life_level ? clamp(floor(progress.life_level),0,3) : 0
    progress.next_id = progress.next_id ? progress.next_id : 1
    progress.tank = progress.tank ? clamp(floor(progress.tank),0,2) : 0
    tank_capacity = 18+progress.tank*6
    tank_scale = 0.75+progress.tank*0.25
    progress.fish = clamp(floor(progress.fish),0,tank_capacity)
    progress.buddies = progress.buddies ? progress.buddies : []
    progress.reef = clamp(floor(progress.reef),0,5)
    progress.palette = clamp(floor(progress.palette),0,2)
    progress.earned = max(0,floor(progress.earned))
    ticks = 0
    fed_ticks = 0
    feed_cooldown = 0
    treasure_ticks = 600
    party = false
    orbit = 0
    orbit_target = 0
    menu_open = false
    profile_open = false
    keyboard_open = false
    reset_open = false
    shop = ""
    selected_fish = -1
    selected_critter = -1
    eaten = 0
    food = []
    nets = []
    net_ticks = 0
    call build_tank
    call build_reef
    call build_fish
    call build_garden
    call build_critters
    bubbles = []
    for i in range(0,24):
        bubbles.push(
            {
                "x": 20 + (-7 + (i % 3) * 7) * tank_scale,
                "y": 30 + (1.5 + (i % 2)) * tank_scale,
                "z": 2 + (i % 8) * 0.95 * tank_scale,
                "model": "aqua/bubble",
                "scale": 0.7 + (i % 3) * 0.3,
                "phase": i * 47
            }
        )
    treasure = [
        {"x": 24, "y": 28.4, "z": 2, "model": "aqua/chest"},
        {"x": 24, "y": 28.4, "z": 3.3, "model": "aqua/pearl", "visible": true}
    ]
    visitor = [{"x": 20, "y": 31.7, "z": 7.5, "model": "aqua/jelly", "visible": progress.reef >= 3}]
    call set_lights
    call animate
    call update_labels

action build_tank:
    tank = [{"x": 20, "y": 30, "z": 2, "model": "aqua/tank"}]
    tank.push({"x": 20, "y": 25.5, "z": 6, "model": "aqua/glass-wide", "pitch": 90, "angle": 90})
    tank.push({"x": 20, "y": 34.5, "z": 6, "model": "aqua/glass-wide", "pitch": 90, "angle": 90})
    tank.push({"x": 11, "y": 30, "z": 6, "model": "aqua/glass-side", "pitch": 90})
    tank.push({"x": 29, "y": 30, "z": 6, "model": "aqua/glass-side", "pitch": 90})
    for i in range(0,6):
        tank.push({"x": 11 + i * 3, "y": 25.5, "z": 10, "model": "aqua/rail"})
        tank.push({"x": 11 + i * 3, "y": 34.5, "z": 10, "model": "aqua/rail"})
        tank.push({"x": 12.5 + i * 3, "y": 34.3, "z": 9.8, "model": "aqua/lamp"})
    for i in range(0,3):
        tank.push({"x": 11, "y": 25.5 + i * 3, "z": 10, "model": "aqua/rail", "angle": 90})
        tank.push({"x": 29, "y": 25.5 + i * 3, "z": 10, "model": "aqua/rail", "angle": 90})
    for part in tank:
        part.x = 20+(part.x-20)*tank_scale
        part.y = 30+(part.y-30)*tank_scale
        part.z = 2+(part.z-2)*tank_scale
        part.scale = tank_scale

action start:
    status = "playing"
    call update_labels

action build_fish:
    save_revision += 1
    residents_dirty = true
    for pellet in food:
        pellet.owner = -1
        pellet.chewing = false
    fish = []
    for i in range(0,progress.fish):
        if i>=progress.buddies.length:
            progress.buddies.push(
                {
                    "name": friend_names[i % 8] + (i >= 8 ? " " + (floor(i / 8) + 1): ""),
                    "age": 0,
                    "kind": i % 8,
                    "hunger": 0,
                    "lifespan": 2700 + (i % 4) * 900,
                    "dead": false,
                    "death_age": 0,
                    "death_z": 6,
                    "bites": 0,
                    "cause": ""
                }
            )
        local buddy = progress.buddies[i]
        buddy.kind = buddy.lifespan ? buddy.kind : i%8
        buddy.hunger = buddy.hunger ? clamp(buddy.hunger,0,900) : 0
        buddy.lifespan = buddy.lifespan ? buddy.lifespan : 2700+(buddy.kind%4)*900
        call prepare_fish_upgrades buddy
        buddy.dead = buddy.dead ? true : false
        buddy.death_age = buddy.death_age ? buddy.death_age : 0
        buddy.death_z = buddy.death_z ? buddy.death_z : 6
        buddy.bites = buddy.bites ? buddy.bites : 0
        buddy.cause = buddy.cause ? buddy.cause : ""
        local care_id = buddy.care ? buddy.care.id : "fish-"+progress.next_id
        if !buddy.care:
            progress.next_id += 1
        call care.restore buddy, care_id, 900
        local a = ticks*(0.65+(i%4)*0.14)+i*137
        fish.push(
            {
                "x": 20 + sin(a) * 6.8 * tank_scale,
                "y": 30 + (-1.5 + (i % 4) * 1.25) * tank_scale,
                "z": 2 + (2 + (i % 3) * 1.65) * tank_scale,
                "angle": 0,
                "model": species[buddy.kind],
                "phase": i * 137,
                "speed": 0.65 + (i % 4) * 0.14,
                "lane": 28.5 + (i % 4) * 1.25,
                "height": 4 + (i % 3) * 1.65,
                "scale": 0.9 + (i % 3) * 0.12,
                "base_scale": 0.9 + (i % 3) * 0.12,
                "target": -1,
                "carrion": -1,
                "carrion_ticks": 0,
                "snacking": false,
                "munch_ticks": 0,
                "munch_duration": 0,
                "snack_wait": 24 + (i * 29) % 90,
                "swim_speed": 0.035 + (i % 4) * 0.009
            }
        )
    call build_fish_style

action build_reef:
    reef = [
        {"x": 13.5, "y": 32.4, "z": 2, "model": "aqua/kelp", "scale": 1.25},
        {"x": 26.5, "y": 32.7, "z": 2, "model": "aqua/kelp", "scale": 1.5},
        {"x": 14.2, "y": 31.2, "z": 2, "model": "aqua/coral"},
        {"x": 25.5, "y": 32.2, "z": 2, "model": "aqua/coral", "scale": 1.2},
        {"x": 13, "y": 30.5, "z": 2, "model": "aqua/rock"},
        {"x": 26.7, "y": 31.5, "z": 2, "model": "aqua/rock", "scale": 1.2},
        {"x": 17.2, "y": 28.7, "z": 2, "model": "aqua/anemone"},
        {"x": 21.8, "y": 32.8, "z": 2, "model": "aqua/kelp", "scale": 0.7}
    ]
    for i in range(0,progress.reef):
        reef.push(
            {
                "x": 15 + i * 2.35,
                "y": 29.7 + (i % 2) * 2,
                "z": 2,
                "model": i % 2 == 0 ? "aqua/coral": "aqua/anemone",
                "scale": 1.25 + i * 0.1
            }
        )
    for plant in reef:
        plant.x = 20+(plant.x-20)*tank_scale
        plant.y = 30+(plant.y-30)*tank_scale
        plant.scale = (plant.scale ? plant.scale : 1)*tank_scale
    call build_obstacles

action set_lights:
    lights = [
        {
            "x": 15,
            "y": 29,
            "z": 6,
            "color": light_colors[progress.palette],
            "radius": 10,
            "intensity": 0.3
        },
        {
            "x": 25,
            "y": 30,
            "z": 7,
            "color": light_colors[(progress.palette + 1) % 3],
            "radius": 10,
            "intensity": 0.35
        },
        {"x": 20, "y": 32, "z": 9, "color": "#5af5b0", "radius": 11, "intensity": 0.22},
        {"x": 24, "y": 28, "z": 3.4, "color": "#ffe076", "radius": 4, "intensity": 0.35}
    ]
    for light in lights:
        light.x = 20+(light.x-20)*tank_scale
        light.y = 30+(light.y-30)*tank_scale
        light.z = 2+(light.z-2)*tank_scale
        light.radius *= tank_scale

action tick(input):
    ticks += 1
    net_ticks = max(0,net_ticks-1)
    fed_ticks = max(0,fed_ticks-1)
    feed_cooldown = max(0,feed_cooldown-1)
    treasure_ticks = min(600,treasure_ticks+1)
    party = ticks%1800 >= 1350
    local turn = (input.right ? 1 : 0)-(input.left ? 1 : 0)
    orbit_target += turn*0.5
    orbit += (orbit_target-orbit)*0.22
    if abs(orbit_target-orbit)<0.01:
        orbit = orbit_target
    if ticks%30 == 0:
        save_revision += 1
        call update_life
        call update_critter_life
        call count_living
        income = alive_count*(1+progress.reef)*(fed_ticks>0 ? 2 : 1)*(party ? 3 : 1)/2
        local total_income = income+progress.income_remainder/2
        local payment = floor(total_income)
        progress.income_remainder = (total_income-payment)*2
        call award_pearls payment
        progress.earned += payment
    call update_feeding
    call update_carrion
    call move_critters
    call eat_critter_food
    if cleanup_index>=0:
        call remove_fish cleanup_index
    call animate
    if ticks%15 == 0:
        if label_second!=floor(ticks/30) || label_revision!=save_revision || label_eaten!=eaten || label_feed!=ceil(feed_cooldown/30) || label_treasure!=ceil((600-treasure_ticks)/30) || label_fed!=(fed_ticks>0):
            call update_labels

action count_living:
    alive_count = 0
    dead_count = 0
    hungry_count = 0
    for buddy in progress.buddies:
        if buddy.dead:
            dead_count += 1
        if !buddy.dead:
            alive_count += 1
            if buddy.hunger>=420:
                hungry_count += 1

action update_life:
    for buddy, index in progress.buddies:
        if buddy.dead:
            buddy.death_age += 1
        if !buddy.dead:
            call care.advance buddy
            if buddy.dead:
                buddy.death_age = 0
                buddy.death_z = fish[index].z
                local dying = fish[index]
                dying.snacking = false
                dying.carrion = -1
                if dying.target>=0:
                    local pellet = food[dying.target]
                    pellet.owner = -1
                    pellet.chewing = false
                dying.target = -1
                dying.munch_ticks = 0
                keyboard_open = false
                if selected_fish==index && shop=="fish":
                    shop = ""
                notice = buddy.name+" has passed on. Tap the floating fish to retrieve with your net."

action animate:
    if camera.angle!=90+orbit || camera.z!=12.75 || camera.x!=20+sin(orbit)*27 || camera.y!=30-cos(orbit)*27:
        camera.x = 20+sin(orbit)*27
        camera.y = 30-cos(orbit)*27
        camera.z = 12.75
        camera.angle = 90+orbit
    for net in nets:
        net.visible = net_ticks>0
    for f, index in fish:
        local buddy = progress.buddies[index]
        local a = ticks*f.speed+f.phase
        if buddy.dead:
            f.model = buddy.death_age>=120 ? "aqua/decay" : "aqua/dead"
            local surface = 2+8*tank_scale
            f.z = buddy.death_age<120 ? min(surface,buddy.death_z+buddy.death_age*0.12) : max(2.35,surface-(buddy.death_age-120)*0.045)
            f.angle = sin(a*0.15)*12
            f.scale = f.base_scale*(1-buddy.bites/8)
        if !buddy.dead && !f.snacking:
            local next_x = 20+sin(a)*6.8*tank_scale
            local next_y = 30+(f.lane-30+cos(a)*0.5)*tank_scale
            local next_z = 2+(f.height-2+sin(a*1.7)*0.32)*tank_scale
            f.x += clamp(next_x-f.x,-0.1,0.1)
            f.y += clamp(next_y-f.y,-0.08,0.08)
            f.z += clamp(next_z-f.z,-0.08,0.08)
            f.angle = cos(a)>=0 ? 0 : 180
    call animate_feet
    call animate_fish_style
    if residents_dirty:
        residents = []
        for f in fish:
            residents.push(f)
        for crab in crabs:
            residents.push(crab)
        for piece in fish_style:
            residents.push(piece)
        residents_dirty = false
    for bubble in bubbles:
        bubble.z = 2+(((ticks*0.035+bubble.phase*0.04)%7.3)+0.2)*tank_scale
        bubble.x = 20+(-7+(bubble.phase/47%3)*7+sin(ticks*1.2+bubble.phase)*0.22)*tank_scale
        bubble.y = 30+(1.5+(bubble.phase/47%2))*tank_scale
    visitor[0].visible = progress.reef>=3
    visitor[0].x = 20+sin(ticks*0.35)*4*tank_scale
    visitor[0].y = 30+1.7*tank_scale
    visitor[0].z = 2+(5.7+sin(ticks*0.8)*0.45)*tank_scale
    for gift in treasure:
        gift.x = 20+4*tank_scale
        gift.y = 30-1.6*tank_scale
        gift.scale = tank_scale
    treasure[1].visible = treasure_ticks>=600
    treasure[1].z = 2+(1.35+sin(ticks*2)*0.18)*tank_scale
    lights[0].intensity = 0.26+sin(ticks*0.7)*0.06
    lights[1].intensity = 0.29+sin(ticks*0.7+120)*0.06
    lights[2].intensity = party ? 0.4 : 0.22
    lights[3].intensity = treasure_ticks>=600 ? 0.35 : 0.08
    if party:
        lights[2].color = light_colors[floor(ticks/150)%3]
    if !party:
        lights[2].color = "#5af5b0"

action update_feeding:
    for pellet in food:
        if pellet.visible:
            pellet.age += 1
            if !pellet.chewing:
                pellet.z = max(2.35,pellet.z-pellet.sink_speed)
                pellet.x = pellet.home_x+sin(pellet.age*(0.6+pellet.kind*0.25)+pellet.phase)*0.24
                pellet.y = pellet.home_y+sin(pellet.age*0.7+pellet.phase)*0.16
            if pellet.age>=feeding_duration || fed_ticks==0:
                pellet.visible = false
                pellet.owner = -1
                pellet.chewing = false
    for f, index in fish:
        f.snacking = false
        f.scale = f.base_scale
        f.snack_wait = max(0,f.snack_wait-1)
        if f.target>=0 && !food[f.target].visible:
            f.target = -1
            f.munch_ticks = 0
        if !progress.buddies[index].dead && f.carrion<0 && f.target<0 && f.snack_wait==0:
            local nearest = 10000
            for pellet, pi in food:
                if pellet.visible && pellet.owner<0:
                    local distance = (pellet.x-f.x)*(pellet.x-f.x)+(pellet.y-f.y)*(pellet.y-f.y)+(pellet.z-f.z)*(pellet.z-f.z)
                    if distance<nearest:
                        nearest = distance
                        f.target = pi
            if f.target>=0:
                food[f.target].owner = index
                f.munch_ticks = 0
                f.munch_duration = 48+(index%4)*18+food[f.target].kind*12
        if f.target>=0:
            local pellet = food[f.target]
            local dx = pellet.x-f.x
            local dy = pellet.y-f.y
            local dz = pellet.z-f.z
            local distance = sqrt(dx*dx+dy*dy+dz*dz)
            f.snacking = true
            if f.munch_ticks==0:
                f.angle = dx>=0 ? 0 : 180
            if distance>0.65 && f.munch_ticks==0:
                local step = min(f.swim_speed,distance)
                f.x += dx/distance*step
                f.y += dy/distance*step
                f.z += dz/distance*step
            if distance<=0.65 || f.munch_ticks>0:
                pellet.chewing = true
                f.munch_ticks += 1
                local facing = f.angle==0 ? 1 : -1
                f.x += clamp(pellet.x-facing*0.48*f.base_scale-f.x,-0.025,0.025)
                f.y += clamp(pellet.y-f.y,-0.025,0.025)
                f.z += clamp(pellet.z+sin(f.munch_ticks*15)*0.045-f.z,-0.025,0.025)
                f.scale = f.base_scale*(1+sin(f.munch_ticks*18)*0.035)
                pellet.scale = pellet.base_scale*(1-0.65*f.munch_ticks/f.munch_duration)
                if f.munch_ticks>=f.munch_duration:
                    pellet.visible = false
                    pellet.owner = -1
                    pellet.chewing = false
                    f.target = -1
                    f.munch_ticks = 0
                    f.snack_wait = 60+(index*37+ticks)%120
                    eaten += 1
                    save_revision += 1
                    call award_pearls 2
                    progress.earned += 2
                    call care.nourish progress.buddies[index], 300

action update_carrion:
    cleanup_index = -1
    for f, index in fish:
        local buddy = progress.buddies[index]
        if !buddy.dead && f.target<0:
            if f.carrion>=0 && (!progress.buddies[f.carrion].dead || progress.buddies[f.carrion].bites>=6):
                f.carrion = -1
                f.carrion_ticks = 0
            if dead_count>0 && f.carrion<0 && buddy.hunger>=120 && f.snack_wait==0:
                local nearest = 10000
                for corpse, ci in fish:
                    if progress.buddies[ci].dead && progress.buddies[ci].death_age>=120 && progress.buddies[ci].bites<6:
                        local distance = (corpse.x-f.x)*(corpse.x-f.x)+(corpse.y-f.y)*(corpse.y-f.y)+(corpse.z-f.z)*(corpse.z-f.z)
                        if distance<nearest:
                            nearest = distance
                            f.carrion = ci
            if f.carrion>=0:
                local corpse = fish[f.carrion]
                local dx = corpse.x-f.x
                local dy = corpse.y-f.y
                local dz = corpse.z-f.z
                local distance = sqrt(dx*dx+dy*dy+dz*dz)
                f.snacking = true
                f.angle = dx>=0 ? 0 : 180
                if distance>0.7:
                    local step = min(f.swim_speed,distance)
                    f.x += dx/distance*step
                    f.y += dy/distance*step
                    f.z += dz/distance*step
                    f.carrion_ticks = 0
                if distance<=0.7:
                    f.carrion_ticks += 1
                    f.scale = f.base_scale*(1+sin(f.carrion_ticks*18)*0.035)
                    if f.carrion_ticks>=90+(index%3)*15:
                        progress.buddies[f.carrion].bites += 1
                        save_revision += 1
                        call care.nourish buddy, 180
                        f.carrion = -1
                        f.carrion_ticks = 0
                        f.snack_wait = 90
    for buddy, index in progress.buddies:
        if buddy.dead && buddy.bites>=6 && cleanup_index<0:
            cleanup_index = index

action remove_fish(index):
    surviving_buddies = []
    for buddy, bi in progress.buddies:
        if bi!=index:
            surviving_buddies.push(buddy)
    progress.buddies = surviving_buddies
    progress.fish = progress.buddies.length
    profile_open = false
    keyboard_open = false
    selected_fish = -1
    if shop=="fish":
        shop = ""
    call build_fish
    call animate
    call update_labels

action feed:
    menu_open = false
    if feed_cooldown>0:
        notice = "Snack time is recharging. Check hunger in each fish's profile."
        call update_labels
        stop when true
    call count_living
    call count_critters
    feed_cost = max(1,alive_count+progress.critters.length-critter_dead_count)
    if progress.pearls<feed_cost:
        notice = "Snack time costs "+feed_cost+" pearls, one per living friend. Save a few more pearls."
        call update_labels
        stop when true
    progress.pearls -= feed_cost
    save_revision += 1
    feeding_duration = 900+progress.food_level*300
    fed_ticks = feeding_duration
    feed_cooldown = feeding_duration+300
    call scatter_critter_food
    eaten = 0
    food = []
    for f, index in fish:
        f.target = -1
        f.carrion = -1
        f.carrion_ticks = 0
        f.munch_ticks = 0
        f.snack_wait = 24+(index*29+ticks)%90
    for i in range(0,max(18,progress.fish)):
        local phase = i*137.5+ticks*0.7
        local x = 20+sin(phase)*6.2*tank_scale
        local y = 30+cos(phase*1.7)*2.4*tank_scale
        local size = 1.3+(i%3)*0.3
        food.push(
            {
                "x": x,
                "y": y,
                "home_x": x,
                "home_y": y,
                "z": 2 + (6.5 + (i % 4) * 0.2) * tank_scale,
                "model": food_models[i % 3],
                "visible": true,
                "owner": -1,
                "age": 0,
                "phase": phase,
                "kind": i % 3,
                "sink_speed": 0.004 + (i % 3) * 0.002,
                "scale": size,
                "base_scale": size,
                "chewing": false
            }
        )
    notice = "Snack shower / "+feed_cost+" pearls! Fish nibble slowly. +2 pearls per finished snack."
    call update_labels

action buy_fish:
    menu_open = false
    call update_labels
    if fish_full:
        notice = progress.tank<2 ? "Full house! Expand the tank for six more friends." : "All 30 swimming buddies are home!"
        call update_labels
        stop when true
    if progress.pearls<fish_cost:
        notice = "Keep relaxing! Your fish are earning the next adoption."
        call update_labels
        stop when true
    progress.pearls -= fish_cost
    progress.fish += 1
    call build_fish
    notice = "New friend adopted! More fins, more pearls."
    call animate
    call update_labels

action grow_tank:
    menu_open = false
    call update_labels
    if tank_locked:
        notice = progress.tank>=2 ? "Your grand lagoon is fully expanded!" : "Save a few more pearls to expand your lagoon."
        call update_labels
        stop when true
    progress.pearls -= tank_cost
    save_revision += 1
    progress.tank += 1
    tank_capacity = 18+progress.tank*6
    tank_scale = 0.75+progress.tank*0.25
    call build_tank
    call build_reef
    call build_garden
    call set_lights
    for crab in crabs:
        crab.x = 20+(crab.x-20)/(tank_scale-0.25)*tank_scale
        crab.y = 30+(crab.y-30)/(tank_scale-0.25)*tank_scale
    call build_obstacles
    call clear_critter_paths
    notice = "Bigger ocean, bigger dreams! Six new fish spaces and more room to swim."
    call animate
    call update_labels

action toggle_menu:
    shop = ""
    profile_open = false
    keyboard_open = false
    menu_open = !menu_open
    call update_labels
    if menu_open:
        call menu_move 0

action close_menu:
    menu_open = false
    call update_labels

action menu_move(direction):
    stop when !menu_open
    menu_index = (menu_index+direction+10)%10
    for i in range(0,10):
        stop when !ui.grid.items[menu_index].disabled
        menu_index = (menu_index+(direction<0 ? 9 : 1))%10
    call update_labels

action grow_reef:
    menu_open = false
    call update_labels
    if reef_full:
        notice = "Your rainbow reef is fully grown. Absolutely fin-tastic!"
        call update_labels
        stop when true
    if progress.pearls<reef_cost:
        notice = "The reef needs a few more pearls. No rush!"
        call update_labels
        stop when true
    progress.pearls -= reef_cost
    save_revision += 1
    progress.reef += 1
    call build_reef
    call clear_critter_paths
    notice = progress.reef==3 ? "A moon jelly moved in! Your reef has a glowing VIP." : "Reef upgraded! Every fish earns one extra pearl per second."
    call animate
    call update_labels

action collect_treasure:
    menu_open = false
    if treasure_ticks<600:
        notice = "The oyster is making another gift. Check back in a moment!"
        call update_labels
        stop when true
    local reward = 25+progress.fish*5
    call award_pearls reward
    save_revision += 1
    progress.earned += reward
    treasure_ticks = 0
    treasure[1].visible = false
    notice = "Oyster treasure! +"+reward+" pearls. Another gift in 20 seconds."
    call update_labels

action cycle_lights:
    menu_open = false
    progress.palette = (progress.palette+1)%3
    save_revision += 1
    call set_lights
    notice = "Lighting changed. Same happy fish, brand-new mood."
    call update_labels

action orbit_view(direction):
    menu_open = false
    orbit_target += direction*15
    call update_labels

action drag_orbit(degrees):
    stop when menu_open || keyboard_open || shop!="" || reset_open
    orbit_target += degrees

action next_view:
    menu_open = false
    orbit_target += 90
    call update_labels

action inspect_fish(index):
    stop when reset_open || shop!=""
    if index<0 || index>=fish.length || floor(index)!=index:
        notice = "That fish is no longer in this lagoon."
        call update_labels
        stop when true
    if progress.buddies[index].dead:
        nets = [
            {
                "x": fish[index].x,
                "y": fish[index].y,
                "z": fish[index].z,
                "model": "aqua/net",
                "visible": true
            }
        ]
        net_ticks = 30
        notice = progress.buddies[index].name+" retrieved with the net. A space is ready for a new friend."
        call remove_fish index
        stop when true
    selected_fish = index
    selected_critter = -1
    profile_open = true
    keyboard_open = false
    menu_open = false
    name_error = ""
    call update_labels

action close_profile:
    profile_open = false
    keyboard_open = false
    name_error = ""
    call update_labels

action retrieve_selected:
    stop when !profile_open
    if selected_critter>=0:
        call inspect_critter selected_critter
        stop when true
    stop when selected_fish<0
    call inspect_fish selected_fish

action rename_fish(fields):
    stop when !profile_open
    name_draft = fields.name ? fields.name : ""
    for i in range(0,name_draft.length):
        stop when !" \t\r\n".includes(name_draft.slice(0,1))
        name_draft = name_draft.slice(1)
    for i in range(0,name_draft.length):
        stop when !" \t\r\n".includes(name_draft.slice(name_draft.length-1))
        name_draft = name_draft.slice(0,name_draft.length-1)
    if name_draft.length==0 || name_draft.length>24:
        name_error = "Choose a name from 1 to 24 characters."
        call update_labels
        stop when true
    if selected_critter>=0:
        progress.critters[selected_critter].name = name_draft
    if selected_critter<0:
        progress.buddies[selected_fish].name = name_draft
    name_error = ""
    notice = "Meet "+name_draft+"! Your friend's name is saved."
    save_revision += 1
    keyboard_open = false
    call update_labels

action open_name_keyboard:
    stop when !profile_open
    local buddy = selected_critter>=0 ? progress.critters[selected_critter] : progress.buddies[selected_fish]
    stop when buddy.dead
    keyboard_open = true
    name_draft = buddy.name
    name_error = ""
    call update_labels

action cancel_name_keyboard:
    keyboard_open = false
    name_error = ""
    call update_labels

action request_reset:
    shop = ""
    menu_open = false
    profile_open = false
    keyboard_open = false
    reset_open = true
    call update_labels

action cancel_reset:
    reset_open = false
    call update_labels

action reset_tank:
    stop when !reset_open
    progress = {
        "pearls": 30,
        "fish": 3,
        "reef": 0,
        "earned": 0,
        "income_remainder": 0,
        "food_level": 0,
        "life_level": 0,
        "palette": 0,
        "tank": 0,
        "next_id": 1,
        "florals": [{"kind": 0, "slot": -1}],
        "critters": [{"kind": 0}],
        "buddies": []
    }
    call initialize
    notice = "A fresh lagoon! Three new fish, one crab and 30 pearls."
    call update_labels

action update_labels:
    label_second = floor(ticks/30)
    label_revision = save_revision
    label_eaten = eaten
    label_feed = ceil(feed_cooldown/30)
    label_treasure = ceil((600-treasure_ticks)/30)
    label_fed = fed_ticks>0
    call count_living
    call count_critters
    profile_hidden = !profile_open
    quick_hidden = menu_open || profile_open || reset_open || shop!=""
    if profile_open:
        local buddy = selected_critter>=0 ? progress.critters[selected_critter] : progress.buddies[selected_fish]
        profile_name = buddy.name
        profile_species = selected_critter>=0 ? critter_names[buddy.kind] : species_names[buddy.kind]
        profile_age = buddy.age<60 ? buddy.age+" seconds" : buddy.age<3600 ? floor(buddy.age/60)+" minutes" : buddy.age<86400 ? floor(buddy.age/3600)+" hours" : floor(buddy.age/86400)+" days"
    fish_cost = 18+progress.fish*progress.fish*3
    reef_cost = 30*(progress.reef+1)*(progress.reef+1)
    tank_cost = 600*(progress.tank+1)*(progress.tank+1)
    tank_locked = progress.tank>=2 || progress.pearls<tank_cost
    tank_label = progress.tank>=2 ? "Grand lagoon complete" : "Expand tank / "+tank_cost+" pearls"
    income = alive_count*(1+progress.reef)*(fed_ticks>0 ? 2 : 1)*(party ? 3 : 1)/2
    fish_full = progress.fish>=tank_capacity
    reef_full = progress.reef>=5
    fish_locked = fish_full || progress.pearls<fish_cost
    reef_locked = reef_full || progress.pearls<reef_cost
    feed_cost = max(1,alive_count+progress.critters.length-critter_dead_count)
    feed_locked = feed_cooldown>0 || progress.pearls<feed_cost
    treasure_locked = treasure_ticks<600
    pearl_label = progress.pearls+" / 100000 pearls"
    income_label = "+"+income+" pearls / sec"
    fish_label = fish_full ? "Tank full / "+tank_capacity+" friends" : "Adopt a fish / "+fish_cost+" pearls"
    reef_label = reef_full ? "Rainbow reef complete" : "Grow reef / "+reef_cost+" pearls"
    feed_label = feed_cooldown>0 ? "Snacks ready in "+ceil(feed_cooldown/30)+"s" : "Feed fish and critters / "+feed_cost+" pearls"
    treasure_label = treasure_locked ? "Oyster gift in "+ceil((600-treasure_ticks)/30)+"s" : "Collect oyster / +"+(25+progress.fish*5)
    lighting_label = light_names[progress.palette]+" / L"
    collection_label = alive_count+" living / "+dead_count+" to net / "+progress.fish+"/"+tank_capacity+" spaces / Reef "+progress.reef+"/5"
    snack_label = eaten+" snacks eaten / +"+(eaten*2)+" bite pearls"
    event_label = party ? "GLOW FESTIVAL! Triple pearls until the minute ends." : "Glow festival in "+ceil((1350-ticks%1800)/30)+"s / triple pearls!"
    ui = {
        "style": "floating",
        "meters": [],
        "objective": pearl_label + " / " + income_label,
        "detail": collection_label,
        "prompt": party ? "GLOW FESTIVAL // 3X PEARLS": "",
        "notice": dead_count > 0 ? dead_count + " fish to retrieve / TAP FISH TO NET": hungry_count > 0 ? hungry_count + " hungry fish / FEED SOON": fed_ticks > 0 ? snack_label: "",
        "panel": null,
        "theme": {
            "background": 860723,
            "surface": 1587530,
            "selected": 2512741,
            "border": 3560808,
            "text": 15858679,
            "muted": 10665415,
            "accent": 8185036,
            "focus": 12845032,
            "radius": 7
        }
    }
    if !menu_open && !profile_open && !reset_open && shop=="":
        ui.buttons = [
            {
                "icon": "menu",
                "label": "Aquarium menu",
                "anchor": "top-right",
                "action": "toggle_menu",
                "size": 30
            },
            {
                "icon": "sound",
                "label": "Sound / M",
                "anchor": "top-right",
                "offset": 38,
                "action": "host.mute",
                "size": 30
            },
            {
                "icon": "feed",
                "label": "Feed fish and critters",
                "anchor": "bottom-left",
                "action": "feed",
                "disabled": feed_locked,
                "size": 30
            },
            {
                "icon": "fish",
                "label": "Adopt fish",
                "anchor": "bottom-left",
                "offset": 38,
                "action": "buy_fish",
                "disabled": fish_locked,
                "size": 30
            },
            {
                "icon": "flower",
                "label": "Floral decorations",
                "anchor": "bottom-left",
                "offset": 76,
                "action": "open_flower_shop",
                "size": 30
            },
            {
                "icon": "critter",
                "label": "Bottom critters",
                "anchor": "bottom-left",
                "offset": 114,
                "action": "open_critter_shop",
                "size": 30
            }
        ]
    if profile_open:
        local buddy = selected_critter>=0 ? progress.critters[selected_critter] : progress.buddies[selected_fish]
        local full = selected_critter>=0 ? 1200 : 600
        ui.callout = {
            "title": profile_name,
            "target": selected_critter >= 0 ? crabs[selected_critter]: fish[selected_fish],
            "width": 238,
            "dismissAction": "close_profile",
            "lines": [
                profile_species,
                "AGE " + profile_age + " / LIFE " + floor(buddy.lifespan / 60) + "m",
                "HUNGER " + floor(min(full, buddy.hunger) * 100 / full) + "% / " + (buddy.dead ? buddy.cause + " / TAP TO NET": buddy.hunger >= full ? "STARVING " + ceil((full * 1.5 - buddy.hunger) / 60) + "m LEFT": buddy.hunger >= full * 0.7 ? "HUNGRY": "CONTENT"),
                name_error ? name_error: selected_critter >= 0 ? "Tank care upgrades in the menu": buddy.style ? "Style Kit / " + pattern_names[buddy.pattern]: "Style Kit available / 120 pearls"
            ],
            "actions": buddy.dead ? [
                {"label": "NET FRIEND", "action": "retrieve_selected"},
                {"label": "CLOSE", "action": "close_profile"}
            ]: selected_critter >= 0 ? [{"label": "RENAME", "action": "open_name_keyboard"}, {"label": "FEED", "action": "feed"}, {"label": "CLOSE", "action": "close_profile"}]: [{"label": "RENAME", "action": "open_name_keyboard"}, {"label": "UPGRADES", "action": "open_fish_upgrades"}, {"label": "CLOSE", "action": "close_profile"}]
        }
    if reset_open:
        ui.callout = {
            "title": "Reset your lagoon?",
            "target": {"x": 20, "y": 30, "z": 2},
            "width": 278,
            "dismissAction": "cancel_reset",
            "lines": [
                "Erase pearls, fish and all upgrades.",
                "Start with three fish and one crab.",
                "Your saved tank will be replaced.",
                "This cannot be undone."
            ],
            "actions": [
                {"label": "RESET TANK", "action": "reset_tank"},
                {"label": "CANCEL", "action": "cancel_reset"}
            ]
        }
    if keyboard_open:
        ui.keyboard = {
            "title": "Name your little friend",
            "value": name_draft,
            "maxLength": 24,
            "submitAction": "rename_fish",
            "cancelAction": "cancel_name_keyboard",
            "width": 480,
            "keyHeight": 28,
            "gap": 4,
            "textScale": 2
        }
    if menu_open:
        ui.grid = {
            "layout": "sidebar",
            "columns": 1,
            "title": "Your lagoon",
            "subtitle": pearl_label + "  /  " + income_label,
            "footer": "UP/DOWN SELECT  /  OK ENTER  /  TAP AWAY CLOSE",
            "dismissAction": "close_menu",
            "moveAction": "menu_move",
            "closeOnActivate": true,
            "width": 302,
            "rowHeight": 28,
            "gap": 2,
            "padding": 10,
            "textScale": 2,
            "items": [
                {
                    "label": "Snack time",
                    "sub": feed_cooldown > 0 ? "Ready in " + ceil(feed_cooldown / 30) + "s  /  Check fish hunger": feed_cost + " pearls  /  One per living friend",
                    "action": "feed",
                    "disabled": feed_locked,
                    "selected": menu_index == 0
                },
                {
                    "label": "Invite a friend",
                    "sub": fish_full ? "All spaces filled  /  " + tank_capacity + " friends": fish_cost + " pearls  /  " + progress.fish + " of " + tank_capacity + " friends",
                    "action": "buy_fish",
                    "disabled": fish_locked,
                    "selected": menu_index == 1
                },
                {
                    "label": "Plant a rainbow",
                    "sub": reef_full ? "Your rainbow reef is complete": reef_cost + " pearls  /  Reef " + progress.reef + " of 5",
                    "action": "grow_reef",
                    "disabled": reef_locked,
                    "selected": menu_index == 2
                },
                {
                    "label": "A bigger ocean",
                    "sub": progress.tank >= 2 ? "Grand lagoon  /  Fully expanded": tank_cost + " pearls  /  Room for six more friends",
                    "action": "grow_tank",
                    "disabled": tank_locked,
                    "selected": menu_index == 3
                },
                {
                    "label": "Oyster surprise",
                    "sub": treasure_locked ? "Your next gift in " + ceil((600 - treasure_ticks) / 30) + "s": "Collect " + (25 + progress.fish * 5) + " pearls  /  A little gift for you",
                    "action": "collect_treasure",
                    "disabled": treasure_locked,
                    "selected": menu_index == 4
                },
                {
                    "label": "Set the mood",
                    "sub": light_names[progress.palette] + "  /  Change lighting",
                    "action": "cycle_lights",
                    "selected": menu_index == 5
                },
                {
                    "label": "A fresh perspective",
                    "sub": "Take a slow look around your reef",
                    "action": "next_view",
                    "selected": menu_index == 6
                },
                {
                    "label": "Fullscreen",
                    "sub": "Let your little ocean fill the room",
                    "action": "host.fullscreen",
                    "selected": menu_index == 7
                },
                {
                    "label": "Reset tank",
                    "sub": "Start fresh  /  Confirmation required",
                    "action": "request_reset",
                    "selected": menu_index == 8
                },
                {
                    "label": "Tank care upgrades",
                    "sub": "Long-lasting food and longevity / 3 levels",
                    "action": "open_care_upgrades",
                    "selected": menu_index == 9
                }
            ]
        }
    if shop!="":
        call shop_labels
    if critter_dead_count>0 && !menu_open && shop=="":
        ui.notice = critter_dead_count+" critters to retrieve / TAP TO NET"
    if critter_hungry_count>0 && dead_count==0 && critter_dead_count==0 && !menu_open && shop=="":
        ui.notice = critter_hungry_count+" hungry critters / FEED SOON"
models.rune
@Palette/aqua
colors = {
    "n":"#102a4b", "d":"#124c68", "b":"#167eab", "c":"#39e9ee",
    "w":"#eeffed", "s":"#c89e70", "g":"#ffe076", "o":"#ff9348",
    "p":"#ff5db5", "v":"#a77cff", "r":"#ff557c", "l":"#6cf3aa",
    "k":"#102039", "t":"#286e7d"
}

@Texture/aqua/sand
palette = aqua
size = [8,8]
pixels:
    {"runs":"s*8","repeat":8}

@Model/aqua/tank
palette = aqua
unit = 0.5
blocks:
    {"from":[-18,-9,-2],"size":[18,18,1],"color":"n"}
    {"from":[0,-9,-2],"size":[18,18,1],"color":"n"}
    {"from":[-18,-9,-1],"size":[18,18,1],"color":"s"}
    {"from":[0,-9,-1],"size":[18,18,1],"color":"s"}
    {"from":[-18,-9,0],"size":[1,1,16],"color":"n"}
    {"from":[17,-9,0],"size":[1,1,16],"color":"n"}
    {"from":[-18,8,0],"size":[1,1,16],"color":"n"}
    {"from":[17,8,0],"size":[1,1,16],"color":"n"}
    {"from":[-18,-9,0],"size":[18,1,1],"color":"g"}
    {"from":[0,-9,0],"size":[18,1,1],"color":"g"}

@Model/aqua/glass-wide
palette = aqua
unit = 1
glass = [8,18]
shapes:
    {"type":"sphere","center":[4,0,0],"radius":0.06,"color":"c"}

@Model/aqua/glass-side
palette = aqua
unit = 1
glass = [8,9]
shapes:
    {"type":"sphere","center":[4,0,0],"radius":0.06,"color":"c"}

@Model/aqua/rail
palette = aqua
unit = 0.125
blocks:
    {"from":[0,0,0],"size":[24,1,1],"color":"c"}

@Model/aqua/lamp
palette = aqua
unit = 1
emissive = "c"
shapes:
    {"type":"sphere","center":[0,0,0],"radius":0.12,"color":"c"}

@Model/aqua/coral
palette = aqua
unit = 0.125
contact_shadow = 0.7
blocks:
    {"from":[-1,-1,0],"size":[3,3,15],"color":"r"}
    {"from":[-7,-1,7],"size":[13,2,2],"color":"r"}
    {"from":[-7,-1,7],"size":[2,2,7],"color":"p"}
    {"from":[4,-1,7],"size":[2,2,11],"color":"p"}
    {"from":[-1,-1,15],"size":[3,3,3],"color":"p"}
shapes:
    {"type":"sphere","center":[0,0,1],"radius":5,"color":"v"}

@Model/aqua/kelp
palette = aqua
unit = 0.125
blocks:
    {"from":[-1,-1,0],"size":[2,2,30],"color":"t"}
    {"from":[-5,-1,5],"size":[5,2,3],"color":"l"}
    {"from":[0,-1,10],"size":[6,2,3],"color":"l"}
    {"from":[-6,-1,17],"size":[6,2,3],"color":"l"}
    {"from":[0,-1,23],"size":[5,2,3],"color":"l"}
    {"from":[-2,-1,29],"size":[3,2,4],"color":"l"}

@Model/aqua/anemone
palette = aqua
unit = 0.05
contact_shadow = 0.6
shapes:
    {"type":"sphere","center":[0,0,4],"radius":13,"color":"b"}
blocks:
    {"from":[-12,-8,6],"size":[4,4,16],"color":"v"}
    {"from":[-2,-8,6],"size":[4,4,24],"color":"c"}
    {"from":[8,-8,6],"size":[4,4,18],"color":"v"}
    {"from":[-7,4,6],"size":[4,4,20],"color":"c"}
    {"from":[4,4,6],"size":[4,4,26],"color":"v"}

@Model/aqua/rock
palette = aqua
unit = 1
shapes:
    {"type":"sphere","center":[0,0,0],"radius":0.8,"color":"t"}
    {"type":"sphere","center":[0.5,0.1,0.2],"radius":0.5,"color":"d"}

@Model/aqua/clown
palette = aqua
unit = 0.1
blocks:
    {"from":[-5,-2,-2],"size":[10,4,5],"color":"o"}
    {"from":[-3,-2,-2],"size":[2,4,5],"color":"w"}
    {"from":[1,-2,-2],"size":[2,4,5],"color":"w"}
    {"from":[-8,-1,-3],"size":[3,2,7],"color":"o"}
    {"from":[-1,-1,3],"size":[4,2,2],"color":"o"}
    {"from":[3,-3,1],"size":[1,1,1],"color":"k"}
    {"from":[3,2,1],"size":[1,1,1],"color":"k"}

@Model/aqua/tang
palette = aqua
unit = 0.1
blocks:
    {"from":[-5,-2,-3],"size":[10,4,7],"color":"b"}
    {"from":[-3,-3,1],"size":[6,6,1],"color":"c"}
    {"from":[-8,-1,-3],"size":[3,2,7],"color":"g"}
    {"from":[-2,-1,4],"size":[5,2,2],"color":"b"}
    {"from":[3,-3,2],"size":[1,1,1],"color":"k"}
    {"from":[3,2,2],"size":[1,1,1],"color":"k"}

@Model/aqua/royal
palette = aqua
unit = 0.1
blocks:
    {"from":[-5,-2,-2],"size":[10,4,5],"color":"v"}
    {"from":[-8,-1,-4],"size":[3,2,9],"color":"p"}
    {"from":[-3,-1,3],"size":[6,2,4],"color":"p"}
    {"from":[-2,-1,-5],"size":[5,2,3],"color":"g"}
    {"from":[3,-3,1],"size":[1,1,1],"color":"k"}
    {"from":[3,2,1],"size":[1,1,1],"color":"k"}

@Model/aqua/puffer
palette = aqua
unit = 0.05
shapes:
    {"type":"sphere","center":[0,0,0],"radius":10,"color":"g"}
blocks:
    {"from":[-16,-2,-4],"size":[8,4,10],"color":"o"}
    {"from":[4,-9,2],"size":[3,3,3],"color":"k"}
    {"from":[4,6,2],"size":[3,3,3],"color":"k"}
    {"from":[-2,-2,9],"size":[4,4,5],"color":"w"}
    {"from":[-2,-2,-13],"size":[4,4,5],"color":"w"}

@Model/aqua/angel
palette = aqua
unit = 0.1
blocks:
    {"from":[-4,-2,-3],"size":[8,4,7],"color":"w"}
    {"from":[-2,-2,-3],"size":[1,4,7],"color":"k"}
    {"from":[1,-2,-3],"size":[1,4,7],"color":"k"}
    {"from":[-2,-1,4],"size":[3,2,8],"color":"g"}
    {"from":[-2,-1,-11],"size":[3,2,8],"color":"g"}
    {"from":[-8,-1,-4],"size":[4,2,9],"color":"w"}
    {"from":[3,-3,1],"size":[1,1,1],"color":"k"}
    {"from":[3,2,1],"size":[1,1,1],"color":"k"}

@Model/aqua/butterfly
palette = aqua
unit = 0.1
blocks:
    {"from":[-4,-2,-4],"size":[8,4,9],"color":"g"}
    {"from":[2,-2,-4],"size":[1,4,9],"color":"k"}
    {"from":[-5,-3,1],"size":[2,1,3],"color":"k"}
    {"from":[-5,2,1],"size":[2,1,3],"color":"k"}
    {"from":[4,-1,-1],"size":[3,2,2],"color":"w"}
    {"from":[-8,-1,-3],"size":[4,2,7],"color":"o"}
    {"from":[-3,-1,5],"size":[5,2,3],"color":"w"}
    {"from":[3,-3,2],"size":[1,1,1],"color":"k"}
    {"from":[3,2,2],"size":[1,1,1],"color":"k"}

@Model/aqua/neon
palette = aqua
unit = 0.08
emissive = "c"
blocks:
    {"from":[-7,-2,-2],"size":[14,4,4],"color":"b"}
    {"from":[-7,-3,1],"size":[14,1,1],"color":"c"}
    {"from":[-7,2,1],"size":[14,1,1],"color":"c"}
    {"from":[-7,-2,-2],"size":[7,4,2],"color":"r"}
    {"from":[-11,-1,-3],"size":[4,2,7],"color":"p"}
    {"from":[5,-3,0],"size":[1,1,1],"color":"k"}
    {"from":[5,2,0],"size":[1,1,1],"color":"k"}

@Model/aqua/lion
palette = aqua
unit = 0.1
blocks:
    {"from":[-5,-2,-2],"size":[10,4,5],"color":"o"}
    {"from":[-4,-2,-2],"size":[1,4,5],"color":"w"}
    {"from":[-1,-2,-2],"size":[1,4,5],"color":"w"}
    {"from":[2,-2,-2],"size":[1,4,5],"color":"w"}
    {"from":[-6,-1,3],"size":[1,2,6],"color":"r"}
    {"from":[-3,-1,3],"size":[1,2,8],"color":"r"}
    {"from":[0,-1,3],"size":[1,2,6],"color":"r"}
    {"from":[-3,-7,-1],"size":[5,5,1],"color":"p"}
    {"from":[-3,2,-1],"size":[5,5,1],"color":"p"}
    {"from":[-9,-1,-4],"size":[4,2,9],"color":"r"}
    {"from":[3,-3,1],"size":[1,1,1],"color":"k"}
    {"from":[3,2,1],"size":[1,1,1],"color":"k"}

@Model/aqua/bubble
palette = aqua
unit = 0.01
emissive = "c"
blocks:
    {"from":[-7,-2,-10],"size":[4,4,20],"color":"c"}
    {"from":[5,-2,-10],"size":[4,4,20],"color":"c"}
    {"from":[-4,-2,8],"size":[10,4,4],"color":"w"}
    {"from":[-4,-2,-10],"size":[10,4,4],"color":"c"}

@Model/aqua/clown-style
palette = aqua
unit = 0.1
shapes:
    {"type":"sphere","center":[-2,0,0],"radius":3,"color":"o"}
    {"type":"sphere","center":[1,0,0],"radius":3.5,"color":"o"}
blocks:
    {"from":[-2,-3,-2],"size":[1,6,5],"color":"w"}
    {"from":[1,-3,-2],"size":[1,6,5],"color":"w"}
    {"from":[2,-4,1],"size":[2,1,2],"color":"w"}
    {"from":[3,-5,1],"size":[1,1,1],"color":"k"}
    {"from":[2,3,1],"size":[2,1,2],"color":"w"}
    {"from":[3,4,1],"size":[1,1,1],"color":"k"}

@Model/aqua/tang-style
palette = aqua
unit = 0.1
shapes:
    {"type":"sphere","center":[0,0,0],"radius":4,"color":"b"}
    {"type":"sphere","center":[2,0,0],"radius":2.5,"color":"b"}
blocks:
    {"from":[-3,-1,4],"size":[5,2,2],"color":"c"}
    {"from":[2,-4,1],"size":[2,1,2],"color":"w"}
    {"from":[3,-5,1],"size":[1,1,1],"color":"k"}
    {"from":[2,3,1],"size":[2,1,2],"color":"w"}
    {"from":[3,4,1],"size":[1,1,1],"color":"k"}

@Model/aqua/royal-style
palette = aqua
unit = 0.1
shapes:
    {"type":"sphere","center":[-2,0,0],"radius":3,"color":"g"}
    {"type":"sphere","center":[1,0,0],"radius":3.5,"color":"v"}
blocks:
    {"from":[-2,-1,3],"size":[5,2,3],"color":"p"}
    {"from":[2,-4,1],"size":[2,1,2],"color":"w"}
    {"from":[3,-5,1],"size":[1,1,1],"color":"k"}
    {"from":[2,3,1],"size":[2,1,2],"color":"w"}
    {"from":[3,4,1],"size":[1,1,1],"color":"k"}

@Model/aqua/puffer-style
palette = aqua
unit = 0.1
shapes:
    {"type":"sphere","center":[0,0,0],"radius":5,"color":"g"}
blocks:
    {"from":[2,-5,1],"size":[2,1,3],"color":"w"}
    {"from":[3,-6,2],"size":[1,1,1],"color":"k"}
    {"from":[2,4,1],"size":[2,1,3],"color":"w"}
    {"from":[3,5,2],"size":[1,1,1],"color":"k"}
    {"from":[-1,-1,5],"size":[2,2,2],"color":"w"}
    {"from":[-1,-1,-7],"size":[2,2,2],"color":"w"}

@Model/aqua/angel-style
palette = aqua
unit = 0.1
shapes:
    {"type":"sphere","center":[0,0,0],"radius":3.5,"color":"w"}
blocks:
    {"from":[-2,-3,-2],"size":[1,6,5],"color":"k"}
    {"from":[-1,-1,3],"size":[2,2,7],"color":"g"}
    {"from":[-1,-1,-9],"size":[2,2,6],"color":"g"}
    {"from":[2,-4,1],"size":[2,1,2],"color":"g"}
    {"from":[3,-5,1],"size":[1,1,1],"color":"k"}
    {"from":[2,3,1],"size":[2,1,2],"color":"g"}
    {"from":[3,4,1],"size":[1,1,1],"color":"k"}

@Model/aqua/butterfly-style
palette = aqua
unit = 0.1
shapes:
    {"type":"sphere","center":[-1,0,0],"radius":4,"color":"g"}
    {"type":"sphere","center":[3,0,0],"radius":2,"color":"w"}
blocks:
    {"from":[-3,-4,1],"size":[2,1,2],"color":"k"}
    {"from":[-3,3,1],"size":[2,1,2],"color":"k"}
    {"from":[3,-3,1],"size":[1,1,1],"color":"k"}
    {"from":[3,2,1],"size":[1,1,1],"color":"k"}
    {"from":[-2,-1,4],"size":[3,2,2],"color":"w"}

@Model/aqua/neon-style
palette = aqua
unit = 0.08
emissive = "c"
shapes:
    {"type":"sphere","center":[-3,0,0],"radius":2.5,"color":"r"}
    {"type":"sphere","center":[0,0,0],"radius":2.5,"color":"b"}
    {"type":"sphere","center":[3,0,0],"radius":2.5,"color":"b"}
blocks:
    {"from":[-5,-3,0],"size":[10,1,1],"color":"c"}
    {"from":[-5,2,0],"size":[10,1,1],"color":"c"}
    {"from":[3,-3,1],"size":[1,1,1],"color":"k"}
    {"from":[3,2,1],"size":[1,1,1],"color":"k"}

@Model/aqua/lion-style
palette = aqua
unit = 0.1
shapes:
    {"type":"sphere","center":[-2,0,0],"radius":3,"color":"r"}
    {"type":"sphere","center":[1,0,0],"radius":3.5,"color":"o"}
blocks:
    {"from":[-2,-3,-2],"size":[1,6,5],"color":"w"}
    {"from":[0,-1,3],"size":[1,2,6],"color":"r"}
    {"from":[-3,-1,3],"size":[1,2,7],"color":"r"}
    {"from":[2,-4,1],"size":[2,1,2],"color":"w"}
    {"from":[3,-5,1],"size":[1,1,1],"color":"k"}
    {"from":[2,3,1],"size":[2,1,2],"color":"w"}
    {"from":[3,4,1],"size":[1,1,1],"color":"k"}

@Model/aqua/style-tail
palette = aqua
unit = 0.1
blocks:
    {"from":[-3,-1,-3],"size":[3,2,7],"color":"g"}
    {"from":[-1,-1,-2],"size":[2,2,5],"color":"o"}

@Model/aqua/style-fin
palette = aqua
unit = 0.1
blocks:
    {"from":[-3,-2,-1],"size":[4,4,1],"color":"c"}

@Model/aqua/candy-stripes
palette = aqua
unit = 0.1
blocks:
    {"from":[-2,-4,-2],"size":[1,8,5],"color":"p"}
    {"from":[0,-4,-2],"size":[1,8,5],"color":"v"}

@Model/aqua/moon-stripes
palette = aqua
unit = 0.1
emissive = "c"
blocks:
    {"from":[-2,-4,-2],"size":[1,8,5],"color":"c"}
    {"from":[0,-4,-2],"size":[1,8,5],"color":"w"}

@Model/aqua/dead
palette = aqua
unit = 0.1
blocks:
    {"from":[-5,-2,-2],"size":[10,4,5],"color":"t"}
    {"from":[-5,-2,2],"size":[10,4,1],"color":"w"}
    {"from":[-8,-1,-3],"size":[3,2,7],"color":"d"}
    {"from":[-1,-1,-4],"size":[4,2,2],"color":"d"}
    {"from":[2,-3,-1],"size":[1,1,1],"color":"k"}
    {"from":[4,-3,-1],"size":[1,1,1],"color":"k"}
    {"from":[3,-3,0],"size":[1,1,1],"color":"k"}
    {"from":[2,-3,1],"size":[1,1,1],"color":"k"}
    {"from":[4,-3,1],"size":[1,1,1],"color":"k"}

@Model/aqua/decay
palette = aqua
unit = 0.1
blocks:
    {"from":[-5,-2,-2],"size":[10,4,5],"color":"t"}
    {"from":[-3,-2,2],"size":[6,4,1],"color":"l"}
    {"from":[-8,-1,-3],"size":[3,2,7],"color":"d"}
    {"from":[3,-3,0],"size":[1,1,1],"color":"k"}

@Model/aqua/crab
palette = aqua
unit = 0.08
contact_shadow = 0.6
blocks:
    {"from":[-4,-3,1],"size":[8,6,4],"color":"o"}
    {"from":[5,-5,2],"size":[4,2,3],"color":"o"}
    {"from":[5,3,2],"size":[4,2,3],"color":"o"}
    {"from":[8,-6,3],"size":[3,4,4],"color":"g"}
    {"from":[8,2,3],"size":[3,4,4],"color":"g"}
    {"from":[2,-2,5],"size":[2,1,3],"color":"w"}
    {"from":[2,1,5],"size":[2,1,3],"color":"w"}
    {"from":[3,-2,7],"size":[1,1,1],"color":"k"}
    {"from":[3,1,7],"size":[1,1,1],"color":"k"}

@Model/aqua/crab_feet
palette = aqua
unit = 0.08
blocks:
    {"from":[-5,-6,0],"size":[2,6,1],"color":"r"}
    {"from":[-1,-7,0],"size":[2,7,1],"color":"r"}
    {"from":[3,-6,0],"size":[2,6,1],"color":"r"}

@Model/aqua/dead_critter
palette = aqua
unit = 0.08
blocks:
    {"from":[-4,-3,0],"size":[8,6,4],"color":"t"}
    {"from":[-3,-3,4],"size":[6,6,1],"color":"w"}
    {"from":[3,-4,1],"size":[1,1,1],"color":"k"}
    {"from":[5,-4,1],"size":[1,1,1],"color":"k"}
    {"from":[4,-4,2],"size":[1,1,1],"color":"k"}
    {"from":[3,-4,3],"size":[1,1,1],"color":"k"}
    {"from":[5,-4,3],"size":[1,1,1],"color":"k"}

@Model/aqua/hermit
palette = aqua
unit = 0.08
contact_shadow = 0.6
blocks:
    {"from":[-4,-3,1],"size":[8,6,4],"color":"o"}
    {"from":[4,-4,2],"size":[5,2,4],"color":"g"}
    {"from":[4,2,2],"size":[5,2,4],"color":"g"}
    {"from":[3,-2,5],"size":[1,1,3],"color":"w"}
    {"from":[3,1,5],"size":[1,1,3],"color":"w"}
    {"from":[3,-2,7],"size":[1,1,1],"color":"k"}
    {"from":[3,1,7],"size":[1,1,1],"color":"k"}
shapes:
    {"type":"sphere","center":[-2,0,6],"radius":5,"color":"v"}
    {"type":"sphere","center":[-3,-3,7],"radius":2,"color":"p"}

@Model/aqua/shrimp
palette = aqua
unit = 0.08
blocks:
    {"from":[-6,-2,2],"size":[12,4,3],"color":"p"}
    {"from":[-6,-1,5],"size":[8,2,2],"color":"r"}
    {"from":[-9,-4,1],"size":[3,8,2],"color":"r"}
    {"from":[5,-2,5],"size":[1,1,2],"color":"k"}
    {"from":[5,1,5],"size":[1,1,2],"color":"k"}
    {"from":[6,-3,5],"size":[6,1,1],"color":"w"}
    {"from":[6,2,5],"size":[6,1,1],"color":"w"}

@Model/aqua/shrimp_feet
palette = aqua
unit = 0.08
blocks:
    {"from":[-4,-4,0],"size":[1,4,2],"color":"p"}
    {"from":[-1,-4,0],"size":[1,4,2],"color":"p"}
    {"from":[2,-4,0],"size":[1,4,2],"color":"p"}
    {"from":[5,-4,0],"size":[1,4,2],"color":"p"}

@Model/aqua/snail
palette = aqua
unit = 0.08
contact_shadow = 0.6
blocks:
    {"from":[-7,-3,0],"size":[14,6,2],"color":"l"}
    {"from":[5,-2,2],"size":[1,1,5],"color":"c"}
    {"from":[5,1,2],"size":[1,1,5],"color":"c"}
    {"from":[5,-2,6],"size":[1,1,1],"color":"k"}
    {"from":[5,1,6],"size":[1,1,1],"color":"k"}
shapes:
    {"type":"sphere","center":[-1,0,5],"radius":5,"color":"v"}
    {"type":"sphere","center":[-1,-3,5],"radius":3,"color":"c"}
    {"type":"sphere","center":[-1,-5,5],"radius":1,"color":"w"}

@Model/aqua/blossom
palette = aqua
unit = 0.1
blocks:
    {"from":[-1,-1,0],"size":[2,2,16],"color":"l"}
    {"from":[-5,-1,5],"size":[5,2,2],"color":"l"}
    {"from":[0,-1,9],"size":[5,2,2],"color":"t"}
shapes:
    {"type":"sphere","center":[-4,0,16],"radius":3,"color":"o"}
    {"type":"sphere","center":[4,0,16],"radius":3,"color":"o"}
    {"type":"sphere","center":[0,0,20],"radius":3,"color":"g"}
    {"type":"sphere","center":[0,0,12],"radius":3,"color":"o"}
    {"type":"sphere","center":[0,-1,16],"radius":2,"color":"g"}

@Model/aqua/fan
palette = aqua
unit = 0.1
blocks:
    {"from":[-1,-1,0],"size":[2,2,22],"color":"v"}
    {"from":[-5,-1,8],"size":[10,2,2],"color":"p"}
    {"from":[-5,-1,8],"size":[2,2,10],"color":"v"}
    {"from":[4,-1,8],"size":[2,2,10],"color":"v"}
    {"from":[-8,-1,13],"size":[16,2,2],"color":"p"}
    {"from":[-8,-1,13],"size":[2,2,7],"color":"v"}
    {"from":[7,-1,13],"size":[2,2,7],"color":"v"}
shapes:
    {"type":"sphere","center":[0,0,22],"radius":2,"color":"c"}
    {"type":"sphere","center":[-5,0,18],"radius":2,"color":"c"}
    {"type":"sphere","center":[5,0,18],"radius":2,"color":"c"}

@Model/aqua/lily
palette = aqua
unit = 0.1
emissive = "c"
blocks:
    {"from":[-1,-1,0],"size":[2,2,12],"color":"t"}
    {"from":[-4,-1,4],"size":[8,2,2],"color":"l"}
shapes:
    {"type":"sphere","center":[-4,0,12],"radius":3,"color":"w"}
    {"type":"sphere","center":[4,0,12],"radius":3,"color":"w"}
    {"type":"sphere","center":[0,-4,12],"radius":3,"color":"w"}
    {"type":"sphere","center":[0,4,12],"radius":3,"color":"w"}
    {"type":"sphere","center":[0,0,14],"radius":2,"color":"c"}

@Model/aqua/net
palette = aqua
unit = 0.1
blocks:
    {"from":[-8,-3,-6],"size":[16,1,1],"color":"c"}
    {"from":[-8,-3,6],"size":[16,1,1],"color":"c"}
    {"from":[-8,-3,-6],"size":[1,1,13],"color":"c"}
    {"from":[7,-3,-6],"size":[1,1,13],"color":"c"}
    {"from":[-4,-3,-6],"size":[1,1,13],"color":"w"}
    {"from":[0,-3,-6],"size":[1,1,13],"color":"w"}
    {"from":[4,-3,-6],"size":[1,1,13],"color":"w"}
    {"from":[-8,-3,-2],"size":[16,1,1],"color":"w"}
    {"from":[-8,-3,2],"size":[16,1,1],"color":"w"}
    {"from":[-1,-3,7],"size":[2,2,14],"color":"g"}

@Model/aqua/food
palette = aqua
unit = 0.01
emissive = "g"
blocks:
    {"from":[-6,-6,-6],"size":[12,12,12],"color":"g"}

@Model/aqua/flake
palette = aqua
unit = 0.01
blocks:
    {"from":[-10,-7,-2],"size":[20,14,4],"color":"o"}
    {"from":[-5,-3,2],"size":[10,6,2],"color":"g"}

@Model/aqua/algae
palette = aqua
unit = 0.01
blocks:
    {"from":[-7,-7,-5],"size":[14,14,10],"color":"l"}
    {"from":[-4,-4,5],"size":[8,8,3],"color":"t"}

@Model/aqua/chest
palette = aqua
unit = 0.05
blocks:
    {"from":[-13,-8,0],"size":[26,16,13],"color":"o"}
    {"from":[-14,-9,13],"size":[28,18,4],"color":"g"}
    {"from":[-3,-10,5],"size":[6,2,8],"color":"g"}

@Model/aqua/pearl
palette = aqua
unit = 1
emissive = "w"
shapes:
    {"type":"sphere","center":[0,0,0],"radius":0.3,"color":"w"}

@Model/aqua/jelly
palette = aqua
unit = 0.05
emissive = "vp"
shapes:
    {"type":"sphere","center":[0,0,0],"radius":14,"color":"v"}
blocks:
    {"from":[-10,-8,-22],"size":[3,3,20],"color":"p"}
    {"from":[8,-8,-26],"size":[3,3,24],"color":"p"}
    {"from":[-8,6,-24],"size":[3,3,22],"color":"p"}
    {"from":[6,6,-20],"size":[3,3,18],"color":"p"}
    {"from":[-6,-13,-1],"size":[3,2,3],"color":"k"}
    {"from":[4,-13,-1],"size":[3,2,3],"color":"k"}
music.rune
@Music/glowtide_drift
type = synth
tempo = 64
time_signature = 4/4
loop = true
volume = 0.055
instruments = {"harmony":"strings","bass":"sine","sparkle":"bell"}
effects = {
    "reverb":{"decay":3.6,"wet":0.38,"pre_delay":0.035,"filter":2400},
    "delay":{"time":0.9375,"feedback":0.22,"wet":0.12,"damping":1800},
    "filter":{"type":"lowpass","cutoff":2200,"q":0.5},
    "chorus":{"rate":0.18,"depth":0.003,"wet":0.22}
}
track_effects = {
    "harmony":{"reverb":0.8,"delay":0.1,"chorus":0.65},
    "bass":{"reverb":0.12,"delay":0,"chorus":0},
    "sparkle":{"reverb":0.7,"delay":0.55,"chorus":0.1}
}
sections = {
    "lagoon":{
        "bars":8,
        "harmony":"[C3,E3,G3,B3]:1 | [C3,E3,G3,D4]:1 | [A2,C3,E3,G3]:1 | [A2,C3,E3,B3]:1 | [F2,A2,C3,E3]:1 | [F2,A2,C3,G3]:1 | [G2,B2,D3,A3]:1 | [G2,B2,E3,A3]:1",
        "bass":"C2:1 | C2:1 | A1:1 | A1:1 | F2:1 | F2:1 | G1:1 | G1:1",
        "sparkle":"-:2 G4:4 -:4 | -:2 E4:2 | -:1 | -:2 B4:4 -:4 | -:2 A4:2 | -:1 | -:2 D4:4 -:4 | -:2 E4:2"
    },
    "moonlight":{
        "bars":8,
        "harmony":"[C3,E3,G3,D4]:1 | [C3,E3,A3,B3]:1 | [E3,G3,B3,D4]:1 | [E3,G3,A3,D4]:1 | [F2,A2,C3,G3]:1 | [F2,A2,D3,E3]:1 | [G2,B2,D3,A3]:1 | [G2,C3,D3,E3]:1",
        "bass":"C2:1 | C2:1 | E2:1 | E2:1 | F2:1 | F2:1 | G1:1 | G1:1",
        "sparkle":"-:1 | -:2 G4:2 | -:2 B4:4 -:4 | -:1 | -:2 E4:2 | -:2 D4:4 -:4 | -:1 | -:2 G4:2"
    }
}
arrangement = ["lagoon","moonlight"]
shell.rune
@Page/aquarium_cabinet
title = Glowtide Aquarium - A Little Ocean of Happy
logic = aquarium_cabinet
style = aquarium_cabinet
view:
    main .aquarium-app:
        header .masthead:
            div:
                p .eyebrow "A LITTLE OCEAN OF HAPPY"
                h1 "Glowtide Aquarium"
                p .subtitle "Small fish. Big feelings. A little care goes a long way."
            div .wallet:
                strong data-pixel-text=pearl_label "30 / 100000 pearls"
                span data-pixel-text=income_label "+1.5 pearls / sec"
        section .tank-card:
            div .toolbar:
                span .collection data-pixel-text=collection_label "3/18 friends / Reef 0/5"
                div .tools:
                    button data-pixel-action=toggle_menu "Aquarium menu / TAB"
                    button data-pixel-action=orbit_view data-pixel-args="[-1]" aria-label="View tank from the left" "Left"
                    button data-pixel-action=orbit_view data-pixel-args="[1]" aria-label="View tank from the right" "Right"
                    button data-pixel-action=cycle_lights data-pixel-text=lighting_label "LAGOON GLOW / L"
                    select data-pixel-lighting=true aria-label="Lighting quality":
                        option value=enhanced selected=true "Enhanced glow"
                        option value=standard "Standard glow"
                    label .gpu-option:
                        input type=checkbox data-pixel-gpu=true
                        span "GPU lighting"
                    button data-pixel-pause=true "Pause / P"
                    button data-pixel-mute=true aria-label="Toggle aquarium sound" "Sound / M"
                    button data-pixel-fullscreen=true "Fullscreen / F"
            div .game-surface:
                canvas data-rune-pixel-3d=true data-pixel-drag-action=drag_orbit data-pixel-pick=residents data-pixel-pick-action=inspect_resident tabindex=0 aria-label="A glowing 3D aquarium. Drag to smoothly rotate. Tap a fish or critter to meet it, or a dead friend to retrieve with your net. Left and right arrows orbit the tank. Space feeds fish and critters."
                div .pause-overlay data-pixel-paused=true hidden=true role=group aria-label="Aquarium paused":
                    strong role=status "Paused"
                    button type=button data-pixel-pause=true aria-label="Resume game" "Resume / P"
            p .festival data-pixel-text=event_label "A glow festival is on its way!"
        section .actions aria-label="Aquarium care and upgrades":
            button .snack data-pixel-action=feed data-pixel-disabled=feed_locked:
                span .action-title "SNACK PARTY"
                span data-pixel-text=feed_label "Feed fish and critters / 4 pearls"
                small "Double income during feeding / SPACE"
            button .adopt data-pixel-action=buy_fish data-pixel-disabled=fish_locked:
                span .action-title "MAKE A FRIEND"
                span data-pixel-text=fish_label "Adopt a fish / 45 pearls"
                small "Eight varieties, from clownfish to glowing neon tetras / 1"
            button .grow data-pixel-action=grow_reef data-pixel-disabled=reef_locked:
                span .action-title "BUILD A RAINBOW"
                span data-pixel-text=reef_label "Grow reef / 30 pearls"
                small "+0.5 pearl per fish per second / 2"
            button .gift data-pixel-action=collect_treasure data-pixel-disabled=treasure_locked:
                span .action-title "OYSTER SURPRISE"
                span data-pixel-text=treasure_label "Collect oyster / +40"
                small "A little gift every 20 seconds / C"
            button .expand data-pixel-action=grow_tank data-pixel-disabled=tank_locked:
                span .action-title "A BIGGER LITTLE OCEAN"
                span data-pixel-text=tank_label "Expand tank / 600 pearls"
                small "More swimming room and six extra fish spaces / 3"
            button data-pixel-action=request_reset:
                span .action-title "FRESH START"
                span "Reset tank"
                small "Erase pearls and upgrades / Confirmation required"
            button data-pixel-action=open_flower_shop:
                span .action-title "FLORAL GARDEN"
                span "Choose a bloom"
                small "Sunburst, violet sea fan and moon lily / From 35 pearls"
            button data-pixel-action=open_critter_shop:
                span .action-title "SANDY NEIGHBORS"
                span "Choose a critter"
                small "Crabs, hermits, shrimp and snails / From 40 pearls"
            button data-pixel-action=open_care_upgrades:
                span .action-title "TANK CARE"
                span "Food and longevity upgrades"
                small "Three levels each / From 150 pearls"
        p .notice data-pixel-text=notice role=status aria-live=polite "Welcome home! Your fish earn pearls just by swimming."
        p .notice data-pixel-text=snack_label "0 snacks eaten / +0 bite pearls"
        section .aquarium-guide aria-label="Aquarium guide":
            h2 "Your aquarium guide"
            p "A little help when you need it. Open a topic to learn more."
            details:
                summary "Controls and exploring"
                p "Drag with a finger or mouse to rotate the tank; tap a resident to see its profile. Left and right arrows or A and D also rotate. The tank grows with each expansion."
                p "Use the in-game menu for care and upgrades, or the snack and fish icons for quick care. The menu works in fullscreen: tap away or X to close, use Up and Down to select, and Enter to confirm. Rename friends with the on-screen keyboard, physical keys, or a controller: D-pad moves, A selects and B cancels."
            details:
                summary "Feeding and caring for friends"
                p "Feed scatters pellets, flakes and algae. Each finished snack earns 2 pearls. Feeding costs one pearl per living fish or critter, with a minimum of one; if you cannot afford it, no food or cooldown is spent."
                p "Fish hunger fills in 10 running minutes, with 5 more before starvation. Fish live 45-90 running minutes. Critter hunger fills in 20 minutes, with 10 more before starvation; critters live 90-180 running minutes. Snacks reduce hunger."
                p "Tap a dead friend to retrieve it with a net and free its space. Unretrieved fish decay and sink after 2 minutes and can be eaten by hungry fish; dead critters remain on the sand until retrieved."
            details:
                summary "Growing your tank"
                p "Adopt eight varieties of fish, expand twice for up to 30 friends, and add up to 12 floral decorations and 12 bottom neighbors. Grow reef level 3 to welcome a moon jelly. Every minute ends with a 15-second glow festival."
                p "Each living fish earns 0.5 pearl per second before reef and event bonuses; fractions carry forward. The wallet holds up to 100,000 pearls, including snacks and oyster rewards. Spend pearls to make room; lifetime earnings are not capped."
                p "Select a fish and open UPGRADES for its 120-pearl Style Kit or 80-pearl Candy and Moon stripes. Owned patterns switch free. Tank care offers food upgrades (150 / 350 / 700 pearls) and longevity (200 / 500 / 1000). Each food level adds 10 seconds to future showers and cooldowns, up to 60 / 70 seconds. Each longevity level adds 10% base lifespan, up to 30%; it does not revive friends or prevent hunger."
            details:
                summary "Saving and starting over"
                p "Progress and care save automatically in this browser. There are no offline earnings or aging, and pause stops the simulation. Choose Resume on the tank or press P to continue. New and reset tanks start with 30 pearls, three fish and one crab; reset requires confirmation."
            details:
                summary "Music and lighting"
                p "Moonlit Drift is an original lo-fi loop that starts on your first interaction. Sound / M mutes it; Pause quiets the aquarium."
                p "GPU lighting is optional. If WebGL is unavailable or its context is lost, lighting falls back to the CPU. Picking and care stay the same; performance depends on the browser and hardware."

@Logic/aquarium_cabinet
state:
    name = "Glowtide Aquarium"

@Style/aquarium_cabinet
rules:
    :root:
        color-scheme = dark
    *:
        box-sizing = border-box
    body:
        margin = 0
        background = radial-gradient(ellipse at top, #153d57, #080f24 75%)
        color = #eafffa
        font-family = system-ui, -apple-system, sans-serif
    .aquarium-app:
        max-width = 1160px
        margin = auto
        padding = clamp(12px, 3vw, 32px)
    .masthead:
        display = flex
        justify-content = space-between
        align-items = center
        flex-wrap = wrap
        gap = 16px
        margin-bottom = 20px
    .eyebrow:
        color = #6cf3cf
        letter-spacing = 3px
        font-size = 11px
        font-weight = 800
    h1:
        margin = 0
        font-size = clamp(26px, 5vw, 44px)
        letter-spacing = -1px
        color = #eafffa
    .subtitle:
        color = #a2c6d6
        margin-bottom = 0
    .wallet:
        display = grid
        gap = 4px
        background = #183948
        border = 1px solid #47766d
        border-radius = 18px
        padding = 14px 24px
        color = #ffe59c
        min-width = 190px
    .wallet strong:
        font-size = 26px
        font-variant-numeric = tabular-nums
    .wallet span:
        color = #6cf3cf
        font-size = 13px
    .tank-card:
        overflow = hidden
        border = 1px solid #39718c
        border-radius = 20px
        background = #0d243c
        box-shadow = 0 0 60px #28c6d51a
    .toolbar:
        display = flex
        flex-wrap = wrap
        justify-content = space-between
        align-items = center
        gap = 10px
        padding = 10px 14px
    .collection:
        color = #a4e7e2
        font-size = 13px
        font-weight = 700
    .tools:
        display = flex
        flex-wrap = wrap
        gap = 6px
    .gpu-option:
        display = flex
        align-items = center
        gap = 6px
        padding = 8px
        font-size = 12px
    button, select:
        font = inherit
        color = #eafffa
        background = #183c54
        border = 1px solid #3e7188
        border-radius = 10px
        padding = 10px
        min-height = 44px
        cursor = pointer
        font-size = 12px
    button:hover:not(:disabled):
        background = #26536b
        border-color = #6cf3cf
    button:focus-visible, select:focus-visible, canvas:focus-visible:
        outline = 3px solid #ffe076
        outline-offset = 3px
    button:disabled:
        cursor = default
        opacity = 0.58
    .game-surface:
        position = relative
        background = #08182d
    .pause-overlay:
        position = absolute
        top = clamp(8px, 3%, 24px)
        left = 50%
        transform = translateX(-50%)
        display = flex
        align-items = center
        gap = 14px
        padding = 8px 12px
        border = 1px solid #47766d
        border-radius = 14px
        background = #10283d
        box-shadow = 0 4px 18px #080f24b3
        pointer-events = none
    .pause-overlay strong:
        color = #eafffa
        font-size = 16px
    .pause-overlay button:
        color = #6cf3cf
        font-weight = 700
        white-space = nowrap
        pointer-events = auto
    [hidden]:
        display = none !important
    canvas:
        display = block
        width = 100%
        height = auto
        aspect-ratio = 8 / 5
        image-rendering = pixelated
        touch-action = none
    .festival:
        margin = 0
        padding = 12px
        text-align = center
        color = #ffd587
        font-size = 13px
        background = #1d2849
    .actions:
        display = grid
        grid-template-columns = repeat(auto-fit, minmax(230px, 1fr))
        gap = 10px
        margin-top = 16px
    .actions button:
        display = grid
        gap = 10px
        text-align = left
        padding = 18px
        background = #142c42
        border-top = 3px solid #6cf3aa
    .actions .adopt:
        border-top-color = #ff9348
    .actions .grow:
        border-top-color = #ff5db5
    .actions .gift:
        border-top-color = #ffe076
    .action-title:
        letter-spacing = 2px
        font-size = 11px
        font-weight = 800
        color = #a4e7e2
    .actions button > span:nth-child(2):
        font-size = 16px
        font-weight = 700
    small:
        color = #b2c4d9
        font-size = 11px
        line-height = 1.5
    .notice:
        min-height = 48px
        padding = 14px
        border-radius = 12px
        background = #16374a
        color = #f8dfaf
        text-align = center
        font-size = 14px
    .aquarium-guide:
        margin-top = 24px
        padding = clamp(16px, 3vw, 24px)
        border = 1px solid #39718c
        border-radius = 18px
        background = #10283d
        color = #9db5ca
        font-size = 14px
        line-height = 1.6
    .aquarium-guide h2:
        margin = 0
        color = #eafffa
        font-size = 20px
    .aquarium-guide > p:
        margin = 6px 0 16px
    .aquarium-guide details:
        border-top = 1px solid #31566a
    .aquarium-guide summary:
        min-height = 44px
        padding = 12px 0
        color = #a4e7e2
        font-weight = 700
        cursor = pointer
    .aquarium-guide summary:focus-visible:
        outline = 3px solid #ffe076
        outline-offset = 3px
    .aquarium-guide details p:
        margin = 0 0 12px
upgrades.rune
@Logic/aquarium
state:
    feeding_duration = 900
    fish_style = []
    styled_species = ["aqua/clown-style","aqua/tang-style","aqua/royal-style","aqua/puffer-style","aqua/angel-style","aqua/butterfly-style","aqua/neon-style","aqua/lion-style"]
    pattern_names = ["Original colors","Candy stripes","Moon stripes"]
    food_prices = [150,350,700]
    life_prices = [200,500,1000]

action award_pearls(amount):
    progress.pearls = min(100000,progress.pearls+amount)

action prepare_fish_upgrades(buddy):
    buddy.style = buddy.style ? true : false
    buddy.candy = buddy.candy ? true : false
    buddy.moon = buddy.moon ? true : false
    buddy.pattern = buddy.pattern==1 && buddy.candy ? 1 : buddy.pattern==2 && buddy.moon ? 2 : 0
    buddy.base_lifespan = buddy.base_lifespan ? buddy.base_lifespan : buddy.lifespan
    if !buddy.dead:
        buddy.lifespan = floor(buddy.base_lifespan*(1+progress.life_level*0.1))

action build_fish_style:
    residents_dirty = true
    fish_style = []
    for f, index in fish:
        local buddy = progress.buddies[index]
        if buddy.style:
            for part in range(0,4):
                fish_style.push({"x":f.x,"y":f.y,"z":f.z,"model":part==0 ? "aqua/style-tail" : part==3 ? "aqua/candy-stripes" : "aqua/style-fin","owner":index,"part":part,"visible":false,"scale":f.base_scale})
    call animate_fish_style

action animate_fish_style:
    for f, index in fish:
        local buddy = progress.buddies[index]
        if !buddy.dead:
            f.model = buddy.style ? styled_species[buddy.kind] : species[buddy.kind]
    for piece in fish_style:
        local f = fish[piece.owner]
        local buddy = progress.buddies[piece.owner]
        piece.visible = buddy.style && !buddy.dead && (piece.part!=3 || buddy.pattern>0)
        local side = piece.part==1 ? -0.25 : piece.part==2 ? 0.25 : 0
        local back = piece.part==0 ? -0.55 : 0
        piece.x = f.x+(cos(f.angle)*back-sin(f.angle)*side)*f.scale
        piece.y = f.y+(sin(f.angle)*back+cos(f.angle)*side)*f.scale
        piece.z = f.z
        piece.scale = f.scale
        piece.angle = f.angle+(piece.part==0 ? sin(ticks*12+f.phase)*22 : piece.part==3 ? 0 : sin(ticks*10+f.phase)*18)
        if piece.part==3:
            piece.model = buddy.pattern==1 ? "aqua/candy-stripes" : "aqua/moon-stripes"

action open_fish_upgrades:
    if selected_fish<0 || selected_fish>=fish.length || selected_critter>=0:
        notice = "Tap a living fish to choose its upgrades."
        call update_labels
        stop when true
    if progress.buddies[selected_fish].dead:
        notice = "Retrieve this friend with the net; dead fish cannot be upgraded."
        call update_labels
        stop when true
    profile_open = false
    keyboard_open = false
    menu_open = false
    shop = "fish"
    shop_index = 0
    shop_error = ""
    call update_labels

action open_care_upgrades:
    profile_open = false
    keyboard_open = false
    menu_open = false
    shop = "care"
    shop_index = 0
    shop_error = ""
    call update_labels

action buy_fish_upgrade(kind):
    if selected_fish<0 || selected_fish>=fish.length || selected_critter>=0 || kind<0 || kind>3 || floor(kind)!=kind:
        notice = "Choose a living fish and an upgrade from its picker."
        shop_error = notice
        call update_labels
        stop when true
    local buddy = progress.buddies[selected_fish]
    if buddy.dead || (kind>0 && !buddy.style):
        notice = buddy.dead ? "Dead fish cannot be upgraded." : "Buy the Style Kit before choosing a color pattern."
        shop_error = notice
        call update_labels
        stop when true
    if kind==0 && buddy.style:
        notice = "This fish already owns the Style Kit."
        shop_error = notice
        call update_labels
        stop when true
    local price = kind==0 ? 120 : kind==1 && !buddy.candy ? 80 : kind==2 && !buddy.moon ? 80 : 0
    if progress.pearls<price:
        notice = "Save "+price+" pearls for this fish's upgrade."
        shop_error = notice
        call update_labels
        stop when true
    progress.pearls -= price
    if kind==0:
        buddy.style = true
    if kind==1:
        buddy.candy = true
        buddy.pattern = 1
    if kind==2:
        buddy.moon = true
        buddy.pattern = 2
    if kind==3:
        buddy.pattern = 0
    shop_index = kind
    save_revision += 1
    shop_error = ""
    notice = buddy.name+" / "+(kind==0 ? "Rounded body and animated fins!" : pattern_names[buddy.pattern])
    call build_fish_style
    call animate
    call update_labels

action buy_care_upgrade(kind):
    if kind!=0 && kind!=1:
        notice = "Choose food or longevity from the tank care picker."
        shop_error = notice
        call update_labels
        stop when true
    local level = kind==0 ? progress.food_level : progress.life_level
    if level>=3:
        notice = "This tank care upgrade is already at level 3."
        shop_error = notice
        call update_labels
        stop when true
    local price = kind==0 ? food_prices[level] : life_prices[level]
    if progress.pearls<price:
        notice = "Save "+price+" pearls for the next tank care level."
        shop_error = notice
        call update_labels
        stop when true
    progress.pearls -= price
    if kind==0:
        progress.food_level += 1
    if kind==1:
        progress.life_level += 1
        for buddy in progress.buddies:
            call prepare_fish_upgrades buddy
            buddy.care.lifespan = buddy.lifespan
        for critter in progress.critters:
            if !critter.dead:
                critter.lifespan = floor(critter.base_lifespan*(1+progress.life_level*0.1))
                critter.care.lifespan = critter.lifespan
    save_revision += 1
    shop_error = ""
    notice = kind==0 ? "Next feeding lasts 10 seconds longer. Cooldown also grows by 10 seconds." : "Living friends gain 10% base lifespan. No revival or hunger protection."
    call update_labels

action upgrade_labels:
    ui.grid.title = shop=="care" ? "Tank care upgrades" : progress.buddies[selected_fish].name+" / Upgrades"
    ui.grid.footer = shop_error ? shop_error : "PURCHASE OR SWITCH / TAP AWAY CLOSE"
    if shop=="fish":
        local buddy = progress.buddies[selected_fish]
        ui.grid.items = [
            {"label":"Style Kit","sub":buddy.style ? "Owned / Rounded body and moving fins" : "120 pearls / Rounded body and moving fins","action":"buy_fish_upgrade","args":[0],"disabled":buddy.dead || buddy.style || progress.pearls<120,"selected":shop_index==0},
            {"label":"Candy stripes","sub":buddy.pattern==1 ? "Active on this fish / Owned" : buddy.candy ? "Owned by this fish / Switch free" : "80 pearls for this fish / Requires Style Kit","action":"buy_fish_upgrade","args":[1],"disabled":buddy.dead || !buddy.style || (!buddy.candy && progress.pearls<80),"selected":shop_index==1},
            {"label":"Moon stripes","sub":buddy.pattern==2 ? "Active on this fish / Owned" : buddy.moon ? "Owned by this fish / Switch free" : "80 pearls for this fish / Requires Style Kit","action":"buy_fish_upgrade","args":[2],"disabled":buddy.dead || !buddy.style || (!buddy.moon && progress.pearls<80),"selected":shop_index==2},
            {"label":"Original colors","sub":buddy.style && buddy.pattern==0 ? "Active on this fish / Free" : "Free / Keep your Style Kit","action":"buy_fish_upgrade","args":[3],"disabled":buddy.dead || !buddy.style,"selected":shop_index==3}
        ]
    if shop=="care":
        ui.grid.items = [
            {"label":"Long-lasting food","sub":progress.food_level>=3 ? "Level 3 / Maximum 60-second shower" : food_prices[progress.food_level]+" pearls / Next shower "+(40+progress.food_level*10)+"s","action":"buy_care_upgrade","args":[0],"disabled":progress.food_level>=3 || progress.pearls<food_prices[progress.food_level],"selected":shop_index==0},
            {"label":"Longevity","sub":progress.life_level>=3 ? "Level 3 / Maximum +30% lifespan" : life_prices[progress.life_level]+" pearls / Next +"+((progress.life_level+1)*10)+"% base lifespan","action":"buy_care_upgrade","args":[1],"disabled":progress.life_level>=3 || progress.pearls<life_prices[progress.life_level],"selected":shop_index==1}
        ]

Cuida tu pequeño océano

Tus amigos ganan perlas mientras el acuario está activo. Aliméntalos, amplía el arrecife, añade decoraciones y adopta peces y criaturas del fondo.

Arrastra el acuario o usa las flechas para girarlo. Toca un habitante para verlo. Usa los controles en pantalla o Espacio para alimentar, C para recoger la ostra y Tab para abrir el menú.

El progreso se guarda en este navegador; la vista integrada y la independiente comparten la partida. Los habitantes no envejecen ni ganan perlas mientras el acuario está cerrado o en pausa.

La interfaz del acuario está actualmente en inglés.

Explorar el código Rune

Consulta los archivos Rune del acuario arriba, o ejecútalo y pruébalo localmente con Vectrune 0.3.13 o posterior.

vectrune examples/games/idle_aquarium/idle_aquarium.rune
vectrune test examples/games/idle_aquarium --type logic
Sitio creado íntegramente con Rune-Web