/* The Apocalypse Calculator. A paper form on the Ministry's green wall.
   Its paper follows the visitor's light or dark setting. */

.calc {
  --focus: var(--ink);
  display: grid;
  margin-top: clamp(3rem, 7vw, 6rem);
  overflow: hidden;
  border-radius: 4px;
  background-color: var(--paper);
  background-image: var(--grain);
  color: var(--ink);
}

.calc__poster {
  display: flex;
  flex-direction: column;
  background: #16452a;
}

.calc__poster img {
  width: 100%;
}

.calc__poster figcaption {
  flex: 1 1 auto;
  display: grid;
  place-items: center;
  padding: 0.9rem 1rem 1.15rem;
  border-top: 3px solid var(--gold);
  color: var(--ministry-cream);
  font-size: clamp(1.75rem, 3.1vw, 2.75rem);
  line-height: 0.92;
  text-align: center;
}

.calc__form {
  display: flex;
  flex-direction: column;
  padding: clamp(1.25rem, 4vw, 3.25rem);
}

.calc__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.calc__title {
  font-size: clamp(2.25rem, 1.2rem + 4.2vw, 4.5rem);
}

/* The box where the Ministry's stamp lands once dinner is covered. */
.calc__office {
  position: relative;
  flex: none;
  display: grid;
  place-items: center;
  width: clamp(6.25rem, 14vw, 9.5rem);
  height: clamp(4.25rem, 8vw, 5.5rem);
  padding: 0.5rem;
  border: 1.5px dashed var(--rule);
  border-radius: 3px;
}

.calc__office-label {
  position: absolute;
  top: 0.5rem;
  left: 0.6rem;
  color: var(--ink-soft);
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1;
}

.calc__stamp {
  margin-top: 0.7rem;
  padding: 0.3rem 0.6rem 0.22rem;
  border: 3px solid currentColor;
  border-radius: 4px;
  color: var(--red);
  font-size: clamp(1.25rem, 2.4vw, 1.75rem);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  rotate: var(--stamp-turn, -8deg);
  translate: var(--stamp-shift, 0 0);
  /* Uneven ink: see the stamp-ink filter in index.html. */
  filter: url("#stamp-ink");
  opacity: 0;
}

.calc[data-state="approved"] .calc__stamp {
  opacity: 0.92;
  animation: stamp-down 0.34s cubic-bezier(0.2, 1.3, 0.4, 1) both;
}

@keyframes stamp-down {
  from {
    opacity: 0;
    scale: 2;
  }

  60% {
    opacity: 1;
    scale: 0.93;
  }

  to {
    opacity: 0.92;
    scale: 1;
  }
}

.calc__assumption {
  max-width: 30em;
  margin-top: 0.9rem;
  color: var(--ink-soft);
}

.calc__controls {
  margin-top: 1.5rem;
}

.calc__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0;
  border-top: 1px solid var(--rule);
}

.calc__row label {
  font-weight: 600;
  line-height: 1.2;
}

.calc__stepper {
  display: flex;
  flex: none;
  border: 1px solid var(--rule);
  border-radius: 3px;
}

.calc__stepper button,
.calc__stepper input {
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.calc__stepper button {
  min-width: 2.75rem;
  min-height: 2.75rem;
  font-size: 1.3125rem;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
}

.calc__stepper input {
  width: 4rem;
  min-width: 0;
  height: 2.75rem;
  font-size: 1rem;
  font-weight: 700;
  appearance: textfield;
  -moz-appearance: textfield;
}

.calc__stepper input::-webkit-inner-spin-button,
.calc__stepper input::-webkit-outer-spin-button {
  -webkit-appearance: none;
}

.calc__stepper input[aria-invalid="true"] {
  background: var(--paper-shade);
  text-decoration: underline wavy var(--red);
}

.calc__stepper button:disabled {
  opacity: 0.36;
  cursor: default;
}

.calc__stepper :is(button, input):focus-visible {
  outline-offset: -3px;
}

.calc__results {
  margin-top: auto;
  padding-top: 1.25rem;
}

.calc__readout {
  padding: 0.9rem 1.1rem 1.05rem;
  border-top: 4px solid var(--gold);
  background: var(--ministry);
  color: var(--ministry-cream);
}

.calc__tally {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.1em 0.35em;
  font-size: clamp(1.3125rem, 2.2vw, 1.75rem);
  line-height: 1.04;
}

.calc__count {
  color: #ffd368;
  display: inline-block;
  font-size: 2em;
  font-variant-numeric: tabular-nums;
  line-height: 0.97;
}

.calc__count.is-ticking {
  animation: tick 0.26s ease;
}

@keyframes tick {
  40% {
    translate: 0 -0.08em;
  }
}

.calc__verdict {
  margin-top: 0.4rem;
  font-size: 0.9375rem;
  line-height: 1.4;
}

/* One small tin per night; filled when that night's dinner is covered. */
.calc__ledger {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.85rem;
}

.calc__ledger[hidden] {
  display: none;
}

.calc__ledger span {
  width: 1.3rem;
  height: 0.85rem;
  border: 1.5px solid rgba(255, 240, 200, 0.6);
  border-radius: 3px;
  scale: 0.84;
  transition: background-color 0.18s ease, border-color 0.18s ease, scale 0.26s cubic-bezier(0.2, 0.9, 0.3, 1);
  transition-delay: calc(var(--i, 0) * 32ms);
}

.calc__ledger span.is-covered {
  border-color: #ffd368;
  background: #ffd368;
  scale: 1;
}

.calc__five {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  min-height: 3rem;
  margin: 0;
  padding: 0.6rem 1.1rem;
  border: 0;
  background: var(--label-red);
  color: var(--on-colour);
  font-weight: 700;
  line-height: 1.24;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 0.15s ease;
}

.calc__five span {
  font-weight: 500;
  white-space: nowrap;
}

.calc__five:disabled {
  background: #73514b;
  cursor: default;
}

.calc__five:focus-visible {
  outline-offset: -4px;
  outline-color: var(--on-colour);
}

@media (hover: hover) {
  .calc__stepper button:hover:enabled {
    background: var(--paper-shade);
  }

  .calc__five:hover:enabled {
    background: #a30d06;
  }
}

@media (min-width: 44em) {
  .calc {
    grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
  }
}

@media (min-width: 60em) {
  .calc {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.12fr);
  }
}

/* Reduced motion: the stamp inks in without slamming down, the little tins change colour
   without growing, and the count does not hop. */
@media (prefers-reduced-motion: reduce) {
  .calc[data-state="approved"] .calc__stamp {
    animation-name: appear;
  }

  .calc__ledger span {
    scale: 1;
    transition-property: background-color, border-color;
  }

  .calc__count.is-ticking {
    animation: none;
  }
}
