-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
684 lines (619 loc) · 30 KB
/
index.html
File metadata and controls
684 lines (619 loc) · 30 KB
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
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
<title>BottleQuiz.com</title>
<meta property="og:title" content="BottleQuiz" />
<meta property="og:description" content="Test your logic" />
<meta property="og:image" content="https://bottlequiz.com/logo_bottlequiz.png" />
<style>
:root{
--gap: 14px; /* lo ajusta JS según N */
--bsize: 120px; /* lo ajusta JS para caber sin scroll */
--brand: #60a5fa;
--green: #16a34a;
}
*{box-sizing:border-box; -webkit-tap-highlight-color: transparent;}
html,body{
height:100%;
/* Mitigar swipe-back y gestos nativos en iOS/webviews */
overscroll-behavior: none;
overscroll-behavior-x: none;
touch-action: none;
-webkit-user-drag: none;
-webkit-touch-callout: none;
}
body{
margin:0; color:#e5e7eb; overflow-x:hidden; /* capamos cualquier scroll horizontal */
background: radial-gradient(1200px 800px at 50% -240px,#0b1220,#060a14 70%,#03060d);
font-family: ui-rounded, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial;
}
/* Pantallas */
.screen{display:none; min-height:100dvh; width:100%; padding:24px 16px 72px;}
.screen.show{display:flex}
/* Start + End centradas verticalmente */
#startScreen.show, #endScreen.show{
flex-direction:column; justify-content:center; align-items:center;
}
/* Marca / títulos */
.logo{width:168px; height:168px; filter: drop-shadow(0 18px 34px rgba(0,0,0,.55)); animation: logo-float 6s ease-in-out infinite;}
@keyframes logo-float {
0%, 100% { transform: translateY(0); }
50% { transform: translateY(-8px); }
}
.title{
margin:0; font-weight:1000; font-size:clamp(2.1rem, 9vw, 3.2rem);
letter-spacing:.4px; line-height:1.02;
background: linear-gradient(90deg, #d9f99d, #a3e635, #d9f99d);
background-size: 200% auto;
-webkit-background-clip: text; background-clip: text; color: transparent;
text-shadow: 0 2px 32px rgba(163, 230, 53, .4);
animation: text-shine 5s linear infinite;
}
@keyframes text-shine {
to {
background-position: 200% center;
}
}
.subtitle{
margin:24px 0 24px; color:#cbd5e1;
font-size:clamp(1rem, 3.8vw, 1.25rem); text-align:center; max-width:720px;
}
/* Botones outline elegantes */
.btn{
height:58px; padding:0 24px; border-radius:16px; font-size:18px; font-weight:900;
cursor:pointer; background:transparent; transition:.2s transform ease, .25s box-shadow ease, .2s background ease;
border:2px solid currentColor;
}
.btn.big{height:66px; font-size:20px; padding:0 28px;}
.btn.blue{color:#a3e635;}
.btn.blue:active{background:rgba(163, 230, 53, .15);}
.btn.green{color:var(--green);}
.btn.green:disabled{opacity:.45; cursor:not-allowed;}
.btn.green:not(:disabled):active{background:rgba(22,163,74,.15);}
/* Juego */
#gameScreen{flex-direction:column; gap:14px; padding-top:10px;}
.topbar{
display:flex; align-items:center; justify-content:space-between; gap:10px;
width:100%; max-width:880px; margin:0 auto;
}
.pill{
background:rgba(17,24,39,.72); border:1px solid rgba(255,255,255,.08);
border-radius:999px; padding:10px 14px; font-size:15px; font-weight:700; color:#fff;
backdrop-filter: blur(6px);
}
.pill b{font-variant-numeric: tabular-nums; color:#fff}
.arena{
flex:1; display:flex; flex-direction:column; gap:22px; align-items:center; justify-content:center; width:100%;
}
.wrap{
width:100%; max-width:none; /* sin tope para medir W real exacto en móviles */
display:flex; flex-direction:column; gap:18px;
}
.row-bottles{
display:flex; align-items:center; justify-content:space-between;
gap:3px; /* Espacio mínimo garantizado */
width:100%;
}
/* Botellas */
.bottle{
height:auto; aspect-ratio:2/3; position:relative; touch-action:none;
flex: 1 0 64px; /* Crecer, no encoger, base de 64px */
}
.bottle.drag-origin{opacity:.45}
.drop-highlight{outline:3px solid rgba(96,165,250,.8); border-radius:16px}
.bot-svg{width:100%; height:100%; display:block; filter: drop-shadow(0 14px 22px rgba(0,0,0,.5));}
.bot-glass{fill:url(#glassGrad); stroke:#ffffff; stroke-opacity:.28; stroke-width:1.4}
.bot-ask{font-weight:900; fill:#94a3b8; paint-order:stroke; stroke:#000; stroke-width:6; stroke-opacity:1}
.drag-proxy{position:fixed; z-index:9999; width:var(--bsize); height:var(--bsize); pointer-events:none; transform:translate(-50%,-50%) scale(1.04)}
/* Aciertos grande */
.status{
min-height:40px; text-align:center;
font-size:clamp(22px, 6vw, 34px);
font-weight:1000; color:#facc15;
text-shadow: 0 6px 18px rgba(250,204,21,.18);
}
/* Botón siguiente/terminar más abajo */
.nextWrap{margin-top:34px; text-align:center;}
/* Footer de marca */
.brand-footer{
position:fixed; left:0; right:0; bottom:20px;
text-align:center; font-weight:400; letter-spacing:.2px;
color:#cbd5e1; opacity:.7; pointer-events:none; user-select:none; font-size:14px;
}
.brand-footer strong {
font-weight:900;
}
/* Fin */
.final-time{
font-size:clamp(1.8rem, 8vw, 3rem);
font-weight:1000; color:#22c55e;
text-shadow: 0 8px 26px rgba(34,197,94,.18);
margin:10px 0 18px;
}
.final-note{
color:#cbd5e1; opacity:.9; font-size:clamp(.95rem, 3.6vw, 1.1rem); margin-bottom:24px;
}
</style>
</head>
<body>
<!-- INICIO -->
<section id="startScreen" class="screen show" aria-labelledby="homeTitle">
<div style="display:flex; flex-direction:column; align-items:center; max-width:980px; margin:0 auto;">
<div id="startLogoContainer" class="logo"></div>
<h1 id="homeTitle" class="title">BottleQuiz.com</h1>
<p class="subtitle" id="homeSubtitle"></p>
<button id="btnStart" class="btn blue big" aria-label="Start"></button>
</div>
</section>
<!-- JUEGO -->
<section id="gameScreen" class="screen" aria-label="Juego BottleQuiz">
<div class="topbar">
<div class="pill"><span id="labelLevel"></span> <b id="level">1/4</b></div>
<div class="pill"><span id="labelTime"></span> <b id="time">00:00</b></div>
<button id="btnExit" class="pill" aria-label="Exit"></button>
</div>
<div class="arena">
<div class="wrap" id="wrap">
<!-- Misteriosas ARRIBA -->
<div id="secretRow" class="row-bottles"></div>
<!-- Jugador ABAJO -->
<div id="playerRow" class="row-bottles"></div>
<div id="status" class="status" aria-live="polite"></div>
<div class="nextWrap">
<button id="btnNext" class="btn green big" disabled></button>
</div>
</div>
</div>
</section>
<!-- FIN -->
<section id="endScreen" class="screen" aria-labelledby="endTitle">
<div style="display:flex; flex-direction:column; align-items:center; max-width:980px; margin:0 auto;">
<div id="endLogoContainer" class="logo"></div>
<h1 id="endTitle" class="title">BottleQuiz.com</h1>
<div class="final-time" id="finalTimeBlock"></div>
<p class="final-note" id="finalNote"></p>
<div id="end-buttons" style="display:flex; gap: 12px; flex-wrap: wrap; justify-content: center; align-items: center;">
<button id="btnAgain" class="btn blue big"></button>
<button id="btnShare" class="btn green big" style="display: none;"></button>
</div>
</div>
</section>
<footer class="brand-footer"><strong>BottleQuiz</strong> by @cnavast</footer>
<script>
(() => {
/* ===== I18N ===== */
const i18n = {
es: {
subtitle: "Ordena tus botellas para igualar el patrón oculto. ¡Pon a prueba tu lógica y rapidez!",
start: "Empezar juego",
exit: "Salir",
level: "Nivel:",
time: "Tiempo:",
next: "Siguiente nivel",
finish: "Terminar",
hits: (h,n)=>`Aciertos: ${h} de ${n}`,
finalTime: t=>`Tu tiempo: ${t}`,
finalNote: "¡Serie completada! ¿Repites para batir tu marca?",
again: "Jugar otra vez",
share: "Compartir"
},
en: {
subtitle: "Arrange the bottles to match the hidden pattern. Test your logic and speed!",
start: "Start Game",
exit: "Exit",
level: "Level:",
time: "Time:",
next: "Next level",
finish: "Finish",
hits: (h,n)=>`Matches: ${h} of ${n}`,
finalTime: t=>`Your time: ${t}`,
finalNote: "Series complete! Try again to beat your score?",
again: "Play again",
share: "Share"
}
};
const lang = (navigator.language || navigator.userLanguage || 'en').toLowerCase().startsWith('es') ? 'es' : 'en';
document.documentElement.lang = lang;
const T = i18n[lang];
/* ===== Config / Estado ===== */
const LEVEL_SIZES = [3,4,5,6];
const PALETTE = ["#ef4444","#3b82f6","#22c55e","#eab308","#8b5cf6","#06b6d4","#ec4899","#6b7280"];
let levelIndex = 0, N = LEVEL_SIZES[0];
let secret = [], player = [];
let startMs = 0, timerId = null;
let dragging = null;
let currentGap = 14;
/* ===== DOM ===== */
const startScreen = document.getElementById('startScreen');
const gameScreen = document.getElementById('gameScreen');
const endScreen = document.getElementById('endScreen');
// Logo containers
const startLogoContainer = document.getElementById('startLogoContainer');
const endLogoContainer = document.getElementById('endLogoContainer');
// Text nodes
const homeSubtitle = document.getElementById('homeSubtitle');
const btnStart = document.getElementById('btnStart');
const btnExit = document.getElementById('btnExit');
const labelLevel = document.getElementById('labelLevel');
const labelTime = document.getElementById('labelTime');
const btnNext = document.getElementById('btnNext');
const finalTimeBlock = document.getElementById('finalTimeBlock');
const finalNote = document.getElementById('finalNote');
const btnAgain = document.getElementById('btnAgain');
const btnShare = document.getElementById('btnShare');
// Game nodes
const levelEl = document.getElementById('level');
const timeEl = document.getElementById('time');
const secretRow = document.getElementById('secretRow');
const playerRow = document.getElementById('playerRow');
const statusEl = document.getElementById('status');
const wrapEl = document.getElementById('wrap');
// Generate logos
startLogoContainer.innerHTML = bottleSVG(PALETTE[Math.floor(Math.random() * PALETTE.length)], { idx: 'logo_start' });
endLogoContainer.innerHTML = bottleSVG(PALETTE[2], { idx: 'logo_end' });
// Apply texts
homeSubtitle.textContent = T.subtitle;
btnStart.textContent = T.start;
btnExit.textContent = T.exit;
labelLevel.textContent = T.level;
labelTime.textContent = T.time;
btnNext.textContent = T.next;
finalNote.textContent = T.finalNote;
btnAgain.textContent = T.again;
btnShare.textContent = T.share;
/* ===== Utils ===== */
const pad = n => String(n).padStart(2,'0');
const fmt = ms => { const s=Math.floor(ms/1000), m=Math.floor(s/60); return `${pad(m)}:${pad(s%60)}`; };
const shuffle = a => { const arr=[...a]; for(let i=arr.length-1;i>0;i--){ const j=Math.floor(Math.random()*(i+1)); [arr[i],arr[j]]=[arr[j],arr[i]]; } return arr; };
function setScreen(scr){
startScreen.classList.toggle('show', scr==='start');
gameScreen .classList.toggle('show', scr==='game');
endScreen .classList.toggle('show', scr==='end');
}
function startTimer(){ startMs = Date.now(); timerId = setInterval(()=> timeEl.textContent = fmt(Date.now()-startMs), 200); }
function stopTimer(){ if (timerId){ clearInterval(timerId); timerId=null; } }
/* ===== Layout (gap + tamaño + padding dinámico) ===== */
function applyLayout(){
// Ya no es necesario, CSS se encarga de todo.
// Padding lateral más estrecho para 5–6 botellas
const sp = (N >= 5) ? '6px' : '16px';
gameScreen.style.paddingLeft = sp;
gameScreen.style.paddingRight = sp;
}
let resizeDebounce;
function onResize(){ clearTimeout(resizeDebounce); resizeDebounce = setTimeout(applyLayout, 60); }
window.addEventListener('resize', onResize);
window.addEventListener('orientationchange', ()=> setTimeout(applyLayout, 200));
/* ===== Botellas (SVG) ===== */
// Función para generar tonos más claros/oscuros de un color
function generateColorShades(hex) {
const p = (c, amt) => {
let usePound = false;
if (c[0] === "#") { c = c.slice(1); usePound = true; }
const num = parseInt(c, 16);
let r = (num >> 16) + amt;
if (r > 255) r = 255; else if (r < 0) r = 0;
let g = ((num >> 8) & 0x00FF) + amt;
if (g > 255) g = 255; else if (g < 0) g = 0;
let b = (num & 0x0000FF) + amt;
if (b > 255) b = 255; else if (b < 0) b = 0;
return (usePound ? "#" : "") + ((r << 16) | (g << 8) | b).toString(16).padStart(6, '0');
};
return {
main: hex,
darkest: p(hex, -80),
dark: p(hex, -25),
light: p(hex, 25),
lightest: p(hex, 60)
};
}
function bottleSVG(fill, {gray=false, ask=false, idx=0}={}){
const shades = gray ? { main: '#9aa3ad', darkest: '#6b7280', dark: '#86919c', light: '#aab3be', lightest: '#c5cdd6' } : generateColorShades(fill);
const gradId = (base) => `${base}_${idx}`; // IDs únicos por botella para evitar conflictos
return `
<svg class="bot-svg" viewBox="120 0 400 600" aria-hidden="true" xml:space="preserve">
<g id="objects_${idx}">
<g>
<g>
<linearGradient id="SVGID_1_${idx}" gradientUnits="userSpaceOnUse" x1="138.5436" y1="337.7342" x2="461.4565" y2="337.7342">
<stop offset="0" style="stop-color:#4d4d4d"/>
<stop offset="0.9988" style="stop-color:#454545"/>
</linearGradient>
<path style="fill:url(#SVGID_1_${idx});" d="M461.456,389.148c0,88.653-71.449,160.617-159.906,161.449 c-89.091,0.838-163.008-72.356-163.007-161.451c0.001-65.856,39.432-122.506,95.976-147.618 c11.357-5.044,18.577-16.42,18.577-28.847v-87.817h93.807v87.819c0,12.445,7.253,23.811,18.625,28.866 C422.047,266.673,461.456,323.31,461.456,389.148z"/>
<circle style="fill:#666666;" cx="274.246" cy="197.975" r="10.896"/>
<path style="fill:#666666;" d="M275.216,223.046c-5.142-1.274-10.432,1.507-12.264,6.478 c-3.724,10.104-11.162,19.19-20.521,22.74c-17.156,6.507-31.132,15.841-39.607,22.304c-4.731,3.608-4.834,10.688-0.188,14.404h0 c3.411,2.729,8.269,2.662,11.601-0.162c6.941-5.883,20.075-15.457,37.108-20.698c15.92-4.899,26.425-17.706,31.249-31.633 C284.588,230.727,281.126,224.511,275.216,223.046L275.216,223.046z"/>
<linearGradient id="${gradId('SVGID_00000041268535452084548570000003881654123983600008')}" gradientUnits="userSpaceOnUse" x1="323.0786" y1="395.1245" x2="187.4762" y2="364.4055">
<stop offset="0" style="stop-color:${shades.main}"/>
<stop offset="0.9976" style="stop-color:${shades.dark}"/>
</linearGradient>
<path style="fill:url(#${gradId('SVGID_00000041268535452084548570000003881654123983600008')});" d="M330.796,374.726 C314,396,289.612,414.266,253.445,415c-67.048,1.361-92.071-39.526-93.11-58.576c-0.081-1.491-0.64-2.911-0.269-4.357l0,0 c0.405-1.579,1.329-2.987,2.653-3.938c12.741-9.151,59.879-27.336,117.47,2.389C300.257,360.874,313.897,376.41,330.796,374.726z"/>
<linearGradient id="${gradId('SVGID_00000174603210042648211360000010347777034316514705')}" gradientUnits="userSpaceOnUse" x1="155.3826" y1="431.8055" x2="416.8826" y2="431.8055">
<stop offset="0" style="stop-color:${shades.light}"/>
<stop offset="0.9976" style="stop-color:${shades.main}"/>
</linearGradient>
<path style="fill:url(#${gradId('SVGID_00000174603210042648211360000010347777034316514705')});" d="M416.883,389.148 c0,58.54-31.162,109.81-77.796,138.12c-12.778,3.645-26.289,5.567-40.255,5.507c-79.381-0.367-143.449-64.741-143.449-144.122 c0-11.857,1.913-24.628,4.617-35.652c4.646,13.026,24.623,56.949,93.445,56.949c36.174,0,56.034-16.7,77.351-35.223 c0.01,0,0.01-0.01,0.01-0.01c19.405-16.849,40.017-35.223,75.221-43.88C413.039,348.922,416.883,368.584,416.883,389.148z"/>
<linearGradient id="${gradId('SVGID_00000129917112938582210110000012673878846641386415')}" gradientUnits="userSpaceOnUse" x1="339.0863" y1="427.4203" x2="443.6269" y2="427.4203">
<stop offset="0.0012" style="stop-color:${shades.darkest}"/>
<stop offset="0.9976" style="stop-color:${shades.dark}"/>
</linearGradient>
<path style="fill:url(#${gradId('SVGID_00000129917112938582210110000012673878846641386415')});" d="M443.627,388.652 c0,65.87-44.188,121.419-104.541,138.615c46.634-28.309,77.796-79.579,77.796-138.12c0-20.563-3.843-40.225-10.856-58.313 c5.2-1.278,10.727-2.348,16.611-3.17c4.23-0.594,8.36,1.733,9.994,5.676c0.01,0.03,0.02,0.049,0.03,0.069 C439.724,350.418,443.627,369.079,443.627,388.652z"/>
<linearGradient id="SVGID_8_${idx}" gradientUnits="userSpaceOnUse" x1="277.822" y1="337.7331" x2="461.4565" y2="337.7331">
<stop offset="0" style="stop-color:#454545"/>
<stop offset="0.9988" style="stop-color:#3b3b3b"/>
</linearGradient>
<path style="fill:url(#SVGID_8_${idx});" d="M461.456,389.148 c0,88.652-71.447,160.614-159.901,161.447c-8.053,0.079-15.977-0.456-23.733-1.535c22.178-3.081,42.92-10.658 61.264-21.792 c60.353-17.196,104.541-72.745,104.541-138.615c0-19.573-3.903-38.234-10.965-55.242c-0.01-0.02-0.02-0.04-0.03-0.069 c-1.634-3.942-5.765-6.27-9.994-5.676c-5.884,0.822-11.411,1.892-16.611,3.17c-15.423-39.829-46.208-72.012-85.067-89.286 c-11.381-5.052-18.632-16.423-18.632-28.864v-87.82h44.574v87.82c0,12.441,7.251,23.812,18.632,28.864 C422.043,266.669,461.456,323.307,461.456,389.148z"/>
<linearGradient id="${gradId('SVGID_00000003784933025178543020000015677254428398651820')}" gradientUnits="userSpaceOnUse" x1="180.3883" y1="426.7246" x2="252.9443" y2="515.3716">
<stop offset="0" style="stop-color:${shades.lightest}"/>
<stop offset="0.9976" style="stop-color:${shades.light}"/>
</linearGradient>
<path style="fill:url(#${gradId('SVGID_00000003784933025178543020000015677254428398651820')});" d="M236.191,480.732 c-28.107-18.461-40.446-48.207-44.974-62.485c-1.451-4.576-6.136-7.299-10.825-6.267h0c-5.485,1.208-8.642,6.974-6.698,12.244 c6.968,18.89,24.746,59.055,53.825,72.35c4.604,2.105,10.042-0.11,12.009-4.775l0,0 C241.221,487.787,239.83,483.122,236.191,480.732z"/>
<linearGradient id="${gradId('SVGID_00000083084080342386673910000004389437495051127725')}" gradientUnits="userSpaceOnUse" x1="225.3076" y1="479.2567" x2="281.4799" y2="517.8752">
<stop offset="0" style="stop-color:${shades.lightest}"/>
<stop offset="0.9976" style="stop-color:${shades.light}"/>
</linearGradient>
<circle style="fill:url(#${gradId('SVGID_00000083084080342386673910000004389437495051127725')});" cx="261.369" cy="504.049" r="10.896"/>
<linearGradient id="SVGID_12_${idx}" gradientUnits="userSpaceOnUse" x1="235.0566" y1="117.1974" x2="364.9434" y2="117.1974">
<stop offset="0" style="stop-color:#454545"/>
<stop offset="0.9988" style="stop-color:#3b3b3b"/>
</linearGradient>
<path style="fill:url(#SVGID_12_${idx});" d="M364.943,95.55v25.707 c0,9.714-29.076,17.589-64.943,17.589s-64.943-7.875-64.943-17.589V95.55H364.943z"/>
<linearGradient id="SVGID_13_${idx}" gradientUnits="userSpaceOnUse" x1="235.0566" y1="95.5496" x2="364.9434" y2="95.5496">
<stop offset="0" style="stop-color:#4d4d4d"/>
<stop offset="0.9988" style="stop-color:#454545"/>
</linearGradient>
<ellipse style="fill:url(#SVGID_13_${idx});" cx="300" cy="95.55" rx="64.943" ry="17.589"/>
<linearGradient id="SVGID_14_${idx}" gradientUnits="userSpaceOnUse" x1="246.799" y1="72.2722" x2="353.201" y2="72.2722">
<stop offset="0" style="stop-color:#844D28"/>
<stop offset="0.9988" style="stop-color:#63311F"/>
</linearGradient>
<path style="fill:url(#SVGID_14_${idx});" d="M348.018,50.202 c3.746,2.703,5.69,7.26,5.068,11.837l-3.917,28.851c-0.446,3.239-2.476,6.032-5.418,7.439c-6.518,3.11-20.137,7.716-43.752,7.716 s-37.234-4.606-43.752-7.716c-2.942-1.407-4.972-4.2-5.418-7.439l-3.917-28.851c-0.621-4.577,1.323-9.134,5.068-11.837 C266.291,39.876,283.145,38.5,300,38.5S333.709,39.876,348.018,50.202z"/>
<linearGradient id="SVGID_15_${idx}" gradientUnits="userSpaceOnUse" x1="263.3504" y1="52.8628" x2="336.6496" y2="52.8628">
<stop offset="0" style="stop-color:#64321F"/>
<stop offset="0.9976" style="stop-color:#4A2417"/>
</linearGradient>
<ellipse style="fill:url(#SVGID_15_${idx});" cx="300" cy="52.863" rx="36.65" ry="8.42"/>
<linearGradient id="SVGID_16_${idx}" gradientUnits="userSpaceOnUse" x1="256.0499" y1="78.1482" x2="268.303" y2="78.1482">
<stop offset="0.0012" style="stop-color:#AD6535"/>
<stop offset="0.9988" style="stop-color:#994C2F"/>
</linearGradient>
<path style="fill:url(#SVGID_16_${idx});" d="M263.294,91.971L263.294,91.971 c-2.999,0.242-5.627-1.992-5.869-4.991l-1.357-16.784c-0.242-2.999,1.992-5.627,4.991-5.869l0,0 c2.999-0.242,5.627,1.992,5.869,4.991l1.357,16.784C268.527,89.1,266.293,91.728,263.294,91.971z"/>
</g>
</g>
</g>
${ask?`<text class="bot-ask" x="300" y="450" font-size="180" text-anchor="middle">?</text>`:''}
</svg>`;
}
function bottleEl(idx,pos=null){
const el = document.createElement('div');
el.className = 'bottle';
el.dataset.idx = idx;
if (pos!==null){ el.dataset.pos = pos; bindPointerDrag(el); }
el.innerHTML = bottleSVG(PALETTE[idx], { idx: `p${pos}` });
return el;
}
function renderSecretHidden(){
secretRow.innerHTML = '';
for (let i=0;i<N;i++){
const b = document.createElement('div');
b.className = 'bottle';
b.innerHTML = bottleSVG('#9aa3ad', {gray:true, ask:true, idx:i});
secretRow.appendChild(b);
}
}
function renderSecretReveal(){
secretRow.innerHTML = '';
secret.forEach((idx, i)=>{
const b=document.createElement('div');
b.className='bottle';
b.innerHTML = bottleSVG(PALETTE[idx], { idx: `s${i}` });
secretRow.appendChild(b);
});
}
function renderPlayer(){
playerRow.innerHTML = '';
player.forEach((idx,i)=> playerRow.appendChild(bottleEl(idx,i)));
}
/* ===== Drag + swap (FLIP con 500ms en la botella destino) ===== */
function bindPointerDrag(el){
el.addEventListener('pointerdown', ev=>{
ev.preventDefault();
el.setPointerCapture(ev.pointerId);
const originPos = +el.dataset.pos;
const proxy = el.cloneNode(true);
proxy.classList.add('drag-proxy');
proxy.style.left = ev.clientX+'px';
proxy.style.top = ev.clientY+'px';
document.body.appendChild(proxy);
el.classList.add('drag-origin');
dragging = { originEl: el, originPos, proxyEl: proxy };
});
el.addEventListener('pointermove', ev=>{
if (!dragging) return;
dragging.proxyEl.style.left = ev.clientX+'px';
dragging.proxyEl.style.top = ev.clientY+'px';
const tgt = elementBottleAtPoint(ev.clientX, ev.clientY);
highlightTarget(tgt);
// Guard extra: evitar que el navegador interprete gesto
ev.preventDefault();
}, { passive:false });
el.addEventListener('pointerup', ev=>{
if (!dragging) return;
el.releasePointerCapture(ev.pointerId);
const tgt = elementBottleAtPoint(ev.clientX, ev.clientY);
endDrag(tgt);
ev.preventDefault();
}, { passive:false });
el.addEventListener('pointercancel', ()=> endDrag(null));
}
function elementBottleAtPoint(x,y){
const e = document.elementFromPoint(x,y);
if (!e) return null;
const b = e.closest('.bottle');
if (b && b.parentElement === playerRow) return b;
return null;
}
function highlightTarget(el){
[...playerRow.children].forEach(c => c.classList.remove('drop-highlight'));
if (el && el !== dragging?.originEl) el.classList.add('drop-highlight');
}
function endDrag(targetEl){
[...playerRow.children].forEach(c => c.classList.remove('drop-highlight'));
if (dragging){
dragging.originEl.classList.remove('drag-origin');
dragging.proxyEl.remove();
if (targetEl && targetEl !== dragging.originEl){
const from = +dragging.originPos;
const to = +targetEl.dataset.pos;
animateSwap(from, to);
updateHits(); // comprobación automática tras cada swap
}
dragging = null;
}
}
function setTransition(el, ms){ el.style.transition = `transform ${ms}ms cubic-bezier(.2,.7,.2,1)`; }
function clearTransition(el){ el.style.transition = ''; }
function animateSwap(from,to){
if (from === to) return;
const kids = [...playerRow.children];
const elDst = kids.find(e => +e.dataset.pos === to);
if (!elDst) return;
// BEFORE
const before = new Map(); kids.forEach(el => before.set(el, el.getBoundingClientRect()));
// Estado + reordenar DOM reutilizando nodos
const next = [...player]; [next[from], next[to]] = [next[to], next[from]]; player = next;
const byIdx = new Map(kids.map(el => [+el.dataset.idx, el]));
const frag = document.createDocumentFragment();
player.forEach((idx,i)=>{ const el = byIdx.get(idx); el.dataset.pos = i; frag.appendChild(el); });
playerRow.appendChild(frag);
// AFTER
const after = new Map(); [...playerRow.children].forEach(el => after.set(el, el.getBoundingClientRect()));
// Inverso sin transición
[...playerRow.children].forEach(el => {
const a = after.get(el), b = before.get(el)||a;
el.style.transform = `translate3d(${b.left-a.left}px, ${b.top-a.top}px, 0)`;
clearTransition(el);
});
// Animar (destino 500ms)
requestAnimationFrame(()=>{ requestAnimationFrame(()=>{
[...playerRow.children].forEach(el => { setTransition(el, (el===elDst)?500:220); el.style.transform='translate3d(0,0,0)'; });
setTimeout(()=>{ [...playerRow.children].forEach(el => { clearTransition(el); el.style.transform=''; }); }, 520);
})});
}
/* ===== Derangement ===== */
function derangedFrom(secretArr){
const n = secretArr.length;
let arr = [...secretArr], guard=0;
do { arr = shuffle(arr); guard++; if (guard>1000) break; }
while (arr.some((v,i)=> v === secretArr[i]));
return arr;
}
/* ===== Niveles / Juego ===== */
function newLevel(){
N = LEVEL_SIZES[levelIndex];
levelEl.textContent = `${levelIndex+1}/${LEVEL_SIZES.length}`;
// layout dinámico (padding lateral + gap + bsize)
applyLayout();
const base = Array.from({length:N}, (_,i)=>i);
secret = shuffle(base);
player = derangedFrom(secret);
renderSecretHidden();
renderPlayer();
statusEl.textContent = T.hits(0, N);
btnNext.disabled = true;
btnNext.textContent = (levelIndex === LEVEL_SIZES.length - 1) ? T.finish : T.next;
}
function countHits(){ return player.reduce((a,v,i)=> a + (v===secret[i]), 0); }
function updateHits(){
const hits = countHits();
statusEl.textContent = T.hits(hits, N);
if (hits === N){
renderSecretReveal();
btnNext.disabled = false;
btnNext.textContent = (levelIndex === LEVEL_SIZES.length - 1) ? T.finish : T.next;
// micro pop
btnNext.animate([{transform:'scale(1)'},{transform:'scale(1.06)'},{transform:'scale(1)'}], {duration:220, easing:'ease-out'});
if (navigator.vibrate) navigator.vibrate(20);
}
}
function startGame(){
levelIndex = 0;
setScreen('game');
timeEl.textContent = '00:00';
stopTimer(); startTimer();
newLevel();
}
function nextLevel(){
if (levelIndex < LEVEL_SIZES.length - 1){
levelIndex++;
newLevel();
} else {
stopTimer();
const finalTime = timeEl.textContent;
// poner el tiempo en la pantalla final con el texto correcto
finalTimeBlock.textContent = T.finalTime(finalTime);
setupShareButton(finalTime);
setScreen('end');
}
}
function backToStart(){
stopTimer();
setScreen('start');
}
/* ===== Eventos ===== */
btnStart.onclick = startGame;
btnExit.onclick = backToStart;
btnNext.onclick = nextLevel;
btnAgain.onclick = startGame;
/* ===== Share ===== */
function setupShareButton(time) {
if (navigator.share) {
btnShare.style.display = 'inline-block';
btnShare.onclick = async () => {
try {
const shareText = lang === 'es'
? `¡He completado BottleQuiz en ${time}! ¿Puedes superar mi tiempo?`
: `I completed BottleQuiz in ${time}! Can you beat my time?`;
await navigator.share({
title: 'BottleQuiz',
text: shareText,
url: 'https://bottlequiz.com',
});
} catch (err) {
console.error("Share failed:", err);
}
};
} else {
btnShare.style.display = 'none';
}
}
/* ===== Mitigaciones iOS/WebView para swipe-back ===== */
const isTouch = 'ontouchstart' in window || navigator.maxTouchPoints > 0;
if (isTouch) {
// Evitar que el navegador se quede con el gesto horizontal
document.addEventListener('touchmove', e => {
if (e.touches.length > 1) return; // permitimos gestos multi-touch si los hubiera
e.preventDefault();
}, { passive: false });
// Durante drag con PointerEvents, bloqueamos cualquier gesto default
window.addEventListener('pointermove', e => {
if (dragging) e.preventDefault();
}, { passive: false });
}
// "Trampa" de historial: si el contenedor intenta navegar atrás con gesto,
// volvemos a insertar el estado actual para que no salga de la página.
try {
history.pushState(null, document.title, location.href);
window.addEventListener('popstate', () => {
history.pushState(null, document.title, location.href);
});
} catch (e) { /* ignorar si no está permitido */ }
/* ===== Inicio ===== */
setScreen('start');
})();
</script>
<script data-goatcounter="https://bottlequiz.goatcounter.com/count"
async src="//gc.zgo.at/count.js"></script>
</body>
</html>