/* ============ Misja: Prawdziwa Energia — Akademia Super Zdrowia ============ */

@font-face {
  font-family: 'Baloo 2';
  font-weight: 400;
  font-display: swap;
  src: url('../assets/fonts/baloo-2-latin-ext-400-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Baloo 2';
  font-weight: 700;
  font-display: swap;
  src: url('../assets/fonts/baloo-2-latin-ext-700-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'Baloo 2';
  font-weight: 800;
  font-display: swap;
  src: url('../assets/fonts/baloo-2-latin-ext-800-normal.woff2') format('woff2');
}

:root {
  --navy: #131f4a;
  --navy-2: #1c2c66;
  --gold: #ffc300;
  --gold-dark: #8a5a00;
  --orange: #e5641b;
  --green: #4caf50;
  --red: #e53935;
  --ink: #10173a;
  --paper: #ffffff;
  --shadow: 0 10px 28px rgba(6, 10, 30, .45);
  --radius: 20px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: 'Baloo 2', 'Segoe UI', Verdana, sans-serif;
  background: var(--navy);
  color: #fff;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

#app { position: fixed; inset: 0; }

/* ---------- ekrany ---------- */
.screen {
  position: absolute; inset: 0;
  display: none;
  opacity: 0;
  transition: opacity .35s ease;
}
.screen.visible { display: flex; flex-direction: column; opacity: 1; }
.hidden { display: none !important; }

/* ---------- przyciski ---------- */
.btn {
  font-family: inherit;
  font-weight: 800;
  font-size: 18px;
  color: var(--ink);
  background: #fff;
  border: none;
  border-radius: 999px;
  padding: 12px 26px;
  cursor: pointer;
  box-shadow: 0 5px 0 rgba(6, 10, 30, .35), var(--shadow);
  transition: transform .08s ease, box-shadow .08s ease, filter .15s;
  text-decoration: none;
  display: inline-block;
  text-align: center;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 rgba(6,10,30,.35); }
.btn-gold { background: linear-gradient(180deg, #ffd54d, var(--gold)); color: #4a2f00; }
.btn-big { font-size: 24px; padding: 16px 44px; }
.btn-small { font-size: 15px; padding: 8px 18px; }
.btn-ghost {
  background: rgba(255,255,255,.13);
  color: #fff;
  border: 2px solid rgba(255,255,255,.45);
  box-shadow: none;
}
.round-btn {
  width: 46px; height: 46px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.5);
  background: rgba(10, 16, 44, .55);
  color: #fff;
  font-size: 19px;
  font-family: inherit;
  cursor: pointer;
  display: grid; place-items: center;
  backdrop-filter: blur(4px);
}
.round-btn:active { transform: scale(.92); }

/* ---------- ładowanie ---------- */
#screen-loading {
  background: radial-gradient(120% 90% at 50% 30%, var(--navy-2), var(--navy));
  align-items: center; justify-content: center;
}
.load-box { text-align: center; padding: 24px; }
.load-bolt { animation: boltpulse 1.1s ease-in-out infinite; }
@keyframes boltpulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.12) rotate(-4deg); } }
.load-box h1 { font-size: 26px; font-weight: 800; margin: 14px 0 20px; }
.load-bar {
  width: min(320px, 70vw); height: 14px;
  border-radius: 999px;
  background: rgba(255,255,255,.15);
  overflow: hidden;
  margin: 0 auto;
}
#load-fill {
  height: 100%; width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--orange), var(--gold));
  transition: width .2s ease;
}
#load-note { margin-top: 12px; opacity: .75; font-size: 15px; }

/* ---------- tytuł ---------- */
#screen-title { align-items: center; justify-content: center; text-align: center; }
.title-bg {
  position: absolute; inset: 0;
  background: url('../assets/img/scene-run.webp') center 22% / cover no-repeat;
  filter: saturate(1.05);
}
.title-bg::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(12,18,48,.25) 0%, rgba(12,18,48,.55) 55%, rgba(12,18,48,.92) 100%);
}
.title-inner { position: relative; z-index: 1; padding: 20px; max-width: 560px; margin-top: auto; margin-bottom: max(28px, env(safe-area-inset-bottom)); }
.title-kicker {
  font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
  font-size: 14px; color: var(--gold);
  text-shadow: 0 2px 8px rgba(0,0,0,.8);
}
.title-logo {
  font-size: clamp(34px, 8vw, 56px);
  font-weight: 800;
  line-height: 1.02;
  margin: 6px 0 10px;
  text-shadow: 0 3px 0 rgba(0,0,0,.35), 0 10px 30px rgba(0,0,0,.7);
}
.title-sub { font-size: 17px; text-shadow: 0 2px 8px rgba(0,0,0,.8); margin-bottom: 20px; }
.title-buttons { display: flex; flex-direction: column; gap: 12px; align-items: center; }
.title-note { margin-top: 16px; font-size: 13px; opacity: .75; text-shadow: 0 2px 6px rgba(0,0,0,.8); }
.sound-btn { position: absolute; top: max(14px, env(safe-area-inset-top)); right: 14px; z-index: 2; }
#btn-sound-map { position: static; }

/* ---------- fabuła ---------- */
#screen-story { background: radial-gradient(120% 90% at 50% 20%, var(--navy-2), var(--navy)); align-items: center; justify-content: center; }
.story-frame {
  width: min(520px, 94vw);
  max-height: 96svh;
  display: flex; flex-direction: column;
  background: #0d1436;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 3px solid rgba(255,255,255,.14);
}
.story-img { position: relative; flex: 1 1 auto; min-height: 0; background: #000; }
.story-img img {
  display: block; width: 100%; height: 100%;
  max-height: 62svh;
  object-fit: cover; object-position: top center;
  animation: kenburns 14s ease-in-out infinite alternate;
}
@keyframes kenburns { from { transform: scale(1); } to { transform: scale(1.07); } }
.story-text { padding: 16px 18px 18px; text-align: center; }
.story-text p { font-size: 17px; line-height: 1.45; margin-bottom: 12px; min-height: 3.6em; }

/* ---------- mapa ---------- */
#screen-map { overflow: hidden; }
.map-bg {
  position: absolute; inset: 0;
  background: url('../assets/img/bg-hub.webp') center / cover no-repeat;
}
.map-bg::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(10,15,40,.78) 0%, rgba(10,15,40,.45) 30%, rgba(10,15,40,.55) 100%);
}
.map-top {
  position: relative; z-index: 2;
  display: flex; gap: 10px; align-items: center;
  padding: max(12px, env(safe-area-inset-top)) 14px 8px;
}
.map-top-right { margin-left: auto; }
.hud-chip {
  background: rgba(10, 16, 44, .68);
  border: 2px solid rgba(255,255,255,.28);
  border-radius: 999px;
  padding: 6px 16px;
  font-weight: 800;
  font-size: 16px;
  backdrop-filter: blur(4px);
}
.map-title {
  position: relative; z-index: 2;
  text-align: center;
  font-size: clamp(20px, 4.6vw, 28px);
  font-weight: 800;
  text-shadow: 0 2px 10px rgba(0,0,0,.8);
  margin-top: 2px;
}
.crystal { position: relative; z-index: 2; display: grid; place-items: center; margin: 4px 0; filter: drop-shadow(0 0 18px rgba(120,150,255,.35)); }
.crystal.lit { filter: drop-shadow(0 0 26px rgba(255,214,64,.75)); animation: crystalglow 2.2s ease-in-out infinite; }
@keyframes crystalglow { 0%,100% { transform: scale(1); } 50% { transform: scale(1.06); } }

.map-nodes {
  position: relative; z-index: 2;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  align-content: safe center;
  padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
}
.node {
  position: relative;
  border: none;
  border-radius: var(--radius);
  background: rgba(13, 20, 54, .82);
  outline: 3px solid rgba(255,255,255,.2);
  color: #fff;
  font-family: inherit;
  padding: 12px 10px 12px;
  text-align: center;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .12s ease, outline-color .2s;
}
.node:not(.locked):hover { transform: translateY(-3px) scale(1.02); outline-color: var(--gold); }
.node:active { transform: scale(.97); }
.node.locked { filter: grayscale(.9) brightness(.6); cursor: not-allowed; }
.node .node-portrait {
  display: block;
  width: 100%;
  height: clamp(88px, 15svh, 150px);
  border-radius: 14px;
  overflow: hidden;
  margin: 0 auto 8px;
  border: 3px solid var(--gold);
  box-shadow: 0 4px 14px rgba(0,0,0,.5);
  background: #223;
}
.node.node-boss .node-portrait { border-color: #b45cff; }
.node .node-portrait img { width: 100%; height: 100%; object-fit: cover; object-position: center 26%; }
.node .node-nr { position: absolute; top: 8px; left: 10px; font-size: 13px; font-weight: 700; opacity: .7; }
.node .node-name { font-weight: 800; font-size: 16px; line-height: 1.15; }
.node .node-hero { font-size: 13px; opacity: .75; margin-top: 1px; }
.node .node-stars { margin-top: 6px; font-size: 15px; letter-spacing: 2px; color: var(--gold); }
.node .node-stars .off { color: rgba(255,255,255,.25); }
.node .node-lock {
  position: absolute; top: 8px; right: 10px; font-size: 15px;
}
.node.node-comic { outline-color: var(--gold); }
.node.node-comic .node-portrait img { object-fit: contain; background: #0d1436; }
.map-foot { position: relative; z-index: 2; text-align: center; padding: 0 0 calc(10px + env(safe-area-inset-bottom)); font-size: 14px; opacity: .8; }

/* ---------- ekran gry ---------- */
#screen-game { background: #0b1130; }
.game-top {
  display: flex; align-items: center; gap: 10px;
  padding: max(10px, env(safe-area-inset-top)) 12px 8px;
  z-index: 5;
}
.game-title-chip { font-weight: 800; font-size: 16px; opacity: .9; }
.game-stats { margin-left: auto; display: flex; gap: 8px; align-items: center; font-weight: 800; }
.stat-chip {
  background: rgba(10, 16, 44, .68);
  border: 2px solid rgba(255,255,255,.28);
  border-radius: 999px;
  padding: 4px 14px;
  font-size: 15px;
  min-width: 66px;
  text-align: center;
  white-space: nowrap;
}
.stat-chip.timer.low { color: #ff8a80; border-color: #ff8a80; animation: blink .5s steps(2) infinite; }
@keyframes blink { 50% { opacity: .55; } }
.hearts { font-size: 17px; letter-spacing: 2px; }
.hearts .off { opacity: .25; }

.arena {
  position: relative;
  flex: 1;
  margin: 0 10px calc(10px + env(safe-area-inset-bottom));
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: inset 0 0 0 3px rgba(255,255,255,.12), var(--shadow);
  background: #000;
  transition: filter .25s ease;
}
.arena.junk-hit { filter: grayscale(.85) brightness(.75); }
.arena.shake { animation: shake .35s ease; }
@keyframes shake {
  0%,100% { transform: translate(0,0); }
  20% { transform: translate(-8px, 3px); }
  40% { transform: translate(7px, -3px); }
  60% { transform: translate(-5px, 2px); }
  80% { transform: translate(4px, -2px); }
}
.arena canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

/* wspólne dla gier DOM */
.game-msg {
  position: absolute; left: 50%; top: 34%;
  transform: translate(-50%, -50%);
  z-index: 6;
  font-size: clamp(22px, 5vw, 34px);
  font-weight: 800;
  text-align: center;
  text-shadow: 0 3px 12px rgba(0,0,0,.85);
  pointer-events: none;
  opacity: 0;
  transition: opacity .3s;
}
.game-msg.show { opacity: 1; }

.float-pt {
  position: absolute;
  z-index: 6;
  font-weight: 800;
  font-size: 20px;
  pointer-events: none;
  text-shadow: 0 2px 6px rgba(0,0,0,.7);
  animation: floatup 1s ease-out forwards;
}
@keyframes floatup { from { opacity: 1; transform: translateY(0); } to { opacity: 0; transform: translateY(-70px); } }

/* --- misja sortowanie --- */
.sort-wrap { position: absolute; inset: 0; background: center / cover no-repeat; }
.sort-dim { position: absolute; inset: 0; background: rgba(8, 12, 36, .55); }
.sort-zone {
  position: absolute; bottom: 12px; width: 42%;
  height: 30%;
  border-radius: var(--radius);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px;
  font-weight: 800; font-size: clamp(13px, 2.6vw, 17px);
  text-align: center;
  border: 3px dashed rgba(255,255,255,.4);
  transition: transform .15s, background .2s, border-color .2s;
}
.sort-zone .zone-ico { font-size: 34px; line-height: 1; }
.sort-zone-left { left: 4%; background: rgba(88, 24, 128, .5); }
.sort-zone-right { right: 4%; background: rgba(20, 90, 50, .5); }
.sort-zone.zone-hot { transform: scale(1.05); border-color: var(--gold); }
.sort-zone .zone-fill {
  position: absolute; bottom: 0; left: 0; right: 0;
  border-radius: 0 0 17px 17px;
  background: linear-gradient(180deg, rgba(255,214,64,.15), rgba(255,214,64,.45));
  height: 0%;
  transition: height .3s ease;
  pointer-events: none;
}
.sort-card {
  position: absolute;
  left: 50%; top: 34%;
  width: min(200px, 44vw);
  aspect-ratio: 1.1;
  margin-left: min(-100px, -22vw);
  border-radius: var(--radius);
  background: rgba(255,255,255,.96);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  cursor: grab;
  touch-action: none;
  z-index: 4;
}
.sort-card img { width: 78%; height: 64%; object-fit: contain; pointer-events: none; }
.sort-card .card-name { font-weight: 800; color: var(--ink); font-size: 17px; }
.sort-ring { position: absolute; top: -8px; right: -8px; width: 44px; height: 44px; }
.sort-ring circle { fill: #fff; stroke: var(--orange); stroke-width: 5; }
.sort-hint { position: absolute; top: 12px; left: 0; right: 0; text-align: center; font-size: 15px; font-weight: 700; text-shadow: 0 2px 8px rgba(0,0,0,.8); opacity: .9; z-index: 3; }

/* --- misja sen (sekwencja) --- */
.sleep-wrap { position: absolute; inset: 0; background: center / cover no-repeat; }
.sleep-dim { position: absolute; inset: 0; background: rgba(6, 8, 28, .42); }
.sleep-status {
  position: absolute; top: 14px; left: 0; right: 0;
  text-align: center; z-index: 3;
  font-weight: 800; font-size: clamp(17px, 3.6vw, 22px);
  text-shadow: 0 2px 10px rgba(0,0,0,.9);
}
.sleep-moons { position: absolute; top: 46px; left: 0; right: 0; text-align: center; font-size: 19px; letter-spacing: 4px; z-index: 3; }
.sleep-moons .off { opacity: .25; }
.sleep-tiles {
  position: absolute; left: 50%; top: 56%;
  transform: translate(-50%, -50%);
  display: grid;
  grid-template-columns: repeat(3, minmax(84px, 110px));
  gap: 14px;
  justify-items: center;
  z-index: 3;
}
.sleep-tiles .tile:nth-child(4) { grid-column: 1 / 2; }
.tile {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 22px;
  border: 3px solid rgba(255,255,255,.35);
  background: rgba(20, 28, 70, .85);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px;
  cursor: pointer;
  font-family: inherit;
  color: #fff;
  font-size: 12.5px;
  font-weight: 700;
  transition: transform .1s, background .15s, border-color .15s, box-shadow .15s;
}
.tile svg { width: 42%; height: 42%; }
.tile.lit {
  background: #ffd54d;
  color: #4a2f00;
  border-color: #fff;
  box-shadow: 0 0 26px rgba(255, 214, 64, .8);
  transform: scale(1.07);
}
.tile.good { background: #4caf50; border-color: #fff; }
.tile.bad { background: var(--red); border-color: #fff; animation: shake .3s; }
.tile:disabled { cursor: default; }

/* ---------- dialogi ---------- */
.overlay {
  position: absolute; inset: 0;
  z-index: 20;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(5, 8, 24, .45);
  padding: 18px;
  padding-bottom: max(26px, env(safe-area-inset-bottom));
}
#result.overlay, #modal.overlay { align-items: center; }
.dialog-box {
  width: min(560px, 96vw);
  display: flex; gap: 14px;
  background: #fff;
  color: var(--ink);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  animation: pop .25s ease;
}
@keyframes pop { from { transform: translateY(24px) scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
.dialog-portrait {
  flex: 0 0 84px;
  width: 84px; height: 84px;
  border-radius: 50%;
  overflow: hidden;
  border: 4px solid var(--gold);
  align-self: center;
  background: #223;
}
.dialog-portrait img { width: 100%; height: 100%; object-fit: cover; }
.dialog-body { flex: 1; display: flex; flex-direction: column; }
.dialog-name { font-weight: 800; color: var(--orange); font-size: 15px; }
.dialog-text { font-size: 17px; line-height: 1.35; flex: 1; margin: 2px 0 8px; min-height: 3.9em; }
.dialog-body .btn { align-self: flex-end; }

/* ---------- wynik ---------- */
.result-box {
  width: min(440px, 94vw);
  background: #fff;
  color: var(--ink);
  border-radius: var(--radius);
  padding: 22px 20px;
  text-align: center;
  box-shadow: var(--shadow);
  animation: pop .3s ease;
}
.result-box h3 { font-size: 25px; font-weight: 800; }
.result-stars { font-size: 44px; letter-spacing: 6px; color: var(--gold); margin: 6px 0 2px; text-shadow: 0 2px 0 rgba(138,90,0,.4); }
.result-stars .off { color: #d8d8de; text-shadow: none; }
.result-score { font-size: 17px; font-weight: 700; margin-bottom: 10px; }
.wiedza-card {
  background: #f2f6ff;
  border-left: 5px solid var(--gold);
  border-radius: 10px;
  text-align: left;
  padding: 10px 14px;
  font-size: 15px;
  line-height: 1.4;
  margin-bottom: 16px;
}
.wiedza-card b { color: var(--orange); }
.result-btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---------- modal ---------- */
.modal-box {
  position: relative;
  width: min(480px, 94vw);
  max-height: 86svh;
  overflow: auto;
  background: #fff;
  color: var(--ink);
  border-radius: var(--radius);
  padding: 24px 22px;
  box-shadow: var(--shadow);
  animation: pop .25s ease;
}
.modal-box h3 { font-size: 21px; margin-bottom: 8px; }
.modal-box h4 { font-size: 16px; margin: 14px 0 4px; }
.modal-box p, .modal-box li { font-size: 15px; line-height: 1.45; }
.modal-box ul, .modal-box ol { padding-left: 20px; margin: 4px 0; }
.modal-close { position: absolute; top: 10px; right: 10px; background: #eee; color: var(--ink); border-color: #ccc; }

/* ---------- nagroda ---------- */
#screen-reward { align-items: center; justify-content: center; text-align: center; overflow: auto; }
.reward-bg {
  position: fixed; inset: 0;
  background: url('../assets/img/bg-reward.webp') center / cover no-repeat;
}
.reward-bg::after { content: ''; position: absolute; inset: 0; background: rgba(10, 14, 40, .68); }
.reward-inner { position: relative; z-index: 1; padding: 26px 18px; max-width: 520px; margin: auto; }
.badge-wrap { animation: badgefloat 3s ease-in-out infinite; filter: drop-shadow(0 8px 24px rgba(255,195,0,.5)); }
@keyframes badgefloat { 0%,100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-8px) rotate(2deg); } }
.reward-inner h2 { font-size: clamp(26px, 6vw, 34px); font-weight: 800; margin: 10px 0 6px; text-shadow: 0 3px 12px rgba(0,0,0,.8); }
.reward-lead { font-size: 17px; margin-bottom: 18px; text-shadow: 0 2px 8px rgba(0,0,0,.8); }
.reward-comic {
  display: flex; gap: 16px; align-items: center;
  background: rgba(13, 20, 54, .8);
  border: 3px solid rgba(255,255,255,.2);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 18px;
  text-align: left;
}
.reward-comic img {
  width: 118px; border-radius: 10px;
  box-shadow: var(--shadow);
  transform: rotate(-3deg);
}
.reward-comic-btns { display: flex; flex-direction: column; gap: 9px; flex: 1; }
.reward-comic-btns .btn { font-size: 15px; padding: 10px 14px; }

/* ---------- efekty ---------- */
#fx-layer { position: fixed; inset: 0; pointer-events: none; z-index: 60; overflow: hidden; }
.confetti {
  position: absolute;
  width: 12px; height: 12px;
  top: -20px;
  border-radius: 3px;
  animation: confall linear forwards;
}
@keyframes confall {
  to { transform: translateY(110vh) rotate(720deg); opacity: .9; }
}

/* wąskie ekrany */
@media (max-width: 560px) {
  .map-nodes { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .node .node-portrait { height: clamp(72px, 11svh, 110px); }
  .dialog-text { font-size: 15.5px; }
  .reward-comic { flex-direction: column; text-align: center; }
  .reward-comic img { width: 40vw; max-width: 150px; }
  .game-title-chip { font-size: 13px; line-height: 1.15; max-width: 30vw; }
  .stat-chip { padding: 3px 9px; font-size: 13px; min-width: 0; }
  .hearts { font-size: 14px; }
  .game-top { gap: 6px; }
}
@media (max-height: 620px) {
  .crystal { display: none; }
  .map-title { font-size: 18px; }
}
