:root {
  --ink: #2f271e;
  --brown: #704222;
  --brown-dark: #43291b;
  --cream: #fffaf0;
  --paper: #fff7e7;
  --gold: #f5b92e;
  --green: #4d892e;
  --green-dark: #2f641f;
  --blue: #62c9ef;
  --stage-ratio: 1.62;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family:
    "Trebuchet MS", "Avenir Next", Avenir, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 12% 8%, rgba(255, 255, 255, 0.8), transparent 23rem),
    linear-gradient(155deg, #fff9e9 0%, #f4dfb7 52%, #e8c989 100%);
}

button {
  font: inherit;
}

button,
.game-stage {
  -webkit-tap-highlight-color: transparent;
}

.page-shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.masthead {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 16px;
  align-items: center;
  margin: 0 auto 20px;
  padding: 0 8px;
}

.brand-mark {
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  border: 3px solid #fff9e8;
  border-radius: 18px;
  background: var(--brown);
  box-shadow: 0 8px 0 #4e2d1a;
  font-size: 30px;
  transform: rotate(-3deg);
}

.kicker,
.section-kicker,
.overlay-eyebrow {
  margin: 0 0 4px;
  color: var(--green-dark);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.masthead h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.85rem, 4vw, 3.15rem);
  line-height: 0.95;
  letter-spacing: -0.045em;
}

.masthead h1 span {
  color: var(--brown);
}

.bessie-badge {
  min-width: 112px;
  padding: 9px 16px;
  border: 1px solid rgba(82, 50, 29, 0.16);
  border-radius: 999px;
  background: rgba(255, 250, 239, 0.72);
  text-align: center;
}

.bessie-badge span {
  display: block;
  color: #826b55;
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.bessie-badge strong {
  color: var(--brown);
  font-family: Georgia, "Times New Roman", serif;
}

.game-card {
  overflow: hidden;
  border: 1px solid rgba(94, 58, 27, 0.15);
  border-radius: 28px;
  background: rgba(255, 250, 239, 0.94);
  box-shadow:
    0 24px 70px rgba(88, 56, 28, 0.18),
    0 3px 0 rgba(255, 255, 255, 0.9) inset;
}

.game-stage {
  --ground-height: 9%;
  position: relative;
  isolation: isolate;
  width: 100%;
  aspect-ratio: var(--stage-ratio);
  min-height: 360px;
  max-height: 680px;
  overflow: hidden;
  outline: none;
  background-color: #64ccef;
  background-image:
    linear-gradient(to bottom, rgba(45, 177, 230, 0.04), rgba(76, 164, 67, 0.05)),
    url("assets/pasture-panorama.png");
  background-position: center center;
  background-size: cover;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}

.game-stage:focus-visible {
  box-shadow: 0 0 0 5px #fff inset, 0 0 0 9px #e7a818 inset;
}

.sun-glow {
  position: absolute;
  z-index: -1;
  top: 4%;
  right: 8%;
  width: 22%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(255, 244, 181, 0.36);
  filter: blur(12px);
}

.cloud {
  position: absolute;
  z-index: -1;
  width: 12%;
  height: 4%;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.52);
  filter: blur(0.5px);
  animation: cloud-drift 18s linear infinite;
}

.cloud::before,
.cloud::after {
  position: absolute;
  bottom: 20%;
  border-radius: 50%;
  background: inherit;
  content: "";
}

.cloud::before {
  left: 22%;
  width: 37%;
  aspect-ratio: 1;
}

.cloud::after {
  right: 18%;
  width: 29%;
  aspect-ratio: 1;
}

.cloud-one {
  top: 18%;
  left: 34%;
}

.cloud-two {
  top: 32%;
  left: 72%;
  width: 9%;
  opacity: 0.7;
  animation-duration: 24s;
}

@keyframes cloud-drift {
  50% {
    translate: 16px 1px;
  }
}

.game-hud {
  position: absolute;
  z-index: 30;
  top: 18px;
  left: 18px;
  right: 18px;
  display: grid;
  grid-template-columns: auto minmax(170px, 280px) auto;
  gap: 10px;
  align-items: stretch;
  pointer-events: none;
}

.hud-chip,
.hud-progress,
.icon-button {
  border: 1px solid rgba(255, 255, 255, 0.75);
  background: rgba(42, 48, 31, 0.67);
  box-shadow: 0 5px 16px rgba(38, 41, 22, 0.14);
  color: white;
  backdrop-filter: blur(10px);
}

.hud-chip {
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding: 9px 15px;
  border-radius: 14px;
}

.hud-chip span {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  opacity: 0.82;
  text-transform: uppercase;
}

.hud-chip strong {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.35rem;
}

.hud-progress {
  padding: 8px 12px 10px;
  border-radius: 14px;
}

.hud-progress-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 5px;
  font-size: 0.69rem;
  font-weight: 800;
}

.progress-track {
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.25);
}

.progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: #ffd568;
  transition: width 180ms ease-out;
}

.icon-button {
  display: grid;
  width: 44px;
  border-radius: 14px;
  place-items: center;
  cursor: pointer;
  pointer-events: auto;
}

.icon-button:hover {
  background: rgba(42, 48, 31, 0.82);
}

.obstacle-layer,
.particle-layer {
  position: absolute;
  z-index: 8;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.obstacle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 11.2%;
  will-change: left;
}

.hay-column {
  position: absolute;
  left: 0;
  width: 100%;
  min-height: 1px;
  background-image: url("assets/hay-bale.png");
  background-repeat: repeat-y;
  background-position-x: center;
  background-size: 100% auto;
  filter:
    drop-shadow(0 4px 1px rgba(83, 49, 13, 0.23))
    drop-shadow(0 10px 10px rgba(73, 54, 18, 0.15));
}

.hay-column.top {
  top: 0;
  border-radius: 0 0 16px 16px;
  background-position-y: bottom;
}

.hay-column.bottom {
  bottom: var(--ground-height);
  border-radius: 16px 16px 0 0;
  background-position-y: top;
}

.hay-column::after {
  position: absolute;
  left: 4%;
  width: 92%;
  height: 13px;
  border-radius: 50%;
  background: rgba(255, 203, 52, 0.42);
  filter: blur(1px);
  content: "";
}

.hay-column.top::after {
  bottom: -1px;
}

.hay-column.bottom::after {
  top: -1px;
}

.bessie {
  position: absolute;
  z-index: 14;
  top: 42%;
  left: 20%;
  width: 10%;
  min-width: 66px;
  max-width: 116px;
  height: auto;
  pointer-events: none;
  transform-origin: 45% 55%;
  filter: drop-shadow(0 7px 4px rgba(48, 38, 23, 0.26));
  will-change: top, transform;
}

.bessie.is-waiting {
  animation: bessie-hover 1.5s ease-in-out infinite;
}

.bessie.is-crashed {
  animation: cow-wobble 400ms ease-in-out;
}

@keyframes bessie-hover {
  50% {
    translate: 0 -8px;
  }
}

@keyframes cow-wobble {
  25% {
    scale: 1.08;
  }
  55% {
    rotate: -12deg;
  }
}

.finish-line {
  position: absolute;
  z-index: 7;
  top: 14%;
  bottom: 9%;
  display: none;
  width: 8px;
  border-left: 4px dashed rgba(255, 255, 255, 0.92);
  border-right: 4px dashed rgba(55, 49, 35, 0.7);
  opacity: 0.88;
}

.finish-line span {
  position: absolute;
  top: -24px;
  left: 50%;
  padding: 5px 9px;
  border-radius: 7px;
  background: #fff9e9;
  color: var(--brown-dark);
  font-size: 0.63rem;
  font-weight: 950;
  letter-spacing: 0.12em;
  transform: translateX(-50%);
}

.ground {
  position: absolute;
  z-index: 18;
  right: 0;
  bottom: 0;
  left: 0;
  height: var(--ground-height);
  background:
    linear-gradient(to bottom, #8ecc3c 0 22%, #6ca82d 23% 34%, #80552c 35% 100%);
  box-shadow: 0 -5px 0 rgba(70, 112, 37, 0.3);
}

.ground::after {
  position: absolute;
  inset: 35% 0 0;
  background:
    radial-gradient(circle at 15px 13px, #a87942 0 2px, transparent 2.5px) 0 0 / 42px
      25px,
    linear-gradient(#80552c, #68411f);
  content: "";
  opacity: 0.8;
}

.ground-grass {
  position: absolute;
  z-index: 1;
  top: -5px;
  width: 100%;
  height: 10px;
  background: repeating-linear-gradient(
    100deg,
    #4f8f24 0 4px,
    #83bd35 4px 8px,
    #b3dc55 8px 12px
  );
  clip-path: polygon(0 55%, 2% 10%, 3% 62%, 5% 0, 6% 65%, 8% 18%, 10% 60%, 100% 45%, 100% 100%, 0 100%);
}

.game-overlay {
  position: absolute;
  z-index: 25;
  display: grid;
  inset: 0;
  padding: 72px 20px 62px;
  place-items: center;
  background:
    linear-gradient(90deg, rgba(27, 47, 31, 0.1), rgba(27, 47, 31, 0.02)),
    rgba(25, 51, 42, 0.12);
  opacity: 1;
  visibility: visible;
  transition:
    opacity 220ms ease,
    visibility 220ms ease;
  cursor: default;
}

.game-overlay.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.overlay-card {
  width: min(470px, calc(100% - 20px));
  max-height: 100%;
  overflow: auto;
  padding: clamp(22px, 4vw, 36px);
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 24px;
  background: rgba(255, 250, 239, 0.94);
  box-shadow: 0 24px 55px rgba(31, 50, 32, 0.22);
  text-align: center;
  backdrop-filter: blur(12px);
}

.overlay-eyebrow {
  color: var(--green);
}

.overlay-card h2 {
  margin: 7px 0 10px;
  color: var(--brown-dark);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.75rem, 4vw, 2.7rem);
  line-height: 1;
  letter-spacing: -0.035em;
}

.overlay-card > p:not(.overlay-eyebrow) {
  max-width: 39ch;
  margin: 0 auto;
  color: #645340;
  font-size: 0.97rem;
  line-height: 1.52;
}

.control-hints {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 20px 0;
  color: #735f49;
  font-size: 0.76rem;
  font-weight: 800;
}

kbd {
  padding: 2px 7px 3px;
  border: 1px solid #cbb999;
  border-bottom-width: 3px;
  border-radius: 6px;
  background: white;
  color: var(--brown-dark);
  font-family: inherit;
  font-size: 0.7rem;
}

.primary-button,
.secondary-button {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: center;
  gap: 12px;
  border: 0;
  border-radius: 13px;
  cursor: pointer;
  font-weight: 900;
}

.primary-button {
  min-height: 52px;
  padding: 12px 20px;
  background: linear-gradient(180deg, #e9a92b, #cc8217);
  box-shadow:
    0 5px 0 #985710,
    0 10px 22px rgba(152, 87, 16, 0.19);
  color: #fffdf5;
  text-shadow: 0 1px 0 rgba(80, 45, 10, 0.35);
}

.primary-button:hover {
  filter: brightness(1.04);
  translate: 0 -1px;
}

.primary-button:active {
  box-shadow: 0 2px 0 #985710;
  translate: 0 3px;
}

.secondary-button {
  margin-top: 12px;
  padding: 8px 16px;
  background: transparent;
  color: var(--brown);
}

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

.toast {
  position: absolute;
  z-index: 40;
  right: 20px;
  bottom: calc(var(--ground-height) + 18px);
  max-width: min(360px, calc(100% - 40px));
  padding: 13px 18px;
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 15px;
  background: rgba(45, 100, 31, 0.94);
  box-shadow: 0 12px 30px rgba(35, 58, 27, 0.25);
  color: white;
  font-size: 0.84rem;
  font-weight: 900;
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition:
    opacity 220ms ease,
    transform 220ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.particle {
  position: absolute;
  z-index: 16;
  color: white;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(0.8rem, 2vw, 1.2rem);
  font-weight: 950;
  text-shadow: 0 2px 0 rgba(83, 54, 28, 0.3);
  animation: particle-pop 650ms ease-out forwards;
}

@keyframes particle-pop {
  to {
    opacity: 0;
    translate: -32px -34px;
    rotate: -12deg;
    scale: 0.8;
  }
}

.below-stage {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
  padding: 28px 30px 18px;
}

.below-stage h2 {
  margin: 0;
  color: var(--brown-dark);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.5rem, 3vw, 2.2rem);
  letter-spacing: -0.03em;
}

.legend {
  display: flex;
  gap: 14px;
  color: #7a6a57;
  font-size: 0.73rem;
  font-weight: 800;
}

.legend span {
  display: flex;
  gap: 6px;
  align-items: center;
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.legend-dot.open {
  background: #65a43c;
}

.legend-dot.locked {
  background: #b3a999;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  padding: 0 30px 28px;
}

.level-button {
  position: relative;
  min-height: 152px;
  overflow: hidden;
  padding: 17px 16px 15px;
  border: 1px solid #dfd0b7;
  border-radius: 17px;
  background: #fffdf7;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  transition:
    transform 160ms ease,
    box-shadow 160ms ease,
    border-color 160ms ease;
}

.level-button:not(:disabled):hover {
  border-color: #bfa16e;
  box-shadow: 0 10px 24px rgba(90, 59, 27, 0.11);
  transform: translateY(-3px);
}

.level-button.is-selected {
  border-color: #5e922e;
  box-shadow: 0 0 0 2px #8bbf53 inset;
  background: #fbfff5;
}

.level-button:disabled {
  background:
    repeating-linear-gradient(135deg, rgba(123, 113, 99, 0.035) 0 7px, transparent 7px 14px),
    #f3efe7;
  color: #9a9185;
  cursor: not-allowed;
}

.level-topline {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.level-number {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 11px;
  background: #5f9134;
  color: white;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.15rem;
  font-weight: 900;
}

.level-button:disabled .level-number {
  background: #b3aa9b;
}

.lock-icon {
  color: #8d8276;
  font-size: 0.85rem;
  font-weight: 900;
}

.level-button h3 {
  margin: 14px 0 5px;
  color: currentColor;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1rem;
  line-height: 1.05;
}

.level-button p {
  margin: 0;
  font-size: 0.69rem;
  font-weight: 700;
  line-height: 1.35;
}

.level-meta {
  display: block;
  margin-top: 11px;
  color: var(--green-dark);
  font-size: 0.65rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.level-button:disabled .level-meta {
  color: #999186;
}

.game-footer {
  display: flex;
  justify-content: space-between;
  gap: 22px;
  align-items: center;
  padding: 17px 30px;
  border-top: 1px solid #ecdfcb;
  background: #f8edda;
}

.game-footer p {
  margin: 0;
  color: #766552;
  font-size: 0.74rem;
  font-weight: 700;
}

.text-button {
  flex: 0 0 auto;
  padding: 5px 0;
  border: 0;
  border-bottom: 1px solid currentColor;
  background: transparent;
  color: #76563c;
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 900;
}

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

@media (max-width: 820px) {
  .level-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .game-stage {
    min-height: 430px;
    aspect-ratio: 1.35;
  }

  .bessie {
    width: 11%;
  }

  .obstacle {
    width: 12%;
  }
}

@media (max-width: 600px) {
  .page-shell {
    width: min(100% - 18px, 1120px);
    padding-top: 16px;
  }

  .masthead {
    grid-template-columns: auto 1fr;
  }

  .brand-mark {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    font-size: 24px;
  }

  .bessie-badge {
    display: none;
  }

  .game-card {
    border-radius: 20px;
  }

  .game-stage {
    min-height: 500px;
    aspect-ratio: 0.82;
    background-position: center;
  }

  .game-hud {
    top: 12px;
    right: 12px;
    left: 12px;
    grid-template-columns: auto 1fr auto;
  }

  .hud-chip {
    padding: 8px 10px;
  }

  .hud-chip span,
  .hud-progress-label span {
    display: none;
  }

  .hud-progress-label {
    justify-content: center;
  }

  .icon-button {
    width: 40px;
  }

  .bessie {
    left: 17%;
    width: 16%;
    min-width: 64px;
  }

  .obstacle {
    width: 17%;
  }

  .game-overlay {
    padding: 72px 10px 56px;
  }

  .overlay-card {
    padding: 22px 19px 24px;
    border-radius: 20px;
  }

  .control-hints {
    margin: 14px 0 17px;
  }

  .hint-divider {
    display: none;
  }

  .below-stage {
    display: block;
    padding: 24px 20px 14px;
  }

  .legend {
    margin-top: 12px;
  }

  .level-grid {
    grid-template-columns: repeat(2, 1fr);
    padding: 0 20px 24px;
  }

  .level-button {
    min-height: 142px;
  }

  .game-footer {
    align-items: flex-start;
    padding: 16px 20px;
  }
}

@media (max-height: 680px) and (min-width: 700px) {
  .page-shell {
    padding-top: 12px;
  }

  .masthead {
    margin-bottom: 12px;
  }

  .game-stage {
    max-height: 540px;
  }

  .overlay-card {
    padding: 20px 28px 23px;
  }

  .control-hints {
    margin: 13px 0 16px;
  }
}

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