:root {
  --paper: #fffdf6;
  --cream: #f5eedf;
  --ink: #29382f;
  --deep-moss: #38543d;
  --moss: #5c7656;
  --muted-ink: #6f746a;
  --line: #d8cdb8;
  --amber: #e5a84d;
  --terracotta: #bd684e;
  --sky: #dce8d1;
  --shadow: rgba(45, 62, 45, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: #e9dfca;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(
      circle at top left,
      rgba(255, 255, 255, 0.5),
      transparent 32rem
    ),
    #e9dfca;
  font-family: Georgia, "Times New Roman", serif;
}

button {
  font: inherit;
}

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

button:disabled {
  cursor: not-allowed;
}

[hidden] {
  display: none !important;
}

.game-shell {
  width: min(1180px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2rem 0 3rem;
}

.eyebrow {
  margin: 0;
  color: var(--terracotta);
  font-family: Arial, sans-serif;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.button {
  min-height: 2.55rem;
  padding: 0.7rem 1rem;
  border: 1px solid transparent;
  border-radius: 0.7rem;
  font-family: Arial, sans-serif;
  font-size: 0.78rem;
  font-weight: 800;
  cursor: pointer;
  transition:
    transform 160ms ease,
    background 160ms ease,
    border-color 160ms ease;
}

.button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.button-primary {
  background: var(--moss);
  color: var(--paper);
}

.button-primary:hover:not(:disabled) {
  background: var(--deep-moss);
}

.button-secondary {
  border-color: var(--line);
  background: #f3ece0;
  color: var(--deep-moss);
}

.button-secondary:hover:not(:disabled) {
  border-color: var(--moss);
  background: #e7f2df;
}

.button-small {
  min-height: 2.1rem;
  padding: 0.55rem 0.8rem;
  font-size: 0.7rem;
}

/* Title screen */

.title-screen {
  display: grid;
  grid-template-columns: minmax(180px, 0.75fr) minmax(0, 1.25fr);
  align-items: center;
  gap: clamp(1.5rem, 5vw, 4rem);
  min-height: 72vh;
  padding: clamp(1.5rem, 5vw, 4rem);
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 1.4rem;
  background:
    radial-gradient(
      circle at 20% 10%,
      rgba(255, 255, 255, 0.85),
      transparent 25rem
    ),
    #fffaf0;
  box-shadow: 0 1rem 3rem var(--shadow);
  animation: title-arrive 600ms ease-out;
}

.title-art {
  position: relative;
  min-height: 15rem;
  border-radius: 1.25rem;
  background:
    linear-gradient(
      transparent 73%,
      rgba(92, 118, 86, 0.16) 73%
    ),
    var(--sky);
}

.title-letter {
  position: absolute;
  top: 22%;
  left: 27%;
  display: grid;
  width: 6rem;
  height: 4.5rem;
  place-items: center;
  border: 4px solid var(--deep-moss);
  border-radius: 0.6rem;
  background: var(--paper);
  color: var(--terracotta);
  font-size: 2.5rem;
  transform: rotate(-8deg);
  box-shadow: 0.4rem 0.6rem 0 rgba(56, 84, 61, 0.14);
}

.title-letter img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
}

.completion-icon img {
  display: block;
  width: 70%;
  height: auto;
  object-fit: contain;
}

.title-snail {
  position: absolute;
  right: 15%;
  bottom: 13%;
  width: clamp(6rem, 18vw, 10rem);
  transform: rotate(-6deg);
}

.title-snail img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
}

.title-copy h1 {
  margin: 0.25rem 0 0.75rem;
  color: var(--deep-moss);
  font-size: clamp(3rem, 9vw, 6.5rem);
  line-height: 0.9;
}

.title-lede {
  max-width: 35rem;
  margin: 0;
  color: var(--muted-ink);
  font-size: clamp(1rem, 2vw, 1.3rem);
  line-height: 1.55;
}

.title-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  margin-top: 1.5rem;
}

.title-progress {
  min-height: 1.4rem;
  margin: 0.8rem 0 0;
  color: var(--muted-ink);
  font-family: Arial, sans-serif;
  font-size: 0.78rem;
}

/* Header */

.game-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.game-header h1 {
  margin: 0.15rem 0 0.35rem;
  color: var(--deep-moss);
  font-size: clamp(2.2rem, 6vw, 4.8rem);
  line-height: 0.95;
}

.game-header h2 {
  margin: 0;
  color: var(--moss);
  font-size: clamp(1.2rem, 3vw, 1.8rem);
}

.header-actions {
  display: flex;
  align-items: flex-end;
  gap: 0.7rem;
}

.level-progress {
  margin: 0 0 0.25rem;
  color: var(--muted-ink);
  font: 700 0.75rem Arial, sans-serif;
  white-space: nowrap;
}

/* Progress */

.progress-panel,
.level-map {
  margin-bottom: 1.5rem;
  padding: 1rem 1.25rem;
  border: 1px solid rgba(255, 255, 255, 0.75);
  border-radius: 1rem;
  background: rgba(255, 253, 246, 0.72);
  box-shadow: 0 0.6rem 1.5rem var(--shadow);
}

.progress-heading,
.level-map-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
}

.progress-heading h2,
.level-map-heading h2 {
  margin: 0;
  font-size: 1.05rem;
}

.progress-heading span {
  color: var(--moss);
  font: 700 0.75rem Arial, sans-serif;
}

.progress-track {
  height: 0.55rem;
  margin-top: 0.8rem;
  overflow: hidden;
  border-radius: 999px;
  background: #e5dcc8;
}

.progress-fill {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--moss);
  transition: width 400ms ease;
}

.progress-stamps {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.7rem;
}

.progress-stamp {
  display: grid;
  width: 1.5rem;
  height: 1.5rem;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #f3ece0;
  color: var(--muted-ink);
  font-family: Arial, sans-serif;
  font-weight: 700;
}

.progress-stamp.complete {
  border-color: var(--moss);
  background: #e7f2df;
  color: var(--moss);
}

/* Level map */

.level-map-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
}

.level-map-description {
  max-width: 48rem;
  margin: 0.75rem 0 1rem;
  color: var(--muted-ink);
  font-family: Arial, sans-serif;
  font-size: 0.82rem;
}

.level-map-list {
  display: grid;
  grid-template-columns: repeat(
    auto-fit,
    minmax(200px, 1fr)
  );
  gap: 0.7rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.level-map-button {
  display: flex;
  width: 100%;
  min-height: 4.2rem;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  background: #f8f1e3;
  color: var(--ink);
  text-align: left;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.level-map-button:not(:disabled) {
  cursor: pointer;
}

.level-map-button:not(:disabled):hover {
  border-color: var(--moss);
  transform: translateY(-1px);
}

.level-map-button:disabled {
  opacity: 0.5;
}

.level-map-button.current {
  border-color: var(--moss);
  box-shadow: 0 0 0 3px rgba(92, 118, 86, 0.14);
}

.level-map-button.rescued {
  background: #e7f2df;
}

.level-map-number {
  display: grid;
  width: 2rem;
  height: 2rem;
  flex: 0 0 2rem;
  place-items: center;
  border-radius: 50%;
  background: #e5dcc8;
  color: var(--deep-moss);
  font: 700 0.9rem Arial, sans-serif;
}

.level-map-button.rescued .level-map-number {
  background: var(--moss);
  color: var(--paper);
}

.level-map-copy {
  display: grid;
  min-width: 0;
  gap: 0.2rem;
}

.level-map-copy strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.level-map-copy small {
  color: var(--muted-ink);
  font-family: Arial, sans-serif;
  font-size: 0.7rem;
}

.level-map > .button {
  margin-top: 1rem;
}

/* Game layout */

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(260px, 0.6fr);
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.puzzle-panel,
.team-panel,
.readme {
  padding: clamp(1.1rem, 3vw, 1.6rem);
  border: 1px solid rgba(255, 255, 255, 0.75);
  border-radius: 1rem;
  background: var(--paper);
  box-shadow: 0 0.6rem 1.5rem var(--shadow);
}

.section-heading,
.readme-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.section-heading h2,
.readme-header h2 {
  margin: 0.25rem 0 0;
  color: var(--deep-moss);
  font-size: 1.4rem;
}

.message {
  min-height: 2.8rem;
  margin: 1rem 0;
  padding: 0.8rem 0.9rem;
  border-left: 4px solid var(--amber);
  background: #fff5d7;
  color: #755424;
}

.readme-status {
  display: inline-flex;
  align-items: center;
  min-height: 1.6rem;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  background: #f3ece0;
  color: var(--muted-ink);
  font: 700 0.7rem Arial, sans-serif;
  white-space: nowrap;
}

/* Cards */

.card-list {
  display: grid;
  gap: 0.7rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.card-button {
  display: grid;
  width: 100%;
  gap: 0.45rem;
  padding: 1rem;
  border: 2px solid var(--line);
  border-radius: 0.85rem;
  background: #fffaf0;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  transition:
    transform 160ms ease,
    border-color 160ms ease,
    background 160ms ease,
    box-shadow 160ms ease;
}

.card-button:hover {
  border-color: var(--moss);
  transform: translateY(-1px);
}

.card-button.selected {
  border-color: var(--amber);
  background: #fff5d7;
  box-shadow: 0 0 0 3px rgba(229, 168, 77, 0.16);
}

.card-button.correct {
  border-color: var(--moss);
  background: #e7f2df;
}

.card-button.incorrect {
  border-color: var(--terracotta);
  background: #fff0e8;
  animation: incorrect-card 350ms ease-out;
}

.card-copy {
  display: grid;
  gap: 0.25rem;
}

.card-title {
  color: var(--deep-moss);
  font-size: 1.05rem;
  font-weight: 700;
}

.card-description {
  color: var(--ink);
  font-size: 0.92rem;
  line-height: 1.4;
}

.card-flavour {
  color: var(--muted-ink);
  font-size: 0.8rem;
  font-style: italic;
}

.puzzle-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1rem;
}

/* Team */

.team-list {
  display: grid;
  gap: 0.7rem;
  margin-top: 1rem;
}

.team-member {
  display: grid;
  grid-template-columns: 3.2rem 1fr auto;
  align-items: center;
  gap: 0.7rem;
  width: 100%;
  padding: 0.65rem;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  background: #fffaf0;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.team-member.selected {
  border-color: var(--moss);
  background: #e7f2df;
}

.team-member strong,
.team-member small {
  display: block;
}

.team-member small {
  margin-top: 0.2rem;
  color: var(--muted-ink);
  font-family: Arial, sans-serif;
  font-size: 0.7rem;
}

.animal-icon {
  display: grid;
  width: 3.2rem;
  height: 3.2rem;
  place-items: center;
}

.animal-icon img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
}

.selection-mark {
  color: var(--moss);
  font: 700 1.2rem Arial, sans-serif;
}

.team-fit {
  margin: 1rem 0 0;
  padding: 0.8rem;
  border-radius: 0.7rem;
  background: #f3ece0;
  color: var(--muted-ink);
  font-family: Arial, sans-serif;
  font-size: 0.78rem;
  line-height: 1.45;
}

.team-fit.ready {
  background: #e7f2df;
  color: var(--deep-moss);
}

.team-fit.partial {
  background: #fff5d7;
  color: #755424;
}

.team-list.needs-attention {
  animation: team-attention 450ms ease-in-out 2;
}

/* README */

.readme {
  margin-bottom: 1.5rem;
  background:
    linear-gradient(
      90deg,
      rgba(189, 104, 78, 0.06),
      transparent 12rem
    ),
    var(--paper);
}

.readme p {
  max-width: 60rem;
  line-height: 1.6;
}

.readme.rescued {
  border-color: var(--moss);
  animation: readme-repaired 700ms ease-out;
}

/* Workshop */

.workshop-scene {
  position: relative;
  min-height: 220px;
  overflow: hidden;
  margin-bottom: 1.5rem;
  border: 1px solid rgba(255, 255, 255, 0.75);
  border-radius: 1rem;
  background:
    linear-gradient(
      transparent 75%,
      rgba(92, 118, 86, 0.16) 75%
    ),
    var(--sky);
  box-shadow: 0 0.6rem 1.5rem var(--shadow);
}

.mailbox {
  position: absolute;
  right: 20%;
  bottom: 35px;
  width: 100px;
  height: 80px;
  border: 4px solid var(--deep-moss);
  border-radius: 18px 18px 8px 8px;
  background: var(--terracotta);
}

.mailbox img,
.review-icon img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.mailbox::before {
  position: absolute;
  top: -30px;
  left: -4px;
  width: 100px;
  height: 42px;
  border: 4px solid var(--deep-moss);
  border-bottom: 0;
  border-radius: 55px 55px 0 0;
  background: var(--terracotta);
  content: "";
}

.mailbox-door {
  position: absolute;
  right: 18px;
  bottom: 12px;
  width: 60px;
  height: 35px;
  border: 3px solid var(--deep-moss);
  border-radius: 8px;
  background: #efbc81;
}

.mailbox-flag {
  position: absolute;
  top: -35px;
  right: -17px;
  width: 8px;
  height: 48px;
  border-radius: 999px;
  background: var(--deep-moss);
  transform-origin: bottom;
  transition: transform 400ms ease;
}

.mailbox-flag::before {
  position: absolute;
  top: 0;
  left: -1px;
  width: 23px;
  height: 16px;
  border-radius: 3px 3px 0 0;
  background: var(--deep-moss);
  content: "";
}

.snail-character {
  position: absolute;
  bottom: 38px;
  left: 8%;
  z-index: 2;
  animation: snail-breathe 3s ease-in-out infinite;
}

.snail-character img {
  display: block;
  width: 8rem;
  height: auto;
}

.delivery-letter {
  position: absolute;
  right: 27%;
  bottom: 88px;
  z-index: 4;
  opacity: 0;
  color: var(--paper);
  font-size: 2rem;
  filter: drop-shadow(
    0 0.25rem 0.15rem rgba(40, 55, 40, 0.2)
  );
}

.delivery-letter img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
}

.delivery-success {
  animation: workshop-glow 900ms ease-in-out 2;
}

.delivery-success .snail-character {
  animation:
    snail-delivery 2.4s ease-in-out forwards,
    snail-breathe 3s ease-in-out infinite;
}

.delivery-success .mailbox {
  animation: mailbox-open 700ms ease-out forwards;
}

.delivery-success .mailbox-flag {
  background: var(--moss);
  transform: rotate(72deg);
}

.delivery-success .delivery-letter {
  animation: letter-delivery 1.5s ease-out 700ms forwards;
}

/* Completion */

.completion-panel {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding: 1rem 1.25rem;
  border: 2px solid var(--moss);
  border-radius: 1rem;
  background: #e7f2df;
  animation: completion-arrive 450ms ease-out;
}

.completion-icon {
  display: grid;
  width: 3rem;
  height: 3rem;
  flex: 0 0 3rem;
  place-items: center;
  border-radius: 50%;
  background: var(--paper);
  font-size: 1.5rem;
}

.completion-panel h2 {
  margin: 0 0 0.2rem;
  font-size: 1.25rem;
}

.completion-panel p {
  margin-bottom: 0;
}

/* Review dialog */

.review-dialog {
  width: min(560px, calc(100% - 2rem));
  padding: 0;
  border: 0;
  border-radius: 1.25rem;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 1.5rem 5rem rgba(35, 51, 38, 0.35);
}

.review-dialog::backdrop {
  background: rgba(36, 55, 40, 0.48);
  backdrop-filter: blur(3px);
}

.review-dialog-content {
  padding: clamp(1.25rem, 5vw, 2rem);
}

.review-dialog h2 {
  margin: 0.25rem 0 0.45rem;
}

.review-dialog p {
  margin-bottom: 0.9rem;
}

.review-icon {
  display: grid;
  width: 3.5rem;
  height: 3.5rem;
  margin-bottom: 1rem;
  place-items: center;
  border-radius: 50%;
  background: #e7f2df;
  font-size: 1.7rem;
}

.review-facts {
  display: grid;
  gap: 0.7rem;
  margin: 1.25rem 0;
}

.review-facts div {
  padding: 0.8rem;
  border-radius: 0.75rem;
  background: #f5eedf;
}

.review-facts dt {
  color: var(--moss);
  font: 700 0.68rem Arial, sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.review-facts dd {
  margin: 0.25rem 0 0;
  color: var(--deep-moss);
}

.review-joke {
  padding: 0.85rem;
  border-left: 4px solid var(--amber);
  background: #fff5d7;
  color: #755424;
  font-style: italic;
}

.review-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.7rem;
  margin-top: 1.5rem;
}

/* Final screen */

.game-complete-screen {
  display: grid;
  min-height: 72vh;
  place-items: center;
  padding: clamp(1.5rem, 5vw, 4rem);
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 1.4rem;
  background:
    radial-gradient(
      circle at 50% 0,
      rgba(255, 224, 134, 0.48),
      transparent 24rem
    ),
    #fffaf0;
  box-shadow: 0 1rem 3rem var(--shadow);
  text-align: center;
  animation: title-arrive 600ms ease-out;
}

.game-complete-screen h2 {
  max-width: 40rem;
  margin: 0.3rem 0 0.75rem;
  color: var(--deep-moss);
  font-size: clamp(2rem, 6vw, 4rem);
  line-height: 1;
}

.game-complete-screen p:not(.eyebrow) {
  max-width: 36rem;
  color: var(--muted-ink);
  font-size: 1.05rem;
  line-height: 1.55;
}

.game-complete-icon {
  display: grid;
  width: 5rem;
  height: 5rem;
  place-items: center;
  margin-bottom: 1rem;
  border-radius: 50%;
  background: #e7f2df;
  color: var(--moss);
  font-size: 2.5rem;
}

.game-complete-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.7rem;
  margin-top: 1rem;
}

/* Footer */

.game-footer {
  color: var(--muted-ink);
  font-family: Arial, sans-serif;
  font-size: 0.75rem;
  text-align: center;
}

/* Utility */

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

/* Animations */

@keyframes title-arrive {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes snail-breathe {
  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-4px);
  }
}

@keyframes snail-delivery {
  0% {
    left: 8%;
  }

  70% {
    left: 48%;
  }

  100% {
    left: 48%;
  }
}

@keyframes mailbox-open {
  0% {
    transform: translateY(0);
  }

  60% {
    transform: translateY(-7px) rotate(-2deg);
  }

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

@keyframes letter-delivery {
  0% {
    opacity: 0;
    transform: translateY(20px) rotate(-12deg);
  }

  35% {
    opacity: 1;
  }

  100% {
    opacity: 1;
    transform: translateY(-45px) rotate(8deg);
  }
}

@keyframes workshop-glow {
  0%,
  100% {
    box-shadow: inset 0 0 0 rgba(255, 224, 134, 0);
  }

  50% {
    box-shadow: inset 0 0 4rem rgba(255, 224, 134, 0.5);
  }
}

@keyframes readme-repaired {
  0% {
    transform: rotate(0);
  }

  40% {
    transform: rotate(-1deg) scale(1.02);
  }

  100% {
    transform: rotate(0) scale(1);
  }
}

@keyframes completion-arrive {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes incorrect-card {
  0%,
  100% {
    transform: translateX(0);
  }

  35% {
    transform: translateX(-4px);
  }

  70% {
    transform: translateX(4px);
  }
}

@keyframes team-attention {
  0%,
  100% {
    transform: translateX(0);
  }

  25% {
    transform: translateX(-5px);
  }

  75% {
    transform: translateX(5px);
  }
}

/* Responsive layout */

@media (max-width: 760px) {
  .title-screen {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .title-art {
    min-height: 12rem;
  }

  .title-copy {
    text-align: center;
  }

  .title-actions {
    justify-content: center;
  }

  .title-progress {
    text-align: center;
  }

  .game-header,
  .progress-heading,
  .level-map-heading,
  .completion-panel {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-actions {
    width: 100%;
    align-items: center;
    justify-content: space-between;
  }

  .game-layout {
    grid-template-columns: 1fr;
  }

  .level-map-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .level-map-actions .button {
    flex: 1;
  }

  .completion-panel .button {
    width: 100%;
  }

  .review-actions {
    flex-direction: column-reverse;
  }

  .review-actions .button {
    width: 100%;
  }

  .game-complete-screen {
    min-height: 70vh;
  }

  .game-complete-actions {
    width: 100%;
  }

  .game-complete-actions .button {
    width: 100%;
  }
}

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