/* דניאל וארץ האור האבוד — עיצוב
 * עולם לילי קסום שמתבהר ככל שדניאל אוסף גבישים (--light בין 0 ל־1).
 */
:root {
  color-scheme: dark;
  --night: #17123d;
  --dusk: #2c2372;
  --gold: #ffcf5a;
  --gold-deep: #f0a830;
  --parch: #fff6df;
  --parch-edge: #f1dfb4;
  --ink: #2a2150;
  --ink-soft: #5a4f86;
  --teal: #2fb8a9;
  --rose: #ff7aa2;
  --good: #34b36b;
  --bad: #e2574c;
  --light: 0;
  --radius: 18px;
  --display: 'Secular One', 'Varela Round', 'Arial Hebrew', 'Segoe UI', sans-serif;
  --body: 'Varela Round', 'Arial Hebrew', 'Segoe UI', Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--body);
  font-size: 18px;
  line-height: 1.6;
  color: var(--parch);
  background: var(--night);
  padding-inline: 16px;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
img { max-width: 100%; }
button { font-family: inherit; }
button:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }

/* ---------- רקע: שמיים שמתבהרים ---------- */
.sky {
  position: fixed; inset: 0; z-index: -2;
  background:
    radial-gradient(1.5px 1.5px at 12% 18%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 72% 12%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 40% 30%, #ffe9a8 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 88% 40%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 22% 62%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 60% 70%, #ffe9a8 50%, transparent 51%),
    linear-gradient(180deg, var(--night) 0%, var(--dusk) 70%, #4a3a8f 100%);
}
.veil {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: radial-gradient(120% 80% at 50% 110%, #ffd98a 0%, #ff9fb8 45%, transparent 75%);
  opacity: calc(var(--light) * .75);
  transition: opacity 1.2s ease;
}

/* ---------- סרגל עליון ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: grid; grid-template-columns: 1fr auto auto auto; align-items: center; gap: 8px;
  max-width: 920px; margin: 0 auto;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 0 10px;
  background: linear-gradient(180deg, var(--night) 70%, transparent);
}
.gems {
  font-family: var(--display); font-size: 22px; color: var(--gold);
  font-variant-numeric: tabular-nums; white-space: nowrap;
  direction: ltr; unicode-bidi: isolate; text-align: right;
}
.tb-btn {
  min-height: 46px; padding: 6px 14px; border-radius: 999px;
  border: 2px solid rgba(255, 207, 90, .45); background: rgba(255, 255, 255, .08);
  color: var(--parch); font-size: 16px; cursor: pointer; white-space: nowrap;
}
.tb-btn:hover { background: rgba(255, 255, 255, .16); }
.tb-icon { width: 46px; padding: 0; font-size: 20px; }

@media (max-width: 600px) {
  .topbar { grid-template-columns: 1fr 1fr; }
  .gems { order: 0; }
  #menuBtn { order: 1; justify-self: end; }
  #bagBtn { order: 2; }
  #journalBtn { order: 3; }
  .tb-btn { font-size: 15px; padding: 6px 8px; }
}

.app { max-width: 920px; margin: 0 auto; padding-block: 8px 48px; }

/* ---------- כפתורים ---------- */
.btn {
  min-height: 54px; padding: 10px 26px; border-radius: 999px; border: 0; cursor: pointer;
  font-family: var(--display); font-size: 21px; line-height: 1.2;
  transition: transform .15s ease, box-shadow .15s ease;
}
.btn:active { transform: scale(.97); }
.btn-primary {
  background: linear-gradient(180deg, #ffe08a, var(--gold-deep)); color: var(--ink);
  box-shadow: 0 5px 0 #b87414, 0 10px 24px rgba(255, 190, 70, .35);
}
.btn-primary:hover { transform: translateY(-2px); }
.btn-ghost { background: rgba(255, 255, 255, .1); color: inherit; border: 2px solid rgba(255, 207, 90, .5); }
.btn-danger { background: var(--bad); color: #fff; box-shadow: 0 4px 0 #9d3028; }
.btn-tip {
  min-height: 46px; padding: 6px 18px; border-radius: 999px; cursor: pointer;
  border: 2px dashed var(--gold-deep); background: transparent; color: var(--ink); font-size: 17px;
}
.actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; align-items: center; }

/* ---------- מסך פתיחה וסיום ---------- */
.start, .end { position: relative; text-align: center; display: grid; justify-items: center; gap: 14px; padding-block: 28px 20px; }
.title {
  font-family: var(--display); font-weight: 400; margin: 0;
  font-size: clamp(38px, 9vw, 72px); line-height: 1.05; text-wrap: balance;
  color: var(--gold);
  text-shadow: 0 0 22px rgba(255, 207, 90, .55), 0 4px 0 #8a4d12;
}
.lead { margin: 0; font-size: clamp(19px, 4.4vw, 24px); max-width: 30ch; text-wrap: balance; }
.hero-daniel { width: clamp(130px, 34vw, 190px); filter: drop-shadow(0 0 26px rgba(255, 207, 90, .45)); animation: bob 3s ease-in-out infinite; }
.hero-daniel.cheer { animation: jump 1.2s ease-in-out infinite; }
.start-gems, .end-gems { display: flex; gap: 12px; justify-content: center; }
.start-gems .gem { opacity: .35; filter: grayscale(.6); }
.greeting { display: grid; gap: 2px; }
.hello { margin: 0; font-family: var(--display); font-size: clamp(28px, 7vw, 40px); line-height: 1.15; color: var(--parch); }
.hello-sub { margin: 0; font-size: clamp(18px, 4.4vw, 22px); color: #ffe7a8; }
.wave { display: inline-block; transform-origin: 70% 80%; animation: wave 2.4s ease-in-out 3; }
@keyframes wave { 0%, 60%, 100% { rotate: 0deg; } 10%, 30% { rotate: 16deg; } 20%, 40% { rotate: -8deg; } }
.start-actions { display: flex; flex-direction: column; gap: 14px; align-items: center; }
.gem { width: 38px; height: 38px; filter: drop-shadow(0 0 8px rgba(255, 255, 255, .5)); }
.gem.big { width: 88px; height: 88px; }
.float { animation: bob 2.6s ease-in-out infinite; }
.d1 { animation-delay: .3s; } .d2 { animation-delay: .6s; } .d3 { animation-delay: .9s; } .d4 { animation-delay: 1.2s; }

.end .title { font-size: clamp(46px, 12vw, 88px); }
.sunburst {
  position: absolute; top: 40px; left: 50%; width: 520px; max-width: 100%; aspect-ratio: 1; z-index: -1;
  transform: translateX(-50%);
  background: radial-gradient(circle, rgba(255, 236, 170, .95) 0%, rgba(255, 190, 110, .45) 35%, transparent 70%);
  animation: dawn 2.4s ease-out both;
}
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 30; }
.confetti span { position: absolute; top: -40px; animation: fall linear infinite; }

/* ---------- מפת המסע ---------- */
.path { list-style: none; margin: 4px 0 10px; padding: 0; display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.path li { display: grid; justify-items: center; text-align: center; line-height: 1.2; opacity: .5; }
.path li span {
  width: 42px; height: 42px; display: grid; place-items: center; font-size: 22px;
  border-radius: 50%; background: rgba(255, 255, 255, .1); border: 2px solid transparent;
}
.path li small { font-size: 13px; margin-top: 3px; }
.path li.done { opacity: 1; }
.path li.done span { border-color: var(--gold); background: rgba(255, 207, 90, .2); }
.path li.current { opacity: 1; }
.path li.current span { border-color: var(--teal); box-shadow: 0 0 14px var(--teal); animation: pulse 1.8s ease-in-out infinite; }
.region { font-family: var(--display); font-weight: 400; font-size: 26px; margin: 0 0 8px; color: var(--gold); text-align: center; }

/* ---------- זירת השלב ---------- */
.scene {
  position: relative; container-type: inline-size; overflow: hidden;
  width: 100%; aspect-ratio: 16 / 9; border-radius: var(--radius);
  border: 3px solid rgba(255, 207, 90, .5);
  box-shadow: 0 12px 30px rgba(0, 0, 0, .35);
  --lit: 0;
}
@media (max-width: 600px) { .scene { aspect-ratio: 4 / 3; } }
.decor, .target, .npc { position: absolute; transform: translate(-50%, -50%); line-height: 1; }
.decor { pointer-events: none; user-select: none; }
.daniel { position: absolute; right: 2%; bottom: 3%; width: 17%; z-index: 3; animation: bob 3s ease-in-out infinite; }
.npc { left: 12%; top: 76%; font-size: 13cqw; z-index: 3; animation: bob 2.6s ease-in-out infinite .5s; }

.scene-village {
  background:
    radial-gradient(circle at 80% 20%, rgba(255, 240, 180, calc(var(--lit) * .18)) 0 30%, transparent 60%),
    linear-gradient(180deg, #3c2f86 0%, #6a4fa8 55%, #4e8a4d 56%, #3d6f3f 100%);
}
.scene-forest { background: linear-gradient(180deg, #1f4a3a 0%, #2d6a4b 55%, #2f5a2c 56%, #234521 100%); }
.scene-cave { background: radial-gradient(ellipse at 50% 55%, #6b5140 0%, #3b2a22 55%, #1c1411 100%); }
.scene-cave::after {
  content: ''; position: absolute; inset: 0; pointer-events: none; z-index: 1;
  background: rgba(8, 5, 4, calc(.62 - var(--lit) * .2));
  transition: background .8s ease;
}
.scene-cave .target { z-index: 2; }
.scene-cave .target.found { filter: drop-shadow(0 0 16px #ffb347); }
.scene-tower {
  background:
    radial-gradient(1.5px 1.5px at 20% 30%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 80% 50%, #fff 50%, transparent 51%),
    radial-gradient(2px 2px at 60% 12%, #ffe9a8 50%, transparent 51%),
    linear-gradient(180deg, #0f1440 0%, #273284 100%);
}
.scene-castle { background: linear-gradient(180deg, #ffb3c7 0%, #ffd9a0 55%, #9ad17a 56%, #6fae55 100%); }

/* מגדל מצויר ב־CSS */
.tower {
  position: absolute; left: 50%; bottom: 0; transform: translateX(-50%);
  width: 20%; height: 86%; display: flex; flex-direction: column; gap: 6%; align-items: center; justify-content: flex-end;
  padding-bottom: 8%;
  background: linear-gradient(90deg, #6f64b8, #9a8fe0 50%, #6f64b8);
  border-radius: 40% 40% 4px 4px / 12% 12% 4px 4px;
}
.tower i { width: 36%; aspect-ratio: 1 / 1.3; border-radius: 50% 50% 4px 4px; background: #1a1848; transition: background .6s, box-shadow .6s; }
.tower i.lit { background: var(--gold); box-shadow: 0 0 14px var(--gold); }
.tower b { position: absolute; top: -10%; font-size: 8cqw; animation: pulse 2s ease-in-out infinite; }

/* פריטים מוסתרים */
.target {
  z-index: 2; cursor: pointer; border: 0; background: none; padding: 0;
  min-width: 46px; min-height: 46px; display: grid; place-items: center;
  transition: filter .5s, opacity .5s, transform .3s;
}
.target.light { filter: grayscale(1) brightness(.55); }
.target.light.found { filter: drop-shadow(0 0 14px #ffd36b) drop-shadow(0 0 4px #fff); }
.target.find { opacity: .42; transform: translate(-50%, -50%) rotate(-12deg); }
.target.find.found { opacity: 1; filter: drop-shadow(0 0 12px #fff27a); transform: translate(-50%, -50%) scale(1.25); }
.target.just { animation: popIn .6s ease; }
.target.found { cursor: default; }

/* ---------- לוח משימה ---------- */
.panel {
  margin-top: 14px; padding: 18px 18px 20px; border-radius: var(--radius);
  background: var(--parch); color: var(--ink);
  border: 3px solid var(--parch-edge);
  box-shadow: 0 10px 26px rgba(0, 0, 0, .3);
  display: grid; gap: 14px;
}
.bubble .who { font-family: var(--display); font-size: 20px; color: var(--ink-soft); display: flex; align-items: center; gap: 8px; }
.bubble .who span { font-size: 30px; }
.bubble p, .task { margin: 0; font-size: 20px; }
.riddle { margin: 0; padding: 12px 14px; border-radius: 12px; background: #efe1bb; font-size: 19px; }
.counter { text-align: center; font-size: 19px; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.counter b { color: var(--ink); font-size: 22px; }
.feedback { min-height: 1.6em; margin: 0; text-align: center; font-weight: bold; color: var(--ink-soft); }

.options { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.opt {
  min-height: 64px; padding: 10px; border-radius: 14px; cursor: pointer;
  border: 3px solid #d9c38e; background: #fff; color: var(--ink); font-size: 19px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform .15s, border-color .2s, background .2s;
}
.opt:hover:not(:disabled) { transform: translateY(-2px); border-color: var(--gold-deep); }
.opt .oe { font-size: 30px; }
.options.nums .opt { font-family: var(--display); font-size: 30px; font-variant-numeric: tabular-nums; }
.opt.right { background: #d9f6e2; border-color: var(--good); }
.opt.wrong { background: #fde1de; border-color: var(--bad); opacity: .6; animation: shake .4s; }
.pattern { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; font-size: 34px; }

.slots { display: flex; justify-content: center; gap: 10px; }
.slot {
  width: 60px; height: 60px; display: grid; place-items: center; font-size: 30px;
  border-radius: 12px; border: 3px dashed #b99e62; background: #f3e6c3;
}
.slots.open .slot { border-style: solid; border-color: var(--good); background: #d9f6e2; animation: popIn .5s; }
.stones { display: flex; justify-content: center; flex-wrap: wrap; gap: 12px; }
.stone {
  width: 64px; height: 64px; font-size: 30px; cursor: pointer; border-radius: 50%;
  border: 3px solid #7d6a8f; background: radial-gradient(circle at 35% 30%, #b8a9c9, #6d5d80);
  box-shadow: 0 4px 0 #4a3d57;
}
.stone:disabled { opacity: .3; cursor: default; box-shadow: none; }

.memory { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; max-width: 420px; width: 100%; margin: 0 auto; }
.card {
  aspect-ratio: 3 / 4; border-radius: 12px; cursor: pointer; font-size: 32px; color: var(--gold);
  border: 3px solid #4a3f8a; background: linear-gradient(160deg, #3d3290, #221a5c);
  transition: transform .25s, background .25s;
}
.card.up { background: #fff; color: var(--ink); transform: rotateY(0) scale(1.03); }
.card.matched { border-color: var(--good); background: #d9f6e2; }

.lock { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.dial { display: grid; justify-items: center; gap: 4px; }
.dial-btn {
  width: 56px; height: 44px; border-radius: 10px; cursor: pointer; font-size: 18px;
  border: 2px solid #b99e62; background: #f3e6c3; color: var(--ink);
}
.digit {
  width: 56px; height: 62px; display: grid; place-items: center; border-radius: 10px;
  font-family: var(--display); font-size: 36px; background: var(--ink); color: var(--gold);
  font-variant-numeric: tabular-nums;
}
.dial-item { font-size: 28px; }
.lock.open .digit { background: var(--good); color: #fff; }

.reward { display: grid; justify-items: center; gap: 12px; text-align: center; }
.reward h3 { font-family: var(--display); font-weight: 400; font-size: 24px; margin: 0; text-wrap: balance; }
.got { display: flex; align-items: center; gap: 12px; text-align: start; padding: 10px 14px; border-radius: 14px; background: #f3e6c3; }
.got span { font-size: 40px; }
.got b, .got small { display: block; }
.got small { font-size: 16px; color: var(--ink-soft); }
.next-hint { margin: 0; font-size: 18px; }

/* ---------- חלון קופץ ---------- */
.modal {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px;
  background: rgba(10, 6, 30, .7);
}
.modal-card {
  position: relative; width: min(520px, 100%); max-height: 86vh; overflow: auto;
  padding: 22px 20px; border-radius: var(--radius);
  background: var(--parch); color: var(--ink); border: 3px solid var(--parch-edge);
  animation: popIn .25s ease;
}
.modal-card h2 { font-family: var(--display); font-weight: 400; margin: 0 0 12px; font-size: 26px; padding-inline-end: 44px; }
.modal-close {
  position: absolute; top: 12px; left: 12px; width: 44px; height: 44px; border-radius: 50%;
  border: 0; background: #efe1bb; color: var(--ink); font-size: 20px; cursor: pointer;
}
.bag { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.bag li { display: flex; gap: 12px; align-items: center; padding: 10px 12px; background: #f3e6c3; border-radius: 12px; }
.bag li > span { font-size: 36px; }
.bag b, .bag small { display: block; }
.bag small { font-size: 16px; color: var(--ink-soft); }
.empty { margin: 0; }
.journal { margin: 0; display: grid; gap: 4px; }
.journal dt { font-family: var(--display); color: var(--ink-soft); margin-top: 8px; }
.journal dd { margin: 0; }
.journal ul { margin: 0; padding-inline-start: 22px; }
.menu { display: grid; gap: 12px; margin-top: 8px; }

/* ---------- הודעות עידוד ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); z-index: 50;
  transform: translate(-50%, calc(100% + 40px)); max-width: calc(100% - 32px); visibility: hidden;
  padding: 12px 22px; border-radius: 999px; text-align: center;
  background: var(--gold); color: var(--ink); font-family: var(--display); font-size: 20px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .35);
  transition: transform .35s ease, visibility .35s; pointer-events: none;
}
.toast.show { transform: translate(-50%, 0); visibility: visible; }

/* ---------- אנימציות ---------- */
@keyframes bob { 0%, 100% { translate: 0 0; } 50% { translate: 0 -6px; } }
@keyframes jump { 0%, 100% { translate: 0 0; } 40% { translate: 0 -22px; } }
@keyframes pulse { 0%, 100% { scale: 1; } 50% { scale: 1.12; } }
@keyframes popIn { 0% { scale: .4; } 70% { scale: 1.2; } 100% { scale: 1; } }
@keyframes shake { 0%, 100% { translate: 0; } 25% { translate: -6px; } 75% { translate: 6px; } }
@keyframes fall { to { transform: translateY(110vh) rotate(360deg); } }
@keyframes dawn { from { opacity: 0; scale: .3; } to { opacity: 1; scale: 1; } }
.shake { animation: shake .4s; }
.spin { animation: spinIn 1s ease both; }
@keyframes spinIn { from { transform: rotateY(0) scale(.3); opacity: 0; } to { transform: rotateY(720deg) scale(1); opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
