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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Voxel Red Panda</title>
  <style>
    * { box-sizing: border-box; }
    html, body {
      width: 100%;
      height: 100%;
      margin: 0;
      overflow: hidden;
      background: #10251d;
      font-family: system-ui, sans-serif;
    }
    canvas {
      display: block;
      width: 100%;
      height: 100%;
      touch-action: none;
      cursor: grab;
    }
    canvas:active { cursor: grabbing; }
    .title {
      position: fixed;
      top: 22px;
      left: 24px;
      color: #f4f0d5;
      text-shadow: 0 2px 12px rgba(0,0,0,.45);
      pointer-events: none;
      user-select: none;
    }
    .title h1 {
      margin: 0 0 5px;
      font-size: clamp(22px, 4vw, 38px);
      letter-spacing: .04em;
    }
    .title p {
      margin: 0;
      font-size: 13px;
      opacity: .8;
    }
    .hint {
      position: fixed;
      right: 20px;
      bottom: 18px;
      padding: 8px 12px;
      border: 1px solid rgba(255,255,255,.18);
      border-radius: 999px;
      color: rgba(255,255,255,.78);
      background: rgba(0,0,0,.18);
      backdrop-filter: blur(8px);
      font-size: 12px;
      pointer-events: none;
      user-select: none;
    }
  </style>
</head>
<body>
  <div class="title">
    <h1>Red Panda</h1>
    <p>A quiet moment in the forest</p>
  </div>
  <div class="hint">Drag to orbit · Scroll to zoom · Double-click to reset</div>

  <script type="module">
    import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";

    const scene = new THREE.Scene();
    scene.background = new THREE.Color(0x17372b);
    scene.fog = new THREE.FogExp2(0x17372b, 0.065);

    const camera = new THREE.PerspectiveCamera(42, innerWidth / innerHeight, 0.1, 100);

    const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: false });
    renderer.setSize(innerWidth, innerHeight);
    renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
    renderer.shadowMap.enabled = true;
    renderer.shadowMap.type = THREE.PCFSoftShadowMap;
    renderer.outputColorSpace = THREE.SRGBColorSpace;
    renderer.toneMapping = THREE.ACESFilmicToneMapping;
    renderer.toneMappingExposure = 1.15;
    document.body.appendChild(renderer.domElement);

    const hemi = new THREE.HemisphereLight(0xc8e6cf, 0x263022, 2.1);
    scene.add(hemi);

    const sun = new THREE.DirectionalLight(0xffe5b5, 3.1);
    sun.position.set(-5, 10, 7);
    sun.castShadow = true;
    sun.shadow.mapSize.set(2048, 2048);
    sun.shadow.camera.left = -10;
    sun.shadow.camera.right = 10;
    sun.shadow.camera.top = 10;
    sun.shadow.camera.bottom = -10;
    sun.shadow.camera.near = 1;
    sun.shadow.camera.far = 30;
    sun.shadow.bias = -0.0004;
    scene.add(sun);

    const rim = new THREE.DirectionalLight(0x9bd4b7, 1.25);
    rim.position.set(6, 5, -6);
    scene.add(rim);

    const materials = {
      fur: new THREE.MeshStandardMaterial({ color: 0xb84b2d, roughness: 0.88, flatShading: true }),
      furDark: new THREE.MeshStandardMaterial({ color: 0x8c321f, roughness: 0.9, flatShading: true }),
      cream: new THREE.MeshStandardMaterial({ color: 0xe8cfaa, roughness: 0.9, flatShading: true }),
      creamLight: new THREE.MeshStandardMaterial({ color: 0xf1dfbd, roughness: 0.92, flatShading: true }),
      black: new THREE.MeshStandardMaterial({ color: 0x171815, roughness: 0.75, flatShading: true }),
      pink: new THREE.MeshStandardMaterial({ color: 0xc57a75, roughness: 0.95, flatShading: true }),
      wood: new THREE.MeshStandardMaterial({ color: 0x695039, roughness: 1, flatShading: true }),
      woodLight: new THREE.MeshStandardMaterial({ color: 0x8b6847, roughness: 1, flatShading: true }),
      moss: new THREE.MeshStandardMaterial({ color: 0x4f7d35, roughness: 1, flatShading: true }),
      mossLight: new THREE.MeshStandardMaterial({ color: 0x789c43, roughness: 1, flatShading: true }),
      leaf: new THREE.MeshStandardMaterial({ color: 0x315f35, roughness: 1, flatShading: true }),
      leafLight: new THREE.MeshStandardMaterial({ color: 0x4e7d42, roughness: 1, flatShading: true }),
      ground: new THREE.MeshStandardMaterial({ color: 0x283a25, roughness: 1 })
    };

    const box = new THREE.BoxGeometry(1, 1, 1);

    function block(parent, material, x, y, z, sx, sy, sz, cast = true) {
      const mesh = new THREE.Mesh(box, material);
      mesh.position.set(x, y, z);
      mesh.scale.set(sx, sy, sz);
      mesh.castShadow = cast;
      mesh.receiveShadow = true;
      parent.add(mesh);
      return mesh;
    }

    function cylinder(parent, material, radiusTop, radiusBottom, height, x, y, z, segments = 8) {
      const mesh = new THREE.Mesh(
        new THREE.CylinderGeometry(radiusTop, radiusBottom, height, segments),
        material
      );
      mesh.position.set(x, y, z);
      mesh.castShadow = true;
      mesh.receiveShadow = true;
      parent.add(mesh);
      return mesh;
    }

    // Forest floor
    const ground = new THREE.Mesh(new THREE.CircleGeometry(30, 48), materials.ground);
    ground.rotation.x = -Math.PI / 2;
    ground.position.y = -0.48;
    ground.receiveShadow = true;
    scene.add(ground);

    // Distant trunks
    const trunkMaterial = new THREE.MeshStandardMaterial({
      color: 0x3b4935, roughness: 1, flatShading: true
    });
    const trunkPositions = [
      [-6, 2.6, -7], [-3.8, 2.2, -9], [4.5, 2.8, -8],
      [7.2, 2.3, -10], [0.2, 2.0, -12], [-9, 2.8, -6]
    ];
    trunkPositions.forEach((p, i) => {
      const trunk = cylinder(scene, trunkMaterial, 0.18 + (i % 2) * 0.07, 0.28, 8, p[0], p[1], p[2], 7);
      trunk.rotation.z = Math.sin(i) * 0.04;
    });

    // Mossy horizontal branch
    const branch = cylinder(scene, materials.wood, 0.28, 0.34, 9.2, 0, 0.28, 0, 9);
    branch.rotation.z = Math.PI / 2;

    const branchTop = cylinder(scene, materials.woodLight, 0.25, 0.28, 9.0, 0, 0.42, 0, 9);
    branchTop.rotation.z = Math.PI / 2;
    branchTop.scale.set(1, 1, 0.78);

    // Small side twig
    const twig = cylinder(scene, materials.wood, 0.07, 0.11, 1.7, -2.45, 0.78, -0.12, 7);
    twig.rotation.z = -0.9;
    twig.rotation.x = 0.25;

    let seed = 17;
    function random() {
      seed = (seed * 16807) % 2147483647;
      return (seed - 1) / 2147483646;
    }

    // Moss chunks and tiny voxel moss tufts
    for (let i = 0; i < 95; i++) {
      const x = -4.2 + random() * 8.4;
      const z = -0.25 + random() * 0.5;
      const y = 0.59 + random() * 0.08;
      const s = 0.08 + random() * 0.18;
      const mat = random() > 0.5 ? materials.moss : materials.mossLight;
      block(scene, mat, x, y, z, s, s * (0.6 + random() * 0.8), s, false);
    }

    // Voxel moss clump hanging from the branch
    for (let i = 0; i < 28; i++) {
      const x = -4.2 + random() * 8.4;
      const z = -0.22 + random() * 0.12;
      const y = 0.19 - random() * 0.22;
      const s = 0.07 + random() * 0.11;
      block(scene, random() > 0.45 ? materials.moss : materials.mossLight, x, y, z, s, s * 1.6, s, false);
    }

    // Background voxel foliage
    for (let i = 0; i < 55; i++) {
      const x = -10 + random() * 20;
      const y = 2.5 + random() * 4.2;
      const z = -7 - random() * 8;
      const s = 0.35 + random() * 0.85;
      const mat = random() > 0.45 ? materials.leaf : materials.leafLight;
      block(scene, mat, x, y, z, s, s * 0.75, s, false);
    }

    // Foreground grass-like plants
    for (let i = 0; i < 35; i++) {
      const x = -7 + random() * 14;
      const z = 1.4 + random() * 5;
      const h = 0.18 + random() * 0.42;
      const mat = random() > 0.5 ? materials.leaf : materials.mossLight;
      const blade = block(scene, mat, x, -0.38 + h / 2, z, 0.08, h, 0.08, false);
      blade.rotation.z = (random() - 0.5) * 0.3;
    }

    // Red panda body
    const panda = new THREE.Group();
    scene.add(panda);

    // Rump and body
    block(panda, materials.furDark, 0, 0.86, -0.12, 1.45, 0.95, 1.15);
    block(panda, materials.fur, 0, 1.42, -0.10, 1.12, 1.12, 1.00);
    block(panda, materials.furDark, 0, 1.76, -0.28, 1.04, 0.58, 0.88);
    block(panda, materials.fur, -0.61, 1.40, -0.10, 0.32, 0.95, 0.78);
    block(panda, materials.fur, 0.61, 1.40, -0.10, 0.32, 0.95, 0.78);

    // Cream chest and belly
    block(panda, materials.cream, 0, 1.45, 0.44, 0.90, 0.92, 0.24);
    block(panda, materials.creamLight, 0, 1.26, 0.56, 0.75, 0.62, 0.10);

    // Soft shoulder tufts
    block(panda, materials.fur, -0.43, 1.88, 0.28, 0.42, 0.28, 0.28);
    block(panda, materials.fur, 0.43, 1.88, 0.28, 0.42, 0.28, 0.28);

    // Head
    block(panda, materials.fur, 0, 2.28, 0.04, 1.12, 0.88, 0.88);

    // Ears
    block(panda, materials.furDark, -0.38, 2.78, -0.04, 0.38, 0.42, 0.36);
    block(panda, materials.furDark, 0.38, 2.78, -0.04, 0.38, 0.42, 0.36);
    block(panda, materials.pink, -0.38, 2.78, 0.16, 0.20, 0.25, 0.08);
    block(panda, materials.pink, 0.38, 2.78, 0.16, 0.20, 0.25, 0.08);

    // Cream face and muzzle
    block(panda, materials.cream, 0, 2.18, 0.51, 0.88, 0.62, 0.18);
    block(panda, materials.creamLight, 0, 2.02, 0.61, 0.70, 0.30, 0.15);
    block(panda, materials.creamLight, 0, 2.00, 0.69, 0.42, 0.17, 0.12);

    // Eyes
    block(panda, materials.black, -0.25, 2.42, 0.55, 0.19, 0.21, 0.09);
    block(panda, materials.black, 0.25, 2.42, 0.55, 0.19, 0.21, 0.09);
    block(panda, materials.creamLight, -0.28, 2.45, 0.60, 0.045, 0.055, 0.025, false);
    block(panda, materials.creamLight, 0.22, 2.45, 0.60, 0.045, 0.055, 0.025, false);

    // Eyebrows
    block(panda, materials.furDark, -0.27, 2.57, 0.55, 0.24, 0.06, 0.09);
    block(panda, materials.furDark, 0.27, 2.57, 0.55, 0.24, 0.06, 0.09);

    // Nose and mouth
    block(panda, materials.black, 0, 2.08, 0.73, 0.16, 0.10, 0.09);
    block(panda, materials.black, 0, 1.99, 0.735, 0.035, 0.16, 0.025, false);
    block(panda, materials.black, -0.065, 2.00, 0.73, 0.09, 0.025, 0.025, false);
    block(panda, materials.black, 0.065, 2.00, 0.73, 0.09, 0.025, 0.025, false);

    // Whisker-like voxel dots
    for (const side of [-1, 1]) {
      for (let i = 0; i < 3; i++) {
        block(
          panda,
          materials.creamLight,
          side * (0.31 + i * 0.09),
          2.00 + i * 0.015,
          0.74,
          0.075,
          0.025,
          0.025,
          false
        );
      }
    }

    // Visible front legs and paws
    block(panda, materials.fur, -0.39, 0.96, 0.38, 0.40, 0.78, 0.50);
    block(panda, materials.fur, 0.39, 0.96, 0.38, 0.40, 0.78, 0.50);
    block(panda, materials.cream, -0.39, 0.66, 0.53, 0.43, 0.34, 0.60);
    block(panda, materials.cream, 0.39, 0.66, 0.53, 0.43, 0.34, 0.60);

    // Tiny claw details
    for (const x of [-0.39, 0.39]) {
      for (const offset of [-0.11, 0, 0.11]) {
        block(panda, materials.creamLight, x + offset, 0.67, 0.85, 0.055, 0.08, 0.055, false);
      }
    }

    // Curled striped tail
    const tail = new THREE.Group();
    panda.add(tail);

    const tailCurve = new THREE.CatmullRomCurve3([
      new THREE.Vector3(0.48, 0.72, -0.23),
      new THREE.Vector3(0.85, 0.52, 0.02),
      new THREE.Vector3(1.25, 0.54, 0.37),
      new THREE.Vector3(1.56, 0.83, 0.60),
      new THREE.Vector3(1.64, 1.18, 0.63),
      new THREE.Vector3(1.47, 1.51, 0.53),
      new THREE.Vector3(1.18, 1.66, 0.38),
      new THREE.Vector3(0.94, 1.60, 0.31),
      new THREE.Vector3(0.88, 1.42, 0.34)
    ]);

    const tailSegments = 22;
    const up = new THREE.Vector3(0, 1, 0);
    for (let i = 0; i < tailSegments; i++) {
      const t = i / (tailSegments - 1);
      const p = tailCurve.getPoint(t);
      const tangent = tailCurve.getTangent(t).normalize();
      const mat = i % 4 < 2 ? materials.fur : materials.cream;
      const segment = block(tail, mat, p.x, p.y, p.z, 0.30, 0.30, 0.42);
      segment.quaternion.setFromUnitVectors(up, tangent);
    }

    // Orbit-style controls implemented without external addons
    const target = new THREE.Vector3(0, 1.55, 0);
    const initialTarget = new THREE.Vector3(0, 1.55, 0);
    const spherical = new THREE.Spherical(8.7, 1.25, 0.12);
    const desired = {
      radius: spherical.radius,
      phi: spherical.phi,
      theta: spherical.theta
    };
    const current = { ...desired };

    let dragging = false;
    let pointerX = 0;
    let pointerY = 0;

    renderer.domElement.addEventListener("pointerdown", e => {
      dragging = true;
      pointerX = e.clientX;
      pointerY = e.clientY;
      renderer.domElement.setPointerCapture(e.pointerId);
    });

    renderer.domElement.addEventListener("pointermove", e => {
      if (!dragging) return;
      const dx = e.clientX - pointerX;
      const dy = e.clientY - pointerY;
      pointerX = e.clientX;
      pointerY = e.clientY;
      desired.theta -= dx * 0.006;
      desired.phi = THREE.MathUtils.clamp(desired.phi - dy * 0.005, 0.68, 1.48);
    });

    function endDrag(e) {
      dragging = false;
      if (e.pointerId !== undefined && renderer.domElement.hasPointerCapture(e.pointerId)) {
        renderer.domElement.releasePointerCapture(e.pointerId);
      }
    }
    renderer.domElement.addEventListener("pointerup", endDrag);
    renderer.domElement.addEventListener("pointercancel", endDrag);

    renderer.domElement.addEventListener("wheel", e => {
      e.preventDefault();
      desired.radius = THREE.MathUtils.clamp(
        desired.radius * Math.exp(e.deltaY * 0.001),
        5.4,
        14
      );
    }, { passive: false });

    renderer.domElement.addEventListener("dblclick", () => {
      target.copy(initialTarget);
      desired.radius = 8.7;
      desired.phi = 1.25;
      desired.theta = 0.12;
    });

    window.addEventListener("resize", () => {
      camera.aspect = innerWidth / innerHeight;
      camera.updateProjectionMatrix();
      renderer.setSize(innerWidth, innerHeight);
      renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
    });

    const clock = new THREE.Clock();

    function animate() {
      requestAnimationFrame(animate);
      const t = clock.getElapsedTime();
      const damping = 0.08;

      current.radius += (desired.radius - current.radius) * damping;
      current.phi += (desired.phi - current.phi) * damping;
      current.theta += (desired.theta - current.theta) * damping;

      spherical.set(current.radius, current.phi, current.theta);
      camera.position.setFromSpherical(spherical).add(target);
      camera.lookAt(target);

      // Subtle breathing motion.
      panda.position.y = Math.sin(t * 1.8) * 0.015;
      panda.rotation.y = Math.sin(t * 0.65) * 0.012;

      renderer.render(scene, camera);
    }

    animate();
  </script>
</body>
</html>