:root {
  --bg: #24180e;
  --card: #f4e9cf;
  --card2: #e5d3ab;
  --edge: #6b4a2b;
  --edge-dark: #4a321c;
  --ink: #3a2614;
  --muted: #7a5c3e;
  --fire: #e8772e;
  --fire-dark: #a24f17;
  --good: #3c9a3c;
  --good-bg: #dcf3cf;
  --bad: #c8452f;
  --bad-bg: #f9d6cd;
  --gold: #f2b632;
  --option: #fffaf0;
  --option-edge: #c2a679;
  --option-shadow: #b39566;
  --title-font: "Chalkboard SE", "Comic Sans MS", "Trebuchet MS", cursive;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  font-family: "Trebuchet MS", "Segoe UI", Verdana, system-ui, sans-serif;
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.hidden { display: none !important; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

/* ---------- HUD ---------- */

#hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) calc(10px + env(safe-area-inset-right)) 8px calc(10px + env(safe-area-inset-left));
  pointer-events: none;
}

.pill {
  background: rgba(36, 22, 10, 0.78);
  color: #fff4dc;
  border-radius: 999px;
  padding: 6px 14px;
  font-weight: bold;
  font-size: clamp(15px, 2.2vw, 20px);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
  white-space: nowrap;
}

.hud-title {
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.hud-right { display: flex; align-items: center; gap: 8px; }

.heart {
  display: inline-block;
  font-size: clamp(20px, 3vw, 28px);
  transition: filter 0.2s, opacity 0.2s;
}
.heart.lost { filter: grayscale(1); opacity: 0.35; }
.heart.pop { animation: pop 0.7s; }
.heart.heal { animation: heal 0.9s; }

@keyframes pop {
  0% { transform: scale(1); }
  30% { transform: scale(1.7) rotate(-14deg); }
  100% { transform: scale(1); }
}

@keyframes heal {
  0% { transform: scale(0.4); filter: drop-shadow(0 0 0 #7dff7a); }
  40% { transform: scale(1.6); filter: drop-shadow(0 0 8px #7dff7a); }
  100% { transform: scale(1); filter: none; }
}

.hud-btn {
  pointer-events: auto;
  width: 50px;
  height: 50px;
  border: 0;
  border-radius: 50%;
  background: rgba(36, 22, 10, 0.78);
  color: #fff4dc;
  font-size: 22px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.35);
}

@media (max-width: 640px) {
  .hud-title { display: none; }
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 12px 20px;
  border-radius: 16px;
  background: rgba(36, 22, 10, 0.9);
  color: #fff4dc;
  font-size: clamp(16px, 2.4vw, 22px);
  font-weight: bold;
  text-align: center;
  pointer-events: none;
  animation: toast-in 0.3s;
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------- nakładki i karty ---------- */

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(16px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
}

#dialog { background: rgba(20, 12, 6, 0.55); }
.screen.dim { background: rgba(20, 12, 6, 0.6); }
.screen.opaque {
  background:
    radial-gradient(ellipse at 50% 15%, rgba(232, 119, 46, 0.35), transparent 55%),
    radial-gradient(ellipse at 50% 40%, #6b4a2b 0%, #3a2614 55%, #1d130a 100%);
}

.card {
  width: 100%;
  max-height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding: clamp(16px, 3vw, 28px);
  background: linear-gradient(180deg, var(--card), var(--card2));
  border: 4px solid var(--edge);
  border-radius: 24px;
  box-shadow: 0 8px 0 var(--edge-dark), 0 20px 50px rgba(0, 0, 0, 0.5);
  outline: none;
  animation: card-in 0.22s ease-out;
}

@keyframes card-in {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.dialog-card { max-width: 780px; }
.dialog-card.shake { animation: shake 0.45s; }

@keyframes shake {
  0%, 100% { transform: none; }
  15% { transform: translate(-12px, 4px) rotate(-1.5deg); }
  30% { transform: translate(10px, -3px) rotate(1.2deg); }
  45% { transform: translate(-8px, 2px) rotate(-0.8deg); }
  60% { transform: translate(6px, -1px); }
  80% { transform: translate(-3px, 0); }
}

/* "BAM!" po złej odpowiedzi */
.bam {
  position: fixed;
  top: 18%;
  left: 50%;
  font-family: var(--title-font);
  font-size: clamp(64px, 14vw, 130px);
  font-weight: bold;
  color: #ffdd33;
  -webkit-text-stroke: 5px #6b1d0e;
  text-shadow: 0 8px 0 #6b1d0e;
  pointer-events: none;
  animation: bam 1.1s ease-out forwards;
}

@keyframes bam {
  0% { transform: translate(-50%, -50%) scale(0.2) rotate(-25deg); opacity: 0; }
  20% { transform: translate(-50%, -50%) scale(1.25) rotate(-8deg); opacity: 1; }
  35% { transform: translate(-50%, -50%) scale(1) rotate(-10deg); }
  75% { opacity: 1; }
  100% { transform: translate(-50%, -80%) scale(1) rotate(-10deg); opacity: 0; }
}

.npc-line {
  font-style: italic;
  font-weight: bold;
  color: #7a3b12;
}
.screen-card { max-width: 780px; text-align: center; }

h1 {
  margin: 4px 0 10px;
  font-family: var(--title-font);
  font-size: clamp(28px, 5vw, 44px);
  line-height: 1.15;
  color: #5a3214;
}

.title-main {
  font-size: clamp(34px, 7vw, 62px);
  text-shadow: 0 3px 0 #f8d9a0;
}

p {
  margin: 8px 0;
  font-size: clamp(17px, 2.3vw, 22px);
  line-height: 1.45;
}

.logo { font-size: clamp(44px, 8vw, 72px); line-height: 1.1; }

.kicker {
  font-size: 15px;
  font-weight: bold;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.story { font-style: italic; }

.controls {
  font-size: clamp(14px, 1.9vw, 17px);
  color: var(--muted);
}

.hint { color: var(--muted); font-style: italic; }

/* ---------- przyciski ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 60px;
  min-width: 200px;
  margin: 8px;
  padding: 12px 26px;
  border: 0;
  border-radius: 18px;
  font-size: clamp(19px, 2.6vw, 24px);
  font-weight: bold;
  color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25);
  background: linear-gradient(180deg, #f59a48, var(--fire));
  box-shadow: 0 6px 0 var(--fire-dark);
  transition: transform 0.08s, box-shadow 0.08s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--fire-dark); }

.btn.secondary {
  background: linear-gradient(180deg, #c9ad84, #a88a62);
  box-shadow: 0 6px 0 #6f5636;
}
.btn.secondary:active { box-shadow: 0 2px 0 #6f5636; }

.btn.danger {
  background: linear-gradient(180deg, #e0644c, var(--bad));
  box-shadow: 0 6px 0 #8a2a1a;
}
.btn.danger:active { box-shadow: 0 2px 0 #8a2a1a; }

.btn:focus-visible, .opt:focus-visible, .lvl:focus-visible, .char:focus-visible, .hud-btn:focus-visible {
  outline: 4px solid #2e86c1;
  outline-offset: 3px;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 12px;
}

.btn-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 12px 0;
}
.btn-col .btn { width: min(340px, 100%); }

/* ---------- okno rozmowy ---------- */

.dlg-head {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 10px;
}

.portrait {
  flex: none;
  width: 84px;
  height: 84px;
  border: 3px solid var(--edge);
  border-radius: 50%;
  background: #fff6df;
}

.dlg-name { font-size: clamp(18px, 2.4vw, 22px); font-weight: bold; }

.dlg-kind {
  display: inline-block;
  margin-top: 4px;
  padding: 3px 12px;
  border-radius: 999px;
  background: var(--edge);
  color: #fff4dc;
  font-size: 14px;
  font-weight: bold;
  letter-spacing: 0.03em;
}

.dlg-q {
  margin: 6px 0 14px;
  font-size: clamp(20px, 2.9vw, 28px);
  font-weight: bold;
  line-height: 1.35;
}

.dlg-quote {
  margin: 0 0 14px;
  padding: 10px 14px;
  border-left: 6px solid var(--fire);
  border-radius: 10px;
  background: #fff8e6;
  font-size: clamp(18px, 2.5vw, 23px);
  font-style: italic;
  line-height: 1.4;
}

.opts { display: grid; gap: 10px; }

.opt {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 64px;
  padding: 10px 14px;
  text-align: left;
  font-size: clamp(17px, 2.4vw, 22px);
  line-height: 1.3;
  background: var(--option);
  border: 3px solid var(--option-edge);
  border-radius: 16px;
  box-shadow: 0 4px 0 var(--option-shadow);
}
.opt:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--option-shadow); }
.opt:disabled { cursor: default; }

.opt-key {
  flex: none;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--edge);
  color: #fff;
  font-size: 18px;
  font-weight: bold;
}

.opt.correct { background: var(--good-bg); border-color: var(--good); box-shadow: 0 4px 0 var(--good); }
.opt.correct .opt-key { background: var(--good); }
.opt.wrong { background: var(--bad-bg); border-color: var(--bad); box-shadow: 0 4px 0 var(--bad); }
.opt.wrong .opt-key { background: var(--bad); }
.opt.dim, .opt.used { opacity: 0.5; }

.feedback {
  margin-top: 14px;
  padding: 12px 16px;
  border-radius: 14px;
  font-size: clamp(17px, 2.4vw, 22px);
  line-height: 1.4;
}
.feedback p { margin: 6px 0 0; }
.feedback.correct { background: var(--good-bg); border: 3px solid var(--good); }
.feedback.wrong { background: var(--bad-bg); border: 3px solid var(--bad); }
.feedback.read { background: #fff8e6; border: 3px solid var(--option-edge); }

.info-text p { margin: 10px 0; }

.dlg-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  margin-top: 8px;
}

.order-slots {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 0 0 14px;
}

.slot {
  flex: 1 1 160px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  padding: 8px 12px;
  border: 3px dashed var(--option-shadow);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.4);
  font-size: clamp(17px, 2.4vw, 22px);
}
.slot-num { font-weight: bold; color: var(--muted); }
.slot.filled { border-style: solid; border-color: var(--good); background: var(--good-bg); }
.slot.fixed { border-style: solid; border-color: var(--bad); background: #fff3ef; }

/* ---------- mapa wędrówki ---------- */

.levels {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
  margin: 16px 0;
}

.lvl {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-height: 170px;
  padding: 14px 10px;
  background: var(--option);
  border: 3px solid var(--option-edge);
  border-radius: 20px;
  box-shadow: 0 5px 0 var(--option-shadow);
}
.lvl:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 var(--option-shadow); }
.lvl .num { font-size: 14px; font-weight: bold; color: var(--muted); }
.lvl .ico { font-size: 44px; line-height: 1; }
.lvl .name { font-size: 17px; font-weight: bold; line-height: 1.2; }
.lvl.locked { opacity: 0.5; filter: grayscale(0.8); cursor: default; }
.lvl.next {
  border-color: var(--fire);
  box-shadow: 0 5px 0 var(--fire-dark);
  animation: glow 1.6s ease-in-out infinite;
}

@keyframes glow {
  50% { box-shadow: 0 5px 0 var(--fire-dark), 0 0 0 6px rgba(232, 119, 46, 0.3); }
}

.stars {
  min-height: 26px;
  font-size: 22px;
  letter-spacing: 2px;
  color: var(--gold);
  text-shadow: 0 1px 0 #8a5a12;
}
.stars .off { color: #cbb894; text-shadow: none; }
.stars.big { font-size: 60px; line-height: 1.1; }

/* ---------- wybór postaci ---------- */

.chars {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 16px;
  margin: 16px 0;
}

.char {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 210px;
  padding: 16px;
  background: var(--option);
  border: 3px solid var(--option-edge);
  border-radius: 22px;
  box-shadow: 0 5px 0 var(--option-shadow);
}
.char:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--option-shadow); }
.char canvas { width: 150px; height: 150px; }
.char .name { font-family: var(--title-font); font-size: 28px; font-weight: bold; }

/* ---------- szafa z czapkami ---------- */

.hats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  margin: 16px 0;
}

.hat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 8px 12px;
  background: var(--option);
  border: 3px solid var(--option-edge);
  border-radius: 20px;
  box-shadow: 0 5px 0 var(--option-shadow);
}
.hat:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 var(--option-shadow); }
.hat canvas { width: 110px; height: 110px; }
.hat .name { font-size: 16px; font-weight: bold; line-height: 1.2; }
.hat.worn { border-color: var(--good); background: var(--good-bg); box-shadow: 0 5px 0 var(--good); }
.hat.locked { opacity: 0.55; filter: grayscale(0.9); cursor: default; }
.hat:focus-visible { outline: 4px solid #2e86c1; outline-offset: 3px; }

.new-hat {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 12px;
  background: #fff3c4;
  border: 2px solid var(--gold);
}

/* ---------- zasady na karcie wstępu ---------- */

.rules {
  max-width: 580px;
  margin: 12px auto;
  padding: 0;
  list-style: none;
  text-align: left;
}
.rules li {
  margin: 6px 0;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.5);
  font-size: clamp(16px, 2.3vw, 21px);
  line-height: 1.35;
}
