File size: 25,507 Bytes
ffe328b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
import { Project } from '../types';

export const SAMPLE_PROJECTS: Project[] = [
  {
    id: 'cyberpunk-pomodoro',
    name: 'Cyberpunk Synthwave Pomodoro',
    description: 'A neon-infused productivity timer with procedural Web Audio sound synthesis, task tracker, and particle ambience.',
    createdAt: Date.now() - 86400000 * 2,
    updatedAt: Date.now() - 86400000,
    activeFileId: 'pomo-html',
    files: [
      {
        id: 'pomo-html',
        name: 'index.html',
        path: '/index.html',
        language: 'html',
        content: `<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Cyberpunk Synthwave Pomodoro</title>
  <script src="https://cdn.tailwindcss.com"></script>
  <link href="https://fonts.googleapis.com/css2?family=Orbitron:wght@400;700;900&family=Share+Tech+Mono&display=swap" rel="stylesheet">
  <link rel="stylesheet" href="style.css">
</head>
<body class="bg-[#0b0c16] text-[#00f3ff] min-h-screen flex flex-col items-center justify-center p-4 selection:bg-[#ff007f] selection:text-white">
  <div class="relative w-full max-w-md bg-[#121424]/90 border border-[#00f3ff]/30 rounded-2xl p-6 shadow-[0_0_50px_rgba(0,243,255,0.15)] backdrop-blur-xl">
    
    <!-- Header -->
    <div class="flex items-center justify-between border-b border-[#00f3ff]/20 pb-4 mb-6">
      <div class="flex items-center gap-2">
        <span class="w-3 h-3 rounded-full bg-[#ff007f] shadow-[0_0_10px_#ff007f]"></span>
        <h1 class="font-['Orbitron'] tracking-widest text-lg font-bold text-white uppercase">VIBE_POMO // V2.0</h1>
      </div>
      <span id="session-count" class="text-xs font-mono text-[#ff007f] bg-[#ff007f]/10 px-2.5 py-1 rounded-full border border-[#ff007f]/30">CYCLE #1</span>
    </div>

    <!-- Timer Ring Display -->
    <div class="relative flex flex-col items-center justify-center my-6">
      <svg class="w-64 h-64 -rotate-90">
        <circle cx="128" cy="128" r="110" stroke="rgba(0,243,255,0.1)" stroke-width="8" fill="none" />
        <circle id="progress-circle" cx="128" cy="128" r="110" stroke="#00f3ff" stroke-width="8" stroke-dasharray="691" stroke-dashoffset="0" stroke-linecap="round" fill="none" class="transition-all duration-300" />
      </svg>
      <div class="absolute flex flex-col items-center">
        <span id="timer-display" class="font-['Orbitron'] text-5xl font-black text-white tracking-wider drop-shadow-[0_0_20px_#00f3ff]">25:00</span>
        <span id="mode-display" class="text-xs font-['Share_Tech_Mono'] uppercase tracking-widest text-[#ff007f] mt-2">FOCUS SEQUENCE</span>
      </div>
    </div>

    <!-- Controls -->
    <div class="flex items-center justify-center gap-4 mb-6">
      <button id="toggle-btn" class="px-8 py-3 rounded-xl bg-gradient-to-r from-[#00f3ff] to-[#00a8ff] text-slate-950 font-['Orbitron'] font-bold text-sm tracking-wider uppercase shadow-[0_0_25px_rgba(0,243,255,0.4)] hover:shadow-[0_0_35px_rgba(0,243,255,0.7)] hover:scale-105 active:scale-95 transition-all cursor-pointer">START</button>
      <button id="reset-btn" class="px-5 py-3 rounded-xl bg-slate-900 border border-slate-700 text-slate-300 hover:text-white hover:border-[#ff007f] hover:shadow-[0_0_15px_rgba(255,0,127,0.3)] transition-all cursor-pointer font-['Share_Tech_Mono']">RESET</button>
      <button id="mode-btn" class="px-4 py-3 rounded-xl bg-slate-900 border border-slate-700 text-slate-300 hover:text-[#00f3ff] hover:border-[#00f3ff] transition-all cursor-pointer font-['Share_Tech_Mono'] text-xs">SWITCH</button>
    </div>

    <!-- Quick Audio Synth Test & Matrix Tasks -->
    <div class="border-t border-[#00f3ff]/20 pt-4">
      <div class="flex items-center justify-between text-xs text-slate-400 font-mono mb-2">
        <span>TASK MATRIX</span>
        <button id="audio-test" class="text-[#00f3ff] hover:underline cursor-pointer">🔊 TEST BEEP</button>
      </div>
      <div class="flex gap-2">
        <input id="task-input" type="text" placeholder="Add protocol objective..." class="flex-1 bg-slate-950/80 border border-slate-800 rounded-lg px-3 py-2 text-xs text-white focus:outline-none focus:border-[#00f3ff]">
        <button id="add-task-btn" class="px-3 py-2 rounded-lg bg-[#00f3ff]/10 text-[#00f3ff] border border-[#00f3ff]/30 text-xs font-bold hover:bg-[#00f3ff]/20 cursor-pointer">ADD</button>
      </div>
      <ul id="task-list" class="mt-3 space-y-1.5 max-h-32 overflow-y-auto">
        <li class="flex items-center justify-between bg-slate-950/40 px-3 py-1.5 rounded text-xs text-slate-300 border border-slate-800/80">
          <span>⚡ Calibrate RiShre Vibe Models</span>
          <span class="text-xs text-[#00f3ff]">IN PROGRESS</span>
        </li>
      </ul>
    </div>
  </div>

  <script src="app.js"></script>
</body>
</html>`
      },
      {
        id: 'pomo-css',
        name: 'style.css',
        path: '/style.css',
        language: 'css',
        content: `/* Cyberpunk scanlines and custom styles */
body::before {
  content: " ";
  display: block;
  position: fixed;
  top: 0; left: 0; bottom: 0; right: 0;
  background: linear-gradient(rgba(18, 16, 16, 0) 50%, rgba(0, 0, 0, 0.25) 50%), linear-gradient(90deg, rgba(255, 0, 0, 0.03), rgba(0, 255, 0, 0.01), rgba(0, 0, 255, 0.03));
  z-index: 99;
  background-size: 100% 3px, 3px 100%;
  pointer-events: none;
}

#progress-circle {
  transition: stroke-dashoffset 0.8s ease-in-out;
}

button:focus-visible {
  outline: 2px solid #00f3ff;
  outline-offset: 2px;
}`
      },
      {
        id: 'pomo-js',
        name: 'app.js',
        path: '/app.js',
        language: 'javascript',
        content: `// Cyberpunk Pomodoro State Machine with Web Audio API Sound Generator
const FOCUS_TIME = 25 * 60;
const BREAK_TIME = 5 * 60;
const CIRCLE_CIRCUMFERENCE = 691;

let timeLeft = FOCUS_TIME;
let totalTime = FOCUS_TIME;
let isRunning = false;
let isFocusMode = true;
let timerInterval = null;
let completedCycles = 0;

const timerDisplay = document.getElementById('timer-display');
const modeDisplay = document.getElementById('mode-display');
const toggleBtn = document.getElementById('toggle-btn');
const resetBtn = document.getElementById('reset-btn');
const modeBtn = document.getElementById('mode-btn');
const progressCircle = document.getElementById('progress-circle');
const sessionCount = document.getElementById('session-count');
const audioTestBtn = document.getElementById('audio-test');
const taskInput = document.getElementById('task-input');
const addTaskBtn = document.getElementById('add-task-btn');
const taskList = document.getElementById('task-list');

// Procedural Synth Sound Generator using Web Audio API
function playSynthChime(frequency = 880, type = 'sine', duration = 0.2) {
  try {
    const AudioCtx = window.AudioContext || window.webkitAudioContext;
    if (!AudioCtx) return;
    const ctx = new AudioCtx();
    const osc = ctx.createOscillator();
    const gain = ctx.createGain();
    osc.type = type;
    osc.frequency.setValueAtTime(frequency, ctx.currentTime);
    gain.gain.setValueAtTime(0.15, ctx.currentTime);
    gain.gain.exponentialRampToValueAtTime(0.001, ctx.currentTime + duration);
    osc.connect(gain);
    gain.connect(ctx.destination);
    osc.start();
    osc.stop(ctx.currentTime + duration);
  } catch (e) {
    console.warn('Audio not allowed yet:', e);
  }
}

function updateDisplay() {
  const mins = Math.floor(timeLeft / 60);
  const secs = timeLeft % 60;
  timerDisplay.textContent = \`\${String(mins).padStart(2, '0')}:\${String(secs).padStart(2, '0')}\`;
  
  const fraction = timeLeft / totalTime;
  const offset = CIRCLE_CIRCUMFERENCE * (1 - fraction);
  progressCircle.style.strokeDashoffset = offset;
}

function toggleTimer() {
  if (isRunning) {
    clearInterval(timerInterval);
    isRunning = false;
    toggleBtn.textContent = 'RESUME';
    playSynthChime(440, 'triangle', 0.1);
  } else {
    isRunning = true;
    toggleBtn.textContent = 'PAUSE';
    playSynthChime(660, 'sine', 0.15);
    timerInterval = setInterval(() => {
      if (timeLeft > 0) {
        timeLeft--;
        updateDisplay();
      } else {
        handleTimerComplete();
      }
    }, 1000);
  }
}

function handleTimerComplete() {
  clearInterval(timerInterval);
  isRunning = false;
  
  // Victory multi-tone chime
  playSynthChime(880, 'sine', 0.2);
  setTimeout(() => playSynthChime(1320, 'sine', 0.3), 150);

  if (isFocusMode) {
    completedCycles++;
    sessionCount.textContent = \`CYCLE #\${completedCycles + 1}\`;
    switchMode(false);
  } else {
    switchMode(true);
  }
}

function resetTimer() {
  clearInterval(timerInterval);
  isRunning = false;
  timeLeft = totalTime;
  toggleBtn.textContent = 'START';
  updateDisplay();
  playSynthChime(330, 'square', 0.08);
}

function switchMode(toFocus = !isFocusMode) {
  isFocusMode = toFocus;
  if (isFocusMode) {
    totalTime = FOCUS_TIME;
    timeLeft = FOCUS_TIME;
    modeDisplay.textContent = 'FOCUS SEQUENCE';
    modeDisplay.className = 'text-xs font-mono uppercase tracking-widest text-[#ff007f] mt-2';
    progressCircle.setAttribute('stroke', '#00f3ff');
  } else {
    totalTime = BREAK_TIME;
    timeLeft = BREAK_TIME;
    modeDisplay.textContent = 'RECHARGE INTERVAL';
    modeDisplay.className = 'text-xs font-mono uppercase tracking-widest text-[#00ff66] mt-2';
    progressCircle.setAttribute('stroke', '#00ff66');
  }
  resetTimer();
}

toggleBtn.addEventListener('click', toggleTimer);
resetBtn.addEventListener('click', resetTimer);
modeBtn.addEventListener('click', () => switchMode());
audioTestBtn.addEventListener('click', () => playSynthChime(880, 'sine', 0.25));

addTaskBtn.addEventListener('click', () => {
  const text = taskInput.value.trim();
  if (!text) return;
  const li = document.createElement('li');
  li.className = 'flex items-center justify-between bg-slate-950/40 px-3 py-1.5 rounded text-xs text-slate-300 border border-slate-800/80 cursor-pointer hover:border-[#00f3ff]/40';
  li.innerHTML = \`<span>⚡ \${text}</span><span class="text-xs text-slate-500 hover:text-[#ff007f]">✕</span>\`;
  li.querySelector('span:last-child').addEventListener('click', (e) => {
    e.stopPropagation();
    li.remove();
  });
  taskList.appendChild(li);
  taskInput.value = '';
  playSynthChime(550, 'sine', 0.08);
});

updateDisplay();
console.log('RiShre Cyberpunk Pomodoro ready.');`
      }
    ]
  },
  {
    id: 'glass-calculator',
    name: 'Glassmorphic Scientific Calculator',
    description: 'A frosted glass calculator featuring scientific math operations, calculation history tape, and haptic animations.',
    createdAt: Date.now() - 86400000 * 4,
    updatedAt: Date.now() - 86400000 * 2,
    activeFileId: 'calc-html',
    files: [
      {
        id: 'calc-html',
        name: 'index.html',
        path: '/index.html',
        language: 'html',
        content: `<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Glassmorphic Calculator</title>
  <script src="https://cdn.tailwindcss.com"></script>
  <link rel="stylesheet" href="style.css">
</head>
<body class="bg-gradient-to-br from-indigo-950 via-slate-900 to-purple-950 min-h-screen flex items-center justify-center p-4 text-white">
  
  <div class="w-full max-w-sm rounded-3xl p-6 bg-slate-900/60 border border-white/10 shadow-[0_8px_32px_0_rgba(0,0,0,0.4)] backdrop-blur-xl flex flex-col gap-4">
    
    <!-- Top Bar -->
    <div class="flex items-center justify-between text-xs text-slate-400 font-medium">
      <div class="flex items-center gap-1.5">
        <span class="w-2.5 h-2.5 rounded-full bg-emerald-400"></span>
        <span class="tracking-wider uppercase">RiShre Calc</span>
      </div>
      <button id="toggle-sci" class="hover:text-cyan-400 transition-colors cursor-pointer">SCI [EXP]</button>
    </div>

    <!-- Screen -->
    <div class="bg-black/30 border border-white/5 rounded-2xl p-4 flex flex-col justify-end text-right min-h-[100px]">
      <div id="history-display" class="text-xs text-slate-400 font-mono tracking-wider h-5 overflow-hidden"></div>
      <div id="main-display" class="text-4xl font-mono font-bold tracking-tight text-white mt-1 break-all">0</div>
    </div>

    <!-- Keypad -->
    <div id="keypad" class="grid grid-cols-4 gap-2.5 text-sm font-medium">
      <!-- Row 1 -->
      <button data-action="clear" class="btn-ctrl col-span-2 bg-rose-500/20 text-rose-300 border border-rose-500/30">AC</button>
      <button data-action="delete" class="btn-ctrl bg-slate-800/60 text-slate-300 border border-white/5">DEL</button>
      <button data-action="op" data-value="/" class="btn-op bg-indigo-500/20 text-cyan-300 border border-cyan-500/20">÷</button>

      <!-- Row 2 -->
      <button data-value="7" class="btn-num">7</button>
      <button data-value="8" class="btn-num">8</button>
      <button data-value="9" class="btn-num">9</button>
      <button data-action="op" data-value="*" class="btn-op bg-indigo-500/20 text-cyan-300 border border-cyan-500/20">×</button>

      <!-- Row 3 -->
      <button data-value="4" class="btn-num">4</button>
      <button data-value="5" class="btn-num">5</button>
      <button data-value="6" class="btn-num">6</button>
      <button data-action="op" data-value="-" class="btn-op bg-indigo-500/20 text-cyan-300 border border-cyan-500/20">−</button>

      <!-- Row 4 -->
      <button data-value="1" class="btn-num">1</button>
      <button data-value="2" class="btn-num">2</button>
      <button data-value="3" class="btn-num">3</button>
      <button data-action="op" data-value="+" class="btn-op bg-indigo-500/20 text-cyan-300 border border-cyan-500/20">+</button>

      <!-- Row 5 -->
      <button data-value="0" class="btn-num col-span-2">0</button>
      <button data-value="." class="btn-num">.</button>
      <button data-action="equals" class="btn-eq bg-gradient-to-r from-cyan-500 to-indigo-500 text-slate-950 font-bold shadow-[0_0_20px_rgba(6,182,212,0.4)]">=</button>
    </div>

    <!-- Scientific Drawer (Hidden by default) -->
    <div id="sci-panel" class="hidden grid grid-cols-3 gap-2 pt-2 border-t border-white/5 text-xs">
      <button data-action="sci" data-value="sin" class="btn-sci">sin</button>
      <button data-action="sci" data-value="cos" class="btn-sci">cos</button>
      <button data-action="sci" data-value="tan" class="btn-sci">tan</button>
      <button data-action="sci" data-value="sqrt" class="btn-sci">√x</button>
      <button data-action="sci" data-value="pow" class="btn-sci">x²</button>
      <button data-action="sci" data-value="pi" class="btn-sci">π</button>
    </div>
  </div>

  <script src="app.js"></script>
</body>
</html>`
      },
      {
        id: 'calc-css',
        name: 'style.css',
        path: '/style.css',
        language: 'css',
        content: `button {
  height: 52px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease-out;
  cursor: pointer;
  user-select: none;
}

button:active {
  transform: scale(0.94);
}

.btn-num {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: #f8fafc;
}

.btn-num:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-ctrl:hover, .btn-op:hover, .btn-sci:hover {
  filter: brightness(1.2);
}

.btn-sci {
  height: 38px;
  background: rgba(14, 165, 233, 0.1);
  border: 1px solid rgba(14, 165, 233, 0.2);
  color: #38bdf8;
}`
      },
      {
        id: 'calc-js',
        name: 'app.js',
        path: '/app.js',
        language: 'javascript',
        content: `// Glassmorphic Calculator Engine
let currentInput = '0';
let previousInput = '';
let currentOp = null;
let shouldResetDisplay = false;

const mainDisplay = document.getElementById('main-display');
const historyDisplay = document.getElementById('history-display');
const keypad = document.getElementById('keypad');
const sciPanel = document.getElementById('sci-panel');
const toggleSciBtn = document.getElementById('toggle-sci');

function updateDisplay() {
  mainDisplay.textContent = currentInput;
  if (currentOp && previousInput) {
    historyDisplay.textContent = \`\${previousInput} \${currentOp}\`;
  } else {
    historyDisplay.textContent = '';
  }
}

function handleNumber(num) {
  if (shouldResetDisplay) {
    currentInput = num;
    shouldResetDisplay = false;
  } else {
    if (num === '.' && currentInput.includes('.')) return;
    currentInput = currentInput === '0' && num !== '.' ? num : currentInput + num;
  }
  updateDisplay();
}

function handleOperator(op) {
  if (currentOp && !shouldResetDisplay) {
    calculate();
  }
  previousInput = currentInput;
  currentOp = op;
  shouldResetDisplay = true;
  updateDisplay();
}

function calculate() {
  if (!currentOp || shouldResetDisplay) return;
  const prev = parseFloat(previousInput);
  const curr = parseFloat(currentInput);
  let result = 0;

  switch (currentOp) {
    case '+': result = prev + curr; break;
    case '-': result = prev - curr; break;
    case '*': result = prev * curr; break;
    case '/': 
      if (curr === 0) {
        currentInput = 'Error';
        currentOp = null;
        updateDisplay();
        return;
      }
      result = prev / curr;
      break;
    default: return;
  }

  currentInput = String(Number(result.toFixed(8)));
  currentOp = null;
  shouldResetDisplay = true;
  updateDisplay();
}

function handleScientific(func) {
  const val = parseFloat(currentInput);
  let res = 0;
  switch (func) {
    case 'sin': res = Math.sin(val); break;
    case 'cos': res = Math.cos(val); break;
    case 'tan': res = Math.tan(val); break;
    case 'sqrt': res = Math.sqrt(val); break;
    case 'pow': res = Math.pow(val, 2); break;
    case 'pi': res = Math.PI; break;
  }
  currentInput = String(Number(res.toFixed(8)));
  shouldResetDisplay = true;
  updateDisplay();
}

keypad.addEventListener('click', (e) => {
  const btn = e.target.closest('button');
  if (!btn) return;

  const action = btn.dataset.action;
  const value = btn.dataset.value;

  if (!action && value) {
    handleNumber(value);
  } else if (action === 'op') {
    handleOperator(value);
  } else if (action === 'equals') {
    calculate();
  } else if (action === 'clear') {
    currentInput = '0';
    previousInput = '';
    currentOp = null;
    shouldResetDisplay = false;
    updateDisplay();
  } else if (action === 'delete') {
    currentInput = currentInput.length > 1 ? currentInput.slice(0, -1) : '0';
    updateDisplay();
  }
});

sciPanel.addEventListener('click', (e) => {
  const btn = e.target.closest('button');
  if (!btn) return;
  handleScientific(btn.dataset.value);
});

toggleSciBtn.addEventListener('click', () => {
  sciPanel.classList.toggle('hidden');
});

console.log('RiShre Glassmorphic Calculator initialized.');`
      }
    ]
  },
  {
    id: 'matrix-visualizer',
    name: 'Quantum Audio Wave Sandbox',
    description: 'An interactive canvas particle & wave simulation with generative ambient audio oscillators.',
    createdAt: Date.now() - 86400000 * 5,
    updatedAt: Date.now() - 86400000 * 3,
    activeFileId: 'wave-html',
    files: [
      {
        id: 'wave-html',
        name: 'index.html',
        path: '/index.html',
        language: 'html',
        content: `<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Quantum Wave Visualizer</title>
  <script src="https://cdn.tailwindcss.com"></script>
  <link rel="stylesheet" href="style.css">
</head>
<body class="bg-black text-cyan-400 min-h-screen overflow-hidden flex flex-col justify-between">
  <!-- HUD Top -->
  <header class="p-4 flex items-center justify-between z-10 bg-gradient-to-b from-black/80 to-transparent">
    <div>
      <h1 class="text-lg font-bold tracking-wider text-white font-mono">QUANTUM_HARMONICS // 01</h1>
      <p class="text-xs text-slate-400 font-mono">Click canvas to trigger sound harmonics</p>
    </div>
    <div class="flex items-center gap-2">
      <button id="toggle-audio" class="px-3 py-1.5 rounded-lg bg-cyan-950 border border-cyan-500/40 text-cyan-300 text-xs font-mono hover:bg-cyan-900 transition-colors">AUDIO: OFF</button>
      <button id="speed-btn" class="px-3 py-1.5 rounded-lg bg-slate-900 border border-slate-700 text-slate-300 text-xs font-mono hover:text-white">WARP: 1X</button>
    </div>
  </header>

  <!-- Canvas Surface -->
  <canvas id="stage" class="absolute inset-0 w-full h-full cursor-crosshair"></canvas>

  <!-- HUD Bottom -->
  <footer class="p-4 z-10 flex justify-between items-center text-xs text-slate-500 font-mono bg-gradient-to-t from-black/80 to-transparent">
    <span>PARTICLES: <strong id="particle-count" class="text-cyan-400">180</strong></span>
    <span>FPS: <strong id="fps-display" class="text-cyan-400">60</strong></span>
  </footer>

  <script src="app.js"></script>
</body>
</html>`
      },
      {
        id: 'wave-css',
        name: 'style.css',
        path: '/style.css',
        language: 'css',
        content: `canvas {
  touch-action: none;
}`
      },
      {
        id: 'wave-js',
        name: 'app.js',
        path: '/app.js',
        language: 'javascript',
        content: `// Quantum Particle & Harmonic Wave Canvas
const canvas = document.getElementById('stage');
const ctx = canvas.getContext('2d');
const particleCountEl = document.getElementById('particle-count');
const fpsDisplay = document.getElementById('fps-display');
const toggleAudioBtn = document.getElementById('toggle-audio');
const speedBtn = document.getElementById('speed-btn');

let width = (canvas.width = window.innerWidth);
let height = (canvas.height = window.innerHeight);
let audioEnabled = false;
let audioCtx = null;
let speedMult = 1.0;
let lastTime = performance.now();
let frameCount = 0;

window.addEventListener('resize', () => {
  width = canvas.width = window.innerWidth;
  height = canvas.height = window.innerHeight;
});

const particles = [];
const NUM_PARTICLES = 160;

for (let i = 0; i < NUM_PARTICLES; i++) {
  particles.push({
    x: Math.random() * width,
    y: Math.random() * height,
    vx: (Math.random() - 0.5) * 1.5,
    vy: (Math.random() - 0.5) * 1.5,
    radius: Math.random() * 2 + 1,
    hue: Math.random() * 60 + 170, // Cyan to Purple
  });
}

function playTone(freq = 440) {
  if (!audioEnabled) return;
  try {
    if (!audioCtx) audioCtx = new (window.AudioContext || window.webkitAudioContext)();
    if (audioCtx.state === 'suspended') audioCtx.resume();
    const osc = audioCtx.createOscillator();
    const gain = audioCtx.createGain();
    osc.frequency.setValueAtTime(freq, audioCtx.currentTime);
    gain.gain.setValueAtTime(0.1, audioCtx.currentTime);
    gain.gain.exponentialRampToValueAtTime(0.001, audioCtx.currentTime + 0.3);
    osc.connect(gain);
    gain.connect(audioCtx.destination);
    osc.start();
    osc.stop(audioCtx.currentTime + 0.3);
  } catch (e) {}
}

canvas.addEventListener('click', (e) => {
  const rect = canvas.getBoundingClientRect();
  const x = e.clientX - rect.left;
  const y = e.clientY - rect.top;
  
  for (let i = 0; i < 15; i++) {
    particles.push({
      x, y,
      vx: (Math.random() - 0.5) * 6,
      vy: (Math.random() - 0.5) * 6,
      radius: Math.random() * 3 + 1,
      hue: Math.random() * 40 + 280,
    });
  }
  playTone(220 + (y / height) * 660);
});

toggleAudioBtn.addEventListener('click', () => {
  audioEnabled = !audioEnabled;
  toggleAudioBtn.textContent = \`AUDIO: \${audioEnabled ? 'ON 🔊' : 'OFF'}\`;
  toggleAudioBtn.className = audioEnabled
    ? 'px-3 py-1.5 rounded-lg bg-cyan-500 text-slate-950 font-bold text-xs font-mono shadow-[0_0_15px_#06b6d4]'
    : 'px-3 py-1.5 rounded-lg bg-cyan-950 border border-cyan-500/40 text-cyan-300 text-xs font-mono';
  if (audioEnabled) playTone(520);
});

speedBtn.addEventListener('click', () => {
  speedMult = speedMult === 1.0 ? 2.5 : speedMult === 2.5 ? 0.5 : 1.0;
  speedBtn.textContent = \`WARP: \${speedMult}X\`;
});

function animate(now) {
  frameCount++;
  if (now - lastTime >= 1000) {
    fpsDisplay.textContent = frameCount;
    frameCount = 0;
    lastTime = now;
    particleCountEl.textContent = particles.length;
  }

  ctx.fillStyle = 'rgba(5, 7, 15, 0.25)';
  ctx.fillRect(0, 0, width, height);

  for (let i = 0; i < particles.length; i++) {
    const p = particles[i];
    p.x += p.vx * speedMult;
    p.y += p.vy * speedMult;

    if (p.x < 0 || p.x > width) p.vx *= -1;
    if (p.y < 0 || p.y > height) p.vy *= -1;

    ctx.beginPath();
    ctx.arc(p.x, p.y, p.radius, 0, Math.PI * 2);
    ctx.fillStyle = \`hsl(\${p.hue}, 90%, 65%)\`;
    ctx.fill();

    // Connect lines
    for (let j = i + 1; j < particles.length; j++) {
      const p2 = particles[j];
      const dx = p.x - p2.x;
      const dy = p.y - p2.y;
      const dist = Math.sqrt(dx * dx + dy * dy);
      if (dist < 85) {
        ctx.beginPath();
        ctx.moveTo(p.x, p.y);
        ctx.lineTo(p2.x, p2.y);
        ctx.strokeStyle = \`hsla(\${p.hue}, 90%, 65%, \${1 - dist / 85})\`;
        ctx.lineWidth = 0.6;
        ctx.stroke();
      }
    }
  }

  // Cap particles
  if (particles.length > 250) {
    particles.splice(0, particles.length - 250);
  }

  requestAnimationFrame(animate);
}

requestAnimationFrame(animate);
console.log('Quantum Sandbox active.');`
      }
    ]
  }
];