:root {
  --bg: #f8f5ea;
  --ink: #1f2a24;
  --accent: #2f644d;
  --line: #d9d0bd;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
  line-height: 1.45;
}

button {
  color: inherit;
  cursor: pointer;
  font: inherit;
}

.app {
  width: min(1120px, calc(100% - 28px));
  margin: auto;
  padding: 22px 0 28px;
}

header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.titleRow {
  display: block;
}

.restartRound {
  display: inline-grid;
  width: 30px;
  height: 30px;
  place-items: center;
  margin-left: 10px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fffdf7;
  color: var(--ink);
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1;
  vertical-align: middle;
}

h1 .restartRound {
  transform: translateY(-0.2em);
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  color: var(--accent);
  font-size: clamp(1.8rem, 4vw, 3rem);
  line-height: 1.05;
}

h2 {
  margin-bottom: 10px;
  font-size: clamp(1.35rem, 2.5vw, 2rem);
}

.status,
.rewards {
  margin-bottom: 0;
  color: #5d665e;
  font-weight: 700;
}

.game {
  display: grid;
  align-items: start;
  grid-template-columns: minmax(0, 1.2fr) minmax(300px, 0.8fr);
  gap: 24px;
  margin-top: 20px;
}

.photo {
  position: relative;
}

.photo img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  border: 1px solid var(--line);
}

.key {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: 30px;
  height: 30px;
  border: 0;
  background: transparent;
  font-size: 1.35rem;
  font-weight: 800;
  line-height: 1;
  text-shadow: 0 1px 2px #fffdf7, 0 -1px 2px rgba(31, 42, 36, 0.25);
  transform: translate(-50%, -50%);
}

.key:hover,
.key:focus-visible {
  transform: translate(-50%, -50%) scale(1.1);
}

.quiz {
  padding-top: 14px;
  border-top: 2px solid var(--ink);
}

.intro {
  margin: 0 0 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  background: #fffdf7;
}

.question {
  color: var(--accent);
  font-size: 1.1rem;
  font-weight: 800;
}

.answer {
  display: block;
  width: 100%;
  min-height: 48px;
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: #fffdf7;
  text-align: left;
}

.answer.ok {
  border-color: var(--accent);
  background: #e5efe8;
}

.answer.no {
  border-color: #9b3f2d;
  background: #f4ded5;
}

.message {
  min-height: 28px;
  margin: 12px 0 0;
  font-weight: 700;
}

.message:empty {
  display: none;
}

.message.good {
  color: var(--accent);
}

.message.bad {
  color: #9b3f2d;
}

.actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 9px 14px;
  border: 1px solid var(--accent);
  background: transparent;
  font-weight: 800;
}

#next {
  background: var(--accent);
  color: white;
}

.puzzle {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 2px;
  aspect-ratio: 1545 / 712;
}

.puzzleMini {
  width: min(400px, 100%);
  margin: 20px auto 0;
}

.puzzleBig {
  width: 100%;
  margin-top: 4px;
}

.piece {
  background-image: url("assets/corridor.jpg");
  background-size: 600% 300%;
  border: 1px solid var(--line);
}

.slot {
  border: 1px dashed var(--line);
  background: #f3eee0;
}

.puzzle button {
  display: block;
  padding: 0;
  background-color: transparent;
}

.puzzle button.slot {
  background-color: #f3eee0;
}

.puzzle .sel {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}

.puzzle button:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}

#finalPuzzleNote {
  margin: 8px 0 0;
}

.finalPuzzleActions {
  margin-top: 8px;
}

#finalStats {
  font-weight: 800;
}

#puzzleContinue {
  background: var(--accent);
  color: white;
}

.trophy {
  display: grid;
  justify-items: center;
  gap: 14px;
  padding: 18px 0 8px;
}

.trophyCup {
  font-size: 72px;
  line-height: 1;
}

.trophySeal {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 20px 26px;
  border: 3px double var(--accent);
  border-radius: 50%;
  color: var(--accent);
  font-weight: 800;
  letter-spacing: 1px;
  text-align: center;
  text-transform: uppercase;
  transform: rotate(-7deg);
}

.trophySeal span:last-child {
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 2px;
}

.trophyText {
  margin: 0;
  color: #5d665e;
  font-weight: 700;
}

@media (prefers-reduced-motion: no-preference) {
  .trophy {
    animation: trophyIn 0.45s;
  }

  @keyframes trophyIn {
    from {
      opacity: 0;
      transform: scale(0.7);
    }

    to {
      opacity: 1;
      transform: scale(1);
    }
  }

  .trophyCup {
    animation: cupBounce 0.8s;
  }

  @keyframes cupBounce {
    0% {
      transform: translateY(-28px);
      opacity: 0;
    }

    60% {
      transform: translateY(6px);
      opacity: 1;
    }

    100% {
      transform: translateY(0);
    }
  }
}

.piece.flip {
  transform: rotate(180deg);
}

.puzzle.solvedBoard {
  gap: 0;
}

.puzzle.solvedBoard .piece {
  border: 0;
}

.confetti {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 50;
}

.confetti span {
  position: absolute;
  top: -18px;
  width: 9px;
  height: 14px;
  animation: confettiFall linear both;
}

@keyframes confettiFall {
  to {
    transform: translateY(105vh) rotate(660deg);
  }
}

@media (prefers-reduced-motion: no-preference) {
  .puzzleMini.shake {
    animation: shake 0.4s;
  }

  @keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-5px); }
    40% { transform: translateX(5px); }
    60% { transform: translateX(-4px); }
    80% { transform: translateX(4px); }
  }

  .puzzle.solvedBoard {
    animation: solvedPop 0.5s;
  }

  @keyframes solvedPop {
    0% { transform: scale(1); }
    40% { transform: scale(1.03); }
    100% { transform: scale(1); }
  }
}

@media (prefers-reduced-motion: reduce) {
  .confetti {
    display: none;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .puzzleBig .piece {
    transition: transform 0.25s;
  }

  .puzzleBig.animatePieces .piece {
    animation: pieceIn 0.45s both;
  }

  @keyframes pieceIn {
    from {
      opacity: 0;
      transform: scale(0.55);
    }

    to {
      opacity: 1;
      transform: scale(1);
    }
  }
}

.rewards,
.sources {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.rewards {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.reward {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fffdf7;
  color: var(--ink);
  white-space: nowrap;
}

.modalLayer {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(31, 42, 36, 0.45);
}

.final {
  width: min(520px, 100%);
  padding: 22px;
  border: 1px solid var(--line);
  background: var(--bg);
  box-shadow: 0 20px 60px rgba(31, 42, 36, 0.25);
}

.finalHead {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
}

.final h2 {
  color: var(--accent);
}

.final h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.finalBlock {
  margin-top: 16px;
}

.finalPrizes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.finalReward {
  display: grid;
  gap: 2px;
  margin-top: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: #fffdf7;
}

.finalReward span,
.finalCoins,
.finalNote {
  color: #5d665e;
}

.finalCoins {
  margin-top: 16px;
}

.instructionsList {
  margin: 12px 0 0;
  padding-left: 20px;
}

.startActions {
  display: flex;
  justify-content: flex-end;
  margin-top: 18px;
}

.startActions button {
  min-height: 42px;
  padding: 9px 14px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: white;
  font-weight: 800;
}

.sourcesInner {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px;
  align-items: center;
  gap: 28px;
}

.sourcesTitle {
  margin-bottom: 8px;
  color: #5d665e;
  font-weight: 800;
}

.sources ul {
  margin: 0;
  padding-left: 20px;
}

.sources a {
  color: var(--accent);
}

.sourceBrand {
  display: grid;
  justify-items: center;
  gap: 3px;
  color: #5d665e;
  font-weight: 800;
  text-align: center;
}

.sourceBrand img {
  width: 76px;
  height: auto;
}

.sourceBrand a {
  display: block;
  line-height: 0;
}

.sourceBrand span {
  font-weight: 700;
}

@media (max-width: 760px) {
  header,
  .game {
    display: block;
  }

  .status,
  .quiz {
    margin-top: 16px;
  }

  .photo img {
    aspect-ratio: 4 / 3;
  }

  .actions {
    flex-direction: column;
  }

  .sourcesInner {
    align-items: flex-start;
    grid-template-columns: 1fr;
  }

  .sourceBrand {
    align-self: center;
  }
}
