:root {
  --cream: #f7edda;
  --paper: #fffaf0;
  --moss: #5e8065;
  --moss-dark: #3f604c;
  --sky: #b9ddea;
  --berry: #c96d70;
  --honey: #eab85d;
  --ink: #30413c;
  --shadow: 0 12px 28px rgb(63 74 62 / 12%);
  color: var(--ink);
  font-family: ui-rounded, "Avenir Next", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--cream);
}

body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  background:
    radial-gradient(circle at 10% 0%, rgb(255 255 255 / 45%), transparent 32rem),
    var(--cream);
  touch-action: manipulation;
}

button,
a,
.scene-card {
  min-width: 64px;
  min-height: 64px;
  touch-action: manipulation;
}

.piece,
.drawing-surface {
  touch-action: none;
}

.puzzle-card {
  max-width: 58rem;
  margin: 0 auto;
  padding: clamp(1rem, 3vw, 2rem);
  border-radius: 2rem;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.puzzle-card-heading {
  display: flex;
  gap: 1rem;
  align-items: center;
}

.puzzle-card-heading h2 {
  margin-bottom: 0.4rem;
}

.puzzle-card-heading p:last-child {
  margin-bottom: 0;
}

.puzzle-board {
  position: relative;
  min-height: min(55vw, 24rem);
  margin-block: 1.25rem;
  overflow: hidden;
  border: 3px solid rgb(63 96 76 / 16%);
  border-radius: 1.5rem;
  background: #eaf4e6;
}

.bridge-board {
  display: grid;
  align-content: center;
  gap: 1.5rem;
  padding: 1.25rem;
}

.bridge-stream {
  position: absolute;
  inset: 32% 0 32%;
  background: repeating-linear-gradient(165deg, #a7d6e4 0 1rem, #8bc6d9 1rem 1.25rem);
}

.bridge-targets,
.bridge-pieces {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
}

.bridge-target,
.plank {
  min-height: 4.5rem;
}

.plank {
  font-size: 0.9rem;
}

.shape-board {
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: 1rem;
  padding: 1rem;
}

.shape-targets,
.shape-pieces {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}

.shape-target,
.shape-piece {
  min-height: 5rem;
}

.shape-piece {
  border-radius: 0.8rem;
}

.shape-roof { clip-path: polygon(50% 0, 100% 100%, 0 100%); }
.shape-door { border-radius: 3rem 3rem 0.5rem 0.5rem; }
.shape-window { border-radius: 50%; }

.shape-target {
  min-height: 5rem;
  background: rgb(185 221 234 / 30%);
}

.path-board {
  min-height: 0;
  background: #eaf4e6;
}

.drawing-surface {
  display: block;
  width: 100%;
  height: auto;
  min-height: 16rem;
  cursor: crosshair;
}

.path-track {
  fill: none;
  stroke: #d8b878;
  stroke-width: 42;
  stroke-linecap: round;
  opacity: 0.42;
}

.path-drawn {
  fill: none;
  stroke: var(--moss-dark);
  stroke-width: 28;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cart {
  font-size: 2rem;
}

.cart.is-rolling {
  animation: cart-roll 1.5s ease-in-out both;
}

.puzzle-status {
  min-height: 1.5rem;
  margin-bottom: 1rem;
  color: var(--moss-dark);
  font-weight: 700;
}

.back-button {
  width: 100%;
  min-height: 4.25rem;
}

.piece.is-dragging {
  transform: scale(1.05) rotate(-2deg);
}

.piece.is-placed {
  opacity: 0.52;
  box-shadow: none;
}

.piece.is-returning {
  animation: drop-return 180ms ease-out;
}

button {
  border: 0;
  border-radius: 1.25rem;
  color: var(--paper);
  background: var(--moss);
  font: inherit;
  font-weight: 700;
  padding: 0.75rem 1.25rem;
  cursor: pointer;
}

button:focus-visible,
a:focus-visible,
.piece:focus-visible,
.target:focus-visible,
.drawing-surface:focus-visible {
  outline: 4px solid var(--honey);
  outline-offset: 3px;
}

#app {
  width: min(100%, 78rem);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(1.25rem, env(safe-area-inset-top))
    max(1.25rem, env(safe-area-inset-right))
    max(1.5rem, env(safe-area-inset-bottom))
    max(1.25rem, env(safe-area-inset-left));
}

#map-screen,
#puzzle-screen {
  min-height: calc(100dvh - 2.75rem);
  display: grid;
  align-content: start;
  gap: 1.25rem;
}

.screen-heading {
  max-width: 48rem;
  margin: 0 auto;
  text-align: center;
}

.eyebrow {
  margin: 0 0 0.25rem;
  color: var(--moss-dark);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

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

h1,
h2 {
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1.1;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2rem, 7vw, 3.6rem);
}

#map,
#puzzle {
  width: 100%;
}

#map {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr));
  gap: 1rem;
  align-items: stretch;
}

.scene-card {
  min-height: 12rem;
  padding: 1.25rem;
  border: 3px solid rgb(94 128 101 / 22%);
  border-radius: 2rem;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.scene-card h2 {
  margin-bottom: 0.5rem;
  font-size: 1.6rem;
}

.scene-icon {
  margin: 0 0 0.5rem;
  font-size: 2.5rem;
  line-height: 1;
}

.scene-status {
  min-height: 1.5rem;
  margin-bottom: 1rem;
  color: var(--moss-dark);
  font-weight: 700;
}

.scene-card.is-complete {
  border-color: var(--honey);
}

.scene-card.is-locked {
  opacity: 0.66;
}

.scene-card.is-locked button {
  cursor: not-allowed;
}

.village-rewards {
  grid-column: 1 / -1;
  padding: 1.25rem;
  border-radius: 1.5rem;
  background: rgb(234 184 93 / 18%);
}

.village-rewards h2 {
  margin-bottom: 0.75rem;
}

.reward-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr));
  gap: 0.75rem;
}

.reward-card {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  min-height: 4.5rem;
  padding: 0.75rem 1rem;
  border: 2px solid rgb(234 184 93 / 55%);
  border-radius: 1rem;
  background: var(--paper);
  animation: reward-pop 420ms ease-out both;
}

.reward-card > span {
  font-size: 1.8rem;
}

.reward-card p {
  margin: 0.15rem 0 0;
}

.piece,
.target {
  display: grid;
  place-items: center;
  border-radius: 1.25rem;
}

.piece {
  color: var(--paper);
  background: var(--berry);
  box-shadow: 0 8px 0 rgb(130 63 68 / 18%);
  user-select: none;
}

.target {
  border: 3px dashed var(--moss);
  background: rgb(185 221 234 / 35%);
}

.target.is-occupied {
  border-style: solid;
  border-color: var(--honey);
  background: rgb(234 184 93 / 24%);
}

.target.is-hint,
.drawing-surface.is-hint {
  animation: hint-glow 900ms ease-in-out infinite alternate;
}

.hint {
  border-left: 0.45rem solid var(--honey);
  border-radius: 1rem;
  padding: 1rem 1.1rem;
  background: rgb(234 184 93 / 22%);
}

.celebrate {
  border-radius: 2rem;
  padding: 1.5rem;
  background: var(--sky);
  animation: celebrate-in 500ms ease-out both;
}

.is-hidden {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes celebrate-in {
  from { opacity: 0; transform: translateY(0.75rem) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes hint-glow {
  from { filter: drop-shadow(0 0 0 rgb(234 184 93 / 0%)); }
  to { filter: drop-shadow(0 0 0.8rem rgb(234 184 93 / 90%)); }
}

@keyframes reward-pop {
  from { opacity: 0; transform: translateY(0.35rem) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes cart-roll {
  from { transform: translateX(0); }
  to { transform: translateX(36rem); }
}

@keyframes drop-return {
  from { transform: translate(var(--drop-x, 0), var(--drop-y, 0)); }
  to { transform: translate(0, 0); }
}

@media (orientation: landscape) and (min-width: 48rem) {
  #map-screen,
  #puzzle-screen {
    padding-block: 1rem;
  }

  .screen-heading {
    text-align: left;
    margin-inline: 0;
  }

  #puzzle-screen {
    grid-template-columns: minmax(14rem, 0.35fr) minmax(0, 1fr);
    align-items: start;
  }

  #puzzle-screen .screen-heading {
    position: sticky;
    top: 1rem;
  }
}

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