Spaces:
Sleeping

byte-vortex commited on
Commit
ebdc6cf
ยท
verified ยท
1 Parent(s): e1aa5a8

Deploy Myco from CI

Browse files
Files changed (1) hide show
  1. ui/renderers.py +377 -39
ui/renderers.py CHANGED
@@ -1,7 +1,5 @@
1
  """Markdown renderers for the Myco Gradio interface."""
2
 
3
- import hashlib
4
- import time
5
  from html import escape
6
  from game.progression import (
7
  AREA_UNLOCKS, current_area, next_area, next_mystery,
@@ -10,63 +8,384 @@ from game.progression import (
10
  from game.state import CollectionState, EMPTY_DEX, MushroomState
11
  from models.mushroom import Mushroom
12
 
 
 
13
  POISONOUS_MUSHROOM_NAMES = {
14
  "Ghost Gill", "Pepper Pixie", "Ruby Knuckle", "Clockwork Chanterelle",
15
  }
16
 
17
- # โ”€โ”€ 8-BIT MATRIX BLUEPRINTS โ”€โ”€
18
- MATRIX_DOME = [[0,0,0,1,1,1,1,0,0,0],[0,0,1,2,2,3,2,1,0,0],[0,1,2,2,3,2,2,2,1,0],[1,2,3,2,2,2,3,2,2,1],[1,1,1,1,1,4,1,1,1,1],[0,0,0,0,1,4,1,0,0,0],[0,0,0,0,1,4,1,0,0,0],[0,0,0,0,1,1,1,0,0,0]]
19
- MATRIX_SKULL = [[0,0,1,1,1,1,1,1,0,0],[0,1,2,2,2,2,2,2,1,0],[1,2,1,2,2,2,1,2,2,1],[1,2,1,2,2,2,1,2,2,1],[0,1,2,2,1,1,2,2,1,0],[0,0,1,2,1,1,2,1,0,0],[0,0,1,4,4,4,4,1,0,0],[0,0,0,1,1,1,1,0,0,0]]
20
- MATRIX_FLAT = [[0,0,1,1,1,1,1,1,0,0],[0,1,3,2,2,2,3,2,1,0],[1,2,2,2,3,2,2,2,2,1],[1,1,1,1,4,4,1,1,1,1],[0,0,0,1,4,4,1,0,0,0],[0,0,0,1,4,4,1,0,0,0],[0,0,1,4,4,4,4,1,0,0],[0,0,1,1,1,1,1,1,0,0]]
21
- MATRIX_STAR = [[0,0,0,0,1,1,0,0,0,0],[0,1,0,1,2,2,1,0,1,0],[1,2,1,2,2,2,2,1,2,1],[0,1,2,3,2,2,3,2,1,0],[0,0,1,1,4,4,1,1,0,0],[0,0,0,1,4,4,1,0,0,0],[0,0,0,1,4,4,1,0,0,0],[0,0,0,1,1,1,1,0,0,0]]
 
 
 
 
 
 
 
 
 
 
 
22
 
23
- def generate_mushroom_sprite(name: str) -> str:
24
- hash_val = int(hashlib.md5(name.encode('utf-8')).hexdigest(), 16)
25
- shapes = [MATRIX_DOME, MATRIX_SKULL, MATRIX_FLAT, MATRIX_STAR]
26
- matrix = shapes[hash_val % len(shapes)]
27
- palettes = [("#d62828", "#f77f00", "#fcbf49"), ("#00f2fe", "#ff007f", "#25003e"), ("#ffb703", "#ffffff", "#fb8500")]
28
- c_cap, c_spot, c_stem = palettes[hash_val % len(palettes)]
29
- color_map = {1: "#121214", 2: c_cap, 3: c_spot, 4: c_stem}
30
- px_scale = 5
31
- shadows = [f"{c*px_scale}px {r*px_scale}px 0 {color_map[v]}"
32
- for r, row in enumerate(matrix) for c, v in enumerate(row) if v in color_map]
33
- return f'<div style="width:{px_scale}px; height:{px_scale}px; box-shadow: {", ".join(shadows)}; margin: 0 auto; transform: scale(1.4);"></div>'
34
-
35
- # โ”€โ”€ SCENE STYLES โ”€โ”€
36
- SCENE_STYLES = """<style>.forest-scene { position: relative; isolation: isolate; overflow: hidden; min-height: 20rem; padding: 0.75rem; border-radius: 28px; background: radial-gradient(circle at 50% 72%, rgba(255,239,173,.26), transparent 8rem), radial-gradient(circle at 18% 24%, rgba(134,225,153,.22), transparent 10rem), linear-gradient(180deg,#123626 0%,#245c3c 54%,#523b20 100%); border: 1px solid rgba(225,255,209,.25); box-shadow: 0 18px 48px rgba(8,30,20,.26); color: #f9ffe9; } .scene-hud { position: relative; z-index: 3; display: flex; flex-wrap: wrap; gap: .4rem; padding: .5rem .75rem; border-radius: 999px; background: rgba(13,38,28,.72); backdrop-filter: blur(6px); font-size: .8rem; font-weight: 800; } .scene-stage { position: relative; height: 13rem; margin: .6rem 0; background: linear-gradient(transparent 62%, rgba(106,79,33,.55) 63%), radial-gradient(ellipse at bottom, rgba(190,255,180,.2), transparent 60%); border-radius: 22px; overflow: hidden; } .scene-stage span { position: absolute; line-height:1; } .tree-left { left:6%; bottom:18%; font-size:5rem; filter:drop-shadow(0 8px 12px rgba(0,0,0,.28)); } .tree-right { right:7%; bottom:20%; font-size:4.75rem; filter:drop-shadow(0 8px 12px rgba(0,0,0,.28)); } .grass-one { left:26%; bottom:14%; font-size:2.4rem; } .grass-two { right:28%; bottom:16%; font-size:2.2rem; } .sparkle-one { left:34%; top:18%; font-size:1.8rem; animation:twinkle 1.8s ease-in-out infinite; } .sparkle-two { right:33%; top:24%; font-size:1.6rem; animation:twinkle 2.2s ease-in-out infinite reverse; } @keyframes twinkle { 0%,100%{opacity:.3;transform:scale(.85);} 50%{opacity:1;transform:scale(1.18);} } .myco-player { font-size:4rem; z-index:2; transition: left .32s cubic-bezier(.34,1.56,.64,1), bottom .32s cubic-bezier(.34,1.56,.64,1); animation: myco-bob 2.4s ease-in-out infinite; filter:drop-shadow(0 6px 14px rgba(255,92,92,.28)); } @keyframes myco-bob { 0%,100%{transform:translateY(0);} 50%{transform:translateY(-.45rem);} } .pos-0-0 .myco-player{left:14%;bottom:62%;} .pos-1-0 .myco-player{left:41%;bottom:62%;} .pos-2-0 .myco-player{left:67%;bottom:62%;} .pos-0-1 .myco-player{left:14%;bottom:36%;} .pos-1-1 .myco-player{left:41%;bottom:36%;} .pos-2-1 .myco-player{left:67%;bottom:36%;} .pos-0-2 .myco-player{left:14%;bottom:13%;} .pos-1-2 .myco-player{left:41%;bottom:13%;} .pos-2-2 .myco-player{left:67%;bottom:13%;} .mushroom-sprite { position: absolute; right:33%; bottom:22%; z-index:2; filter:drop-shadow(0 6px 14px rgba(0,0,0,.3)); } .state-waiting .mushroom-sprite { opacity:0; } .state-discovered .mushroom-sprite { animation: shroom-popup 0.7s cubic-bezier(.34,1.56,.64,1) both; } .state-discovered .myco-player { animation: myco-bob 2.4s ease-in-out infinite, myco-run-in 0.6s cubic-bezier(.34,1.56,.64,1) both; } @keyframes shroom-popup { 0%{ opacity:0; transform:translateY(3rem) scale(.2); } 60%{ opacity:1; transform:translateY(-.4rem) scale(1.18); } 100%{ opacity:1; transform:translateY(0) scale(1); } } @keyframes myco-run-in { 0%{ transform:translateX(-3rem) scaleX(-1); } 100%{ transform:translateX(0) scaleX(1); } } .state-picked .mushroom-sprite { animation: shroom-catch 0.55s cubic-bezier(.34,1.56,.64,1) both; } .state-picked .myco-player { animation: myco-bob 2.4s ease-in-out infinite, myco-catch-jump 0.55s ease both; } @keyframes shroom-catch { 0%{ opacity:1; transform:translateY(0) scale(1); } 40%{ opacity:1; transform:translateY(-2.5rem) scale(1.3) rotate(15deg); } 100%{ opacity:0; transform:translateY(-5rem) scale(.2) rotate(40deg); } } @keyframes myco-catch-jump { 0%,100%{ transform:translateY(0); } 40%{ transform:translateY(-1.4rem) scale(1.1); } } .state-danger .mushroom-sprite { animation: shroom-popup 0.7s cubic-bezier(.34,1.56,.64,1) both, poison-pulse 1.2s ease-in-out infinite 0.7s; filter: drop-shadow(0 0 18px rgba(255,62,91,.9)); } .state-danger .myco-player { animation: myco-bob 2.4s ease-in-out infinite, myco-recoil 0.5s ease both; } @keyframes poison-pulse { 0%,100%{ filter:drop-shadow(0 0 10px rgba(255,62,91,.6)); } 50%{ filter:drop-shadow(0 0 28px rgba(255,62,91,1)); } } @keyframes myco-recoil { 0%{ transform:translateX(0); } 30%{ transform:translateX(-1.2rem); } 60%{ transform:translateX(.4rem); } 100%{ transform:translateX(0); } } .state-game-over .forest-scene, .state-game-over { animation: screen-shake .45s ease both; background: radial-gradient(circle at 50% 72%, rgba(255,62,91,.35), transparent 8rem), linear-gradient(180deg,#3b0a0a 0%,#6b1a1a 54%,#2a0a0a 100%) !important; } .state-game-over .mushroom-sprite { animation: shroom-explode .6s ease both; filter: drop-shadow(0 0 24px rgba(255,62,91,1)); } .state-game-over .myco-player { animation: myco-fall .6s ease both; } @keyframes screen-shake { 0%,100%{ transform:translateX(0); } 20%{ transform:translateX(-8px); } 40%{ transform:translateX(8px); } 60%{ transform:translateX(-5px); } 80%{ transform:translateX(5px); } } @keyframes shroom-explode { 0%{ transform:scale(1) rotate(0); opacity:1; } 50%{ transform:scale(1.8) rotate(20deg); opacity:.8; } 100%{ transform:scale(0) rotate(90deg); opacity:0; } } @keyframes myco-fall { 0%{ transform:rotate(0) translateY(0); opacity:1; } 100%{ transform:rotate(-90deg) translateY(2rem); opacity:.4; } } .rarity-rare .mushroom-sprite { filter:drop-shadow(0 0 18px rgba(138,220,255,.9)); } .rarity-legendary .mushroom-sprite{ filter:drop-shadow(0 0 28px rgba(255,215,0,1)); animation:legendary-pulse 1s ease-in-out infinite 0.7s; } @keyframes legendary-pulse { 0%,100%{ filter:drop-shadow(0 0 18px rgba(255,215,0,.7)); transform:scale(1); } 50%{ filter:drop-shadow(0 0 36px rgba(255,215,0,1)); transform:scale(1.1); } } .forest-map { display:grid; grid-template-columns:repeat(3,1fr); gap:.3rem; margin:.4rem auto .6rem; max-width:9rem; padding:.4rem; border:1px solid rgba(255,255,255,.18); border-radius:14px; background:rgba(13,38,28,.58); } .map-tile { display:grid; min-height:1.7rem; place-items:center; border-radius:8px; background:rgba(255,255,255,.1); font-weight:900; } .map-tile.active { background:rgba(255,224,138,.92); color:#3d2c00!important; } .scene-caption { display:flex; justify-content:space-between; gap:.6rem; padding:.55rem .8rem; border-radius:14px; background:rgba(13,38,28,.68); backdrop-filter:blur(6px); align-items:center; } .scene-caption span { color:#d9f4d4; } .score-burst { margin:.65rem auto 0; max-width:520px; padding:.5rem .85rem; border-radius:999px; background:rgba(255,224,112,.18); border:1px solid rgba(255,244,190,.36); color:#fff7d6; font-weight:900; text-align:center; animation:score-pop .56s ease both; } @keyframes score-pop { 0%{transform:scale(.92);opacity:0;} 45%{transform:scale(1.06);opacity:1;} 100%{transform:scale(1);opacity:1;} } .state-game-over .score-burst { background:rgba(130,0,30,.45); border-color:rgba(255,120,140,.55); } .story-moment { margin:.75rem auto 0; max-width:760px; padding:.8rem 1rem; border:1px solid rgba(255,234,166,.3); border-radius:18px; background:rgba(25,18,45,.72); color:#fff7d6; box-shadow:0 0 24px rgba(165,111,255,.22); } .story-moment strong,.story-moment span { display:block; } .story-moment span { margin-top:.2rem; color:#f6e7b2; } .generating .forest-scene, .pending .forest-scene { opacity:.88!important; } .progress-level,.progress-level-inner { display:none!important; } div.gradio-html { background:transparent!important; } .wrap.default.pending,.wrap.default.generating { background:transparent!important; }</style>"""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
 
38
  def hero_markdown() -> str:
39
- return '<div class="myco-hero"><div class="myco-mascot">๐Ÿ„</div><div><p class="eyebrow">Tiny AI forest game</p><h1>Myco</h1><p>Follow an AI mushroom companion through a glowing forest.</p></div></div>'
 
 
 
 
 
 
 
 
 
40
 
41
  def home_forest_markdown() -> str:
42
- return '<div class="home-forest-postcard"><p><strong>The Milky Way is awake.</strong> Myco hears a brown mushroom whispering your first clue.</p></div>'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
  def play_hook_markdown() -> str:
45
- return '<div class="play-hook"><h2>Goal: follow clues until Myco remembers the Impossible Mushroom.</h2></div>'
 
 
 
 
 
 
 
 
 
 
 
46
 
47
- def forest_scene(current: MushroomState | None, collection: CollectionState | None, position: tuple[int, int] | None = None) -> str:
48
- count = len(_safe_collection(collection))
49
- area = current_area(count)
 
 
 
 
50
  pos_x, pos_y = _safe_position(position)
51
  pos_cls = f"pos-{pos_x}-{pos_y}"
 
52
  if current is None:
53
- mushroom_name, rarity, sprite_html, status, omen = "Hidden mushroom", "common", "โœจ", "The moss is listening.", "Myco is waiting."
54
- event_label, encounter, mystery_label, score_total, health, reward_text, state_cls = "๐ŸŒŒ Dreaming Forest", "...", "The Wrong Memory", "0", "3", "Search a clearing to score spores.", "state-waiting"
 
 
 
 
 
 
 
 
 
 
55
  else:
56
  mushroom_name = current.get("name", "Mystery mushroom")
57
- rarity = current.get("rarity", "Common").lower()
58
- sprite_html = generate_mushroom_sprite(mushroom_name)
59
- game_over, studied = current.get("game_over") == "Yes", current.get("studied") == "Yes"
60
- event_label = f"{current.get('event_emoji','โœจ')} {current.get('event_title','Strange Omen')}"
61
- encounter, mystery_label = current.get("encounter", "..."), current.get("mystery_title", "The Wrong Memory")
62
- score_total, health, reward_text = current.get("score_total", "0"), current.get("health", "3"), current.get("reward_text", "...")
63
- state_cls = _scene_state_class(current)
64
- status = f"A {rarity} {mushroom_name} breaks through the moss!"
 
 
 
 
 
 
65
  omen = "New field note unlocked." if studied else "Ask Myco what the forest is hiding."
66
- if current.get("picked") == "Yes": omen = "โœ… Picked!"
 
 
 
 
 
 
67
  anim_key = str(int(time.time() * 1000))[-6:]
68
- return f'''{SCENE_STYLES}<div class="forest-scene rarity-{escape(rarity)} {pos_cls} {state_cls}" data-key="{anim_key}"><div class="scene-hud"><span>๐Ÿงญ {escape(area.name)}</span><span>๐ŸŽฎ ({pos_x+1},{pos_y+1})</span><span>๐Ÿ“– {count} found</span></div><div class="scene-stage"><span class="myco-player">๐Ÿ„</span><div class="mushroom-sprite">{sprite_html}</div></div></div>'''
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
 
71
  def _safe_position(position):
72
  if position is None:
@@ -272,4 +591,23 @@ def game_intro_markdown() -> str:
272
  </p>
273
  </div>
274
  """
 
 
 
 
 
 
 
 
 
 
 
 
275
 
 
 
 
 
 
 
 
 
1
  """Markdown renderers for the Myco Gradio interface."""
2
 
 
 
3
  from html import escape
4
  from game.progression import (
5
  AREA_UNLOCKS, current_area, next_area, next_mystery,
 
8
  from game.state import CollectionState, EMPTY_DEX, MushroomState
9
  from models.mushroom import Mushroom
10
 
11
+ import hashlib
12
+
13
  POISONOUS_MUSHROOM_NAMES = {
14
  "Ghost Gill", "Pepper Pixie", "Ruby Knuckle", "Clockwork Chanterelle",
15
  }
16
 
17
+ # โ”€โ”€ Inline CSS + keyframes injected once into the scene โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
18
+ SCENE_STYLES = """
19
+ <style>
20
+ /* โ”€โ”€ Base scene โ”€โ”€ */
21
+ .forest-scene {
22
+ position: relative; isolation: isolate;
23
+ overflow: hidden; min-height: 20rem;
24
+ padding: 0.75rem; border-radius: 28px;
25
+ background:
26
+ radial-gradient(circle at 50% 72%, rgba(255,239,173,.26), transparent 8rem),
27
+ radial-gradient(circle at 18% 24%, rgba(134,225,153,.22), transparent 10rem),
28
+ linear-gradient(180deg,#123626 0%,#245c3c 54%,#523b20 100%);
29
+ border: 1px solid rgba(225,255,209,.25);
30
+ box-shadow: 0 18px 48px rgba(8,30,20,.26);
31
+ color: #f9ffe9;
32
+ }
33
 
34
+ /* โ”€โ”€ HUD bar โ”€โ”€ */
35
+ .scene-hud {
36
+ position: relative; z-index: 3;
37
+ display: flex; flex-wrap: wrap; gap: .4rem;
38
+ padding: .5rem .75rem; border-radius: 999px;
39
+ background: rgba(13,38,28,.72); backdrop-filter: blur(6px);
40
+ font-size: .8rem; font-weight: 800;
41
+ }
42
+
43
+ /* โ”€โ”€ Stage โ”€โ”€ */
44
+ .scene-stage {
45
+ position: relative; height: 13rem;
46
+ margin: .6rem 0;
47
+ background:
48
+ linear-gradient(transparent 62%, rgba(106,79,33,.55) 63%),
49
+ radial-gradient(ellipse at bottom, rgba(190,255,180,.2), transparent 60%);
50
+ border-radius: 22px; overflow: hidden;
51
+ }
52
+ .scene-stage span { position: absolute; line-height:1; }
53
+
54
+ /* โ”€โ”€ Trees / grass โ”€โ”€ */
55
+ .tree-left { left:6%; bottom:18%; font-size:5rem; filter:drop-shadow(0 8px 12px rgba(0,0,0,.28)); }
56
+ .tree-right { right:7%; bottom:20%; font-size:4.75rem; filter:drop-shadow(0 8px 12px rgba(0,0,0,.28)); }
57
+ .grass-one { left:26%; bottom:14%; font-size:2.4rem; }
58
+ .grass-two { right:28%;bottom:16%; font-size:2.2rem; }
59
+
60
+ /* โ”€โ”€ Sparkles โ”€โ”€ */
61
+ .sparkle-one { left:34%; top:18%; font-size:1.8rem; animation:twinkle 1.8s ease-in-out infinite; }
62
+ .sparkle-two { right:33%; top:24%; font-size:1.6rem; animation:twinkle 2.2s ease-in-out infinite reverse; }
63
+ @keyframes twinkle {
64
+ 0%,100%{opacity:.3;transform:scale(.85);}
65
+ 50%{opacity:1;transform:scale(1.18);}
66
+ }
67
+
68
+ /* โ”€โ”€ Myco player โ€” position grid โ”€โ”€ */
69
+ .myco-player {
70
+ font-size:4rem; z-index:2;
71
+ transition: left .32s cubic-bezier(.34,1.56,.64,1), bottom .32s cubic-bezier(.34,1.56,.64,1);
72
+ animation: myco-bob 2.4s ease-in-out infinite;
73
+ filter:drop-shadow(0 6px 14px rgba(255,92,92,.28));
74
+ }
75
+ @keyframes myco-bob {
76
+ 0%,100%{transform:translateY(0);}
77
+ 50%{transform:translateY(-.45rem);}
78
+ }
79
+ .pos-0-0 .myco-player{left:14%;bottom:62%;}
80
+ .pos-1-0 .myco-player{left:41%;bottom:62%;}
81
+ .pos-2-0 .myco-player{left:67%;bottom:62%;}
82
+ .pos-0-1 .myco-player{left:14%;bottom:36%;}
83
+ .pos-1-1 .myco-player{left:41%;bottom:36%;}
84
+ .pos-2-1 .myco-player{left:67%;bottom:36%;}
85
+ .pos-0-2 .myco-player{left:14%;bottom:13%;}
86
+ .pos-1-2 .myco-player{left:41%;bottom:13%;}
87
+ .pos-2-2 .myco-player{left:67%;bottom:13%;}
88
+
89
+ /* โ”€โ”€ Mushroom sprite โ”€โ”€ */
90
+ .mushroom-sprite {
91
+ right:33%; bottom:22%; font-size:3.6rem; z-index:2;
92
+ filter:drop-shadow(0 6px 14px rgba(0,0,0,.3));
93
+ }
94
+
95
+ /* โ”€โ”€ STATE: waiting (no mushroom) โ”€โ”€ */
96
+ .state-waiting .mushroom-sprite { opacity:0; }
97
+
98
+ /* โ”€โ”€ STATE: discovered โ€” mushroom pops up, Myco runs toward it โ”€โ”€ */
99
+ .state-discovered .mushroom-sprite {
100
+ animation: shroom-popup 0.7s cubic-bezier(.34,1.56,.64,1) both;
101
+ }
102
+ .state-discovered .myco-player {
103
+ animation: myco-bob 2.4s ease-in-out infinite,
104
+ myco-run-in 0.6s cubic-bezier(.34,1.56,.64,1) both;
105
+ }
106
+ @keyframes shroom-popup {
107
+ 0% { opacity:0; transform:translateY(3rem) scale(.2); }
108
+ 60% { opacity:1; transform:translateY(-.4rem) scale(1.18); }
109
+ 100% { opacity:1; transform:translateY(0) scale(1); }
110
+ }
111
+ @keyframes myco-run-in {
112
+ 0% { transform:translateX(-3rem) scaleX(-1); }
113
+ 100% { transform:translateX(0) scaleX(1); }
114
+ }
115
+
116
+ /* โ”€โ”€ STATE: picked โ€” mushroom flies up and disappears โ”€โ”€ */
117
+ .state-picked .mushroom-sprite {
118
+ animation: shroom-catch 0.55s cubic-bezier(.34,1.56,.64,1) both;
119
+ }
120
+ .state-picked .myco-player {
121
+ animation: myco-bob 2.4s ease-in-out infinite,
122
+ myco-catch-jump 0.55s ease both;
123
+ }
124
+ @keyframes shroom-catch {
125
+ 0% { opacity:1; transform:translateY(0) scale(1); }
126
+ 40% { opacity:1; transform:translateY(-2.5rem) scale(1.3) rotate(15deg); }
127
+ 100% { opacity:0; transform:translateY(-5rem) scale(.2) rotate(40deg); }
128
+ }
129
+ @keyframes myco-catch-jump {
130
+ 0%,100%{ transform:translateY(0); }
131
+ 40% { transform:translateY(-1.4rem) scale(1.1); }
132
+ }
133
+
134
+ /* โ”€โ”€ STATE: danger (poison, not yet picked) โ”€โ”€ */
135
+ .state-danger .mushroom-sprite {
136
+ animation: shroom-popup 0.7s cubic-bezier(.34,1.56,.64,1) both,
137
+ poison-pulse 1.2s ease-in-out infinite 0.7s;
138
+ filter: drop-shadow(0 0 18px rgba(255,62,91,.9));
139
+ }
140
+ .state-danger .myco-player {
141
+ animation: myco-bob 2.4s ease-in-out infinite,
142
+ myco-recoil 0.5s ease both;
143
+ }
144
+ @keyframes poison-pulse {
145
+ 0%,100%{ filter:drop-shadow(0 0 10px rgba(255,62,91,.6)); }
146
+ 50% { filter:drop-shadow(0 0 28px rgba(255,62,91,1)); }
147
+ }
148
+ @keyframes myco-recoil {
149
+ 0% { transform:translateX(0); }
150
+ 30% { transform:translateX(-1.2rem); }
151
+ 60% { transform:translateX(.4rem); }
152
+ 100%{ transform:translateX(0); }
153
+ }
154
+
155
+ /* โ”€โ”€ STATE: game over โ”€โ”€ */
156
+ .state-game-over .forest-scene,
157
+ .state-game-over {
158
+ animation: screen-shake .45s ease both;
159
+ background:
160
+ radial-gradient(circle at 50% 72%, rgba(255,62,91,.35), transparent 8rem),
161
+ linear-gradient(180deg,#3b0a0a 0%,#6b1a1a 54%,#2a0a0a 100%) !important;
162
+ }
163
+ .state-game-over .mushroom-sprite {
164
+ animation: shroom-explode .6s ease both;
165
+ filter: drop-shadow(0 0 24px rgba(255,62,91,1));
166
+ }
167
+ .state-game-over .myco-player {
168
+ animation: myco-fall .6s ease both;
169
+ }
170
+ @keyframes screen-shake {
171
+ 0%,100%{ transform:translateX(0); }
172
+ 20% { transform:translateX(-8px); }
173
+ 40% { transform:translateX(8px); }
174
+ 60% { transform:translateX(-5px); }
175
+ 80% { transform:translateX(5px); }
176
+ }
177
+ @keyframes shroom-explode {
178
+ 0% { transform:scale(1) rotate(0); opacity:1; }
179
+ 50% { transform:scale(1.8) rotate(20deg); opacity:.8; }
180
+ 100%{ transform:scale(0) rotate(90deg); opacity:0; }
181
+ }
182
+ @keyframes myco-fall {
183
+ 0% { transform:rotate(0) translateY(0); opacity:1; }
184
+ 100%{ transform:rotate(-90deg) translateY(2rem); opacity:.4; }
185
+ }
186
+
187
+ /* โ”€โ”€ Rarity glows โ”€โ”€ */
188
+ .rarity-rare .mushroom-sprite { filter:drop-shadow(0 0 18px rgba(138,220,255,.9)); }
189
+ .rarity-legendary .mushroom-sprite{ filter:drop-shadow(0 0 28px rgba(255,215,0,1)); animation:legendary-pulse 1s ease-in-out infinite 0.7s; }
190
+ @keyframes legendary-pulse {
191
+ 0%,100%{ filter:drop-shadow(0 0 18px rgba(255,215,0,.7)); transform:scale(1); }
192
+ 50% { filter:drop-shadow(0 0 36px rgba(255,215,0,1)); transform:scale(1.1); }
193
+ }
194
+
195
+ /* โ”€โ”€ Mini map grid โ”€โ”€ */
196
+ .forest-map {
197
+ display:grid; grid-template-columns:repeat(3,1fr);
198
+ gap:.3rem; margin:.4rem auto .6rem;
199
+ max-width:9rem; padding:.4rem;
200
+ border:1px solid rgba(255,255,255,.18); border-radius:14px;
201
+ background:rgba(13,38,28,.58);
202
+ }
203
+ .map-tile {
204
+ display:grid; min-height:1.7rem; place-items:center;
205
+ border-radius:8px; background:rgba(255,255,255,.1); font-weight:900;
206
+ }
207
+ .map-tile.active { background:rgba(255,224,138,.92); color:#3d2c00!important; }
208
+
209
+ /* โ”€โ”€ Caption โ”€โ”€ */
210
+ .scene-caption {
211
+ display:flex; justify-content:space-between; gap:.6rem;
212
+ padding:.55rem .8rem; border-radius:14px;
213
+ background:rgba(13,38,28,.68); backdrop-filter:blur(6px);
214
+ align-items:center;
215
+ }
216
+ .scene-caption span { color:#d9f4d4; }
217
+
218
+ /* โ”€โ”€ Score burst โ”€โ”€ */
219
+ .score-burst {
220
+ margin:.65rem auto 0; max-width:520px;
221
+ padding:.5rem .85rem; border-radius:999px;
222
+ background:rgba(255,224,112,.18); border:1px solid rgba(255,244,190,.36);
223
+ color:#fff7d6; font-weight:900; text-align:center;
224
+ animation:score-pop .56s ease both;
225
+ }
226
+ @keyframes score-pop {
227
+ 0%{transform:scale(.92);opacity:0;}
228
+ 45%{transform:scale(1.06);opacity:1;}
229
+ 100%{transform:scale(1);opacity:1;}
230
+ }
231
+ .state-game-over .score-burst {
232
+ background:rgba(130,0,30,.45); border-color:rgba(255,120,140,.55);
233
+ }
234
+
235
+ /* โ”€โ”€ Story moment โ”€โ”€ */
236
+ .story-moment {
237
+ margin:.75rem auto 0; max-width:760px;
238
+ padding:.8rem 1rem; border:1px solid rgba(255,234,166,.3);
239
+ border-radius:18px; background:rgba(25,18,45,.72);
240
+ color:#fff7d6; box-shadow:0 0 24px rgba(165,111,255,.22);
241
+ }
242
+ .story-moment strong,.story-moment span { display:block; }
243
+ .story-moment span { margin-top:.2rem; color:#f6e7b2; }
244
+
245
+ /* โ”€โ”€ Suppress Gradio white flash โ”€โ”€ */
246
+ .generating .forest-scene, .pending .forest-scene { opacity:.88!important; }
247
+ .progress-level,.progress-level-inner { display:none!important; }
248
+ div.gradio-html { background:transparent!important; }
249
+ .wrap.default.pending,.wrap.default.generating { background:transparent!important; }
250
+ </style>
251
+ """
252
 
253
  def hero_markdown() -> str:
254
+ return """
255
+ <div class="myco-hero">
256
+ <div class="myco-mascot">๐Ÿ„</div>
257
+ <div>
258
+ <p class="eyebrow">Tiny AI forest game</p>
259
+ <h1>Myco</h1>
260
+ <p>Follow an AI mushroom companion through a glowing forest. Every discovery starts with Myco's intuition.</p>
261
+ </div>
262
+ </div>
263
+ """
264
 
265
  def home_forest_markdown() -> str:
266
+ return """
267
+ <div class="home-forest-postcard" aria-label="Animated Myco forest postcard">
268
+ <div class="home-sky">
269
+ <span class="home-milky-way" title="Milky Way">๐ŸŒŒ</span>
270
+ <span class="home-star star-one">โœจ</span>
271
+ <span class="home-star star-two">โœฆ</span>
272
+ <span class="home-star star-three">โœง</span>
273
+ </div>
274
+ <div class="home-forest-floor">
275
+ <span class="home-tree left">๐ŸŒฒ</span>
276
+ <span class="home-grass grass-left">๐ŸŒฟ</span>
277
+ <span class="home-myco" title="Myco">๐Ÿ„</span>
278
+ <span class="home-brown-mushroom" title="Brown mushroom">๐Ÿ„โ€๐ŸŸซ</span>
279
+ <span class="home-grass grass-right">๐Ÿƒ</span>
280
+ <span class="home-tree right">๐ŸŒณ</span>
281
+ <span class="home-moon">๐ŸŒ–</span>
282
+ </div>
283
+ <p><strong>The Milky Way is awake.</strong> Myco hears a brown mushroom whispering your first clue.</p>
284
+ <span class="home-whisper">"Tap Play. Let's find what the forest is hiding."</span>
285
+ </div>
286
+ """
287
 
288
  def play_hook_markdown() -> str:
289
+ return """
290
+ <div class="play-hook">
291
+ <p class="eyebrow">Mission</p>
292
+ <h2>Goal: follow clues until Myco remembers the Impossible Mushroom.</h2>
293
+ <div class="hook-steps">
294
+ <span>1 ยท Move through the forest</span>
295
+ <span>2 ยท Search Clearing โ€” mushroom pops up!</span>
296
+ <span>3 ยท Myco reacts ยท Pick, Study, or Follow Whisper</span>
297
+ </div>
298
+ <p>Every clue advances one mystery. Follow whispers to reveal why the MycoDex is regrowing a forest that vanished.</p>
299
+ </div>
300
+ """
301
 
302
+ def forest_scene(
303
+ current: MushroomState | None,
304
+ collection: CollectionState | None,
305
+ position: tuple[int, int] | None = None,
306
+ ) -> str:
307
+ count = len(_safe_collection(collection))
308
+ area = current_area(count)
309
  pos_x, pos_y = _safe_position(position)
310
  pos_cls = f"pos-{pos_x}-{pos_y}"
311
+
312
  if current is None:
313
+ mushroom_name = "Hidden mushroom"
314
+ rarity = "common"
315
+ sprite = "โœจ"
316
+ status = "The moss is listening. Click Search Clearing to wake the forest."
317
+ omen = "Myco is waiting to sense the first spore."
318
+ event_label = "๐ŸŒŒ Dreaming Forest"
319
+ encounter = "The next clearing may reveal a memory, creature, or poison omen."
320
+ mystery_label = "The Wrong Memory"
321
+ score_total = "0"
322
+ health = "3"
323
+ reward_text = "Search a clearing to score spores."
324
+ state_cls = "state-waiting"
325
  else:
326
  mushroom_name = current.get("name", "Mystery mushroom")
327
+ rarity = current.get("rarity", "Common").lower()
328
+ sprite = "๐Ÿ„โ€๐ŸŸซ"
329
+ game_over = current.get("game_over") == "Yes"
330
+ studied = current.get("studied") == "Yes"
331
+ event_label = f"{current.get('event_emoji','โœจ')} {current.get('event_title','Strange Omen')}"
332
+ encounter = current.get("encounter", "The forest waits for Myco's reaction.")
333
+ mystery_label = current.get("mystery_title", "The Wrong Memory")
334
+ score_total = current.get("score_total", "0")
335
+ health = current.get("health", "3")
336
+ reward_text = current.get("reward_text", "Decide whether to risk the pickup.")
337
+ state_cls = _scene_state_class(current)
338
+ status = f"A {rarity} {mushroom_name} breaks through the moss!"
339
+ if game_over:
340
+ status = f"๐Ÿ’€ GAME OVER: {mushroom_name} was poisonous!"
341
  omen = "New field note unlocked." if studied else "Ask Myco what the forest is hiding."
342
+ if current.get("picked") == "Yes":
343
+ omen = "โœ… Picked! Move to the next clearing."
344
+ if game_over:
345
+ omen = "Press Search Clearing to start a new run."
346
+
347
+ # Unique key forces browser to re-run CSS animations on every render
348
+ import time
349
  anim_key = str(int(time.time() * 1000))[-6:]
 
350
 
351
+ return f'''{SCENE_STYLES}
352
+ <div class="forest-scene rarity-{escape(rarity)} {pos_cls} {state_cls}" data-key="{anim_key}">
353
+ <div class="scene-hud">
354
+ <span>๐Ÿงญ {escape(area.name)}</span>
355
+ <span>๐ŸŽฎ ({pos_x+1},{pos_y+1})</span>
356
+ <span>๐Ÿ“– {count} found</span>
357
+ <span>โญ {escape(score_total)}</span>
358
+ <span>โค๏ธ {escape(health)}/3</span>
359
+ <span>{escape(event_label)}</span>
360
+ <span>๐Ÿงฉ {escape(mystery_label)}</span>
361
+ </div>
362
+
363
+ <div class="scene-stage" aria-label="Magical forest scene">
364
+ <span class="tree tree-left">๐ŸŒฒ</span>
365
+ <span class="tree tree-right">๐ŸŒณ</span>
366
+ <span class="grass grass-one">๐ŸŒฟ</span>
367
+ <span class="grass grass-two">๐Ÿƒ</span>
368
+ <span class="myco-player" title="Myco">๐Ÿ„</span>
369
+ <span class="mushroom-sprite" title="{escape(mushroom_name)}">{sprite if current else "โœจ"}</span>
370
+ <span class="sparkle sparkle-one">โœจ</span>
371
+ <span class="sparkle sparkle-two">โœฆ</span>
372
+ </div>
373
+
374
+ <div class="forest-map" aria-label="Forest grid">
375
+ {_movement_tiles(pos_x, pos_y)}
376
+ </div>
377
+
378
+ <div class="scene-caption">
379
+ <strong>{escape(status)}</strong>
380
+ <span>{escape(omen)}</span>
381
+ </div>
382
+ <div class="score-burst" aria-live="polite">{escape(reward_text)}</div>
383
+ <div class="story-moment">
384
+ <strong>{escape(event_label)}</strong>
385
+ <span>{escape(encounter)}</span>
386
+ </div>
387
+ </div>
388
+ '''
389
 
390
  def _safe_position(position):
391
  if position is None:
 
591
  </p>
592
  </div>
593
  """
594
+
595
+ def get_emerging_mushroom_html(name: str) -> str:
596
+ """
597
+ Generates a unique procedural mushroom sprite for the emerging state.
598
+ Uses the name hash to determine color and hue shift.
599
+ """
600
+ hash_val = int(hashlib.md5(name.encode('utf-8')).hexdigest(), 16)
601
+
602
+ # Procedural color logic based on the name
603
+ hue = (hash_val % 360)
604
+ saturation = 60 + (hash_val % 30)
605
+ lightness = 40 + (hash_val % 20)
606
 
607
+ # This generates the HTML sprite using a CSS filter for consistent color variety
608
+ return (
609
+ f'<div class="mushroom-sprite" '
610
+ f'style="filter: hue-rotate({hue}deg) saturate({saturation}%) brightness({lightness}%); '
611
+ f'display: inline-block; transition: transform 0.3s ease;" '
612
+ f'title="{escape(name)}">๐Ÿ„</div>'
613
+ )