Tastes of Croatia
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>Okusi Hrvatske — Tastes of Croatia</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Baloo+2:wght@500;600;700;800&family=Nunito:wght@600;700;800&display=swap" rel="stylesheet">
<style>
:root{
--cream:#fff7e8;
--paper:#fffaf1;
--terracotta:#c85c3a;
--deep-red:#9e2f2f;
--olive:#667a42;
--olive-dark:#47562f;
--adriatic:#2f6f9f;
--adriatic-dark:#1d4f73;
--gold:#e3a72f;
--ink:#2d2a26;
--muted:#7b746b;
--card:#fffdf7;
--shadow:0 14px 35px rgba(66,45,28,.18);
--radius:24px;
}
*{box-sizing:border-box}
html,body{margin:0;min-height:100%;font-family:"Nunito",system-ui,sans-serif;background:linear-gradient(#7fc7df 0 24%,#e8d19e 24% 100%);color:var(--ink);overflow-x:hidden}
body{min-height:100vh}
button{font:inherit;border:0;cursor:pointer}
.hidden{display:none!important}
.app{min-height:100vh;position:relative}
.screen{min-height:100vh;padding:18px;display:flex;flex-direction:column;align-items:center;justify-content:center;animation:fadeIn .35s ease}
@keyframes fadeIn{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:none}}
.checker{background-image:linear-gradient(45deg,#b12b2b 25%,transparent 25%),linear-gradient(-45deg,#b12b2b 25%,transparent 25%),linear-gradient(45deg,transparent 75%,#b12b2b 75%),linear-gradient(-45deg,transparent 75%,#b12b2b 75%);background-size:28px 28px;background-position:0 0,0 14px,14px -14px,-14px 0}
.hero{width:min(980px,100%);background:rgba(255,250,241,.96);border-radius:34px;box-shadow:var(--shadow);overflow:hidden;border:4px solid rgba(255,255,255,.65)}
.heroTop{height:54px;display:flex;align-items:center;justify-content:center;color:white;font-weight:900;text-shadow:0 2px 0 rgba(0,0,0,.15)}
.heroBody{padding:36px 24px 28px;text-align:center;background:radial-gradient(circle at top,#fff 0,#fff9ed 55%,#f7edd9 100%)}
h1{font-family:"Baloo 2",cursive;font-size:clamp(48px,9vw,92px);line-height:.88;margin:0;color:var(--deep-red);text-shadow:0 4px 0 #f4c7b9}
.subtitle{font-family:"Baloo 2";font-size:clamp(20px,3vw,31px);font-weight:800;color:var(--adriatic-dark);margin:12px 0 22px}
.konobaArt{font-size:clamp(56px,9vw,94px);letter-spacing:4px;margin:8px 0 18px;filter:drop-shadow(0 6px 3px rgba(0,0,0,.1))}
.btnRow{display:flex;gap:12px;flex-wrap:wrap;justify-content:center}.btn{padding:14px 24px;border-radius:18px;background:var(--terracotta);color:white;font-weight:900;box-shadow:0 6px 0 #8f3a25;transition:.15s;min-width:140px}.btn:hover{transform:translateY(-2px)}.btn:active{transform:translateY(4px);box-shadow:0 2px 0 #8f3a25}.btn.blue{background:var(--adriatic);box-shadow:0 6px 0 var(--adriatic-dark)}.btn.olive{background:var(--olive);box-shadow:0 6px 0 var(--olive-dark)}.btn.ghost{background:#efe6d5;color:var(--ink);box-shadow:0 6px 0 #cfc2aa}.btn.small{padding:10px 15px;min-width:auto;border-radius:14px}
.menuStats{display:flex;justify-content:center;gap:18px;margin-top:20px;flex-wrap:wrap;color:var(--muted);font-weight:800}.chip{padding:9px 14px;border-radius:999px;background:white;border:2px solid #eadbc2}
.panel{width:min(1060px,100%);background:rgba(255,250,241,.96);border-radius:30px;box-shadow:var(--shadow);overflow:hidden}.panelHead{padding:18px 22px;background:var(--adriatic-dark);color:white;display:flex;align-items:center;justify-content:space-between;gap:12px}.panelHead h2{font-family:"Baloo 2";font-size:34px;margin:0}.panelBody{padding:22px}
.levelGrid{display:grid;grid-template-columns:repeat(4,1fr);gap:16px}.levelCard{background:var(--card);border:3px solid #eddcc0;border-radius:22px;padding:18px;text-align:left;position:relative;min-height:210px;box-shadow:0 8px 18px rgba(0,0,0,.08)}.levelCard.locked{filter:grayscale(.8);opacity:.6}.regionArt{font-size:52px}.levelCard h3{font-family:"Baloo 2";font-size:25px;margin:5px 0}.levelCard p{margin:0 0 12px;color:var(--muted);font-weight:700}.stars{color:#d9a01e;font-size:25px;letter-spacing:2px}.lock{position:absolute;right:14px;top:14px;font-size:28px}.levelCard .btn{width:100%;padding:10px;margin-top:10px}
.howList{max-width:760px;text-align:left;margin:0 auto}.howList li{margin:10px 0;line-height:1.4;font-weight:700}
.codexGrid{display:grid;grid-template-columns:repeat(2,1fr);gap:14px}.codexCard{background:white;border:2px solid #eadbc2;border-radius:18px;padding:15px;display:grid;grid-template-columns:70px 1fr;gap:12px;align-items:start}.codexCard.locked{opacity:.48;filter:grayscale(1)}.codexIcon{font-size:50px;text-align:center}.codexCard h3{margin:0 0 4px;font-family:"Baloo 2";font-size:24px}.codexCard p{margin:4px 0;color:var(--muted);font-size:14px}.ingredientPills{display:flex;flex-wrap:wrap;gap:5px;margin-top:7px}.ingredientPills span{background:#f4ecdf;border-radius:999px;padding:4px 8px;font-size:12px;font-weight:800}
/* GAME */
#gameScreen{justify-content:flex-start;padding:0;background:linear-gradient(#76bcd7 0 18%,#d5b987 18% 100%)}
.gameTop{width:100%;background:rgba(34,62,77,.94);color:white;padding:8px 12px;display:flex;align-items:center;justify-content:space-between;gap:8px;position:sticky;top:0;z-index:10;box-shadow:0 5px 20px rgba(0,0,0,.18)}.gameStats{display:flex;gap:8px;flex-wrap:wrap}.stat{background:rgba(255,255,255,.13);padding:7px 10px;border-radius:12px;font-weight:900;white-space:nowrap}.regionName{font-family:"Baloo 2";font-size:22px;font-weight:900}
.gameWorld{width:min(1180px,100%);display:grid;grid-template-columns:1.05fr 1.4fr;gap:14px;padding:14px 14px 190px}.customersArea,.kitchen{background:rgba(255,250,241,.9);border-radius:24px;box-shadow:var(--shadow);border:3px solid rgba(255,255,255,.5)}.sectionTitle{font-family:"Baloo 2";font-size:24px;font-weight:900;margin:0;padding:12px 16px;color:var(--deep-red)}
.customers{padding:0 12px 14px;display:grid;gap:10px}.customer{background:#fff;border:2px solid #eadbc2;border-radius:20px;padding:10px;display:grid;grid-template-columns:70px 1fr;gap:10px;align-items:center;transition:.25s}.customer.happy{animation:happy .55s ease}.customer.angry{animation:shake .45s ease;background:#ffe1dc}@keyframes happy{50%{transform:translateY(-8px) rotate(2deg)}}@keyframes shake{20%,60%{transform:translateX(-7px)}40%,80%{transform:translateX(7px)}}.person{font-size:55px;text-align:center}.bubble{position:relative;background:#fff8e8;border:2px solid #ecd5ad;border-radius:16px;padding:8px 10px}.bubble:before{content:"";position:absolute;left:-10px;top:23px;border:10px solid transparent;border-right-color:#ecd5ad}.bubble:after{content:"";position:absolute;left:-7px;top:24px;border:9px solid transparent;border-right-color:#fff8e8}.orderLine{display:flex;justify-content:space-between;gap:8px;align-items:center}.orderName{font-weight:900}.orderIcons{font-size:24px}.patienceTrack{height:10px;background:#e5e0d8;border-radius:99px;overflow:hidden;margin-top:7px}.patienceBar{height:100%;width:100%;background:hsl(120,60%,44%);transition:width .15s linear,background .15s linear}.customerMeta{font-size:12px;color:var(--muted);font-weight:800;margin-top:4px}
.kitchen{padding-bottom:14px}.kitchenInner{padding:0 14px;display:grid;grid-template-columns:1fr 1fr;gap:14px}.assembly,.cooker{background:white;border:2px solid #eadbc2;border-radius:20px;min-height:250px;padding:12px;position:relative}.stationTitle{font-weight:900;color:var(--adriatic-dark);display:flex;justify-content:space-between;align-items:center}.dishSelect{width:100%;padding:10px;border-radius:12px;border:2px solid #dfd1ba;font:inherit;font-weight:800;background:#fffaf0;margin-top:8px}.plateZone{margin:15px auto 8px;width:180px;height:180px;border-radius:50%;background:radial-gradient(circle,#fff 0 56%,#e5e2dc 57% 61%,#f8f7f2 62% 100%);box-shadow:inset 0 0 0 2px #d5d2cb,0 8px 20px rgba(0,0,0,.12);display:flex;flex-wrap:wrap;align-content:center;justify-content:center;gap:2px;padding:25px;position:relative;transition:.2s}.plateZone.dragover{transform:scale(1.04);box-shadow:inset 0 0 0 4px var(--olive),0 8px 20px rgba(0,0,0,.12)}.plateZone.shake{animation:shake .4s ease}.plateEmpty{color:#aaa;font-size:13px;text-align:center;font-weight:800}.onPlate{font-size:27px;filter:drop-shadow(0 2px 1px rgba(0,0,0,.1))}.prepSteps{font-size:12px;color:var(--muted);text-align:center;font-weight:800;min-height:18px}.resetBtn{position:absolute;right:10px;bottom:10px;background:#eee0cd;border-radius:12px;padding:7px 10px;font-weight:900;color:#684f3e}
.cooker{display:flex;flex-direction:column;align-items:center}.stoveBtn{margin-top:18px;width:125px;height:125px;border-radius:50%;background:radial-gradient(circle at 50% 45%,#2b2b2b 0 34%,#555 35% 42%,#202020 43% 100%);box-shadow:inset 0 0 0 10px #815c43,0 10px 20px rgba(0,0,0,.25);font-size:48px;color:white;display:flex;align-items:center;justify-content:center;position:relative;transition:.2s}.stoveBtn.ready{box-shadow:inset 0 0 0 10px #815c43,0 0 24px #e4ab3a}.stoveBtn.cooking{animation:sizzle .5s infinite alternate}@keyframes sizzle{to{transform:scale(1.025)}}.cookRing{position:absolute;inset:-12px;border-radius:50%;background:conic-gradient(var(--gold) calc(var(--p,0)*1%),#dfd8ca 0);z-index:-1}.cookLabel{margin-top:15px;text-align:center;font-weight:900}.quality{height:24px;margin-top:4px;font-size:16px;font-weight:900}.servePlate{margin-top:10px;background:var(--olive);color:white;border-radius:15px;padding:10px 15px;font-weight:900;box-shadow:0 5px 0 var(--olive-dark);touch-action:none}.servePlate[disabled]{opacity:.4;cursor:not-allowed}
.ingredientTray{position:fixed;left:50%;transform:translateX(-50%);bottom:10px;width:min(1140px,calc(100% - 20px));background:rgba(47,44,38,.94);border:3px solid rgba(255,255,255,.18);border-radius:24px;padding:10px;z-index:20;box-shadow:0 15px 35px rgba(0,0,0,.3)}.trayLabel{color:white;font-size:13px;font-weight:900;margin:0 0 6px 8px}.ingredients{display:flex;gap:8px;overflow-x:auto;padding-bottom:4px;scrollbar-width:thin}.ingredient{min-width:84px;background:#fff8e9;border-radius:15px;padding:8px 6px;text-align:center;font-weight:900;border:2px solid #e6cfaa;user-select:none;touch-action:none;cursor:grab}.ingredient:active{cursor:grabbing;transform:scale(.96)}.ingIcon{font-size:28px;display:block}.ingName{font-size:11px;line-height:1.05;display:block;margin-top:3px}
.toast{position:fixed;left:50%;top:78px;transform:translateX(-50%) translateY(-20px);background:#27231f;color:white;padding:10px 16px;border-radius:999px;font-weight:900;opacity:0;pointer-events:none;z-index:60;transition:.25s;max-width:90%;text-align:center}.toast.show{opacity:1;transform:translateX(-50%) translateY(0)}
.modal{position:fixed;inset:0;background:rgba(30,24,20,.56);display:flex;align-items:center;justify-content:center;padding:18px;z-index:50}.modalCard{width:min(520px,100%);background:#fffaf0;border-radius:26px;box-shadow:0 22px 60px rgba(0,0,0,.35);padding:24px;text-align:center;border:4px solid #fff}.modalIcon{font-size:64px}.modalCard h3{font-family:"Baloo 2";font-size:31px;margin:5px 0;color:var(--deep-red)}.modalCard p{line-height:1.45;color:#5f574d;font-weight:700}.modalCard strong{color:var(--adriatic-dark)}
.resultBox{text-align:center;padding:34px}.resultBox h2{font-family:"Baloo 2";font-size:45px;margin:0;color:var(--deep-red)}.bigStars{font-size:54px;letter-spacing:8px;color:#e2a326;text-shadow:0 3px 0 #9f7110}.resultStats{font-size:20px;font-weight:900;margin:10px 0 22px}
@media(max-width:850px){.levelGrid{grid-template-columns:repeat(2,1fr)}.gameWorld{grid-template-columns:1fr}.kitchenInner{grid-template-columns:1fr 1fr}.codexGrid{grid-template-columns:1fr}.customers{grid-template-columns:repeat(2,1fr)}.customer{grid-template-columns:50px 1fr}.person{font-size:42px}}
@media(max-width:620px){.screen{padding:10px}.heroBody{padding:28px 14px}.levelGrid{grid-template-columns:1fr}.gameTop{align-items:flex-start}.regionName{font-size:17px}.gameWorld{padding:8px 8px 180px}.customers{grid-template-columns:1fr}.kitchenInner{grid-template-columns:1fr}.assembly,.cooker{min-height:220px}.plateZone{width:155px;height:155px}.stoveBtn{width:105px;height:105px}.ingredient{min-width:74px}.codexCard{grid-template-columns:55px 1fr}.panelBody{padding:14px}}
</style>
</head>
<body>
<div class="app">
<div id="toast" class="toast"></div>
<!-- START SCREEN -->
<section id="startScreen" class="screen">
<div class="hero">
<div class="heroTop checker">DOBRODOŠLI U KONOBU!</div>
<div class="heroBody">
<div class="konobaArt">🌊 🏠 🍽️ 🌿</div>
<h1>Okusi Hrvatske</h1>
<div class="subtitle">Tastes of Croatia</div>
<p style="max-width:700px;margin:0 auto 24px;font-weight:800;color:#6b6258">Run a cozy Croatian konoba, build traditional dishes in the right order, cook them perfectly, and serve your guests before their patience runs out.</p>
<div class="btnRow">
<button class="btn" onclick="showLevelSelect()">▶ Play</button>
<button class="btn blue" onclick="showHowTo()">❓ How to Play</button>
<button class="btn olive" onclick="showCodex()">📖 Cookbook</button>
</div>
<div class="menuStats">
<div class="chip">🏆 High Score: <span id="menuHighScore">0</span></div>
<div class="chip">🪙 Total Coins: <span id="menuCoins">0</span></div>
<div class="chip">🗺️ Regions Unlocked: <span id="menuUnlocked">1</span>/4</div>
</div>
</div>
</div>
</section>
<!-- HOW TO PLAY -->
<section id="howScreen" class="screen hidden">
<div class="panel">
<div class="panelHead"><h2>How to Play</h2><button class="btn small ghost" onclick="showStart()">← Back</button></div>
<div class="panelBody">
<ol class="howList">
<li>👩🍳 Watch each customer’s order bubble and select that dish in the kitchen.</li>
<li>🥕 Drag ingredients to the plate in the exact recipe order. On mobile, tap an ingredient to place it.</li>
<li>🔥 When the recipe is assembled, tap the stove. Cooking starts automatically and shows progress.</li>
<li>✨ After the ideal cook point, tap the stove again to finish. Timing determines Gold, Silver, or Bronze quality.</li>
<li>🍽️ Tap “Serve Plate”, then tap the matching customer — or drag the finished plate onto that customer.</li>
<li>❤️ Customers lose patience over time. Wrong ingredients cost patience; failed orders cost a life.</li>
<li>⭐ Finish enough orders before the level timer expires to earn up to three stars and unlock new Croatian regions.</li>
</ol>
<div class="btnRow" style="margin-top:22px"><button class="btn" onclick="showLevelSelect()">Choose a Region</button></div>
</div>
</div>
</section>
<!-- LEVEL SELECT -->
<section id="levelScreen" class="screen hidden">
<div class="panel">
<div class="panelHead"><h2>Choose Your Region</h2><button class="btn small ghost" onclick="showStart()">← Menu</button></div>
<div class="panelBody"><div id="levelGrid" class="levelGrid"></div></div>
</div>
</section>
<!-- CODEX -->
<section id="codexScreen" class="screen hidden">
<div class="panel">
<div class="panelHead"><h2>📖 Konoba Cookbook</h2><button class="btn small ghost" onclick="showStart()">← Menu</button></div>
<div class="panelBody"><div id="codexGrid" class="codexGrid"></div></div>
</div>
</section>
<!-- GAMEPLAY -->
<section id="gameScreen" class="screen hidden">
<div class="gameTop">
<div class="regionName" id="gameRegion">Dalmatia</div>
<div class="gameStats">
<div class="stat">⭐ <span id="scoreEl">0</span></div>
<div class="stat">🪙 <span id="coinEl">0</span></div>
<div class="stat">❤️ <span id="livesEl">3</span></div>
<div class="stat">⏱️ <span id="timeEl">60</span>s</div>
<div class="stat">🍽️ <span id="servedEl">0</span>/<span id="goalEl">6</span></div>
</div>
<button class="btn small ghost" onclick="quitLevel()">✕</button>
</div>
<div class="gameWorld">
<div class="customersArea">
<h3 class="sectionTitle">Guest Queue</h3>
<div id="customers" class="customers"></div>
</div>
<div class="kitchen">
<h3 class="sectionTitle">Konoba Kitchen</h3>
<div class="kitchenInner">
<div class="assembly">
<div class="stationTitle">🥣 Assemble <span id="assemblyStatus">Choose dish</span></div>
<select id="dishSelect" class="dishSelect"></select>
<div id="plateZone" class="plateZone" aria-label="Plate drop zone">
<div id="plateEmpty" class="plateEmpty">Drop / tap ingredients here</div>
</div>
<div id="prepSteps" class="prepSteps"></div>
<button class="resetBtn" onclick="resetPlate(true)">↻ Reset</button>
</div>
<div class="cooker">
<div class="stationTitle" style="width:100%">🔥 Cook <span id="cookStatus">Not ready</span></div>
<button id="stoveBtn" class="stoveBtn" onclick="handleStove()" aria-label="Cook station"><span id="stoveIcon">🔥</span><span id="cookRing" class="cookRing"></span></button>
<div id="cookLabel" class="cookLabel">Build the recipe first</div>
<div id="quality" class="quality"></div>
<button id="servePlate" class="servePlate" disabled draggable="true">🍽️ Serve Plate</button>
</div>
</div>
</div>
</div>
<div class="ingredientTray">
<div class="trayLabel">INGREDIENT TRAY — drag to plate or tap</div>
<div id="ingredients" class="ingredients"></div>
</div>
</section>
<!-- LEVEL COMPLETE -->
<section id="completeScreen" class="screen hidden">
<div class="panel resultBox">
<div style="font-size:72px">🎉</div><h2>Service Complete!</h2>
<div id="completeRegion" class="subtitle" style="margin:4px 0">Dalmatia</div>
<div id="completeStars" class="bigStars">★★★</div>
<div id="completeStats" class="resultStats"></div>
<div id="completeFact" style="max-width:680px;margin:0 auto 22px;background:#fff1d6;border-radius:18px;padding:16px;font-weight:800"></div>
<div class="btnRow">
<button id="nextLevelBtn" class="btn" onclick="nextLevel()">Next Region →</button>
<button class="btn blue" onclick="retryLevel()">Retry</button>
<button class="btn ghost" onclick="showLevelSelect()">Regions</button>
</div>
</div>
</section>
<!-- GAME OVER -->
<section id="gameOverScreen" class="screen hidden">
<div class="panel resultBox">
<div style="font-size:72px">😵💫</div><h2>Konoba Closed!</h2>
<p style="font-weight:800;color:var(--muted)">Too many guests left unhappy.</p>
<div id="gameOverStats" class="resultStats"></div>
<div class="btnRow"><button class="btn" onclick="retryLevel()">Play Again</button><button class="btn ghost" onclick="showLevelSelect()">Regions</button></div>
</div>
</section>
<div id="factModal" class="modal hidden" onclick="closeFact(event)">
<div class="modalCard" onclick="event.stopPropagation()">
<div id="factIcon" class="modalIcon">🍽️</div><h3 id="factTitle">Dish served!</h3><p id="factText"></p>
<button class="btn small" onclick="closeFact()">Back to Kitchen</button>
</div>
</div>
</div>
<script>
/* =====================================================
OKUSI HRVATSKE — single-file game
Real illustrations/audio can later replace the emoji/CSS art.
===================================================== */
// ---------- DISH DATA ----------
const DISHES = {
cevapi:{name:"Ćevapi",region:"Dalmatia & continental grill culture",requiredIngredients:["cevapi-roll","onion","ajvar","kajmak","lepinja"],cookTime:5000,basePoints:100,image:"🥙",funFact:"Ćevapi are commonly served sizzling from the grill with flatbread, chopped onion, and rich pepper-based ajvar."},
peka:{name:"Peka",region:"Dalmatia",requiredIngredients:["potato","octopus","olive-oil","rosemary","garlic"],cookTime:7000,basePoints:150,image:"🐙",funFact:"Peka is traditionally slow-cooked under a heavy bell-shaped lid covered with hot embers, giving meat or octopus a deeply roasted flavor."},
pasticada:{name:"Pašticada",region:"Dalmatia",requiredIngredients:["beef","prosek","gnocchi"],cookTime:6500,basePoints:140,image:"🥘",funFact:"Dalmatian pašticada is a festive slow-braised beef dish, often paired with gnocchi and a sweet-savory sauce enriched with prošek."},
strukli:{name:"Štrukli",region:"Zagorje",requiredIngredients:["dough","cottage-cheese","sour-cream"],cookTime:5000,basePoints:110,image:"🧀",funFact:"Zagorski štrukli are rolled dough parcels filled with fresh cheese and can be boiled or baked, often under a creamy topping."},
fritule:{name:"Fritule",region:"Dalmatia & Istria",requiredIngredients:["fritule-dough","raisins","powdered-sugar"],cookTime:3500,basePoints:90,image:"🍩",funFact:"Fritule are tiny festive dough fritters traditionally made around holidays, often scented with citrus, rum, or raisins."},
crniRizoto:{name:"Crni rižoto",region:"Dalmatia",requiredIngredients:["rice","cuttlefish-ink","squid","parsley"],cookTime:6000,basePoints:130,image:"🦑",funFact:"Black risotto gets its dramatic color and briny depth from cuttlefish or squid ink, a hallmark of Adriatic seafood cooking."},
sarma:{name:"Sarma",region:"Continental Croatia / Slavonia",requiredIngredients:["cabbage","minced-meat","tomato-sauce"],cookTime:7000,basePoints:130,image:"🥬",funFact:"Sarma is especially beloved in winter, with fermented cabbage leaves wrapped around a hearty meat-and-rice filling."},
rozata:{name:"Rožata",region:"Dubrovnik",requiredIngredients:["custard","caramel","mint"],cookTime:4500,basePoints:120,image:"🍮",funFact:"Dubrovnik rožata is a silky caramel custard related to crème caramel and is traditionally perfumed with a local rose liqueur."}
};
const INGREDIENTS = {
"cevapi-roll": ["🥩","Ćevapi"], onion:["🧅","Onion"], ajvar:["🫑","Ajvar"], kajmak:["🥛","Kajmak"], lepinja:["🫓","Lepinja"],
potato:["🥔","Potatoes"], octopus:["🐙","Octopus"], "olive-oil":["🫒","Olive oil"], rosemary:["🌿","Rosemary"], garlic:["🧄","Garlic"],
beef:["🥩","Beef"], prosek:["🍷","Prošek sauce"], gnocchi:["🥔","Gnocchi"],
dough:["🥟","Dough"], "cottage-cheese":["🧀","Fresh cheese"], "sour-cream":["🥛","Sour cream"],
"fritule-dough":["🍞","Fritule dough"], raisins:["🍇","Rum raisins"], "powdered-sugar":["❄️","Powdered sugar"],
rice:["🍚","Rice"], "cuttlefish-ink":["⚫","Cuttlefish ink"], squid:["🦑","Squid"], parsley:["🌿","Parsley"],
cabbage:["🥬","Cabbage"], "minced-meat":["🥩","Meat filling"], "tomato-sauce":["🍅","Tomato sauce"],
custard:["🍮","Custard"], caramel:["🍯","Caramel"], mint:["🌿","Mint leaf"]
};
const LEVELS = [
{name:"Istria",icon:"🌿",desc:"A gentle first service with roomy patience timers.",duration:70,goal:5,maxCustomers:2,patience:46,dishes:["fritule","strukli","cevapi"]},
{name:"Dalmatia",icon:"🌊",desc:"Seafood, grill favorites, and faster Adriatic service.",duration:80,goal:7,maxCustomers:3,patience:40,dishes:["peka","pasticada","crniRizoto","cevapi","rozata","fritule"]},
{name:"Slavonia",icon:"🌾",desc:"Heartier plates, busier tables, less time to spare.",duration:85,goal:8,maxCustomers:3,patience:34,dishes:["sarma","cevapi","pasticada","strukli"]},
{name:"Zagorje",icon:"⛰️",desc:"Master service: all eight dishes can appear.",duration:95,goal:10,maxCustomers:4,patience:30,dishes:Object.keys(DISHES)}
];
// ---------- PERSISTENT SAVE ----------
const SAVE_KEY="okusiHrvatskeSave_v1";
let saveData = loadSave();
function loadSave(){
try{return Object.assign({highScore:0,totalCoins:0,unlockedLevel:1,levelStars:[0,0,0,0],unlockedDishes:["fritule","strukli","cevapi"]},JSON.parse(localStorage.getItem(SAVE_KEY)||"{}"));}
catch(e){return {highScore:0,totalCoins:0,unlockedLevel:1,levelStars:[0,0,0,0],unlockedDishes:["fritule","strukli","cevapi"]};}
}
function persist(){localStorage.setItem(SAVE_KEY,JSON.stringify(saveData));updateMenuStats();}
// ---------- GAME STATE ----------
let state={levelIndex:0,score:0,coins:0,lives:3,timeLeft:0,served:0,customers:[],selectedDish:null,plate:[],cooking:false,cooked:false,cookStart:0,cookProgress:0,quality:"",qualityMultiplier:1,gameTimer:null,customerTimer:null,cookRAF:null,spawnTimer:null,servingMode:false,levelActive:false,lastFact:null,customerSeq:1};
const customerFaces=["👩","👨","👵","🧔","👩🦱","👨🦳","👩🦰","🧑"];
// ---------- SCREEN / MENU RENDERING ----------
const screens=["startScreen","howScreen","levelScreen","codexScreen","gameScreen","completeScreen","gameOverScreen"];
function showScreen(id){screens.forEach(s=>document.getElementById(s).classList.toggle("hidden",s!==id));}
function showStart(){stopAllTimers();showScreen("startScreen");updateMenuStats();}
function showHowTo(){showScreen("howScreen");}
function showLevelSelect(){stopAllTimers();renderLevels();showScreen("levelScreen");}
function showCodex(){renderCodex();showScreen("codexScreen");}
function updateMenuStats(){document.getElementById("menuHighScore").textContent=saveData.highScore;document.getElementById("menuCoins").textContent=saveData.totalCoins;document.getElementById("menuUnlocked").textContent=saveData.unlockedLevel;}
function renderLevels(){
const grid=document.getElementById("levelGrid");grid.innerHTML="";
LEVELS.forEach((lvl,i)=>{const locked=i>=saveData.unlockedLevel;const stars=saveData.levelStars[i]||0;const el=document.createElement("div");el.className="levelCard"+(locked?" locked":"");el.innerHTML=`${locked?'<div class="lock">🔒</div>':''}<div class="regionArt">${lvl.icon}</div><h3>${i+1}. ${lvl.name}</h3><p>${lvl.desc}</p><div class="stars">${"★".repeat(stars)}${"☆".repeat(3-stars)}</div><button class="btn ${locked?'ghost':''}" ${locked?'disabled':''}>${locked?'Locked':'Open Konoba'}</button>`;if(!locked)el.querySelector("button").onclick=()=>startLevel(i);grid.appendChild(el);});
}
function renderCodex(){
const grid=document.getElementById("codexGrid");grid.innerHTML="";
Object.entries(DISHES).forEach(([key,d])=>{const unlocked=saveData.unlockedDishes.includes(key);const el=document.createElement("div");el.className="codexCard"+(unlocked?"":" locked");const pills=d.requiredIngredients.map(id=>`<span>${INGREDIENTS[id][0]} ${INGREDIENTS[id][1]}</span>`).join("");el.innerHTML=`<div class="codexIcon">${unlocked?d.image:'🔒'}</div><div><h3>${unlocked?d.name:'Locked recipe'}</h3>${unlocked?`<p><strong>Region:</strong> ${d.region}</p><div class="ingredientPills">${pills}</div><p>${d.funFact}</p>`:'<p>Serve this dish in a region to unlock its cookbook entry.</p>'}</div>`;grid.appendChild(el);});
}
// ---------- LEVEL START / END ----------
function startLevel(index){
stopAllTimers();
const lvl=LEVELS[index];
state={...state,levelIndex:index,score:0,coins:0,lives:3,timeLeft:lvl.duration,served:0,customers:[],selectedDish:null,plate:[],cooking:false,cooked:false,cookStart:0,cookProgress:0,quality:"",qualityMultiplier:1,gameTimer:null,customerTimer:null,cookRAF:null,spawnTimer:null,servingMode:false,levelActive:true,lastFact:null,customerSeq:1};
document.getElementById("gameRegion").textContent=`${lvl.icon} ${lvl.name} Konoba`;
document.getElementById("goalEl").textContent=lvl.goal;
setupDishSelect();renderIngredients();resetPlate(false);updateHUD();showScreen("gameScreen");
for(let i=0;i<Math.min(2,lvl.maxCustomers);i++)spawnCustomer(true);
state.gameTimer=setInterval(()=>{if(!state.levelActive)return;state.timeLeft--;updateHUD();if(state.timeLeft<=0)finishLevel();},1000);
state.customerTimer=setInterval(updateCustomers,200);
state.spawnTimer=setInterval(()=>{if(state.levelActive&&state.customers.length<lvl.maxCustomers)spawnCustomer();},2600);
}
function stopAllTimers(){
if(state.gameTimer)clearInterval(state.gameTimer);if(state.customerTimer)clearInterval(state.customerTimer);if(state.spawnTimer)clearInterval(state.spawnTimer);if(state.cookRAF)cancelAnimationFrame(state.cookRAF);
state.gameTimer=state.customerTimer=state.spawnTimer=state.cookRAF=null;state.levelActive=false;
}
function quitLevel(){stopAllTimers();showLevelSelect();}
function retryLevel(){startLevel(state.levelIndex);}
function nextLevel(){const n=Math.min(state.levelIndex+1,LEVELS.length-1);if(n===state.levelIndex)showLevelSelect();else startLevel(n);}
function finishLevel(){
if(!state.levelActive)return;stopAllTimers();
const lvl=LEVELS[state.levelIndex];let stars=state.served>=lvl.goal?1:0;if(state.served>=lvl.goal+2)stars=2;if(state.served>=lvl.goal+4||state.score>=lvl.goal*125)stars=3;
if(state.served<Math.max(2,Math.ceil(lvl.goal*.5))){gameOver(false);return;}
saveData.highScore=Math.max(saveData.highScore,state.score);saveData.totalCoins+=state.coins;saveData.levelStars[state.levelIndex]=Math.max(saveData.levelStars[state.levelIndex]||0,stars);
if(stars>=1&&state.levelIndex+1<LEVELS.length)saveData.unlockedLevel=Math.max(saveData.unlockedLevel,state.levelIndex+2);
persist();
document.getElementById("completeRegion").textContent=`${lvl.icon} ${lvl.name}`;document.getElementById("completeStars").textContent="★".repeat(stars)+"☆".repeat(3-stars);document.getElementById("completeStats").innerHTML=`Score: ${state.score} • Coins: ${state.coins} • Dishes served: ${state.served}`;
const fact=state.lastFact||DISHES[lvl.dishes[0]];document.getElementById("completeFact").innerHTML=`<strong>Konoba note:</strong> ${fact.funFact}`;document.getElementById("nextLevelBtn").style.display=(state.levelIndex<LEVELS.length-1&&saveData.unlockedLevel>state.levelIndex+1)?"inline-block":"none";showScreen("completeScreen");
}
function gameOver(countCoins=true){
stopAllTimers();saveData.highScore=Math.max(saveData.highScore,state.score);if(countCoins)saveData.totalCoins+=state.coins;persist();document.getElementById("gameOverStats").innerHTML=`Final score: ${state.score}<br>Coins earned: ${state.coins}<br>Dishes served: ${state.served}`;showScreen("gameOverScreen");
}
// ---------- CUSTOMERS ----------
function spawnCustomer(initial=false){
const lvl=LEVELS[state.levelIndex];if(state.customers.length>=lvl.maxCustomers)return;
let dishKey=lvl.dishes[Math.floor(Math.random()*lvl.dishes.length)];
// Avoid too many duplicate orders when possible.
const used=new Set(state.customers.map(c=>c.dishKey));const options=lvl.dishes.filter(k=>!used.has(k));if(options.length)dishKey=options[Math.floor(Math.random()*options.length)];
const variance=initial?4:Math.random()*8-4;
state.customers.push({id:state.customerSeq++,dishKey,face:customerFaces[Math.floor(Math.random()*customerFaces.length)],patience:lvl.patience+variance,maxPatience:lvl.patience+variance,born:performance.now()});renderCustomers();
}
function updateCustomers(){
if(!state.levelActive)return;let changed=false;
state.customers.forEach(c=>{c.patience-=.2;});
const expired=state.customers.filter(c=>c.patience<=0);
expired.forEach(c=>{removeCustomer(c.id);loseLife(`A guest waiting for ${DISHES[c.dishKey].name} ran out of patience!`);changed=true;});
if(state.lives<=0){gameOver();return;}if(changed||state.customers.length)renderCustomers();
}
function renderCustomers(){
const box=document.getElementById("customers");box.innerHTML="";
if(!state.customers.length){box.innerHTML='<div style="padding:18px;color:#7b746b;font-weight:900">Waiting for the next guest…</div>';return;}
state.customers.forEach(c=>{const d=DISHES[c.dishKey];const pct=Math.max(0,c.patience/c.maxPatience*100);const hue=Math.max(0,Math.min(120,pct*1.2));const el=document.createElement("div");el.className="customer";el.dataset.id=c.id;el.innerHTML=`<div class="person">${c.face}</div><div class="bubble"><div class="orderLine"><span class="orderName">${d.image} ${d.name}</span><span class="orderIcons">${d.requiredIngredients.slice(0,4).map(x=>INGREDIENTS[x][0]).join('')}</span></div><div class="patienceTrack"><div class="patienceBar" style="width:${pct}%;background:hsl(${hue},68%,45%)"></div></div><div class="customerMeta">❤️ ${Math.ceil(c.patience)} sec patience</div></div>`;
el.onclick=()=>{if(state.servingMode)serveToCustomer(c.id);};el.addEventListener("dragover",e=>{if(state.cooked)e.preventDefault()});el.addEventListener("drop",e=>{e.preventDefault();if(state.cooked)serveToCustomer(c.id)});box.appendChild(el);
});
}
function removeCustomer(id){state.customers=state.customers.filter(c=>c.id!==id);renderCustomers();setTimeout(()=>{if(state.levelActive&&state.customers.length<LEVELS[state.levelIndex].maxCustomers)spawnCustomer();},700);}
function loseLife(msg){state.lives--;updateHUD();toast(msg);playBuzz();}
// ---------- ASSEMBLY / DRAG AND DROP ----------
function setupDishSelect(){
const sel=document.getElementById("dishSelect");sel.innerHTML='<option value="">— Select a dish —</option>'+LEVELS[state.levelIndex].dishes.map(k=>`<option value="${k}">${DISHES[k].image} ${DISHES[k].name}</option>`).join("");sel.onchange=()=>{state.selectedDish=sel.value||null;resetPlate(false);updateAssemblyStatus();};
}
function renderIngredients(){
const tray=document.getElementById("ingredients");tray.innerHTML="";Object.entries(INGREDIENTS).forEach(([id,[icon,name]])=>{const el=document.createElement("div");el.className="ingredient";el.draggable=true;el.dataset.id=id;el.innerHTML=`<span class="ingIcon">${icon}</span><span class="ingName">${name}</span>`;el.addEventListener("dragstart",e=>{e.dataTransfer.setData("text/plain",id);});el.addEventListener("click",()=>placeIngredient(id));el.addEventListener("touchstart",()=>{}, {passive:true});tray.appendChild(el);});
}
const plateZone=document.getElementById("plateZone");plateZone.addEventListener("dragover",e=>{e.preventDefault();plateZone.classList.add("dragover")});plateZone.addEventListener("dragleave",()=>plateZone.classList.remove("dragover"));plateZone.addEventListener("drop",e=>{e.preventDefault();plateZone.classList.remove("dragover");placeIngredient(e.dataTransfer.getData("text/plain"));});
function placeIngredient(id){
if(!state.levelActive||state.cooking||state.cooked)return;if(!state.selectedDish){toast("Choose a dish first.");shakePlate();return;}
const recipe=DISHES[state.selectedDish].requiredIngredients;const expected=recipe[state.plate.length];
if(id!==expected){shakePlate();toast(`Wrong ingredient — next is ${INGREDIENTS[expected][1]}. Patience -2!`);state.customers.forEach(c=>c.patience=Math.max(0,c.patience-2));playBuzz();return;}
state.plate.push(id);playChop();renderPlate();updateAssemblyStatus();if(state.plate.length===recipe.length){document.getElementById("stoveBtn").classList.add("ready");document.getElementById("cookLabel").textContent="Recipe ready — tap the stove!";document.getElementById("cookStatus").textContent="Ready";toast(`${DISHES[state.selectedDish].name} ready to cook!`);}
}
function renderPlate(){const empty=document.getElementById("plateEmpty");plateZone.querySelectorAll(".onPlate").forEach(n=>n.remove());empty.style.display=state.plate.length?"none":"block";state.plate.forEach(id=>{const s=document.createElement("span");s.className="onPlate";s.title=INGREDIENTS[id][1];s.textContent=INGREDIENTS[id][0];plateZone.appendChild(s);});const d=state.selectedDish?DISHES[state.selectedDish]:null;document.getElementById("prepSteps").textContent=d?`${state.plate.length}/${d.requiredIngredients.length}: ${d.requiredIngredients.map((id,i)=>`${i<state.plate.length?'✓':'•'} ${INGREDIENTS[id][1]}`).join(' → ')}`:"";}
function updateAssemblyStatus(){if(!state.selectedDish)document.getElementById("assemblyStatus").textContent="Choose dish";else document.getElementById("assemblyStatus").textContent=`${state.plate.length}/${DISHES[state.selectedDish].requiredIngredients.length}`;}
function resetPlate(showMsg=false){if(state.cookRAF)cancelAnimationFrame(state.cookRAF);state.plate=[];state.cooking=false;state.cooked=false;state.cookProgress=0;state.quality="";state.qualityMultiplier=1;state.servingMode=false;document.getElementById("stoveBtn").classList.remove("ready","cooking");document.getElementById("cookRing").style.setProperty("--p",0);document.getElementById("cookStatus").textContent="Not ready";document.getElementById("cookLabel").textContent="Build the recipe first";document.getElementById("quality").textContent="";document.getElementById("servePlate").disabled=true;document.getElementById("servePlate").textContent="🍽️ Serve Plate";renderPlate();updateAssemblyStatus();if(showMsg)toast("Plate cleared.");}
function shakePlate(){plateZone.classList.remove("shake");void plateZone.offsetWidth;plateZone.classList.add("shake");}
// ---------- COOKING ----------
function handleStove(){
if(!state.selectedDish)return toast("Choose a dish first.");const d=DISHES[state.selectedDish];if(state.plate.length!==d.requiredIngredients.length)return toast("Finish the recipe before cooking.");if(state.cooked)return toast("This dish is already cooked — serve it!");
if(!state.cooking){state.cooking=true;state.cookStart=performance.now();document.getElementById("stoveBtn").classList.remove("ready");document.getElementById("stoveBtn").classList.add("cooking");document.getElementById("cookStatus").textContent="Cooking";document.getElementById("cookLabel").textContent="Tap again near the golden zone (90–115%)";playSizzle();cookLoop();return;}
finishCooking();
}
function cookLoop(){
if(!state.cooking)return;const d=DISHES[state.selectedDish];const elapsed=performance.now()-state.cookStart;state.cookProgress=elapsed/d.cookTime;document.getElementById("cookRing").style.setProperty("--p",Math.min(130,state.cookProgress*100));
let text=`${Math.round(state.cookProgress*100)}%`;
if(state.cookProgress>=.9&&state.cookProgress<=1.15)text+=" • GOLDEN ZONE!";else if(state.cookProgress>1.15)text+=" • getting dark…";document.getElementById("quality").textContent=text;
if(state.cookProgress>=1.35){finishCooking(true);return;}state.cookRAF=requestAnimationFrame(cookLoop);
}
function finishCooking(auto=false){
if(!state.cooking)return;state.cooking=false;if(state.cookRAF)cancelAnimationFrame(state.cookRAF);state.cooked=true;document.getElementById("stoveBtn").classList.remove("cooking");const p=state.cookProgress;
if(p>=.9&&p<=1.15){state.quality="Gold";state.qualityMultiplier=1.3;}
else if((p>=.72&&p<.9)||(p>1.15&&p<=1.26)){state.quality="Silver";state.qualityMultiplier=1.05;}
else{state.quality="Bronze";state.qualityMultiplier=.78;}
document.getElementById("quality").textContent=`${state.quality==='Gold'?'✨':state.quality==='Silver'?'🥈':'🥉'} ${state.quality} quality`;
document.getElementById("cookStatus").textContent="Done";document.getElementById("cookLabel").textContent=auto?"Cooked automatically at the limit.":"Dish finished!";document.getElementById("servePlate").disabled=false;toast(`${state.quality} quality — serve the matching guest!`);
}
// ---------- SERVING ----------
const serveBtn=document.getElementById("servePlate");serveBtn.addEventListener("click",()=>{if(!state.cooked)return;state.servingMode=!state.servingMode;serveBtn.textContent=state.servingMode?"👆 Tap a customer":"🍽️ Serve Plate";toast(state.servingMode?"Tap the customer who ordered this dish.":"Serving cancelled.");});serveBtn.addEventListener("dragstart",e=>{if(!state.cooked){e.preventDefault();return;}e.dataTransfer.setData("text/plain","finished-plate")});
function serveToCustomer(id){
if(!state.cooked||!state.selectedDish)return;const c=state.customers.find(x=>x.id===id);if(!c)return;
const el=document.querySelector(`.customer[data-id="${id}"]`);
if(c.dishKey!==state.selectedDish){el?.classList.add("angry");setTimeout(()=>el?.classList.remove("angry"),500);removeCustomer(id);loseLife(`Wrong dish! That guest wanted ${DISHES[c.dishKey].name}.`);resetPlate(false);if(state.lives<=0)gameOver();return;}
const d=DISHES[state.selectedDish];const speed=Math.max(.35,c.patience/c.maxPatience);const points=Math.round(d.basePoints*state.qualityMultiplier*(.65+.55*speed));const coins=Math.max(5,Math.round(points/18));state.score+=points;state.coins+=coins;state.served++;state.lastFact=d;saveData.unlockedDishes=[...new Set([...saveData.unlockedDishes,state.selectedDish])];persist();
if(el){el.classList.add("happy");setTimeout(()=>removeCustomer(id),450)}else removeCustomer(id);playDing();updateHUD();showFact(d,points,coins);resetPlate(false);
if(state.served>=LEVELS[state.levelIndex].goal+5)finishLevel();
}
function showFact(d,points,coins){document.getElementById("factIcon").textContent=d.image;document.getElementById("factTitle").textContent=`${d.name} served!`;document.getElementById("factText").innerHTML=`<strong>${d.region}</strong><br>${d.funFact}<br><br>⭐ +${points} points 🪙 +${coins} coins`;document.getElementById("factModal").classList.remove("hidden");}
function closeFact(e){if(e&&e.target!==document.getElementById("factModal"))return;document.getElementById("factModal").classList.add("hidden");}
// ---------- HUD / TOAST ----------
function updateHUD(){document.getElementById("scoreEl").textContent=state.score;document.getElementById("coinEl").textContent=state.coins;document.getElementById("livesEl").textContent=state.lives;document.getElementById("timeEl").textContent=Math.max(0,state.timeLeft);document.getElementById("servedEl").textContent=state.served;}
let toastTimer=null;function toast(msg){const t=document.getElementById("toast");t.textContent=msg;t.classList.add("show");clearTimeout(toastTimer);toastTimer=setTimeout(()=>t.classList.remove("show"),1800);}
// ---------- SIMPLE SOUND HOOKS (Web Audio API) ----------
// Replace these generated tones with real audio assets later if desired.
let audioCtx=null;function tone(freq=440,dur=.08,type="sine",vol=.035){try{audioCtx=audioCtx||new (window.AudioContext||window.webkitAudioContext)();const o=audioCtx.createOscillator(),g=audioCtx.createGain();o.type=type;o.frequency.value=freq;g.gain.value=vol;o.connect(g);g.connect(audioCtx.destination);o.start();g.gain.exponentialRampToValueAtTime(.001,audioCtx.currentTime+dur);o.stop(audioCtx.currentTime+dur);}catch(e){}}
function playChop(){tone(180,.045,"square",.02)}function playSizzle(){tone(720,.11,"sawtooth",.012)}function playDing(){tone(660,.08,"sine",.04);setTimeout(()=>tone(880,.13,"sine",.035),75)}function playBuzz(){tone(120,.16,"sawtooth",.025)}
// ---------- INIT ----------
updateMenuStats();renderLevels();renderCodex();showStart();
</script>
</body>
</html>