:root {
  --ink: #203022;
  --deep-green: #254f31;
  --grass: #67b94f;
  --grass-dark: #3e843d;
  --sky: #8fd8f8;
  --cream: #fff8df;
  --paper: #fffdf3;
  --dirt: #9a633b;
  --dirt-dark: #654027;
  --yellow: #ffd54c;
  --orange: #f08d38;
  --red: #ce5149;
}

* {
  box-sizing: border-box;
}

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

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--sky);
  color: var(--ink);
  font-family: Arial, sans-serif;
}

button,
a {
  font: inherit;
}

button:focus-visible,
[tabindex="0"]:focus-visible,
a:focus-visible {
  outline: 4px solid #1738b2;
  outline-offset: 4px;
}

.game-shell {
  min-height: 100vh;
  overflow: hidden;
  position: relative;
  padding: 0 28px 28px;
  background:
    linear-gradient(180deg, transparent 0 72%, rgba(255,255,255,.16) 72% 73%, transparent 73%),
    var(--sky);
}

.game-shell::after {
  content: "";
  position: fixed;
  z-index: 0;
  left: 0;
  right: 0;
  bottom: 0;
  height: 74px;
  background:
    linear-gradient(90deg, rgba(0,0,0,.08) 25%, transparent 25% 50%, rgba(255,255,255,.08) 50% 75%, transparent 75%) 0 0 / 64px 32px,
    var(--grass-dark);
  border-top: 12px solid var(--grass);
}

.topbar,
.intro,
.custom-builder,
.game-card,
footer {
  position: relative;
  z-index: 2;
  width: min(1180px, 100%);
  margin-inline: auto;
}

.topbar {
  min-height: 82px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: var(--deep-green);
  text-decoration: none;
  font-size: 1.08rem;
  font-weight: 900;
  letter-spacing: -.02em;
}

.brand-cube {
  width: 32px;
  height: 32px;
  display: inline-block;
  background: var(--dirt);
  border: 3px solid var(--dirt-dark);
  box-shadow: inset 0 9px 0 var(--grass), 4px 4px 0 rgba(37,79,49,.22);
}

.score-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: rgba(255,253,243,.92);
  border: 3px solid var(--deep-green);
  border-radius: 10px;
  box-shadow: 4px 4px 0 rgba(37,79,49,.18);
  font-size: .92rem;
  font-weight: 700;
}

.score-star {
  color: var(--orange);
  font-size: 1.25rem;
  text-shadow: 1px 1px 0 var(--deep-green);
}

.intro {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(310px, .7fr);
  gap: 40px;
  align-items: end;
  padding: 30px 2px 28px;
}

.eyebrow,
.zone-kicker,
.challenge-label {
  margin: 0 0 7px;
  color: var(--deep-green);
  font-size: .74rem;
  font-weight: 950;
  letter-spacing: .14em;
}

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

h1 {
  max-width: 720px;
  margin-bottom: 10px;
  font-family: "Courier New", monospace;
  font-size: clamp(2.3rem, 5vw, 4.4rem);
  line-height: .98;
  letter-spacing: -.07em;
  color: #173c2a;
  text-shadow: 3px 3px 0 rgba(255,255,255,.42);
}

.intro-copy {
  max-width: 650px;
  margin-bottom: 0;
  font-size: 1.05rem;
  line-height: 1.55;
  font-weight: 600;
}

.how-to {
  display: grid;
  gap: 8px;
  padding: 18px;
  background: rgba(255,253,243,.82);
  border: 3px solid rgba(37,79,49,.65);
  box-shadow: 7px 7px 0 rgba(37,79,49,.14);
}

.how-to span {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: .92rem;
  font-weight: 750;
}

.how-to b {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
  background: var(--yellow);
  border: 2px solid var(--deep-green);
  box-shadow: 2px 2px 0 var(--deep-green);
}

.custom-builder {
  margin-bottom: 18px;
  background: rgba(255,253,243,.9);
  border: 3px solid var(--deep-green);
  box-shadow: 6px 6px 0 rgba(37,79,49,.16);
}

.custom-builder summary {
  padding: 12px 16px;
  cursor: pointer;
  color: var(--deep-green);
  font-size: .85rem;
  font-weight: 900;
  list-style-position: inside;
}

.custom-builder[open] summary {
  background: #edf5dc;
  border-bottom: 2px solid var(--deep-green);
}

.custom-builder-form {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) auto minmax(90px, .45fr) auto;
  gap: 12px;
  align-items: end;
  padding: 16px 18px 8px;
}

.custom-builder-form label {
  display: grid;
  gap: 5px;
  color: var(--deep-green);
  font-size: .7rem;
  font-weight: 850;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.custom-builder-form input {
  width: 100%;
  height: 44px;
  padding: 7px 10px;
  color: var(--deep-green);
  background: var(--paper);
  border: 3px solid var(--deep-green);
  border-radius: 0;
  font-family: "Courier New", monospace;
  font-size: 1rem;
  font-weight: 900;
}

.custom-operator {
  align-self: end;
  padding-bottom: 7px;
  color: var(--dirt);
  font-family: "Courier New", monospace;
  font-size: 1.6rem;
  font-weight: 950;
}

.custom-builder-form button {
  min-height: 44px;
  padding: 8px 14px;
  cursor: pointer;
  color: var(--paper);
  background: var(--deep-green);
  border: 2px solid var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  font-size: .78rem;
  font-weight: 900;
}

.custom-help {
  margin: 0;
  padding: 3px 18px 14px;
  color: #536449;
  font-size: .72rem;
  font-weight: 700;
}

.custom-help.has-error {
  color: #a73630;
}

.game-card {
  position: relative;
  overflow: hidden;
  background: var(--paper);
  border: 4px solid var(--deep-green);
  border-radius: 4px;
  box-shadow: 12px 12px 0 rgba(30,72,40,.25);
}

.challenge-bar {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 40px;
  align-items: center;
  padding: 22px 28px;
  background: #f7e8b7;
  border-bottom: 4px solid var(--deep-green);
}

.equation {
  display: flex;
  align-items: center;
  gap: 12px;
  font-family: "Courier New", monospace;
  font-size: clamp(2rem, 4vw, 3.1rem);
  line-height: 1;
  font-weight: 950;
  color: #173c2a;
}

.operator {
  color: var(--dirt);
}

.answer-box {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  color: var(--red);
  background: var(--paper);
  border: 3px dashed var(--red);
}

.mission-copy {
  justify-self: end;
  max-width: 400px;
  font-size: 1.05rem;
  line-height: 1.45;
  text-align: right;
}

.play-area {
  display: grid;
  grid-template-columns: minmax(240px, .72fr) 68px minmax(0, 1.55fr);
  gap: 20px;
  align-items: stretch;
  padding: 26px 28px;
}

.cube-pile,
.lots-section {
  min-width: 0;
}

.cube-pile {
  display: flex;
  flex-direction: column;
  min-height: 330px;
  padding: 18px;
  cursor: pointer;
  background: #e6d8a5;
  border: 3px dashed var(--dirt);
  transition: background .15s ease, transform .15s ease;
}

.cube-pile.has-selection,
.lot.can-drop {
  background-color: #fff2a9;
}

.pile-heading,
.lots-heading,
.lot-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.pile-heading h2,
.lots-heading h2 {
  margin: 0;
  font-size: 1.13rem;
  letter-spacing: -.03em;
}

.pickaxe {
  font-size: 1.6rem;
  filter: grayscale(1);
}

.cube-grid {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  justify-content: center;
  gap: 12px;
  min-height: 190px;
  padding: 22px 6px;
}

.voxel-cube {
  position: relative;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  padding: 0;
  cursor: grab;
  background: var(--dirt);
  border: 3px solid var(--dirt-dark);
  border-radius: 0;
  box-shadow:
    inset 0 11px 0 var(--grass),
    inset 0 14px 0 var(--grass-dark),
    5px 5px 0 rgba(71,43,26,.33);
  transition: transform .12s ease, filter .12s ease;
}

.voxel-cube:hover {
  transform: translate(-1px, -2px);
  filter: brightness(1.06);
}

.voxel-cube:active {
  cursor: grabbing;
  transform: translate(3px, 3px);
  box-shadow:
    inset 0 11px 0 var(--grass),
    inset 0 14px 0 var(--grass-dark),
    2px 2px 0 rgba(71,43,26,.33);
}

.voxel-cube.is-selected {
  transform: translate(-2px, -5px) rotate(-4deg);
  outline: 4px solid var(--yellow);
  outline-offset: 2px;
  filter: brightness(1.1);
}

.voxel-cube:disabled {
  cursor: default;
  opacity: 1;
}

.cube-pixel {
  position: absolute;
  display: block;
  width: 5px;
  height: 5px;
  background: var(--dirt-dark);
}

.cube-pixel-one {
  left: 7px;
  bottom: 7px;
}

.cube-pixel-two {
  right: 7px;
  bottom: 13px;
  background: #c48654;
}

.voxel-cube.is-package {
  width: 52px;
  flex-basis: 52px;
}

.cube-value {
  position: relative;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  color: #fffdf3;
  font-family: "Courier New", monospace;
  font-size: .72rem;
  line-height: 1;
  text-shadow: 2px 2px 0 #422818;
}

.touch-instruction,
.empty-pile {
  margin: auto 0 0;
  color: #654b34;
  font-size: .8rem;
  line-height: 1.4;
  text-align: center;
  font-weight: 700;
}

.empty-pile {
  width: 100%;
  align-self: center;
  margin: auto;
}

.arrow-sign {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--deep-green);
}

.arrow-sign span {
  font-size: 2.5rem;
  line-height: 1;
}

.arrow-sign small {
  margin-top: 8px;
  font-size: .58rem;
  font-weight: 950;
  letter-spacing: .11em;
}

.lots-heading {
  margin-bottom: 14px;
}

.lots-total {
  padding: 6px 10px;
  color: var(--paper);
  background: var(--deep-green);
  font-family: "Courier New", monospace;
  font-size: .78rem;
  font-weight: 900;
}

.lots-actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.reset-share {
  padding: 6px 8px;
  cursor: pointer;
  color: var(--deep-green);
  background: var(--paper);
  border: 2px solid var(--deep-green);
  border-radius: 0;
  font-size: .68rem;
  font-weight: 850;
}

.lot-input-help {
  margin: -5px 0 12px;
  color: #5b6852;
  font-size: .72rem;
  line-height: 1.4;
}

.lots-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.lots-2,
.lots-4 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.lot {
  min-width: 0;
  min-height: 145px;
  overflow: hidden;
  cursor: pointer;
  background: #ead5a1;
  border: 3px solid var(--deep-green);
  box-shadow: 4px 4px 0 rgba(37,79,49,.14);
  transition: transform .15s ease, background .15s ease;
}

.lot.can-drop:hover {
  transform: translateY(-3px);
}

.lot.is-over {
  border-color: var(--red);
  background: #ffd2c8;
}

.lot.is-under {
  border-color: var(--orange);
  background: #ffeac1;
}

.lot-label {
  padding: 7px 9px;
  color: var(--paper);
  background: var(--deep-green);
  font-size: .68rem;
  font-weight: 950;
  letter-spacing: .08em;
}

.lot-count-input {
  display: grid;
  place-items: center;
  width: 46px;
  height: 26px;
  padding: 1px 3px;
  color: var(--deep-green);
  background: var(--yellow);
  border: 2px solid var(--ink);
  border-radius: 0;
  font-family: "Courier New", monospace;
  font-size: .9rem;
  font-weight: 950;
  text-align: center;
}

.lot-count-input:focus {
  background: #fff4b0;
  outline: 3px solid #1738b2;
  outline-offset: 2px;
}

.lot-count-input:disabled {
  opacity: 1;
}

.lot-ground {
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
  gap: 10px;
  min-height: 106px;
  padding: 16px 8px;
  background:
    linear-gradient(90deg, transparent 48%, rgba(101,64,39,.08) 48% 52%, transparent 52%) 0 0 / 28px 28px,
    #ead5a1;
  border-top: 9px solid var(--grass);
}

.drop-here {
  color: rgba(37,79,49,.62);
  font-size: .72rem;
  font-weight: 800;
  text-align: center;
}

.mission-strip {
  padding: 10px 28px;
  color: #51381f;
  background: #fff8df;
  border-bottom: 2px solid rgba(37,79,49,.35);
  font-size: .82rem;
  line-height: 1.45;
  text-align: center;
}

.answer-form {
  justify-self: end;
  width: min(360px, 100%);
}

.answer-form label {
  display: block;
  margin-bottom: 7px;
  color: var(--deep-green);
  font-size: .72rem;
  font-weight: 900;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.answer-row {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 8px;
}

.answer-row input {
  width: 92px;
  min-width: 0;
  height: 52px;
  padding: 4px 8px;
  color: var(--deep-green);
  background: var(--paper);
  border: 3px solid var(--deep-green);
  border-radius: 0;
  font-family: "Courier New", monospace;
  font-size: 1.65rem;
  font-weight: 950;
  text-align: center;
}

.answer-row input[aria-invalid="true"] {
  border-color: var(--red);
  background: #fff0ed;
}

.answer-row button {
  min-height: 52px;
  padding: 8px 14px;
  cursor: pointer;
  color: var(--paper);
  background: var(--deep-green);
  border: 3px solid var(--ink);
  box-shadow: 4px 4px 0 var(--ink);
  font-weight: 900;
}

.answer-row button:active:not(:disabled) {
  transform: translate(3px, 3px);
  box-shadow: 1px 1px 0 var(--ink);
}

.answer-row .quick-next-button {
  grid-column: 2;
  min-height: 43px;
  color: var(--deep-green);
  background: var(--yellow);
  border-color: var(--deep-green);
  box-shadow: 4px 4px 0 var(--deep-green);
  font-size: .75rem;
}

.answer-row .quick-next-button:hover {
  background: #ffe375;
}

.answer-row button:disabled,
.answer-row input:disabled {
  cursor: default;
  opacity: .72;
}

.answer-error {
  display: block;
  min-height: 17px;
  margin-top: 5px;
  color: transparent;
  font-size: .7rem;
  font-weight: 750;
}

.answer-error.is-visible {
  color: #a73630;
}

.math-bridge {
  margin: 0 28px 26px;
  padding: 20px;
  background: #eef5e3;
  border: 3px solid var(--deep-green);
  box-shadow: 5px 5px 0 rgba(37,79,49,.16);
}

.math-bridge-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 16px;
}

.math-bridge-heading h2 {
  margin: 0;
  font-size: 1.1rem;
}

.bridge-division {
  flex: 0 0 auto;
  padding: 10px 14px;
  color: var(--paper);
  background: var(--deep-green);
  font-family: "Courier New", monospace;
  font-size: 1.05rem;
  font-weight: 950;
  box-shadow: 4px 4px 0 rgba(37,79,49,.22);
}

.lot-number-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 14px;
}

.lot-number-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 58px;
  padding: 6px 8px;
  background: var(--paper);
  border: 2px solid var(--deep-green);
  font-size: .7rem;
  font-weight: 850;
}

.lot-number-chip strong {
  margin-left: auto;
  font-family: "Courier New", monospace;
  font-size: .85rem;
}

.number-steps {
  display: grid;
  grid-template-columns: 1fr 1fr .7fr;
  gap: 10px;
}

.number-step {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 76px;
  padding: 11px 13px;
  background: var(--paper);
  border-left: 6px solid var(--dirt);
}

.number-step.is-equal {
  border-left-color: var(--grass-dark);
}

.number-step.is-uneven {
  border-left-color: var(--orange);
}

.step-label {
  margin-bottom: 5px;
  color: #5c684f;
  font-size: .66rem;
  font-weight: 850;
  letter-spacing: .03em;
  text-transform: uppercase;
}

.number-step strong {
  overflow-wrap: anywhere;
  font-family: "Courier New", monospace;
  font-size: clamp(.88rem, 2vw, 1.08rem);
}

.bridge-explanation {
  margin: 13px 0 0;
  color: #415137;
  font-size: .78rem;
  line-height: 1.45;
  font-weight: 700;
}

.feedback {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
  min-height: 84px;
  padding: 15px 28px;
  background: #edf5dc;
  border-top: 3px solid var(--deep-green);
}

.feedback-try {
  background: #fff0c5;
}

.feedback-success {
  color: #173c2a;
  background: #c8f0aa;
}

.feedback-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  background: var(--paper);
  border: 3px solid var(--deep-green);
  box-shadow: 3px 3px 0 var(--deep-green);
  font-size: 1.2rem;
}

.feedback strong {
  display: block;
  margin-bottom: 3px;
  font-size: .95rem;
}

.feedback p {
  margin-bottom: 0;
  font-size: .8rem;
  line-height: 1.35;
}

.hint-button,
.next-button {
  padding: 9px 13px;
  cursor: pointer;
  color: var(--paper);
  background: var(--deep-green);
  border: 2px solid var(--ink);
  border-radius: 0;
  box-shadow: 3px 3px 0 var(--ink);
  font-size: .75rem;
  font-weight: 850;
}

.next-button {
  color: var(--deep-green);
  background: var(--yellow);
  font-weight: 950;
}

.hint-button:active,
.next-button:active {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--ink);
}

.hint-card {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 18px;
  color: #573d13;
  background: var(--yellow);
  border-top: 3px solid var(--deep-green);
}

.hint-card p {
  margin: 0;
  font-size: .88rem;
}

.celebration {
  position: absolute;
  inset: 0;
  z-index: 8;
  pointer-events: none;
}

.celebration span {
  position: absolute;
  top: -40px;
  color: var(--orange);
  font-size: 1.8rem;
  text-shadow: 2px 2px 0 var(--deep-green);
  animation: fall 1.7s ease-in forwards;
}

.celebration span:nth-child(1) { left: 12%; animation-delay: .05s; }
.celebration span:nth-child(2) { left: 30%; color: var(--grass); animation-delay: .22s; }
.celebration span:nth-child(3) { left: 52%; animation-delay: .12s; }
.celebration span:nth-child(4) { left: 71%; color: var(--red); animation-delay: .32s; }
.celebration span:nth-child(5) { left: 88%; animation-delay: .02s; }

@keyframes fall {
  0% { transform: translateY(0) rotate(0); opacity: 0; }
  12% { opacity: 1; }
  100% { transform: translateY(680px) rotate(280deg); opacity: 0; }
}

.pixel-sun {
  position: absolute;
  z-index: 0;
  top: 90px;
  right: 7vw;
  width: 74px;
  height: 74px;
  background: var(--yellow);
  box-shadow: 0 0 0 12px rgba(255,213,76,.2);
}

.cloud {
  position: absolute;
  z-index: 0;
  width: 92px;
  height: 25px;
  background: rgba(255,255,255,.7);
  box-shadow: 24px -20px 0 rgba(255,255,255,.7), 58px 0 0 rgba(255,255,255,.7);
}

.cloud-one {
  top: 150px;
  left: 4vw;
}

.cloud-two {
  top: 260px;
  right: 10vw;
  transform: scale(.7);
  opacity: .65;
}

footer {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 28px 0 8px;
  color: var(--deep-green);
  font-size: .76rem;
  font-weight: 800;
}

@media (max-width: 900px) {
  .intro {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .how-to {
    grid-template-columns: repeat(3, 1fr);
  }

  .play-area {
    grid-template-columns: 1fr;
  }

  .cube-pile {
    min-height: 230px;
  }

  .cube-grid {
    min-height: 110px;
  }

  .arrow-sign {
    flex-direction: row;
    gap: 10px;
  }

  .arrow-sign span {
    transform: rotate(90deg);
  }
}

@media (max-width: 620px) {
  .game-shell {
    padding-inline: 12px;
  }

  .topbar {
    min-height: 68px;
  }

  .brand {
    font-size: .94rem;
  }

  .score-card {
    padding: 8px 10px;
    font-size: .78rem;
  }

  .intro {
    padding-top: 22px;
  }

  h1 {
    font-size: 2.35rem;
  }

  .intro-copy {
    font-size: .94rem;
  }

  .how-to {
    grid-template-columns: 1fr;
  }

  .custom-builder-form {
    grid-template-columns: 1fr auto .7fr;
  }

  .custom-builder-form button {
    grid-column: 1 / -1;
  }

  .challenge-bar {
    grid-template-columns: 1fr;
    gap: 14px;
    padding: 19px;
  }

  .mission-copy {
    justify-self: start;
    text-align: left;
  }

  .answer-form {
    justify-self: stretch;
  }

  .play-area {
    padding: 18px;
  }

  .lots-grid,
  .lots-2,
  .lots-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .lot {
    min-height: 134px;
  }

  .voxel-cube {
    width: 38px;
    height: 38px;
    flex-basis: 38px;
  }

  .feedback {
    grid-template-columns: auto 1fr;
    padding: 14px 18px;
  }

  .hint-button,
  .next-button {
    grid-column: 1 / -1;
    width: 100%;
  }

  .math-bridge {
    margin: 0 18px 18px;
    padding: 16px;
  }

  .math-bridge-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .bridge-division {
    width: 100%;
    text-align: center;
  }

  .number-steps {
    grid-template-columns: 1fr;
  }
}

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